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/MenuBar/8007006/bug8007006.java
38821 views
1
/*
2
* Copyright (c) 2013, 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 8007006
27
* @summary [macosx] Closing subwindow loses main window menus.
28
* @author Leonid Romanov
29
* @library ../../../../lib/testlibrary
30
* @build ExtendedRobot jdk.testlibrary.OSInfo
31
* @run main bug8007006
32
*/
33
34
import java.awt.*;
35
import java.awt.event.*;
36
37
import jdk.testlibrary.OSInfo;
38
39
public class bug8007006 {
40
private static Frame frame1;
41
private static Frame frame2;
42
43
public static void main(String[] args) throws Exception {
44
if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
45
System.out.println("This test is for MacOS only. Automatically passed on other platforms.");
46
return;
47
}
48
49
System.setProperty("apple.laf.useScreenMenuBar", "true");
50
51
ExtendedRobot robot = new ExtendedRobot();
52
robot.setAutoDelay(50);
53
54
createAndShowGUI();
55
robot.waitForIdle(1500);
56
57
frame2.dispose();
58
59
robot.waitForIdle(1500);
60
61
62
// open "Apple" menu (the leftmost one)
63
robot.keyPress(KeyEvent.VK_META);
64
robot.keyPress(KeyEvent.VK_SHIFT);
65
robot.keyPress(KeyEvent.VK_SLASH);
66
robot.keyRelease(KeyEvent.VK_SLASH);
67
robot.keyRelease(KeyEvent.VK_SHIFT);
68
robot.keyRelease(KeyEvent.VK_META);
69
70
// Select our menu
71
robot.keyPress(KeyEvent.VK_LEFT);
72
robot.keyRelease(KeyEvent.VK_LEFT);
73
74
// Select menu item
75
robot.keyPress(KeyEvent.VK_DOWN);
76
robot.keyRelease(KeyEvent.VK_DOWN);
77
robot.keyPress(KeyEvent.VK_ENTER);
78
robot.keyRelease(KeyEvent.VK_ENTER);
79
80
robot.waitForIdle();
81
82
MenuBar mbar = frame1.getMenuBar();
83
Menu menu = mbar.getMenu(0);
84
CheckboxMenuItem item = (CheckboxMenuItem)menu.getItem(0);
85
boolean isChecked = item.getState();
86
87
frame1.dispose();
88
89
if (isChecked) {
90
throw new Exception("Test failed: menu item remained checked");
91
}
92
}
93
94
private static void createAndShowGUI() {
95
frame1 = new Frame("Frame 1");
96
frame1.setMenuBar(createMenuBar());
97
frame1.setSize(200, 200);
98
99
frame2 = new Frame("Frame 2");
100
frame2.setMenuBar(createMenuBar());
101
frame2.setSize(200, 200);
102
103
frame1.setVisible(true);
104
frame2.setVisible(true);
105
}
106
107
private static MenuBar createMenuBar() {
108
MenuBar mbar = new MenuBar();
109
Menu menu = new Menu("Menu");
110
MenuItem item = new CheckboxMenuItem("Checked", true);
111
112
menu.add(item);
113
mbar.add(menu);
114
115
return mbar;
116
}
117
118
}
119
120