Skip to content

Commit 398f486

Browse files
author
Andrew Lu
committed
8306812: Open source several AWT Miscellaneous tests
Backport-of: c494770ca0662d95ed35f9244a7a9e012aab61a7
1 parent aeb6381 commit 398f486

File tree

5 files changed

+515
-0
lines changed

5 files changed

+515
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2004, 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 4994151
27+
@summary REGRESSION: Bug when setting the foreground of a JWindow
28+
@key headful
29+
*/
30+
31+
import java.awt.EventQueue;
32+
import java.awt.Color;
33+
34+
import javax.swing.JWindow;
35+
36+
public class SetForegroundTest {
37+
static JWindow jwindow;
38+
39+
public static void main(String[] args) throws Exception {
40+
try {
41+
EventQueue.invokeAndWait(() -> {
42+
jwindow = new JWindow();
43+
jwindow.pack();
44+
jwindow.setForeground(Color.BLACK);
45+
System.out.println("TEST PASSED");
46+
});
47+
} finally {
48+
EventQueue.invokeAndWait(() -> {
49+
if (jwindow != null) {
50+
jwindow.dispose();
51+
}
52+
});
53+
}
54+
}
55+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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 4791953
27+
@requires (os.family == "linux" | os.family == "mac")
28+
@summary Checks that popup menu stay open after a triggering click.
29+
@key headful
30+
@run main/othervm -Dsun.java2d.uiScale=1 PopupMenuStayOpen
31+
*/
32+
33+
import java.awt.Component;
34+
import java.awt.EventQueue;
35+
import java.awt.Frame;
36+
import java.awt.Point;
37+
import java.awt.PopupMenu;
38+
import java.awt.Robot;
39+
import java.awt.Toolkit;
40+
41+
import java.awt.event.ActionEvent;
42+
import java.awt.event.ActionListener;
43+
import java.awt.event.MouseAdapter;
44+
import java.awt.event.MouseEvent;
45+
import java.awt.event.InputEvent;
46+
47+
public class PopupMenuStayOpen {
48+
public static final int MAX_COUNT = 100;
49+
public volatile static boolean wasActionFired = false;
50+
static Frame frame;
51+
static PopupMenu pom;
52+
volatile static Point point;
53+
54+
public static void main(String[] args) throws Exception {
55+
56+
String nm = Toolkit.getDefaultToolkit().getClass().getName();
57+
58+
try {
59+
EventQueue.invokeAndWait(() -> {
60+
frame = new Frame("Click-to-see-Popup");
61+
pom = new PopupMenu();
62+
frame.setTitle(nm);
63+
frame.setSize(300, 300);
64+
frame.setLocationRelativeTo(null);
65+
frame.setVisible(true);
66+
pom.add("A long enough line");
67+
68+
pom.getItem(0).addActionListener(new ActionListener() {
69+
public void actionPerformed(ActionEvent ae) {
70+
wasActionFired = true;
71+
}
72+
});
73+
74+
frame.add(pom);
75+
frame.addMouseListener(new MouseAdapter() {
76+
public void mousePressed(MouseEvent me) {
77+
pom.show(frame, me.getX(), me.getY());
78+
}
79+
});
80+
});
81+
82+
Robot robot = new Robot();
83+
robot.delay(1000);
84+
robot.waitForIdle();
85+
86+
EventQueue.invokeAndWait(() -> {
87+
point = frame.getLocationOnScreen();
88+
});
89+
90+
robot.mouseMove(point.x + 50, point.y + 100);
91+
robot.mousePress(InputEvent.BUTTON2_DOWN_MASK);
92+
robot.mouseRelease(InputEvent.BUTTON2_DOWN_MASK);
93+
94+
robot.delay(1000);
95+
robot.waitForIdle();
96+
97+
robot.mouseMove(point.x + 50 + 30, point.y + 100 + 15);
98+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
99+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
100+
robot.delay(500);
101+
102+
103+
if (!wasActionFired) {
104+
throw new RuntimeException("Popup not visible or has no focus");
105+
}
106+
System.out.println("Test Pass!!");
107+
} finally {
108+
EventQueue.invokeAndWait(() -> {
109+
if (frame != null) {
110+
frame.dispose();
111+
}
112+
});
113+
}
114+
}
115+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright (c) 1999, 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 4288230
27+
@summary Tests that Robot can move mouse to another screen
28+
@key headful
29+
*/
30+
31+
import java.awt.EventQueue;
32+
import java.awt.Frame;
33+
import java.awt.GraphicsConfiguration;
34+
import java.awt.GraphicsDevice;
35+
import java.awt.GraphicsEnvironment;
36+
import java.awt.Rectangle;
37+
import java.awt.Robot;
38+
39+
import java.awt.event.MouseEvent;
40+
import java.awt.event.MouseMotionAdapter;
41+
42+
public class RobotMoveMultiscreen {
43+
static volatile int x_dest = 20;
44+
static volatile int y_dest = 20;
45+
static Frame frame;
46+
static volatile Boolean testCondition = false;
47+
48+
public static void main(String[] args) throws Exception {
49+
GraphicsDevice[] devs =
50+
GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
51+
52+
if (devs.length <= 1) {
53+
System.out.println("Minimum 2 display screens are required" +
54+
" for the test, Found " + devs.length);
55+
return;
56+
}
57+
try {
58+
EventQueue.invokeAndWait(() -> {
59+
GraphicsDevice workDev = devs[devs.length - 1];
60+
GraphicsConfiguration config = workDev.getDefaultConfiguration();
61+
Rectangle bounds = config.getBounds();
62+
x_dest = bounds.x + bounds.width / 2;
63+
y_dest = bounds.y + bounds.height / 2;
64+
frame = new Frame("Listening frame");
65+
frame.addMouseMotionListener(new MouseMotionAdapter() {
66+
public void mouseMoved(MouseEvent e) {
67+
testCondition = true;
68+
}
69+
});
70+
frame.setLocation(x_dest,y_dest);
71+
frame.setSize(100,100);
72+
frame.setVisible(true);
73+
});
74+
75+
Robot robot = new Robot();
76+
robot.delay(1000);
77+
robot.waitForIdle();
78+
robot.mouseMove(x_dest+50, y_dest+50);
79+
robot.waitForIdle();
80+
EventQueue.invokeAndWait(() -> {
81+
if (testCondition == false) {
82+
throw new RuntimeException("Can't move to another display");
83+
}
84+
});
85+
86+
System.out.println("Test Pass!!");
87+
} finally {
88+
EventQueue.invokeAndWait(() -> {
89+
if (frame != null) {
90+
frame.dispose();
91+
}
92+
});
93+
}
94+
}
95+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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 4677084
27+
@summary Tests that the PageIncrement (BlockIncrement) and
28+
LineIncrement (UnitIncrement) cannot be < 1
29+
@key headful
30+
*/
31+
32+
import java.awt.Scrollbar;
33+
34+
public class PageIncrementTest {
35+
static Scrollbar sb;
36+
37+
public static void main(String[] args) {
38+
sb = new Scrollbar();
39+
sb.setBlockIncrement(0);
40+
sb.setUnitIncrement(0);
41+
42+
if (sb.getBlockIncrement() < 1) {
43+
String msg = "Failed: getBlockIncrement() == " + sb.getBlockIncrement();
44+
System.out.println(msg);
45+
throw new RuntimeException(msg);
46+
}
47+
if (sb.getUnitIncrement() < 1) {
48+
String msg = "Failed: getLineIncrement() == " + sb.getUnitIncrement();
49+
System.out.println(msg);
50+
throw new RuntimeException(msg);
51+
}
52+
53+
sb.setBlockIncrement(-1);
54+
sb.setUnitIncrement(-1);
55+
56+
if (sb.getBlockIncrement() < 1) {
57+
String msg = "Failed: getBlockIncrement() == " + sb.getBlockIncrement();
58+
System.out.println(msg);
59+
throw new RuntimeException(msg);
60+
}
61+
if (sb.getUnitIncrement() < 1) {
62+
String msg = "Failed: getLineIncrement() == " + sb.getUnitIncrement();
63+
System.out.println(msg);
64+
throw new RuntimeException(msg);
65+
}
66+
67+
sb.setBlockIncrement(2);
68+
sb.setUnitIncrement(2);
69+
70+
if (sb.getBlockIncrement() != 2) {
71+
String msg = "Failed: getBlockIncrement() == " + sb.getBlockIncrement();
72+
System.out.println(msg);
73+
throw new RuntimeException(msg);
74+
}
75+
if (sb.getUnitIncrement() != 2) {
76+
String msg = "Failed: getLineIncrement() == " + sb.getUnitIncrement();
77+
System.out.println(msg);
78+
throw new RuntimeException(msg);
79+
}
80+
System.out.println("Test Pass!!");
81+
}
82+
}

0 commit comments

Comments
 (0)