Path: blob/master/test/jdk/java/awt/Modal/MultipleDialogs/MultipleDialogs5Test.java
41153 views
/*1* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @key headful26* @bug 805435827* @summary This is a simple check if a chain of dialogs having different28* modality types block each other properly.29*30* @library ../helpers /lib/client/31* @library /test/lib32* @build ExtendedRobot33* @build Flag34* @build TestDialog35* @build TestFrame36* @build TestWindow37* @run main MultipleDialogs5Test38*/394041import java.awt.*;42import static jdk.test.lib.Asserts.*;434445public class MultipleDialogs5Test {4647private volatile ParentFrame parent;48private volatile ModalDialog appDialog, docDialog, tkDialog;49private volatile CustomWindow window;5051private static int delay = 500;5253private void createGUI() {5455parent = new ParentFrame();56parent.setLocation(50, 50);57parent.setVisible(true);5859appDialog = new ModalDialog(parent);60appDialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);61appDialog.setLocation(250, 50);6263docDialog = new ModalDialog(appDialog);64docDialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);65docDialog.setLocation(450, 50);6667window = new CustomWindow(docDialog);68window.setLocation(50, 250);6970tkDialog = new ModalDialog(docDialog);71tkDialog.setLocation(250, 250);72tkDialog.setModalityType(Dialog.ModalityType.TOOLKIT_MODAL);7374appDialog.setWindowToOpen(docDialog);75docDialog.setWindowToOpen(window);76}7778public void doTest() throws Exception {7980try {81EventQueue.invokeAndWait(this::createGUI);8283ExtendedRobot robot = new ExtendedRobot();84robot.waitForIdle(delay);8586parent.clickOpenButton(robot);87robot.waitForIdle(delay);8889parent.checkBlockedFrame(robot,90"This Frame is blocked by an application modal dialog.");9192appDialog.clickOpenButton(robot);93robot.waitForIdle(delay);9495appDialog.checkBlockedDialog(robot,96"This Dialog is blocked by a document modal dialog.");9798docDialog.clickOpenButton(robot);99robot.waitForIdle(delay);100101docDialog.checkUnblockedDialog(robot,102"This Dialog is not blocked by any modal dialog.");103104window.clickOpenButton(robot);105robot.waitForIdle(delay);106107window.checkBlockedWindow(robot,108"This Window is blocked by a toolkit modal dialog.");109110tkDialog.clickCloseButton(robot);111robot.waitForIdle(delay);112assertFalse(tkDialog.isVisible(),113"The toolkit modal dialog was not disposed.");114115window.clickCloseButton(robot);116robot.waitForIdle(delay);117assertFalse(window.isVisible(),118"The window was not disposed.");119120docDialog.clickCloseButton(robot);121robot.waitForIdle(delay);122assertFalse(docDialog.isVisible(),123"The document modal dialog was not disposed.");124125appDialog.clickCloseButton(robot);126robot.waitForIdle(delay);127assertFalse(appDialog.isVisible(),128"The application modal dialog was not disposed.");129} finally {130EventQueue.invokeAndWait(this::closeAll); // if something wasn't closed131}132}133134private void closeAll() {135136if (appDialog != null) { appDialog.dispose(); }137if (tkDialog != null) { tkDialog.dispose(); }138if (docDialog != null) { docDialog.dispose(); }139if (parent != null) { parent.dispose(); }140if (window != null) { window.dispose(); }141}142143private class ParentFrame extends TestFrame {144145@Override146public void doOpenAction() {147if (appDialog != null) { appDialog.setVisible(true); }148}149}150151private class CustomWindow extends TestWindow {152153public CustomWindow(Dialog d) { super(d); }154155@Override156public void doOpenAction() {157if (tkDialog != null) { tkDialog.setVisible(true); }158}159160@Override161public void doCloseAction() { this.dispose(); }162}163164private class ModalDialog extends TestDialog {165166private Window w;167168public ModalDialog(Frame f) { super(f); }169public ModalDialog(Dialog d) { super(d); }170171public void setWindowToOpen(Window w) { this.w = w; }172173@Override174public void doCloseAction() { this.dispose(); }175176@Override177public void doOpenAction() {178if (w != null) { w.setVisible(true); }179}180}181182public static void main(String[] args) throws Exception {183(new MultipleDialogs5Test()).doTest();184}185}186187188