01: package abbot.editor.recorder;
02:
03: import java.awt.*;
04:
05: import javax.swing.JLabel;
06:
07: import junit.extensions.abbot.RepeatHelper;
08: import abbot.script.Resolver;
09: import abbot.tester.*;
10: import abbot.tester.Robot;
11:
12: /**
13: * Unit test to verify proper capture of user semantic events on a Window.
14: */
15: public class WindowRecorderTest extends AbstractSemanticRecorderFixture {
16:
17: private Window window;
18: private WindowTester tester;
19:
20: public WindowRecorderTest(String name) {
21: super (name);
22: }
23:
24: protected void setUp() throws Exception {
25: super .setUp();
26: tester = new WindowTester();
27: }
28:
29: protected SemanticRecorder createSemanticRecorder(Resolver r) {
30: return new WindowRecorder(r);
31: }
32:
33: protected Frame showWindow() {
34: Frame frame = showFrame(new JLabel(getName()));
35: window = new Window(frame);
36: window.add(new JLabel("One big label"));
37: showWindow(window);
38: return frame;
39: }
40:
41: public void testCaptureClose() {
42: showWindow();
43: startRecording();
44: tester.actionClose(window);
45: assertStep("Close\\(.*\\)");
46: }
47:
48: public void testCaptureResize() {
49: showWindow();
50: startRecording();
51: try {
52: tester.actionResize(window, 200, 200);
53: assertEquals("Window not resized", new Dimension(200, 200),
54: window.getSize());
55: assertStep("Resize\\(.*\\)");
56: } catch (ActionFailedException afe) {
57: assertTrue("Resizing should only be disallowed on mac/w32",
58: !Robot.canResizeWindows());
59: }
60: }
61:
62: // Linux/1.4.1_02 fails when this is run with the other tests on a VNC
63: // connection; INPUT_METHOD_TEXT_CHANGED gets generated, which stops the
64: // recorder from receiving the COMPONENT_MOVED event.
65: public void testCaptureMove() {
66: // Move a frame, since windows aren't always moveable
67: Frame f = showFrame(new JLabel(getName()));
68: startRecording();
69: tester.actionMove(f, 200, 200);
70: assertEquals("Frame not moved", new Point(200, 200), f
71: .getLocationOnScreen());
72: assertStep("Move\\(.*\\)");
73: }
74:
75: public static void main(String[] args) {
76: RepeatHelper.runTests(args, WindowRecorderTest.class);
77: }
78: }
|