-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3dd0bd8
Open source
TejeshR13 6702f51
Updated review comments
TejeshR13 92b224a
Update PL
TejeshR13 7a22269
Update PL
TejeshR13 a83a393
Update review comments
TejeshR13 584f58b
Updated review comments
TejeshR13 b1c137a
Updated review comments
TejeshR13 b858947
Updated review comments
TejeshR13 4c8fe2c
Empty commit
TejeshR13 3a2cf46
Resolve merge conflict
TejeshR13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.