Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Modal/NullModalityDialogTest/NullModalityDialogTest.java
38821 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.*;24import java.awt.event.KeyEvent;2526import static jdk.testlibrary.Asserts.*;272829/*30* @test31* @bug 804736732* @summary Check whether a Dialog set with null modality type33* behaves like a modeless dialog34*35* @library ../helpers ../../../../lib/testlibrary/36* @build ExtendedRobot37* @build Flag38* @build TestDialog39* @build TestFrame40* @build TestWindow41* @run main NullModalityDialogTest42*/434445public class NullModalityDialogTest {4647class CustomDialog extends TestDialog {48public CustomDialog(Frame f) {49super(f);50}51@Override52public void doOpenAction() {53if (frame != null) {54frame.setVisible(true);55}56if (window != null) {57window.setVisible(true);58}59}60}6162class CustomFrame extends TestFrame {63@Override64public void doOpenAction() {65if (dialog != null) {66dialog.setVisible(true);67}68}69}7071private TestFrame parent;72private TestDialog dialog;73private TestFrame frame;74private TestWindow window;7576private static final int delay = 1000;7778private final ExtendedRobot robot;7980NullModalityDialogTest() throws Exception {8182robot = new ExtendedRobot();83EventQueue.invokeLater(this::createGUI);84}8586private void createGUI() {8788parent = new CustomFrame();89parent.setTitle("Parent");90parent.setLocation(50, 50);9192dialog = new CustomDialog(parent);93dialog.setTitle("Dialog");94dialog.setModalityType((Dialog.ModalityType) null);95dialog.setLocation(250, 50);9697frame = new TestFrame();98frame.setTitle("Frame");99frame.setLocation(50, 250);100101window = new TestWindow(frame);102window.setLocation(250, 250);103104parent.setVisible(true);105}106107private void closeAll() {108if (parent != null) { parent.dispose(); }109if (dialog != null) { dialog.dispose(); }110if (frame != null) { frame.dispose(); }111if (window != null) { window.dispose(); }112}113114public void doTest() throws Exception {115116robot.waitForIdle(delay);117118parent.clickOpenButton(robot);119robot.waitForIdle(delay);120121dialog.activated.waitForFlagTriggered();122assertTrue(dialog.activated.flag(), "Dialog did not trigger " +123"Window Activated event when it became visible");124125dialog.closeGained.waitForFlagTriggered();126assertTrue(dialog.closeGained.flag(), "the 1st button did not gain focus " +127"when the Dialog became visible");128129assertTrue(dialog.closeButton.hasFocus(), "the 1st button in the Dialog " +130"gained focus but lost it afterwards");131132dialog.openGained.reset();133134robot.type(KeyEvent.VK_TAB);135136dialog.openGained.waitForFlagTriggered();137assertTrue(dialog.openGained.flag(),138"Tab navigation did not happen properly on Dialog. Open button " +139"did not gain focus on tab press when parent frame is visible");140141dialog.clickOpenButton(robot);142robot.waitForIdle(delay);143144frame.activated.waitForFlagTriggered();145assertTrue(frame.activated.flag(), "Frame did not trigger activated when " +146"made visible. Dialog and its parent frame are visible");147148frame.checkUnblockedFrame(robot, "Frame is the parent of a visible Dialog.");149window.checkUnblockedWindow(robot, "Frame and its child Dialog are visible.");150151robot.waitForIdle(delay);152153EventQueue.invokeAndWait(this::closeAll);154}155156public static void main(String[] args) throws Exception {157NullModalityDialogTest test = new NullModalityDialogTest();158test.doTest();159}160}161162163