Skip to content

Commit ae3f093

Browse files
committed
Backport a0794e0a054c5e7ed051efa6362726cdd7598255
1 parent 59468ba commit ae3f093

File tree

3 files changed

+360
-0
lines changed

3 files changed

+360
-0
lines changed

test/jdk/ProblemList.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,7 @@ java/awt/Focus/AppletInitialFocusTest/AppletInitialFocusTest1.java 8256289 windo
829829
java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java 8258103 linux-all
830830
java/awt/Focus/FrameMinimizeTest/FrameMinimizeTest.java 8016266 linux-x64
831831
java/awt/Frame/SizeMinimizedTest.java 8305915 linux-x64
832+
java/awt/PopupMenu/PopupHangTest.java 8340022 windows-all
832833
java/awt/dnd/WinMoveFileToShellTest.java 8341665 windows-all
833834

834835

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
/*
2+
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
/*
24+
* @test
25+
* @bug 4145193
26+
* @summary Mouse event activates multiple pull-down menus when testing Oracle app
27+
* @library /java/awt/regtesthelpers
28+
* @build PassFailJFrame
29+
* @run main/manual PopupHangTest
30+
*/
31+
32+
import java.awt.BorderLayout;
33+
import java.awt.Component;
34+
import java.awt.Color;
35+
import java.awt.Dimension;
36+
import java.awt.Frame;
37+
import java.awt.Graphics;
38+
import java.awt.Label;
39+
import java.awt.MenuItem;
40+
import java.awt.PopupMenu;
41+
import java.awt.event.FocusEvent;
42+
import java.awt.event.KeyEvent;
43+
import java.awt.event.MouseEvent;
44+
import java.awt.event.FocusListener;
45+
import java.awt.event.KeyListener;
46+
import java.awt.event.MouseListener;
47+
import java.awt.event.MouseMotionListener;
48+
49+
public class PopupHangTest {
50+
private static final String INSTRUCTIONS = """
51+
2 areas yellow and red should be seen.
52+
53+
Clicking in these areas should cause a menu to popup. See if you can
54+
get the menu to stay up and grab all input. One way to do this is to
55+
click and hold the mouse to popup the menu, move away/outside of the
56+
menu and release the mouse. At that point, the input is grabbed and
57+
the *only* way out is to hit the escape key. Try this on both areas.
58+
59+
To make things worse, when the popup menu is up, click repeatedly on
60+
the LightWeight component area. Hit escape. Do you see multiple menus appearing ?
61+
62+
If you do not see either of the two problems above, the problem is fixed.
63+
Press pass, else press Fail""";
64+
65+
static Frame frame;
66+
67+
public static void main(String[] args) throws Exception {
68+
PassFailJFrame.builder()
69+
.title("PopupHangTest")
70+
.instructions(INSTRUCTIONS)
71+
.rows((int) INSTRUCTIONS.lines().count() + 2)
72+
.columns(45)
73+
.testUI(PopupHangTest::createUI)
74+
.logArea()
75+
.build()
76+
.awaitAndCheck();
77+
}
78+
79+
private static Frame createUI() {
80+
TestMenuButton m1;
81+
TestHeavyButton m2;
82+
frame = new Frame();
83+
84+
frame.setLayout (new BorderLayout ());
85+
86+
m1 = new TestMenuButton("LightWeight component");
87+
m1.setBackground(Color.yellow);
88+
89+
m2 = new TestHeavyButton("HeavyWeight component");
90+
m2.setBackground(Color.red);
91+
92+
frame.add("North", m1);
93+
frame.add("South", m2);
94+
95+
m1.requestFocus();
96+
frame.setSize(200, 110);
97+
return frame;
98+
}
99+
100+
}
101+
102+
class TestMenuButton extends Component implements MouseListener,
103+
MouseMotionListener,
104+
KeyListener,
105+
FocusListener {
106+
107+
PopupMenu popupMenu = null;
108+
String name;
109+
110+
TestMenuButton(String name) {
111+
PopupMenu menu = popupMenu = new PopupMenu("Popup");
112+
menu.add(new MenuItem("item 1"));
113+
menu.add(new MenuItem("item 2"));
114+
menu.add(new MenuItem("item 3"));
115+
this.add(menu);
116+
this.name = name;
117+
addMouseListener(this);
118+
addMouseMotionListener(this);
119+
addKeyListener(this);
120+
addFocusListener(this);
121+
}
122+
123+
void println(String messageIn) {
124+
PassFailJFrame.log(messageIn);
125+
}
126+
127+
public void mouseClicked(MouseEvent event) {
128+
/*
129+
popupMenu.show(this, event.getX(), event.getY());
130+
*/
131+
}
132+
public void mousePressed(MouseEvent event) {
133+
println("TestMenuButton.mousePressed() called !!");
134+
popupMenu.show(this, event.getX(), event.getY());
135+
}
136+
public void mouseReleased(MouseEvent event) {
137+
println("TestMenuButton.mouseReleased() called !!");
138+
}
139+
public void mouseEntered(MouseEvent event) {
140+
println("TestMenuButton.mouseEntered() called !!");
141+
requestFocus();
142+
}
143+
public void mouseExited(MouseEvent event) {
144+
}
145+
146+
public void mouseDragged(MouseEvent event) {
147+
println("TestMenuButton.mouseDragged() called !!");
148+
}
149+
public void mouseMoved(MouseEvent event) {
150+
println("TestMenuButton.mouseMoved() called !!");
151+
}
152+
153+
public void keyPressed(KeyEvent event) {
154+
println("TestMenuButton.keyPressed() called !!");
155+
}
156+
public void keyReleased(KeyEvent event) {
157+
println("TestMenuButton.keyReleased() called !!");
158+
}
159+
public void keyTyped(KeyEvent event) {
160+
println("TestMenuButton.keyTyped() called !!");
161+
}
162+
163+
164+
public void focusGained(FocusEvent e){
165+
println("TestMenuButton.focusGained():" + e);
166+
}
167+
public void focusLost(FocusEvent e){
168+
println("TestMenuButton.focusLost():" + e);
169+
}
170+
171+
172+
public void paint(Graphics g) {
173+
Dimension d = getSize();
174+
175+
g.setColor(getBackground());
176+
g.fillRect(0, 0, d.width-1, d.height-1);
177+
178+
g.setColor(Color.black);
179+
g.drawString(name, 15, 15);
180+
}
181+
182+
public Dimension getPreferredSize() {
183+
return (new Dimension(200, 50));
184+
}
185+
186+
}
187+
188+
class TestHeavyButton extends Label implements MouseListener,
189+
MouseMotionListener,
190+
KeyListener,
191+
FocusListener {
192+
193+
PopupMenu popupMenu = null;
194+
String name;
195+
196+
TestHeavyButton(String name) {
197+
super(name);
198+
PopupMenu menu = popupMenu = new PopupMenu("Popup");
199+
menu.add(new MenuItem("item 1"));
200+
menu.add(new MenuItem("item 2"));
201+
menu.add(new MenuItem("item 3"));
202+
this.add(menu);
203+
this.name = name;
204+
addMouseListener(this);
205+
addMouseMotionListener(this);
206+
addKeyListener(this);
207+
addFocusListener(this);
208+
}
209+
210+
void println(String messageIn) {
211+
PassFailJFrame.log(messageIn);
212+
}
213+
214+
public void mouseClicked(MouseEvent event) {
215+
/*
216+
popupMenu.show(this, event.getX(), event.getY());
217+
*/
218+
}
219+
public void mousePressed(MouseEvent event) {
220+
println("TestHeavyButton.mousePressed() called !!");
221+
popupMenu.show(this, event.getX(), event.getY());
222+
}
223+
public void mouseReleased(MouseEvent event) {
224+
println("TestHeavyButton.mouseReleased() called !!");
225+
}
226+
public void mouseEntered(MouseEvent event) {
227+
println("TestHeavyButton.mouseEntered() called !!");
228+
requestFocus();
229+
}
230+
public void mouseExited(MouseEvent event) {
231+
}
232+
233+
public void mouseDragged(MouseEvent event) {
234+
println("TestHeavyButton.mouseDragged() called !!");
235+
}
236+
public void mouseMoved(MouseEvent event) {
237+
println("TestHeavyButton.mouseMoved() called !!");
238+
}
239+
240+
public void keyPressed(KeyEvent event) {
241+
println("TestHeavyButton.keyPressed() called !!");
242+
}
243+
public void keyReleased(KeyEvent event) {
244+
println("TestHeavyButton.keyReleased() called !!");
245+
}
246+
public void keyTyped(KeyEvent event) {
247+
println("TestHeavyButton.keyTyped() called !!");
248+
}
249+
250+
public void focusGained(FocusEvent e){
251+
println("TestHeavyButton.focusGained():" + e);
252+
}
253+
public void focusLost(FocusEvent e){
254+
println("TestHeavyButton.focusLost():" + e);
255+
}
256+
257+
}
258+
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright (c) 2004, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
/*
24+
* @test
25+
* @bug 6180413 6184485 6267144
26+
* @summary test for popup menu visual bugs in XAWT
27+
* @library /java/awt/regtesthelpers
28+
* @build PassFailJFrame
29+
* @run main/manual PopupMenuVisuals
30+
*/
31+
32+
import java.awt.Button;
33+
import java.awt.CheckboxMenuItem;
34+
import java.awt.Frame;
35+
import java.awt.Menu;
36+
import java.awt.MenuItem;
37+
import java.awt.MenuShortcut;
38+
import java.awt.PopupMenu;
39+
import java.awt.event.ActionEvent;
40+
import java.awt.event.ActionListener;
41+
import java.awt.event.KeyEvent;
42+
43+
public class PopupMenuVisuals {
44+
private static final String INSTRUCTIONS = """
45+
This test should show a button 'Popup'.
46+
Click on the button. A popup menu should be shown.
47+
If following conditions are met:
48+
- Menu is disabled
49+
- Menu has caption 'Popup menu' (only applicable for linux)
50+
- Menu items don't show shortcuts
51+
52+
Click Pass else click Fail.""";
53+
54+
static PopupMenu pm;
55+
static Frame frame;
56+
57+
public static void main(String[] args) throws Exception {
58+
PassFailJFrame.builder()
59+
.title("PopupMenu Instructions")
60+
.instructions(INSTRUCTIONS)
61+
.rows((int) INSTRUCTIONS.lines().count() + 2)
62+
.columns(35)
63+
.testUI(PopupMenuVisuals::createTestUI)
64+
.build()
65+
.awaitAndCheck();
66+
}
67+
68+
static class Listener implements ActionListener {
69+
public void actionPerformed(ActionEvent e) {
70+
pm.show(frame, 0, 0);
71+
}
72+
}
73+
74+
private static Frame createTestUI() {
75+
Button b = new Button("Popup");
76+
pm = new PopupMenu("Popup menu");
77+
MenuItem mi1 = new MenuItem("Item 1");
78+
CheckboxMenuItem mi2 = new CheckboxMenuItem("Item 2");
79+
CheckboxMenuItem mi3 = new CheckboxMenuItem("Item 3");
80+
Menu sm = new Menu("Submenu");
81+
82+
//Get things going. Request focus, set size, et cetera
83+
frame = new Frame("PopupMenuVisuals");
84+
frame.setSize (200,200);
85+
frame.validate();
86+
87+
frame.add(b);
88+
b.addActionListener(new Listener());
89+
mi1.setShortcut(new MenuShortcut(KeyEvent.VK_A));
90+
pm.add(mi1);
91+
pm.add(mi2);
92+
pm.add(mi3);
93+
pm.add(sm);
94+
sm.add(new MenuItem("Item"));
95+
pm.setEnabled(false);
96+
mi3.setState(true);
97+
frame.add(pm);
98+
return frame;
99+
}
100+
101+
}

0 commit comments

Comments
 (0)