Skip to content

Commit cdf6286

Browse files
committed
8328753: Open source few Undecorated Frame tests
8337886: java/awt/Frame/MaximizeUndecoratedTest.java fails in OEL due to a slight color difference Backport-of: 539990cd9a7241e7e9d8f5dc1fdf832eb0fa7860
1 parent 816822a commit cdf6286

File tree

3 files changed

+350
-0
lines changed

3 files changed

+350
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright (c) 2000, 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.Button;
25+
import java.awt.Color;
26+
import java.awt.Dialog;
27+
import java.awt.FlowLayout;
28+
import java.awt.Frame;
29+
import java.awt.Point;
30+
31+
/*
32+
* @test
33+
* @bug 4340727
34+
* @summary Tests that undecorated property is set correctly
35+
* when Frames and Dialogs are mixed.
36+
* @library /java/awt/regtesthelpers
37+
* @build PassFailJFrame
38+
* @run main/manual FrameDialogMixedTest
39+
*/
40+
41+
public class FrameDialogMixedTest {
42+
private static final int SIZE = 100;
43+
44+
private static final String INSTRUCTIONS = """
45+
When the test starts, a RED UNDECORATED Frame is seen.
46+
Click on "Create Dialog" button, you should see a GREEN UNDECORATED Dialog.
47+
If both the frame and the dialog are undecorated press PASS otherwise FAIL.""";
48+
49+
public static void main(String[] args) throws Exception {
50+
PassFailJFrame.builder()
51+
.title("Undecorated Frame & Dialog Test Instructions")
52+
.instructions(INSTRUCTIONS)
53+
.rows((int) INSTRUCTIONS.lines().count() + 2)
54+
.columns(40)
55+
.testUI(FrameDialogMixedTest::createUI)
56+
.build()
57+
.awaitAndCheck();
58+
}
59+
60+
private static Frame createUI() {
61+
Frame frame = new Frame("Undecorated Frame");
62+
frame.setSize(SIZE, SIZE);
63+
frame.setBackground(Color.RED);
64+
frame.setUndecorated(true);
65+
frame.setLayout(new FlowLayout(FlowLayout.CENTER));
66+
67+
Button button = new Button("Create Dialog");
68+
button.addActionListener(e -> {
69+
Dialog dialog = new Dialog(frame);
70+
Point frameLoc = frame.getLocationOnScreen();
71+
dialog.setBounds(frameLoc.x + frame.getSize().width + 5,
72+
frameLoc.y,
73+
SIZE, SIZE);
74+
dialog.setBackground(Color.GREEN);
75+
dialog.setUndecorated(true);
76+
dialog.setVisible(true);
77+
});
78+
79+
frame.add(button);
80+
return frame;
81+
}
82+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Copyright (c) 2005, 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.GraphicsEnvironment;
29+
import java.awt.Point;
30+
import java.awt.Rectangle;
31+
import java.awt.Robot;
32+
import java.awt.Toolkit;
33+
import java.awt.image.BufferedImage;
34+
import java.io.File;
35+
import java.io.IOException;
36+
import java.util.stream.Stream;
37+
import javax.imageio.ImageIO;
38+
39+
import jtreg.SkippedException;
40+
41+
/*
42+
* @test
43+
* @key headful
44+
* @bug 4862945
45+
* @summary Undecorated frames miss certain mwm functions in the mwm hints.
46+
* @library /test/lib
47+
* @build jtreg.SkippedException
48+
* @run main MaximizeUndecoratedTest
49+
*/
50+
51+
public class MaximizeUndecoratedTest {
52+
private static final int SIZE = 300;
53+
private static final int OFFSET = 5;
54+
55+
private static Frame frame;
56+
private static Robot robot;
57+
58+
private static volatile Dimension screenSize;
59+
private static volatile Rectangle maxBounds;
60+
61+
public static void main(String[] args) throws Exception {
62+
if (!Toolkit.getDefaultToolkit()
63+
.isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
64+
throw new SkippedException("Test is not applicable as"
65+
+ " the Window manager does not support MAXIMIZATION");
66+
}
67+
68+
try {
69+
robot = new Robot();
70+
71+
EventQueue.invokeAndWait(MaximizeUndecoratedTest::createUI);
72+
robot.waitForIdle();
73+
robot.delay(1000);
74+
75+
EventQueue.invokeAndWait(() -> {
76+
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
77+
maxBounds = GraphicsEnvironment.getLocalGraphicsEnvironment()
78+
.getMaximumWindowBounds();
79+
System.out.println("Maximum Window Bounds: " + maxBounds);
80+
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
81+
});
82+
robot.waitForIdle();
83+
robot.delay(500);
84+
85+
// Colors sampled at top-left, top-right, bottom-right & bottom-left
86+
// corners of maximized frame.
87+
Point[] points = new Point[] {
88+
new Point(maxBounds.x + OFFSET, maxBounds.y + OFFSET),
89+
new Point(maxBounds.width - OFFSET, maxBounds.y + OFFSET),
90+
new Point(maxBounds.width - OFFSET, maxBounds.height - OFFSET),
91+
new Point(maxBounds.x + OFFSET, maxBounds.height - OFFSET)
92+
};
93+
94+
if (!Stream.of(points)
95+
.map(p -> robot.getPixelColor(p.x, p.y))
96+
.allMatch(c -> c.equals(Color.GREEN))) {
97+
saveScreenCapture();
98+
throw new RuntimeException("Test Failed !! Frame not maximized.");
99+
}
100+
} finally {
101+
EventQueue.invokeAndWait(() -> {
102+
if (frame != null) {
103+
frame.setExtendedState(Frame.NORMAL);
104+
frame.dispose();
105+
}
106+
});
107+
}
108+
}
109+
110+
private static void createUI() {
111+
frame = new Frame("Test Maximization of Frame");
112+
frame.setSize(SIZE, SIZE);
113+
frame.setBackground(Color.GREEN);
114+
frame.setResizable(true);
115+
frame.setUndecorated(true);
116+
frame.setLocationRelativeTo(null);
117+
frame.setVisible(true);
118+
}
119+
120+
private static void saveScreenCapture() {
121+
BufferedImage image = robot.createScreenCapture(new Rectangle(new Point(),
122+
screenSize));
123+
try {
124+
ImageIO.write(image, "png", new File("MaximizedFrame.png"));
125+
} catch (IOException e) {
126+
e.printStackTrace();
127+
}
128+
}
129+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
* Copyright (c) 2005, 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.Point;
29+
import java.awt.Rectangle;
30+
import java.awt.Robot;
31+
import java.awt.Toolkit;
32+
import java.awt.event.WindowAdapter;
33+
import java.awt.event.WindowEvent;
34+
import java.awt.image.BufferedImage;
35+
import java.io.File;
36+
import java.io.IOException;
37+
import java.util.concurrent.CountDownLatch;
38+
import java.util.concurrent.TimeUnit;
39+
import javax.imageio.ImageIO;
40+
41+
import jtreg.SkippedException;
42+
43+
/*
44+
* @test
45+
* @key headful
46+
* @bug 6251941
47+
* @summary Undecorated frames should be minimizable.
48+
* @library /test/lib
49+
* @build jtreg.SkippedException
50+
* @run main MinimizeUndecoratedTest
51+
*/
52+
53+
public class MinimizeUndecoratedTest {
54+
private static final int SIZE = 300;
55+
private static final CountDownLatch isMinimized = new CountDownLatch(1);
56+
57+
private static Frame frame;
58+
private static Robot robot;
59+
60+
private static volatile Point frameLoc;
61+
62+
public static void main(String[] args) throws Exception {
63+
if (!Toolkit.getDefaultToolkit()
64+
.isFrameStateSupported(Frame.ICONIFIED)) {
65+
throw new SkippedException("Test is not applicable as"
66+
+ " the Window manager does not support MINIMIZATION");
67+
}
68+
69+
try {
70+
robot = new Robot();
71+
EventQueue.invokeAndWait(MinimizeUndecoratedTest::createUI);
72+
robot.waitForIdle();
73+
robot.delay(1000);
74+
75+
EventQueue.invokeAndWait(() -> frameLoc = frame.getLocationOnScreen());
76+
77+
Color beforeColor = robot.getPixelColor(frameLoc.x + SIZE / 2,
78+
frameLoc.y + SIZE / 2);
79+
80+
EventQueue.invokeAndWait(() -> frame.setExtendedState(Frame.ICONIFIED));
81+
robot.waitForIdle();
82+
robot.delay(500);
83+
84+
if (!isMinimized.await(8, TimeUnit.SECONDS)) {
85+
throw new RuntimeException("Window iconified event not received.");
86+
}
87+
88+
EventQueue.invokeAndWait(() -> System.out.println("Frame state: "
89+
+ frame.getExtendedState()));
90+
Color afterColor = robot.getPixelColor(frameLoc.x + SIZE / 2,
91+
frameLoc.y + SIZE / 2);
92+
93+
if (beforeColor.equals(afterColor)) {
94+
saveScreenCapture();
95+
throw new RuntimeException("Color before & after minimization : "
96+
+ beforeColor + " vs " + afterColor + "\n"
97+
+ "Test Failed !! Frame not minimized.");
98+
}
99+
} finally {
100+
EventQueue.invokeAndWait(() -> {
101+
if (frame != null) {
102+
frame.setExtendedState(Frame.NORMAL);
103+
frame.dispose();
104+
}
105+
});
106+
}
107+
}
108+
109+
private static void createUI() {
110+
frame = new Frame("Test Minimization of Frame");
111+
frame.setSize(SIZE, SIZE);
112+
frame.setBackground(Color.GREEN);
113+
frame.setResizable(true);
114+
frame.setUndecorated(true);
115+
frame.addWindowStateListener(new WindowAdapter() {
116+
@Override
117+
public void windowStateChanged(WindowEvent e) {
118+
if (e.getNewState() == Frame.ICONIFIED) {
119+
System.out.println("Window iconified event received.");
120+
isMinimized.countDown();
121+
}
122+
}
123+
});
124+
125+
frame.setLocationRelativeTo(null);
126+
frame.setVisible(true);
127+
}
128+
129+
private static void saveScreenCapture() {
130+
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
131+
BufferedImage image = robot.createScreenCapture(new Rectangle(new Point(),
132+
screenSize));
133+
try {
134+
ImageIO.write(image, "png", new File("MinimizedFrame.png"));
135+
} catch (IOException e) {
136+
e.printStackTrace();
137+
}
138+
}
139+
}

0 commit comments

Comments
 (0)