Path: blob/master/test/jdk/java/awt/Modal/ModalBlockingTests/BlockingDocModalTest.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/*29* @test30* @key headful31* @bug 804961732* @summary Test if a document modality works as expected:33* whether all the windows lying down the document root34* (Frame) get blocked.35*36* @library ../helpers /lib/client/37* @library /test/lib38* @build ExtendedRobot39* @build Flag40* @build TestDialog41* @build TestFrame42* @build TestWindow43* @run main BlockingDocModalTest44*/454647public class BlockingDocModalTest {4849private static final int delay = 500;50private final ExtendedRobot robot;5152private TestDialog dialog, childDialog;53private TestFrame frame;54private TestWindow window;555657public BlockingDocModalTest() throws Exception {5859robot = new ExtendedRobot();60EventQueue.invokeLater(this::createGUI);61}6263private void createGUI() {6465frame = new CustomFrame();66frame.setLocation(50, 50);67frame.setVisible(true);6869dialog = new TestDialog(frame);70dialog.setLocation(250, 250);71dialog.setVisible(true);7273childDialog = new CustomDialog(dialog);74childDialog.setLocation(250, 50);75childDialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);7677window = new TestWindow(frame);78window.setLocation(50, 250);79}8081public void doTest() throws Exception {8283try {8485robot.waitForIdle(delay);8687frame.clickOpenButton(robot);88robot.waitForIdle(delay);8990childDialog.activated.waitForFlagTriggered();91assertTrue(childDialog.activated.flag(), "Dialog did not trigger " +92"Window Activated event when it became visible");9394childDialog.closeGained.waitForFlagTriggered();95assertTrue(childDialog.closeGained.flag(), "the 1st button did not " +96"gain focus when the Dialog became visible");9798assertTrue(childDialog.closeButton.hasFocus(), "the 1st dialog button " +99"gained focus but lost it afterwards");100101frame.checkBlockedFrame(robot, "A document modal Dialog from " +102"this Frame's child hierarchy should block this frame");103104childDialog.checkUnblockedDialog(robot,105"This is a document modal childDialog.");106107childDialog.clickOpenButton(robot);108robot.waitForIdle(delay);109110window.checkBlockedWindow(robot,111"A document modal dialog having a parent belonging " +112"to this Window's document hierarchy is displayed.");113114dialog.checkBlockedDialog(robot,115"A document modal child dialog should block this Dialog.");116117robot.waitForIdle(delay);118119} finally {120EventQueue.invokeAndWait(this::closeAll);121}122}123124private void closeAll() {125if (dialog != null) { dialog.dispose(); }126if ( frame != null) { frame.dispose(); }127if (window != null) { window.dispose(); }128if (childDialog != null) { childDialog.dispose(); }129}130131132class CustomFrame extends TestFrame {133134@Override135public void doOpenAction() {136if (childDialog != null) { childDialog.setVisible(true); }137}138}139140class CustomDialog extends TestDialog {141142public CustomDialog(Dialog d) { super(d); }143144@Override145public void doOpenAction() {146if (window != null) { window.setVisible(true); }147}148}149150151public static void main(String[] args) throws Exception {152(new BlockingDocModalTest()).doTest();153}154}155156157