|
| 1 | +/* |
| 2 | + * Copyright (c) 2004, 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.awt.Toolkit; |
| 27 | +import java.lang.reflect.InvocationTargetException; |
| 28 | +import javax.swing.JButton; |
| 29 | +import jtreg.SkippedException; |
| 30 | + |
| 31 | +/* |
| 32 | + * @test |
| 33 | + * @bug 4974135 |
| 34 | + * @summary FileDialog should open current directory by default. |
| 35 | + * @requires (os.family == "linux") |
| 36 | + * @library /java/awt/regtesthelpers |
| 37 | + * @library /test/lib |
| 38 | + * @build PassFailJFrame |
| 39 | + * @build jtreg.SkippedException |
| 40 | + * @run main/manual FileDialogOpenDirTest |
| 41 | + */ |
| 42 | + |
| 43 | +public class FileDialogOpenDirTest { |
| 44 | + private static JButton initialize() { |
| 45 | + System.setProperty("sun.awt.disableGtkFileDialogs", "true"); |
| 46 | + |
| 47 | + JButton open = new JButton("Open File Dialog"); |
| 48 | + open.addActionListener(e -> { |
| 49 | + new FileDialog((Frame) null).setVisible(true); |
| 50 | + }); |
| 51 | + |
| 52 | + return open; |
| 53 | + } |
| 54 | + |
| 55 | + public static void main(String[] args) throws InterruptedException, |
| 56 | + InvocationTargetException { |
| 57 | + String toolkit = Toolkit.getDefaultToolkit().getClass().getName(); |
| 58 | + if (!toolkit.equals("sun.awt.X11.XToolkit")) { |
| 59 | + throw new SkippedException("Test is not designed for toolkit " + toolkit); |
| 60 | + } |
| 61 | + |
| 62 | + String curdir = System.getProperty("user.dir"); |
| 63 | + String instructions = """ |
| 64 | + Click the \"Open File Dialog\" button below to open FileDialog. |
| 65 | + Verify that the directory opened is current directory, that is: |
| 66 | + $curdir, |
| 67 | + If so press Pass, otherwise press Fail |
| 68 | + """.replace("$curdir", curdir); |
| 69 | + |
| 70 | + PassFailJFrame.builder() |
| 71 | + .title("Directory File Dialog Test Instructions") |
| 72 | + .instructions(instructions) |
| 73 | + .rows((int) instructions.lines().count() + 1) |
| 74 | + .columns(40) |
| 75 | + .splitUIBottom(FileDialogOpenDirTest::initialize) |
| 76 | + .build() |
| 77 | + .awaitAndCheck(); |
| 78 | + } |
| 79 | +} |
0 commit comments