|
1 /* |
|
2 * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. |
|
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 import java.awt.*; |
|
25 import java.awt.event.KeyEvent; |
|
26 |
|
27 import static jdk.testlibrary.Asserts.*; |
|
28 |
|
29 |
|
30 /* |
|
31 * @test |
|
32 * @bug 8047367 |
|
33 * @summary Check whether a Dialog set with null modality type |
|
34 * behaves like a modeless dialog |
|
35 * |
|
36 * @library ../helpers ../../../../lib/testlibrary/ |
|
37 * @build ExtendedRobot |
|
38 * @build Flag |
|
39 * @build TestDialog |
|
40 * @build TestFrame |
|
41 * @build TestWindow |
|
42 * @run main NullModalityDialogTest |
|
43 */ |
|
44 |
|
45 |
|
46 public class NullModalityDialogTest { |
|
47 |
|
48 class CustomDialog extends TestDialog { |
|
49 public CustomDialog(Frame f) { |
|
50 super(f); |
|
51 } |
|
52 @Override |
|
53 public void doOpenAction() { |
|
54 if (frame != null) { |
|
55 frame.setVisible(true); |
|
56 } |
|
57 if (window != null) { |
|
58 window.setVisible(true); |
|
59 } |
|
60 } |
|
61 } |
|
62 |
|
63 class CustomFrame extends TestFrame { |
|
64 @Override |
|
65 public void doOpenAction() { |
|
66 if (dialog != null) { |
|
67 dialog.setVisible(true); |
|
68 } |
|
69 } |
|
70 } |
|
71 |
|
72 private TestFrame parent; |
|
73 private TestDialog dialog; |
|
74 private TestFrame frame; |
|
75 private TestWindow window; |
|
76 |
|
77 private static final int delay = 1000; |
|
78 |
|
79 private final ExtendedRobot robot; |
|
80 |
|
81 NullModalityDialogTest() throws Exception { |
|
82 |
|
83 robot = new ExtendedRobot(); |
|
84 EventQueue.invokeLater(this::createGUI); |
|
85 } |
|
86 |
|
87 private void createGUI() { |
|
88 |
|
89 parent = new CustomFrame(); |
|
90 parent.setTitle("Parent"); |
|
91 parent.setLocation(50, 50); |
|
92 |
|
93 dialog = new CustomDialog(parent); |
|
94 dialog.setTitle("Dialog"); |
|
95 dialog.setModalityType((Dialog.ModalityType) null); |
|
96 dialog.setLocation(250, 50); |
|
97 |
|
98 frame = new TestFrame(); |
|
99 frame.setTitle("Frame"); |
|
100 frame.setLocation(50, 250); |
|
101 |
|
102 window = new TestWindow(frame); |
|
103 window.setLocation(250, 250); |
|
104 |
|
105 parent.setVisible(true); |
|
106 } |
|
107 |
|
108 private void closeAll() { |
|
109 if (parent != null) { parent.dispose(); } |
|
110 if (dialog != null) { dialog.dispose(); } |
|
111 if (frame != null) { frame.dispose(); } |
|
112 if (window != null) { window.dispose(); } |
|
113 } |
|
114 |
|
115 public void doTest() throws Exception { |
|
116 |
|
117 robot.waitForIdle(delay); |
|
118 |
|
119 parent.clickOpenButton(robot); |
|
120 robot.waitForIdle(delay); |
|
121 |
|
122 dialog.activated.waitForFlagTriggered(); |
|
123 assertTrue(dialog.activated.flag(), "Dialog did not trigger " + |
|
124 "Window Activated event when it became visible"); |
|
125 |
|
126 dialog.closeGained.waitForFlagTriggered(); |
|
127 assertTrue(dialog.closeGained.flag(), "the 1st button did not gain focus " + |
|
128 "when the Dialog became visible"); |
|
129 |
|
130 assertTrue(dialog.closeButton.hasFocus(), "the 1st button in the Dialog " + |
|
131 "gained focus but lost it afterwards"); |
|
132 |
|
133 dialog.openGained.reset(); |
|
134 |
|
135 robot.type(KeyEvent.VK_TAB); |
|
136 |
|
137 dialog.openGained.waitForFlagTriggered(); |
|
138 assertTrue(dialog.openGained.flag(), |
|
139 "Tab navigation did not happen properly on Dialog. Open button " + |
|
140 "did not gain focus on tab press when parent frame is visible"); |
|
141 |
|
142 dialog.clickOpenButton(robot); |
|
143 robot.waitForIdle(delay); |
|
144 |
|
145 frame.activated.waitForFlagTriggered(); |
|
146 assertTrue(frame.activated.flag(), "Frame did not trigger activated when " + |
|
147 "made visible. Dialog and its parent frame are visible"); |
|
148 |
|
149 frame.checkUnblockedFrame(robot, "Frame is the parent of a visible Dialog."); |
|
150 window.checkUnblockedWindow(robot, "Frame and its child Dialog are visible."); |
|
151 |
|
152 robot.waitForIdle(delay); |
|
153 |
|
154 EventQueue.invokeAndWait(this::closeAll); |
|
155 } |
|
156 |
|
157 public static void main(String[] args) throws Exception { |
|
158 NullModalityDialogTest test = new NullModalityDialogTest(); |
|
159 test.doTest(); |
|
160 } |
|
161 } |