Skip to content

Commit e2385eb

Browse files
committed
8340687: Open source closed frame tests #1
Backport-of: 47fcf5a
1 parent 4e0c9ee commit e2385eb

File tree

4 files changed

+458
-0
lines changed

4 files changed

+458
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
import java.awt.Dialog;
25+
import java.awt.Frame;
26+
import java.awt.Window;
27+
import java.util.List;
28+
29+
/*
30+
* @test
31+
* @bug 4240766 8259023
32+
* @summary Frame Icon is wrong - should be Coffee Cup or Duke image icon
33+
* @requires (os.family == "windows")
34+
* @library /java/awt/regtesthelpers
35+
* @build PassFailJFrame
36+
* @run main/manual DefaultFrameIconTest
37+
*/
38+
39+
public class DefaultFrameIconTest {
40+
41+
private static final String INSTRUCTIONS = """
42+
You should see a dialog and a frame.
43+
If both have Coffee Cup or Duke image icon in the upper left corner,
44+
the test passes, otherwise it fails.
45+
""";
46+
47+
public static void main(String[] args) throws Exception {
48+
PassFailJFrame.builder()
49+
.title("DefaultFrameIconTest Instructions")
50+
.instructions(INSTRUCTIONS)
51+
.columns(45)
52+
.testUI(DefaultFrameIconTest::createAndShowUI)
53+
.positionTestUI(DefaultFrameIconTest::positionTestWindows)
54+
.build()
55+
.awaitAndCheck();
56+
}
57+
58+
private static void positionTestWindows(List<? extends Window> testWindows,
59+
PassFailJFrame.InstructionUI instructionUI) {
60+
int gap = 5;
61+
int x = instructionUI.getLocation().x + instructionUI.getSize().width + gap;
62+
for (Window w : testWindows) {
63+
w.setLocation(x, instructionUI.getLocation().y);
64+
x += w.getWidth() + gap;
65+
}
66+
}
67+
68+
private static List<Window> createAndShowUI() {
69+
Frame testFrame = new Frame("Frame DefaultFrameIconTest");
70+
Dialog testDialog = new Dialog(testFrame, "Dialog DefaultFrameIconTest");
71+
72+
testDialog.setSize(250, 100);
73+
74+
testFrame.setSize(250, 100);
75+
return List.of(testFrame, testDialog);
76+
}
77+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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 javax.imageio.ImageIO;
25+
import java.awt.Color;
26+
import java.awt.EventQueue;
27+
import java.awt.Frame;
28+
import java.awt.Menu;
29+
import java.awt.MenuBar;
30+
import java.awt.Rectangle;
31+
import java.awt.Robot;
32+
import java.awt.image.BufferedImage;
33+
import java.io.File;
34+
import java.io.IOException;
35+
36+
/*
37+
* @test
38+
* @key headful
39+
* @bug 4127271
40+
* @summary Tests that disposing of a Frame with MenuBar removes all traces
41+
* of the Frame from the screen.
42+
*/
43+
44+
public class DisposeTest {
45+
private static Frame backgroundFrame;
46+
private static Frame testedFrame;
47+
48+
private static final Rectangle backgroundFrameBounds =
49+
new Rectangle(100, 100, 200, 200);
50+
private static final Rectangle testedFrameBounds =
51+
new Rectangle(150, 150, 100, 100);
52+
53+
private static Robot robot;
54+
55+
public static void main(String[] args) throws Exception {
56+
robot = new Robot();
57+
try {
58+
EventQueue.invokeAndWait(DisposeTest::initAndShowGui);
59+
robot.waitForIdle();
60+
robot.delay(500);
61+
EventQueue.invokeAndWait(testedFrame::dispose);
62+
robot.waitForIdle();
63+
robot.delay(500);
64+
test();
65+
} finally {
66+
EventQueue.invokeAndWait(() -> {
67+
backgroundFrame.dispose();
68+
testedFrame.dispose();
69+
});
70+
}
71+
}
72+
73+
private static void test() {
74+
BufferedImage bi = robot.createScreenCapture(backgroundFrameBounds);
75+
int redPix = Color.RED.getRGB();
76+
77+
for (int x = 0; x < bi.getWidth(); x++) {
78+
for (int y = 0; y < bi.getHeight(); y++) {
79+
if (bi.getRGB(x, y) != redPix) {
80+
try {
81+
ImageIO.write(bi, "png",
82+
new File("failure.png"));
83+
} catch (IOException ignored) {}
84+
throw new RuntimeException("Test failed");
85+
}
86+
}
87+
}
88+
}
89+
90+
private static void initAndShowGui() {
91+
backgroundFrame = new Frame("DisposeTest background");
92+
backgroundFrame.setUndecorated(true);
93+
backgroundFrame.setBackground(Color.RED);
94+
backgroundFrame.setBounds(backgroundFrameBounds);
95+
backgroundFrame.setVisible(true);
96+
97+
testedFrame = new UglyFrame();
98+
}
99+
100+
static class UglyFrame extends Frame {
101+
public UglyFrame() {
102+
super("DisposeTest");
103+
MenuBar mb = new MenuBar();
104+
Menu m = new Menu("menu");
105+
mb.add(m);
106+
setMenuBar(mb);
107+
setBounds(testedFrameBounds);
108+
setVisible(true);
109+
}
110+
}
111+
}
112+
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
import java.awt.Color;
26+
import java.awt.Component;
27+
import java.awt.Dimension;
28+
import java.awt.FlowLayout;
29+
import java.awt.Frame;
30+
import java.awt.Graphics;
31+
32+
/*
33+
* @test
34+
* @bug 4023385
35+
* @summary resizing a frame causes too many repaints
36+
* @library /java/awt/regtesthelpers
37+
* @build PassFailJFrame
38+
* @run main/manual FramePaintTest
39+
*/
40+
41+
public class FramePaintTest {
42+
private static final String INSTRUCTIONS = """
43+
You should see a Frame titled "Repaint Test", filled with colored blocks.
44+
45+
Resize the frame several times, both inward as well as outward.
46+
47+
The blocks should move to fill the window without any flashes or
48+
glitches which ensures that repaint is not done excessively
49+
""";
50+
51+
public static void main(String[] args) throws Exception {
52+
PassFailJFrame.builder()
53+
.title("FramePaintTest Instructions")
54+
.instructions(INSTRUCTIONS)
55+
.columns(45)
56+
.testUI(ResizeLW::new)
57+
.build()
58+
.awaitAndCheck();
59+
}
60+
61+
static class ResizeLW extends Frame {
62+
63+
public ResizeLW() {
64+
super("Repaint Test");
65+
setBackground(Color.red);
66+
setLayout(new FlowLayout());
67+
setSize(300, 300);
68+
69+
for (int i = 0; i < 10; i++) {
70+
add(new ColorComp(Color.blue));
71+
add(new ColorComp(Color.green));
72+
}
73+
}
74+
75+
private static class ColorComp extends Component {
76+
public ColorComp(Color c) {
77+
super();
78+
setBackground(c);
79+
}
80+
81+
public void paint(Graphics g) {
82+
g.setColor(getBackground());
83+
g.fillRect(0, 0, getWidth(), getHeight());
84+
}
85+
86+
public Dimension getPreferredSize() {
87+
return new Dimension(50, 50);
88+
}
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)