Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Modal/MultipleDialogs/MultipleDialogs2Test.java
38828 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*/2223/*24* @test25* @bug 805435826* @summary Check whether a set of dialogs created with an application excluded Frame27* parent has a proper modal blocking behavior. Also show a document modal28* dialog and check if it blocks the document properly.29*30* @library ../helpers ../../../../lib/testlibrary/31* @build ExtendedRobot32* @build Flag33* @build TestDialog34* @build TestFrame35* @run main/timeout=500 MultipleDialogs2Test36*/373839import java.awt.*;40import java.util.ArrayList;41import java.util.List;42import java.util.Collections;43import java.util.Iterator;4445public class MultipleDialogs2Test {4647private volatile CustomFrame frame;48private List<CustomDialog> dialogList;49private static final int delay = 500;5051private int dialogCount = -1;5253private void createGUI() {5455final int n = 8;56dialogList = new ArrayList<>();5758frame = new CustomFrame();59frame.setLocation(50, 50);60frame.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);61frame.setVisible(true);6263CustomDialog dlg;6465int x = 250, y = 50;66for (int i = 0; i < n - 1; ++i) {6768dlg = new CustomDialog(frame);69dlg.setLocation(x, y);70x += 200;71if (x > 600) {72x = 50;73y += 200;74}7576Dialog.ModalityType type;77if (i % 3 == 0) {78type = Dialog.ModalityType.MODELESS;79} else if (i % 3 == 1) {80type = Dialog.ModalityType.APPLICATION_MODAL;81} else {82type = Dialog.ModalityType.TOOLKIT_MODAL;83}84dlg.setModalityType(type);85dialogList.add(dlg);86}8788dlg = new CustomDialog(frame);89dlg.setLocation(x, y);90dlg.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);91dialogList.add(dlg);92}9394public void doTest() throws Exception {9596try {97EventQueue.invokeAndWait(this::createGUI);9899ExtendedRobot robot = new ExtendedRobot();100robot.waitForIdle(delay);101102List<CustomDialog> dialogs = Collections.synchronizedList(dialogList);103final int n = dialogs.size();104105synchronized(dialogs) {106for (int i = 0; i < n - 1; ++i) {107108frame.clickOpenButton(robot);109robot.waitForIdle(delay);110111dialogs.get(i).checkUnblockedDialog(112robot, i + ": This is " + getType(i) + ".");113114if (isToolkitModal(i)) {115116for (int j = 0; j < i; ++j) {117dialogs.get(j).checkBlockedDialog(robot, j + ": This dialog " +118"should be blocked by a toolkit modal dialog.");119}120121frame.checkBlockedFrame(robot, i + ": A toolkit modal dialog " +122"should block this application modality excluded frame.");123124break;125126} else {127for (int j = 0; j < i; ++j) {128dialogs.get(j).checkUnblockedDialog(robot,129j + ": An application modality excluded frame " +130"is the parent of this dialog.");131}132133frame.checkUnblockedFrame(robot, i + ": The frame is " +134"application modality excluded, but it is blocked.");135}136}137138int tkIndex = dialogCount; // continue testing139final int tk0 = tkIndex;140141for (int i = tk0 + 1; i < n - 1; ++i) {142143dialogs.get(tkIndex).clickOpenButton(robot);144robot.waitForIdle(delay);145146frame.checkBlockedFrame(robot, i + ": A toolkit modal dialog " +147"should block this application modality excluded frame.");148149if (isToolkitModal(i)) {150dialogs.get(i).checkUnblockedDialog(robot, i + ": This is " +151"a toolkit modal dialog with blocked frame parent. " +152"Another toolkit modal dialog is visible.");153154for (int j = 0; j < i; ++j) {155dialogs.get(j).checkBlockedDialog(robot, j + ": " +156"A toolkit modal dialog should block this child " +157"dialog of application modality excluded frame.");158}159tkIndex = i;160} else {161dialogs.get(i).checkBlockedDialog(162robot, i + ": This is " + getType(i) + " with blocked " +163"Frame parent. Also, a toolkit modal dialog is visible.");164165for (int j = 0; j < i; ++j) {166if (j != tkIndex) {167dialogs.get(j).checkBlockedDialog(robot, j +168": A toolkit modal dialog should block this " +169"child dialog of an application modality excluded frame.");170}171}172}173}174175// show a document modal dialog; the toolkit modal dialog should block it176dialogs.get(tkIndex).clickOpenButton(robot);177robot.waitForIdle(delay);178179frame.checkBlockedFrame(robot, "A toolkit modal dialog is visible.");180181for (int i = 0; i < n; ++i) {182if (i == tkIndex) {183dialogs.get(tkIndex).checkUnblockedDialog(robot,184tkIndex + ": This is a toolkit modal dialog. " +185"A document modal dialog is visible.");186} else {187dialogs.get(i).checkBlockedDialog(robot,188i + ": A toolkit modal dialog should block this dialog.");189}190}191192dialogs.get(tk0 + 3).clickCloseButton(robot); // close 2nd toolkit dialog193robot.waitForIdle(delay);194195for (int i = 0; i < n; ++i) {196197if (i == tk0 + 3) { continue; }198if (i == tk0) {199dialogs.get(i).checkUnblockedDialog(robot,200i + ": This is a toolkit modal dialog. A blocking " +201"toolkit modal dialog was opened and then closed.");202} else {203dialogs.get(i).checkBlockedDialog(robot,204i + ": This dialog should be blocked by a toolkit modal dialog. " +205"Another blocking toolkit modal dialog was closed.");206}207}208209dialogs.get(tk0).clickCloseButton(robot);210robot.waitForIdle(delay);211212frame.checkBlockedFrame(213robot, "A document modal dialog should block this Frame.");214215for (int i = 0; i < n - 1; ++i) {216if (!isToolkitModal(i)) {217dialogs.get(i).checkUnblockedDialog(robot, i + ": The parent " +218"of the dialog is an app modality excluded Frame.");219}220}221222dialogs.get(n - 1).clickCloseButton(robot);223robot.waitForIdle(delay);224225frame.checkUnblockedFrame(robot, "A document modal dialog " +226"blocking this Frame was closed.");227228for (int i = 0; i < n - 1; ++i) {229if (!isToolkitModal(i)) {230dialogs.get(i).checkUnblockedDialog(robot, i + ": A document modal " +231"dialog blocking the parent frame was closed.");232}233}234} // synchronized235236} finally {237EventQueue.invokeAndWait(this::closeAll);238}239}240241private boolean isToolkitModal(int i) { return (i % 3 == 2); }242243private String getType(int i) {244245switch (dialogList.get(i).getModalityType()) {246case APPLICATION_MODAL:247return "an application modal dialog";248case DOCUMENT_MODAL:249return "a document modal dialog";250case TOOLKIT_MODAL:251return "a toolkit modal dialog";252}253return "a modeless dialog";254}255256public void closeAll() {257258if (frame != null) { frame.dispose(); }259if (dialogList != null) {260Iterator<CustomDialog> it = dialogList.iterator();261while (it.hasNext()) { it.next().dispose(); }262}263}264265class CustomFrame extends TestFrame {266267@Override268public void doOpenAction() {269if ((dialogList != null) && (dialogList.size() > dialogCount)) {270dialogCount++;271CustomDialog d = dialogList.get(dialogCount);272if (d != null) { d.setVisible(true); }273}274}275}276277class CustomDialog extends TestDialog {278279public CustomDialog(Frame frame) { super(frame); }280281@Override282public void doCloseAction() { this.dispose(); }283284@Override285public void doOpenAction() {286if ((dialogList != null) && (dialogList.size() > dialogCount)) {287dialogCount++;288if (dialogList.get(dialogCount) != null) {289dialogList.get(dialogCount).setVisible(true);290}291}292}293}294295public static void main(String[] args) throws Exception {296(new MultipleDialogs2Test()).doTest();297}298}299300301