Path: blob/master/test/jdk/java/awt/Modal/ModalBlockingTests/BlockingFDTest.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.*;252627// FD: Frame -> Dialog2829public class BlockingFDTest {3031private TestFrame frame;32private TestDialog dialog;3334private static final int delay = 500;35private final ExtendedRobot robot;3637private final Dialog.ModalityType modalityType;38private final boolean setModal;3940private BlockingFDTest(Dialog.ModalityType modType, boolean modal) throws Exception {4142modalityType = modType;43setModal = modal;4445robot = new ExtendedRobot();46EventQueue.invokeLater(this::createGUI);47}4849public BlockingFDTest(Dialog.ModalityType modType) throws Exception {50this(modType, false);51}5253public BlockingFDTest() throws Exception {54this(null, true);55}5657private void createGUI() {5859frame = new CustomFrame();60frame.setLocation(50, 50);61dialog = new TestDialog(frame);62if (setModal) {63dialog.setModal(true);64} else if (modalityType != null) {65dialog.setModalityType(modalityType);66}67dialog.setLocation(250, 50);6869frame.setVisible(true);70}7172public void doTest() throws Exception {7374try {7576robot.waitForIdle(delay);7778frame.clickOpenButton(robot);79robot.waitForIdle(delay);8081dialog.activated.waitForFlagTriggered();82assertTrue(dialog.activated.flag(), "Dialog did not trigger " +83"Window Activated event when it became visible");8485dialog.closeGained.waitForFlagTriggered();86assertTrue(dialog.closeGained.flag(), "the 1st Dialog button " +87"did not gain focus when it became visible");8889assertTrue(dialog.closeButton.hasFocus(), "the 1st Dialog button " +90"gained the focus but lost it afterwards");9192if ((modalityType == Dialog.ModalityType.APPLICATION_MODAL) ||93(modalityType == Dialog.ModalityType.DOCUMENT_MODAL) ||94(modalityType == Dialog.ModalityType.TOOLKIT_MODAL) ||95setModal)96{97frame.checkBlockedFrame(robot,98"Frame is the parent of a visible " + modalityType + " Dialog.");99} else {100frame.checkUnblockedFrame(robot,101"Frame is the parent of a visible " + modalityType + " Dialog.");102}103robot.waitForIdle(delay);104105} finally {106EventQueue.invokeAndWait(this::closeAll);107}108}109110private void closeAll() {111if (frame != null) { frame.dispose(); }112if (dialog != null) { dialog.dispose(); }113}114115116class CustomFrame extends TestFrame {117118@Override119public void doOpenAction() {120if (dialog != null) { dialog.setVisible(true); }121}122}123}124125126