Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8202880: Test javax/swing/JPopupMenu/8075063/ContextMenuScrollTest.ja…
…va fails

Reviewed-by: aivanov
  • Loading branch information
prsadhuk committed Jan 18, 2021
1 parent 68cf65d commit 3f19ef6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 52 deletions.
3 changes: 1 addition & 2 deletions test/jdk/ProblemList.txt
@@ -1,6 +1,6 @@
###########################################################################
#
# Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2009, 2021, 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
Expand Down Expand Up @@ -754,7 +754,6 @@ javax/swing/JInternalFrame/Test6325652.java 8224977 macosx-all
javax/swing/JPopupMenu/4870644/bug4870644.java 8194130 macosx-all,linux-all
javax/swing/PopupFactory/6276087/NonOpaquePopupMenuTest.java 8065099,8208565 macosx-all,linux-all
javax/swing/UIDefaults/6302464/bug6302464.java 8199079 macosx-all
javax/swing/JPopupMenu/8075063/ContextMenuScrollTest.java 202880 linux-all
javax/swing/dnd/8139050/NativeErrorsInTableDnD.java 8202765 macosx-all,linux-all
javax/swing/Popup/TaskbarPositionTest.java 8065097 macosx-all,linux-all
javax/swing/JEditorPane/6917744/bug6917744.java 8213124 macosx-all
Expand Down
83 changes: 33 additions & 50 deletions test/jdk/javax/swing/JPopupMenu/8075063/ContextMenuScrollTest.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, 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
Expand Down Expand Up @@ -46,72 +46,54 @@

public class ContextMenuScrollTest extends JPopupMenu
{
private JMenuItem undo;
private JMenuItem redo;
private JMenuItem cut;
private JMenuItem copy;
private JMenuItem paste;
private JMenuItem delete;
private JMenuItem selectAll;
private final Robot robot;
private JFrame frame;
private JMenuBar menuBar;
private JMenu menu;
private volatile Point p = null;
private volatile Dimension d = null;
private static Robot robot;
private static JFrame frame;
private static JMenu menu;
private static volatile Point p = null;
private static volatile Dimension d = null;
private static volatile boolean popupVisible = false;

public static void main(String[] args) throws Exception {
new ContextMenuScrollTest();
}
void blockTillDisplayed(JComponent comp) throws Exception {
while (p == null) {
try {
SwingUtilities.invokeAndWait(() -> {
p = comp.getLocationOnScreen();
d = menu.getSize();
});
} catch (IllegalStateException e) {
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
}
}
}
}

public ContextMenuScrollTest() throws Exception
{
robot = new Robot();
robot.setAutoDelay(200);
robot.setAutoDelay(100);
try {
SwingUtilities.invokeAndWait(()->createGUI());
blockTillDisplayed(menu);
robot.waitForIdle();
robot.delay(1000);

SwingUtilities.invokeAndWait(() -> {
p = menu.getLocationOnScreen();
d = menu.getSize();
});
System.out.println("p " + p + " d " + d);
robot.mouseMove(p.x + d.width/2, p.y + d.height/2);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.waitForIdle();
robot.delay(1000);

System.out.println("popmenu visible " + menu.isPopupMenuVisible());
robot.mouseWheel(1);
robot.waitForIdle();
System.out.println("popmenu visible " + menu.isPopupMenuVisible());
if (!menu.isPopupMenuVisible()) {

SwingUtilities.invokeAndWait(() -> {
popupVisible = menu.isPopupMenuVisible();
});
if (!popupVisible) {
throw new RuntimeException("Popup closes on mouse scroll");
}
} finally {
SwingUtilities.invokeAndWait(()->frame.dispose());
}
}

public void createGUI() {

public static void createGUI() {
frame = new JFrame();
menuBar = new JMenuBar();
JMenuBar menuBar = new JMenuBar();
menu = new JMenu("Menu");
menuBar.add(menu);

undo = new JMenuItem("Undo");
JMenuItem undo = new JMenuItem("Undo");
undo.setEnabled(false);
undo.setAccelerator(KeyStroke.getKeyStroke("control Z"));
undo.addActionListener(new ActionListener() {
Expand All @@ -122,7 +104,7 @@ public void actionPerformed(ActionEvent event) {

menu.add(undo);

redo = new JMenuItem("Redo");
JMenuItem redo = new JMenuItem("Redo");
redo.setEnabled(false);
redo.setAccelerator(KeyStroke.getKeyStroke("control Y"));
redo.addActionListener(new ActionListener() {
Expand All @@ -134,7 +116,7 @@ public void actionPerformed(ActionEvent event) {

menu.add(new JSeparator());

cut = new JMenuItem("Cut");
JMenuItem cut = new JMenuItem("Cut");
cut.setEnabled(false);
cut.setAccelerator(KeyStroke.getKeyStroke("control X"));
cut.addActionListener(new ActionListener() {
Expand All @@ -145,7 +127,7 @@ public void actionPerformed(ActionEvent event) {

menu.add(cut);

copy = new JMenuItem("Copy");
JMenuItem copy = new JMenuItem("Copy");
copy.setEnabled(false);
copy.setAccelerator(KeyStroke.getKeyStroke("control C"));
copy.addActionListener(new ActionListener() {
Expand All @@ -156,7 +138,7 @@ public void actionPerformed(ActionEvent event) {

menu.add(copy);

paste = new JMenuItem("Paste");
JMenuItem paste = new JMenuItem("Paste");
paste.setEnabled(false);
paste.setAccelerator(KeyStroke.getKeyStroke("control V"));
paste.addActionListener(new ActionListener() {
Expand All @@ -167,7 +149,7 @@ public void actionPerformed(ActionEvent event) {

menu.add(paste);

delete = new JMenuItem("Delete");
JMenuItem delete = new JMenuItem("Delete");
delete.setEnabled(false);
delete.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
delete.addActionListener(new ActionListener() {
Expand All @@ -180,7 +162,7 @@ public void actionPerformed(ActionEvent event) {

menu.add(new JSeparator());

selectAll = new JMenuItem("Select All");
JMenuItem selectAll = new JMenuItem("Select All");
selectAll.setEnabled(false);
selectAll.setAccelerator(KeyStroke.getKeyStroke("control A"));
selectAll.addActionListener(new ActionListener() {
Expand All @@ -192,6 +174,7 @@ public void actionPerformed(ActionEvent event) {
frame.setJMenuBar(menuBar);

frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}

1 comment on commit 3f19ef6

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.