Skip to content

Commit 1ab83e6

Browse files
author
Satyen Subramaniam
committed
8354365: Opensource few Modal and Full Screen related tests
Backport-of: e21387e0454e821e5720e781138dcc4c24a14ec7
1 parent b04b10a commit 1ab83e6

File tree

5 files changed

+488
-0
lines changed

5 files changed

+488
-0
lines changed

test/jdk/ProblemList.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ java/awt/Modal/MultipleDialogs/MultipleDialogs2Test.java 8198665 macosx-all
410410
java/awt/Modal/MultipleDialogs/MultipleDialogs3Test.java 8198665 macosx-all
411411
java/awt/Modal/MultipleDialogs/MultipleDialogs4Test.java 8198665 macosx-all
412412
java/awt/Modal/MultipleDialogs/MultipleDialogs5Test.java 8198665 macosx-all
413+
java/awt/Modal/NativeDialogToFrontBackTest.java 7188049 windows-all,linux-all
413414
java/awt/Mouse/EnterExitEvents/DragWindowOutOfFrameTest.java 8177326 macosx-all
414415
java/awt/Mouse/EnterExitEvents/ResizingFrameTest.java 8005021 macosx-all
415416
java/awt/Mouse/EnterExitEvents/FullscreenEnterEventTest.java 8051455 macosx-all
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
* Copyright (c) 2005, 2025, 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.Frame;
28+
import java.awt.GraphicsEnvironment;
29+
30+
import java.awt.event.ActionEvent;
31+
import java.awt.event.ActionListener;
32+
33+
import javax.swing.JPanel;
34+
35+
/*
36+
* @test
37+
* @bug 6225472 6682536
38+
* @requires (os.family != "linux")
39+
* @summary Tests that non-focusable Frame in full-screen mode overlaps the task bar.
40+
* @library /java/awt/regtesthelpers
41+
* @build PassFailJFrame
42+
* @run main/manual NonfocusableFrameFullScreenTest
43+
*/
44+
45+
public class NonfocusableFrameFullScreenTest extends JPanel {
46+
boolean fullscreen = false;
47+
48+
public static void main(String[] args) throws Exception {
49+
final String INSTRUCTIONS = """
50+
1. Press "Show Frame" button to show a Frame with two buttons.
51+
52+
2. Press the button "To Full Screen" to bring the frame to
53+
full-screen mode:
54+
55+
The frame should overlap the taskbar
56+
57+
3. Press "To Windowed" button:
58+
The frame should return to its original size.
59+
The frame shouldn't be alwaysOnTop.
60+
61+
4. Press "Set Always On Top" button and make sure the frame
62+
is alwaysOnTop, then press "To Full Screen" button
63+
and then "To Windowed" button:
64+
65+
The frame should return to its original size keeping alwaysOnTop
66+
state on.
67+
68+
Press Pass if everything is as expected.""";
69+
70+
PassFailJFrame.builder()
71+
.instructions(INSTRUCTIONS)
72+
.columns(45)
73+
.testUI(NonfocusableFrameFullScreenTest::new)
74+
.build()
75+
.awaitAndCheck();
76+
}
77+
78+
private NonfocusableFrameFullScreenTest() {
79+
Button b = new Button("Show Frame");
80+
b.addActionListener(new ActionListener() {
81+
@Override
82+
public void actionPerformed(ActionEvent e) {
83+
showFrame();
84+
}
85+
});
86+
setLayout(new BorderLayout());
87+
add(b, BorderLayout.CENTER);
88+
}
89+
90+
@Override
91+
public Dimension getPreferredSize() {
92+
return new Dimension(200, 100);
93+
}
94+
95+
public void showFrame() {
96+
Frame frame = new Frame("Test Frame");
97+
98+
Button button = new Button("To Full Screen");
99+
button.addActionListener(new ActionListener() {
100+
@Override
101+
public void actionPerformed(ActionEvent e) {
102+
if (fullscreen) {
103+
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().
104+
setFullScreenWindow(null);
105+
button.setLabel("To Full Screen");
106+
fullscreen = false;
107+
} else {
108+
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().
109+
setFullScreenWindow(frame);
110+
button.setLabel("To Windowed");
111+
fullscreen = true;
112+
}
113+
frame.validate();
114+
}
115+
});
116+
117+
Button button2 = new Button("Set Always On Top");
118+
button2.addActionListener(new ActionListener() {
119+
@Override
120+
public void actionPerformed(ActionEvent e) {
121+
if (frame.isAlwaysOnTop()) {
122+
button2.setLabel("Set Always On Top");
123+
frame.setAlwaysOnTop(false);
124+
} else {
125+
button2.setLabel("Set Not Always On Top");
126+
frame.setAlwaysOnTop(true);
127+
}
128+
frame.validate();
129+
}
130+
});
131+
132+
frame.setLayout(new BorderLayout());
133+
frame.add(button, BorderLayout.WEST);
134+
frame.add(button2, BorderLayout.EAST);
135+
frame.setBounds(400, 200, 350, 100);
136+
frame.setFocusableWindowState(false);
137+
frame.setVisible(true);
138+
}
139+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
* Copyright (c) 2005, 2025, 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.Dialog;
26+
import java.awt.Frame;
27+
28+
import java.awt.event.ActionEvent;
29+
import java.awt.event.ActionListener;
30+
import java.awt.event.WindowAdapter;
31+
import java.awt.event.WindowEvent;
32+
import java.awt.event.WindowListener;
33+
34+
/*
35+
* @test
36+
* @bug 6271779
37+
* @summary This test shows and hides a modal dialog several times without destroying its
38+
* peer. Without the fix this may lead to application (or even WM) hang.
39+
* @library /java/awt/regtesthelpers
40+
* @build PassFailJFrame
41+
* @run main/manual AddRemoveTransientForsTest
42+
*/
43+
44+
public class AddRemoveTransientForsTest {
45+
46+
private static Dialog d1;
47+
private static Dialog d2;
48+
49+
public static void main(String[] args) throws Exception {
50+
final String INSTRUCTIONS = """
51+
When the test starts, a frame is shown with a button 'Show Dialog D1'.
52+
53+
1. Press the button 'Show Dialog D1' to show a modal dialog D1 with a button
54+
'Show dialog D2'.
55+
56+
2. Press the button 'Show dialog D2' to show another modal dialog D2 with a button
57+
'Close'.
58+
59+
3. Press the button 'Close' to close dialog D2.
60+
61+
4. Repeat steps 2 and 3 several times (at least 3-4 times).
62+
63+
If the application is not hung, press Pass.
64+
65+
NOTE: all the modal dialogs must be closed before pressing Pass button.""";
66+
67+
PassFailJFrame.builder()
68+
.instructions(INSTRUCTIONS)
69+
.columns(45)
70+
.testUI(AddRemoveTransientForsTest::init)
71+
.build()
72+
.awaitAndCheck();
73+
}
74+
75+
public static Frame init() {
76+
Frame f = new Frame("AddRemoveTransientForsTest Frame");
77+
Button b = new Button("Show dialog D1");
78+
b.addActionListener(new ActionListener() {
79+
@Override
80+
public void actionPerformed(ActionEvent e)
81+
{
82+
d1.setVisible(true);
83+
}
84+
});
85+
f.add(b);
86+
f.setSize(200, 100);
87+
88+
WindowListener wl = new WindowAdapter() {
89+
@Override
90+
public void windowClosing(WindowEvent e)
91+
{
92+
e.getWindow().dispose();
93+
}
94+
};
95+
96+
d1 = new Dialog(f, "D1", true);
97+
d1.setBounds(200, 200, 200, 100);
98+
d1.addWindowListener(wl);
99+
Button b1 = new Button("Show dialog D2");
100+
b1.addActionListener(new ActionListener() {
101+
@Override
102+
public void actionPerformed(ActionEvent e)
103+
{
104+
d2.setVisible(true);
105+
}
106+
});
107+
d1.add(b1);
108+
109+
d2 = new Dialog(d1, "D2", true);
110+
d2.setBounds(300, 300, 200, 100);
111+
Button b2 = new Button("Close");
112+
b2.addActionListener(new ActionListener() {
113+
@Override
114+
public void actionPerformed(ActionEvent e)
115+
{
116+
d2.setVisible(false);
117+
}
118+
});
119+
d2.add(b2);
120+
121+
return f;
122+
}
123+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright (c) 2005, 2025, 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.EventQueue;
26+
import java.awt.Frame;
27+
28+
import java.awt.event.WindowAdapter;
29+
import java.awt.event.WindowEvent;
30+
import java.awt.event.WindowListener;
31+
32+
/*
33+
* @test
34+
* @bug 6278150
35+
* @key headful
36+
* @summary Initially modal blocked window causes modal dialog to lose focus
37+
* @run main DialogLosesFocusTest
38+
*/
39+
40+
public class DialogLosesFocusTest {
41+
private static Frame parent;
42+
private static Dialog dialog;
43+
private static Frame blocked;
44+
private static volatile boolean failed;
45+
46+
public static void main(String[] args) throws Exception {
47+
try {
48+
createAndShowUI();
49+
50+
sleepForMsecs(10000);
51+
52+
if (failed) {
53+
throw new RuntimeException("Test Failed");
54+
}
55+
} finally {
56+
EventQueue.invokeAndWait(() -> {
57+
if (parent != null) {
58+
parent.dispose();
59+
}
60+
if (dialog != null) {
61+
dialog.dispose();
62+
}
63+
if (blocked != null) {
64+
blocked.dispose();
65+
}
66+
});
67+
}
68+
}
69+
70+
public static void createAndShowUI() throws Exception {
71+
EventQueue.invokeAndWait(() -> {
72+
parent = new Frame("Parent frame");
73+
parent.setBounds(0, 0, 300, 100);
74+
parent.setVisible(true);
75+
});
76+
77+
sleepForMsecs(1000);
78+
79+
EventQueue.invokeLater(() -> {
80+
dialog = new Dialog(parent, "Modal dialog", Dialog.ModalityType.APPLICATION_MODAL);
81+
dialog.setBounds(100, 120, 300, 100);
82+
dialog.setVisible(true);
83+
});
84+
85+
sleepForMsecs(1000);
86+
87+
EventQueue.invokeAndWait(() -> {
88+
blocked = new Frame("Blocked frame");
89+
blocked.setBounds(200, 240, 300, 100);
90+
blocked.addWindowListener(new WindowAdapter() {
91+
@Override
92+
public void windowActivated(WindowEvent we) {
93+
if (dialog.isVisible()) {
94+
failed = true;
95+
}
96+
}
97+
});
98+
blocked.setVisible(true);
99+
});
100+
}
101+
102+
private static void sleepForMsecs(int t) {
103+
try {
104+
Thread.sleep(t);
105+
} catch (Exception z) {}
106+
}
107+
}

0 commit comments

Comments
 (0)