Path: blob/master/test/jdk/java/awt/Modal/ModalBlockingTests/BlockingFDWTest.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.*;262728// FDW: Frame -> Dialog -> Window2930public class BlockingFDWTest {3132private TestFrame frame;33private TestDialog dialog;34private TestWindow window;3536private Dialog hiddenDialog;37private Frame hiddenFrame;3839private static final int delay = 500;40private final ExtendedRobot robot;4142public enum DialogOwner {HIDDEN_DIALOG, NULL_DIALOG, HIDDEN_FRAME, NULL_FRAME};4344public BlockingFDWTest(Dialog.ModalityType modalityType,45DialogOwner owner) throws Exception {4647robot = new ExtendedRobot();48EventQueue.invokeLater(() -> { createGUI(modalityType, owner); });49}5051private void createGUI(Dialog.ModalityType modalityType,52DialogOwner owner) {5354frame = new CustomFrame();55frame.setLocation(50, 50);5657switch (owner) {58case HIDDEN_DIALOG:59hiddenDialog = new Dialog((Frame) null);60dialog = new CustomDialog(hiddenDialog);61break;62case NULL_DIALOG:63dialog = new CustomDialog((Dialog) null);64break;65case HIDDEN_FRAME:66hiddenFrame = new Frame();67dialog = new CustomDialog(hiddenFrame);68break;69case NULL_FRAME:70dialog = new CustomDialog((Frame) null);71break;72}7374assertFalse(dialog == null, "error: null dialog");7576dialog.setLocation(250, 50);77if (modalityType != null) {78dialog.setModalityType(modalityType);79}8081window = new TestWindow(frame);82window.setLocation(450, 50);8384frame.setVisible(true);85}8687public void doTest() throws Exception {8889try {9091robot.waitForIdle(delay);9293frame.clickOpenButton(robot);94robot.waitForIdle(delay);9596dialog.activated.waitForFlagTriggered();97assertTrue(dialog.activated.flag(), "Dialog did not trigger " +98"Window Activated event when it became visible");99100dialog.closeGained.waitForFlagTriggered();101assertTrue(dialog.closeGained.flag(), "the 1st Dialog button " +102"did not gain focus when it became visible");103104assertTrue(dialog.closeButton.hasFocus(), "the 1st Dialog button " +105"gained the focus but lost it afterwards");106107frame.checkUnblockedFrame(robot, "A " + dialog.getModalityType() + " dialog is visible.");108109dialog.checkUnblockedDialog(robot, "A Frame is visible.");110111dialog.openClicked.reset();112dialog.clickOpenButton(robot);113robot.waitForIdle(delay);114115window.checkUnblockedWindow(robot,116"A Frame and a " + dialog.getModalityType() + " Dialog are visible.");117robot.waitForIdle(delay);118119} finally {120EventQueue.invokeAndWait(this::closeAll);121}122}123124private void closeAll() {125if (frame != null) { frame.dispose(); }126if (dialog != null) { dialog.dispose(); }127if (window != null) { window.dispose(); }128if (hiddenDialog != null) { hiddenDialog.dispose(); }129if (hiddenFrame != null) { hiddenFrame.dispose(); }130}131132133class CustomFrame extends TestFrame {134135@Override136public void doOpenAction() {137if (dialog != null) { dialog.setVisible(true); }138}139}140141class CustomDialog extends TestDialog {142143public CustomDialog(Dialog dialog) {144super(dialog);145}146147public CustomDialog(Frame frame) {148super(frame);149}150151@Override152public void doOpenAction() {153if (window != null) { window.setVisible(true); }154}155156@Override157public void doCloseAction() {158this.dispose();159}160}161}162163164