Path: blob/master/test/jdk/java/awt/Modal/ModalExclusionTests/ExcludeFrameTest.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*/2223import java.awt.*;24import java.awt.event.*;25import java.awt.print.*;2627import static jdk.test.lib.Asserts.*;282930public class ExcludeFrameTest implements AWTEventListener {31class CustomFrame extends TestFrame {3233@Override34public void doOpenAction() {35if (window != null) {36window.setVisible(true);37}38}39}4041class CustomDialog extends TestDialog {4243public CustomDialog(Frame frame) {44super(frame);45}4647@Override48public void doOpenAction() {49switch (childDialogType) {50case PRINT_SETUP:51PrinterJob.getPrinterJob().printDialog();52break;53case PAGE_SETUP:54PrinterJob.getPrinterJob().pageDialog(new PageFormat());55break;56case FILE_DIALOG:57fileDialog = new FileDialog((Frame) null);58fileDialog.setLocation(20, 200);59fileDialog.setVisible(true);60break;61}62}63}6465class CustomWindow extends TestWindow {6667public CustomWindow(Frame frame) {68super(frame);69}7071@Override72public void doOpenAction() {73if (dialog != null) {74dialog.setVisible(true);75}76}77}7879private TestDialog dialog;80private TestFrame frame;81private TestWindow window;82private FileDialog fileDialog;8384private boolean windowAppeared = false;85private final Object windowLock;8687private static final int delay = 1000;88private final ExtendedRobot robot;8990private final Dialog.ModalExclusionType exclusionType;9192public enum DialogToShow {PAGE_SETUP, PRINT_SETUP, FILE_DIALOG};93private final DialogToShow childDialogType;94private String type;9596public ExcludeFrameTest(Dialog.ModalExclusionType exclType,97DialogToShow dialogType) throws Exception {98exclusionType = exclType;99childDialogType = dialogType;100101type = "File";102if (dialogType == DialogToShow.PAGE_SETUP) {103type = "Page setup";104} else if (dialogType == DialogToShow.PRINT_SETUP) {105type = "Print setup";106}107108windowLock = new Object();109robot = new ExtendedRobot();110EventQueue.invokeAndWait( this::createGUI );111}112113@Override114public void eventDispatched(AWTEvent event) {115if (event.getID() == WindowEvent.WINDOW_OPENED) {116windowAppeared = true;117synchronized (windowLock) {118windowLock.notifyAll();119}120}121}122123private void createGUI() {124frame = new CustomFrame();125frame.setLocation(20, 20);126frame.setModalExclusionType(exclusionType);127dialog = new CustomDialog(frame);128dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);129dialog.setLocation(220, 20);130window = new CustomWindow(frame);131window.setLocation(420, 20);132Toolkit.getDefaultToolkit().addAWTEventListener(133ExcludeFrameTest.this, AWTEvent.WINDOW_EVENT_MASK);134frame.setVisible(true);135}136137private void closeAll() {138if (dialog != null) { dialog.dispose(); }139if (frame != null) { frame.dispose(); }140if (window != null) { window.dispose(); }141if (fileDialog != null) {142fileDialog.dispose();143} else {144robot.type(KeyEvent.VK_ESCAPE);145}146}147148public void doTest() throws Exception {149150robot.waitForIdle(delay);151152frame.clickOpenButton(robot);153robot.waitForIdle(delay);154155window.clickOpenButton(robot);156robot.waitForIdle(delay);157158dialog.clickOpenButton(robot);159robot.waitForIdle(delay);160161if (! windowAppeared) {162synchronized (windowLock) {163try {164windowLock.wait(10 * delay);165} catch (InterruptedException e) {}166}167}168169assertTrue(windowAppeared, type + " dialog didn't appear");170171frame.toFront();172robot.waitForIdle(delay);173174String excl = "";175if (exclusionType == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {176excl = "Application";177} else if (exclusionType == Dialog.ModalExclusionType.TOOLKIT_EXCLUDE) {178excl = "Toolkit";179}180181frame.checkUnblockedFrame(robot, excl + " modal " + type +182" dialog should not block this modal excluded Frame");183dialog.checkUnblockedDialog(robot, excl + " modal " + type +184" dialog should not block this modal excluded app. modal Dialog");185window.checkUnblockedWindow(robot, excl + " modal " + type +186" dialog should not block this modal excluded Window");187188robot.waitForIdle();189closeAll();190}191}192193194