Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Modal/MultipleDialogs/MultipleDialogs4Test.java
38828 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*/2223/*24* @test25* @bug 8054358 805500326* @summary Check whether application and document modality levels for Dialog27* work properly. Also check whether the blocking dialogs are28* opening on top of the windows they block.29*30* @library ../helpers ../../../../lib/testlibrary/31* @build ExtendedRobot32* @build Flag33* @build TestDialog34* @build TestFrame35* @run main MultipleDialogs4Test36*/373839import java.awt.*;40import static jdk.testlibrary.Asserts.*;414243public class MultipleDialogs4Test {4445private volatile TopLevelFrame frame;46private volatile CustomFrame secondFrame;47private volatile TestFrame thirdFrame;48private volatile TestDialog dialog, secondDialog, docChildDialog, appChildDialog;4950private static final int delay = 500;515253private void createGUI() {5455frame = new TopLevelFrame();56frame.setLocation(50, 50);57frame.setVisible(true);5859dialog = new TestDialog((Dialog) null);60dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);61dialog.setLocation(150, 50);6263appChildDialog = new TestDialog(dialog);64appChildDialog.setLocation(150, 90);6566secondFrame = new CustomFrame();67secondFrame.setLocation(50, 250);6869secondDialog = new TestDialog(secondFrame);70secondDialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);71secondDialog.setLocation(150, 250);7273docChildDialog = new TestDialog(secondFrame);74docChildDialog.setBackground(Color.black);75docChildDialog.setLocation(250, 250);7677thirdFrame = new TestFrame();78thirdFrame.setLocation(250, 50);79}8081public void doTest() throws Exception {8283try {84EventQueue.invokeAndWait(this::createGUI);8586final int nAttempts = 3;87ExtendedRobot robot = new ExtendedRobot();88robot.waitForIdle(delay);8990frame.clickOpenButton(robot);91robot.waitForIdle(delay);9293secondFrame.clickOpenButton(robot);94robot.waitForIdle(delay);9596secondFrame.checkBlockedFrame(robot,97"A document modal dialog should block this Frame.");9899secondDialog.checkUnblockedDialog(robot, "This is a document " +100"modal dialog. No window blocks it.");101102frame.checkUnblockedFrame(robot,103"There are no dialogs blocking this Frame.");104105frame.clickCloseButton(robot);106robot.waitForIdle(delay);107108frame.clickDummyButton(robot, nAttempts, false,109"The frame still on top even after showing a modal dialog.");110robot.waitForIdle(delay);111112EventQueue.invokeAndWait(() -> { thirdFrame.setVisible(true); });113robot.waitForIdle(delay);114115dialog.clickDummyButton(robot);116robot.waitForIdle(delay);117118secondDialog.clickDummyButton(119robot, nAttempts, false, "The document modal dialog " +120"was not blocked by an application modal dialog.");121robot.waitForIdle(delay);122123EventQueue.invokeLater(() -> { docChildDialog.setVisible(true); });124robot.waitForIdle(delay);125126Color c = robot.getPixelColor(127(int) secondDialog.getLocationOnScreen().x + secondDialog.getSize().width - 25,128(int) secondDialog.getLocationOnScreen().y + secondDialog.getSize().height - 25);129assertFalse(c.equals(Color.black), "A dialog which should be blocked " +130"by document modal dialog overlapping it.");131132EventQueue.invokeLater(() -> { appChildDialog.setVisible(true); });133robot.waitForIdle(delay);134135appChildDialog.activated.waitForFlagTriggered();136assertTrue(appChildDialog.activated.flag(), "The child dialog of the " +137"application modal dialog still not visible.");138robot.waitForIdle(delay);139140dialog.clickDummyButton(robot, nAttempts, false, "The child dialog of " +141"the application modal dialog did not overlap it.");142robot.waitForIdle(delay);143144} finally {145EventQueue.invokeAndWait(this::closeAll);146}147}148149public void closeAll() {150151if (frame != null) { frame.dispose(); }152if (dialog != null) { dialog.dispose(); }153if (appChildDialog != null) { appChildDialog.dispose(); }154if (secondFrame != null) { secondFrame.dispose(); }155if (secondDialog != null) { secondDialog.dispose(); }156if (docChildDialog != null) { docChildDialog.dispose(); }157if (thirdFrame != null) { thirdFrame.dispose(); }158}159160class TopLevelFrame extends TestFrame {161162@Override163public void doOpenAction() { secondFrame.setVisible(true); }164@Override165public void doCloseAction() { dialog.setVisible(true); }166}167168class CustomFrame extends TestFrame {169170@Override171public void doOpenAction() { secondDialog.setVisible(true); }172}173174public static void main(String[] args) throws Exception {175(new MultipleDialogs4Test()).doTest();176}177}178179180