Skip to content

Commit

Permalink
8316164: Opensource JMenuBar manual test
Browse files Browse the repository at this point in the history
Reviewed-by: tr, jdv
  • Loading branch information
prsadhuk committed Sep 14, 2023
1 parent 33c62e4 commit 8f4dfc4
Showing 1 changed file with 128 additions and 0 deletions.
128 changes: 128 additions & 0 deletions test/jdk/javax/swing/JMenuBar/bug4403749.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright (c) 2001, 2023, 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 4403749
* @summary Tests that keyboard accelerator implementation in JMenuBar is
MenuElement aware
* @key headful
* @run main bug4403749
*/

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import javax.swing.MenuElement;
import javax.swing.MenuSelectionManager;
import javax.swing.SwingUtilities;

public class bug4403749 {
static JFrame frame;
static volatile Point pt;
static volatile Dimension dim;
static volatile boolean passed;

public static void main(String[] args) throws Exception {
Robot robot = new Robot();
robot.setAutoDelay(100);
try {
SwingUtilities.invokeAndWait(() -> {
frame = new JFrame("bug4403749");
JMenuBar mbar = new JMenuBar();
JMenu menu = new JMenu("Menu");
JPanel panel = new TestMenuElement();
menu.add(panel);
mbar.add(menu);
frame.setJMenuBar(mbar);

frame.getContentPane().add(new JButton(""));
frame.setSize(200, 200);
frame.setLocationRelativeTo(null);
frame.setAlwaysOnTop(true);
frame.setVisible(true);
});
robot.waitForIdle();
robot.delay(1000);
SwingUtilities.invokeAndWait(() -> {
pt = frame.getLocationOnScreen();
dim = frame.getSize();
});
robot.mouseMove(pt.x + dim.width / 2, pt.y + dim.height / 2);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.waitForIdle();
robot.delay(200);
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_ALT);
if (!passed) {
throw new RuntimeException("Failed: processKeyBinding wasn't called");
}
} finally {
SwingUtilities.invokeAndWait(() -> {
if (frame != null) {
frame.dispose();
}
});
}
}

static class TestMenuElement extends JPanel implements MenuElement {
public void processMouseEvent(MouseEvent event,
MenuElement[] path,
MenuSelectionManager manager) {}

public void processKeyEvent(KeyEvent event,
MenuElement[] path,
MenuSelectionManager manager) {}

public void menuSelectionChanged(boolean isIncluded) {}

public MenuElement[] getSubElements() {
return new MenuElement[0];
}

public Component getComponent() {
return this;
}

protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
int condition, boolean pressed) {
passed = true;
return super.processKeyBinding(ks, e, condition, pressed);
}
}
}

5 comments on commit 8f4dfc4

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 8f4dfc4 Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk11u-dev

... Type-O, I meant 21 ...

@openjdk
Copy link

@openjdk openjdk bot commented on 8f4dfc4 Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch backport-GoeLin-8f4dfc44 in my personal fork of openjdk/jdk11u-dev. To create a pull request with this backport targeting openjdk/jdk11u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 8f4dfc44 from the openjdk/jdk repository.

The commit being backported was authored by Prasanta Sadhukhan on 14 Sep 2023 and was reviewed by Tejesh R and Jayathirth D V.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk11u-dev:

$ git fetch https://github.com/openjdk-bots/jdk11u-dev.git backport-GoeLin-8f4dfc44:backport-GoeLin-8f4dfc44
$ git checkout backport-GoeLin-8f4dfc44
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk11u-dev.git backport-GoeLin-8f4dfc44

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 8f4dfc4 Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 8f4dfc4 Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch backport-GoeLin-8f4dfc44 in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 8f4dfc44 from the openjdk/jdk repository.

The commit being backported was authored by Prasanta Sadhukhan on 14 Sep 2023 and was reviewed by Tejesh R and Jayathirth D V.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-GoeLin-8f4dfc44:backport-GoeLin-8f4dfc44
$ git checkout backport-GoeLin-8f4dfc44
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-GoeLin-8f4dfc44

Please sign in to comment.