Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Modal/ModalBlockingTests/BlockingDDTest.java
41153 views
1
/*
2
* Copyright (c) 2007, 2018, 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 static jdk.test.lib.Asserts.*;
26
27
// DD: Dialog -> Dialog
28
29
public class BlockingDDTest {
30
31
private TestDialog parent, dialog;
32
33
private static final int delay = 1000;
34
private final ExtendedRobot robot;
35
36
private final Dialog.ModalityType modalityType;
37
private final boolean setModal;
38
39
private BlockingDDTest(Dialog.ModalityType modType, boolean modal) throws Exception {
40
41
modalityType = modType;
42
setModal = modal;
43
robot = new ExtendedRobot();
44
createGUI();
45
}
46
47
public BlockingDDTest(Dialog.ModalityType modType) throws Exception {
48
this(modType, false);
49
}
50
51
public BlockingDDTest() throws Exception {
52
this(null, true);
53
}
54
55
56
private void showParent() {
57
58
parent = new TestDialog((Frame) null);
59
parent.setTitle("Parent");
60
parent.setLocation(50, 50);
61
parent.setVisible(true);
62
}
63
64
private void showChild() {
65
66
dialog = new TestDialog(parent);
67
if (setModal) {
68
dialog.setModal(true);
69
} else if (modalityType != null) {
70
dialog.setModalityType(modalityType);
71
}
72
73
dialog.setLocation(250, 50);
74
dialog.setVisible(true);
75
}
76
77
78
private void createGUI() throws Exception {
79
80
EventQueue.invokeAndWait(this::showParent);
81
robot.waitForIdle(delay);
82
EventQueue.invokeLater(this::showChild);
83
robot.waitForIdle(delay);
84
}
85
86
public void doTest() throws Exception {
87
88
try {
89
dialog.activated.waitForFlagTriggered();
90
assertTrue(dialog.activated.flag(), "Dialog did not trigger " +
91
"Window Activated event when it became visible");
92
93
dialog.closeGained.waitForFlagTriggered();
94
assertTrue(dialog.closeGained.flag(), "the 1st Dialog button " +
95
"did not gain focus when it became visible");
96
97
assertTrue(dialog.closeButton.hasFocus(), "the 1st Dialog button " +
98
"gained the focus but lost it afterwards");
99
100
dialog.checkUnblockedDialog(robot, "Modal Dialog shouldn't be blocked.");
101
102
if ((modalityType == Dialog.ModalityType.APPLICATION_MODAL) ||
103
(modalityType == Dialog.ModalityType.DOCUMENT_MODAL) ||
104
(modalityType == Dialog.ModalityType.TOOLKIT_MODAL) ||
105
dialog.isModal())
106
{
107
parent.checkBlockedDialog(robot,
108
"Dialog is the parent of a visible " + modalityType + " Dialog.");
109
} else {
110
parent.checkUnblockedDialog(robot,
111
"Dialog is the parent of a visible " + modalityType + " Dialog.");
112
}
113
114
robot.waitForIdle(delay);
115
} finally {
116
EventQueue.invokeAndWait(this::closeAll);
117
}
118
}
119
120
private void closeAll() {
121
if (parent != null) { parent.dispose(); }
122
if (dialog != null) { dialog.dispose(); }
123
}
124
}
125
126