Skip to content

Commit 257d5ef

Browse files
author
Andrew Lu
committed
8316240: Open source several add/remove MenuBar manual tests
Backport-of: 3809d69ac4b3d186ccdc336949b658e4671347c8
1 parent 8c80c8f commit 257d5ef

File tree

4 files changed

+514
-0
lines changed

4 files changed

+514
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright (c) 1998, 2023, 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.Frame;
25+
import java.awt.Menu;
26+
import java.awt.MenuBar;
27+
import java.awt.event.MouseAdapter;
28+
import java.awt.event.MouseEvent;
29+
import javax.swing.SwingUtilities;
30+
31+
/*
32+
* @test
33+
* @bug 4028130
34+
* @summary Test dynamically adding and removing a menu bar
35+
* @library /java/awt/regtesthelpers
36+
* @build PassFailJFrame
37+
* @run main/manual AddRemoveMenuBarTest_1
38+
*/
39+
40+
public class AddRemoveMenuBarTest_1 {
41+
42+
private static final String INSTRUCTIONS = """
43+
An initially empty frame should appear.
44+
45+
Click anywhere in the frame to add a menu bar at the top of the frame.
46+
47+
Click again to replace the menu bar with another menu bar.
48+
49+
Each menu bar has one (empty) menu, labelled with the
50+
number of the menu bar appearing.
51+
52+
After a menubar is added, the frame should not be resized nor repositioned
53+
on the screen;
54+
55+
it should have the same size and position.
56+
57+
Upon test completion, click Pass or Fail appropriately.
58+
""";
59+
60+
public static void main(String[] args) throws Exception {
61+
PassFailJFrame passFailJFrame = new PassFailJFrame.Builder()
62+
.title("AddRemoveMenuBarTest_1 Instructions")
63+
.instructions(INSTRUCTIONS)
64+
.testTimeOut(5)
65+
.rows(18)
66+
.columns(45)
67+
.build();
68+
69+
SwingUtilities.invokeAndWait(() -> {
70+
AddRemoveMenuBar_1 frame = new AddRemoveMenuBar_1();
71+
72+
PassFailJFrame.addTestWindow(frame);
73+
PassFailJFrame.positionTestWindow(frame,
74+
PassFailJFrame.Position.HORIZONTAL);
75+
76+
frame.setVisible(true);
77+
});
78+
79+
passFailJFrame.awaitAndCheck();
80+
}
81+
}
82+
83+
class AddRemoveMenuBar_1 extends Frame {
84+
int menuCount;
85+
86+
AddRemoveMenuBar_1() {
87+
super("AddRemoveMenuBar_1");
88+
setSize(200, 200);
89+
menuCount = 0;
90+
91+
addMouseListener(new MouseAdapter() {
92+
@Override
93+
public void mouseClicked(MouseEvent e) {
94+
setMenuBar();
95+
}
96+
});
97+
}
98+
99+
void setMenuBar() {
100+
MenuBar bar = new MenuBar();
101+
bar.add(new Menu(Integer.toString(menuCount++)));
102+
setMenuBar(bar);
103+
}
104+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright (c) 1998, 2023, 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.Frame;
25+
import java.awt.Menu;
26+
import java.awt.MenuBar;
27+
import java.awt.event.MouseAdapter;
28+
import java.awt.event.MouseEvent;
29+
import javax.swing.SwingUtilities;
30+
31+
/*
32+
* @test
33+
* @bug 4028130
34+
* @key headful
35+
* @summary Test dynamically adding and removing a menu bar
36+
* @library /java/awt/regtesthelpers
37+
* @build PassFailJFrame
38+
* @run main/manual AddRemoveMenuBarTest_2
39+
*/
40+
41+
public class AddRemoveMenuBarTest_2 {
42+
private static final String INSTRUCTIONS = """
43+
A frame with a menu bar appears.
44+
45+
Click anywhere in the frame to replace the menu bar with
46+
another one.
47+
48+
Each menu bar has one (empty) menu, 'foo'.
49+
50+
After the menu bar replacement, the containing frame
51+
should not be resized nor repositioned on the screen.
52+
53+
Upon test completion, click Pass or Fail appropriately.
54+
""";
55+
56+
public static void main(String[] args) throws Exception {
57+
PassFailJFrame passFailJFrame = new PassFailJFrame.Builder()
58+
.title("AddRemoveMenuBarTest_2 Instructions")
59+
.instructions(INSTRUCTIONS)
60+
.testTimeOut(5)
61+
.rows(15)
62+
.columns(45)
63+
.build();
64+
65+
SwingUtilities.invokeAndWait(() -> {
66+
AddRemoveMenuBar_2 frame = new AddRemoveMenuBar_2();
67+
68+
PassFailJFrame.addTestWindow(frame);
69+
PassFailJFrame.positionTestWindow(frame,
70+
PassFailJFrame.Position.HORIZONTAL);
71+
72+
frame.setVisible(true);
73+
});
74+
75+
passFailJFrame.awaitAndCheck();
76+
}
77+
}
78+
79+
class AddRemoveMenuBar_2 extends Frame {
80+
AddRemoveMenuBar_2() {
81+
super("AddRemoveMenuBar_2");
82+
setSize(200, 200);
83+
setMenuBar();
84+
addMouseListener(new MouseAdapter() {
85+
@Override
86+
public void mouseClicked(MouseEvent e) {
87+
setMenuBar();
88+
}
89+
});
90+
}
91+
92+
int count = 0;
93+
94+
void setMenuBar() {
95+
MenuBar bar = new MenuBar();
96+
bar.add(new Menu("foo " + count++));
97+
super.setMenuBar(bar);
98+
}
99+
}

0 commit comments

Comments
 (0)