8054358: move awt automated tests from AWT_Modality to OpenJDK repository - part 7
authoravstepan
Tue, 30 Dec 2014 17:26:06 +0400
changeset 28536 e68477f552c4
parent 28535 74115b2c211f
child 28537 0a030920b0f5
8054358: move awt automated tests from AWT_Modality to OpenJDK repository - part 7 Reviewed-by: pchelko
jdk/test/java/awt/Modal/MultipleDialogs/MultipleDialogs1Test.java
jdk/test/java/awt/Modal/MultipleDialogs/MultipleDialogs2Test.java
jdk/test/java/awt/Modal/MultipleDialogs/MultipleDialogs3Test.java
jdk/test/java/awt/Modal/MultipleDialogs/MultipleDialogs4Test.java
jdk/test/java/awt/Modal/MultipleDialogs/MultipleDialogs5Test.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Modal/MultipleDialogs/MultipleDialogs1Test.java	Tue Dec 30 17:26:06 2014 +0400
@@ -0,0 +1,209 @@
+/*
+ * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8054358
+ * @summary Check whether a set of dialogs created with a toolkit excluded Frame
+ *          parent has a proper modal blocking behavior. Also show a document modal
+ *          dialog and check if it blocks the document properly.
+ *
+ * @library ../helpers ../../../../lib/testlibrary/
+ * @build ExtendedRobot
+ * @build Flag
+ * @build TestDialog
+ * @build TestFrame
+ * @run main/timeout=500 MultipleDialogs1Test
+ */
+
+
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Collections;
+import java.util.Iterator;
+
+public class MultipleDialogs1Test {
+
+    private volatile CustomFrame frame;
+    private List<CustomDialog> dialogList;
+
+    private static int delay = 500;
+    private int dialogCount = -1;
+
+    public void createGUI() {
+
+        final int n = 8;
+        dialogList = new ArrayList<>();
+
+        frame = new CustomFrame();
+        frame.setLocation(50, 50);
+        frame.setModalExclusionType(Dialog.ModalExclusionType.TOOLKIT_EXCLUDE);
+        frame.setVisible(true);
+
+        int x = 250, y = 50;
+
+        CustomDialog dlg;
+
+        for (int i = 0; i < n - 1; ++i) {
+
+            dlg = new CustomDialog(frame);
+            dlg.setLocation(x, y);
+            x += 200;
+
+            if (x > 600) {
+                x = 50;
+                y += 200;
+            }
+
+            Dialog.ModalityType type;
+
+            if (i % 3 == 0) {
+                type = Dialog.ModalityType.MODELESS;
+            } else if (i % 3 == 1) {
+                type = Dialog.ModalityType.APPLICATION_MODAL;
+            } else {
+                type = Dialog.ModalityType.TOOLKIT_MODAL;
+            }
+
+            dlg.setModalityType(type);
+            dialogList.add(dlg);
+        }
+
+        dlg = new CustomDialog(frame);
+        dlg.setLocation(x, y);
+        dlg.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
+        dialogList.add(dlg);
+    }
+
+    public void doTest() throws Exception {
+
+        try {
+            EventQueue.invokeAndWait(this::createGUI);
+
+            ExtendedRobot robot = new ExtendedRobot();
+            robot.waitForIdle(delay);
+
+            List<CustomDialog> dialogs = Collections.synchronizedList(dialogList);
+
+            final int n = dialogs.size();
+
+            synchronized(dialogs) {
+                for (int i = 0; i < n - 1; ++i) {
+
+                    frame.clickOpenButton(robot);
+                    robot.waitForIdle(delay);
+
+                    dialogs.get(i).checkUnblockedDialog(
+                        robot, i + ": This is " + getType(i) + ".");
+
+                    frame.checkUnblockedFrame(robot, i + ": Other dialogs are visible.");
+
+                    if (i > 0) {
+                        for (int j = 0; j < i; j++) {
+                            dialogs.get(j).checkUnblockedDialog(robot, j + ": A toolkit modality " +
+                                "excluded frame is a parent of this dialog.");
+                        }
+                    }
+                } // i
+
+                frame.clickOpenButton(robot);
+                robot.waitForIdle(delay);
+
+                dialogs.get(n - 1).checkUnblockedDialog(
+                    robot, (n - 1) + ": This is " + getType(n - 1) + ".");
+
+                frame.checkBlockedFrame(robot,
+                    "A document modal dialog with Frame parent is visible.");
+
+                for (int i = 0; i < n - 1; ++i) {
+                    dialogs.get(i).checkUnblockedDialog(robot,
+                        i + ": A document modal dialog should not block " +
+                        "this dialog. The parent is modality excluded.");
+                }
+
+                dialogs.get(n - 1).clickCloseButton(robot);
+                robot.waitForIdle(delay);
+
+                for (int i = 0; i < n - 1; ++i) {
+                    dialogs.get(i).checkUnblockedDialog(robot, i + ": A document modal " +
+                        "dialog which blocked this dialog was closed.");
+                }
+                frame.checkUnblockedFrame(robot,
+                    "A blocking document modal dialog was closed.");
+                robot.waitForIdle(delay);
+            } // synchronized
+
+        } finally {
+            EventQueue.invokeAndWait(this::closeAll);
+        }
+    }
+
+    private String getType(int i) {
+
+        switch (dialogList.get(i).getModalityType()) {
+            case APPLICATION_MODAL:
+                return "an application modal dialog";
+            case DOCUMENT_MODAL:
+                return "a document modal dialog";
+            case TOOLKIT_MODAL:
+                return "a toolkit modal dialog";
+        }
+        return "a modeless dialog";
+    }
+
+    private void closeAll() {
+
+        if (frame != null) { frame.dispose(); }
+        if (dialogList != null) {
+            Iterator<CustomDialog> it = dialogList.iterator();
+            while (it.hasNext()) { it.next().dispose(); }
+        }
+    }
+
+    class CustomFrame extends TestFrame {
+
+        @Override
+        public void doOpenAction() {
+            if ((dialogList != null) && (dialogList.size() > dialogCount)) {
+                dialogCount++;
+                CustomDialog d = dialogList.get(dialogCount);
+                if (d != null) { d.setVisible(true); }
+            }
+        }
+    }
+
+    class CustomDialog extends TestDialog {
+
+        public CustomDialog(Frame  f) { super(f); }
+        public CustomDialog(Dialog d) { super(d); }
+
+        @Override
+        public void doCloseAction() { this.dispose(); }
+    }
+
+
+    public static void main(String[] args) throws Exception {
+        (new MultipleDialogs1Test()).doTest();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Modal/MultipleDialogs/MultipleDialogs2Test.java	Tue Dec 30 17:26:06 2014 +0400
@@ -0,0 +1,299 @@
+/*
+ * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8054358
+ * @summary Check whether a set of dialogs created with an application excluded Frame
+ *          parent has a proper modal blocking behavior. Also show a document modal
+ *          dialog and check if it blocks the document properly.
+ *
+ * @library ../helpers ../../../../lib/testlibrary/
+ * @build ExtendedRobot
+ * @build Flag
+ * @build TestDialog
+ * @build TestFrame
+ * @run main/timeout=500 MultipleDialogs2Test
+ */
+
+
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Collections;
+import java.util.Iterator;
+
+public class MultipleDialogs2Test {
+
+    private volatile CustomFrame frame;
+    private List<CustomDialog> dialogList;
+    private static final int delay = 500;
+
+    private int dialogCount = -1;
+
+    private void createGUI() {
+
+        final int n = 8;
+        dialogList = new ArrayList<>();
+
+        frame = new CustomFrame();
+        frame.setLocation(50, 50);
+        frame.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
+        frame.setVisible(true);
+
+        CustomDialog dlg;
+
+        int x = 250, y = 50;
+        for (int i = 0; i < n - 1; ++i) {
+
+            dlg = new CustomDialog(frame);
+            dlg.setLocation(x, y);
+            x += 200;
+            if (x > 600) {
+                x = 50;
+                y += 200;
+            }
+
+            Dialog.ModalityType type;
+            if (i % 3 == 0) {
+                type = Dialog.ModalityType.MODELESS;
+            } else if (i % 3 == 1) {
+                type = Dialog.ModalityType.APPLICATION_MODAL;
+            } else {
+                type = Dialog.ModalityType.TOOLKIT_MODAL;
+            }
+            dlg.setModalityType(type);
+            dialogList.add(dlg);
+        }
+
+        dlg = new CustomDialog(frame);
+        dlg.setLocation(x, y);
+        dlg.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
+        dialogList.add(dlg);
+    }
+
+    public void doTest() throws Exception {
+
+        try {
+            EventQueue.invokeAndWait(this::createGUI);
+
+            ExtendedRobot robot = new ExtendedRobot();
+            robot.waitForIdle(delay);
+
+            List<CustomDialog> dialogs = Collections.synchronizedList(dialogList);
+            final int n = dialogs.size();
+
+            synchronized(dialogs) {
+                for (int i = 0; i < n - 1; ++i) {
+
+                    frame.clickOpenButton(robot);
+                    robot.waitForIdle(delay);
+
+                    dialogs.get(i).checkUnblockedDialog(
+                        robot, i + ": This is " + getType(i) + ".");
+
+                    if (isToolkitModal(i)) {
+
+                        for (int j = 0; j < i; ++j) {
+                            dialogs.get(j).checkBlockedDialog(robot, j + ": This dialog " +
+                                "should be blocked by a toolkit modal dialog.");
+                        }
+
+                        frame.checkBlockedFrame(robot, i + ": A toolkit modal dialog " +
+                            "should block this application modality excluded frame.");
+
+                        break;
+
+                    } else {
+                        for (int j = 0; j < i; ++j) {
+                            dialogs.get(j).checkUnblockedDialog(robot,
+                                j + ": An application modality excluded frame " +
+                                "is the parent of this dialog.");
+                        }
+
+                        frame.checkUnblockedFrame(robot, i + ": The frame is " +
+                            "application modality excluded, but it is blocked.");
+                    }
+                }
+
+                int tkIndex = dialogCount; // continue testing
+                final int tk0 = tkIndex;
+
+                for (int i = tk0 + 1; i < n - 1; ++i) {
+
+                    dialogs.get(tkIndex).clickOpenButton(robot);
+                    robot.waitForIdle(delay);
+
+                    frame.checkBlockedFrame(robot, i + ": A toolkit modal dialog " +
+                        "should block this application modality excluded frame.");
+
+                    if (isToolkitModal(i)) {
+                        dialogs.get(i).checkUnblockedDialog(robot, i + ": This is " +
+                            "a toolkit modal dialog with blocked frame parent. " +
+                            "Another toolkit modal dialog is visible.");
+
+                        for (int j = 0; j < i; ++j) {
+                            dialogs.get(j).checkBlockedDialog(robot, j + ": " +
+                                "A toolkit modal dialog should block this child " +
+                                "dialog of application modality excluded frame.");
+                        }
+                        tkIndex = i;
+                    } else {
+                        dialogs.get(i).checkBlockedDialog(
+                            robot, i + ": This is " + getType(i) + " with blocked " +
+                            "Frame parent. Also, a toolkit modal dialog is visible.");
+
+                        for (int j = 0; j < i; ++j) {
+                            if (j != tkIndex) {
+                                dialogs.get(j).checkBlockedDialog(robot, j +
+                                    ": A toolkit modal dialog should block this " +
+                                    "child dialog of an application modality excluded frame.");
+                            }
+                        }
+                    }
+                }
+
+                // show a document modal dialog; the toolkit modal dialog should block it
+                dialogs.get(tkIndex).clickOpenButton(robot);
+                robot.waitForIdle(delay);
+
+                frame.checkBlockedFrame(robot, "A toolkit modal dialog is visible.");
+
+                for (int i = 0; i < n; ++i) {
+                    if (i == tkIndex) {
+                        dialogs.get(tkIndex).checkUnblockedDialog(robot,
+                            tkIndex + ": This is a toolkit modal dialog. " +
+                            "A document modal dialog is visible.");
+                    } else {
+                        dialogs.get(i).checkBlockedDialog(robot,
+                            i + ": A toolkit modal dialog should block this dialog.");
+                    }
+                }
+
+                dialogs.get(tk0 + 3).clickCloseButton(robot); // close 2nd toolkit dialog
+                robot.waitForIdle(delay);
+
+                for (int i = 0; i < n; ++i) {
+
+                    if (i == tk0 + 3) { continue; }
+                    if (i == tk0) {
+                        dialogs.get(i).checkUnblockedDialog(robot,
+                            i + ": This is a toolkit modal dialog. A blocking " +
+                            "toolkit modal dialog was opened and then closed.");
+                    } else {
+                        dialogs.get(i).checkBlockedDialog(robot,
+                            i + ": This dialog should be blocked by a toolkit modal dialog. " +
+                            "Another blocking toolkit modal dialog was closed.");
+                    }
+                }
+
+                dialogs.get(tk0).clickCloseButton(robot);
+                robot.waitForIdle(delay);
+
+                frame.checkBlockedFrame(
+                        robot, "A document modal dialog should block this Frame.");
+
+                for (int i = 0; i < n - 1; ++i) {
+                    if (!isToolkitModal(i)) {
+                        dialogs.get(i).checkUnblockedDialog(robot, i + ": The parent " +
+                            "of the dialog is an app modality excluded Frame.");
+                    }
+                }
+
+                dialogs.get(n - 1).clickCloseButton(robot);
+                robot.waitForIdle(delay);
+
+                frame.checkUnblockedFrame(robot, "A document modal dialog " +
+                    "blocking this Frame was closed.");
+
+                for (int i = 0; i < n - 1; ++i) {
+                    if (!isToolkitModal(i)) {
+                        dialogs.get(i).checkUnblockedDialog(robot, i + ": A document modal " +
+                            "dialog blocking the parent frame was closed.");
+                    }
+                }
+            } // synchronized
+
+        } finally {
+            EventQueue.invokeAndWait(this::closeAll);
+        }
+    }
+
+    private boolean isToolkitModal(int i) { return (i % 3 == 2); }
+
+    private String getType(int i) {
+
+        switch (dialogList.get(i).getModalityType()) {
+            case APPLICATION_MODAL:
+                return "an application modal dialog";
+            case DOCUMENT_MODAL:
+                return "a document modal dialog";
+            case TOOLKIT_MODAL:
+                return "a toolkit modal dialog";
+        }
+        return "a modeless dialog";
+    }
+
+    public void closeAll() {
+
+        if (frame != null) { frame.dispose(); }
+        if (dialogList != null) {
+            Iterator<CustomDialog> it = dialogList.iterator();
+            while (it.hasNext()) { it.next().dispose(); }
+        }
+    }
+
+    class CustomFrame extends TestFrame {
+
+        @Override
+        public void doOpenAction() {
+            if ((dialogList != null) && (dialogList.size() > dialogCount)) {
+                dialogCount++;
+                CustomDialog d = dialogList.get(dialogCount);
+                if (d != null) { d.setVisible(true); }
+            }
+        }
+    }
+
+    class CustomDialog extends TestDialog {
+
+        public CustomDialog(Frame frame) { super(frame); }
+
+        @Override
+        public void doCloseAction() { this.dispose(); }
+
+        @Override
+        public void doOpenAction() {
+            if ((dialogList != null) && (dialogList.size() > dialogCount)) {
+                dialogCount++;
+                if (dialogList.get(dialogCount) != null) {
+                    dialogList.get(dialogCount).setVisible(true);
+                }
+            }
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        (new MultipleDialogs2Test()).doTest();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Modal/MultipleDialogs/MultipleDialogs3Test.java	Tue Dec 30 17:26:06 2014 +0400
@@ -0,0 +1,286 @@
+/*
+ * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8054358
+ * @summary Check correctness of modal blocking behavior for a chain of Dialogs
+ *          having different modality types with a Frame as a document root.
+ *
+ * @library ../helpers ../../../../lib/testlibrary/
+ * @build ExtendedRobot
+ * @build Flag
+ * @build TestDialog
+ * @build TestFrame
+ * @run main/timeout=500 MultipleDialogs3Test
+ */
+
+
+import java.awt.*;
+import static jdk.testlibrary.Asserts.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Collections;
+import java.util.Iterator;
+
+
+public class MultipleDialogs3Test {
+
+    private volatile CustomFrame  frame;
+    private List<CustomDialog> dialogList;
+    private static int delay = 500;
+
+    private int dialogCount = -1;
+
+    public void createGUI() {
+
+        final int n = 8;
+        dialogList = new ArrayList<>();
+
+        frame = new CustomFrame();
+        frame.setLocation(50, 50);
+        frame.setVisible(true);
+
+        int x = 250;
+        int y = 50;
+        for (int i = 0; i < n; ++i) {
+
+            CustomDialog dlg;
+            if (i == 0) {
+                dlg = new CustomDialog(frame);
+            } else {
+                dlg = new CustomDialog(dialogList.get(i - 1));
+            }
+            dlg.setLocation(x, y);
+            x += 200;
+            if (x > 600) {
+                x = 50;
+                y += 200;
+            }
+
+            Dialog.ModalityType type;
+
+            if (i % 4 == 0) {
+                type = Dialog.ModalityType.MODELESS;
+            } else if (i % 4 == 1) {
+                type = Dialog.ModalityType.DOCUMENT_MODAL;
+            } else if (i % 4 == 2) {
+                type = Dialog.ModalityType.APPLICATION_MODAL;
+            } else {
+                type = Dialog.ModalityType.TOOLKIT_MODAL;
+            }
+
+            dlg.setModalityType(type);
+            dialogList.add(dlg);
+        }
+    }
+
+    public void doTest() throws Exception {
+
+        try {
+            EventQueue.invokeAndWait(this::createGUI);
+
+            ExtendedRobot robot = new ExtendedRobot();
+            robot.waitForIdle(delay);
+
+            frame.clickOpenButton(robot);
+            robot.waitForIdle(delay);
+
+            List<CustomDialog> dialogs = Collections.synchronizedList(dialogList);
+            final int n = dialogs.size();
+
+            synchronized(dialogs) {
+                for (int i = 0; i < n; ++i) {
+                    dialogs.get(i).activated.waitForFlagTriggered();
+                    assertTrue(dialogs.get(i).activated.flag(), i + ": Dialog did not " +
+                        "trigger windowActivated event when it became visible.");
+
+                    dialogs.get(i).closeGained.waitForFlagTriggered();
+                    assertTrue(dialogs.get(i).closeGained.flag(), i + ": Close button " +
+                        "did not gain focus when Dialog became visible.");
+
+                    assertTrue(dialogs.get(i).closeButton.hasFocus(), i +
+                        ": Close button gained focus but then lost it.");
+
+                    dialogs.get(i).checkUnblockedDialog(robot,
+                        i + ": The dialog shouldn't be blocked.");
+
+                    if (i == 0) {
+                        assertTrue(dialogs.get(0).getModalityType() ==
+                            Dialog.ModalityType.MODELESS, "0: invalid modality type.");
+
+                        frame.checkUnblockedFrame(robot, i + ": A modeless dialog was " +
+                            "shown, but the parent frame became blocked.");
+
+                    } else {
+                        if (i % 4 == 0) { // modeless dialog
+                            assertTrue(dialogs.get(i).getModalityType() ==
+                                Dialog.ModalityType.MODELESS, i +
+                                ": incorrect dialog modality type.");
+
+                            dialogs.get(i - 1).checkUnblockedDialog(robot, i + ": A modeless " +
+                                "dialog was shown, but the parent dialog became blocked.");
+
+                            if (i > 0) {
+                                for (int j = 0; j < i - 1; ++j) {
+
+                                    dialogs.get(j).checkBlockedDialog(robot, i + ", " + j +
+                                        ": Showing a modeless dialog as a child of a " +
+                                        "modal dialog unblocked some dialog in its hierarchy.");
+                                }
+                            }
+                        } else {
+
+                            for (int j = 0; j < i; ++j) {
+
+                                dialogs.get(j).checkBlockedDialog(robot, i + ", " + j +
+                                    ": A modal dialog was shown, but some dialog " +
+                                    "in its hierarchy became unblocked.");
+                            }
+                        }
+
+                        frame.checkBlockedFrame(robot, i + ": A modal was dialog shown, " +
+                            "but the document root frame became unblocked.");
+                    }
+
+                    if (i != n - 1) {
+                        dialogs.get(i).clickOpenButton(robot);
+                        robot.waitForIdle(delay);
+                    }
+                }
+
+                for (int i = n - 1; i >= 0; --i) {
+
+                    resetAll();
+                    dialogs.get(i).clickCloseButton(robot);
+                    robot.waitForIdle(delay);
+
+                    if (i > 0) {
+
+                        dialogs.get(i - 1).activated.waitForFlagTriggered();
+                        assertTrue(dialogs.get(i - 1).activated.flag(), i + ": Dialog " +
+                            "was not activated when a child dialog was closed.");
+
+                        if (i == 1) {
+
+                            frame.checkUnblockedFrame(robot, "1: Frame having " +
+                                "a child modeless dialog was blocked.");
+
+                            dialogs.get(0).checkUnblockedDialog(robot,
+                                "0: A modeless dialog at the bottom " +
+                                "of the hierarchy was blocked.");
+
+                        } else if ((i - 1) % 4 == 0) { // dialog[i - 1] is modeless
+
+                            for (int j = 0; j < i - 2; ++j) {
+
+                                dialogs.get(j).checkBlockedDialog(robot, i + ", " + j +
+                                    ": A dialog in the hierarchy was not blocked. " +
+                                    "A dialog blocking a modeless dialog was closed.");
+                            }
+
+                            dialogs.get(i - 2).checkUnblockedDialog(robot, i + ": A modal " +
+                                "dialog having a child modeless dialog was blocked.");
+
+                            dialogs.get(i - 1).checkUnblockedDialog(robot, i + ": A modeless " +
+                                "dialog at the bottom of the hierarchy was blocked.");
+
+                            frame.checkBlockedFrame(robot, i +
+                                ": Frame having a child modal dialog was not blocked.");
+
+                        } else {
+                            for (int j = 0; j <= i - 2; ++j) {
+                                dialogs.get(j).checkBlockedDialog(robot, i + ", " + j +
+                                    ": A dialog in the hierarchy was not blocked. " +
+                                    "A child dialog was closed.");
+                            }
+
+                            dialogs.get(i - 1).checkUnblockedDialog(robot, (i - 1) +
+                                ": A dialog was not unblocked when the modal dialog was closed.");
+
+                            frame.checkBlockedFrame(robot, i + ": Frame having " +
+                                "a child modal dialog was not blocked. " +
+                                "Another child dialog was closed.");
+                        }
+                    } else {
+                        frame.activated.waitForFlagTriggered();
+                        assertTrue(frame.activated.flag(), i + ": Frame was not " +
+                            "activated when a child dialog was closed.");
+                    }
+                }
+            } // synchronized
+
+        } finally {
+            EventQueue.invokeAndWait(this::closeAll);
+        }
+    }
+
+    private void resetAll() {
+        frame.resetStatus();
+        Iterator<CustomDialog> it = dialogList.iterator();
+        while (it.hasNext()) { it.next().resetStatus(); }
+    }
+
+    public void closeAll() {
+        if (frame != null) { frame.dispose(); }
+        if (dialogList != null) {
+            Iterator<CustomDialog> it = dialogList.iterator();
+            while (it.hasNext()) { it.next().dispose(); }
+        }
+    }
+
+    class CustomFrame extends TestFrame {
+
+        @Override
+        public void doOpenAction() {
+            if ((dialogList != null) && (dialogList.size() > dialogCount)) {
+                dialogCount++;
+                CustomDialog d = dialogList.get(dialogCount);
+                if (d != null) { d.setVisible(true); }
+            }
+        }
+    }
+
+    class CustomDialog extends TestDialog {
+
+        public CustomDialog(Frame frame)   { super(frame); }
+        public CustomDialog(Dialog dialog) { super(dialog); }
+
+        @Override
+        public void doCloseAction() { this.dispose(); }
+
+        @Override
+        public void doOpenAction() {
+            if ((dialogList != null) && (dialogList.size() > dialogCount)) {
+                dialogCount++;
+                CustomDialog d = dialogList.get(dialogCount);
+                if (d != null) { d.setVisible(true); }
+            }
+        }
+    }
+
+
+    public static void main(String[] args) throws Exception {
+        (new MultipleDialogs3Test()).doTest();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Modal/MultipleDialogs/MultipleDialogs4Test.java	Tue Dec 30 17:26:06 2014 +0400
@@ -0,0 +1,178 @@
+/*
+ * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8054358 8055003
+ * @summary Check whether application and document modality levels for Dialog
+ *          work properly. Also check whether the blocking dialogs are
+ *          opening on top of the windows they block.
+ *
+ * @library ../helpers ../../../../lib/testlibrary/
+ * @build ExtendedRobot
+ * @build Flag
+ * @build TestDialog
+ * @build TestFrame
+ * @run main MultipleDialogs4Test
+ */
+
+
+import java.awt.*;
+import static jdk.testlibrary.Asserts.*;
+
+
+public class MultipleDialogs4Test {
+
+    private volatile TopLevelFrame frame;
+    private volatile CustomFrame   secondFrame;
+    private volatile TestFrame     thirdFrame;
+    private volatile TestDialog    dialog, secondDialog, docChildDialog, appChildDialog;
+
+    private static final int delay = 500;
+
+
+    private void createGUI() {
+
+        frame = new TopLevelFrame();
+        frame.setLocation(50, 50);
+        frame.setVisible(true);
+
+        dialog = new TestDialog((Dialog) null);
+        dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
+        dialog.setLocation(150, 50);
+
+        appChildDialog = new TestDialog(dialog);
+        appChildDialog.setLocation(150, 90);
+
+        secondFrame = new CustomFrame();
+        secondFrame.setLocation(50, 250);
+
+        secondDialog = new TestDialog(secondFrame);
+        secondDialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
+        secondDialog.setLocation(150, 250);
+
+        docChildDialog = new TestDialog(secondFrame);
+        docChildDialog.setBackground(Color.black);
+        docChildDialog.setLocation(250, 250);
+
+        thirdFrame = new TestFrame();
+        thirdFrame.setLocation(250, 50);
+    }
+
+    public void doTest() throws Exception {
+
+        try {
+            EventQueue.invokeAndWait(this::createGUI);
+
+            final int nAttempts = 3;
+            ExtendedRobot robot = new ExtendedRobot();
+            robot.waitForIdle(delay);
+
+            frame.clickOpenButton(robot);
+            robot.waitForIdle(delay);
+
+            secondFrame.clickOpenButton(robot);
+            robot.waitForIdle(delay);
+
+            secondFrame.checkBlockedFrame(robot,
+                "A document modal dialog should block this Frame.");
+
+            secondDialog.checkUnblockedDialog(robot, "This is a document " +
+                "modal dialog. No window blocks it.");
+
+            frame.checkUnblockedFrame(robot,
+                "There are no dialogs blocking this Frame.");
+
+            frame.clickCloseButton(robot);
+            robot.waitForIdle(delay);
+
+            frame.clickDummyButton(robot, nAttempts, false,
+                "The frame still on top even after showing a modal dialog.");
+            robot.waitForIdle(delay);
+
+            EventQueue.invokeAndWait(() -> { thirdFrame.setVisible(true); });
+            robot.waitForIdle(delay);
+
+            dialog.clickDummyButton(robot);
+            robot.waitForIdle(delay);
+
+            secondDialog.clickDummyButton(
+                robot, nAttempts, false, "The document modal dialog " +
+                "was not blocked by an application modal dialog.");
+            robot.waitForIdle(delay);
+
+            EventQueue.invokeLater(() -> { docChildDialog.setVisible(true); });
+            robot.waitForIdle(delay);
+
+            Color c = robot.getPixelColor(
+                (int) secondDialog.getLocationOnScreen().x + secondDialog.getSize().width  - 25,
+                (int) secondDialog.getLocationOnScreen().y + secondDialog.getSize().height - 25);
+            assertFalse(c.equals(Color.black), "A dialog which should be blocked " +
+                "by document modal dialog overlapping it.");
+
+            EventQueue.invokeLater(() -> { appChildDialog.setVisible(true); });
+            robot.waitForIdle(delay);
+
+            appChildDialog.activated.waitForFlagTriggered();
+            assertTrue(appChildDialog.activated.flag(), "The child dialog of the " +
+                "application modal dialog still not visible.");
+            robot.waitForIdle(delay);
+
+            dialog.clickDummyButton(robot, nAttempts, false, "The child dialog of " +
+                "the application modal dialog did not overlap it.");
+            robot.waitForIdle(delay);
+
+        } finally {
+            EventQueue.invokeAndWait(this::closeAll);
+        }
+    }
+
+    public void closeAll() {
+
+        if (frame != null) { frame.dispose(); }
+        if (dialog != null) { dialog.dispose(); }
+        if (appChildDialog != null) { appChildDialog.dispose(); }
+        if (secondFrame != null) { secondFrame.dispose(); }
+        if (secondDialog != null) { secondDialog.dispose(); }
+        if (docChildDialog != null) { docChildDialog.dispose(); }
+        if (thirdFrame != null) { thirdFrame.dispose(); }
+    }
+
+    class TopLevelFrame extends TestFrame {
+
+        @Override
+        public void doOpenAction() { secondFrame.setVisible(true); }
+        @Override
+        public void doCloseAction() { dialog.setVisible(true); }
+    }
+
+    class CustomFrame extends TestFrame {
+
+        @Override
+        public void doOpenAction() { secondDialog.setVisible(true); }
+    }
+
+    public static void main(String[] args) throws Exception {
+        (new MultipleDialogs4Test()).doTest();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Modal/MultipleDialogs/MultipleDialogs5Test.java	Tue Dec 30 17:26:06 2014 +0400
@@ -0,0 +1,184 @@
+/*
+ * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8054358
+ * @summary This is a simple check if a chain of dialogs having different
+  *         modality types block each other properly.
+ *
+ * @library ../helpers ../../../../lib/testlibrary/
+ * @build ExtendedRobot
+ * @build Flag
+ * @build TestDialog
+ * @build TestFrame
+ * @build TestWindow
+ * @run main MultipleDialogs5Test
+ */
+
+
+import java.awt.*;
+import static jdk.testlibrary.Asserts.*;
+
+
+public class MultipleDialogs5Test {
+
+    private volatile ParentFrame parent;
+    private volatile ModalDialog appDialog, docDialog, tkDialog;
+    private volatile CustomWindow window;
+
+    private static int delay = 500;
+
+    private void createGUI() {
+
+        parent = new ParentFrame();
+        parent.setLocation(50, 50);
+        parent.setVisible(true);
+
+        appDialog = new ModalDialog(parent);
+        appDialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
+        appDialog.setLocation(250, 50);
+
+        docDialog = new ModalDialog(appDialog);
+        docDialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
+        docDialog.setLocation(450, 50);
+
+        window = new CustomWindow(docDialog);
+        window.setLocation(50, 250);
+
+        tkDialog = new ModalDialog(docDialog);
+        tkDialog.setLocation(250, 250);
+        tkDialog.setModalityType(Dialog.ModalityType.TOOLKIT_MODAL);
+
+        appDialog.setWindowToOpen(docDialog);
+        docDialog.setWindowToOpen(window);
+    }
+
+    public void doTest() throws Exception {
+
+         try {
+            EventQueue.invokeAndWait(this::createGUI);
+
+            ExtendedRobot robot = new ExtendedRobot();
+            robot.waitForIdle(delay);
+
+            parent.clickOpenButton(robot);
+            robot.waitForIdle(delay);
+
+            parent.checkBlockedFrame(robot,
+                "This Frame is blocked by an application modal dialog.");
+
+            appDialog.clickOpenButton(robot);
+            robot.waitForIdle(delay);
+
+            appDialog.checkBlockedDialog(robot,
+                "This Dialog is blocked by a document modal dialog.");
+
+            docDialog.clickOpenButton(robot);
+            robot.waitForIdle(delay);
+
+            docDialog.checkUnblockedDialog(robot,
+                "This Dialog is not blocked by any modal dialog.");
+
+            window.clickOpenButton(robot);
+            robot.waitForIdle(delay);
+
+            window.checkBlockedWindow(robot,
+                "This Window is blocked by a toolkit modal dialog.");
+
+            tkDialog.clickCloseButton(robot);
+            robot.waitForIdle(delay);
+            assertFalse(tkDialog.isVisible(),
+                "The toolkit modal dialog was not disposed.");
+
+            window.clickCloseButton(robot);
+            robot.waitForIdle(delay);
+            assertFalse(window.isVisible(),
+                "The window was not disposed.");
+
+            docDialog.clickCloseButton(robot);
+            robot.waitForIdle(delay);
+            assertFalse(docDialog.isVisible(),
+                "The document modal dialog was not disposed.");
+
+            appDialog.clickCloseButton(robot);
+            robot.waitForIdle(delay);
+            assertFalse(appDialog.isVisible(),
+                "The application modal dialog was not disposed.");
+        } finally {
+            EventQueue.invokeAndWait(this::closeAll); // if something wasn't closed
+        }
+    }
+
+    private void closeAll() {
+
+        if (appDialog != null) { appDialog.dispose(); }
+        if (tkDialog  != null) {  tkDialog.dispose(); }
+        if (docDialog != null) { docDialog.dispose(); }
+        if (parent != null) { parent.dispose(); }
+        if (window != null) { window.dispose(); }
+    }
+
+    private class ParentFrame extends TestFrame {
+
+        @Override
+        public void doOpenAction() {
+            if (appDialog != null) { appDialog.setVisible(true); }
+        }
+    }
+
+    private class CustomWindow extends TestWindow {
+
+        public CustomWindow(Dialog d) { super(d); }
+
+        @Override
+        public void doOpenAction() {
+            if (tkDialog != null) { tkDialog.setVisible(true); }
+        }
+
+        @Override
+        public void doCloseAction() { this.dispose(); }
+    }
+
+    private class ModalDialog extends TestDialog {
+
+        private Window w;
+
+        public ModalDialog(Frame  f) { super(f); }
+        public ModalDialog(Dialog d) { super(d); }
+
+        public void setWindowToOpen(Window w) { this.w = w; }
+
+        @Override
+        public void doCloseAction() { this.dispose(); }
+
+        @Override
+        public void doOpenAction() {
+            if (w != null) { w.setVisible(true); }
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        (new MultipleDialogs5Test()).doTest();
+    }
+}