|
1
|
|
package abbot.finder;
|
|
2
|
|
|
|
3
|
|
import java.awt.*;
|
|
4
|
|
import java.awt.event.*;
|
|
5
|
|
import javax.swing.*;
|
|
6
|
|
|
|
7
|
|
import junit.extensions.abbot.*;
|
|
8
|
|
import junit.extensions.abbot.Timer;
|
|
9
|
|
import abbot.tester.*;
|
|
10
|
|
import abbot.finder.matchers.*;
|
|
11
|
|
|
|
12
|
|
public class TestHierarchyTest extends ComponentTestFixture {
|
|
13
|
|
|
|
14
|
|
private TestHierarchy hierarchy;
|
|
15
|
|
|
|
16
|
7
|
protected Hierarchy createHierarchy() {
|
|
17
|
7
|
return new TestHierarchy();
|
|
18
|
|
}
|
|
19
|
|
|
|
20
|
7
|
protected void setUp() {
|
|
21
|
7
|
hierarchy = (TestHierarchy)getHierarchy();
|
|
22
|
|
}
|
|
23
|
|
|
|
24
|
4
|
protected void hideWindow(Window w) {
|
|
25
|
|
|
|
26
|
|
|
|
27
|
|
|
|
28
|
|
class Flag { volatile boolean closed; }
|
|
29
|
4
|
final Flag flag = new Flag();
|
|
30
|
4
|
w.addWindowListener(new WindowAdapter() {
|
|
31
|
4
|
public void windowClosed(WindowEvent e) {
|
|
32
|
4
|
e.getWindow().removeWindowListener(this);
|
|
33
|
4
|
flag.closed = true;
|
|
34
|
|
}
|
|
35
|
|
});
|
|
36
|
4
|
super.hideWindow(w);
|
|
37
|
4
|
while (!flag.closed) {
|
|
38
|
0
|
getRobot().sleep();
|
|
39
|
|
}
|
|
40
|
|
}
|
|
41
|
|
|
|
42
|
1
|
public void testFilterNewIgnoredWindows() throws Exception {
|
|
43
|
1
|
TestHierarchy hierarchy = new TestHierarchy();
|
|
44
|
1
|
Frame f = showFrame(new JLabel(getName()));
|
|
45
|
1
|
assertTrue("Frame should be in hierarchy", hierarchy.contains(f));
|
|
46
|
|
|
|
47
|
1
|
hierarchy.dispose(f);
|
|
48
|
1
|
showWindow(f);
|
|
49
|
1
|
assertTrue("Frame should no longer appear in hierarchy",
|
|
50
|
|
!hierarchy.contains(f));
|
|
51
|
|
|
|
52
|
1
|
JDialog d = new JDialog(f, getName());
|
|
53
|
1
|
d.getContentPane().add(new JLabel("dialog"));
|
|
54
|
1
|
showWindow(d);
|
|
55
|
1
|
assertTrue("Filtered frame dialog should not appear in hierarchy",
|
|
56
|
|
!hierarchy.contains(d));
|
|
57
|
|
|
|
58
|
1
|
disposeWindow(d);
|
|
59
|
1
|
assertTrue("Disposed dialog should not appear in hierarhcy",
|
|
60
|
|
!hierarchy.contains(d));
|
|
61
|
|
|
|
62
|
1
|
showWindow(d);
|
|
63
|
1
|
assertTrue("Redisplayed dialog should not appear in hierarchy",
|
|
64
|
|
!hierarchy.contains(d));
|
|
65
|
|
}
|
|
66
|
|
|
|
67
|
1
|
public void testAutoFilterDisposedWindows() throws Exception {
|
|
68
|
1
|
JButton openButton = new JButton("open");
|
|
69
|
1
|
final Frame f = showFrame(openButton);
|
|
70
|
|
class Flag { volatile boolean flag = true; }
|
|
71
|
1
|
final Flag flag = new Flag();
|
|
72
|
1
|
final String CLOSE = "close";
|
|
73
|
|
class TestDialog extends JDialog {
|
|
74
|
4
|
public TestDialog(final boolean dispose) {
|
|
75
|
4
|
super(f, TestHierarchyTest.this.getName());
|
|
76
|
4
|
JButton close = new JButton(CLOSE);
|
|
77
|
4
|
close.setName(CLOSE);
|
|
78
|
4
|
getContentPane().add(close);
|
|
79
|
4
|
close.addActionListener(new ActionListener() {
|
|
80
|
3
|
public void actionPerformed(ActionEvent e) {
|
|
81
|
3
|
if (dispose)
|
|
82
|
2
|
TestDialog.this.dispose();
|
|
83
|
|
else
|
|
84
|
1
|
TestDialog.this.setVisible(false);
|
|
85
|
|
}
|
|
86
|
|
});
|
|
87
|
4
|
setModal(true);
|
|
88
|
|
}
|
|
89
|
|
}
|
|
90
|
1
|
openButton.addActionListener(new ActionListener() {
|
|
91
|
4
|
public void actionPerformed(ActionEvent e) {
|
|
92
|
4
|
JDialog d = new TestDialog(flag.flag);
|
|
93
|
4
|
d.pack();
|
|
94
|
4
|
d.show();
|
|
95
|
|
}
|
|
96
|
|
});
|
|
97
|
1
|
ComponentTester tester = new ComponentTester();
|
|
98
|
1
|
tester.actionClick(openButton);
|
|
99
|
1
|
JButton closeButton = (JButton)
|
|
100
|
|
getFinder().find(new NameMatcher(CLOSE));
|
|
101
|
1
|
tester.actionClick(closeButton);
|
|
102
|
|
|
|
103
|
|
|
|
104
|
|
|
|
105
|
1
|
tester.actionClick(openButton);
|
|
106
|
1
|
JButton closeButton2 = (JButton)
|
|
107
|
|
getFinder().find(new NameMatcher(CLOSE));
|
|
108
|
1
|
assertTrue("Should pick up new button, not old one: " + closeButton,
|
|
109
|
|
!closeButton2.equals(closeButton));
|
|
110
|
1
|
tester.actionClick(closeButton2);
|
|
111
|
|
|
|
112
|
|
|
|
113
|
1
|
flag.flag = false;
|
|
114
|
1
|
tester.actionClick(openButton);
|
|
115
|
1
|
closeButton = (JButton)
|
|
116
|
|
getFinder().find(new NameMatcher(CLOSE));
|
|
117
|
1
|
tester.actionClick(closeButton);
|
|
118
|
|
|
|
119
|
1
|
tester.actionClick(openButton);
|
|
120
|
1
|
closeButton2 = (JButton)
|
|
121
|
|
getFinder().find(new NameMatcher(CLOSE));
|
|
122
|
1
|
assertEquals("Second lookup should match first",
|
|
123
|
|
closeButton, closeButton2);
|
|
124
|
|
}
|
|
125
|
|
|
|
126
|
|
|
|
127
|
1
|
public void testFilterMenuItem() throws Exception {
|
|
128
|
1
|
JFrame frame = new JFrame(getName());
|
|
129
|
1
|
JMenuBar mb = new JMenuBar();
|
|
130
|
1
|
JMenu menu = new JMenu("File");
|
|
131
|
1
|
JMenuItem mi = new JMenuItem("Item");
|
|
132
|
1
|
menu.add(mi);
|
|
133
|
1
|
mb.add(menu);
|
|
134
|
1
|
frame.setJMenuBar(mb);
|
|
135
|
1
|
showWindow(frame);
|
|
136
|
1
|
hierarchy.dispose(frame);
|
|
137
|
1
|
assertTrue("Hierarchy should no longer contain frame",
|
|
138
|
|
!hierarchy.contains(frame));
|
|
139
|
1
|
assertTrue("Hierarchy should no longer contain menu bar",
|
|
140
|
|
!hierarchy.contains(mb));
|
|
141
|
1
|
assertTrue("Hierarchy should no longer contain menu",
|
|
142
|
|
!hierarchy.contains(menu));
|
|
143
|
1
|
assertTrue("Hierarchy should no longer contain menu item",
|
|
144
|
|
!hierarchy.contains(mi));
|
|
145
|
|
}
|
|
146
|
|
|
|
147
|
1
|
public void testAutoRemoveFileChooserDialogs() throws Exception {
|
|
148
|
1
|
final JFileChooser chooser = new JFileChooser();
|
|
149
|
1
|
final Frame frame = showFrame(new JLabel(getName()));
|
|
150
|
1
|
Dialog d1 = showModalDialog(new Runnable() {
|
|
151
|
1
|
public void run() {
|
|
152
|
1
|
chooser.showOpenDialog(frame);
|
|
153
|
|
}
|
|
154
|
|
});
|
|
155
|
1
|
hideWindow(d1);
|
|
156
|
1
|
assertTrue("Transient file chooser dialog should now be filtered: "
|
|
157
|
|
+ d1.getName(),
|
|
158
|
|
hierarchy.isFiltered(d1));
|
|
159
|
1
|
assertTrue("Transient file chooser dialog should no longer be in the hierarchy",
|
|
160
|
|
!hierarchy.contains(d1));
|
|
161
|
|
}
|
|
162
|
|
|
|
163
|
1
|
public void testAutoRemoveJOptionPaneShowConfirm() throws Exception {
|
|
164
|
1
|
final JLabel confirm = new JLabel("confirm");
|
|
165
|
1
|
Runnable r = new Runnable() {
|
|
166
|
1
|
public void run() {
|
|
167
|
1
|
JOptionPane.showConfirmDialog(null, confirm);
|
|
168
|
|
}
|
|
169
|
|
};
|
|
170
|
1
|
Dialog d = showModalDialog(r);
|
|
171
|
1
|
hideWindow(d);
|
|
172
|
1
|
assertTrue("Transient option pane dialog should now be filtered: "
|
|
173
|
|
+ d.getName(),
|
|
174
|
|
hierarchy.isFiltered(d));
|
|
175
|
1
|
assertTrue("Transient option pane dialog should no longer be in the hierarchy",
|
|
176
|
|
!hierarchy.contains(d));
|
|
177
|
|
}
|
|
178
|
|
|
|
179
|
1
|
public void testAutoRemoveJOptionPaneShowInput() throws Exception {
|
|
180
|
1
|
final JLabel input = new JLabel("input");
|
|
181
|
1
|
Runnable r = new Runnable() {
|
|
182
|
1
|
public void run() {
|
|
183
|
1
|
JOptionPane.showInputDialog(null, input);
|
|
184
|
|
}
|
|
185
|
|
};
|
|
186
|
1
|
Dialog d = showModalDialog(r);
|
|
187
|
1
|
hideWindow(d);
|
|
188
|
1
|
assertTrue("Transient option pane dialog should now be filtered: "
|
|
189
|
|
+ d.getName(),
|
|
190
|
|
hierarchy.isFiltered(d));
|
|
191
|
1
|
assertTrue("Transient option pane dialog should no longer be in the hierarchy",
|
|
192
|
|
!hierarchy.contains(d));
|
|
193
|
|
}
|
|
194
|
|
|
|
195
|
1
|
public void testAutoRemoveJOptionPaneShowMessage() throws Exception {
|
|
196
|
1
|
final JLabel message = new JLabel("message");
|
|
197
|
1
|
Runnable r = new Runnable() {
|
|
198
|
1
|
public void run() {
|
|
199
|
1
|
JOptionPane.showMessageDialog(null, message);
|
|
200
|
|
}
|
|
201
|
|
};
|
|
202
|
1
|
Dialog d = showModalDialog(r);
|
|
203
|
1
|
hideWindow(d);
|
|
204
|
1
|
assertTrue("Transient option pane dialog should now be filtered: "
|
|
205
|
|
+ d.getName(),
|
|
206
|
|
hierarchy.isFiltered(d));
|
|
207
|
1
|
assertTrue("Transient option pane dialog should no longer be in the hierarchy",
|
|
208
|
|
!hierarchy.contains(d));
|
|
209
|
|
}
|
|
210
|
|
|
|
211
|
7
|
public TestHierarchyTest(String name) {
|
|
212
|
7
|
super(name);
|
|
213
|
|
}
|
|
214
|
|
|
|
215
|
0
|
public static void main(String[] args) {
|
|
216
|
0
|
RepeatHelper.runTests(args, TestHierarchyTest.class);
|
|
217
|
|
}
|
|
218
|
|
}
|
|
219
|
|
|