Path: blob/master/test/jdk/java/awt/Modal/OnTop/OnTopFDFTest.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.*;2627// FDF: Frame - Dialog - Frame2829public class OnTopFDFTest {3031private volatile CustomDialog dialog;32private volatile TestFrame leftFrame, rightFrame;33private volatile Dialog hiddenDialog;34private volatile Frame hiddenFrame;3536private static final int delay = 500;37private final ExtendedRobot robot;3839public enum DialogOwner {HIDDEN_DIALOG, NULL_DIALOG, HIDDEN_FRAME, NULL_FRAME, FRAME};4041private DialogOwner owner;42boolean setModal;4344Dialog.ModalityType modalityType;4546private OnTopFDFTest(Dialog.ModalityType modType,47boolean modal,48DialogOwner o) throws Exception {4950modalityType = modType;51setModal = modal;52owner = o;53robot = new ExtendedRobot();54EventQueue.invokeLater(this::createGUI);55}5657public OnTopFDFTest(Dialog.ModalityType modalityType,58DialogOwner o) throws Exception {59this(modalityType, false, o);60}6162public OnTopFDFTest(DialogOwner o) throws Exception {63this(null, true, o);64}6566private void createGUI() {6768leftFrame = new TestFrame();69leftFrame.setSize(200, 100);70leftFrame.setLocation(50, 50);71leftFrame.setVisible(true);7273switch (owner) {74case HIDDEN_DIALOG:75hiddenDialog = new Dialog((Frame) null);76dialog = new CustomDialog(hiddenDialog);77break;78case NULL_DIALOG:79dialog = new CustomDialog((Dialog) null);80break;81case HIDDEN_FRAME:82hiddenFrame = new Frame();83dialog = new CustomDialog(hiddenFrame);84break;85case NULL_FRAME:86dialog = new CustomDialog((Frame) null);87break;88case FRAME:89dialog = new CustomDialog(leftFrame);90break;91}9293if (setModal) {94dialog.setModal(true);95modalityType = dialog.getModalityType();96} else if (modalityType != null) {97dialog.setModalityType(modalityType);98}99100dialog.setSize(200, 100);101dialog.setLocation(200, 50);102103rightFrame = new TestFrame();104rightFrame.setSize(200, 100);105rightFrame.setLocation(350, 50);106107dialog.setVisible(true);108}109110private void BlockingTest() throws Exception {111112dialog.checkUnblockedDialog(robot, "Checking if " + modalityType +113" dialog appears on top of blocked Frame.");114robot.waitForIdle(delay);115116rightFrame.closeClicked.waitForFlagTriggered(5);117assertFalse(rightFrame.closeClicked.flag(),118"Frame is on top of " + modalityType + " Dialog.");119robot.waitForIdle(delay);120121leftFrame.transferFocusToBlockedFrame(robot,122modalityType + " dialog blocks the Frame.", leftFrame.closeButton);123robot.waitForIdle(delay);124125dialog.clickCloseButton(robot);126robot.waitForIdle(delay);127}128129private void Test() throws Exception {130131rightFrame.clickCloseButton(robot);132robot.waitForIdle(delay);133134rightFrame.closeClicked.reset();135dialog.transferFocusToDialog(136robot, "Frame partially hides the dialog.", dialog.openButton);137robot.waitForIdle(delay);138139dialog.checkUnblockedDialog(140robot, "This is " + modalityType + " dialog.");141robot.waitForIdle(delay);142143rightFrame.closeClicked.waitForFlagTriggered(5);144assertFalse(rightFrame.closeClicked.flag(), "Clicking on a " +145modalityType + " dialog did not bring it to the top. " +146"A frame is on top of the dialog.");147robot.waitForIdle(delay);148149dialog.closeClicked.reset();150151if (owner == DialogOwner.FRAME) {152153if (modalityType == Dialog.ModalityType.MODELESS) {154leftFrame.transferFocusToFrame(robot, "modeless dialog " +155"partially hides the Frame.", leftFrame.closeButton);156} else {157leftFrame.transferFocusToBlockedFrame(robot, "a document modal " +158"dialog partially hides the Frame.", leftFrame.closeButton);159}160161} else {162163leftFrame.transferFocusToFrame(robot,164"A dialog partially hides the Frame.", leftFrame.closeButton);165robot.waitForIdle(delay);166167leftFrame.checkUnblockedFrame(robot,168modalityType + " dialog present should not block this Frame.");169robot.waitForIdle(delay);170171dialog.closeClicked.waitForFlagTriggered(5);172assertFalse(dialog.closeClicked.flag(), "Clicking on a frame did not " +173"bring it to the top. The document modal dialog is staying on top.");174}175176robot.waitForIdle(delay);177}178179180public void doTest() throws Exception {181182try {183184robot.waitForIdle(delay);185186dialog.activated.waitForFlagTriggered();187assertTrue(dialog.activated.flag(), "Dialog still not visible.");188189dialog.clickOpenButton(robot);190robot.waitForIdle(delay);191192switch (modalityType) {193case DOCUMENT_MODAL:194case MODELESS:195Test();196break;197case APPLICATION_MODAL:198case TOOLKIT_MODAL:199BlockingTest();200break;201}202203} finally {204EventQueue.invokeAndWait(this::closeAll);205}206}207208private void closeAll() {209if (dialog != null) { dialog.dispose(); }210if (leftFrame != null) { leftFrame.dispose(); }211if (rightFrame != null) { rightFrame.dispose(); }212if (hiddenDialog != null) { hiddenDialog.dispose(); }213if (hiddenFrame != null) { hiddenFrame.dispose(); }214}215216217class CustomDialog extends TestDialog {218219public CustomDialog(Dialog d) { super(d); }220public CustomDialog(Frame f) { super(f); }221222@Override223public void doOpenAction() {224if (rightFrame != null) {225rightFrame.setVisible(true);226}227}228}229}230231232