Path: blob/master/test/jdk/java/awt/Modal/MultipleDialogs/MultipleDialogs1Test.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*/2223/*24* @test25* @key headful26* @bug 805435827* @summary Check whether a set of dialogs created with a toolkit excluded Frame28* parent has a proper modal blocking behavior. Also show a document modal29* dialog and check if it blocks the document properly.30*31* @library ../helpers /lib/client/32* @library /test/lib33* @build ExtendedRobot34* @build Flag35* @build TestDialog36* @build TestFrame37* @run main/timeout=500 MultipleDialogs1Test38*/394041import java.awt.*;42import java.util.ArrayList;43import java.util.List;44import java.util.Collections;45import java.util.Iterator;4647public class MultipleDialogs1Test {4849private volatile CustomFrame frame;50private List<CustomDialog> dialogList;5152private static int delay = 500;53private int dialogCount = -1;5455public void createGUI() {5657final int n = 8;58dialogList = new ArrayList<>();5960frame = new CustomFrame();61frame.setLocation(50, 50);62frame.setModalExclusionType(Dialog.ModalExclusionType.TOOLKIT_EXCLUDE);63frame.setVisible(true);6465int x = 250, y = 50;6667CustomDialog dlg;6869for (int i = 0; i < n - 1; ++i) {7071dlg = new CustomDialog(frame);72dlg.setLocation(x, y);73x += 200;7475if (x > 600) {76x = 50;77y += 200;78}7980Dialog.ModalityType type;8182if (i % 3 == 0) {83type = Dialog.ModalityType.MODELESS;84} else if (i % 3 == 1) {85type = Dialog.ModalityType.APPLICATION_MODAL;86} else {87type = Dialog.ModalityType.TOOLKIT_MODAL;88}8990dlg.setModalityType(type);91dialogList.add(dlg);92}9394dlg = new CustomDialog(frame);95dlg.setLocation(x, y);96dlg.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);97dialogList.add(dlg);98}99100public void doTest() throws Exception {101102try {103EventQueue.invokeAndWait(this::createGUI);104105ExtendedRobot robot = new ExtendedRobot();106robot.waitForIdle(delay);107108List<CustomDialog> dialogs = Collections.synchronizedList(dialogList);109110final int n = dialogs.size();111112synchronized(dialogs) {113for (int i = 0; i < n - 1; ++i) {114115frame.clickOpenButton(robot);116robot.waitForIdle(delay);117118dialogs.get(i).checkUnblockedDialog(119robot, i + ": This is " + getType(i) + ".");120121frame.checkUnblockedFrame(robot, i + ": Other dialogs are visible.");122123if (i > 0) {124for (int j = 0; j < i; j++) {125dialogs.get(j).checkUnblockedDialog(robot, j + ": A toolkit modality " +126"excluded frame is a parent of this dialog.");127}128}129} // i130131frame.clickOpenButton(robot);132robot.waitForIdle(delay);133134dialogs.get(n - 1).checkUnblockedDialog(135robot, (n - 1) + ": This is " + getType(n - 1) + ".");136137frame.checkBlockedFrame(robot,138"A document modal dialog with Frame parent is visible.");139140for (int i = 0; i < n - 1; ++i) {141dialogs.get(i).checkUnblockedDialog(robot,142i + ": A document modal dialog should not block " +143"this dialog. The parent is modality excluded.");144}145146dialogs.get(n - 1).clickCloseButton(robot);147robot.waitForIdle(delay);148149for (int i = 0; i < n - 1; ++i) {150dialogs.get(i).checkUnblockedDialog(robot, i + ": A document modal " +151"dialog which blocked this dialog was closed.");152}153frame.checkUnblockedFrame(robot,154"A blocking document modal dialog was closed.");155robot.waitForIdle(delay);156} // synchronized157158} finally {159EventQueue.invokeAndWait(this::closeAll);160}161}162163private String getType(int i) {164165switch (dialogList.get(i).getModalityType()) {166case APPLICATION_MODAL:167return "an application modal dialog";168case DOCUMENT_MODAL:169return "a document modal dialog";170case TOOLKIT_MODAL:171return "a toolkit modal dialog";172}173return "a modeless dialog";174}175176private void closeAll() {177178if (frame != null) { frame.dispose(); }179if (dialogList != null) {180Iterator<CustomDialog> it = dialogList.iterator();181while (it.hasNext()) { it.next().dispose(); }182}183}184185class CustomFrame extends TestFrame {186187@Override188public void doOpenAction() {189if ((dialogList != null) && (dialogList.size() > dialogCount)) {190dialogCount++;191CustomDialog d = dialogList.get(dialogCount);192if (d != null) { d.setVisible(true); }193}194}195}196197class CustomDialog extends TestDialog {198199public CustomDialog(Frame f) { super(f); }200public CustomDialog(Dialog d) { super(d); }201202@Override203public void doCloseAction() { this.dispose(); }204}205206207public static void main(String[] args) throws Exception {208(new MultipleDialogs1Test()).doTest();209}210}211212213