Skip to content

Commit 5d7aa66

Browse files
committed
8340279: Open source several AWT Dialog tests - Batch 2
Backport-of: e0dabfb4bfd93a4407518177043d3dbc85c4bbd9
1 parent f5add27 commit 5d7aa66

12 files changed

+542
-0
lines changed

test/jdk/ProblemList.txt

+2
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ java/awt/KeyboardFocusmanager/ConsumeNextMnemonicKeyTypedTest/ConsumeNextMnemoni
488488

489489
java/awt/Window/GetScreenLocation/GetScreenLocationTest.java 8225787 linux-x64
490490
java/awt/Dialog/MakeWindowAlwaysOnTop/MakeWindowAlwaysOnTop.java 8266243 macosx-aarch64
491+
java/awt/Dialog/PrintToFileTest/PrintToFileRevoked.java 8029249 macosx-all
492+
java/awt/Dialog/PrintToFileTest/PrintToFileGranted.java 8029249 macosx-all
491493
java/awt/dnd/DragSourceMotionListenerTest.java 8225131 windows-all
492494
java/awt/dnd/RejectDragTest.java 7124259 macosx-all
493495
java/awt/dnd/DnDHTMLToOutlookTest/DnDHTMLToOutlookTest.java 8027424 generic-all
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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.event.WindowListener;
27+
import java.util.List;
28+
29+
/*
30+
* @test
31+
* @bug 4058953 4094035
32+
* @summary Test to verify system menu of a dialog on win32
33+
* @requires (os.family == "windows")
34+
* @library /java/awt/regtesthelpers
35+
* @build PassFailJFrame
36+
* @run main/manual DialogSystemMenu
37+
*/
38+
39+
public class DialogSystemMenu {
40+
public static void main(String[] args) throws Exception {
41+
String INSTRUCTIONS = """
42+
1. Check the following on the first dialog window:
43+
Right-clicking on the title bar
44+
should bring up a system menu.
45+
The system menu should not allow any
46+
of the Maximize, Minimize and
47+
Restore actions
48+
49+
2. The second dialog should be non-resizable
50+
and have no application icon.
51+
""";
52+
PassFailJFrame.builder()
53+
.title("Test Instructions")
54+
.instructions(INSTRUCTIONS)
55+
.rows((int) INSTRUCTIONS.lines().count() + 2)
56+
.columns(35)
57+
.testUI(initialize())
58+
.build()
59+
.awaitAndCheck();
60+
}
61+
62+
public static List<Dialog> initialize() {
63+
Frame frame = new java.awt.Frame("Parent Frame");
64+
String txt = """
65+
This is a resizable dialog
66+
Right-clicking on the title bar
67+
should bring up a system menu
68+
The system menu should not
69+
allow any
70+
of the Maximize, Minimize and
71+
Restore actions
72+
""";
73+
String txt_non = """
74+
This is a non-resizable dialog
75+
It should be really non-resizable
76+
and have no application icon
77+
""";
78+
TestApp resizable = new TestApp(frame, "Test for 4058953", txt, true);
79+
resizable.setLocation(0, 0);
80+
81+
TestApp non_resizable = new TestApp(frame, "Test for 4094035", txt_non, false);
82+
non_resizable.setLocation(320, 0);
83+
return List.of(resizable, non_resizable);
84+
}
85+
}
86+
87+
88+
class TestApp extends Dialog implements WindowListener {
89+
public TestApp(java.awt.Frame parent, String title, String txt, boolean resize) {
90+
super(parent, title, false);
91+
92+
java.awt.TextArea ta = new java.awt.TextArea(txt);
93+
ta.setEditable(false);
94+
this.add(ta, "Center");
95+
this.addWindowListener(this);
96+
this.setSize(300, 200);
97+
this.setResizable(resize);
98+
}
99+
100+
101+
public void windowOpened(java.awt.event.WindowEvent myEvent) {
102+
}
103+
104+
public void windowClosed(java.awt.event.WindowEvent myEvent) {
105+
}
106+
107+
public void windowIconified(java.awt.event.WindowEvent myEvent) {
108+
}
109+
110+
public void windowDeiconified(java.awt.event.WindowEvent myEvent) {
111+
}
112+
113+
public void windowActivated(java.awt.event.WindowEvent myEvent) {
114+
}
115+
116+
public void windowDeactivated(java.awt.event.WindowEvent myEvent) {
117+
}
118+
119+
public void windowClosing(java.awt.event.WindowEvent myEvent) {
120+
this.dispose();
121+
}
122+
}

test/jdk/java/awt/Dialog/DialogSystemMenu/icon24x24.gif

Loading

test/jdk/java/awt/Dialog/DialogSystemMenu/iconone.gif

Loading

