Skip to content

Commit 2d49408

Browse files
committed
8340271: Open source several AWT Robot tests
Backport-of: bc36ace72c1189dcd6d0c05d40d8c568acd89b01
1 parent ddf0d07 commit 2d49408

File tree

2 files changed

+182
-0
lines changed

2 files changed

+182
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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 4292503
27+
* @summary OutOfMemoryError with lots of Robot.createScreenCapture
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @requires (os.family == "linux")
31+
* @run main/manual CreateScreenCapture
32+
*/
33+
34+
import java.awt.Dialog;
35+
import java.awt.Frame;
36+
import java.awt.Image;
37+
import java.awt.Rectangle;
38+
import java.awt.Robot;
39+
import java.awt.TextArea;
40+
41+
public class CreateScreenCapture {
42+
43+
static TextArea messageText;
44+
45+
private static final String INSTRUCTIONS = """
46+
This test is linux only!
47+
Once you see these instructions, run 'top' program.
48+
Watch for java process.
49+
The memory size used by this process should stop growing after several steps.
50+
Numbers of steps test is performing are displayed in output window.
51+
After 5-7 steps the size taken by the process should become stable.
52+
If this happens, then test passed otherwise test failed.
53+
54+
Small oscillations of the memory size are, however, acceptable.""";
55+
56+
public static void main(String[] args) throws Exception {
57+
Robot robot = new Robot();
58+
PassFailJFrame passFail = new PassFailJFrame(INSTRUCTIONS);
59+
Dialog dialog = new Dialog(new Frame(), "Instructions");
60+
messageText = new TextArea("", 5, 80, TextArea.SCROLLBARS_BOTH);
61+
dialog.add(messageText);
62+
PassFailJFrame.addTestWindow(dialog);
63+
PassFailJFrame.positionTestWindow(dialog, PassFailJFrame.Position.HORIZONTAL);
64+
dialog.setSize(200, 300);
65+
dialog.setVisible(true);
66+
Rectangle rect = new Rectangle(0, 0, 1000, 1000);
67+
for (int i = 0; i < 100; i++) {
68+
Image image = robot.createScreenCapture(rect);
69+
image.flush();
70+
image = null;
71+
robot.delay(200);
72+
log("step #" + i);
73+
}
74+
passFail.awaitAndCheck();
75+
}
76+
77+
private static void log(String messageIn) {
78+
messageText.append(messageIn + "\n");
79+
}
80+
}
81+
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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 4374578
27+
* @summary Test robot wheel scrolling of Text
28+
* @requires (os.family == "Windows") | (os.family == "linux")
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual RobotScrollTest
32+
*/
33+
34+
import java.awt.Frame;
35+
import java.awt.Point;
36+
import java.awt.Rectangle;
37+
import java.awt.Robot;
38+
import java.awt.TextArea;
39+
40+
public class RobotScrollTest {
41+
42+
static TextArea ta;
43+
static Robot robot;
44+
45+
private static final String INSTRUCTIONS = """
46+
0. DON'T TOUCH ANYTHING!
47+
1. This test is for Windows and Linux only.
48+
2. Just sit back, and watch the Robot move the mouse to the TextArea.
49+
3. Once the pointer is on the text area, the Robot will use the mouse wheel
50+
to scroll the text.
51+
If the text scrolled, press PASS, else, press FAIL.""";
52+
53+
public static void main(String[] args) throws Exception {
54+
robot = new Robot();
55+
robot.setAutoDelay(100);
56+
PassFailJFrame passFail = new PassFailJFrame(INSTRUCTIONS);
57+
createTestUI();
58+
passFail.awaitAndCheck();
59+
}
60+
61+
private static void createTestUI() {
62+
Frame f = new Frame("RobotScrollTest");
63+
ta = new TextArea();
64+
for (int i = 0; i < 100; i++) {
65+
ta.append(i + "\n");
66+
}
67+
f.add(ta);
68+
f.setLocation(0, 400);
69+
f.pack();
70+
PassFailJFrame.addTestWindow(f);
71+
PassFailJFrame.positionTestWindow(f, PassFailJFrame.Position.HORIZONTAL);
72+
f.setVisible(true);
73+
doTest();
74+
}
75+
76+
private static void doTest() {
77+
robot.waitForIdle();
78+
robot.delay(1000);
79+
// get loc of TextArea
80+
Point taAt = ta.getLocationOnScreen();
81+
// get bounds of button
82+
Rectangle bounds = ta.getBounds();
83+
84+
// move mouse to middle of button
85+
robot.mouseMove(taAt.x + bounds.width / 2,
86+
taAt.y + bounds.height / 2);
87+
88+
// rotate wheel a few times
89+
for (int j = 1; j < 8; j++) {
90+
for (int k = 0; k < 5; k++) {
91+
robot.mouseWheel(j);
92+
}
93+
94+
for (int k = 0; k < 5; k++) {
95+
robot.mouseWheel(-1 * j);
96+
}
97+
}
98+
}
99+
100+
}
101+

0 commit comments

Comments
 (0)