Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Modal/ModalBlockingTests/BlockingDocModalTest.java
38829 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*/222324import java.awt.*;25import static jdk.testlibrary.Asserts.*;262728/*29* @test30* @bug 804961731* @summary Test if a document modality works as expected:32* whether all the windows lying down the document root33* (Frame) get blocked.34*35* @library ../helpers ../../../../lib/testlibrary/36* @build ExtendedRobot37* @build Flag38* @build TestDialog39* @build TestFrame40* @build TestWindow41* @run main BlockingDocModalTest42*/434445public class BlockingDocModalTest {4647private static final int delay = 500;48private final ExtendedRobot robot;4950private TestDialog dialog, childDialog;51private TestFrame frame;52private TestWindow window;535455public BlockingDocModalTest() throws Exception {5657robot = new ExtendedRobot();58EventQueue.invokeLater(this::createGUI);59}6061private void createGUI() {6263frame = new CustomFrame();64frame.setLocation(50, 50);65frame.setVisible(true);6667dialog = new TestDialog(frame);68dialog.setLocation(250, 250);69dialog.setVisible(true);7071childDialog = new CustomDialog(dialog);72childDialog.setLocation(250, 50);73childDialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);7475window = new TestWindow(frame);76window.setLocation(50, 250);77}7879public void doTest() throws Exception {8081try {8283robot.waitForIdle(delay);8485frame.clickOpenButton(robot);86robot.waitForIdle(delay);8788childDialog.activated.waitForFlagTriggered();89assertTrue(childDialog.activated.flag(), "Dialog did not trigger " +90"Window Activated event when it became visible");9192childDialog.closeGained.waitForFlagTriggered();93assertTrue(childDialog.closeGained.flag(), "the 1st button did not " +94"gain focus when the Dialog became visible");9596assertTrue(childDialog.closeButton.hasFocus(), "the 1st dialog button " +97"gained focus but lost it afterwards");9899frame.checkBlockedFrame(robot, "A document modal Dialog from " +100"this Frame's child hierarchy should block this frame");101102childDialog.checkUnblockedDialog(robot,103"This is a document modal childDialog.");104105childDialog.clickOpenButton(robot);106robot.waitForIdle(delay);107108window.checkBlockedWindow(robot,109"A document modal dialog having a parent belonging " +110"to this Window's document hierarchy is displayed.");111112dialog.checkBlockedDialog(robot,113"A document modal child dialog should block this Dialog.");114115robot.waitForIdle(delay);116117} finally {118EventQueue.invokeAndWait(this::closeAll);119}120}121122private void closeAll() {123if (dialog != null) { dialog.dispose(); }124if ( frame != null) { frame.dispose(); }125if (window != null) { window.dispose(); }126if (childDialog != null) { childDialog.dispose(); }127}128129130class CustomFrame extends TestFrame {131132@Override133public void doOpenAction() {134if (childDialog != null) { childDialog.setVisible(true); }135}136}137138class CustomDialog extends TestDialog {139140public CustomDialog(Dialog d) { super(d); }141142@Override143public void doOpenAction() {144if (window != null) { window.setVisible(true); }145}146}147148149public static void main(String[] args) throws Exception {150(new BlockingDocModalTest()).doTest();151}152}153154155