Path: blob/master/test/jdk/java/awt/Modal/ModalBlockingTests/BlockingDFWTest.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.KeyEvent;25import static jdk.test.lib.Asserts.*;2627// DFW: Dialog -> Frame -> Window2829public class BlockingDFWTest {3031private static final int delay = 500;32private final ExtendedRobot robot;3334public enum Parent {DIALOG, FRAME};3536private ParentDialog parentDialog;37private ParentFrame parentFrame;38private TestDialog dialog;39private TestFrame frame;40private TestWindow window;414243public BlockingDFWTest(Parent parentWin, Dialog.ModalityType modalityType) throws Exception {4445robot = new ExtendedRobot();46EventQueue.invokeLater(() -> { createGUI(parentWin, modalityType); });47}4849private void createGUI(Parent parentWin, Dialog.ModalityType modalityType) {5051Window p = null;52switch (parentWin) {53case DIALOG:54parentDialog = new ParentDialog((Dialog) null);55dialog = new CustomDialog(parentDialog);56p = parentDialog;57break;58case FRAME:59parentFrame = new ParentFrame();60dialog = new CustomDialog(parentFrame);61p = parentFrame;62break;63}6465assertFalse(p == null, "invalid parent");66p.setLocation(50, 50);67dialog.setLocation(250, 50);68if (modalityType != null) { dialog.setModalityType(modalityType); }6970frame = new TestFrame();71frame.setLocation(50, 250);72window = new TestWindow(frame);73window.setLocation(250, 250);7475p.setVisible(true);76}7778public void doTest() throws Exception {7980try {8182robot.waitForIdle(delay);8384if (parentDialog != null) { parentDialog.clickOpenButton(robot); }85else if (parentFrame != null) { parentFrame.clickOpenButton(robot); }86robot.waitForIdle(delay);8788dialog.activated.waitForFlagTriggered();89assertTrue(dialog.activated.flag(), "Dialog did not trigger " +90"Window Activated event when it became visible");9192dialog.closeGained.waitForFlagTriggered();93assertTrue(dialog.closeGained.flag(), "the 1st button did not gain " +94"focus when the dialog became visible");9596assertTrue(dialog.closeButton.hasFocus(), "the 1st dialog button " +97"gained focus, but lost it afterwards");9899dialog.openGained.reset();100robot.type(KeyEvent.VK_TAB);101102dialog.openGained.waitForFlagTriggered();103assertTrue(dialog.openGained.flag(), "Tab navigation did not happen " +104"properly; open button did not gain focus on tab press " +105"when parent frame is visible");106107dialog.clickOpenButton(robot);108robot.waitForIdle(delay);109110frame.activated.waitForFlagTriggered();111assertTrue(frame.activated.flag(), "Frame did not trigger " +112"Window Activated event when made visible.");113114frame.checkUnblockedFrame(robot, "Frame should not be blocked.");115window.checkUnblockedWindow(robot, "Window should not be blocked.");116robot.waitForIdle(delay);117118} finally {119EventQueue.invokeAndWait(this::closeAll);120}121}122123private void closeAll() {124if (dialog != null) { dialog.dispose(); }125if ( frame != null) { frame.dispose(); }126if (window != null) { window.dispose(); }127if (parentDialog != null) { parentDialog.dispose(); }128if (parentFrame != null) { parentFrame.dispose(); }129}130131132class ParentDialog extends TestDialog {133134public ParentDialog(Dialog d) { super(d); }135136@Override137public void doOpenAction() {138if (dialog != null) { dialog.setVisible(true); }139}140}141142class ParentFrame extends TestFrame {143144@Override145public void doOpenAction() {146if (dialog != null) { dialog.setVisible(true); }147}148}149150class CustomDialog extends TestDialog {151152public CustomDialog(Dialog d) { super(d); }153public CustomDialog(Frame f) { super(f); }154155@Override156public void doOpenAction() {157if (frame != null) { frame.setVisible(true); }158if (window != null) { window.setVisible(true); }159}160}161}162163164