author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 55184 | 8cddb14bb234 |
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 6271849 |
e4813eded7cb
8213110: Remove the use of applets in automatic tests
serb
parents:
50834
diff
changeset
|
28 |
@summary Tests that component in modal excluded Window which parent is blocked responses to mouse clicks. |
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 ModalExcludedWindowClickTest |
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 ModalExcludedWindowClickTest { |
29731 | 38 |
Robot robot; |
39 |
Frame frame = new Frame("Frame"); |
|
40 |
Window w = new Window(frame); |
|
41 |
Dialog d = new Dialog ((Dialog)null, "NullParentDialog", true); |
|
42 |
Button button = new Button("Button"); |
|
43 |
boolean actionPerformed = false; |
|
44 |
||
45 |
public static void main (String args[]) { |
|
46 |
ModalExcludedWindowClickTest app = new ModalExcludedWindowClickTest(); |
|
47 |
app.init(); |
|
48 |
app.start(); |
|
49 |
} |
|
50 |
||
51 |
public void init() { |
|
52 |
try { |
|
53 |
robot = new Robot(); |
|
54 |
} catch (AWTException e) { |
|
55 |
throw new RuntimeException("Error: unable to create robot", e); |
|
56 |
} |
|
57 |
} |
|
58 |
||
59 |
public void start() { |
|
60 |
||
61 |
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
|
62 |
System.out.println("No testing on MToolkit."); |
29731 | 63 |
return; |
64 |
} |
|
65 |
||
66 |
button.addActionListener(new ActionListener() { |
|
67 |
public void actionPerformed(ActionEvent e) { |
|
68 |
actionPerformed = true; |
|
50834
9cf279436b9d
8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents:
47216
diff
changeset
|
69 |
System.out.println(e.paramString()); |
29731 | 70 |
} |
71 |
}); |
|
72 |
||
73 |
EventQueue.invokeLater(new Runnable() { |
|
74 |
public void run() { |
|
75 |
frame.setSize(200, 200); |
|
76 |
frame.setVisible(true); |
|
77 |
||
78 |
w.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE); |
|
79 |
w.add(button); |
|
80 |
w.setSize(200, 200); |
|
81 |
w.setLocation(230, 230); |
|
82 |
w.setVisible(true); |
|
83 |
||
84 |
d.setSize(200, 200); |
|
85 |
d.setLocation(0, 230); |
|
86 |
d.setVisible(true); |
|
87 |
||
88 |
} |
|
89 |
}); |
|
90 |
||
91 |
waitTillShown(d); |
|
92 |
||
93 |
test(); |
|
94 |
} |
|
95 |
||
96 |
void test() { |
|
97 |
clickOn(button); |
|
98 |
waitForIdle(); |
|
99 |
if (!actionPerformed) { |
|
100 |
throw new RuntimeException("Test failed!"); |
|
101 |
} |
|
50834
9cf279436b9d
8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents:
47216
diff
changeset
|
102 |
System.out.println("Test passed."); |
29731 | 103 |
} |
104 |
||
105 |
void clickOn(Component c) { |
|
106 |
Point p = c.getLocationOnScreen(); |
|
107 |
Dimension d = c.getSize(); |
|
108 |
||
50834
9cf279436b9d
8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents:
47216
diff
changeset
|
109 |
System.out.println("Clicking " + c); |
29731 | 110 |
|
111 |
if (c instanceof Frame) { |
|
112 |
robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + ((Frame)c).getInsets().top/2); |
|
113 |
} else { |
|
114 |
robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + (int)(d.getHeight()/2)); |
|
115 |
} |
|
55184
8cddb14bb234
8224830: test/jdk/java/awt/Focus/ModalExcludedWindowClickTest/ModalExcludedWindowClickTest.java fails on linux-x64
psadhukhan
parents:
54231
diff
changeset
|
116 |
waitForIdle(); |
29731 | 117 |
robot.mousePress(InputEvent.BUTTON1_MASK); |
55184
8cddb14bb234
8224830: test/jdk/java/awt/Focus/ModalExcludedWindowClickTest/ModalExcludedWindowClickTest.java fails on linux-x64
psadhukhan
parents:
54231
diff
changeset
|
118 |
robot.delay(50); |
29731 | 119 |
robot.mouseRelease(InputEvent.BUTTON1_MASK); |
120 |
waitForIdle(); |
|
121 |
} |
|
122 |
void waitTillShown(Component c) { |
|
123 |
while (true) { |
|
124 |
try { |
|
125 |
Thread.sleep(100); |
|
55184
8cddb14bb234
8224830: test/jdk/java/awt/Focus/ModalExcludedWindowClickTest/ModalExcludedWindowClickTest.java fails on linux-x64
psadhukhan
parents:
54231
diff
changeset
|
126 |
Point p = c.getLocationOnScreen(); |
8cddb14bb234
8224830: test/jdk/java/awt/Focus/ModalExcludedWindowClickTest/ModalExcludedWindowClickTest.java fails on linux-x64
psadhukhan
parents:
54231
diff
changeset
|
127 |
if (p != null) |
8cddb14bb234
8224830: test/jdk/java/awt/Focus/ModalExcludedWindowClickTest/ModalExcludedWindowClickTest.java fails on linux-x64
psadhukhan
parents:
54231
diff
changeset
|
128 |
break; |
29731 | 129 |
} catch (InterruptedException e) { |
130 |
throw new RuntimeException(e); |
|
131 |
} catch (IllegalComponentStateException e) {} |
|
132 |
} |
|
133 |
} |
|
134 |
void waitForIdle() { |
|
135 |
try { |
|
136 |
robot.waitForIdle(); |
|
137 |
EventQueue.invokeAndWait( new Runnable() { |
|
138 |
public void run() {} // Dummy implementation |
|
139 |
}); |
|
140 |
} catch(InterruptedException ie) { |
|
50834
9cf279436b9d
8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents:
47216
diff
changeset
|
141 |
System.out.println("waitForIdle, non-fatal exception caught:"); |
29731 | 142 |
ie.printStackTrace(); |
143 |
} catch(InvocationTargetException ite) { |
|
50834
9cf279436b9d
8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents:
47216
diff
changeset
|
144 |
System.out.println("waitForIdle, non-fatal exception caught:"); |
29731 | 145 |
ite.printStackTrace(); |
146 |
} |
|
147 |
||
148 |
// wait longer... |
|
149 |
robot.delay(200); |
|
150 |
} |
|
151 |
} |