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