Skip to content

8353445: Open source several AWT Menu tests - Batch 1 #24649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -819,4 +819,5 @@ java/awt/Checkbox/CheckboxBoxSizeTest.java 8340870 windows-all
java/awt/Checkbox/CheckboxIndicatorSizeTest.java 8340870 windows-all
java/awt/Checkbox/CheckboxNullLabelTest.java 8340870 windows-all
java/awt/dnd/WinMoveFileToShellTest.java 8341665 windows-all
java/awt/Menu/MenuVisibilityTest.java 8161110 macosx-all
java/awt/Modal/NativeDialogToFrontBackTest.java 7188049 windows-all,linux-all
98 changes: 98 additions & 0 deletions test/jdk/java/awt/Menu/MenuActionEventTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright (c) 2000, 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 4094620
* @summary MenuItem.enableEvents does not work
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual MenuActionEventTest
*/

import java.awt.AWTEvent;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.event.ActionEvent;

public class MenuActionEventTest {
public static void main(String[] args) throws Exception {
String INSTRUCTIONS = """
1. Click on the Menu and then on Menuitem on the frame.
2. If you find the following message being printed in
the test log area:,
_MenuItem: action event",
click PASS, else click FAIL"
""";
PassFailJFrame.builder()
.instructions(INSTRUCTIONS)
.columns(35)
.testUI(MenuActionEventTest::initialize)
.logArea()
.build()
.awaitAndCheck();
}

static Frame initialize() {
Frame f = new Frame("Menu Action Event Test");
f.setLayout(new BorderLayout());
f.setMenuBar(new MenuBar());
Menu m = new _Menu("Menu");
MenuBar mb = f.getMenuBar();
mb.add(m);
MenuItem mi = new _MenuItem("Menuitem");
m.add(mi);
f.setBounds(204, 152, 396, 300);
return f;
}

static class _Menu extends Menu {
public _Menu(String text) {
super(text);
enableEvents(AWTEvent.ACTION_EVENT_MASK);
}

@Override
protected void processActionEvent(ActionEvent e) {
PassFailJFrame.log("_Menu: action event");
super.processActionEvent(e);
}
}

static class _MenuItem extends MenuItem {
public _MenuItem(String text) {
super(text);
enableEvents(AWTEvent.ACTION_EVENT_MASK);
}

@Override
protected void processActionEvent(ActionEvent e) {
PassFailJFrame.log("_MenuItem: action event");
super.processActionEvent(e);
}
}

}
71 changes: 71 additions & 0 deletions test/jdk/java/awt/Menu/MenuVisibilityTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2004, 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 5046491 6423258
* @summary CheckboxMenuItem: menu text is missing from test frame
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual MenuVisibilityTest
*/

import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;

public class MenuVisibilityTest {
public static void main(String[] args) throws Exception {
String INSTRUCTIONS = """
1. Press on a MenuBar with a long name.
2. Select "First item" in an opened menu.
If you see that "First menu item was pressed" in
the test log area, press PASS
Otherwise press FAIL"
""";
PassFailJFrame.builder()
.instructions(INSTRUCTIONS)
.columns(35)
.testUI(MenuVisibilityTest::initialize)
.logArea()
.build()
.awaitAndCheck();
}

public static Frame initialize() {
Frame frame = new Frame("Menu visibility test");
String menuTitle = "I_have_never_seen_so_long_Menu_Title_" +
"!_ehe-eha-ehu-ehi_ugu-gu!!!_;)_BANG_BANG...";
MenuBar menubar = new MenuBar();
Menu menu = new Menu(menuTitle);
MenuItem menuItem = new MenuItem("First item");
menuItem.addActionListener(e ->
PassFailJFrame.log("First menu item was pressed."));
menu.add(menuItem);
menubar.add(menu);
frame.setMenuBar(menubar);
frame.setSize(100, 200);
return frame;
}
}
152 changes: 152 additions & 0 deletions test/jdk/java/awt/Menu/RmInHideTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
* Copyright (c) 1998, 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 4039387
* @summary Checks that calling Frame.remove() within hide() doesn't
* cause SEGV
* @key headful
* @run main RmInHideTest
*/

import java.awt.Button;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.Point;
import java.awt.Robot;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;

public class RmInHideTest {
static volatile Point point;
static RmInHideTestFrame frame;
static volatile Dimension dimension;

public static void main(String[] args) throws Exception {
Robot robot = new Robot();
try {
EventQueue.invokeAndWait(() -> {
frame = new RmInHideTestFrame();
frame.setSize(200, 200);
frame.setVisible(true);
});
robot.waitForIdle();
robot.delay(1000);
EventQueue.invokeAndWait(() -> {
point = frame.getButtonLocation();
dimension = frame.getButtonDimension();
});
robot.mouseMove(point.x + dimension.width / 2, point.y + dimension.height / 2);
robot.mousePress(MouseEvent.BUTTON2_DOWN_MASK);
robot.mouseRelease(MouseEvent.BUTTON2_DOWN_MASK);
robot.waitForIdle();
robot.delay(100);
System.out.println("Test pass");
} finally {
EventQueue.invokeAndWait(() -> {
if (frame != null) {
frame.dispose();
}
});
}
}

static class RmInHideTestFrame extends Frame implements ActionListener {
MenuBar menubar = null;
Button b;

public RmInHideTestFrame() {
super("RmInHideTest");
b = new Button("Hide");
b.setActionCommand("hide");
b.addActionListener(this);
add("Center", b);

MenuBar bar = new MenuBar();

Menu menu = new Menu("Test1", true);
menu.add(new MenuItem("Test1A"));
menu.add(new MenuItem("Test1B"));
menu.add(new MenuItem("Test1C"));
bar.add(menu);

menu = new Menu("Test2", true);
menu.add(new MenuItem("Test2A"));
menu.add(new MenuItem("Test2B"));
menu.add(new MenuItem("Test2C"));
bar.add(menu);
setMenuBar(bar);
}

@Override
public Dimension minimumSize() {
return new Dimension(200, 200);
}

@Override
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if (cmd.equals("hide")) {
hide();
try {
Thread.currentThread().sleep(2000);
} catch (InterruptedException ex) {
// do nothing
}
show();
}
}

@Override
public void hide() {
menubar = getMenuBar();
if (menubar != null) {
remove(menubar);
}
super.hide();
}


@Override
public void show() {
if (menubar != null) {
setMenuBar(menubar);
}
super.show();
}

public Point getButtonLocation() {
return b.getLocationOnScreen();
}

public Dimension getButtonDimension() {
return b.getSize();
}
}
}
Loading