Skip to content

Commit 6071346

Browse files
author
Alisen Chung
committedOct 14, 2024
8339879: Open some dialog awt tests
Reviewed-by: honkar, prr
1 parent a8a8b2d commit 6071346

4 files changed

+571
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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 java.awt.Dialog;
25+
import java.awt.Frame;
26+
27+
/*
28+
* @test
29+
* @bug 4964237
30+
* @requires (os.family == "windows")
31+
* @summary Win: Changing theme changes java dialogs title icon
32+
* @library /java/awt/regtesthelpers
33+
* @build PassFailJFrame
34+
* @run main/manual DefaultIconTest
35+
*/
36+
37+
public class DefaultIconTest {
38+
static String instructions = """
39+
This test shows frame and two dialogs
40+
Change windows theme. Resizable dialog should retain default icon
41+
Non-resizable dialog should retain no icon
42+
Press PASS if icons look correct, FAIL otherwise
43+
""";
44+
45+
public static void main(String[] args) throws Exception {
46+
PassFailJFrame.builder()
47+
.title("ShownModalDialogSerializationTest Instructions")
48+
.instructions(instructions)
49+
.testTimeOut(5)
50+
.rows(10)
51+
.columns(35)
52+
.testUI(DefaultIconTest::createGUIs)
53+
.build()
54+
.awaitAndCheck();
55+
}
56+
57+
public static Frame createGUIs() {
58+
Frame f = new Frame("DefaultIconTest");
59+
f.setSize(200, 100);
60+
Dialog d1 = new Dialog(f, "Resizable Dialog, should show default icon");
61+
d1.setSize(200, 100);
62+
d1.setVisible(true);
63+
d1.setLocation(0, 150);
64+
Dialog d2 = new Dialog(f, "Non-resizable dialog, should have no icon");
65+
d2.setSize(200, 100);
66+
d2.setVisible(true);
67+
d2.setResizable(false);
68+
d2.setLocation(0, 300);
69+
return f;
70+
}
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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 java.awt.Dialog;
25+
import java.awt.Dimension;
26+
import java.awt.Frame;
27+
import java.awt.event.ComponentEvent;
28+
import java.awt.event.ComponentListener;
29+
30+
/*
31+
* @test
32+
* @bug 4912551
33+
* @summary Checks that with resizable set to false before show()
34+
* dialog can not be resized.
35+
* @library /java/awt/regtesthelpers
36+
* @build PassFailJFrame
37+
* @run main/manual DialogInitialResizability
38+
*/
39+
40+
public class DialogInitialResizability {
41+
static String instructions = """
42+
When this test is run a dialog will display (setResizable Test).
43+
This dialog should not be resizable.
44+
45+
Additionally ensure that there are NO componentResized events in the log section.
46+
If the above conditions are true, then Press PASS else FAIL.
47+
""";
48+
49+
private static final Dimension INITIAL_SIZE = new Dimension(400, 150);
50+
public static void main(String[] args) throws Exception {
51+
PassFailJFrame.builder()
52+
.title("DialogInitialResizability")
53+
.instructions(instructions)
54+
.testTimeOut(5)
55+
.rows((int) instructions.lines().count() + 2)
56+
.columns(40)
57+
.testUI(DialogInitialResizability::createGUI)
58+
.logArea()
59+
.build()
60+
.awaitAndCheck();
61+
}
62+
63+
public static MyDialog createGUI() {
64+
Frame f = new Frame("invisible dialog owner");
65+
66+
MyDialog ld = new MyDialog(f);
67+
ld.setBounds(100, 100, INITIAL_SIZE.width, INITIAL_SIZE.height);
68+
ld.setResizable(false);
69+
70+
PassFailJFrame.log("Dialog isResizable is set to: " + ld.isResizable());
71+
PassFailJFrame.log("Dialog Initial Size " + ld.getSize());
72+
return ld;
73+
}
74+
75+
private static class MyDialog extends Dialog implements ComponentListener {
76+
public MyDialog(Frame f) {
77+
super(f, "setResizable test", false);
78+
this.addComponentListener(this);
79+
}
80+
81+
public void componentResized(ComponentEvent e) {
82+
if (!e.getComponent().getSize().equals(INITIAL_SIZE)) {
83+
PassFailJFrame.log("Component Resized. Test Failed!!");
84+
}
85+
}
86+
87+
public void componentMoved(ComponentEvent e) {
88+
}
89+
90+
public void componentShown(ComponentEvent e) {
91+
}
92+
93+
public void componentHidden(ComponentEvent e) {
94+
}
95+
}
96+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,312 @@
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.Button;
25+
import java.awt.Choice;
26+
import java.awt.Dialog;
27+
import java.awt.FileDialog;
28+
import java.awt.FlowLayout;
29+
import java.awt.Frame;
30+
import java.awt.GridLayout;
31+
import java.awt.List;
32+
import java.awt.Panel;
33+
import java.awt.Point;
34+
import java.awt.Window;
35+
import java.awt.event.ActionEvent;
36+
import java.awt.event.ActionListener;
37+
import java.awt.event.WindowAdapter;
38+
import java.awt.event.WindowEvent;
39+
import java.util.Vector;
40+
import java.util.Enumeration;
41+
42+
/*
43+
* @test
44+
* @bug 4110094 4178930 4178390
45+
* @summary Test: Rewrite of Win modal dialogs
46+
* @library /java/awt/regtesthelpers
47+
* @build PassFailJFrame
48+
* @run main/manual NestedDialogTest
49+
*/
50+
51+
public class NestedDialogTest {
52+
private static Vector windows = new Vector();
53+
static String instructions = """
54+
To solve various race conditions, windows modal dialogs were rewritten. This
55+
test exercises various modal dialog boundary conditions and checks that
56+
previous fixes to modality are incorporated in the rewrite.
57+
58+
Check the following:
59+
- No IllegalMonitorStateException is thrown when a dialog closes
60+
61+
- Open multiple nested dialogs and verify that all other windows
62+
are disabled when modal dialog is active.
63+
64+
- Check that the proper window is activated when a modal dialog closes.
65+
66+
- Close nested dialogs out of order (e.g. close dialog1 before dialog2)
67+
and verify that this works and no deadlock occurs.
68+
69+
- Check that all other windows are disabled when a FileDialog is open.
70+
71+
- Check that the proper window is activated when a FileDialog closes.
72+
73+
- Verify that the active window nevers switches to another application
74+
when closing dialogs, even temporarily.
75+
76+
- Check that choosing Hide always sucessfully hides a dialog. You should
77+
try this multiple times to catch any race conditions.
78+
79+
- Check that the scrollbar on the Choice component in the dialog works, as opposed
80+
to just using drag-scrolling or the cursor keys
81+
""";
82+
83+
public static void main(String[] args) throws Exception {
84+
PassFailJFrame.builder()
85+
.title("NestedDialogTest")
86+
.instructions(instructions)
87+
.testTimeOut(5)
88+
.rows((int) instructions.lines().count() + 2)
89+
.columns(35)
90+
.testUI(NestedDialogTest::createGUI)
91+
.build()
92+
.awaitAndCheck();
93+
}
94+
95+
public static Frame createGUI() {
96+
Frame frame1 = new NestedDialogTestFrame("frame0");
97+
Frame frame2 = new NestedDialogTestFrame("frame1");
98+
frame2.setLocation(100, 100);
99+
return frame1;
100+
}
101+
102+
public static void addWindow(Window window) {
103+
// System.out.println("Pushing window " + window);
104+
windows.removeElement(window);
105+
windows.addElement(window);
106+
}
107+
108+
public static void removeWindow(Window window) {
109+
// System.out.println("Popping window " + window);
110+
windows.removeElement(window);
111+
}
112+
113+
public static Window getWindow(int index) {
114+
return (Window) windows.elementAt(index);
115+
}
116+
117+
public static Enumeration enumWindows() {
118+
return windows.elements();
119+
}
120+
121+
public static int getWindowIndex(Window win) {
122+
return windows.indexOf(win);
123+
}
124+
}
125+
126+
class NestedDialogTestFrame extends Frame {
127+
NestedDialogTestFrame(String name) {
128+
super(name);
129+
setSize(200, 200);
130+
show();
131+
132+
setLayout(new FlowLayout());
133+
Button btnDlg = new Button("Dialog...");
134+
add(btnDlg);
135+
Button btnFileDlg = new Button("FileDialog...");
136+
add(btnFileDlg);
137+
138+
addWindowListener(new WindowAdapter() {
139+
public void windowClosing(WindowEvent ev) {
140+
System.exit(0);
141+
}
142+
});
143+
144+
btnDlg.addActionListener(
145+
new ActionListener() {
146+
public void actionPerformed(ActionEvent e) {
147+
Dialog d1 = new SimpleDialog(NestedDialogTestFrame.this, null, true);
148+
System.out.println("Returned from showing dialog: " + d1);
149+
}
150+
}
151+
);
152+
153+
btnFileDlg.addActionListener(
154+
new ActionListener() {
155+
public void actionPerformed(ActionEvent e) {
156+
FileDialog dlg = new FileDialog(NestedDialogTestFrame.this);
157+
dlg.show();
158+
}
159+
}
160+
);
161+
162+
validate();
163+
}
164+
165+
public void show() {
166+
if (!isVisible()) {
167+
NestedDialogTest.addWindow(this);
168+
}
169+
super.show();
170+
}
171+
172+
public void dispose() {
173+
NestedDialogTest.removeWindow(this);
174+
super.dispose();
175+
}
176+
}
177+
178+
class SimpleDialog extends Dialog {
179+
Button btnNested;
180+
Button btnFileDlg;
181+
Button btnShow;
182+
Button btnHide;
183+
Button btnDispose;
184+
Button btnExit;
185+
List listWins;
186+
Dialog dlgPrev;
187+
188+
public SimpleDialog(Frame frame, Dialog prev, boolean isModal) {
189+
super(frame, "", isModal);
190+
191+
dlgPrev = prev;
192+
193+
addWindowListener(new WindowAdapter() {
194+
public void windowActivated(WindowEvent ev) {
195+
populateListWin();
196+
}
197+
});
198+
199+
setTitle(getName());
200+
201+
Panel panelNorth = new Panel();
202+
panelNorth.setLayout(new GridLayout(1, 1));
203+
listWins = new List();
204+
panelNorth.add(listWins);
205+
206+
Panel panelSouth = new Panel();
207+
panelSouth.setLayout(new FlowLayout());
208+
btnNested = new Button("Dialog...");
209+
panelSouth.add(btnNested);
210+
btnFileDlg = new Button("FileDialog...");
211+
panelSouth.add(btnFileDlg);
212+
btnShow = new Button("Show");
213+
panelSouth.add(btnShow);
214+
btnHide = new Button("Hide");
215+
panelSouth.add(btnHide);
216+
btnDispose = new Button("Dispose");
217+
panelSouth.add(btnDispose);
218+
219+
Choice cbox = new Choice();
220+
cbox.add("Test1");
221+
cbox.add("Test2");
222+
cbox.add("Test3");
223+
cbox.add("Test4");
224+
cbox.add("Test5");
225+
cbox.add("Test6");
226+
cbox.add("Test7");
227+
cbox.add("Test8");
228+
cbox.add("Test9");
229+
cbox.add("Test10");
230+
cbox.add("Test11");
231+
panelSouth.add(cbox);
232+
233+
validate();
234+
235+
add("Center", panelNorth);
236+
add("South", panelSouth);
237+
238+
btnNested.addActionListener(new ActionListener() {
239+
public void actionPerformed(ActionEvent e) {
240+
Dialog dlg = new SimpleDialog((Frame) getParent(), SimpleDialog.this, true);
241+
System.out.println("Returned from showing dialog: " + dlg);
242+
}
243+
});
244+
245+
btnFileDlg.addActionListener(new ActionListener() {
246+
public void actionPerformed(ActionEvent e) {
247+
FileDialog dlg = new FileDialog((Frame) getParent());
248+
dlg.show();
249+
}
250+
});
251+
252+
btnHide.addActionListener(new ActionListener() {
253+
public void actionPerformed(ActionEvent e) {
254+
Window wnd = getSelectedWindow();
255+
System.out.println(wnd);
256+
wnd.hide();
257+
}
258+
});
259+
260+
btnShow.addActionListener(new ActionListener() {
261+
public void actionPerformed(ActionEvent e) {
262+
getSelectedWindow().show();
263+
}
264+
});
265+
266+
btnDispose.addActionListener(new ActionListener() {
267+
public void actionPerformed(ActionEvent e) {
268+
getSelectedWindow().dispose();
269+
populateListWin();
270+
}
271+
});
272+
273+
pack();
274+
setSize(getSize().width, getSize().height * 2);
275+
if (dlgPrev != null) {
276+
Point pt = dlgPrev.getLocation();
277+
setLocation(pt.x + 30, pt.y + 50);
278+
}
279+
show();
280+
}
281+
282+
private Window getSelectedWindow() {
283+
Window window;
284+
int index = listWins.getSelectedIndex();
285+
286+
window = NestedDialogTest.getWindow(index);
287+
return window;
288+
}
289+
290+
private void populateListWin() {
291+
Enumeration enumWindows = NestedDialogTest.enumWindows();
292+
293+
listWins.removeAll();
294+
while (enumWindows.hasMoreElements()) {
295+
Window win = (Window) enumWindows.nextElement();
296+
listWins.add(win.getName());
297+
}
298+
listWins.select(NestedDialogTest.getWindowIndex(this));
299+
}
300+
301+
public void show() {
302+
if (!isVisible()) {
303+
NestedDialogTest.addWindow(this);
304+
}
305+
super.show();
306+
}
307+
308+
public void dispose() {
309+
NestedDialogTest.removeWindow(this);
310+
super.dispose();
311+
}
312+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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.Dialog;
25+
import java.awt.EventQueue;
26+
import java.awt.Frame;
27+
import java.awt.Label;
28+
29+
import java.awt.TextArea;
30+
import java.io.File;
31+
import java.io.FileOutputStream;
32+
import java.io.ObjectOutputStream;
33+
34+
/*
35+
* @test
36+
* @bug 4739757
37+
* @summary REGRESSION: Modal Dialog is not serializable after showing
38+
* @key headful
39+
* @run main ShownModalDialogSerializationTest
40+
*/
41+
42+
public class ShownModalDialogSerializationTest {
43+
static volatile Frame frame;
44+
static volatile Frame outputFrame;
45+
static volatile Dialog dialog;
46+
47+
public static void main(String[] args) throws Exception {
48+
49+
EventQueue.invokeLater(ShownModalDialogSerializationTest::createTestUI);
50+
51+
while (dialog == null || !dialog.isShowing()) {
52+
Thread.sleep(500);
53+
}
54+
File file = new File("dialog.ser");
55+
FileOutputStream fos = new FileOutputStream(file);
56+
ObjectOutputStream oos = new ObjectOutputStream(fos);
57+
oos.writeObject(dialog);
58+
oos.flush();
59+
file.delete();
60+
61+
EventQueue.invokeAndWait(ShownModalDialogSerializationTest::deleteTestUI);
62+
}
63+
64+
static void deleteTestUI() {
65+
if (dialog != null) {
66+
dialog.setVisible(false);
67+
dialog.dispose();
68+
}
69+
if (frame != null) {
70+
frame.setVisible(false);
71+
frame.dispose();
72+
}
73+
if (outputFrame != null) {
74+
outputFrame.setVisible(false);
75+
outputFrame.dispose();
76+
}
77+
}
78+
79+
private static void createTestUI() {
80+
outputFrame = new Frame("ShownModalDialogSerializationTest");
81+
TextArea output = new TextArea(40, 50);
82+
outputFrame.add(output);
83+
84+
frame = new Frame("invisible dialog owner");
85+
dialog = new Dialog(frame, "Dialog for Close", true);
86+
dialog.add(new Label("Close This Dialog"));
87+
outputFrame.setSize(200, 200);
88+
outputFrame.setVisible(true);
89+
dialog.pack();
90+
dialog.setVisible(true);
91+
}
92+
}

0 commit comments

Comments
 (0)
Please sign in to comment.