Skip to content

Commit 3f19ef6

Browse files
committedJan 18, 2021
8202880: Test javax/swing/JPopupMenu/8075063/ContextMenuScrollTest.java fails
Reviewed-by: aivanov
1 parent 68cf65d commit 3f19ef6

File tree

2 files changed

+34
-52
lines changed

2 files changed

+34
-52
lines changed
 

‎test/jdk/ProblemList.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
###########################################################################
22
#
3-
# Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
3+
# Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
44
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
#
66
# This code is free software; you can redistribute it and/or modify it
@@ -754,7 +754,6 @@ javax/swing/JInternalFrame/Test6325652.java 8224977 macosx-all
754754
javax/swing/JPopupMenu/4870644/bug4870644.java 8194130 macosx-all,linux-all
755755
javax/swing/PopupFactory/6276087/NonOpaquePopupMenuTest.java 8065099,8208565 macosx-all,linux-all
756756
javax/swing/UIDefaults/6302464/bug6302464.java 8199079 macosx-all
757-
javax/swing/JPopupMenu/8075063/ContextMenuScrollTest.java 202880 linux-all
758757
javax/swing/dnd/8139050/NativeErrorsInTableDnD.java 8202765 macosx-all,linux-all
759758
javax/swing/Popup/TaskbarPositionTest.java 8065097 macosx-all,linux-all
760759
javax/swing/JEditorPane/6917744/bug6917744.java 8213124 macosx-all

‎test/jdk/javax/swing/JPopupMenu/8075063/ContextMenuScrollTest.java

+33-50
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -46,72 +46,54 @@
4646

4747
public class ContextMenuScrollTest extends JPopupMenu
4848
{
49-
private JMenuItem undo;
50-
private JMenuItem redo;
51-
private JMenuItem cut;
52-
private JMenuItem copy;
53-
private JMenuItem paste;
54-
private JMenuItem delete;
55-
private JMenuItem selectAll;
56-
private final Robot robot;
57-
private JFrame frame;
58-
private JMenuBar menuBar;
59-
private JMenu menu;
60-
private volatile Point p = null;
61-
private volatile Dimension d = null;
49+
private static Robot robot;
50+
private static JFrame frame;
51+
private static JMenu menu;
52+
private static volatile Point p = null;
53+
private static volatile Dimension d = null;
54+
private static volatile boolean popupVisible = false;
6255

6356
public static void main(String[] args) throws Exception {
64-
new ContextMenuScrollTest();
65-
}
66-
void blockTillDisplayed(JComponent comp) throws Exception {
67-
while (p == null) {
68-
try {
69-
SwingUtilities.invokeAndWait(() -> {
70-
p = comp.getLocationOnScreen();
71-
d = menu.getSize();
72-
});
73-
} catch (IllegalStateException e) {
74-
try {
75-
Thread.sleep(1000);
76-
} catch (InterruptedException ie) {
77-
}
78-
}
79-
}
80-
}
81-
82-
public ContextMenuScrollTest() throws Exception
83-
{
8457
robot = new Robot();
85-
robot.setAutoDelay(200);
58+
robot.setAutoDelay(100);
8659
try {
8760
SwingUtilities.invokeAndWait(()->createGUI());
88-
blockTillDisplayed(menu);
8961
robot.waitForIdle();
62+
robot.delay(1000);
9063

64+
SwingUtilities.invokeAndWait(() -> {
65+
p = menu.getLocationOnScreen();
66+
d = menu.getSize();
67+
});
68+
System.out.println("p " + p + " d " + d);
9169
robot.mouseMove(p.x + d.width/2, p.y + d.height/2);
92-
robot.mousePress(InputEvent.BUTTON1_MASK);
93-
robot.mouseRelease(InputEvent.BUTTON1_MASK);
70+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
71+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
9472
robot.waitForIdle();
73+
robot.delay(1000);
9574

96-
System.out.println("popmenu visible " + menu.isPopupMenuVisible());
9775
robot.mouseWheel(1);
9876
robot.waitForIdle();
99-
System.out.println("popmenu visible " + menu.isPopupMenuVisible());
100-
if (!menu.isPopupMenuVisible()) {
77+
78+
SwingUtilities.invokeAndWait(() -> {
79+
popupVisible = menu.isPopupMenuVisible();
80+
});
81+
if (!popupVisible) {
10182
throw new RuntimeException("Popup closes on mouse scroll");
10283
}
10384
} finally {
10485
SwingUtilities.invokeAndWait(()->frame.dispose());
10586
}
10687
}
10788

108-
public void createGUI() {
89+
90+
public static void createGUI() {
10991
frame = new JFrame();
110-
menuBar = new JMenuBar();
92+
JMenuBar menuBar = new JMenuBar();
11193
menu = new JMenu("Menu");
11294
menuBar.add(menu);
11395

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

123105
menu.add(undo);
124106

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

135117
menu.add(new JSeparator());
136118

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

146128
menu.add(cut);
147129

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

157139
menu.add(copy);
158140

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

168150
menu.add(paste);
169151

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

181163
menu.add(new JSeparator());
182164

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

194176
frame.pack();
177+
frame.setLocationRelativeTo(null);
195178
frame.setVisible(true);
196179
}
197180
}

0 commit comments

Comments
 (0)
Please sign in to comment.