From 2a84acf3dd07edc3fcb3de12a4072f958926a0ca Mon Sep 17 00:00:00 2001 From: Alexander Stepanov Date: Wed, 9 Jul 2014 12:56:03 +0400 Subject: [PATCH] 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2 Reviewed-by: pchelko --- .../FocusTransferDWFAppModalTest.java | 49 ++++ .../FocusTransferDWFDocModalTest.java | 49 ++++ .../FocusTransferDWFModelessTest.java | 49 ++++ .../FocusTransferDWFNonModalTest.java | 48 ++++ .../FocusTransferDWFTest.java | 186 ++++++++++++ .../FocusTransferDialogsAppModalTest.java | 50 ++++ .../FocusTransferDialogsDocModalTest.java | 50 ++++ .../FocusTransferDialogsModelessTest.java | 50 ++++ .../FocusTransferDialogsNonModalTest.java | 49 ++++ .../FocusTransferDialogsTest.java | 193 +++++++++++++ .../FocusTransferFDWAppModalTest.java | 49 ++++ .../FocusTransferFDWDocModalTest.java | 49 ++++ .../FocusTransferFDWModelessTest.java | 49 ++++ .../FocusTransferFDWNonModalTest.java | 48 ++++ .../FocusTransferFDWTest.java | 152 ++++++++++ .../FocusTransferFWDAppModal1Test.java | 50 ++++ .../FocusTransferFWDAppModal2Test.java | 50 ++++ .../FocusTransferFWDAppModal3Test.java | 50 ++++ .../FocusTransferFWDAppModal4Test.java | 50 ++++ .../FocusTransferFWDDocModal1Test.java | 50 ++++ .../FocusTransferFWDDocModal2Test.java | 50 ++++ .../FocusTransferFWDDocModal3Test.java | 50 ++++ .../FocusTransferFWDDocModal4Test.java | 50 ++++ .../FocusTransferFWDModeless1Test.java | 50 ++++ .../FocusTransferFWDModeless2Test.java | 50 ++++ .../FocusTransferFWDModeless3Test.java | 50 ++++ .../FocusTransferFWDModeless4Test.java | 50 ++++ .../FocusTransferFWDNonModal1Test.java | 49 ++++ .../FocusTransferFWDNonModal2Test.java | 49 ++++ .../FocusTransferFWDNonModal3Test.java | 49 ++++ .../FocusTransferFWDNonModal4Test.java | 49 ++++ .../FocusTransferFWDTest.java | 201 +++++++++++++ .../FocusTransferWDFAppModal1Test.java | 51 ++++ .../FocusTransferWDFAppModal2Test.java | 52 ++++ .../FocusTransferWDFAppModal3Test.java | 52 ++++ .../FocusTransferWDFDocModal1Test.java | 51 ++++ .../FocusTransferWDFDocModal2Test.java | 52 ++++ .../FocusTransferWDFDocModal3Test.java | 51 ++++ .../FocusTransferWDFModeless1Test.java | 51 ++++ .../FocusTransferWDFModeless2Test.java | 52 ++++ .../FocusTransferWDFModeless3Test.java | 51 ++++ .../FocusTransferWDFNonModal1Test.java | 51 ++++ .../FocusTransferWDFNonModal2Test.java | 52 ++++ .../FocusTransferWDFNonModal3Test.java | 51 ++++ .../FocusTransferWDFTest.java | 272 ++++++++++++++++++ .../ModalitySettingsTest.java | 139 +++++++++ .../NullModalityDialogTest.java | 161 +++++++++++ .../java/awt/Modal/helpers/TestDialog.java | 38 ++- .../java/awt/Modal/helpers/TestFrame.java | 60 ++-- .../java/awt/Modal/helpers/TestWindow.java | 42 ++- 50 files changed, 3390 insertions(+), 56 deletions(-) create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDWFAppModalTest.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDWFDocModalTest.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDWFModelessTest.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDWFNonModalTest.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDWFTest.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsAppModalTest.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsDocModalTest.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsModelessTest.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsNonModalTest.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsTest.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWAppModalTest.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWDocModalTest.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWModelessTest.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWNonModalTest.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWTest.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDAppModal1Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDAppModal2Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDAppModal3Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDAppModal4Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDDocModal1Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDDocModal2Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDDocModal3Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDDocModal4Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDModeless1Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDModeless2Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDModeless3Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDModeless4Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDNonModal1Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDNonModal2Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDNonModal3Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDNonModal4Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDTest.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFAppModal1Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFAppModal2Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFAppModal3Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFDocModal1Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFDocModal2Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFDocModal3Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFModeless1Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFModeless2Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFModeless3Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFNonModal1Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFNonModal2Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFNonModal3Test.java create mode 100644 jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFTest.java create mode 100644 jdk/test/java/awt/Modal/ModalitySettingsTest/ModalitySettingsTest.java create mode 100644 jdk/test/java/awt/Modal/NullModalityDialogTest/NullModalityDialogTest.java diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDWFAppModalTest.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDWFAppModalTest.java new file mode 100644 index 00000000000..20f15fbe4de --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDWFAppModalTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 + * @summary Check whether the focus transfer between windows occurs correctly when the following + * happens: an application modal dialog (D) having null frame owner is shown; + * a window having D as owner is shown; a frame is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferDWFAppModalTest + */ + +public class FocusTransferDWFAppModalTest { + + public static void main(String[] args) throws Exception { + FocusTransferDWFTest test = new FocusTransferDWFTest( + Dialog.ModalityType.APPLICATION_MODAL); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDWFDocModalTest.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDWFDocModalTest.java new file mode 100644 index 00000000000..bb70a4fc090 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDWFDocModalTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 8049339 + * @summary Check whether the focus transfer between windows occurs correctly when the + * following happens: a document modal dialog (D) having null frame owner is shown; + * a window having D as owner is shown; a frame is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferDWFDocModalTest + */ + +public class FocusTransferDWFDocModalTest { + + public static void main(String[] args) throws Exception { + FocusTransferDWFTest test = new FocusTransferDWFTest( + Dialog.ModalityType.DOCUMENT_MODAL); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDWFModelessTest.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDWFModelessTest.java new file mode 100644 index 00000000000..eb2ca1ecd08 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDWFModelessTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 8049339 + * @summary Check whether the focus transfer between windows occurs correctly when the + * following happens: a modeless dialog (D) having null frame owner is shown; + * a window having D as owner is shown; a frame is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferDWFModelessTest + */ + +public class FocusTransferDWFModelessTest { + + public static void main(String[] args) throws Exception { + FocusTransferDWFTest test = new FocusTransferDWFTest( + Dialog.ModalityType.MODELESS); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDWFNonModalTest.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDWFNonModalTest.java new file mode 100644 index 00000000000..697c5c3d409 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDWFNonModalTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 8049339 + * @summary Check whether the focus transfer between windows occurs correctly when the following + * happens: a non-modal dialog (D) having null frame owner is shown; a window having D + * as owner is shown; a frame is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferDWFNonModalTest + */ + +public class FocusTransferDWFNonModalTest { + + public static void main(String[] args) throws Exception { + FocusTransferDWFTest test = new FocusTransferDWFTest(null); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDWFTest.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDWFTest.java new file mode 100644 index 00000000000..c6097b74b92 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDWFTest.java @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2007, 2014, 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.*; + +import static jdk.testlibrary.Asserts.*; + +// DWF: Dialog -> Window -> Frame +public class FocusTransferDWFTest { + + class CustomDialog extends TestDialog { + + public CustomDialog(Frame f) { + super(f); + } + + @Override + public void doOpenAction() { + if (window != null) { + window.setVisible(true); + } + } + + @Override + public void doCloseAction() { + this.dispose(); + } + } + + class CustomFrame extends TestFrame { + + @Override + public void doCloseAction() { + this.dispose(); + } + } + + class CustomWindow extends TestWindow { + + public CustomWindow(Dialog d) { + super(d); + } + + @Override + public void doOpenAction() { + if (frame != null) { + frame.setVisible(true); + } + } + + @Override + public void doCloseAction() { + this.dispose(); + } + } + + private TestDialog dialog; + private TestFrame frame; + private TestWindow window; + + private static final int delay = 1000; + + private final ExtendedRobot robot; + + private Dialog.ModalityType modalityType; + + FocusTransferDWFTest(Dialog.ModalityType modType) throws Exception { + + modalityType = modType; + + robot = new ExtendedRobot(); + EventQueue.invokeLater(this::createGUI); + } + + private void createGUI() { + + frame = new CustomFrame(); + frame.setLocation(50, 50); + + dialog = new CustomDialog((Frame) null); + if (modalityType == null) { + modalityType = Dialog.ModalityType.MODELESS; + } else { + dialog.setModalityType(modalityType); + } + dialog.setLocation(250, 50); + + window = new CustomWindow(dialog); + window.setLocation(450, 50); + dialog.setVisible(true); + } + + private void closeAll() { + if (dialog != null) { dialog.dispose(); } + if ( frame != null) { frame.dispose(); } + if (window != null) { window.dispose(); } + } + + public void doTest() throws Exception { + + robot.waitForIdle(delay); + + try { + + dialog.checkCloseButtonFocusGained(true); + + dialog.clickOpenButton(robot); + robot.waitForIdle(delay); + + window.checkCloseButtonFocusGained(true); + dialog.checkOpenButtonFocusLost(true); + + window.clickOpenButton(robot); + robot.waitForIdle(delay); + + switch (modalityType) { + case APPLICATION_MODAL: + frame.checkCloseButtonFocusGained(false, 10); + window.checkOpenButtonFocusLost(false, 10); + + frame.closeGained.reset(); + + dialog.clickCloseButton(robot); + robot.waitForIdle(delay); + + frame.checkCloseButtonFocusGained(true); + assertFalse(window.isVisible(), "window shouldn't be visible"); + + break; + + case DOCUMENT_MODAL: + case MODELESS: + frame.checkCloseButtonFocusGained(true); + window.checkOpenButtonFocusLost(true); + + window.openGained.reset(); + + frame.clickCloseButton(robot); + robot.waitForIdle(delay); + + window.checkOpenButtonFocusGained(true); + + dialog.openGained.reset(); + window.clickCloseButton(robot); + robot.waitForIdle(delay); + + dialog.checkOpenButtonFocusGained(true); + + break; + } + + } catch (Exception e) { + + // make screenshot before exit + Rectangle rect = new Rectangle(0, 0, 650, 250); + java.awt.image.BufferedImage img = robot.createScreenCapture(rect); + javax.imageio.ImageIO.write(img, "jpg", new java.io.File("NOK.jpg")); + + throw e; + } + + robot.waitForIdle(delay); + + EventQueue.invokeAndWait(this::closeAll); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsAppModalTest.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsAppModalTest.java new file mode 100644 index 00000000000..900c3889786 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsAppModalTest.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 + * @summary Check whether the focus transfer between windows occurs correctly when + * the following happens: an application modal dialog (D1) having a null + * frame owner is shown; a dialog (D2) having D1 owner is shown; a dialog + * with a hidden frame owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferDialogsAppModalTest + */ + +public class FocusTransferDialogsAppModalTest { + + public static void main(String[] args) throws Exception { + FocusTransferDialogsTest test = new FocusTransferDialogsTest( + Dialog.ModalityType.APPLICATION_MODAL); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsDocModalTest.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsDocModalTest.java new file mode 100644 index 00000000000..62e04584dc6 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsDocModalTest.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 + * @summary Check whether the focus transfer between windows occurs correctly when + * the following happens: a document modal dialog (D1) having a null + * frame owner is shown; a dialog (D2) having D1 owner is shown; a dialog + * with a hidden frame owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferDialogsDocModalTest + */ + +public class FocusTransferDialogsDocModalTest { + + public static void main(String[] args) throws Exception { + FocusTransferDialogsTest test = new FocusTransferDialogsTest( + Dialog.ModalityType.DOCUMENT_MODAL); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsModelessTest.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsModelessTest.java new file mode 100644 index 00000000000..2215b5a9b36 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsModelessTest.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 + * @summary Check whether the focus transfer between windows occurs correctly when + * the following happens: a modeless dialog (D1) having a null + * frame owner is shown; a dialog (D2) having D1 owner is shown; a dialog + * with a hidden frame owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferDialogsModelessTest + */ + +public class FocusTransferDialogsModelessTest { + + public static void main(String[] args) throws Exception { + FocusTransferDialogsTest test = new FocusTransferDialogsTest( + Dialog.ModalityType.MODELESS); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsNonModalTest.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsNonModalTest.java new file mode 100644 index 00000000000..dc87c0f4268 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsNonModalTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 + * @summary Check whether the focus transfer between windows occurs correctly when + * the following happens: a non-modal dialog (D1) having a null + * frame owner is shown; a dialog (D2) having D1 owner is shown; a dialog + * with a hidden frame owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferDialogsNonModalTest + */ + +public class FocusTransferDialogsNonModalTest { + + public static void main(String[] args) throws Exception { + FocusTransferDialogsTest test = new FocusTransferDialogsTest(null); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsTest.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsTest.java new file mode 100644 index 00000000000..322dd6b94d4 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsTest.java @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2007, 2014, 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.*; + + +public class FocusTransferDialogsTest { + + class CustomDialog1 extends TestDialog { + + public CustomDialog1(Frame f) { + super(f); + } + + @Override + public void doOpenAction() { + if (dialog2 != null) { + dialog2.setVisible(true); + } + } + + @Override + public void doCloseAction() { + this.dispose(); + } + } + + class CustomDialog2 extends TestDialog { + + public CustomDialog2(Dialog d) { + super(d); + } + + @Override + public void doOpenAction() { + if (dialog3 != null) { + dialog3.setVisible(true); + } + } + + @Override + public void doCloseAction() { + this.dispose(); + } + } + + class CustomDialog3 extends TestDialog { + + public CustomDialog3(Frame f) { + super(f); + } + + public CustomDialog3(Dialog d) { + super(d); + } + + @Override + public void doCloseAction() { + this.dispose(); + } + } + + + private TestDialog dialog1, dialog2, dialog3; + private Frame parentFrame; + + private static final int delay = 1000; + private final ExtendedRobot robot; + private Dialog.ModalityType modalityType; + + FocusTransferDialogsTest(Dialog.ModalityType modType) throws Exception { + + modalityType = modType; + robot = new ExtendedRobot(); + EventQueue.invokeLater(this::createGUI); + } + + private void createGUI() { + + dialog1 = new CustomDialog1((Frame) null); + dialog1.setTitle("Dialog1"); + dialog1.setLocation(50, 50); + + if (modalityType != null) { + dialog1.setModalityType(modalityType); + } else { + modalityType = Dialog.ModalityType.MODELESS; + } + + dialog2 = new CustomDialog2(dialog1); + dialog2.setTitle("Dialog2"); + dialog2.setLocation(250, 50); + + parentFrame = new Frame(); + dialog3 = new CustomDialog3(parentFrame); + dialog3.setTitle("Dialog3"); + dialog3.setLocation(450, 50); + + dialog1.setVisible(true); + } + + private void closeAll() { + if (dialog1 != null) { dialog1.dispose(); } + if (dialog2 != null) { dialog2.dispose(); } + if (dialog3 != null) { dialog3.dispose(); } + if (parentFrame != null) { parentFrame.dispose(); } + } + + public void doTest() throws Exception { + + robot.waitForIdle(delay); + + try { + + dialog1.checkCloseButtonFocusGained(true); + + dialog1.clickOpenButton(robot); + robot.waitForIdle(delay); + + dialog2.checkCloseButtonFocusGained(true); + dialog1.checkOpenButtonFocusLost(true); + + dialog1.openGained.reset(); + dialog2.clickOpenButton(robot); + robot.waitForIdle(delay); + + switch (modalityType) { + case APPLICATION_MODAL: + + dialog3.checkCloseButtonFocusGained(false, 10); + dialog2.checkOpenButtonFocusLost(true); + + dialog1.checkCloseButtonFocusGained(true); + dialog3.closeGained.reset(); + + dialog1.clickCloseButton(robot); + robot.waitForIdle(delay); + + dialog3.checkCloseButtonFocusGained(true); + + break; + + case DOCUMENT_MODAL: + case MODELESS: + + dialog3.checkCloseButtonFocusGained(true); + dialog2.checkOpenButtonFocusLost(true); + + dialog1.openGained.reset(); + + dialog2.clickCloseButton(robot); + robot.waitForIdle(delay); + + dialog1.checkOpenButtonFocusGained(true); + + break; + } + + } catch (Exception e) { + + // make screenshot before exit + Rectangle rect = new Rectangle(0, 0, 650, 250); + java.awt.image.BufferedImage img = robot.createScreenCapture(rect); + javax.imageio.ImageIO.write(img, "jpg", new java.io.File("NOK.jpg")); + + throw e; + } + + robot.waitForIdle(delay); + EventQueue.invokeAndWait(this::closeAll); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWAppModalTest.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWAppModalTest.java new file mode 100644 index 00000000000..f3fc961d460 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWAppModalTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 + * @summary Check whether the focus transfer between windows occurs correctly when + * the following happens: a frame is shown; an application modal dialog (D) + * having a null frame owner is shown; a window having D as owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferFDWAppModalTest + */ + +public class FocusTransferFDWAppModalTest { + + public static void main(String[] args) throws Exception { + FocusTransferFDWTest test = new FocusTransferFDWTest( + Dialog.ModalityType.APPLICATION_MODAL); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWDocModalTest.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWDocModalTest.java new file mode 100644 index 00000000000..9a163e47bbc --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWDocModalTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 + * @summary Check whether the focus transfer between windows occurs correctly when + * the following happens: a frame is shown; a document modal dialog (D) + * having a null frame owner is shown; a window having D as owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferFDWDocModalTest + */ + +public class FocusTransferFDWDocModalTest { + + public static void main(String[] args) throws Exception { + FocusTransferFDWTest test = new FocusTransferFDWTest( + Dialog.ModalityType.DOCUMENT_MODAL); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWModelessTest.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWModelessTest.java new file mode 100644 index 00000000000..41dce55fea8 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWModelessTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 + * @summary Check whether the focus transfer between windows occurs correctly when + * the following happens: a frame is shown; a modeless dialog (D) + * having a null frame owner is shown; a window having D as owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferFDWModelessTest + */ + +public class FocusTransferFDWModelessTest { + + public static void main(String[] args) throws Exception { + FocusTransferFDWTest test = new FocusTransferFDWTest( + Dialog.ModalityType.MODELESS); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWNonModalTest.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWNonModalTest.java new file mode 100644 index 00000000000..32117624ecb --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWNonModalTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 + * @summary Check whether the focus transfer between windows occurs correctly when + * the following happens: a frame is shown; a non-modal dialog (D) + * having a null frame owner is shown; a window having D as owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferFDWNonModalTest + */ + +public class FocusTransferFDWNonModalTest { + + public static void main(String[] args) throws Exception { + FocusTransferFDWTest test = new FocusTransferFDWTest(null); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWTest.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWTest.java new file mode 100644 index 00000000000..41e2fb086f2 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWTest.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2007, 2014, 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.*; + +// FDW: Frame -> Dialog -> Window +public class FocusTransferFDWTest { + + class CustomFrame extends TestFrame { + + @Override + public void doOpenAction() { + if (dialog != null) { + dialog.setVisible(true); + } + } + } + + class CustomWindow extends TestWindow { + + public CustomWindow(Dialog d) { + super(d); + } + + @Override + public void doCloseAction() { + this.dispose(); + } + } + + class CustomDialog extends TestDialog { + + public CustomDialog(Frame f) { + super(f); + } + + @Override + public void doOpenAction() { + if (window != null) { + window.setVisible(true); + } + } + + @Override + public void doCloseAction() { + this.dispose(); + } + } + + private TestDialog dialog; + private TestFrame frame; + private TestWindow window; + + private static final int delay = 1000; + + private final ExtendedRobot robot; + + private final Dialog.ModalityType modalityType; + + FocusTransferFDWTest(Dialog.ModalityType modType) throws Exception { + + modalityType = modType; + + robot = new ExtendedRobot(); + EventQueue.invokeLater(this::createGUI); + } + + private void createGUI() { + + frame = new CustomFrame(); + frame.setLocation(50, 50); + dialog = new CustomDialog((Frame) null); + if (modalityType != null) { + dialog.setModalityType(modalityType); + } + dialog.setLocation(250, 50); + window = new CustomWindow(dialog); + window.setLocation(450, 50); + frame.setVisible(true); + } + + private void closeAll() { + if (dialog != null) { dialog.dispose(); } + if ( frame != null) { frame.dispose(); } + if (window != null) { window.dispose(); } + } + + public void doTest() throws Exception { + + robot.waitForIdle(delay); + + try { + + frame.checkCloseButtonFocusGained(true); + + frame.clickOpenButton(robot); + robot.waitForIdle(delay); + + dialog.checkCloseButtonFocusGained(true); + + frame.checkOpenButtonFocusLost(true); + + dialog.clickOpenButton(robot); + robot.waitForIdle(delay); + + window.checkCloseButtonFocusGained(true); + dialog.checkOpenButtonFocusLost(true); + + dialog.openGained.reset(); + window.clickCloseButton(robot); + + dialog.checkOpenButtonFocusGained(true); + + frame.openGained.reset(); + dialog.clickCloseButton(robot); + + frame.checkOpenButtonFocusGained(true); + + } catch (Exception e) { + + // make screenshot before exit + Rectangle rect = new Rectangle(0, 0, 650, 250); + java.awt.image.BufferedImage img = robot.createScreenCapture(rect); + javax.imageio.ImageIO.write(img, "jpg", new java.io.File("NOK.jpg")); + + throw e; + } + + robot.waitForIdle(delay); + EventQueue.invokeAndWait(this::closeAll); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDAppModal1Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDAppModal1Test.java new file mode 100644 index 00000000000..121aeb5494f --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDAppModal1Test.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 8049339 + * @summary Check whether the focus transfer between windows occurs correctly when the following happens: + * a frame (F) is shown; a window having F as owner is shown; an application modal dialog having + * a hidden dialog owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferFWDAppModal1Test + */ + +public class FocusTransferFWDAppModal1Test { + + public static void main(String[] args) throws Exception { + FocusTransferFWDTest test = new FocusTransferFWDTest( + Dialog.ModalityType.APPLICATION_MODAL, + FocusTransferFWDTest.DialogParent.HIDDEN_DIALOG); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDAppModal2Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDAppModal2Test.java new file mode 100644 index 00000000000..ba1ff589406 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDAppModal2Test.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 8049339 + * @summary Check whether the focus transfer between windows occurs correctly when the following happens: + * a frame (F) is shown; a window having F as owner is shown; an application modal dialog having + * a hidden frame owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferFWDAppModal2Test + */ + +public class FocusTransferFWDAppModal2Test { + + public static void main(String[] args) throws Exception { + FocusTransferFWDTest test = new FocusTransferFWDTest( + Dialog.ModalityType.APPLICATION_MODAL, + FocusTransferFWDTest.DialogParent.HIDDEN_FRAME); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDAppModal3Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDAppModal3Test.java new file mode 100644 index 00000000000..5098658d7e9 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDAppModal3Test.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 8049339 + * @summary Check whether the focus transfer between windows occurs correctly when the following happens: + * a frame (F) is shown; a window having F as owner is shown; an application modal dialog having + * a null dialog owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferFWDAppModal3Test + */ + +public class FocusTransferFWDAppModal3Test { + + public static void main(String[] args) throws Exception { + FocusTransferFWDTest test = new FocusTransferFWDTest( + Dialog.ModalityType.APPLICATION_MODAL, + FocusTransferFWDTest.DialogParent.NULL_DIALOG); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDAppModal4Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDAppModal4Test.java new file mode 100644 index 00000000000..f4ae06489aa --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDAppModal4Test.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 8049339 + * @summary Check whether the focus transfer between windows occurs correctly when the following happens: + * a frame (F) is shown; a window having F as owner is shown; an application modal dialog having + * a null frame owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferFWDAppModal4Test + */ + +public class FocusTransferFWDAppModal4Test { + + public static void main(String[] args) throws Exception { + FocusTransferFWDTest test = new FocusTransferFWDTest( + Dialog.ModalityType.APPLICATION_MODAL, + FocusTransferFWDTest.DialogParent.NULL_FRAME); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDDocModal1Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDDocModal1Test.java new file mode 100644 index 00000000000..4f3958f98d4 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDDocModal1Test.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 8049339 + * @summary Check whether the focus transfer between windows occurs correctly when the following happens: + * a frame (F) is shown; a window having F as owner is shown; a document modal dialog having + * a hidden dialog owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferFWDDocModal1Test + */ + +public class FocusTransferFWDDocModal1Test { + + public static void main(String[] args) throws Exception { + FocusTransferFWDTest test = new FocusTransferFWDTest( + Dialog.ModalityType.DOCUMENT_MODAL, + FocusTransferFWDTest.DialogParent.HIDDEN_DIALOG); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDDocModal2Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDDocModal2Test.java new file mode 100644 index 00000000000..f68eb0e3a63 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDDocModal2Test.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 8049339 + * @summary Check whether the focus transfer between windows occurs correctly when the following happens: + * a frame (F) is shown; a window having F as owner is shown; a document modal dialog having + * a hidden frame owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferFWDDocModal2Test + */ + +public class FocusTransferFWDDocModal2Test { + + public static void main(String[] args) throws Exception { + FocusTransferFWDTest test = new FocusTransferFWDTest( + Dialog.ModalityType.DOCUMENT_MODAL, + FocusTransferFWDTest.DialogParent.HIDDEN_FRAME); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDDocModal3Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDDocModal3Test.java new file mode 100644 index 00000000000..7ad9e8e3d4a --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDDocModal3Test.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 8049339 + * @summary Check whether the focus transfer between windows occurs correctly when the following happens: + * a frame (F) is shown; a window having F as owner is shown; a document modal dialog having + * a null dialog owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferFWDDocModal3Test + */ + +public class FocusTransferFWDDocModal3Test { + + public static void main(String[] args) throws Exception { + FocusTransferFWDTest test = new FocusTransferFWDTest( + Dialog.ModalityType.DOCUMENT_MODAL, + FocusTransferFWDTest.DialogParent.NULL_DIALOG); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDDocModal4Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDDocModal4Test.java new file mode 100644 index 00000000000..d689b61be83 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDDocModal4Test.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 8049339 + * @summary Check whether the focus transfer between windows occurs correctly when the following happens: + * a frame (F) is shown; a window having F as owner is shown; a document modal dialog having + * a null frame owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferFWDDocModal4Test + */ + +public class FocusTransferFWDDocModal4Test { + + public static void main(String[] args) throws Exception { + FocusTransferFWDTest test = new FocusTransferFWDTest( + Dialog.ModalityType.DOCUMENT_MODAL, + FocusTransferFWDTest.DialogParent.NULL_FRAME); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDModeless1Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDModeless1Test.java new file mode 100644 index 00000000000..bdf00c0ca24 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDModeless1Test.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 8049339 + * @summary Check whether the focus transfer between windows occurs correctly when the following happens: + * a frame (F) is shown; a window having F as owner is shown; a modeless dialog having + * a hidden dialog owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferFWDModeless1Test + */ + +public class FocusTransferFWDModeless1Test { + + public static void main(String[] args) throws Exception { + FocusTransferFWDTest test = new FocusTransferFWDTest( + Dialog.ModalityType.MODELESS, + FocusTransferFWDTest.DialogParent.HIDDEN_DIALOG); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDModeless2Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDModeless2Test.java new file mode 100644 index 00000000000..a1d31e4328a --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDModeless2Test.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 8049339 + * @summary Check whether the focus transfer between windows occurs correctly when the following happens: + * a frame (F) is shown; a window having F as owner is shown; a modeless dialog having + * a hidden frame owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferFWDModeless2Test + */ + +public class FocusTransferFWDModeless2Test { + + public static void main(String[] args) throws Exception { + FocusTransferFWDTest test = new FocusTransferFWDTest( + Dialog.ModalityType.MODELESS, + FocusTransferFWDTest.DialogParent.HIDDEN_FRAME); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDModeless3Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDModeless3Test.java new file mode 100644 index 00000000000..6ed6f9eab21 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDModeless3Test.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 8049339 + * @summary Check whether the focus transfer between windows occurs correctly when the following happens: + * a frame (F) is shown; a window having F as owner is shown; a modeless dialog having + * a null dialog owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferFWDModeless3Test + */ + +public class FocusTransferFWDModeless3Test { + + public static void main(String[] args) throws Exception { + FocusTransferFWDTest test = new FocusTransferFWDTest( + Dialog.ModalityType.MODELESS, + FocusTransferFWDTest.DialogParent.NULL_DIALOG); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDModeless4Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDModeless4Test.java new file mode 100644 index 00000000000..956b69127bb --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDModeless4Test.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 8049339 + * @summary Check whether the focus transfer between windows occurs correctly when the following happens: + * a frame (F) is shown; a window having F as owner is shown; a modeless dialog having + * a null frame owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferFWDModeless4Test + */ + +public class FocusTransferFWDModeless4Test { + + public static void main(String[] args) throws Exception { + FocusTransferFWDTest test = new FocusTransferFWDTest( + Dialog.ModalityType.MODELESS, + FocusTransferFWDTest.DialogParent.NULL_FRAME); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDNonModal1Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDNonModal1Test.java new file mode 100644 index 00000000000..fd06036bce7 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDNonModal1Test.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 8049339 + * @summary Check whether the focus transfer between windows occurs correctly when the following happens: + * a frame (F) is shown; a window having F as owner is shown; a non-modal dialog having + * a hidden dialog owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferFWDNonModal1Test + */ + +public class FocusTransferFWDNonModal1Test { + + public static void main(String[] args) throws Exception { + FocusTransferFWDTest test = new FocusTransferFWDTest( + null, FocusTransferFWDTest.DialogParent.HIDDEN_DIALOG); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDNonModal2Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDNonModal2Test.java new file mode 100644 index 00000000000..82283113c8c --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDNonModal2Test.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 8049339 + * @summary Check whether the focus transfer between windows occurs correctly when the following happens: + * a frame (F) is shown; a window having F as owner is shown; a non-modal dialog having + * a hidden frame owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferFWDNonModal2Test + */ + +public class FocusTransferFWDNonModal2Test { + + public static void main(String[] args) throws Exception { + FocusTransferFWDTest test = new FocusTransferFWDTest( + null, FocusTransferFWDTest.DialogParent.HIDDEN_FRAME); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDNonModal3Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDNonModal3Test.java new file mode 100644 index 00000000000..4475351ba43 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDNonModal3Test.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 8049339 + * @summary Check whether the focus transfer between windows occurs correctly when the following happens: + * a frame (F) is shown; a window having F as owner is shown; a non-modal dialog having + * a null dialog owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferFWDNonModal3Test + */ + +public class FocusTransferFWDNonModal3Test { + + public static void main(String[] args) throws Exception { + FocusTransferFWDTest test = new FocusTransferFWDTest( + null, FocusTransferFWDTest.DialogParent.NULL_DIALOG); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDNonModal4Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDNonModal4Test.java new file mode 100644 index 00000000000..6ceed537376 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDNonModal4Test.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 8049339 + * @summary Check whether the focus transfer between windows occurs correctly when the following happens: + * a frame (F) is shown; a window having F as owner is shown; a non-modal dialog having + * a null frame owner is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferFWDNonModal4Test + */ + +public class FocusTransferFWDNonModal4Test { + + public static void main(String[] args) throws Exception { + FocusTransferFWDTest test = new FocusTransferFWDTest( + null, FocusTransferFWDTest.DialogParent.NULL_FRAME); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDTest.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDTest.java new file mode 100644 index 00000000000..2d7a37419d1 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferFWDTest.java @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2007, 2014, 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.*; +import static jdk.testlibrary.Asserts.*; + + +// FWD: Frame -> Window -> Dialog +public class FocusTransferFWDTest { + + class CustomFrame extends TestFrame { + + @Override + public void doOpenAction() { + if (window != null) { + window.setVisible(true); + } + } + + @Override + public void doCloseAction() { + this.dispose(); + } + } + + class CustomWindow extends TestWindow { + + public CustomWindow(Frame f) { + super(f); + } + + @Override + public void doOpenAction() { + if (dialog != null) { + dialog.setVisible(true); + } + } + + @Override + public void doCloseAction() { + this.dispose(); + } + } + + class CustomDialog extends TestDialog { + + public CustomDialog(Frame f) { + super(f); + } + + public CustomDialog(Dialog d) { + super(d); + } + + @Override + public void doCloseAction() { + this.dispose(); + } + } + + private TestDialog dialog; + private TestFrame frame; + private TestWindow window; + + private Frame parentFrame; + private Dialog parentDialog; + + private static final int delay = 1000; + + private final ExtendedRobot robot; + + private final Dialog.ModalityType modalityType; + + public enum DialogParent {NULL_DIALOG, NULL_FRAME, HIDDEN_DIALOG, HIDDEN_FRAME}; + private DialogParent dialogParent; + + FocusTransferFWDTest(Dialog.ModalityType modType, + DialogParent dlgParent) throws Exception { + + modalityType = modType; + dialogParent = dlgParent; + + robot = new ExtendedRobot(); + EventQueue.invokeLater(this::createGUI); + } + + private void createGUI() { + + frame = new CustomFrame(); + frame.setLocation(50, 50); + + switch (dialogParent) { + case NULL_DIALOG: + dialog = new CustomDialog((Dialog) null); + break; + case NULL_FRAME: + dialog = new CustomDialog((Frame) null); + break; + case HIDDEN_DIALOG: + parentDialog = new Dialog((Frame) null); + dialog = new CustomDialog(parentDialog); + break; + case HIDDEN_FRAME: + parentFrame = new Frame(); + dialog = new CustomDialog(parentFrame); + break; + } + + assertTrue(dialog != null, "error: null dialog"); + + if (modalityType != null) { + dialog.setModalityType(modalityType); + } + + dialog.setLocation(250, 50); + window = new CustomWindow(frame); + window.setLocation(450, 50); + frame.setVisible(true); + } + + private void closeAll() { + if (dialog != null) { dialog.dispose(); } + if ( frame != null) { frame.dispose(); } + if (window != null) { window.dispose(); } + + if (parentDialog != null) { parentDialog.dispose(); } + if (parentFrame != null) { parentFrame.dispose(); } + } + + public void doTest() throws Exception { + + robot.waitForIdle(delay); + + try { + + frame.checkCloseButtonFocusGained(true); + + frame.clickOpenButton(robot); + robot.waitForIdle(delay); + + window.checkCloseButtonFocusGained(true); + frame.checkOpenButtonFocusLost(true); + + window.clickOpenButton(robot); + robot.waitForIdle(delay); + + dialog.checkCloseButtonFocusGained(true); + window.checkOpenButtonFocusLost(true); + + window.openGained.reset(); + + dialog.clickCloseButton(robot); + robot.waitForIdle(delay); + + window.checkOpenButtonFocusGained(true); + + frame.openGained.reset(); + + window.clickCloseButton(robot); + robot.waitForIdle(delay); + + frame.checkOpenButtonFocusGained(true); + + frame.clickCloseButton(robot); + robot.waitForIdle(delay); + + } catch (Exception e) { + + // make screenshot before exit + Rectangle rect = new Rectangle(0, 0, 650, 250); + java.awt.image.BufferedImage img = robot.createScreenCapture(rect); + javax.imageio.ImageIO.write(img, "jpg", new java.io.File("NOK.jpg")); + + throw e; + } + + robot.waitForIdle(delay); + EventQueue.invokeAndWait(this::closeAll); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFAppModal1Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFAppModal1Test.java new file mode 100644 index 00000000000..d23593634c1 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFAppModal1Test.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 + * @summary Check whether the focus transfer between windows occurs correctly when + * the following happens: a window having a hidden frame owner is shown; + * an application modal dialog having a frame (F) owner is shown; F is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferWDFAppModal1Test + */ + +public class FocusTransferWDFAppModal1Test { + + public static void main(String[] args) throws Exception { + FocusTransferWDFTest test = new FocusTransferWDFTest( + Dialog.ModalityType.APPLICATION_MODAL, + FocusTransferWDFTest.DialogParent.FRAME, + FocusTransferWDFTest.WindowParent.NEW_FRAME); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFAppModal2Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFAppModal2Test.java new file mode 100644 index 00000000000..e37420f3cdb --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFAppModal2Test.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 8048263 + * @summary Check whether the focus transfer between windows occurs correctly when + * the following happens: a window having a hidden frame owner is shown; + * an application modal dialog having a null dialog owner is shown; + * a frame is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferWDFAppModal2Test + */ + +public class FocusTransferWDFAppModal2Test { + + public static void main(String[] args) throws Exception { + FocusTransferWDFTest test = new FocusTransferWDFTest( + Dialog.ModalityType.APPLICATION_MODAL, + FocusTransferWDFTest.DialogParent.NULL_DIALOG, + FocusTransferWDFTest.WindowParent.NEW_FRAME); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFAppModal3Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFAppModal3Test.java new file mode 100644 index 00000000000..f75c869272a --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFAppModal3Test.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 + * @summary Check whether the focus transfer between windows occurs correctly when + * the following happens: a window having a frame (F) owner is shown; + * an application modal dialog having F owner is shown; F is shown. + * + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferWDFAppModal3Test + */ + +public class FocusTransferWDFAppModal3Test { + + public static void main(String[] args) throws Exception { + FocusTransferWDFTest test = new FocusTransferWDFTest( + Dialog.ModalityType.APPLICATION_MODAL, + FocusTransferWDFTest.DialogParent.FRAME, + FocusTransferWDFTest.WindowParent.FRAME); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFDocModal1Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFDocModal1Test.java new file mode 100644 index 00000000000..cd1e9e8f9d9 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFDocModal1Test.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 + * @summary Check whether the focus transfer between windows occurs correctly when + * the following happens: a window having a hidden frame owner is shown; + * a document modal dialog with a frame (F) owner is shown; F is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferWDFDocModal1Test + */ + +public class FocusTransferWDFDocModal1Test { + + public static void main(String[] args) throws Exception { + FocusTransferWDFTest test = new FocusTransferWDFTest( + Dialog.ModalityType.DOCUMENT_MODAL, + FocusTransferWDFTest.DialogParent.FRAME, + FocusTransferWDFTest.WindowParent.NEW_FRAME); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFDocModal2Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFDocModal2Test.java new file mode 100644 index 00000000000..9f3a1f88cc8 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFDocModal2Test.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 + * @summary Check whether the focus transfer between windows occurs correctly when + * the following happens: a window having a hidden frame owner is shown; + * a document modal dialog having a null dialog owner is shown; + * a frame is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferWDFDocModal2Test + */ + +public class FocusTransferWDFDocModal2Test { + + public static void main(String[] args) throws Exception { + FocusTransferWDFTest test = new FocusTransferWDFTest( + Dialog.ModalityType.DOCUMENT_MODAL, + FocusTransferWDFTest.DialogParent.NULL_DIALOG, + FocusTransferWDFTest.WindowParent.NEW_FRAME); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFDocModal3Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFDocModal3Test.java new file mode 100644 index 00000000000..2c116b09677 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFDocModal3Test.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 + * @summary Check whether the focus transfer between windows occurs correctly when + * the following happens: a window having a frame (F) owner is shown; + * a document modal dialog having F owner is shown; F is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferWDFDocModal3Test + */ + +public class FocusTransferWDFDocModal3Test { + + public static void main(String[] args) throws Exception { + FocusTransferWDFTest test = new FocusTransferWDFTest( + Dialog.ModalityType.DOCUMENT_MODAL, + FocusTransferWDFTest.DialogParent.FRAME, + FocusTransferWDFTest.WindowParent.FRAME); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFModeless1Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFModeless1Test.java new file mode 100644 index 00000000000..73d36b65bf0 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFModeless1Test.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 + * @summary Check whether the focus transfer between windows occurs correctly when + * the following happens: a window having a hidden frame owner is shown; + * a modeless dialog having a frame (F) owner is shown; F is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferWDFModeless1Test + */ + +public class FocusTransferWDFModeless1Test { + + public static void main(String[] args) throws Exception { + FocusTransferWDFTest test = new FocusTransferWDFTest( + Dialog.ModalityType.MODELESS, + FocusTransferWDFTest.DialogParent.FRAME, + FocusTransferWDFTest.WindowParent.NEW_FRAME); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFModeless2Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFModeless2Test.java new file mode 100644 index 00000000000..e496e253f58 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFModeless2Test.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 + * @summary Check whether the focus transfer between windows occurs correctly when + * the following happens: a window having a hidden frame owner is shown; + * a modeless dialog having a null dialog owner is shown; + * a frame is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferWDFModeless2Test + */ + +public class FocusTransferWDFModeless2Test { + + public static void main(String[] args) throws Exception { + FocusTransferWDFTest test = new FocusTransferWDFTest( + Dialog.ModalityType.MODELESS, + FocusTransferWDFTest.DialogParent.FRAME, + FocusTransferWDFTest.WindowParent.NEW_FRAME); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFModeless3Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFModeless3Test.java new file mode 100644 index 00000000000..df3ff81dc3d --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFModeless3Test.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 + * @summary Check whether the focus transfer between windows occurs correctly when + * the following happens: a window having a frame (F) owner is shown; + * a modeless dialog having F owner is shown; F is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferWDFModeless3Test + */ + +public class FocusTransferWDFModeless3Test { + + public static void main(String[] args) throws Exception { + FocusTransferWDFTest test = new FocusTransferWDFTest( + Dialog.ModalityType.MODELESS, + FocusTransferWDFTest.DialogParent.FRAME, + FocusTransferWDFTest.WindowParent.FRAME); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFNonModal1Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFNonModal1Test.java new file mode 100644 index 00000000000..c700a054136 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFNonModal1Test.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 + * @summary Check whether the focus transfer between windows occurs correctly when + * the following happens: a window having a hidden frame owner is shown; + * a non-modal dialog having a frame (F) owner is shown; F is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferWDFNonModal1Test + */ + +public class FocusTransferWDFNonModal1Test { + + public static void main(String[] args) throws Exception { + FocusTransferWDFTest test = new FocusTransferWDFTest( + null, + FocusTransferWDFTest.DialogParent.FRAME, + FocusTransferWDFTest.WindowParent.NEW_FRAME); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFNonModal2Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFNonModal2Test.java new file mode 100644 index 00000000000..5e36b8d50a7 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFNonModal2Test.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 + * @summary Check whether the focus transfer between windows occurs correctly when + * the following happens: a window having a hidden frame owner is shown; + * a non-modal dialog having a null dialog owner is shown; + * a frame is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferWDFNonModal2Test + */ + +public class FocusTransferWDFNonModal2Test { + + public static void main(String[] args) throws Exception { + FocusTransferWDFTest test = new FocusTransferWDFTest( + null, + FocusTransferWDFTest.DialogParent.NULL_DIALOG, + FocusTransferWDFTest.WindowParent.NEW_FRAME); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFNonModal3Test.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFNonModal3Test.java new file mode 100644 index 00000000000..e0d3ebbb1f2 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFNonModal3Test.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2007, 2014, 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.Dialog; + +/* + * @test + * @bug 8047367 + * @summary Check whether the focus transfer between windows occurs correctly when + * the following happens: a window having a frame (F) owner is shown; + * a non-modal dialog having F owner is shown; F is shown. + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main FocusTransferWDFNonModal3Test + */ + +public class FocusTransferWDFNonModal3Test { + + public static void main(String[] args) throws Exception { + FocusTransferWDFTest test = new FocusTransferWDFTest( + null, + FocusTransferWDFTest.DialogParent.FRAME, + FocusTransferWDFTest.WindowParent.FRAME); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFTest.java b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFTest.java new file mode 100644 index 00000000000..d79e715bfe9 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFTest.java @@ -0,0 +1,272 @@ +/* + * Copyright (c) 2007, 2014, 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.*; +import static jdk.testlibrary.Asserts.*; + +// WDF: Window -> Dialog -> Frame +public class FocusTransferWDFTest { + + class CustomDialog extends TestDialog { + + public CustomDialog(Frame f) { + super(f); + } + + public CustomDialog(Dialog d) { + super(d); + } + + @Override + public void doOpenAction() { + if (frame != null) { + frame.setVisible(true); + } + } + + @Override + public void doCloseAction() { + this.dispose(); + } + } + + class CustomFrame extends TestFrame { + + @Override + public void doCloseAction() { + this.dispose(); + } + } + + class CustomWindow extends TestWindow { + + public CustomWindow(Frame f) { + super(f); + } + + @Override + public void doOpenAction() { + if (dialog != null) { + dialog.setVisible(true); + } + } + } + + + private TestDialog dialog; + private TestFrame frame; + private TestWindow window; + + private Frame parentFrame; + + private static final int delay = 1000; + + private final ExtendedRobot robot; + + private Dialog.ModalityType modalityType; + + public enum DialogParent {FRAME, NULL_DIALOG}; + private DialogParent dialogParent; + + public enum WindowParent {FRAME, NEW_FRAME}; + private WindowParent windowParent; + + + FocusTransferWDFTest(Dialog.ModalityType modType, + DialogParent dlgParent, + WindowParent winParent) throws Exception { + + modalityType = modType; + dialogParent = dlgParent; + windowParent = winParent; + + robot = new ExtendedRobot(); + EventQueue.invokeLater( this::createGUI ); + } + + private void createGUI() { + + frame = new CustomFrame(); + frame.setLocation(50, 50); + + switch (dialogParent) { + case FRAME: + dialog = new CustomDialog(frame); + break; + case NULL_DIALOG: + dialog = new CustomDialog((Dialog) null); + break; + } + assertTrue(dialog != null, "error: null dialog"); + + if (modalityType == null) { + modalityType = Dialog.ModalityType.MODELESS; + } else { + dialog.setModalityType(modalityType); + } + + dialog.setLocation(250, 50); + + switch (windowParent) { + case FRAME: + window = new CustomWindow(frame); + break; + case NEW_FRAME: + parentFrame = new Frame(); + window = new CustomWindow(parentFrame); + break; + } + assertTrue(window != null, "error: null window"); + + window.setLocation(450, 50); + window.setVisible(true); + } + + private void closeAll() { + if (dialog != null) { dialog.dispose(); } + if ( frame != null) { frame.dispose(); } + if (window != null) { window.dispose(); } + + if (parentFrame != null) { parentFrame.dispose(); } + } + + private void ModalTest() throws Exception { + frame.checkCloseButtonFocusGained(false, 10); + dialog.checkOpenButtonFocusLost(false, 10); + + dialog.clickCloseButton(robot); + robot.waitForIdle(delay); + + frame.checkCloseButtonFocusGained(true); + + window.openGained.reset(); + + frame.clickCloseButton(robot); + robot.waitForIdle(delay); + } + + public void doTest() throws Exception { + + try { + + robot.waitForIdle(delay); + + window.checkCloseButtonFocusGained(false, 10); + + window.clickOpenButton(robot); + robot.waitForIdle(delay); + + dialog.checkCloseButtonFocusGained(true); + window.checkOpenButtonFocusLost(false, 10); + + dialog.clickOpenButton(robot); + robot.waitForIdle(delay); + + switch (modalityType) { + case APPLICATION_MODAL: + ModalTest(); + if (windowParent == WindowParent.FRAME) { + assertFalse(window.isVisible(), + "window shouldn't be visible"); + } else { // WindowParent.NEW_FRAME + window.checkOpenButtonFocusGained(false, 10); + } + + break; + + case DOCUMENT_MODAL: + if (dialogParent == DialogParent.FRAME) { + ModalTest(); + if (windowParent == WindowParent.FRAME) { // 10 + assertFalse(window.isVisible(), + "window shouldn't be visible"); + } else { // WindowParent.NEW_FRAME + window.checkOpenButtonFocusGained(false, 10); + } + } else { // DialogParent.NULL_DIALOG + frame.checkCloseButtonFocusGained(true); + dialog.checkOpenButtonFocusLost(true); + + dialog.openGained.reset(); + + frame.clickCloseButton(robot); + robot.waitForIdle(delay); + + dialog.checkOpenButtonFocusGained(true); + + window.openGained.reset(); + + dialog.clickCloseButton(robot); + robot.waitForIdle(delay); + + window.checkOpenButtonFocusGained(false, 10); + } + break; + + case MODELESS: + + frame.checkCloseButtonFocusGained(true); + dialog.checkOpenButtonFocusLost(true); + + dialog.openGained.reset(); + + frame.clickCloseButton(robot); + robot.waitForIdle(delay); + + if (dialogParent == DialogParent.NULL_DIALOG) { + dialog.checkOpenButtonFocusGained(true); + + window.openGained.reset(); + + dialog.clickCloseButton(robot); + robot.waitForIdle(delay); + + window.checkOpenButtonFocusGained(false, 10); + } else { + assertFalse(dialog.isVisible(), + "dialog shouldn't be visible"); + + if (windowParent == WindowParent.FRAME) { + assertFalse(window.isVisible(), + "window shouldn't be visible"); + } + } + + break; + } + + } catch (Exception e) { + + // make screenshot before exit + Rectangle rect = new Rectangle(0, 0, 650, 250); + java.awt.image.BufferedImage img = robot.createScreenCapture(rect); + javax.imageio.ImageIO.write(img, "jpg", new java.io.File("NOK.jpg")); + + throw e; + } + + robot.waitForIdle(delay); + EventQueue.invokeAndWait(this::closeAll); + } +} diff --git a/jdk/test/java/awt/Modal/ModalitySettingsTest/ModalitySettingsTest.java b/jdk/test/java/awt/Modal/ModalitySettingsTest/ModalitySettingsTest.java new file mode 100644 index 00000000000..614b32cd090 --- /dev/null +++ b/jdk/test/java/awt/Modal/ModalitySettingsTest/ModalitySettingsTest.java @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2007, 2014, 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.*; +import static jdk.testlibrary.Asserts.*; + +/* + * @test + * @bug 8047367 + * @summary Check modality settings for Window and Dialog. + * + * @library ../../../../lib/testlibrary/ + * @run main ModalitySettingsTest + */ + + + +public class ModalitySettingsTest { + + private void doTest() throws Exception { + + Window w = new Window(new Frame()); + + boolean unexpectedExc = false; + + try { + Dialog d = new Dialog(w); + } catch (IllegalArgumentException iae) { + } catch (Exception e) { + unexpectedExc = true; + } + + assertFalse(unexpectedExc, "unexpected exception occured when a " + + "Window instance was passed to Dialog constructor"); + + Dialog d = new Dialog((Frame) null); + assertTrue(d.getModalityType() == Dialog.ModalityType.MODELESS, + "the default modality type returned by Dialog " + + "differs from Dialog.ModalityType.MODELESS"); + + Frame f = new Frame(); + assertTrue(f.getModalExclusionType() == Dialog.ModalExclusionType.NO_EXCLUDE, + "the default modality exclusion type returned by Frame" + + "differs from Dialog.ModalExclusionType.NO_EXCLUDE"); + + w = new Window((Frame) null); + assertTrue(w.getModalExclusionType() == Dialog.ModalExclusionType.NO_EXCLUDE, + "the default modality exclusion type returned by Window " + + "differs from Dialog.ModalExclusionType.NO_EXCLUDE"); + + d = new Dialog((Frame) null); + assertTrue(d.getModalExclusionType() == Dialog.ModalExclusionType.NO_EXCLUDE, + "the default modality exclusion type returned by Dialog " + + "differs from Dialog.ModalExclusionType.NO_EXCLUDE"); + + d.setModalityType(Dialog.ModalityType.TOOLKIT_MODAL); + assertTrue(d.getModalityType() == Dialog.ModalityType.TOOLKIT_MODAL, + "the modality type returned by Dialog " + + "differs from Dialog.ModalityType.TOOLKIT_MODAL " + + "after setting the modality type to that value"); + + d.setModal(false); + assertTrue(d.getModalityType() == Dialog.ModalityType.MODELESS, + "the modality type returned by Dialog differs from " + + "Dialog.ModalityType.MODELESS after calling setModal(false)"); + + d.setModal(true); + assertTrue(d.getModalityType() == Dialog.ModalityType.APPLICATION_MODAL, + "the modality type returned by Dialog differs from " + + "Dialog.ModalityType.APPLICATION_MODAL after calling setModal(true)"); + + w.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE); + assertTrue(w.getModalExclusionType() == + Dialog.ModalExclusionType.APPLICATION_EXCLUDE, + "getModalExclusionType method for Window did not return " + + "Dialog.ModalExclusionType.APPLICATION_EXCLUDE after " + + "setting it to that value"); + + d = new Dialog((Frame) null); + d.setModalityType(Dialog.ModalityType.TOOLKIT_MODAL); + assertTrue(d.isModal(), "method isModal for Dialog " + + "returned false when the Dialog is toolkit modal"); + + d.setModalityType(Dialog.ModalityType.MODELESS); + assertFalse(d.isModal(), "method isModal for Dialog " + + "returned true when the Dialog is MODELESS"); + + d = new Dialog((Frame) null, (Dialog.ModalityType) null); + assertTrue(d.getModalityType() == Dialog.ModalityType.MODELESS, + "The modality type returned for a Dialog constructed " + + "with null modality type differs from MODELESS"); + + d = new Dialog((Frame) null); + d.setModalityType(null); + assertTrue(d.getModalityType() == Dialog.ModalityType.MODELESS, + "the modality type returned for a Dialog set with null " + + "modality type differs from MODELESS"); + + d.setModalExclusionType(null); + assertTrue(d.getModalExclusionType() == Dialog.ModalExclusionType.NO_EXCLUDE, + "The exlcusion type returned for a Dialog set with null " + + "exclusion type differs from NO_EXCLUDE"); + + try { + Dialog.ModalityType.valueOf("invalid"); + } catch (IllegalArgumentException iae) { + } catch (Exception e) { + unexpectedExc = true; + } + + assertFalse(unexpectedExc, "unexpected exception occured when an " + + "invalid value was passed to ModalityType.valueOf method"); + } + + public static void main(String[] args) throws Exception { + ModalitySettingsTest test = new ModalitySettingsTest(); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/NullModalityDialogTest/NullModalityDialogTest.java b/jdk/test/java/awt/Modal/NullModalityDialogTest/NullModalityDialogTest.java new file mode 100644 index 00000000000..f8632ff14df --- /dev/null +++ b/jdk/test/java/awt/Modal/NullModalityDialogTest/NullModalityDialogTest.java @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2007, 2014, 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.*; +import java.awt.event.KeyEvent; + +import static jdk.testlibrary.Asserts.*; + + +/* + * @test + * @bug 8047367 + * @summary Check whether a Dialog set with null modality type + * behaves like a modeless dialog + * + * @library ../helpers ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @build Flag + * @build TestDialog + * @build TestFrame + * @build TestWindow + * @run main NullModalityDialogTest + */ + + +public class NullModalityDialogTest { + + class CustomDialog extends TestDialog { + public CustomDialog(Frame f) { + super(f); + } + @Override + public void doOpenAction() { + if (frame != null) { + frame.setVisible(true); + } + if (window != null) { + window.setVisible(true); + } + } + } + + class CustomFrame extends TestFrame { + @Override + public void doOpenAction() { + if (dialog != null) { + dialog.setVisible(true); + } + } + } + + private TestFrame parent; + private TestDialog dialog; + private TestFrame frame; + private TestWindow window; + + private static final int delay = 1000; + + private final ExtendedRobot robot; + + NullModalityDialogTest() throws Exception { + + robot = new ExtendedRobot(); + EventQueue.invokeLater(this::createGUI); + } + + private void createGUI() { + + parent = new CustomFrame(); + parent.setTitle("Parent"); + parent.setLocation(50, 50); + + dialog = new CustomDialog(parent); + dialog.setTitle("Dialog"); + dialog.setModalityType((Dialog.ModalityType) null); + dialog.setLocation(250, 50); + + frame = new TestFrame(); + frame.setTitle("Frame"); + frame.setLocation(50, 250); + + window = new TestWindow(frame); + window.setLocation(250, 250); + + parent.setVisible(true); + } + + private void closeAll() { + if (parent != null) { parent.dispose(); } + if (dialog != null) { dialog.dispose(); } + if (frame != null) { frame.dispose(); } + if (window != null) { window.dispose(); } + } + + public void doTest() throws Exception { + + robot.waitForIdle(delay); + + parent.clickOpenButton(robot); + robot.waitForIdle(delay); + + dialog.activated.waitForFlagTriggered(); + assertTrue(dialog.activated.flag(), "Dialog did not trigger " + + "Window Activated event when it became visible"); + + dialog.closeGained.waitForFlagTriggered(); + assertTrue(dialog.closeGained.flag(), "the 1st button did not gain focus " + + "when the Dialog became visible"); + + assertTrue(dialog.closeButton.hasFocus(), "the 1st button in the Dialog " + + "gained focus but lost it afterwards"); + + dialog.openGained.reset(); + + robot.type(KeyEvent.VK_TAB); + + dialog.openGained.waitForFlagTriggered(); + assertTrue(dialog.openGained.flag(), + "Tab navigation did not happen properly on Dialog. Open button " + + "did not gain focus on tab press when parent frame is visible"); + + dialog.clickOpenButton(robot); + robot.waitForIdle(delay); + + frame.activated.waitForFlagTriggered(); + assertTrue(frame.activated.flag(), "Frame did not trigger activated when " + + "made visible. Dialog and its parent frame are visible"); + + frame.checkUnblockedFrame(robot, "Frame is the parent of a visible Dialog."); + window.checkUnblockedWindow(robot, "Frame and its child Dialog are visible."); + + robot.waitForIdle(delay); + + EventQueue.invokeAndWait(this::closeAll); + } + + public static void main(String[] args) throws Exception { + NullModalityDialogTest test = new NullModalityDialogTest(); + test.doTest(); + } +} diff --git a/jdk/test/java/awt/Modal/helpers/TestDialog.java b/jdk/test/java/awt/Modal/helpers/TestDialog.java index a3791778bc1..d547886cddc 100644 --- a/jdk/test/java/awt/Modal/helpers/TestDialog.java +++ b/jdk/test/java/awt/Modal/helpers/TestDialog.java @@ -332,35 +332,47 @@ public class TestDialog extends Dialog implements ActionListener, "button did not gain focus. " + message); } - public void checkCloseButtonFocusGained() { - checkCloseButtonFocusGained(Flag.ATTEMPTS); + public void checkCloseButtonFocusGained(boolean refState) { + checkCloseButtonFocusGained(refState, Flag.ATTEMPTS); } - public void checkCloseButtonFocusGained(int attempts) { + public void checkCloseButtonFocusGained(boolean refState, int attempts) { try { closeGained.waitForFlagTriggered(attempts); } catch (InterruptedException e) {} - assertTrue(closeGained.flag(), - "dialog Close button did not gain focus"); + + String msg = "dialog Close button "; + msg += (refState ? "did not gain focus" : + "gained focus when it should not"); + + assertTrue(closeGained.flag() == refState, msg); } - public void checkOpenButtonFocusGained() { + public void checkOpenButtonFocusGained(boolean refState) { try { openGained.waitForFlagTriggered(); } catch (InterruptedException e) {} - assertTrue(openGained.flag(), - "dialog Open button did not gain focus"); + + String msg = "dialog Open button "; + msg += (refState ? "did not gain focus" : + "gained focus when it should not"); + + assertTrue(openGained.flag() == refState, msg); } - public void checkOpenButtonFocusLost() { - checkOpenButtonFocusLost(Flag.ATTEMPTS); + public void checkOpenButtonFocusLost(boolean refState) { + checkOpenButtonFocusLost(refState, Flag.ATTEMPTS); } - public void checkOpenButtonFocusLost(int attempts) { + public void checkOpenButtonFocusLost(boolean refState, int attempts) { try { openLost.waitForFlagTriggered(attempts); } catch (InterruptedException e) {} - assertTrue(openLost.flag(), - "dialog Open button did not lose focus"); + + String msg = "dialog Open button "; + msg += (refState ? "did not lose focus" : + "lost focus when it should not"); + + assertTrue(openLost.flag() == refState, msg); } } diff --git a/jdk/test/java/awt/Modal/helpers/TestFrame.java b/jdk/test/java/awt/Modal/helpers/TestFrame.java index 8b646f82291..7af2a3bf686 100644 --- a/jdk/test/java/awt/Modal/helpers/TestFrame.java +++ b/jdk/test/java/awt/Modal/helpers/TestFrame.java @@ -324,46 +324,50 @@ public class TestFrame extends Frame implements ActionListener, "button did not gain focus on tab press. " + message); } - public void checkCloseButtonFocusGained() { - checkCloseButtonFocusGained(Flag.ATTEMPTS); + public void checkCloseButtonFocusGained(boolean refState) { + checkCloseButtonFocusGained(refState, Flag.ATTEMPTS); } - public void checkCloseButtonFocusGained(int attempts) { - + public void checkCloseButtonFocusGained(boolean refState, int attempts) { try { closeGained.waitForFlagTriggered(attempts); } catch (InterruptedException e) {} - if (closeGained.flag()) { - Component focusOwner = - KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); - assertTrue(closeButton.equals(focusOwner), - "close button gained focus, but it is not the current focus owner"); - } else { - assertTrue(false, "frame Close button did not gain focus"); - } + String msg = "frame Close button "; + msg += (refState ? "did not gain focus" : + "gained focus when it should not"); + + assertTrue(closeGained.flag() == refState, msg); } - public void checkOpenButtonFocusGained() { - try { - openGained.waitForFlagTriggered(); - } catch (InterruptedException e) {} - - if (openGained.flag()) { - Component focusOwner = - KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); - assertTrue(openButton.equals(focusOwner), - "open button gained focus, but it is not the current focus owner"); - } else { - assertTrue(false, "frame Open button did not gain focus"); - } + public void checkOpenButtonFocusGained(boolean refState) { + checkOpenButtonFocusGained(refState, Flag.ATTEMPTS); } - public void checkOpenButtonFocusLost() { + public void checkOpenButtonFocusGained(boolean refState, int attempts) { try { - openLost.waitForFlagTriggered(); + openGained.waitForFlagTriggered(attempts); } catch (InterruptedException e) {} - assertTrue(openLost.flag(), "frame Open button did not lose focus"); + String msg = "frame Open button "; + msg += (refState ? "did not gain focus" : + "gained focus when it should not"); + + assertTrue(openGained.flag() == refState, msg); + } + + public void checkOpenButtonFocusLost(boolean refState) { + checkOpenButtonFocusLost(refState, Flag.ATTEMPTS); + } + + public void checkOpenButtonFocusLost(boolean refState, int attempts) { + try { + openLost.waitForFlagTriggered(attempts); + } catch (InterruptedException e) {} + + String msg = "frame Open button "; + msg += (refState ? "did not lose focus" : + "lost focus when it should not"); + assertTrue(openLost.flag()== refState, msg); } } diff --git a/jdk/test/java/awt/Modal/helpers/TestWindow.java b/jdk/test/java/awt/Modal/helpers/TestWindow.java index c929aefbf73..4e7cdb6fe79 100644 --- a/jdk/test/java/awt/Modal/helpers/TestWindow.java +++ b/jdk/test/java/awt/Modal/helpers/TestWindow.java @@ -295,39 +295,51 @@ public class TestWindow extends Window implements ActionListener, "button did not gain focus on tab press. " + message); } - public void checkCloseButtonFocusGained() { - checkCloseButtonFocusGained(Flag.ATTEMPTS); + public void checkCloseButtonFocusGained(boolean refState) { + checkCloseButtonFocusGained(refState, Flag.ATTEMPTS); } - public void checkCloseButtonFocusGained(int attempts) { + public void checkCloseButtonFocusGained(boolean refState, int attempts) { try { closeGained.waitForFlagTriggered(attempts); } catch (InterruptedException e) {} - assertTrue(closeGained.flag(), - "window Close button did not gain focus"); + + String msg = "window Close button "; + msg += (refState ? "did not gain focus" : + "gained focus when it should not"); + + assertTrue(closeGained.flag() == refState, msg); } - public void checkOpenButtonFocusGained() { - checkOpenButtonFocusGained(Flag.ATTEMPTS); + + public void checkOpenButtonFocusGained(boolean refState) { + checkOpenButtonFocusGained(refState, Flag.ATTEMPTS); } - public void checkOpenButtonFocusGained(int attempts) { + public void checkOpenButtonFocusGained(boolean refState, int attempts) { try { openGained.waitForFlagTriggered(attempts); } catch (InterruptedException e) {} - assertTrue(openGained.flag(), - "window Open button did not gain focus"); + + String msg = "window Open button "; + msg += (refState ? "did not gain focus" : + "gained focus when it should not"); + + assertTrue(openGained.flag() == refState, msg); } - public void checkOpenButtonFocusLost() { - checkOpenButtonFocusLost(Flag.ATTEMPTS); + public void checkOpenButtonFocusLost(boolean refState) { + checkOpenButtonFocusLost(refState, Flag.ATTEMPTS); } - public void checkOpenButtonFocusLost(int attempts) { + public void checkOpenButtonFocusLost(boolean refState, int attempts) { try { openLost.waitForFlagTriggered(attempts); } catch (InterruptedException e) {} - assertTrue(openLost.flag(), - "window Open button did not lose focus"); + + String msg = "window Open button "; + msg += (refState ? "did not lose focus" : + "lost focus when it should not"); + assertTrue(openLost.flag()== refState, msg); } }