jdk/test/java/awt/Modal/ModalBlockingTests/UnblockedDialogTest.java
author avstepan
Mon, 21 Jul 2014 13:17:43 +0400
changeset 25787 f1c606e8b3f8
permissions -rw-r--r--
8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3 Reviewed-by: pchelko
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25787
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
     1
/*
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
     2
 * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
     4
 *
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
     8
 *
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    13
 * accompanied this code).
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    14
 *
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    18
 *
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    21
 * questions.
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    22
 */
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    23
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    24
import java.awt.*;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    25
import static jdk.testlibrary.Asserts.*;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    26
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    27
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    28
public class UnblockedDialogTest {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    29
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    30
    private TestDialog dialog;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    31
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    32
    private static final int delay = 500;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    33
    private final ExtendedRobot robot;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    34
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    35
    private Dialog parentDialog;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    36
    private Frame  parentFrame;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    37
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    38
    private enum DialogOwner {HIDDEN_DIALOG, HIDDEN_FRAME, NULL_DIALOG, NULL_FRAME};
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    39
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    40
    Dialog.ModalityType modalityType;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    41
    boolean setModal;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    42
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    43
    private UnblockedDialogTest(Dialog.ModalityType modType,
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    44
                                boolean             set) throws Exception {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    45
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    46
        robot = new ExtendedRobot();
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    47
        modalityType = modType;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    48
        setModal = set;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    49
    }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    50
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    51
    public UnblockedDialogTest(Dialog.ModalityType modType) throws Exception {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    52
        this(modType, false);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    53
    }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    54
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    55
    public UnblockedDialogTest() throws Exception { this(null, true); }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    56
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    57
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    58
    private void createGUI(DialogOwner owner) {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    59
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    60
        switch (owner) {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    61
            case HIDDEN_DIALOG:
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    62
                parentDialog = new Dialog((Frame) null);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    63
                dialog = new TestDialog(parentDialog);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    64
                break;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    65
            case NULL_DIALOG:
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    66
                dialog = new TestDialog((Dialog) null);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    67
                break;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    68
            case HIDDEN_FRAME:
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    69
                parentFrame = new Frame();
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    70
                dialog = new TestDialog(parentFrame);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    71
                break;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    72
            case NULL_FRAME:
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    73
                dialog = new TestDialog((Frame) null);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    74
                break;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    75
        }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    76
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    77
        assertFalse(dialog == null, "error: null dialog");
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    78
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    79
        dialog.setLocation(50, 50);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    80
        if (setModal) {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    81
            dialog.setModal(true);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    82
        } else if (modalityType != null) {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    83
            dialog.setModalityType(modalityType);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    84
        }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    85
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    86
        dialog.setVisible(true);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    87
    }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    88
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    89
    public void doTest() throws Exception {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    90
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    91
        try {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    92
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    93
            robot.waitForIdle(delay);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    94
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    95
            for (DialogOwner owner: DialogOwner.values()) {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    96
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    97
                EventQueue.invokeLater(() -> { createGUI(owner); });
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    98
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    99
                robot.waitForIdle(delay);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   100
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   101
                dialog.activated.waitForFlagTriggered();
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   102
                assertTrue(dialog.activated.flag(), "Dialog did not trigger " +
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   103
                    "Window Activated event when it became visible");
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   104
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   105
                dialog.closeGained.waitForFlagTriggered();
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   106
                assertTrue(dialog.closeGained.flag(), "The 1st button did not " +
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   107
                    "gain focus when the dialog became visible");
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   108
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   109
                dialog.checkUnblockedDialog(robot, "");
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   110
                robot.waitForIdle(delay);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   111
            }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   112
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   113
        } finally {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   114
            EventQueue.invokeAndWait(this::closeAll);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   115
        }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   116
    }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   117
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   118
    private void closeAll() {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   119
        if (dialog != null) { dialog.dispose(); }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   120
        if (parentDialog != null) { parentDialog.dispose(); }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   121
        if (parentFrame  != null) {  parentFrame.dispose(); }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   122
    }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   123
}