Skip to content

Commit a2391a9

Browse files
author
Alisen Chung
committedSep 23, 2023
8316053: Open some swing tests 3
Reviewed-by: dnguyen, prr
1 parent d2d7d9a commit a2391a9

File tree

4 files changed

+415
-0
lines changed

4 files changed

+415
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2003, 2023, 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 4859570
27+
* @summary SwingUtilities.sharedOwnerFrame is never disposed
28+
* @key headful
29+
*/
30+
31+
import java.awt.Robot;
32+
import java.awt.Window;
33+
import javax.swing.JDialog;
34+
import javax.swing.SwingUtilities;
35+
36+
public class bug4859570 {
37+
static Window owner;
38+
39+
public static void main(String[] args) throws Exception {
40+
SwingUtilities.invokeAndWait(() -> {
41+
JDialog dialog = new JDialog();
42+
dialog.setTitle("bug4859570");
43+
dialog.setBounds(100, 100, 100, 100);
44+
dialog.setVisible(true);
45+
46+
owner = dialog.getOwner();
47+
dialog.dispose();
48+
});
49+
50+
Robot r = new Robot();
51+
r.waitForIdle();
52+
r.delay(1000);
53+
54+
SwingUtilities.invokeAndWait(() -> {
55+
if (owner.isDisplayable()) {
56+
throw new RuntimeException("The shared owner frame should be disposed.");
57+
}
58+
});
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2003, 2023, 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 4936652
27+
* @key headful
28+
* @summary JDialog.setVisible, JDialog.dispose works incorrectly
29+
*/
30+
31+
import javax.swing.JDialog;
32+
import javax.swing.SwingUtilities;
33+
34+
public class bug4936652 {
35+
public static void main(String[] args) throws Exception {
36+
SwingUtilities.invokeAndWait(() -> {
37+
for (int i = 0 ; i < 100; i++) {
38+
System.out.println("i: " + i);
39+
JDialog o = new JDialog();
40+
o.setTitle("bug4936652");
41+
o.setVisible(true);
42+
o.setVisible(false);
43+
o.dispose();
44+
}
45+
});
46+
}
47+
}
+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* Copyright (c) 2002, 2023, 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 4768127
27+
* @summary ToolTipManager not removed from components
28+
* @key headful
29+
*/
30+
31+
import java.awt.Point;
32+
import java.awt.Rectangle;
33+
import java.awt.Robot;
34+
import java.awt.event.InputEvent;
35+
import java.awt.event.MouseMotionListener;
36+
import javax.swing.JDesktopPane;
37+
import javax.swing.JFrame;
38+
import javax.swing.JInternalFrame;
39+
import javax.swing.JLabel;
40+
import javax.swing.SwingUtilities;
41+
import javax.swing.ToolTipManager;
42+
43+
public class bug4768127 {
44+
static JFrame fr;
45+
static volatile Point p;
46+
static volatile JLabel[] label = new JLabel[2];
47+
48+
public static void main(String[] args) throws Exception {
49+
try {
50+
SwingUtilities.invokeAndWait(() -> {
51+
fr = new JFrame("bug4768127");
52+
53+
JDesktopPane jdp = new JDesktopPane();
54+
JInternalFrame jif1 = new JInternalFrame("jif 1");
55+
JInternalFrame jif2 = new JInternalFrame("jif 2");
56+
label[0] = new JLabel("Label 1");
57+
label[1] = new JLabel("Label 2");
58+
59+
label[0].setToolTipText("tooltip 1");
60+
jif1.getContentPane().add(label[0]);
61+
jif1.setBounds(0, 0, 130, 160);
62+
jif1.setVisible(true);
63+
jdp.add(jif1);
64+
65+
label[1].setToolTipText("tooltip 2");
66+
jif2.getContentPane().add(label[1]);
67+
jif2.setBounds(210, 0, 130, 220);
68+
jif2.setVisible(true);
69+
jdp.add(jif2);
70+
71+
fr.getContentPane().add(jdp);
72+
fr.setLocationRelativeTo(null);
73+
74+
fr.setSize(400, 300);
75+
fr.setVisible(true);
76+
});
77+
78+
Robot robot = new Robot();
79+
robot.setAutoDelay(10);
80+
robot.waitForIdle();
81+
robot.delay(3000);
82+
83+
clickLabel(0, robot);
84+
robot.waitForIdle();
85+
robot.delay(3000);
86+
87+
clickLabel(1, robot);
88+
robot.waitForIdle();
89+
robot.delay(3000);
90+
91+
clickLabel(0, robot);
92+
robot.waitForIdle();
93+
robot.delay(3000);
94+
95+
clickLabel(1, robot);
96+
robot.waitForIdle();
97+
robot.delay(3000);
98+
99+
MouseMotionListener[] mml = label[0].getMouseMotionListeners();
100+
if (mml.length > 0 && mml[0] instanceof ToolTipManager) {
101+
throw new RuntimeException("Extra MouseMotionListeners were added to the label \"Label 1\" by ToolTipManager");
102+
}
103+
} finally {
104+
SwingUtilities.invokeAndWait(() -> {
105+
if (fr != null) {
106+
fr.dispose();
107+
}
108+
});
109+
}
110+
}
111+
112+
static void clickLabel(int i, Robot robot) throws Exception {
113+
SwingUtilities.invokeAndWait(() -> {
114+
p = label[i].getLocationOnScreen();
115+
});
116+
final Rectangle rect = label[i].getBounds();
117+
robot.mouseMove(p.x + rect.width / 2, p.y + rect.height / 2);
118+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
119+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
120+
121+
//Generate mouseMotionEvent
122+
robot.mouseMove(p.x + rect.width / 2 + 3, p.y + rect.height / 2 + 3);
123+
robot.mouseMove(p.x + rect.width / 2, p.y + rect.height / 2);
124+
}
125+
}

0 commit comments

Comments
 (0)
Failed to load comments.