Path: blob/master/test/jdk/java/awt/Modal/ModalBlockingTests/BlockingDFTest.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*/222324import java.awt.*;25import static jdk.test.lib.Asserts.*;262728// DF: Dialog -> Frame2930public class BlockingDFTest {3132private TestDialog dialog;33private TestFrame frame;3435private static final int delay = 500;36private final ExtendedRobot robot;3738private BlockingDFTest(Dialog.ModalityType modalityType,39boolean setModal) throws Exception {4041robot = new ExtendedRobot();42EventQueue.invokeLater(() -> { createGUI(modalityType, setModal); });43}4445public BlockingDFTest(Dialog.ModalityType modalityType) throws Exception {46this(modalityType, false);47}4849public BlockingDFTest() throws Exception { this(null, true); }505152private void createGUI(Dialog.ModalityType modalityType,53boolean setModal) {5455frame = new TestFrame();56frame.setLocation(50, 50);57frame.setVisible(true);5859dialog = new TestDialog((Dialog) null);60dialog.setLocation(250, 50);61if (setModal) {62dialog.setModal(true);63} else if (modalityType != null) {64dialog.setModalityType(modalityType);65}6667dialog.setVisible(true);68}6970public void doTest() throws Exception {7172try {7374robot.waitForIdle(delay);75dialog.activated.waitForFlagTriggered();76assertTrue(dialog.activated.flag(), "Dialog did not trigger " +77"Window Activated event when it became visible");7879dialog.closeGained.waitForFlagTriggered();80assertTrue(dialog.closeGained.flag(), "The 1st button did not " +81"gain focus when the dialog became visible");8283dialog.checkUnblockedDialog(robot, "");84frame.checkBlockedFrame(robot, "");85robot.waitForIdle(delay);8687} finally {88EventQueue.invokeAndWait(this::closeAll);89}90}9192private void closeAll() {93if (frame != null) { frame.dispose(); }94if (dialog != null) { dialog.dispose(); }95}96}979899