Skip to content

Commit c5a68d0

Browse files
committed
8340432: Open source some MenuBar tests - Set2
Backport-of: 013250e4a7bc2fa83c6e57bb8fad6002dbe3176c
1 parent ad14612 commit c5a68d0

File tree

4 files changed

+325
-0
lines changed

4 files changed

+325
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (c) 1998, 2024, 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 4028130 4112308
27+
* @summary Test for location of Frame/MenuBar when MenuBar is re-added
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual MenuBarAddRemoveTest
31+
*/
32+
33+
import java.awt.Button;
34+
import java.awt.Frame;
35+
import java.awt.Menu;
36+
import java.awt.MenuBar;
37+
38+
public class MenuBarAddRemoveTest {
39+
public static void main(String[] args) throws Exception {
40+
String INSTRUCTIONS = """
41+
1. Click the left mouse button on the "Re-Add MenuBar"
42+
button several times.
43+
3. The Frame/MenuBar may repaint or flash, but the location
44+
of its upper left corner should never change.
45+
""";
46+
47+
PassFailJFrame.builder()
48+
.title("Test Instructions")
49+
.instructions(INSTRUCTIONS)
50+
.rows((int) INSTRUCTIONS.lines().count() + 2)
51+
.columns(35)
52+
.testUI(MenuBarAddRemoveTest::createUI)
53+
.build()
54+
.awaitAndCheck();
55+
}
56+
57+
private static Frame createUI() {
58+
Frame f = new Frame("Re-Add MenuBar Test Frame");
59+
Button b = new Button("Re-Add MenuBar");
60+
b.addActionListener(e -> f.setMenuBar(createMenuBar()));
61+
f.setMenuBar(createMenuBar());
62+
f.add(b);
63+
f.pack();
64+
return f;
65+
}
66+
67+
private static MenuBar createMenuBar() {
68+
MenuBar bar = new MenuBar();
69+
bar.add(new Menu("foo"));
70+
return bar;
71+
}
72+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 2005, 2024, 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 6185057
27+
* @summary Disabling a frame does not disable the menus on the frame, on
28+
* solaris/linux
29+
* @requires os.family != "mac"
30+
* @library /java/awt/regtesthelpers
31+
* @build PassFailJFrame
32+
* @run main/manual MenuBarOnDisabledFrame
33+
*/
34+
35+
import java.awt.Button;
36+
import java.awt.Frame;
37+
import java.awt.Menu;
38+
import java.awt.MenuBar;
39+
import java.awt.MenuItem;
40+
41+
public class MenuBarOnDisabledFrame {
42+
public static void main(String[] args) throws Exception {
43+
String INSTRUCTIONS = """
44+
Check if MenuBar is disabled on 'Disabled frame'
45+
Press pass if menu bar is disabled, fail otherwise
46+
""";
47+
48+
PassFailJFrame.builder()
49+
.title("Test Instructions")
50+
.instructions(INSTRUCTIONS)
51+
.rows((int) INSTRUCTIONS.lines().count() + 2)
52+
.columns(35)
53+
.testUI(MenuBarOnDisabledFrame::createUI)
54+
.build()
55+
.awaitAndCheck();
56+
}
57+
58+
public static Frame createUI() {
59+
Frame f = new Frame("Disabled frame");
60+
MenuBar mb = new MenuBar();
61+
Menu m1 = new Menu("Disabled Menu 1");
62+
Menu m2 = new Menu("Disabled Menu 2");
63+
MenuItem m11 = new MenuItem("MenuItem 1.1");
64+
MenuItem m21 = new MenuItem("MenuItem 2.1");
65+
Button b = new Button("Disabled button");
66+
67+
m1.add(m11);
68+
m2.add(m21);
69+
mb.add(m1);
70+
mb.add(m2);
71+
f.setMenuBar(mb);
72+
f.add(b);
73+
f.setEnabled(false);
74+
f.setSize(300, 300);
75+
return f;
76+
}
77+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright (c) 2005, 2024, 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 6180416
27+
* @summary Tests MenuBar and drop down menu visuals
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual MenuBarVisuals
31+
*/
32+
33+
import java.awt.Frame;
34+
import java.awt.Menu;
35+
import java.awt.MenuBar;
36+
import java.awt.MenuItem;
37+
import java.awt.MenuShortcut;
38+
import java.awt.event.KeyEvent;
39+
40+
public class MenuBarVisuals {
41+
public static void main(String[] args) throws Exception {
42+
String INSTRUCTIONS = """
43+
Look at the MenuBar and traverse the menus using mouse and
44+
keyboard. Then check if following is showing correctly:
45+
1. Mnemonic label Ctrl+A is NOT drawn for Menu 1/Submenu 1.1
46+
2. Mnemonic label Ctrl+B is drawn for
47+
Menu 1/Submenu 1.1/Item 1.1.1
48+
3. Mnemonic label Ctrl+C is drawn for Menu1/Item 1.2
49+
Press PASS if Menu is drawing correctly, FAIL otherwise.
50+
""";
51+
52+
PassFailJFrame.builder()
53+
.title("Test Instructions")
54+
.instructions(INSTRUCTIONS)
55+
.rows((int) INSTRUCTIONS.lines().count() + 2)
56+
.columns(35)
57+
.testUI(MenuBarVisuals::createUI)
58+
.build()
59+
.awaitAndCheck();
60+
}
61+
62+
private static Frame createUI() {
63+
Frame f = new Frame("MenuBar Visuals Test");
64+
MenuBar mb = new MenuBar();
65+
Menu menu1 = new Menu("Menu 1");
66+
Menu submenu11 = new Menu("Submenu 1.1");
67+
MenuItem item111 = new MenuItem("Item 1.1.1");
68+
MenuItem item112 = new MenuItem("Item 1.1.2");
69+
MenuItem item12 = new MenuItem("Item 1.2");
70+
Menu menu2 = new Menu("Menu 2");
71+
MenuItem item21 = new MenuItem("Item 2.1");
72+
MenuItem item22 = new MenuItem("Item 2.2");
73+
item111.setShortcut(new MenuShortcut(KeyEvent.VK_B, false));
74+
submenu11.add(item111);
75+
submenu11.add(item112);
76+
submenu11.setShortcut(new MenuShortcut(KeyEvent.VK_A, false));
77+
menu1.add(submenu11);
78+
item12.setShortcut(new MenuShortcut(KeyEvent.VK_C, false));
79+
menu1.add(item12);
80+
mb.add(menu1);
81+
menu2.add(item21);
82+
menu2.add(item22);
83+
mb.add(menu2);
84+
f.setMenuBar(mb);
85+
f.setSize(300, 300);
86+
return f;
87+
}
88+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright (c) 1999, 2024, 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 4275843
27+
* @summary MenuBar doesn't display all of its Menus correctly on Windows
28+
* @requires os.family == "windows"
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual SetHelpMenuTest
32+
*/
33+
34+
import java.awt.Frame;
35+
import java.awt.Menu;
36+
import java.awt.MenuBar;
37+
import java.awt.MenuItem;
38+
39+
public class SetHelpMenuTest {
40+
public static void main(String[] args) throws Exception {
41+
String INSTRUCTIONS = """
42+
An empty frame should be visible. When focused, the MenuBar
43+
should have 5 menus ("one", "two", "three", "Help 2",
44+
"four"). If so, then the test passed. Otherwise, the test
45+
failed.
46+
""";
47+
48+
PassFailJFrame.builder()
49+
.title("Test Instructions")
50+
.instructions(INSTRUCTIONS)
51+
.rows((int) INSTRUCTIONS.lines().count() + 2)
52+
.columns(35)
53+
.testUI(SetHelpMenuTest::createUI)
54+
.build()
55+
.awaitAndCheck();
56+
}
57+
58+
private static Frame createUI() {
59+
Frame f = new Frame("Help MenuBar Test");
60+
f.setSize(100, 100);
61+
62+
MenuBar mb = new MenuBar();
63+
Menu h1, h2;
64+
65+
f.setMenuBar(mb);
66+
mb.add(createMenu("one", false));
67+
mb.add(createMenu("two", false));
68+
mb.add(createMenu("three", true));
69+
70+
mb.add(h1 = createMenu("Help 1", false)); // h1 is HelpMenu
71+
mb.setHelpMenu(h1);
72+
73+
mb.add(h2 = createMenu("Help 2", false)); // h2 replaced h1
74+
mb.setHelpMenu(h2);
75+
76+
mb.add(createMenu("four", false));
77+
78+
return f;
79+
}
80+
81+
private static Menu createMenu(String name, boolean tearOff) {
82+
Menu m = new Menu(name, tearOff);
83+
m.add(new MenuItem(name + " item 1"));
84+
m.add(new MenuItem(name + " item 2"));
85+
m.add(new MenuItem(name + " item 3"));
86+
return m;
87+
}
88+
}

0 commit comments

Comments
 (0)