author | serb |
Wed, 27 Feb 2019 18:46:55 -0800 | |
changeset 54231 | e4813eded7cb |
parent 50834 | 9cf279436b9d |
permissions | -rw-r--r-- |
29731 | 1 |
/* |
50834
9cf279436b9d
8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. |
29731 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
54231
e4813eded7cb
8213110: Remove the use of applets in automatic tests
serb
parents:
50834
diff
changeset
|
25 |
@test |
e4813eded7cb
8213110: Remove the use of applets in automatic tests
serb
parents:
50834
diff
changeset
|
26 |
@key headful |
e4813eded7cb
8213110: Remove the use of applets in automatic tests
serb
parents:
50834
diff
changeset
|
27 |
@bug 6253913 |
e4813eded7cb
8213110: Remove the use of applets in automatic tests
serb
parents:
50834
diff
changeset
|
28 |
@summary Tests that a Window shown before its owner is focusable. |
e4813eded7cb
8213110: Remove the use of applets in automatic tests
serb
parents:
50834
diff
changeset
|
29 |
@modules java.desktop/sun.awt |
e4813eded7cb
8213110: Remove the use of applets in automatic tests
serb
parents:
50834
diff
changeset
|
30 |
@run main WindowUpdateFocusabilityTest |
29731 | 31 |
*/ |
32 |
||
33 |
import java.awt.*; |
|
34 |
import java.awt.event.*; |
|
35 |
import java.lang.reflect.*; |
|
36 |
||
54231
e4813eded7cb
8213110: Remove the use of applets in automatic tests
serb
parents:
50834
diff
changeset
|
37 |
public class WindowUpdateFocusabilityTest { |
29731 | 38 |
Robot robot; |
39 |
boolean focusGained = false; |
|
40 |
final Object monitor = new Object(); |
|
41 |
FocusListener listener = new FocusAdapter () { |
|
42 |
public void focusGained(FocusEvent e) { |
|
50834
9cf279436b9d
8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents:
47216
diff
changeset
|
43 |
System.out.println(e.toString()); |
29731 | 44 |
synchronized (monitor) { |
45 |
focusGained = true; |
|
46 |
monitor.notifyAll(); |
|
47 |
} |
|
48 |
} |
|
49 |
}; |
|
50 |
||
51 |
public static void main(String[] args) { |
|
52 |
WindowUpdateFocusabilityTest app = new WindowUpdateFocusabilityTest(); |
|
53 |
app.init(); |
|
54 |
app.start(); |
|
55 |
} |
|
56 |
||
57 |
public void init() { |
|
58 |
try { |
|
59 |
robot = new Robot(); |
|
60 |
} catch (AWTException e) { |
|
61 |
throw new RuntimeException("Error: couldn't create robot"); |
|
62 |
} |
|
63 |
} |
|
64 |
||
65 |
public void start() { |
|
66 |
if ("sun.awt.motif.MToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) { |
|
50834
9cf279436b9d
8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents:
47216
diff
changeset
|
67 |
System.out.println("No testing on Motif."); |
29731 | 68 |
return; |
69 |
} |
|
70 |
||
71 |
test(new Frame("Frame owner")); |
|
72 |
Frame dialog_owner = new Frame("dialog's owner"); |
|
73 |
test(new Dialog(dialog_owner)); |
|
74 |
test(new Dialog(dialog_owner, Dialog.ModalityType.DOCUMENT_MODAL)); |
|
75 |
test(new Dialog(dialog_owner, Dialog.ModalityType.APPLICATION_MODAL)); |
|
76 |
test(new Dialog(dialog_owner, Dialog.ModalityType.TOOLKIT_MODAL)); |
|
77 |
test(new Dialog((Window) null, Dialog.ModalityType.MODELESS)); |
|
78 |
test(new Dialog((Window) null, Dialog.ModalityType.DOCUMENT_MODAL)); |
|
79 |
test(new Dialog((Window) null, Dialog.ModalityType.APPLICATION_MODAL)); |
|
80 |
test(new Dialog((Window) null, Dialog.ModalityType.TOOLKIT_MODAL)); |
|
81 |
dialog_owner.dispose(); |
|
82 |
} |
|
83 |
||
84 |
private void test(final Window owner) |
|
85 |
{ |
|
86 |
Window window0 = new Window(owner); // will not be shown |
|
87 |
Window window1 = new Window(window0); |
|
88 |
Window window2 = new Window(window1); |
|
89 |
Button button1 = new Button("button1"); |
|
90 |
Button button2 = new Button("button2"); |
|
91 |
button1.addFocusListener(listener); |
|
92 |
button2.addFocusListener(listener); |
|
93 |
||
94 |
owner.setBounds(800, 0, 100, 100); |
|
95 |
window1.setBounds(800, 300, 100, 100); |
|
96 |
window2.setBounds(800, 150, 100, 100); |
|
97 |
||
98 |
window1.add(button1); |
|
99 |
window2.add(button2); |
|
100 |
||
101 |
window2.setVisible(true); |
|
102 |
window1.setVisible(true); |
|
103 |
EventQueue.invokeLater(new Runnable() { |
|
104 |
public void run() { |
|
105 |
owner.setVisible(true); |
|
106 |
} |
|
107 |
}); |
|
108 |
||
109 |
try { |
|
110 |
EventQueue.invokeAndWait(new Runnable() { |
|
111 |
public void run() { |
|
112 |
// do nothing just wait until previous invokeLater will be executed |
|
113 |
} |
|
114 |
}); |
|
115 |
} catch (InterruptedException ie) { |
|
116 |
throw new RuntimeException(ie); |
|
117 |
} catch (InvocationTargetException ite) { |
|
118 |
throw new RuntimeException(ite); |
|
119 |
} |
|
120 |
||
121 |
robot.delay(1000); |
|
122 |
||
123 |
clickOn(button1); |
|
124 |
||
125 |
if (!isFocusGained()) { |
|
126 |
throw new RuntimeException("Test failed: window1 is not focusable!"); |
|
127 |
} |
|
128 |
||
129 |
focusGained = false; |
|
130 |
clickOn(button2); |
|
131 |
||
132 |
if (!isFocusGained()) { |
|
133 |
throw new RuntimeException("Test failed: window2 is not focusable!"); |
|
134 |
} |
|
135 |
||
50834
9cf279436b9d
8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents:
47216
diff
changeset
|
136 |
System.out.println("Test for " + owner.getName() + " passed."); |
29731 | 137 |
owner.dispose(); |
138 |
} |
|
139 |
||
140 |
void clickOn(Component c) { |
|
141 |
Point p = c.getLocationOnScreen(); |
|
142 |
Dimension d = c.getSize(); |
|
143 |
||
50834
9cf279436b9d
8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents:
47216
diff
changeset
|
144 |
System.out.println("Clicking " + c); |
29731 | 145 |
|
146 |
robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + (int)(d.getHeight()/2)); |
|
147 |
||
148 |
robot.mousePress(InputEvent.BUTTON1_MASK); |
|
149 |
robot.mouseRelease(InputEvent.BUTTON1_MASK); |
|
150 |
waitForIdle(); |
|
151 |
} |
|
152 |
||
153 |
void waitForIdle() { |
|
154 |
try { |
|
155 |
robot.waitForIdle(); |
|
156 |
robot.delay(50); |
|
157 |
EventQueue.invokeAndWait( new Runnable() { |
|
158 |
public void run() {} // Dummy implementation |
|
159 |
}); |
|
160 |
} catch(InterruptedException ie) { |
|
50834
9cf279436b9d
8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents:
47216
diff
changeset
|
161 |
System.out.println("waitForIdle, non-fatal exception caught:"); |
29731 | 162 |
ie.printStackTrace(); |
163 |
} catch(InvocationTargetException ite) { |
|
50834
9cf279436b9d
8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents:
47216
diff
changeset
|
164 |
System.out.println("waitForIdle, non-fatal exception caught:"); |
29731 | 165 |
ite.printStackTrace(); |
166 |
} |
|
167 |
} |
|
168 |
||
169 |
boolean isFocusGained() { |
|
170 |
synchronized (monitor) { |
|
171 |
if (!focusGained) { |
|
172 |
try { |
|
173 |
monitor.wait(3000); |
|
174 |
} catch (InterruptedException e) { |
|
50834
9cf279436b9d
8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents:
47216
diff
changeset
|
175 |
System.out.println("Interrupted unexpectedly!"); |
29731 | 176 |
throw new RuntimeException(e); |
177 |
} |
|
178 |
} |
|
179 |
} |
|
180 |
return focusGained; |
|
181 |
} |
|
182 |
} |