From 4e703b285b5b34fdfb342d194cd744660d4c2be1 Mon Sep 17 00:00:00 2001 From: Alisen Chung Date: Wed, 16 Oct 2024 21:57:15 +0000 Subject: [PATCH] 8340140: Open some dialog awt tests 3 Reviewed-by: prr, honkar --- .../java/awt/Dialog/ClosingParentTest.java | 100 +++++++++++++++++ .../awt/Dialog/FileDialogEmptyTitleTest.java | 59 ++++++++++ .../java/awt/Dialog/FileDialogUIUpdate.java | 83 ++++++++++++++ .../awt/Dialog/MenuAndModalDialogTest.java | 104 ++++++++++++++++++ 4 files changed, 346 insertions(+) create mode 100644 test/jdk/java/awt/Dialog/ClosingParentTest.java create mode 100644 test/jdk/java/awt/Dialog/FileDialogEmptyTitleTest.java create mode 100644 test/jdk/java/awt/Dialog/FileDialogUIUpdate.java create mode 100644 test/jdk/java/awt/Dialog/MenuAndModalDialogTest.java diff --git a/test/jdk/java/awt/Dialog/ClosingParentTest.java b/test/jdk/java/awt/Dialog/ClosingParentTest.java new file mode 100644 index 00000000000..9b2750ab95f --- /dev/null +++ b/test/jdk/java/awt/Dialog/ClosingParentTest.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.Button; +import java.awt.Dialog; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowEvent; +import java.awt.event.WindowAdapter; + +/* + * @test + * @bug 4336913 + * @summary On Windows, disable parent window controls while modal dialog is being created. + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual ClosingParentTest + */ + +public class ClosingParentTest { + + static String instructions = """ + When the test starts, you will see a Frame with a Button + titled 'Show modal dialog with delay'. Press this button + and before the modal Dialog is shown, try to close the + Frame using X button or system menu for windowing systems + which don't provide X button in Window decorations. The + delay before Dialog showing is 5 seconds. + If in test output you see message about WINDOW_CLOSING + being dispatched, then test fails. If no such message + is printed, the test passes. + """; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("ClosingParentTest") + .instructions(instructions) + .testTimeOut(5) + .rows(10) + .columns(35) + .testUI(ClosingParentTest::createGUI) + .build() + .awaitAndCheck(); + } + + public static Frame createGUI() { + Frame frame = new Frame("Main Frame"); + Dialog dialog = new Dialog(frame, true); + + Button button = new Button("Show modal dialog with delay"); + button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + Thread.currentThread().sleep(5000); + } catch (InterruptedException x) { + x.printStackTrace(); + } + + dialog.setVisible(true); + } + }); + frame.add(button); + frame.pack(); + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.out.println("WINDOW_CLOSING dispatched on the frame"); + } + }); + + dialog.setSize(100, 100); + dialog.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + dialog.dispose(); + } + }); + + return frame; + } +} diff --git a/test/jdk/java/awt/Dialog/FileDialogEmptyTitleTest.java b/test/jdk/java/awt/Dialog/FileDialogEmptyTitleTest.java new file mode 100644 index 00000000000..d288a7c18f6 --- /dev/null +++ b/test/jdk/java/awt/Dialog/FileDialogEmptyTitleTest.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.FileDialog; +import java.awt.Frame; + +/* + * @test + * @bug 4177831 + * @summary solaris: default FileDialog title is not empty + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual FileDialogEmptyTitleTest + */ + +public class FileDialogEmptyTitleTest { + static String instructions = """ + Test passes if title of file dialog is empty, + otherwise test failed. + """; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("FileDialogEmptyTitleTest") + .instructions(instructions) + .testTimeOut(5) + .rows(10) + .columns(35) + .testUI(FileDialogEmptyTitleTest::createGUI) + .build() + .awaitAndCheck(); + } + + public static FileDialog createGUI() { + Frame frame = new Frame("invisible dialog owner"); + FileDialog fileDialog = new FileDialog(frame); + return fileDialog; + } +} diff --git a/test/jdk/java/awt/Dialog/FileDialogUIUpdate.java b/test/jdk/java/awt/Dialog/FileDialogUIUpdate.java new file mode 100644 index 00000000000..f97d947991b --- /dev/null +++ b/test/jdk/java/awt/Dialog/FileDialogUIUpdate.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.FileDialog; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/* + * @test + * @bug 4859390 + * @requires (os.family == "windows") + * @summary Verify that FileDialog matches the look + of the native windows FileDialog + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual FileDialogUIUpdate + */ + +public class FileDialogUIUpdate extends Frame { + static String instructions = """ + Click the button to show the FileDialog. Then open the Paint + application (usually found in Program Files->Accessories). + Select File->Open from Paint to display a native Open dialog. + Compare the native dialog to the AWT FileDialog. + Specifically, confirm that the Places Bar icons are along the left side (or + not, if the native dialog doesn't have them), and that the + dialogs are both resizable (or not). + If the file dialogs both look the same press Pass. If not, + press Fail. + """; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("FileDialogUIUpdate") + .instructions(instructions) + .testTimeOut(5) + .rows(12) + .columns(35) + .testUI(FileDialogUIUpdate::new) + .build() + .awaitAndCheck(); + } + + public FileDialogUIUpdate() { + final FileDialog fd = new FileDialog(new Frame("FileDialogUIUpdate frame"), + "Open FileDialog"); + Button showButton = new Button("Show FileDialog"); + setLayout(new BorderLayout()); + + fd.setDirectory("c:/"); + showButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + fd.setVisible(true); + } + }); + + add(showButton); + setSize(200, 200); + } +} diff --git a/test/jdk/java/awt/Dialog/MenuAndModalDialogTest.java b/test/jdk/java/awt/Dialog/MenuAndModalDialogTest.java new file mode 100644 index 00000000000..c22116ff8df --- /dev/null +++ b/test/jdk/java/awt/Dialog/MenuAndModalDialogTest.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.Button; +import java.awt.Dialog; +import java.awt.Frame; +import java.awt.Menu; +import java.awt.MenuBar; +import java.awt.MenuItem; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/* + * @test + * @bug 4070085 + * @summary Java program locks up X server + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual MenuAndModalDialogTest + */ + +public class MenuAndModalDialogTest { + static Frame frame; + static String instructions = """ + 1. Bring up the File Menu and leave it up. + 2. In a few seconds, the modal dialog will appear. + 3. Verify that your system does not lock up when you push the "OK" button. + """; + + public static void main(String[] args) throws Exception { + PassFailJFrame pf = PassFailJFrame.builder() + .title("MenuAndModalDialogTest") + .instructions(instructions) + .testTimeOut(5) + .rows(10) + .columns(35) + .testUI(MenuAndModalDialogTest::createFrame) + .build(); + + // Allow time to pop up the menu + try { + Thread.currentThread().sleep(5000); + } catch (InterruptedException exception) { + } + + createDialog(); + pf.awaitAndCheck(); + } + + public static Frame createFrame() { + frame = new Frame("MenuAndModalDialogTest frame"); + + MenuBar menuBar = new MenuBar(); + frame.setMenuBar(menuBar); + + Menu file = new Menu("File"); + menuBar.add(file); + + MenuItem menuItem = new MenuItem("A Menu Entry"); + file.add(menuItem); + + frame.setSize(200, 200); + frame.setLocationRelativeTo(null); + return frame; + } + + public static void createDialog() { + Dialog dialog = new Dialog(frame); + + Button button = new Button("OK"); + dialog.add(button); + button.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + dialog.dispose(); + } + } + ); + + dialog.setSize(200, 200); + dialog.setModal(true); + dialog.setVisible(true); + } +}