Path: blob/master/test/jdk/java/awt/Modal/NullModalityDialogTest/NullModalityDialogTest.java
41153 views
/*1* Copyright (c) 2007, 2021, 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.test.lib.Asserts.*;272829/*30* @test31* @key headful32* @bug 804736733* @summary Check whether a Dialog set with null modality type34* behaves like a modeless dialog35*36* @library ../helpers /lib/client/37* @library /test/lib38* @build ExtendedRobot39* @build Flag40* @build TestDialog41* @build TestFrame42* @build TestWindow43* @run main NullModalityDialogTest44*/454647public class NullModalityDialogTest {4849class CustomDialog extends TestDialog {50public CustomDialog(Frame f) {51super(f);52}53@Override54public void doOpenAction() {55if (frame != null) {56frame.setVisible(true);57}58if (window != null) {59window.setVisible(true);60}61}62}6364class CustomFrame extends TestFrame {65@Override66public void doOpenAction() {67if (dialog != null) {68dialog.setVisible(true);69}70}71}7273private TestFrame parent;74private TestDialog dialog;75private TestFrame frame;76private TestWindow window;7778private static final int delay = 1000;7980private final ExtendedRobot robot;8182NullModalityDialogTest() throws Exception {8384robot = new ExtendedRobot();85robot.setAutoDelay(100);86EventQueue.invokeAndWait(this::createGUI);87}8889private void createGUI() {9091parent = new CustomFrame();92parent.setTitle("Parent");93parent.setLocation(50, 50);9495dialog = new CustomDialog(parent);96dialog.setTitle("Dialog");97dialog.setModalityType((Dialog.ModalityType) null);98dialog.setLocation(250, 50);99100frame = new TestFrame();101frame.setTitle("Frame");102frame.setLocation(50, 250);103104window = new TestWindow(frame);105window.setLocation(250, 250);106107parent.setVisible(true);108}109110private void closeAll() {111if (parent != null) { parent.dispose(); }112if (dialog != null) { dialog.dispose(); }113if (frame != null) { frame.dispose(); }114if (window != null) { window.dispose(); }115}116117public void doTest() throws Exception {118119robot.waitForIdle(delay);120121parent.clickOpenButton(robot);122robot.waitForIdle(delay);123124dialog.activated.waitForFlagTriggered();125assertTrue(dialog.activated.flag(), "Dialog did not trigger " +126"Window Activated event when it became visible");127128dialog.closeGained.waitForFlagTriggered();129assertTrue(dialog.closeGained.flag(), "the 1st button did not gain focus " +130"when the Dialog became visible");131132assertTrue(dialog.closeButton.hasFocus(), "the 1st button in the Dialog " +133"gained focus but lost it afterwards");134135dialog.openGained.reset();136137robot.keyPress(KeyEvent.VK_TAB);138robot.keyRelease(KeyEvent.VK_TAB);139robot.waitForIdle();140141dialog.openGained.waitForFlagTriggered();142assertTrue(dialog.openGained.flag(),143"Tab navigation did not happen properly on Dialog. Open button " +144"did not gain focus on tab press when parent frame is visible");145146dialog.clickOpenButton(robot);147robot.waitForIdle(delay);148149frame.activated.waitForFlagTriggered();150assertTrue(frame.activated.flag(), "Frame did not trigger activated when " +151"made visible. Dialog and its parent frame are visible");152153frame.checkUnblockedFrame(robot, "Frame is the parent of a visible Dialog.");154window.checkUnblockedWindow(robot, "Frame and its child Dialog are visible.");155156robot.waitForIdle(delay);157158EventQueue.invokeAndWait(this::closeAll);159}160161public static void main(String[] args) throws Exception {162NullModalityDialogTest test = new NullModalityDialogTest();163test.doTest();164}165}166167168