Skip to content

Commit 486a664

Browse files
author
Harshitha Onkar
committed
8353486: Open source Swing Tests - Set 4
Reviewed-by: azvegint, dnguyen, tr
1 parent f98af0a commit 486a664

File tree

5 files changed

+462
-0
lines changed

5 files changed

+462
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2003, 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 4464774
27+
* @requires (os.family == "windows")
28+
* @summary JFileChooser: selection of left-side folder buttons shown incorrectly
29+
in Windows L&F
30+
* @library /java/awt/regtesthelpers
31+
* @build PassFailJFrame
32+
* @run main/manual bug4464774
33+
*/
34+
35+
import javax.swing.JFileChooser;
36+
import javax.swing.UIManager;
37+
38+
public class bug4464774 {
39+
private static final String INSTRUCTIONS = """
40+
Click any button from the buttons to the left
41+
("Documents", "Desktop", "My Computer" etc.) in FileChooser dialog.
42+
When the button is toggled, it should be lowered and
43+
should NOT have focus painted inside it (black dotted frame).
44+
45+
If the above is true, press PASS else FAIL.
46+
""";
47+
48+
public static void main(String[] argv) throws Exception {
49+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
50+
PassFailJFrame.builder()
51+
.instructions(INSTRUCTIONS)
52+
.columns(65)
53+
.rows(10)
54+
.testUI(() -> {
55+
JFileChooser jfc = new JFileChooser();
56+
jfc.setControlButtonsAreShown(false);
57+
return jfc;
58+
})
59+
.build()
60+
.awaitAndCheck();
61+
}
62+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 4522756
27+
* @requires (os.family == "windows")
28+
* @summary Verifies that the Desktop icon is not missing when
29+
JFileChooser is opened for the first time.
30+
* @library /java/awt/regtesthelpers
31+
* @build PassFailJFrame
32+
* @run main/manual bug4522756
33+
*/
34+
35+
import javax.swing.JFileChooser;
36+
import javax.swing.UIManager;
37+
38+
public class bug4522756 {
39+
private static final String INSTRUCTIONS = """
40+
Verify the following:
41+
42+
1. If Desktop icon image is present on the Desktop button
43+
on the left panel of JFileChooser.
44+
2. Press Desktop button. Check that you actually
45+
go up to the desktop.
46+
47+
If the above is true, press PASS else FAIL.
48+
""";
49+
50+
public static void main(String[] args) throws Exception {
51+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
52+
PassFailJFrame.builder()
53+
.instructions(INSTRUCTIONS)
54+
.columns(50)
55+
.rows(12)
56+
.testUI(() -> {
57+
JFileChooser jfc = new JFileChooser();
58+
jfc.setControlButtonsAreShown(false);
59+
return jfc;
60+
})
61+
.build()
62+
.awaitAndCheck();
63+
}
64+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* Copyright (c) 2003, 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+
* @key headful
27+
* @bug 4759934
28+
* @summary windows activation problem
29+
* @library /javax/swing/regtesthelpers
30+
* @build Util
31+
* @run main bug4759934
32+
*/
33+
34+
import java.awt.Dialog;
35+
import java.awt.Point;
36+
import java.awt.Robot;
37+
import java.awt.event.KeyEvent;
38+
import java.awt.event.MouseEvent;
39+
import javax.swing.JButton;
40+
import javax.swing.JDialog;
41+
import javax.swing.JFileChooser;
42+
import javax.swing.JFrame;
43+
import javax.swing.SwingUtilities;
44+
45+
public class bug4759934 {
46+
private static JFrame fr;
47+
private static Dialog dlg;
48+
private static JFileChooser jfc;
49+
50+
private static JButton frameBtn;
51+
private static JButton dialogBtn;
52+
53+
public static void main(String[] args) throws Exception {
54+
try {
55+
Robot robot = new Robot();
56+
robot.setAutoWaitForIdle(true);
57+
robot.setAutoDelay(50);
58+
59+
SwingUtilities.invokeAndWait(bug4759934::createTestUI);
60+
robot.waitForIdle();
61+
robot.delay(1000);
62+
63+
Point frameBtnLoc = Util.getCenterPoint(frameBtn);
64+
robot.mouseMove(frameBtnLoc.x, frameBtnLoc.y);
65+
robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
66+
robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
67+
robot.delay(500);
68+
69+
Point dlgBtnLoc = Util.getCenterPoint(dialogBtn);
70+
robot.mouseMove(dlgBtnLoc.x , dlgBtnLoc.y);
71+
robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
72+
robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
73+
robot.delay(500);
74+
75+
robot.keyPress(KeyEvent.VK_ESCAPE);
76+
robot.keyRelease(KeyEvent.VK_ESCAPE);
77+
robot.delay(500);
78+
79+
SwingUtilities.invokeAndWait(() -> {
80+
if (frameBtn.hasFocus() && !dialogBtn.hasFocus()) {
81+
throw new RuntimeException("Test failed! Focus was passed back" +
82+
" to Frame instead of Dialog");
83+
}
84+
});
85+
} finally {
86+
SwingUtilities.invokeAndWait(() -> {
87+
if (dlg != null) {
88+
dlg.dispose();
89+
}
90+
if (fr != null) {
91+
fr.dispose();
92+
}
93+
});
94+
}
95+
}
96+
97+
private static void createTestUI() {
98+
fr = new JFrame("bug4759934 - JFrame");
99+
100+
frameBtn = new JButton("Show Dialog");
101+
frameBtn.addActionListener(e -> createDialog());
102+
fr.add(frameBtn);
103+
104+
fr.setSize(300, 200);
105+
fr.setLocationRelativeTo(null);
106+
fr.setVisible(true);
107+
}
108+
109+
private static void createDialog() {
110+
dlg = new JDialog(fr, "bug4759934 - JDialog");
111+
112+
dialogBtn = new JButton("Show FileChooser");
113+
dlg.add(dialogBtn);
114+
115+
dialogBtn.addActionListener(e -> {
116+
jfc = new JFileChooser();
117+
jfc.showOpenDialog(dlg);
118+
});
119+
120+
dlg.setSize(300, 200);
121+
dlg.setLocation(fr.getX() + fr.getWidth() + 10, fr.getY());
122+
dlg.setVisible(true);
123+
}
124+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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 4943900
27+
* @summary Tests that FileFilter combo box is shown in FileChooser
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4943900
31+
*/
32+
33+
import java.io.File;
34+
import javax.swing.JFileChooser;
35+
import javax.swing.JFrame;
36+
import javax.swing.UIManager;
37+
import javax.swing.filechooser.FileFilter;
38+
39+
public class bug4943900 {
40+
private static final String INSTRUCTIONS = """
41+
<html>
42+
<ol>
43+
<li>When the test runs, a <code>JFileChooser</code> will be displayed.
44+
<li>Ensure that there is a filter combo box with these two items:
45+
<ul>
46+
<li><b>Text Files (*.txt)</b>
47+
&mdash; <em>[must be selected when the dialog opens]</em>
48+
<li><b>All Files</b>
49+
</ul>
50+
<li>Leave the <b>Text files</b> item selected and check that the
51+
filter works: only <code>*.txt</code> files can appear in the file list.
52+
You can navigate directories in the file chooser and find one
53+
that contains some <code>*.txt</code> files to ensure they are shown in
54+
the file list. On macOS when the text filter is applied verify
55+
that the non-text files are greyed out.
56+
<li>Try switching the filters and ensure that the file list
57+
is updated properly.
58+
<li>If the <code>FileFilter</code> works correctly,
59+
press <b>Pass</b> else press <b>Fail</b>.
60+
</ol>
61+
</html>
62+
""";
63+
64+
public static void main(String[] args) throws Exception {
65+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
66+
67+
PassFailJFrame.builder()
68+
.title("bug4943900 Test Instructions")
69+
.instructions(INSTRUCTIONS)
70+
.rows(14)
71+
.columns(50)
72+
.testUI(bug4943900::createAndShowUI)
73+
.build()
74+
.awaitAndCheck();
75+
}
76+
77+
public static JFrame createAndShowUI() {
78+
JFileChooser fc = new JFileChooser();
79+
fc.setControlButtonsAreShown(false);
80+
TextFileFilter filter = new TextFileFilter();
81+
fc.setFileFilter(filter);
82+
83+
JFrame frame = new JFrame("bug4943900 - JFileChooser");
84+
frame.add(fc);
85+
frame.pack();
86+
return frame;
87+
}
88+
89+
private static final class TextFileFilter extends FileFilter {
90+
@Override
91+
public boolean accept(File f) {
92+
if (f != null) {
93+
if (f.isDirectory()) {
94+
return true;
95+
}
96+
String extension = getExtension(f);
97+
return extension != null && extension.equals("txt");
98+
}
99+
return false;
100+
}
101+
102+
@Override
103+
public String getDescription() {
104+
return "Text Files (*.txt)";
105+
}
106+
107+
private static String getExtension(File f) {
108+
if (f != null) {
109+
String filename = f.getName();
110+
int i = filename.lastIndexOf('.');
111+
if (i > 0 && i < filename.length() - 1) {
112+
return filename.substring(i + 1).toLowerCase();
113+
}
114+
}
115+
return null;
116+
}
117+
}
118+
}

0 commit comments

Comments
 (0)