Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Frame/CycleThroughFrameTest/CycleThroughFrameTest.java
38828 views
1
/*
2
* Copyright (c) 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
/*
25
@test
26
@bug 8206392
27
@requires (os.family == "mac")
28
@summary Cycle through frames using keyboard shortcut doesn't work on Mac
29
@compile CycleThroughFrameTest.java
30
@run main/manual CycleThroughFrameTest
31
*/
32
33
import java.awt.Frame;
34
import java.awt.Button;
35
import java.awt.TextArea;
36
import java.awt.FlowLayout;
37
import javax.swing.JFrame;
38
import javax.swing.SwingUtilities;
39
40
public class CycleThroughFrameTest {
41
42
public static final int maxFrames = 5;
43
private static JFrame[] frame;
44
private static Frame instructionFrame;
45
private static volatile boolean testContinueFlag = true;
46
47
private static final String TEST_INSTRUCTIONS =
48
" This is a manual test\n\n" +
49
" 1) Configure Keyboard shortcut if not done in your system:\n" +
50
" 2) Open System Preferences, go to -> Keyboard -> Shortcuts -> Keyboard\n" +
51
" 3) Enable 'Move focus to next window' if disabled\n" +
52
" 4) Enable 'Move focus to next window drawer' if disabled\n" +
53
" 5) Close System Preferences\n" +
54
" 5) Press COMMAND + ` keys to cycle through frames in forward order\n" +
55
" 6) Press FAIL if focus doesn't move to next frame\n" +
56
" 7) Press COMMAND + SHIFT + ` to cycle through frames in reverse order\n" +
57
" 8) Press FAIL if focus doesn't move to next frame in reverse order\n" +
58
" 9) Press PASS otherwise";
59
60
private static final String FAIL_MESSAGE = "Focus doesn't move to next frame";
61
62
public void showJFrame(int frameNumber) {
63
64
String title = "Frame " + frameNumber;
65
frame[frameNumber] = new JFrame(title);
66
frame[frameNumber].setSize(300, 200);
67
frame[frameNumber].setLocation(50+(frameNumber*20), 50+(frameNumber*20));
68
frame[frameNumber].setVisible(true);
69
}
70
71
private void createAndShowFrame() throws Exception {
72
SwingUtilities.invokeAndWait(new Runnable() {
73
public void run() {
74
frame = new JFrame[maxFrames];
75
for (int i = 0; i < maxFrames; i++) {
76
showJFrame(i);
77
}
78
}
79
});
80
}
81
82
public void createAndShowInstructionFrame() {
83
Button passButton = new Button("Pass");
84
passButton.setEnabled(true);
85
86
Button failButton = new Button("Fail");
87
failButton.setEnabled(true);
88
89
TextArea instructions = new TextArea(12, 70);
90
instructions.setText(TEST_INSTRUCTIONS);
91
92
instructionFrame = new Frame("Test Instructions");
93
instructionFrame.add(passButton);
94
instructionFrame.add(failButton);
95
instructionFrame.add(instructions);
96
instructionFrame.setSize(200,200);
97
instructionFrame.setLayout(new FlowLayout());
98
instructionFrame.pack();
99
instructionFrame.setVisible(true);
100
101
passButton.addActionListener(ae -> {
102
dispose();
103
testContinueFlag = false;
104
});
105
106
failButton.addActionListener(ae -> {
107
dispose();
108
testContinueFlag = false;
109
throw new RuntimeException(FAIL_MESSAGE);
110
});
111
}
112
113
private static void dispose() {
114
for (int i = 0; i < maxFrames; i++) {
115
frame[i].dispose();
116
}
117
instructionFrame.dispose();
118
}
119
120
public static void main(String[] args) throws Exception {
121
122
CycleThroughFrameTest testObj = new CycleThroughFrameTest();
123
testObj.createAndShowFrame();
124
testObj.createAndShowInstructionFrame();
125
126
final int sleepTime = 300000;
127
final int sleepLoopTime = 1000;
128
int remainingSleepTime = sleepTime;
129
while(remainingSleepTime > 0 && testContinueFlag) {
130
Thread.sleep(sleepLoopTime);
131
remainingSleepTime -= sleepLoopTime;
132
}
133
134
if (testContinueFlag) {
135
dispose();
136
throw new RuntimeException("Timed out after " +
137
(sleepTime - remainingSleepTime) / 1000 + " seconds");
138
}
139
}
140
}
141
142
143