Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Modal/MultipleDialogs/MultipleDialogs5Test.java
38828 views
/*1* Copyright (c) 2007, 2014, 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* @bug 805435826* @summary This is a simple check if a chain of dialogs having different27* modality types block each other properly.28*29* @library ../helpers ../../../../lib/testlibrary/30* @build ExtendedRobot31* @build Flag32* @build TestDialog33* @build TestFrame34* @build TestWindow35* @run main MultipleDialogs5Test36*/373839import java.awt.*;40import static jdk.testlibrary.Asserts.*;414243public class MultipleDialogs5Test {4445private volatile ParentFrame parent;46private volatile ModalDialog appDialog, docDialog, tkDialog;47private volatile CustomWindow window;4849private static int delay = 500;5051private void createGUI() {5253parent = new ParentFrame();54parent.setLocation(50, 50);55parent.setVisible(true);5657appDialog = new ModalDialog(parent);58appDialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);59appDialog.setLocation(250, 50);6061docDialog = new ModalDialog(appDialog);62docDialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);63docDialog.setLocation(450, 50);6465window = new CustomWindow(docDialog);66window.setLocation(50, 250);6768tkDialog = new ModalDialog(docDialog);69tkDialog.setLocation(250, 250);70tkDialog.setModalityType(Dialog.ModalityType.TOOLKIT_MODAL);7172appDialog.setWindowToOpen(docDialog);73docDialog.setWindowToOpen(window);74}7576public void doTest() throws Exception {7778try {79EventQueue.invokeAndWait(this::createGUI);8081ExtendedRobot robot = new ExtendedRobot();82robot.waitForIdle(delay);8384parent.clickOpenButton(robot);85robot.waitForIdle(delay);8687parent.checkBlockedFrame(robot,88"This Frame is blocked by an application modal dialog.");8990appDialog.clickOpenButton(robot);91robot.waitForIdle(delay);9293appDialog.checkBlockedDialog(robot,94"This Dialog is blocked by a document modal dialog.");9596docDialog.clickOpenButton(robot);97robot.waitForIdle(delay);9899docDialog.checkUnblockedDialog(robot,100"This Dialog is not blocked by any modal dialog.");101102window.clickOpenButton(robot);103robot.waitForIdle(delay);104105window.checkBlockedWindow(robot,106"This Window is blocked by a toolkit modal dialog.");107108tkDialog.clickCloseButton(robot);109robot.waitForIdle(delay);110assertFalse(tkDialog.isVisible(),111"The toolkit modal dialog was not disposed.");112113window.clickCloseButton(robot);114robot.waitForIdle(delay);115assertFalse(window.isVisible(),116"The window was not disposed.");117118docDialog.clickCloseButton(robot);119robot.waitForIdle(delay);120assertFalse(docDialog.isVisible(),121"The document modal dialog was not disposed.");122123appDialog.clickCloseButton(robot);124robot.waitForIdle(delay);125assertFalse(appDialog.isVisible(),126"The application modal dialog was not disposed.");127} finally {128EventQueue.invokeAndWait(this::closeAll); // if something wasn't closed129}130}131132private void closeAll() {133134if (appDialog != null) { appDialog.dispose(); }135if (tkDialog != null) { tkDialog.dispose(); }136if (docDialog != null) { docDialog.dispose(); }137if (parent != null) { parent.dispose(); }138if (window != null) { window.dispose(); }139}140141private class ParentFrame extends TestFrame {142143@Override144public void doOpenAction() {145if (appDialog != null) { appDialog.setVisible(true); }146}147}148149private class CustomWindow extends TestWindow {150151public CustomWindow(Dialog d) { super(d); }152153@Override154public void doOpenAction() {155if (tkDialog != null) { tkDialog.setVisible(true); }156}157158@Override159public void doCloseAction() { this.dispose(); }160}161162private class ModalDialog extends TestDialog {163164private Window w;165166public ModalDialog(Frame f) { super(f); }167public ModalDialog(Dialog d) { super(d); }168169public void setWindowToOpen(Window w) { this.w = w; }170171@Override172public void doCloseAction() { this.dispose(); }173174@Override175public void doOpenAction() {176if (w != null) { w.setVisible(true); }177}178}179180public static void main(String[] args) throws Exception {181(new MultipleDialogs5Test()).doTest();182}183}184185186