Path: blob/master/test/jdk/java/awt/Modal/OnTop/OnTopDDFTest.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.*;2627// DDF: Dialog - Dialog - Frame2829public class OnTopDDFTest {3031private volatile TestDialog dialog, leftDialog;32private volatile TestFrame rightFrame;33private volatile Frame hiddenFrame;3435private static final int delay = 500;36private final ExtendedRobot robot;3738boolean setModal;3940Dialog.ModalityType modalityType;4142private OnTopDDFTest(Dialog.ModalityType modType,43boolean modal) throws Exception {44modalityType = modType;45setModal = modal;4647robot = new ExtendedRobot();48EventQueue.invokeLater(this::createGUI);49}5051public OnTopDDFTest(Dialog.ModalityType modalityType) throws Exception {52this(modalityType, false);53}5455public OnTopDDFTest() throws Exception {56this(null, true);57}5859private void createGUI() {6061hiddenFrame = new Frame();62leftDialog = new TestDialog(hiddenFrame);63leftDialog.setSize(200, 100);64leftDialog.setLocation(50, 50);65leftDialog.setVisible(true);6667dialog = new CustomDialog(leftDialog);68if (setModal) {69dialog.setModal(true);70modalityType = dialog.getModalityType();71} else if (modalityType != null) {72dialog.setModalityType(modalityType);73}7475dialog.setSize(200, 100);76dialog.setLocation(200, 50);7778rightFrame = new TestFrame();79rightFrame.setSize(200, 100);80rightFrame.setLocation(350, 50);8182dialog.setVisible(true);83}8485public void doTest() throws Exception {8687try {8889robot.waitForIdle(delay);9091dialog.activated.waitForFlagTriggered();92assertTrue(dialog.activated.flag(), "Dialog still not visible.");9394dialog.clickOpenButton(robot);95robot.waitForIdle(delay);9697if ((modalityType == Dialog.ModalityType.MODELESS) ||98(modalityType == Dialog.ModalityType.DOCUMENT_MODAL)) {99100rightFrame.clickCloseButton(robot);101robot.waitForIdle(delay);102103rightFrame.closeClicked.reset();104dialog.transferFocusToDialog(robot, "A Frame partially hides the " +105modalityType + " Dialog.", dialog.openButton);106robot.waitForIdle(delay);107108dialog.checkUnblockedDialog(robot,109"This is " + modalityType + " dialog and no other Dialogs blocks it.");110robot.waitForIdle(delay);111112rightFrame.closeClicked.waitForFlagTriggered(5);113assertFalse(rightFrame.closeClicked.flag(), "Clicking on " + modalityType +114"dialog did not bring it to the top. A frame on top of Dialog.");115robot.waitForIdle(delay);116117dialog.closeClicked.reset();118if (modalityType == Dialog.ModalityType.MODELESS) {119leftDialog.transferFocusToDialog(robot, "This dialog is not " +120"blocked by any other dialogs.", leftDialog.closeButton);121} else {122leftDialog.transferFocusToBlockedDialog(robot, "This dialog is not " +123"blocked by any other dialogs.", leftDialog.closeButton);124}125} else {126dialog.checkUnblockedDialog(robot, "Checking if modal dialog " +127"appears on top of blocked Frame.");128robot.waitForIdle(delay);129130rightFrame.closeClicked.waitForFlagTriggered(5);131assertFalse(rightFrame.closeClicked.flag(),132"Frame on top of an application modal Dialog.");133robot.waitForIdle(delay);134135leftDialog.transferFocusToBlockedDialog(robot,136"An application modal dialog blocks the Dialog.", leftDialog.closeButton);137}138139robot.waitForIdle(delay);140141dialog.clickCloseButton(robot);142robot.waitForIdle(delay);143144} finally {145EventQueue.invokeAndWait(this::closeAll);146}147}148149private void closeAll() {150if (dialog != null) { dialog.dispose(); }151if (leftDialog != null) { leftDialog.dispose(); }152if (rightFrame != null) { rightFrame.dispose(); }153if (hiddenFrame != null) { hiddenFrame.dispose(); }154}155156157class CustomDialog extends TestDialog {158159public CustomDialog(Dialog d) { super(d); }160161@Override162public void doOpenAction() {163if (rightFrame != null) {164rightFrame.setVisible(true);165}166}167}168}169170171