Skip to content

Commit f2a767f

Browse files
author
Alexander Zvegintsev
committed
8340907: Open source closed frame tests # 2
Reviewed-by: prr, honkar
1 parent 7b1e6f8 commit f2a767f

File tree

5 files changed

+441
-0
lines changed

5 files changed

+441
-0
lines changed

test/jdk/ProblemList.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ java/awt/Focus/AutoRequestFocusTest/AutoRequestFocusToFrontTest.java 6848406 gen
121121
java/awt/Focus/AutoRequestFocusTest/AutoRequestFocusSetVisibleTest.java 6848407 generic-all
122122
java/awt/Frame/MaximizedUndecorated/MaximizedUndecorated.java 8022302 generic-all
123123
java/awt/Frame/RestoreToOppositeScreen/RestoreToOppositeScreen.java 8286840 linux-all
124+
java/awt/Frame/InitialIconifiedTest.java 8203920 macosx-all,linux-all
124125
java/awt/FileDialog/FileDialogIconTest/FileDialogIconTest.java 8160558 windows-all
125126
java/awt/event/MouseWheelEvent/InfiniteRecursion/InfiniteRecursion.java 8060176 windows-all,macosx-all
126127
java/awt/event/MouseWheelEvent/InfiniteRecursion/InfiniteRecursion_1.java 8060176 windows-all,macosx-all
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* Copyright (c) 2003, 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+
* DeiconifyClipTest.java
26+
*
27+
* summary:
28+
*
29+
* What happens is that we call AwtWindow::UpdateInsets when
30+
* processing WM_NCCALCSIZE delivered on programmatic deiconification.
31+
* At this point IsIconic returns false (so UpdateInsets proceeds),
32+
* but the rect sizes still seems to be those weird of the iconic
33+
* state. Based on them we compute insets with top = left = 0 (and
34+
* bottom and right that are completely bogus) and pass them to
35+
* PaintUpdateRgn which results in incorrect clip origin. Immediately
36+
* after that we do UpdateInsets again during WM_SIZE processing and
37+
* get real values.
38+
*/
39+
40+
import javax.swing.BoxLayout;
41+
import javax.swing.JFrame;
42+
import javax.swing.SwingUtilities;
43+
import java.awt.Color;
44+
import java.awt.Dimension;
45+
import java.awt.Frame;
46+
import java.awt.Graphics;
47+
import java.awt.Insets;
48+
49+
/*
50+
* @test
51+
* @bug 4792958
52+
* @summary Incorrect clip region after programmatic restore
53+
* @library /java/awt/regtesthelpers
54+
* @build PassFailJFrame
55+
* @run main/manual DeiconifyClipTest
56+
*/
57+
58+
public class DeiconifyClipTest {
59+
private static final String INSTRUCTIONS = """
60+
This test creates a frame that is automatically iconified/deiconified
61+
in a cycle.
62+
63+
The test FAILS if after deiconfication the frame has a greyed-out area
64+
in the lower-right corner.
65+
If the frame contents is drawn completely - the test PASSES.
66+
67+
Press PASS or FAIL button accordingly.
68+
""";
69+
70+
static TestFrame testFrame;
71+
static volatile boolean shouldContinue = true;
72+
73+
public static void main(String[] args) throws Exception {
74+
PassFailJFrame passFailJFrame = PassFailJFrame.builder()
75+
.title("DeiconifyClipTest Instructions")
76+
.instructions(INSTRUCTIONS)
77+
.columns(45)
78+
.testUI(DeiconifyClipTest::createAndShowUI)
79+
.build();
80+
try {
81+
runThread();
82+
} finally {
83+
passFailJFrame.awaitAndCheck();
84+
shouldContinue = false;
85+
}
86+
}
87+
88+
private static void runThread() {
89+
new Thread(() -> {
90+
for (int i = 0; i < 1000 && shouldContinue; ++i) {
91+
try {
92+
Thread.sleep(3000);
93+
SwingUtilities.invokeAndWait(() -> {
94+
if ((testFrame.getExtendedState() & Frame.ICONIFIED)
95+
!= 0) {
96+
testFrame.setExtendedState(Frame.NORMAL);
97+
} else {
98+
testFrame.setState(Frame.ICONIFIED);
99+
}
100+
});
101+
} catch (Exception ignored) {
102+
}
103+
}
104+
}).start();
105+
}
106+
107+
static Frame createAndShowUI() {
108+
testFrame = new TestFrame();
109+
testFrame.getContentPane().setLayout(new BoxLayout(testFrame.getContentPane(),
110+
BoxLayout.Y_AXIS));
111+
testFrame.getContentPane().setBackground(Color.yellow);
112+
testFrame.setSize(300, 300);
113+
return testFrame;
114+
}
115+
116+
static class TestFrame extends JFrame {
117+
public TestFrame() {
118+
super("DeiconifyClipTest");
119+
}
120+
121+
// make it more visible if the clip is wrong.
122+
public void paint(Graphics g) {
123+
Insets b = getInsets();
124+
Dimension d = getSize();
125+
126+
int x = b.left;
127+
int y = b.top;
128+
int w = d.width - x - b.right;
129+
int h = d.height - y - b.bottom;
130+
131+
g.setColor(Color.white);
132+
g.fillRect(0, 0, d.width, d.height);
133+
134+
g.setColor(Color.green);
135+
g.drawRect(x, y, w-1, h-1);
136+
g.drawLine(x, y, x+w, y+h);
137+
g.drawLine(x, y+h, x+w, y);
138+
}
139+
}
140+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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.Button;
26+
import java.awt.Cursor;
27+
import java.awt.Frame;
28+
import java.awt.Panel;
29+
import java.awt.event.ActionListener;
30+
import java.lang.Exception;
31+
import java.lang.InterruptedException;
32+
import java.lang.Object;
33+
import java.lang.String;
34+
import java.lang.Thread;
35+
36+
/*
37+
* @test
38+
* @bug 4097226
39+
* @summary Frame.setCursor() sometimes doesn't update the cursor until user moves the mouse
40+
* @library /java/awt/regtesthelpers
41+
* @build PassFailJFrame
42+
* @run main/manual FrameSetCursorTest
43+
*/
44+
45+
public class FrameSetCursorTest {
46+
private static final String INSTRUCTIONS = """
47+
1. Keep the instruction dialog and TestFrame side by side so that
48+
you can read the instructions while doing the test
49+
2. Click on the 'Start Busy' button on the frame titled 'TestFrame'
50+
and DO NOT MOVE THE MOUSE ANYWHERE till you complete the steps below
51+
3. The cursor on the TestFrame changes to busy cursor
52+
4. If you don't see the busy cursor press 'Fail' after
53+
the `done sleeping` message
54+
5. If the busy cursor is seen, after 5 seconds the message
55+
'done sleeping' is displayed in the message window
56+
6. Check for the cursor type after the display of 'done sleeping'
57+
7. If the cursor on the TestFrame has changed back to default cursor
58+
(without you touching or moving the mouse), then press 'Pass'
59+
else if the frame still shows the busy cursor press 'Fail'
60+
""";
61+
62+
public static void main(String[] args) throws Exception {
63+
PassFailJFrame.builder()
64+
.title("FrameSetCursorTest Instructions")
65+
.instructions(INSTRUCTIONS)
66+
.columns(45)
67+
.testUI(FrameSetCursorTest::createAndShowUI)
68+
.logArea(5)
69+
.build()
70+
.awaitAndCheck();
71+
72+
}
73+
74+
static Frame createAndShowUI() {
75+
Frame frame = new Frame("TestFrame");
76+
Panel panel = new Panel();
77+
Button busyButton = new Button("Start Busy");
78+
79+
ActionListener actionListener = event -> {
80+
Object source = event.getSource();
81+
if (source == busyButton) {
82+
frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
83+
try {
84+
Thread.sleep(5000);
85+
} catch (InterruptedException ignored) {}
86+
PassFailJFrame.log("done sleeping");
87+
frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
88+
}
89+
};
90+
91+
busyButton.addActionListener(actionListener);
92+
panel.setLayout(new BorderLayout());
93+
panel.add("North", busyButton);
94+
95+
frame.add(panel);
96+
frame.pack();
97+
frame.setSize(200, 200);
98+
return frame;
99+
}
100+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright (c) 2003, 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.Rectangle;
29+
import java.awt.Robot;
30+
import java.awt.image.BufferedImage;
31+
import java.io.File;
32+
import java.io.IOException;
33+
34+
/*
35+
* @test
36+
* @key headful
37+
* @bug 4851435
38+
* @summary Frame is not shown initially iconified after pack
39+
*/
40+
41+
public class InitialIconifiedTest {
42+
43+
private static Frame backgroundFrame;
44+
private static Frame testedFrame;
45+
46+
private static final Rectangle backgroundFrameBounds =
47+
new Rectangle(100, 100, 200, 200);
48+
private static final Rectangle testedFrameBounds =
49+
new Rectangle(150, 150, 100, 100);
50+
51+
private static Robot robot;
52+
53+
public static void main(String[] args) throws Exception {
54+
robot = new Robot();
55+
56+
try {
57+
EventQueue.invokeAndWait(InitialIconifiedTest::initAndShowGui);
58+
robot.waitForIdle();
59+
robot.delay(500);
60+
test();
61+
} finally {
62+
EventQueue.invokeAndWait(() -> {
63+
backgroundFrame.dispose();
64+
testedFrame.dispose();
65+
});
66+
}
67+
}
68+
69+
private static void initAndShowGui() {
70+
backgroundFrame = new Frame("DisposeTest background");
71+
backgroundFrame.setUndecorated(true);
72+
backgroundFrame.setBackground(Color.RED);
73+
backgroundFrame.setBounds(backgroundFrameBounds);
74+
backgroundFrame.setVisible(true);
75+
76+
testedFrame = new Frame("Should have started ICONIC");
77+
testedFrame.setExtendedState(Frame.ICONIFIED);
78+
testedFrame.setBounds(testedFrameBounds);
79+
testedFrame.setVisible(true);
80+
}
81+
82+
private static void test() {
83+
BufferedImage bi = robot.createScreenCapture(backgroundFrameBounds);
84+
int redPix = Color.RED.getRGB();
85+
86+
for (int x = 0; x < bi.getWidth(); x++) {
87+
for (int y = 0; y < bi.getHeight(); y++) {
88+
if (bi.getRGB(x, y) != redPix) {
89+
try {
90+
ImageIO.write(bi, "png",
91+
new File("failure.png"));
92+
} catch (IOException ignored) {}
93+
throw new RuntimeException("Test failed");
94+
}
95+
}
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)