jdk/test/java/awt/Modal/ModalBlockingTests/BlockingDFTest.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
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    25
import java.awt.*;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    26
import static jdk.testlibrary.Asserts.*;
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
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    29
// DF: Dialog -> Frame
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    30
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    31
public class BlockingDFTest {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    32
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    33
    private TestDialog dialog;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    34
    private TestFrame  frame;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    35
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    36
    private static final int delay = 500;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    37
    private final ExtendedRobot robot;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    38
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    39
    private BlockingDFTest(Dialog.ModalityType modalityType,
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    40
                           boolean             setModal) throws Exception {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    41
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    42
        robot = new ExtendedRobot();
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    43
        EventQueue.invokeLater(() -> { createGUI(modalityType, setModal); });
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    44
    }
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
    public BlockingDFTest(Dialog.ModalityType modalityType) throws Exception {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    47
        this(modalityType, false);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    48
    }
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
    public BlockingDFTest() throws Exception { this(null, true); }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    51
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    52
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    53
    private void createGUI(Dialog.ModalityType modalityType,
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    54
                           boolean             setModal) {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    55
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    56
        frame = new TestFrame();
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    57
        frame.setLocation(50, 50);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    58
        frame.setVisible(true);
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
        dialog = new TestDialog((Dialog) null);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    61
        dialog.setLocation(250, 50);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    62
        if (setModal) {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    63
            dialog.setModal(true);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    64
        } else if (modalityType != null) {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    65
            dialog.setModalityType(modalityType);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    66
        }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    67
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    68
        dialog.setVisible(true);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    69
    }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    70
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    71
    public void doTest() throws Exception {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    72
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    73
        try {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    74
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    75
            robot.waitForIdle(delay);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    76
            dialog.activated.waitForFlagTriggered();
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    77
            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
    78
                "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
    79
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    80
            dialog.closeGained.waitForFlagTriggered();
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    81
            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
    82
                "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
    83
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    84
            dialog.checkUnblockedDialog(robot, "");
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    85
            frame.checkBlockedFrame(robot, "");
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    86
            robot.waitForIdle(delay);
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
        } finally {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    89
            EventQueue.invokeAndWait(this::closeAll);
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
    }
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
    private void closeAll() {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    94
        if (frame  != null) {  frame.dispose(); }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    95
        if (dialog != null) { dialog.dispose(); }
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
}