Skip to content

Commit 22f8bba

Browse files
author
duke
committed
Backport 97ee8bbda2c7d7f76866690a34a5021fade2f438
1 parent f39ce94 commit 22f8bba

File tree

5 files changed

+764
-0
lines changed

5 files changed

+764
-0
lines changed

test/jdk/ProblemList.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ java/awt/Focus/ToFrontFocusTest/ToFrontFocus.java 7156130 linux-all
136136
java/awt/Focus/WrongKeyTypedConsumedTest/WrongKeyTypedConsumedTest.java 8169096 macosx-all
137137
java/awt/event/KeyEvent/CorrectTime/CorrectTime.java 6626492 generic-all
138138
java/awt/EventQueue/6980209/bug6980209.java 8198615 macosx-all
139+
java/awt/EventQueue/PushPopDeadlock/PushPopDeadlock.java 8024034 generic-all
139140
java/awt/grab/EmbeddedFrameTest1/EmbeddedFrameTest1.java 7080150 macosx-all
140141
java/awt/event/InputEvent/EventWhenTest/EventWhenTest.java 8168646 generic-all
141142
java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.java 8198626 macosx-all
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 1999, 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+
/*
25+
* @test
26+
* @bug 4212687
27+
* @summary Verifies that calling EventQueue.push() and EventQueue.pop()
28+
* does not deadlock.
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual PushPopDeadlock
32+
*/
33+
34+
import java.awt.EventQueue;
35+
import java.awt.Frame;
36+
import java.awt.Label;
37+
import java.awt.Robot;
38+
import java.awt.Toolkit;
39+
40+
public class PushPopDeadlock {
41+
static int counter = 0;
42+
static Robot robot;
43+
static Frame f;
44+
static Label l;
45+
46+
public static void main(String[] args) throws Exception {
47+
robot = new Robot();
48+
String INSTRUCTIONS = """
49+
Click rapidly in the Frame labeled 'Click Here!'.
50+
The number in the Frame should continue to increase. If the number
51+
stops increasing (remains at a constant value), the test fails.
52+
""";
53+
54+
PassFailJFrame pfJFrame = PassFailJFrame.builder()
55+
.title("Test Instructions")
56+
.instructions(INSTRUCTIONS)
57+
.rows((int) INSTRUCTIONS.lines().count() + 2)
58+
.columns(35)
59+
.testUI(PushPopDeadlock::createUI)
60+
.build();
61+
PushPopDeadlock.test();
62+
pfJFrame.awaitAndCheck();
63+
}
64+
65+
public static Frame createUI() {
66+
f = new Frame("Click Here!");
67+
l = new Label("Counter: " + counter);
68+
f.add(l);
69+
f.setSize(200, 200);
70+
return f;
71+
}
72+
73+
public static void test() {
74+
EventQueue q = new EventQueue() {
75+
public void push(EventQueue queue) {
76+
super.push(queue);
77+
pop();
78+
}
79+
};
80+
EventQueue q2 = new EventQueue();
81+
82+
Toolkit.getDefaultToolkit().getSystemEventQueue().push(q);
83+
84+
new Thread(() -> {
85+
while (true) {
86+
robot.delay(500);
87+
l.setText("Counter: " + ++counter);
88+
q.push(q2);
89+
try {
90+
Thread.currentThread().sleep(500);
91+
} catch (InterruptedException e) {
92+
return;
93+
}
94+
}
95+
}).start();
96+
}
97+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright (c) 1999, 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+
/*
25+
* @test
26+
* @bug 4058400
27+
* @summary Tests that calling addNotify on a lightweight component more than
28+
* once does not break event dispatching for that component.
29+
* @key headful
30+
* @run main MultipleAddNotifyTest
31+
*/
32+
33+
import java.awt.Color;
34+
import java.awt.Component;
35+
import java.awt.Dimension;
36+
import java.awt.EventQueue;
37+
import java.awt.FlowLayout;
38+
import java.awt.Frame;
39+
import java.awt.Graphics;
40+
import java.awt.Robot;
41+
import java.awt.event.InputEvent;
42+
import java.awt.event.MouseAdapter;
43+
import java.awt.event.MouseEvent;
44+
45+
public class MultipleAddNotifyTest {
46+
static volatile boolean passFlag;
47+
static volatile int posX;
48+
static volatile int posY;
49+
static Frame f;
50+
static LightComponent l;
51+
52+
public static void main(String[] args) throws Exception {
53+
Robot r;
54+
try {
55+
r = new Robot();
56+
r.setAutoWaitForIdle(true);
57+
passFlag = false;
58+
59+
EventQueue.invokeAndWait(() -> {
60+
f = new Frame("Multiple addNotify Test");
61+
l = new LightComponent();
62+
f.setLayout(new FlowLayout());
63+
l.addMouseListener(new MouseAdapter() {
64+
@Override
65+
public void mouseClicked(MouseEvent e) {
66+
System.out.println("Mouse Clicked");
67+
passFlag = true;
68+
}
69+
});
70+
f.add(l);
71+
f.addNotify();
72+
f.addNotify();
73+
74+
if (!l.isVisible()) {
75+
throw new RuntimeException("Test failed. LW Component " +
76+
"not visible.");
77+
}
78+
f.setSize(200, 200);
79+
f.setLocationRelativeTo(null);
80+
f.setVisible(true);
81+
});
82+
r.waitForIdle();
83+
r.delay(1000);
84+
85+
EventQueue.invokeAndWait(() -> {
86+
posX = f.getX() + l.getWidth() + (l.getWidth() / 2);
87+
posY = f.getY() + l.getHeight();
88+
});
89+
90+
r.mouseMove(posX, posY);
91+
r.delay(500);
92+
93+
r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
94+
r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
95+
r.delay(500);
96+
97+
if (!passFlag) {
98+
throw new RuntimeException("Test failed. MouseClicked event " +
99+
"not working properly.");
100+
}
101+
} finally {
102+
EventQueue.invokeAndWait(() -> {
103+
if (f != null) {
104+
f.dispose();
105+
}
106+
});
107+
}
108+
}
109+
}
110+
111+
class LightComponent extends Component {
112+
public void paint(Graphics g) {
113+
setSize(100, 100);
114+
Dimension d = getSize();
115+
g.setColor(Color.red);
116+
g.fillRect(0, 0, d.width, d.height);
117+
}
118+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (c) 2001, 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+
/*
25+
* @test
26+
* @bug 4476083
27+
* @summary Disabled components do not receive MouseEvent in Popups
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual PopupTest
31+
*/
32+
33+
import java.awt.BorderLayout;
34+
import java.awt.Component;
35+
import java.awt.Frame;
36+
37+
import javax.swing.JButton;
38+
import javax.swing.JLabel;
39+
import javax.swing.JMenuItem;
40+
import javax.swing.JPopupMenu;
41+
42+
public class PopupTest {
43+
public static void main(String[] args) throws Exception {
44+
String INSTRUCTIONS = """
45+
PopupMenus should disappear when a disabled component is
46+
clicked.
47+
48+
Step 1. Pop down the popup menu by clicking on it.
49+
Step 2. Click on the disabled component to make the menu
50+
disappear.
51+
52+
If the menu disappears when the disabled component is clicked,
53+
the test passes, otherwise, the test fails.
54+
""";
55+
56+
PassFailJFrame.builder()
57+
.title("Test Instructions")
58+
.instructions(INSTRUCTIONS)
59+
.columns(35)
60+
.testUI(PopupTest::createUI)
61+
.build()
62+
.awaitAndCheck();
63+
}
64+
65+
private static Frame createUI() {
66+
Frame f = new Frame("Disabled Component in Popup Test");
67+
f.setLayout(new BorderLayout());
68+
69+
JButton b = new JButton("step 1: press me to display menu");
70+
b.addActionListener(e -> {
71+
JPopupMenu m = new JPopupMenu();
72+
m.add(new JMenuItem("item 1"));
73+
m.add(new JMenuItem("item 2"));
74+
m.add(new JMenuItem("item 3"));
75+
m.add(new JMenuItem("item 4"));
76+
m.add(new JMenuItem("item 5"));
77+
m.add(new JMenuItem("item 6"));
78+
m.show((Component) e.getSource(), 0, 10);
79+
});
80+
81+
JLabel disabled = new JLabel("step 2: click me. the menu should be " +
82+
"dismissed");
83+
disabled.setEnabled(false);
84+
85+
JLabel enabled = new JLabel("step 3: there is no step 3");
86+
87+
f.add(BorderLayout.NORTH, b);
88+
f.add(BorderLayout.CENTER, disabled);
89+
f.add(BorderLayout.SOUTH, enabled);
90+
f.setSize(300, 200);
91+
return f;
92+
}
93+
}

0 commit comments

Comments
 (0)