Path: blob/master/test/jdk/java/awt/Modal/ModalBlockingTests/BlockingWindowsDocModalTest.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 java.awt.event.KeyEvent;26import static jdk.test.lib.Asserts.*;2728import java.util.List;29import java.util.ArrayList;3031public class BlockingWindowsDocModalTest {3233private ParentDialog parentDialog;34private ParentFrame parentFrame;35private CustomDialog dialog;36private TestDialog secondDialog, childDialog;37private TestFrame secondFrame;38private TestWindow window, childWindow, secondWindow;394041private static final int delay = 500;42private final ExtendedRobot robot;4344private List<Window> allWindows;4546public enum Parent {DIALOG, FRAME};47private Parent root;4849public BlockingWindowsDocModalTest(Parent p) throws Exception {5051root = p;5253robot = new ExtendedRobot();54EventQueue.invokeLater(this::createGUI);55}5657private void createGUI() {5859allWindows = new ArrayList<>();6061switch (root) {62case DIALOG:63parentDialog = new ParentDialog((Dialog) null);64parentDialog.setLocation(50, 50);65parentDialog.setVisible(true);66allWindows.add(parentDialog);6768dialog = new CustomDialog(parentDialog);69secondDialog = new TestDialog(parentDialog);70window = new TestWindow(parentDialog);71break;72case FRAME:73parentFrame = new ParentFrame();74parentFrame.setLocation(50, 50);75parentFrame.setVisible(true);76allWindows.add(parentFrame);7778dialog = new CustomDialog(parentFrame);79secondDialog = new TestDialog(parentFrame);80window = new TestWindow(parentFrame);81break;82}8384allWindows.add(dialog);85allWindows.add(secondDialog);86allWindows.add(window);8788dialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);89dialog.setLocation(250, 50);90window.setLocation(450, 50);91secondDialog.setLocation(450, 250);9293secondFrame = new TestFrame();94allWindows.add(secondFrame);95secondFrame.setLocation(50, 250);9697secondWindow = new TestWindow(secondFrame);98allWindows.add(secondWindow);99secondWindow.setLocation(250, 250);100101childDialog = new TestDialog(dialog);102allWindows.add(childDialog);103childDialog.setLocation(250, 450);104105childWindow = new TestWindow(dialog);106allWindows.add(childWindow);107childWindow.setLocation(50, 450);108}109110public void doTest() throws Exception {111112try {113robot.waitForIdle(delay);114115if (root == Parent.DIALOG) {116parentDialog.clickOpenButton(robot);117} else { //Parent.FRAME118parentFrame.clickOpenButton(robot);119}120robot.waitForIdle(delay);121122dialog.activated.waitForFlagTriggered();123assertTrue(dialog.activated.flag(), "Dialog did not trigger " +124"Window Acivated event when it became visible");125126dialog.closeGained.waitForFlagTriggered();127assertTrue(dialog.closeGained.flag(),128"the 1st Dialog button didn't gain focus");129130assertTrue(dialog.closeButton.hasFocus(), "the 1st Dialog button " +131"gained focus but lost it afterwards");132133dialog.openGained.reset();134robot.type(KeyEvent.VK_TAB);135136dialog.openGained.waitForFlagTriggered();137assertTrue(dialog.openGained.flag(), "Tab navigation did not happen properly on Dialog; " +138"Open button did not gain focus on tab press when parent frame is visible");139140dialog.clickOpenButton(robot);141robot.waitForIdle(delay);142143secondFrame.checkUnblockedFrame(robot,144"A document modal dialog and its parent are visible.");145secondWindow.checkUnblockedWindow(robot,146"A Frame and a document modal Dialog are visible.");147148if (root == Parent.DIALOG) {149parentDialog.checkBlockedDialog(robot, "Dialog is a parent of a document modal dialog.");150} else { //Parent.FRAME151parentFrame.checkBlockedFrame(robot, "Frame is a parent of a document modal dialog.");152}153154secondDialog.checkBlockedDialog(robot,155"The parent of the Dialog is also the parent of a document modal dialog");156window.checkBlockedWindow(robot,157"The parent of the Window is also the parent of a document modal dialog");158159childWindow.checkUnblockedWindow(robot,160"The parent of the Window is a document modal dialog");161childDialog.checkUnblockedDialog(robot,162"The parent of the Dialog is a document modal dialog");163robot.waitForIdle(delay);164165} finally {166EventQueue.invokeAndWait(this::closeAll);167}168}169170private void closeAll() {171for (Window w: allWindows) {172if (w != null) { w.dispose(); }173}174}175176class ParentDialog extends TestDialog {177178public ParentDialog(Dialog d) { super(d); }179180@Override181public void doOpenAction() {182if (dialog != null) { dialog.setVisible(true); }183}184}185186class ParentFrame extends TestFrame {187188@Override189public void doOpenAction() {190if (dialog != null) { dialog.setVisible(true); }191}192193}194195class CustomDialog extends TestDialog {196197public CustomDialog(Dialog d) { super(d); }198public CustomDialog(Frame f) { super(f); }199200@Override201public void doOpenAction() {202if (secondFrame != null) { secondFrame.setVisible(true); }203if (secondWindow != null) { secondWindow.setVisible(true); }204if (secondDialog != null) { secondDialog.setVisible(true); }205if (window != null) { window.setVisible(true); }206if (childWindow != null) { childWindow.setVisible(true); }207if (childDialog != null) { childDialog.setVisible(true); }208}209}210}211212213