|
1
|
|
package abbot.tester;
|
|
2
|
|
|
|
3
|
|
import java.awt.*;
|
|
4
|
|
import java.awt.event.*;
|
|
5
|
|
import javax.swing.*;
|
|
6
|
|
import javax.swing.border.*;
|
|
7
|
|
|
|
8
|
|
import junit.framework.*;
|
|
9
|
|
import junit.extensions.abbot.*;
|
|
10
|
|
import junit.extensions.abbot.Timer;
|
|
11
|
|
|
|
12
|
|
public class WindowTrackerTest extends ComponentTestFixture {
|
|
13
|
|
|
|
14
|
|
private class MouseWatcher extends MouseAdapter {
|
|
15
|
|
private boolean gotClick = false;
|
|
16
|
303
|
public void mousePressed(MouseEvent e) {
|
|
17
|
303
|
gotClick = true;
|
|
18
|
|
}
|
|
19
|
|
}
|
|
20
|
|
|
|
21
|
|
private WindowTracker tracker;
|
|
22
|
|
|
|
23
|
411
|
private void wait(Window w, boolean state, String msg) {
|
|
24
|
411
|
Timer timer = new Timer();
|
|
25
|
411
|
while (tracker.isWindowReady(w) != state) {
|
|
26
|
261
|
if (timer.elapsed() > WindowTracker.WINDOW_READY_DELAY+500)
|
|
27
|
0
|
fail(msg);
|
|
28
|
261
|
try { Thread.sleep(10); } catch(InterruptedException e) { }
|
|
29
|
|
}
|
|
30
|
|
}
|
|
31
|
|
|
|
32
|
5
|
protected void setUp() {
|
|
33
|
5
|
tracker = new WindowTracker();
|
|
34
|
|
}
|
|
35
|
|
|
|
36
|
5
|
protected void tearDown() {
|
|
37
|
5
|
tracker = null;
|
|
38
|
|
}
|
|
39
|
|
|
|
40
|
|
private class MissedShow1 extends AssertionFailedError {
|
|
41
|
0
|
public MissedShow1() {
|
|
42
|
0
|
super("Window not ready after initial show");
|
|
43
|
|
}
|
|
44
|
|
}
|
|
45
|
|
private class MissedShow2 extends AssertionFailedError {
|
|
46
|
0
|
public MissedShow2() {
|
|
47
|
0
|
super("Window not ready after subsequent show");
|
|
48
|
|
}
|
|
49
|
|
}
|
|
50
|
|
|
|
51
|
1
|
public void testTrackWindowState() throws Throwable {
|
|
52
|
1
|
Frame w = new Frame(getName());
|
|
53
|
1
|
w.pack();
|
|
54
|
1
|
w.show();
|
|
55
|
1
|
wait(w, true, "WindowTracker didn't catch initial Window.show()");
|
|
56
|
1
|
assertTrue("Window should be showing", w.isShowing());
|
|
57
|
|
|
|
58
|
1
|
w.hide();
|
|
59
|
1
|
wait(w, false, "WindowTracker didn't catch Window.hide()");
|
|
60
|
1
|
assertTrue("Window should not be showing", !w.isShowing());
|
|
61
|
|
|
|
62
|
1
|
w.show();
|
|
63
|
1
|
wait(w, true, "WindowTracker didn't catch Window.show() after hide");
|
|
64
|
1
|
assertTrue("Window should be showing", w.isShowing());
|
|
65
|
|
|
|
66
|
|
|
|
67
|
1
|
w.dispose();
|
|
68
|
1
|
wait(w, false, "WindowTracker didn't catch Window.dispose()");
|
|
69
|
1
|
assertTrue("Window should not be showing", !w.isShowing());
|
|
70
|
|
}
|
|
71
|
|
|
|
72
|
101
|
public void testSingleWindowReady() throws Throwable {
|
|
73
|
101
|
JFrame f = new JFrame(getName());
|
|
74
|
101
|
MouseWatcher watcher = new MouseWatcher();
|
|
75
|
101
|
f.addMouseListener(watcher);
|
|
76
|
101
|
f.getContentPane().add(new JLabel(getName()));
|
|
77
|
101
|
f.pack();
|
|
78
|
101
|
f.setSize(100, 100);
|
|
79
|
101
|
f.show();
|
|
80
|
101
|
try {
|
|
81
|
101
|
wait(f, true, "WindowTracker didn't catch initial Window.show");
|
|
82
|
101
|
getRobot().click(f);
|
|
83
|
101
|
getRobot().waitForIdle();
|
|
84
|
101
|
if (!watcher.gotClick)
|
|
85
|
0
|
throw new MissedShow1();
|
|
86
|
|
|
|
87
|
101
|
watcher.gotClick = false;
|
|
88
|
101
|
f.hide();
|
|
89
|
101
|
wait(f, false, "WindowTracker didn't catch Window.hide after show");
|
|
90
|
|
|
|
91
|
101
|
f.show();
|
|
92
|
101
|
wait(f, true, "WindowTracker didn't catch Window.show after hide");
|
|
93
|
101
|
assertTrue("Window not ready", tracker.isWindowReady(f));
|
|
94
|
101
|
getRobot().click(f);
|
|
95
|
101
|
getRobot().waitForIdle();
|
|
96
|
101
|
if (!watcher.gotClick)
|
|
97
|
0
|
throw new MissedShow2();
|
|
98
|
|
}
|
|
99
|
|
finally {
|
|
100
|
101
|
f.dispose();
|
|
101
|
|
}
|
|
102
|
|
}
|
|
103
|
|
|
|
104
|
101
|
public void testComplexWindowReady() throws Throwable {
|
|
105
|
101
|
JList list = new JList(new String[] {
|
|
106
|
|
"one", "two", "three", "four", "five"
|
|
107
|
|
});
|
|
108
|
101
|
JFrame f = new JFrame(getName() + "1");
|
|
109
|
101
|
f.getContentPane().add(list);
|
|
110
|
101
|
MouseWatcher watcher = new MouseWatcher();
|
|
111
|
101
|
list.addMouseListener(watcher);
|
|
112
|
101
|
f.pack();
|
|
113
|
101
|
f.setLocation(100, 100);
|
|
114
|
101
|
f.show();
|
|
115
|
101
|
try {
|
|
116
|
101
|
wait(f, true, "WindowTracker didn't catch window");
|
|
117
|
|
|
|
118
|
101
|
getRobot().click(list);
|
|
119
|
101
|
getRobot().waitForIdle();
|
|
120
|
|
|
|
121
|
101
|
assertTrue("Window not ready for click", watcher.gotClick);
|
|
122
|
|
}
|
|
123
|
|
finally {
|
|
124
|
101
|
f.dispose();
|
|
125
|
|
}
|
|
126
|
|
}
|
|
127
|
|
|
|
128
|
1
|
public void testTrackRepeatedWindowReady() throws Throwable {
|
|
129
|
|
|
|
130
|
1
|
if (getRobot().getEventMode() != Robot.EM_ROBOT)
|
|
131
|
0
|
return;
|
|
132
|
1
|
int EXPECTED = 100;
|
|
133
|
1
|
int count1 = EXPECTED;
|
|
134
|
1
|
int count2 = EXPECTED;
|
|
135
|
1
|
int count3 = EXPECTED;
|
|
136
|
1
|
for (int i=0;i < EXPECTED;i++) {
|
|
137
|
100
|
try {
|
|
138
|
100
|
testSingleWindowReady();
|
|
139
|
|
}
|
|
140
|
|
catch(MissedShow1 e) {
|
|
141
|
0
|
--count1;
|
|
142
|
|
}
|
|
143
|
|
catch(MissedShow2 e) {
|
|
144
|
0
|
--count2;
|
|
145
|
|
}
|
|
146
|
100
|
try {
|
|
147
|
100
|
testComplexWindowReady();
|
|
148
|
|
}
|
|
149
|
|
catch(AssertionFailedError e) {
|
|
150
|
0
|
--count3;
|
|
151
|
|
}
|
|
152
|
|
}
|
|
153
|
1
|
assertEquals("Missed some clicks on initial show", EXPECTED, count1);
|
|
154
|
1
|
assertEquals("Missed some clicks on subsequent show", EXPECTED, count2);
|
|
155
|
1
|
assertEquals("Missed clicks on complex window", EXPECTED, count3);
|
|
156
|
|
}
|
|
157
|
|
|
|
158
|
1
|
public void testTrackWindowReadyAfterDispose() throws Exception {
|
|
159
|
1
|
Frame w = new Frame(getName());
|
|
160
|
1
|
w.pack();
|
|
161
|
1
|
w.show();
|
|
162
|
1
|
wait(w, true, "Didn't catch initial Window.show()");
|
|
163
|
1
|
assertTrue("Window not showing", w.isShowing());
|
|
164
|
|
|
|
165
|
1
|
w.dispose();
|
|
166
|
1
|
wait(w, false, "Didn't catch Window.dispose()");
|
|
167
|
1
|
assertTrue("Window not hidden", !w.isShowing());
|
|
168
|
|
|
|
169
|
1
|
w.pack();
|
|
170
|
1
|
w.show();
|
|
171
|
1
|
wait(w, true, "Didn't catch Window.show() after dispose(), pack()");
|
|
172
|
1
|
assertTrue("Window not showing", w.isShowing());
|
|
173
|
|
}
|
|
174
|
|
|
|
175
|
0
|
public static void main(String[] args) {
|
|
176
|
0
|
RepeatHelper.runTests(args, WindowTrackerTest.class);
|
|
177
|
|
}
|
|
178
|
|
}
|
|
179
|
|
|