8352678: Opensource few JMenuItem tests

Reviewed-by: abhiscxk
This commit is contained in:
Prasanta Sadhukhan 2025-03-27 10:11:11 +00:00
parent 66b5dba690
commit 8a40498d79
4 changed files with 336 additions and 0 deletions

View File

@ -0,0 +1,67 @@
/*
* Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4207339
* @summary Verifies HTML label support for MenuItems
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual bug4207339
*/
import javax.swing.JPanel;
import javax.swing.JMenuItem;
public class bug4207339 {
private static final String INSTRUCTIONS = """
This tests html support in menuItem.
A MenuItem will be shown.
If the MenuItem is showing "big" text bigger than rest
and "red" text in red color and the text are in multiple lines,
and text "Yo" in blue color,
then press Pass else press Fail.""";
public static void main(String[] args) throws Exception {
PassFailJFrame.builder()
.title("bug4207339 Instructions")
.instructions(INSTRUCTIONS)
.columns(35)
.splitUI(bug4207339::createTestUI)
.build()
.awaitAndCheck();
}
private static JPanel createTestUI() {
JPanel panel = new JPanel();
JMenuItem mi = new JMenuItem("<html><center>Is this text <font size=+3>big</font>" +
"and <font color=red>red</font>?" +
"<br>And on multiple lines?<br><br>" +
"<font size=+2 color=blue face=AvantGarde>Yo!</font>" +
"Then press <em><b>PASS</b>!</center></html>");
panel.add(mi);
return panel;
}
}

View File

@ -0,0 +1,114 @@
/*
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4327146
* @summary Tests menu width after removeAll()
* @key headful
* @run main bug4327146
*/
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.event.InputEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;
public class bug4327146 {
private static JButton b;
private static JMenu m;
private static JFrame frame;
private static volatile Point loc;
private static volatile Dimension dim;
private static volatile Rectangle old_popupBounds;
private static volatile Rectangle new_popupBounds;
public static void main(String[] args) throws Exception {
Robot robot = new Robot();
try {
SwingUtilities.invokeAndWait(() -> {
frame = new JFrame("bug4327146");
m = new JMenu("Menu");
m.add(new JMenuItem("I'm an ugly bug, fix me right now please!"));
JMenuBar mbar = new JMenuBar();
mbar.add(m);
frame.setJMenuBar(mbar);
b = new JButton("Cut");
b.addActionListener(e -> {
m.removeAll();
m.add(new JMenuItem("Fixed :)"));
});
mbar.add(b);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
robot.waitForIdle();
robot.delay(1000);
SwingUtilities.invokeAndWait(() -> {
loc = b.getLocationOnScreen();
dim = b.getSize();
m.doClick();
});
robot.waitForIdle();
robot.delay(500);
SwingUtilities.invokeAndWait(() -> {
old_popupBounds = m.getPopupMenu().getBounds();
});
robot.mouseMove(loc.x + dim.width / 2, loc.y + dim.height / 2);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.waitForIdle();
robot.delay(500);
SwingUtilities.invokeAndWait(() -> {
m.doClick();
});
robot.waitForIdle();
robot.delay(500);
SwingUtilities.invokeAndWait(() -> {
new_popupBounds = m.getPopupMenu().getBounds();
});
if (new_popupBounds.getWidth() >= old_popupBounds.getWidth()) {
System.out.println("before cut popup Bounds " + old_popupBounds);
System.out.println("after cut popupBounds " + new_popupBounds);
throw new RuntimeException("JMenu popup width is wrong");
}
} finally {
SwingUtilities.invokeAndWait(() -> {
if (frame != null) {
frame.dispose();
}
});
}
}
}

View File

@ -0,0 +1,81 @@
/*
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4402082
* @requires (os.family == "windows")
* @summary Tests that JMenuItem accelerator is rendered correctly.
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual bug4402082
*/
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
public class bug4402082 {
private static final String INSTRUCTIONS = """
You see three menu items, each having different look-and-feels.
Each menu item should display accelerator "F1" on its right side.
The accelerator should be fully visible. If it is partially
offscreen, or not visible at all, test fails.""";
public static void main(String[] args) throws Exception {
PassFailJFrame.builder()
.title("bug4402082 Instructions")
.instructions(INSTRUCTIONS)
.columns(35)
.testUI(bug4402082::createTestUI)
.build()
.awaitAndCheck();
}
static JMenuItem getMenuItem(String lnf) {
try {
UIManager.setLookAndFeel(lnf);
} catch (Exception exc) {
System.err.println("Could not load LookAndFeel: " + lnf);
}
JMenuItem mi = new JMenuItem("Bad Item");
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
return mi;
}
private static JFrame createTestUI() {
JFrame frame = new JFrame("bug4402082");
Container pane = frame.getContentPane();
pane.setLayout(new GridLayout(3,1));
pane.add(getMenuItem("javax.swing.plaf.metal.MetalLookAndFeel"));
pane.add(getMenuItem("com.sun.java.swing.plaf.motif.MotifLookAndFeel"));
pane.add(getMenuItem("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"));
frame.pack();
return frame;
}
}

View File

@ -0,0 +1,74 @@
/*
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6197830
* @requires (os.family == "linux")
* @summary Fix for 4729669 does not work on Motif and GTK look and feels
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual bug6197830
*/
public class bug6197830 {
private static final String INSTRUCTIONS = """
Four windows should appear: Left-to-right and Right-to-left for
the two different Look and Feels (Motif and GTK).
Check that text on all the menu items of all menus is properly
vertically aligned.""";
public static void main(String[] args) throws Exception {
PassFailJFrame.builder()
.title("bug6197830 Instructions")
.instructions(INSTRUCTIONS)
.columns(35)
.testUI(bug6197830::createTestUI)
.position(PassFailJFrame.Position.TOP_LEFT_CORNER)
.build()
.awaitAndCheck();
}
private static List<JFrame> createTestUI() {
JFrame frame1 = MenuItemTest.doMenuItemTest(true,
"com.sun.java.swing.plaf.motif.MotifLookAndFeel",
20);
frame1.setLocation(300, 300);
JFrame frame2 = MenuItemTest.doMenuItemTest(false,
"com.sun.java.swing.plaf.motif.MotifLookAndFeel",
20);
frame2.setLocation((int)(frame1.getLocation().getX() + frame1.getWidth()
+ 100), 300);
JFrame frame3 = MenuItemTest.doMenuItemTest(true,
"com.sun.java.swing.plaf.gtk.GTKLookAndFeel", 420);
frame3.setLocation(300, (int)(frame1.getLocation().getY()
+ frame1.getHeight() + 100));
JFrame frame4 = MenuItemTest.doMenuItemTest(false,
"com.sun.java.swing.plaf.gtk.GTKLookAndFeel", 420);
frame4.setLocation((int)(frame3.getLocation().getX() + frame3.getWidth()
+ 100),
(int)frame3.getLocation().getY());
return List.of(frame1, frame2, frame3, frame4);
}
}