Skip to content

Commit bd73127

Browse files
author
Harshitha Onkar
committed
8354532: Open source JFileChooser Tests - Set 7
Reviewed-by: prr
1 parent 76dec47 commit bd73127

File tree

4 files changed

+387
-0
lines changed

4 files changed

+387
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright (c) 2002, 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+
/*
25+
* @test
26+
* @bug 4357012
27+
* @requires (os.family == "windows")
28+
* @summary JFileChooser.showSaveDialog inconsistent with Windows Save Dialog
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual bug4357012
32+
*/
33+
34+
import java.io.File;
35+
import java.io.IOException;
36+
import javax.swing.JComponent;
37+
import javax.swing.JFileChooser;
38+
import javax.swing.UIManager;
39+
40+
public class bug4357012 {
41+
private static File workDir = null;
42+
private static File dir = null;
43+
private static File file = null;
44+
private static final String INSTRUCTIONS = """
45+
<html>
46+
Test is for Windows LAF only
47+
<p>In JFileChooser's files list :
48+
<ol>
49+
<li>Select directory. Verify that the directory name doesn't
50+
appear in "file name" field.</li>
51+
<li>Select file. Verify that the file name appears in
52+
"file name" field.</li>
53+
<li>Select directory again. Verify that the previous file name
54+
remains in file name field.</li>
55+
</ol>
56+
</p>
57+
</html>
58+
""";
59+
60+
public static void main(String[] argv) throws Exception {
61+
try {
62+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
63+
createTestDir();
64+
PassFailJFrame.builder()
65+
.instructions(INSTRUCTIONS)
66+
.rows(10)
67+
.columns(40)
68+
.testUI(bug4357012::createTestUI)
69+
.build()
70+
.awaitAndCheck();
71+
} finally {
72+
if (workDir != null) {
73+
System.out.println("Deleting '" + file + "': " + file.delete());
74+
System.out.println("Deleting '" + dir + "': " + dir.delete());
75+
System.out.println("Deleting '" + workDir + "': " + workDir.delete());
76+
}
77+
}
78+
}
79+
80+
private static void createTestDir() throws IOException {
81+
String tempDir = ".";
82+
String fs = System.getProperty("file.separator");
83+
84+
workDir = new File(tempDir + fs + "bug4357012");
85+
System.out.println("Creating '" + workDir + "': " + workDir.mkdir());
86+
87+
dir = new File(workDir + fs + "Directory");
88+
System.out.println("Creating '" + dir + "': " + dir.mkdir());
89+
90+
file = new File(workDir + fs + "File.txt");
91+
System.out.println("Creating '" + file + "': " + file.createNewFile());
92+
}
93+
94+
private static JComponent createTestUI() {
95+
JFileChooser fc = new JFileChooser(workDir);
96+
fc.setDialogType(JFileChooser.SAVE_DIALOG);
97+
return fc;
98+
}
99+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright (c) 2011, 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+
/*
25+
* @test
26+
* @bug 4926884
27+
* @requires (os.family == "windows")
28+
* @summary Win L&F: JFileChooser problems with "My Documents" folder
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual bug4926884
32+
*/
33+
34+
import java.io.File;
35+
import java.io.FileOutputStream;
36+
import java.io.IOException;
37+
import java.io.OutputStream;
38+
import javax.swing.JFileChooser;
39+
import javax.swing.UIManager;
40+
41+
public class bug4926884 {
42+
private static final String INSTRUCTIONS = """
43+
Validate next statements step by step:
44+
45+
1. In the file list there are several dirs and files (like "ski",
46+
"Snowboard" etc.)
47+
2. Select "Details" view mode.
48+
3. Make file list in focus (e.g. by pressing mouse button)
49+
4. Press key "w" several times with delay LESS than 1 second.
50+
Selection should be changed across files started with letter "w"
51+
(without case sensitive).
52+
5. Press key "w" several times with delay MORE than 1 second.
53+
Selection should be changed across files started with letter "w"
54+
(without case sensitive).
55+
6. Type "winnt" (with delay less than 1 second between letters) -
56+
directory "winnt" should be selected.
57+
7. Change conditions:
58+
- Move column "Name" to the second position
59+
- Change sort mode by clicking column "Size"
60+
8. Repeat items 4-6
61+
62+
If above is true press PASS else FAIL
63+
""";
64+
65+
private static final String[] DIRS = {"www", "winnt", "ski"};
66+
private static final String[] FILES = {"Window", "weel", "mice",
67+
"Wall", "Snowboard", "wood"};
68+
private static final File testDir = new File(".");
69+
70+
public static void main(String[] argv) throws Exception {
71+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
72+
try {
73+
createTestDir();
74+
PassFailJFrame.builder()
75+
.instructions(INSTRUCTIONS)
76+
.columns(40)
77+
.testUI(() -> new JFileChooser(testDir))
78+
.build()
79+
.awaitAndCheck();
80+
} finally {
81+
deleteTempDir();
82+
}
83+
}
84+
85+
private static void createTestDir() throws IOException {
86+
testDir.mkdir();
87+
88+
for (String dir : DIRS) {
89+
new File(testDir, dir).mkdir();
90+
}
91+
92+
for (int i = 0; i < FILES.length; i++) {
93+
94+
try (OutputStream outputStream = new FileOutputStream(
95+
new File(testDir, FILES[i]))) {
96+
for (int j = 0; j < i * 1024; j++) {
97+
outputStream.write('#');
98+
}
99+
}
100+
}
101+
}
102+
103+
private static void deleteTempDir() {
104+
File[] files = testDir.listFiles();
105+
106+
for (File file : files) {
107+
if (file != null) {
108+
file.delete();
109+
}
110+
}
111+
112+
testDir.delete();
113+
}
114+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2004, 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+
/*
25+
* @test
26+
* @bug 5045464
27+
* @requires (os.family == "linux")
28+
* @summary Regression: GTK L&F, JFileChooser shows "null/" in folder list
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual bug5045464
32+
*/
33+
34+
import javax.swing.JComponent;
35+
import javax.swing.JFileChooser;
36+
import javax.swing.SwingUtilities;
37+
import javax.swing.UIManager;
38+
39+
public class bug5045464 {
40+
private static final String INSTRUCTIONS = """
41+
When the filechooser appears check the directory list (the left list).
42+
If it starts with two items: "./" (current directory)
43+
and "../" (parent directory) press PASS.
44+
If something else is here (e.g. "null/" instead of "./")
45+
press FAIL.
46+
""";
47+
48+
public static void main(String[] argv) throws Exception {
49+
PassFailJFrame.builder()
50+
.instructions(INSTRUCTIONS)
51+
.columns(40)
52+
.testUI(bug5045464::createTestUI)
53+
.build()
54+
.awaitAndCheck();
55+
}
56+
57+
private static JComponent createTestUI() {
58+
JFileChooser fc = new JFileChooser();
59+
fc.setControlButtonsAreShown(false);
60+
try {
61+
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
62+
} catch (Exception ex) {
63+
throw new RuntimeException("Test Failed!", ex);
64+
}
65+
SwingUtilities.updateComponentTreeUI(fc);
66+
return fc;
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright (c) 2011, 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+
/*
25+
* @test
26+
* @bug 6515169
27+
* @requires (os.family == "windows")
28+
* @summary wrong grid header in JFileChooser
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual bug6515169
32+
*/
33+
34+
import javax.swing.ButtonGroup;
35+
import javax.swing.JCheckBoxMenuItem;
36+
import javax.swing.JFileChooser;
37+
import javax.swing.JFrame;
38+
import javax.swing.JMenu;
39+
import javax.swing.JMenuBar;
40+
import javax.swing.SwingUtilities;
41+
import javax.swing.UIManager;
42+
43+
public class bug6515169 {
44+
private static JFrame frame;
45+
private static final String INSTRUCTIONS = """
46+
This test is to verify JFileChooser on Windows and Metal LAF.
47+
Use the "Change LaF" menu to switch between the 2 LaF
48+
and verify the following.
49+
50+
a. Change view mode to "Details"
51+
b. Check that 4 columns appear: Name, Size, Type and Date Modified
52+
c. Change current directory by pressing any available subdirectory
53+
or by pressing button "Up One Level".
54+
d. Check that still four columns exist.
55+
56+
Change LaF and repeat the steps a-d.
57+
If all conditions are true press PASS, else FAIL.
58+
""";
59+
60+
public static void main(String[] argv) throws Exception {
61+
PassFailJFrame.builder()
62+
.instructions(INSTRUCTIONS)
63+
.columns(40)
64+
.testUI(bug6515169::createTestUI)
65+
.build()
66+
.awaitAndCheck();
67+
}
68+
69+
private static JFrame createTestUI() {
70+
frame = new JFrame("bug6515169");
71+
JMenuBar bar = new JMenuBar();
72+
JMenu lafMenu = new JMenu("Change LaF");
73+
ButtonGroup lafGroup = new ButtonGroup();
74+
JCheckBoxMenuItem lafItem1 = new JCheckBoxMenuItem("Window LaF");
75+
lafItem1.addActionListener(e ->
76+
setLaF(UIManager.getSystemLookAndFeelClassName()));
77+
lafGroup.add(lafItem1);
78+
lafMenu.add(lafItem1);
79+
80+
JCheckBoxMenuItem lafItem2 = new JCheckBoxMenuItem("Metal LaF");
81+
lafItem2.addActionListener(e ->
82+
setLaF(UIManager.getCrossPlatformLookAndFeelClassName()));
83+
lafGroup.add(lafItem2);
84+
lafMenu.add(lafItem2);
85+
86+
bar.add(lafMenu);
87+
frame.setJMenuBar(bar);
88+
89+
String dir = ".";
90+
JFileChooser fc = new JFileChooser(dir);
91+
fc.setControlButtonsAreShown(false);
92+
frame.add(fc);
93+
frame.pack();
94+
95+
return frame;
96+
}
97+
98+
private static void setLaF(String laf) {
99+
try {
100+
UIManager.setLookAndFeel(laf);
101+
SwingUtilities.updateComponentTreeUI(frame);
102+
} catch (Exception e) {
103+
throw new RuntimeException("Test Failed!", e);
104+
}
105+
}
106+
}

0 commit comments

Comments
 (0)