test/jdk/java/awt/Dialog/DialogSystemMenu/icontwo.gif

Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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.FileDialog;
25+
import java.awt.Frame;
26+
import java.io.File;
27+
import java.io.FilenameFilter;
28+
29+
/*
30+
* @test
31+
* @bug 4364256
32+
* @summary Test to File Dialog filter
33+
* @requires (os.family == "windows")
34+
* @library /java/awt/regtesthelpers
35+
* @build PassFailJFrame
36+
* @run main/manual FileDialogFilterTest
37+
*/
38+
39+
public class FileDialogFilterTest {
40+
public static void main(String[] args) throws Exception {
41+
String INSTRUCTIONS = """
42+
Run the test, make sure a file dialog
43+
comes up with no crash. If the file dialog
44+
comes up successfully then press PASS, else FAIL.
45+
""";
46+
PassFailJFrame.builder()
47+
.title("Test Instructions")
48+
.instructions(INSTRUCTIONS)
49+
.rows((int) INSTRUCTIONS.lines().count() + 2)
50+
.columns(35)
51+
.testUI(initialize())
52+
.build()
53+
.awaitAndCheck();
54+
}
55+
56+
public static FileDialog initialize() {
57+
FileDialog fDlg = new FileDialog(new Frame());
58+
fDlg.addNotify();
59+
fDlg.setFilenameFilter(new MyFilter());
60+
return fDlg;
61+
}
62+
}
63+
64+
class MyFilter implements FilenameFilter {
65+
public boolean accept(File dir, String name) {
66+
return true;
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import java.awt.Button;
2+
import java.awt.FlowLayout;
3+
import java.awt.Frame;
4+
import java.awt.PrintJob;
5+
import java.awt.event.ActionEvent;
6+
import java.awt.event.ActionListener;
7+
8+
class PrintToFileFrame extends Frame implements ActionListener {
9+
Button nativeDlg = new Button("Show print dialog");
10+
11+
public PrintToFileFrame() {
12+
this.setLayout(new FlowLayout());
13+
add(nativeDlg);
14+
nativeDlg.addActionListener(this);
15+
16+
setSize(300, 300);
17+
}
18+
19+
@SuppressWarnings("removal")
20+
public void actionPerformed(ActionEvent ae) {
21+
if (System.getSecurityManager() == null) {
22+
throw new RuntimeException("Security manager isn't installed.");
23+
}
24+
25+
try {
26+
System.getSecurityManager().checkPrintJobAccess();
27+
System.out.println("checkPrintJobAccess - OK");
28+
} catch (SecurityException e) {
29+
System.out.println("checkPrintJobAccess - ERROR " + e);
30+
}
31+
32+
PrintJob printJob = getToolkit().getPrintJob(this, null, null);
33+
34+
if (printJob != null) {
35+
System.out.println("Print Job: " + printJob);
36+
} else {
37+
System.out.println("Print Job is null.");
38+
}
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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.print.PrinterJob;
25+
26+
/*
27+
* @test
28+
* @bug 6275359
29+
* @summary Test to verify system menu of a dialog on win32
30+
* @requires (os.family == "windows")
31+
* @library /java/awt/regtesthelpers
32+
* @build PassFailJFrame
33+
* @compile PrintToFileFrame.java
34+
* @compile PrintToFileGranted.java
35+
* @run main/manual/policy=granted/othervm PrintToFileGranted
36+
*/
37+
38+
public class PrintToFileGranted {
39+
public static void main(String[] args) throws Exception {
40+
String INSTRUCTIONS;
41+
if (isPrintSupport()) {
42+
INSTRUCTIONS = """
43+
1. Click on 'Show file dialog' button A print dialog will come up
44+
2. If checkbox 'Print to file' is enabled then the test passed
45+
else the test failed
46+
3. Close the print dialog before pressing PASS or FAIL buttons
47+
""";
48+
} else {
49+
INSTRUCTIONS = """
50+
1. The test requires printer installed in your system,
51+
but there is no printers found
52+
Please install one and re-run the test
53+
""";
54+
}
55+
56+
PassFailJFrame.builder()
57+
.title("Test Instructions")
58+
.instructions(INSTRUCTIONS)
59+
.rows((int) INSTRUCTIONS.lines().count() + 2)
60+
.columns(35)
61+
.testUI(new PrintToFileFrame())
62+
.build()
63+
.awaitAndCheck();
64+
}
65+
66+
public static boolean isPrintSupport() {
67+
PrinterJob pj = PrinterJob.getPrinterJob();
68+
return pj.getPrintService() != null;
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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.print.PrinterJob;
25+
26+
/*
27+
* @test
28+
* @bug 6275359
29+
* @summary Test to verify Printing ignores Security permissions
30+
* using native dialog
31+
* @requires (os.family == "windows")
32+
* @library /java/awt/regtesthelpers
33+
* @build PassFailJFrame
34+
* @compile PrintToFileRevoked.java
35+
* @run main/manual/policy=revoked/othervm PrintToFileRevoked
36+
*/
37+
38+
public class PrintToFileRevoked {
39+
public static void main(String[] args) throws Exception {
40+
String INSTRUCTIONS;
41+
if (isPrintSupport()) {
42+
INSTRUCTIONS = """
43+
1. Click on 'Show file dialog' button A print dialog will come up
44+
2. If checkbox 'Print to file' is disabled then the test passed
45+
else the test failed
46+
3. Close the print dialog before pressing PASS or FAIL buttons
47+
""";
48+
} else {
49+
INSTRUCTIONS = """
50+
1. The test requires printer installed in your system,
51+
but there is no printers found
52+
Please install one and re-run the test
53+
""";
54+
}
55+
PassFailJFrame.builder()
56+
.title("Test Instructions")
57+
.instructions(INSTRUCTIONS)
58+
.rows((int) INSTRUCTIONS.lines().count() + 2)
59+
.columns(35)
60+
.testUI(new PrintToFileFrame())
61+
.build()
62+
.awaitAndCheck();
63+
}
64+
65+
public static boolean isPrintSupport() {
66+
PrinterJob pj = PrinterJob.getPrinterJob();
67+
return pj.getPrintService() != null;
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* AUTOMATICALLY GENERATED ON Thu Jan 03 15:48:39 PST 2002*/
2+
/* DO NOT EDIT */
3+
4+
grant {
5+
permission java.lang.RuntimePermission "queuePrintJob";
6+
permission java.util.PropertyPermission "*", "read";
7+
permission java.io.FilePermission "<<ALL FILES>>", "read";
8+
permission java.io.FilePermission "<<ALL FILES>>", "write";
9+
permission java.lang.RuntimePermission "accessClassInPackage.sun.util.locale.provider";
10+
};

0 commit comments

Comments
 (0)