Path: blob/master/test/jdk/java/awt/Modal/ToFront/FrameToFrontModalBlockedTest.java
41153 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*/2223import java.awt.*;242526public class FrameToFrontModalBlockedTest {2728private volatile CustomDialog dialog;29private volatile TestFrame leftFrame, rightFrame;30private volatile Dialog hiddenDialog;31private volatile Frame hiddenFrame;3233private static final int delay = 500;34private final ExtendedRobot robot;3536public enum DialogOwner {HIDDEN_DIALOG, NULL_DIALOG, HIDDEN_FRAME, NULL_FRAME, FRAME};3738private DialogOwner owner;39boolean setModal;4041Dialog.ModalityType modalityType;4243private FrameToFrontModalBlockedTest(Dialog.ModalityType modType,44boolean modal,45DialogOwner o) throws Exception {46modalityType = modType;47setModal = modal;48owner = o;4950robot = new ExtendedRobot();51EventQueue.invokeLater(this::createGUI);52}5354public FrameToFrontModalBlockedTest(Dialog.ModalityType modalityType,55DialogOwner o) throws Exception {56this(modalityType, false, o);57}5859public FrameToFrontModalBlockedTest(DialogOwner o) throws Exception {60this(null, true, o);61}6263private void createGUI() {6465leftFrame = new TestFrame();66leftFrame.setSize(200, 100);67leftFrame.setLocation(50, 50);68leftFrame.setVisible(true);6970switch (owner) {71case HIDDEN_DIALOG:72hiddenDialog = new Dialog((Frame) null);73dialog = new CustomDialog(hiddenDialog);74break;75case NULL_DIALOG:76dialog = new CustomDialog((Dialog) null);77break;78case HIDDEN_FRAME:79hiddenFrame = new Frame();80dialog = new CustomDialog(hiddenFrame);81break;82case NULL_FRAME:83dialog = new CustomDialog((Frame) null);84break;85case FRAME:86dialog = new CustomDialog(leftFrame);87break;88}8990if (setModal) {91dialog.setModal(true);92modalityType = dialog.getModalityType();93} else if (modalityType != null) {94dialog.setModalityType(modalityType);95}9697dialog.setSize(200, 100);98dialog.setLocation(230, 50);99100rightFrame = new TestFrame();101rightFrame.setSize(200, 100);102rightFrame.setLocation(280, 50);103104if (setModal ||105(modalityType == Dialog.ModalityType.APPLICATION_MODAL)) {106rightFrame.setModalExclusionType(107Dialog.ModalExclusionType.APPLICATION_EXCLUDE);108}109110if (modalityType == Dialog.ModalityType.TOOLKIT_MODAL) {111rightFrame.setModalExclusionType(112Dialog.ModalExclusionType.TOOLKIT_EXCLUDE);113}114115dialog.setVisible(true);116}117118private void blockingTest() throws Exception {119120dialog.clickOpenButton(robot);121robot.waitForIdle(delay);122123rightFrame.clickCloseButton(robot);124robot.waitForIdle(delay);125126EventQueue.invokeAndWait(() -> { leftFrame.toFront(); });127robot.waitForIdle(delay);128129rightFrame.clickDummyButton(robot);130robot.waitForIdle(delay);131132EventQueue.invokeAndWait(() -> { leftFrame.toFront(); });133robot.waitForIdle(delay);134135leftFrame.clickDummyButton(robot, 7, false,136"Calling toFront for Frame blocked by " + dialog.getModalityType() +137" dialog brought it to the top of the modal dialog.");138robot.waitForIdle(delay);139}140141private void docModalTest() throws Exception {142143if (owner == DialogOwner.FRAME) { blockingTest(); }144else {145EventQueue.invokeAndWait(() -> { leftFrame.toFront(); });146robot.waitForIdle(delay);147148leftFrame.clickDummyButton(robot);149robot.waitForIdle(delay);150151EventQueue.invokeAndWait(() -> { dialog.toFront(); });152robot.waitForIdle(delay);153154dialog.clickDummyButton(robot);155robot.waitForIdle(delay);156}157158}159160161public void doTest() throws Exception {162163try {164165robot.waitForIdle(delay);166167switch (modalityType) {168case APPLICATION_MODAL:169case TOOLKIT_MODAL:170blockingTest();171break;172case DOCUMENT_MODAL:173docModalTest();174break;175default:176throw new RuntimeException(177"improper modality type, please do not use it for this test");178}179180} finally {181EventQueue.invokeAndWait(this::closeAll);182}183}184185private void closeAll() {186if (dialog != null) { dialog.dispose(); }187if (leftFrame != null) { leftFrame.dispose(); }188if (rightFrame != null) { rightFrame.dispose(); }189if (hiddenDialog != null) { hiddenDialog.dispose(); }190if (hiddenFrame != null) { hiddenFrame.dispose(); }191}192193194class CustomDialog extends TestDialog {195196public CustomDialog(Dialog d) { super(d); }197public CustomDialog(Frame f) { super(f); }198199@Override200public void doOpenAction() {201if (rightFrame != null) {202rightFrame.setVisible(true);203}204}205}206}207208209