Path: blob/master/test/jdk/java/awt/Modal/ModalBlockingTests/BlockingDDTest.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*/2223import java.awt.*;24import static jdk.test.lib.Asserts.*;2526// DD: Dialog -> Dialog2728public class BlockingDDTest {2930private TestDialog parent, dialog;3132private static final int delay = 1000;33private final ExtendedRobot robot;3435private final Dialog.ModalityType modalityType;36private final boolean setModal;3738private BlockingDDTest(Dialog.ModalityType modType, boolean modal) throws Exception {3940modalityType = modType;41setModal = modal;42robot = new ExtendedRobot();43createGUI();44}4546public BlockingDDTest(Dialog.ModalityType modType) throws Exception {47this(modType, false);48}4950public BlockingDDTest() throws Exception {51this(null, true);52}535455private void showParent() {5657parent = new TestDialog((Frame) null);58parent.setTitle("Parent");59parent.setLocation(50, 50);60parent.setVisible(true);61}6263private void showChild() {6465dialog = new TestDialog(parent);66if (setModal) {67dialog.setModal(true);68} else if (modalityType != null) {69dialog.setModalityType(modalityType);70}7172dialog.setLocation(250, 50);73dialog.setVisible(true);74}757677private void createGUI() throws Exception {7879EventQueue.invokeAndWait(this::showParent);80robot.waitForIdle(delay);81EventQueue.invokeLater(this::showChild);82robot.waitForIdle(delay);83}8485public void doTest() throws Exception {8687try {88dialog.activated.waitForFlagTriggered();89assertTrue(dialog.activated.flag(), "Dialog did not trigger " +90"Window Activated event when it became visible");9192dialog.closeGained.waitForFlagTriggered();93assertTrue(dialog.closeGained.flag(), "the 1st Dialog button " +94"did not gain focus when it became visible");9596assertTrue(dialog.closeButton.hasFocus(), "the 1st Dialog button " +97"gained the focus but lost it afterwards");9899dialog.checkUnblockedDialog(robot, "Modal Dialog shouldn't be blocked.");100101if ((modalityType == Dialog.ModalityType.APPLICATION_MODAL) ||102(modalityType == Dialog.ModalityType.DOCUMENT_MODAL) ||103(modalityType == Dialog.ModalityType.TOOLKIT_MODAL) ||104dialog.isModal())105{106parent.checkBlockedDialog(robot,107"Dialog is the parent of a visible " + modalityType + " Dialog.");108} else {109parent.checkUnblockedDialog(robot,110"Dialog is the parent of a visible " + modalityType + " Dialog.");111}112113robot.waitForIdle(delay);114} finally {115EventQueue.invokeAndWait(this::closeAll);116}117}118119private void closeAll() {120if (parent != null) { parent.dispose(); }121if (dialog != null) { dialog.dispose(); }122}123}124125126