Path: blob/master/test/jdk/java/awt/Modal/MultipleDialogs/MultipleDialogs4Test.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*/2223/*24* @test25* @key headful26* @bug 8054358 805500327* @summary Check whether application and document modality levels for Dialog28* work properly. Also check whether the blocking dialogs are29* opening on top of the windows they block.30*31* @library ../helpers /lib/client/32* @library /test/lib33* @build ExtendedRobot34* @build Flag35* @build TestDialog36* @build TestFrame37* @run main MultipleDialogs4Test38*/394041import java.awt.*;42import static jdk.test.lib.Asserts.*;434445public class MultipleDialogs4Test {4647private volatile TopLevelFrame frame;48private volatile CustomFrame secondFrame;49private volatile TestFrame thirdFrame;50private volatile TestDialog dialog, secondDialog, docChildDialog, appChildDialog;5152private static final int delay = 500;535455private void createGUI() {5657frame = new TopLevelFrame();58frame.setLocation(50, 50);59frame.setVisible(true);6061dialog = new TestDialog((Dialog) null);62dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);63dialog.setLocation(150, 50);6465appChildDialog = new TestDialog(dialog);66appChildDialog.setLocation(150, 90);6768secondFrame = new CustomFrame();69secondFrame.setLocation(50, 250);7071secondDialog = new TestDialog(secondFrame);72secondDialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);73secondDialog.setLocation(150, 250);7475docChildDialog = new TestDialog(secondFrame);76docChildDialog.setBackground(Color.black);77docChildDialog.setLocation(250, 250);7879thirdFrame = new TestFrame();80thirdFrame.setLocation(250, 50);81}8283public void doTest() throws Exception {8485try {86EventQueue.invokeAndWait(this::createGUI);8788final int nAttempts = 3;89ExtendedRobot robot = new ExtendedRobot();90robot.waitForIdle(delay);9192frame.clickOpenButton(robot);93robot.waitForIdle(delay);9495secondFrame.clickOpenButton(robot);96robot.waitForIdle(delay);9798secondFrame.checkBlockedFrame(robot,99"A document modal dialog should block this Frame.");100101secondDialog.checkUnblockedDialog(robot, "This is a document " +102"modal dialog. No window blocks it.");103104frame.checkUnblockedFrame(robot,105"There are no dialogs blocking this Frame.");106107frame.clickCloseButton(robot);108robot.waitForIdle(delay);109110frame.clickDummyButton(robot, nAttempts, false,111"The frame still on top even after showing a modal dialog.");112robot.waitForIdle(delay);113114EventQueue.invokeAndWait(() -> { thirdFrame.setVisible(true); });115robot.waitForIdle(delay);116117dialog.clickDummyButton(robot);118robot.waitForIdle(delay);119120secondDialog.clickDummyButton(121robot, nAttempts, false, "The document modal dialog " +122"was not blocked by an application modal dialog.");123robot.waitForIdle(delay);124125EventQueue.invokeLater(() -> { docChildDialog.setVisible(true); });126robot.waitForIdle(delay);127128Color c = robot.getPixelColor(129(int) secondDialog.getLocationOnScreen().x + secondDialog.getSize().width - 25,130(int) secondDialog.getLocationOnScreen().y + secondDialog.getSize().height - 25);131assertFalse(c.equals(Color.black), "A dialog which should be blocked " +132"by document modal dialog overlapping it.");133134EventQueue.invokeLater(() -> { appChildDialog.setVisible(true); });135robot.waitForIdle(delay);136137appChildDialog.activated.waitForFlagTriggered();138assertTrue(appChildDialog.activated.flag(), "The child dialog of the " +139"application modal dialog still not visible.");140robot.waitForIdle(delay);141142dialog.clickDummyButton(robot, nAttempts, false, "The child dialog of " +143"the application modal dialog did not overlap it.");144robot.waitForIdle(delay);145146} finally {147EventQueue.invokeAndWait(this::closeAll);148}149}150151public void closeAll() {152153if (frame != null) { frame.dispose(); }154if (dialog != null) { dialog.dispose(); }155if (appChildDialog != null) { appChildDialog.dispose(); }156if (secondFrame != null) { secondFrame.dispose(); }157if (secondDialog != null) { secondDialog.dispose(); }158if (docChildDialog != null) { docChildDialog.dispose(); }159if (thirdFrame != null) { thirdFrame.dispose(); }160}161162class TopLevelFrame extends TestFrame {163164@Override165public void doOpenAction() { secondFrame.setVisible(true); }166@Override167public void doCloseAction() { dialog.setVisible(true); }168}169170class CustomFrame extends TestFrame {171172@Override173public void doOpenAction() { secondDialog.setVisible(true); }174}175176public static void main(String[] args) throws Exception {177(new MultipleDialogs4Test()).doTest();178}179}180181182