Skip to content

Commit 89ad022

Browse files
committed
8341191: Open source few more AWT FileDialog tests
Backport-of: 50ec169116b486a49dc2dcb4218264bd48db79cc
1 parent 97b7430 commit 89ad022

File tree

4 files changed

+328
-0
lines changed

4 files changed

+328
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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.Button;
25+
import java.awt.FileDialog;
26+
import java.awt.Frame;
27+
28+
import java.awt.event.ActionEvent;
29+
import java.awt.event.ActionListener;
30+
31+
/*
32+
* @test
33+
* @bug 6259434
34+
* @summary PIT: Choice in FileDialog is not responding to keyboard interactions, XToolkit
35+
* @requires (os.family == "linux")
36+
* @library /java/awt/regtesthelpers
37+
* @build PassFailJFrame
38+
* @run main/manual KeyboardInteractionTest
39+
*/
40+
41+
public class KeyboardInteractionTest {
42+
public static void main(String[] args) throws Exception {
43+
System.setProperty("sun.awt.disableGtkFileDialogs", "true");
44+
String INSTRUCTIONS = """
45+
1) Click on 'Show File Dialog' button to bring up the FileDialog window.
46+
A file dialog will come up.
47+
2) You will see a text field 'Enter full path or filename'.
48+
Right next to it, you will see a button.
49+
Transfer the focus on this button using 'TAB'.
50+
Make sure that the popup choice is not shown.
51+
3) Press 'ESC'. If file dialog isn't disposed, then the test failed.
52+
4) Again, click on 'Show File Dialog' to bring up the file dialog.
53+
A file dialog will come up.
54+
5) You will see a text field 'Enter full path or filename'.
55+
Right next to it, you will see a button.
56+
Click on this button. The popup choice will appear.
57+
6) Look at the popup choice. Change the current item in the popup
58+
choice by the arrow keys.
59+
If the text in the 'Enter full path or filename' text field isn't
60+
changed, then the test failed.
61+
7) The test passed.
62+
""";
63+
64+
PassFailJFrame.builder()
65+
.title("KeyboardInteractionTest Instruction")
66+
.instructions(INSTRUCTIONS)
67+
.columns(40)
68+
.testUI(KeyboardInteractionTest::createUI)
69+
.build()
70+
.awaitAndCheck();
71+
}
72+
73+
public static Frame createUI() {
74+
Frame f = new Frame("KeyboardInteractionTest Test");
75+
Button b = new Button("Show File Dialog");
76+
FileDialog fd = new FileDialog(f);
77+
b.addActionListener(new ActionListener() {
78+
@Override
79+
public void actionPerformed(ActionEvent e) {
80+
fd.setVisible(true);
81+
}
82+
});
83+
f.add(b);
84+
f.setSize(300, 200);
85+
return f;
86+
}
87+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.Button;
25+
import java.awt.FileDialog;
26+
import java.awt.Frame;
27+
28+
import java.awt.event.ActionEvent;
29+
import java.awt.event.ActionListener;
30+
31+
/*
32+
* @test
33+
* @bug 6240084
34+
* @summary Test that disposing unfurled list by the pressing ESC
35+
* in FileDialog is working properly on XToolkit
36+
* @library /java/awt/regtesthelpers
37+
* @build PassFailJFrame
38+
* @run main/manual PathChoiceDisposeTest
39+
*/
40+
41+
public class PathChoiceDisposeTest {
42+
public static void main(String[] args) throws Exception {
43+
System.setProperty("sun.awt.disableGtkFileDialogs", "true");
44+
String INSTRUCTIONS = """
45+
1) Click on 'Show File Dialog' button to bring up the FileDialog window.
46+
2) Open the directory selection choice by clicking button next to
47+
'Enter Path or Folder Name'. A drop-down will appear.
48+
3) Press 'ESC'.
49+
4) If you see that the dialog gets disposed and the popup
50+
still remains on the screen, the test failed, otherwise passed.
51+
""";
52+
53+
PassFailJFrame.builder()
54+
.title("PathChoiceDisposeTest Instruction")
55+
.instructions(INSTRUCTIONS)
56+
.columns(40)
57+
.testUI(PathChoiceDisposeTest::createUI)
58+
.build()
59+
.awaitAndCheck();
60+
}
61+
62+
public static Frame createUI() {
63+
Frame f = new Frame("PathChoiceDisposeTest Test");
64+
Button b = new Button("Show File Dialog");
65+
FileDialog fd = new FileDialog(f);
66+
b.addActionListener(new ActionListener() {
67+
@Override
68+
public void actionPerformed(ActionEvent e) {
69+
fd.setVisible(true);
70+
}
71+
});
72+
f.add(b);
73+
f.setSize(300, 200);
74+
return f;
75+
}
76+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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.Button;
25+
import java.awt.FileDialog;
26+
import java.awt.Frame;
27+
28+
import java.awt.event.ActionEvent;
29+
import java.awt.event.ActionListener;
30+
31+
/*
32+
* @test
33+
* @bug 6240074
34+
* @summary Test that file drop-down field in FileDialog is working properly on XToolkit
35+
* @requires (os.family == "linux")
36+
* @library /java/awt/regtesthelpers
37+
* @build PassFailJFrame
38+
* @run main/manual PathChoiceWorkArrowsTest
39+
*/
40+
41+
public class PathChoiceWorkArrowsTest {
42+
public static void main(String[] args) throws Exception {
43+
System.setProperty("sun.awt.disableGtkFileDialogs", "true");
44+
String INSTRUCTIONS = """
45+
This is only XAWT test.
46+
47+
1) Click on 'Show File Dialog' to bring up the FileDialog window.
48+
A file dialog would come up.
49+
2) Click on the button next to 'Enter folder name' field.
50+
A drop-down will appear. After this, there are 2 scenarios.
51+
3) Press the down arrow one by one. You will see a '/' being
52+
appended as soon as the current entry is removed.
53+
Keep pressing till the last entry is reached. Now the drop-down
54+
will stop responding to arrow keys. If yes, the test failed.
55+
4) Press the up arrow. The cursor will directly go to the last
56+
entry ('/') and navigation will stop there. You will see 2
57+
entries being selected at the same time.
58+
If yes, the test failed.
59+
""";
60+
61+
PassFailJFrame.builder()
62+
.title("PathChoiceWorkArrowsTest Instruction")
63+
.instructions(INSTRUCTIONS)
64+
.columns(40)
65+
.testUI(PathChoiceWorkArrowsTest::createUI)
66+
.build()
67+
.awaitAndCheck();
68+
}
69+
70+
public static Frame createUI() {
71+
Frame f = new Frame("PathChoiceWorkArrowsTest Test");
72+
Button b = new Button("Show File Dialog");
73+
FileDialog fd = new FileDialog(f);
74+
b.addActionListener(new ActionListener() {
75+
@Override
76+
public void actionPerformed(ActionEvent e) {
77+
fd.setSize(200, 200);
78+
fd.setLocation(200, 200);
79+
fd.setVisible(true);
80+
}
81+
});
82+
f.add(b);
83+
f.setSize(300, 200);
84+
return f;
85+
}
86+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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.Button;
25+
import java.awt.FileDialog;
26+
import java.awt.Frame;
27+
28+
import java.awt.event.ActionEvent;
29+
import java.awt.event.ActionListener;
30+
31+
/*
32+
* @test
33+
* @bug 6260650
34+
* @summary FileDialog.getDirectory() does not return null when file dialog is cancelled
35+
* @library /java/awt/regtesthelpers
36+
* @build PassFailJFrame
37+
* @run main/manual SavedDirInitTest
38+
*/
39+
40+
public class SavedDirInitTest {
41+
public static void main(String[] args) throws Exception {
42+
String INSTRUCTIONS = """
43+
Click on 'Show File Dialog' button to bring up the FileDialog window.
44+
1) A file dialog will come up.
45+
2) Press 'Cancel' button to cancel the file dialog.
46+
3) The result (passed or failed) will be shown in the message window below.
47+
""";
48+
49+
PassFailJFrame.builder()
50+
.title("SavedDirInitTest Instruction")
51+
.instructions(INSTRUCTIONS)
52+
.columns(40)
53+
.testUI(SavedDirInitTest::createUI)
54+
.logArea(2)
55+
.build()
56+
.awaitAndCheck();
57+
}
58+
59+
public static Frame createUI() {
60+
Frame f = new Frame("SavedDirInitTest Test");
61+
Button b = new Button("Show File Dialog");
62+
FileDialog fd = new FileDialog(f);
63+
b.addActionListener(new ActionListener() {
64+
@Override
65+
public void actionPerformed(ActionEvent e) {
66+
fd.setVisible(true);
67+
if (fd.getDirectory() == null && fd.getFile() == null) {
68+
PassFailJFrame.log("TEST PASSED");
69+
} else {
70+
PassFailJFrame.log("TEST FAILED. dir = " + fd.getDirectory()
71+
+ " , file = " + fd.getFile());
72+
}
73+
}
74+
});
75+
f.add(b);
76+
f.setSize(300, 200);
77+
return f;
78+
}
79+
}

0 commit comments

Comments
 (0)