Skip to content

Commit 3f355fc

Browse files
committed
8340437: Open source few more AWT Frame related tests
Backport-of: 9bd478593cc92a716151d1373f3426f1d92143bb
1 parent 8197db4 commit 3f355fc

File tree

4 files changed

+771
-0
lines changed

4 files changed

+771
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
import java.awt.BorderLayout;
25+
import java.awt.Button;
26+
import java.awt.Dimension;
27+
import java.awt.EventQueue;
28+
import java.awt.Frame;
29+
import java.awt.Point;
30+
import java.awt.Robot;
31+
import java.awt.Window;
32+
import java.awt.event.InputEvent;
33+
import java.awt.event.MouseAdapter;
34+
import java.awt.event.MouseEvent;
35+
36+
/*
37+
* @test
38+
* @bug 5062118
39+
* @key headful
40+
* @summary Disabling of a parent should not disable Window.
41+
* @run main DisabledParentOfToplevel
42+
*/
43+
44+
public class DisabledParentOfToplevel {
45+
private static Button okBtn;
46+
private static Window ww;
47+
private static Frame parentFrame;
48+
private static volatile Point p;
49+
private static volatile Dimension d;
50+
51+
public static void main(String[] args) throws Exception {
52+
Robot robot = new Robot();
53+
robot.setAutoDelay(100);
54+
try {
55+
EventQueue.invokeAndWait(() -> {
56+
createAndShowUI();
57+
});
58+
robot.delay(1000);
59+
EventQueue.invokeAndWait(() -> {
60+
p = okBtn.getLocationOnScreen();
61+
d = okBtn.getSize();
62+
});
63+
robot.mouseMove(p.x + d.width / 2, p.x + d.height / 2);
64+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
65+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
66+
robot.delay(500);
67+
if (ww.isVisible()) {
68+
throw new RuntimeException("Window is visible but should be hidden: failure.");
69+
}
70+
} finally {
71+
EventQueue.invokeAndWait(() -> {
72+
if (parentFrame != null) {
73+
parentFrame.dispose();
74+
}
75+
});
76+
}
77+
}
78+
79+
private static void createAndShowUI() {
80+
parentFrame = new Frame("parentFrame");
81+
parentFrame.setSize(100, 100);
82+
parentFrame.setEnabled(false);
83+
ww = new Window(parentFrame);
84+
ww.setLayout(new BorderLayout());
85+
okBtn = new Button("Click to Close Me");
86+
ww.add(okBtn);
87+
ww.setSize(250, 250);
88+
ww.setLocation(110, 110);
89+
okBtn.addMouseListener(new MouseAdapter() {
90+
public void mousePressed(MouseEvent me) {
91+
System.out.println("Pressed: close");
92+
ww.setVisible(false);
93+
}
94+
});
95+
parentFrame.setVisible(true);
96+
ww.setVisible(true);
97+
okBtn.requestFocus();
98+
}
99+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright (c) 2002, 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+
import java.awt.Color;
25+
import java.awt.Dimension;
26+
import java.awt.EventQueue;
27+
import java.awt.Frame;
28+
import java.awt.GraphicsConfiguration;
29+
import java.awt.GraphicsEnvironment;
30+
import java.awt.Point;
31+
import java.awt.Rectangle;
32+
import java.awt.Robot;
33+
import java.awt.image.BufferedImage;
34+
import java.io.File;
35+
import java.io.IOException;
36+
import javax.imageio.ImageIO;
37+
38+
/*
39+
* @test
40+
* @bug 4328588
41+
* @key headful
42+
* @summary Non-default visual on top-level Frame should work
43+
* @run main FrameVisualTest
44+
*/
45+
46+
public class FrameVisualTest {
47+
private static GraphicsConfiguration[] gcs;
48+
private static volatile Frame[] frames;
49+
private static volatile int index;
50+
51+
private static Frame f;
52+
private static Robot robot;
53+
private static volatile Point p;
54+
private static volatile Dimension d;
55+
private static final int TOLERANCE = 5;
56+
57+
public static void main(String[] args) throws Exception {
58+
gcs = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getConfigurations();
59+
robot = new Robot();
60+
robot.setAutoDelay(100);
61+
try {
62+
EventQueue.invokeAndWait(() -> {
63+
createAndShowUI();
64+
});
65+
robot.delay(1000);
66+
System.out.println("frames.length: "+frames.length);
67+
for (index = 0; index < frames.length; index++) {
68+
EventQueue.invokeAndWait(() -> {
69+
p = frames[index].getLocation();
70+
d = frames[index].getSize();
71+
});
72+
Rectangle rect = new Rectangle(p, d);
73+
BufferedImage img = robot.createScreenCapture(rect);
74+
if (chkImgBackgroundColor(img)) {
75+
try {
76+
ImageIO.write(img, "png", new File("Frame_" + index + ".png"));
77+
} catch (IOException ignored) {}
78+
throw new RuntimeException("Frame visual test failed with non-white background color");
79+
}
80+
}
81+
} finally {
82+
for (index = 0; index < frames.length; index++) {
83+
EventQueue.invokeAndWait(() -> {
84+
if (frames[index] != null) {
85+
frames[index].dispose();
86+
}
87+
});
88+
}
89+
}
90+
}
91+
92+
private static void createAndShowUI() {
93+
frames = new Frame[gcs.length];
94+
for (int i = 0; i < frames.length; i++) {
95+
frames[i] = new Frame("Frame w/ gc " + i, gcs[i]);
96+
frames[i].setSize(100, 100);
97+
frames[i].setUndecorated(true);
98+
frames[i].setBackground(Color.WHITE);
99+
frames[i].setVisible(true);
100+
}
101+
}
102+
103+
private static boolean chkImgBackgroundColor(BufferedImage img) {
104+
105+
// scan for mid-line and if it is non-white color then return true.
106+
for (int x = 1; x < img.getWidth() - 1; ++x) {
107+
Color c = new Color(img.getRGB(x, img.getHeight() / 2));
108+
if ((c.getRed() - Color.WHITE.getRed()) > TOLERANCE &&
109+
(c.getGreen() - Color.WHITE.getGreen()) > TOLERANCE &&
110+
(c.getBlue() - Color.WHITE.getBlue()) > TOLERANCE) {
111+
return true;
112+
}
113+
}
114+
return false;
115+
}
116+
}
117+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
import java.awt.BorderLayout;
25+
import java.awt.Frame;
26+
import java.awt.Label;
27+
import java.awt.Panel;
28+
import java.awt.TextField;
29+
30+
/*
31+
* @test
32+
* @bug 4113040
33+
* @library /java/awt/regtesthelpers
34+
* @build PassFailJFrame
35+
* @summary Checks that IMStatusBar does not affect Frame layout
36+
* @run main/manual/othervm -Duser.language=ja -Duser.country=JP IMStatusBar
37+
*/
38+
39+
public class IMStatusBar {
40+
41+
public static void main(String[] args) throws Exception {
42+
String INSTRUCTIONS = """
43+
If the window appears the right size, but then resizes so that the
44+
status field overlaps the bottom label, press Fail; otherwise press Pass.
45+
""";
46+
47+
PassFailJFrame.builder()
48+
.title("IMStatusBar Instruction")
49+
.instructions(INSTRUCTIONS)
50+
.rows((int) INSTRUCTIONS.lines().count() + 2)
51+
.columns(40)
52+
.testUI(IMStatusBar::createUI)
53+
.build()
54+
.awaitAndCheck();
55+
}
56+
57+
private static Frame createUI() {
58+
Frame f = new Frame();
59+
Panel centerPanel = new Panel();
60+
f.setSize(200, 200);
61+
f.setLayout(new BorderLayout());
62+
f.add(new Label("Top"), BorderLayout.NORTH);
63+
f.add(centerPanel, BorderLayout.CENTER);
64+
f.add(new Label("Bottom"), BorderLayout.SOUTH);
65+
centerPanel.setLayout(new BorderLayout());
66+
centerPanel.add(new TextField("Middle"), BorderLayout.CENTER);
67+
centerPanel.validate();
68+
return f;
69+
}
70+
}

0 commit comments

Comments
 (0)