Skip to content

Commit 9b3765f

Browse files
committed
8327972: Convert java/awt/FileDialog/SaveFileNameOverrideTest/SaveFileNameOverrideTest.html applet test to main
Backport-of: 7283c8b075aa289dbb9cb80f6937b3349c8d4769
1 parent e120d5f commit 9b3765f

File tree

3 files changed

+91
-134
lines changed

3 files changed

+91
-134
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (c) 2011, 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 javax.swing.JButton;
25+
import java.awt.FileDialog;
26+
import java.awt.Frame;
27+
import java.io.File;
28+
29+
/*
30+
* @test
31+
* @bug 6998877 8022531
32+
* @summary After double-click on the folder names, FileNameOverrideTest FAILED
33+
* @library /java/awt/regtesthelpers
34+
* @build PassFailJFrame
35+
* @run main/manual SaveFileNameOverrideTest
36+
*/
37+
38+
public class SaveFileNameOverrideTest {
39+
40+
private final static String clickDirName = "Directory for double click";
41+
private static final String INSTRUCTIONS =
42+
"""
43+
1) Click on the 'Show File Dialog' button. A file dialog will appear.
44+
2) Double-click on '%s'
45+
3) Click on a confirmation button.
46+
(It can be 'OK', 'Save' or any other name depending on the platform).
47+
3) The test will automatically pass or fail.
48+
"""
49+
.formatted(clickDirName);
50+
private final static String dirPath = ".";
51+
52+
public static void main(String[] args) throws Exception {
53+
System.out.println(System.getProperties());
54+
System.out.println(new File(dirPath).getAbsolutePath());
55+
File tmpDir = new File(dirPath + File.separator + clickDirName);
56+
if (!tmpDir.mkdir()) {
57+
throw new RuntimeException("Cannot create directory.");
58+
}
59+
tmpDir.deleteOnExit();
60+
61+
PassFailJFrame
62+
.builder()
63+
.title("SaveFileNameOverrideTest Instructions")
64+
.instructions(INSTRUCTIONS)
65+
.splitUIRight(SaveFileNameOverrideTest::getButton)
66+
.rows(8)
67+
.columns(40)
68+
.build()
69+
.awaitAndCheck();
70+
}
71+
72+
public static JButton getButton() {
73+
JButton showBtn = new JButton("Show File Dialog");
74+
showBtn.addActionListener(e -> {
75+
FileDialog fd =
76+
new FileDialog((Frame) null, "Save", FileDialog.SAVE);
77+
78+
fd.setFile("input");
79+
fd.setDirectory(new File(dirPath).getAbsolutePath());
80+
fd.setVisible(true);
81+
82+
String output = fd.getFile();
83+
if ("input".equals(output)) {
84+
PassFailJFrame.forcePass();
85+
} else {
86+
PassFailJFrame.forceFail("TEST FAILED (output file - " + output + ")");
87+
}
88+
});
89+
return showBtn;
90+
}
91+
}

test/jdk/java/awt/FileDialog/SaveFileNameOverrideTest/SaveFileNameOverrideTest.html

Lines changed: 0 additions & 45 deletions
This file was deleted.

test/jdk/java/awt/FileDialog/SaveFileNameOverrideTest/SaveFileNameOverrideTest.java

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)