jdk/test/java/awt/Modal/ModalBlockingTests/BlockingFDTest.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
// FD: Frame -> Dialog
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
public class BlockingFDTest {
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 TestFrame  frame;
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
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    35
    private static final int delay = 500;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    36
    private final ExtendedRobot robot;
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 final Dialog.ModalityType modalityType;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    39
    private final boolean setModal;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    40
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    41
    private BlockingFDTest(Dialog.ModalityType modType, boolean modal) throws Exception {
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
        modalityType = modType;
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    44
        setModal = modal;
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
        EventQueue.invokeLater(this::createGUI);
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 BlockingFDTest(Dialog.ModalityType modType) throws Exception {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    51
        this(modType, false);
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
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    54
    public BlockingFDTest() throws Exception {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    55
        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() {
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
        frame = new CustomFrame();
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    61
        frame.setLocation(50, 50);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    62
        dialog = new TestDialog(frame);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    63
        if (setModal) {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    64
            dialog.setModal(true);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    65
        } else if (modalityType != null) {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    66
            dialog.setModalityType(modalityType);
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.setLocation(250, 50);
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
        frame.setVisible(true);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    71
    }
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
    public void doTest() throws Exception {
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
        try {
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
            robot.waitForIdle(delay);
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
            frame.clickOpenButton(robot);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    80
            robot.waitForIdle(delay);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    81
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    82
            dialog.activated.waitForFlagTriggered();
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    83
            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
    84
                "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
    85
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    86
            dialog.closeGained.waitForFlagTriggered();
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    87
            assertTrue(dialog.closeGained.flag(), "the 1st Dialog button " +
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    88
                "did not gain focus when it became visible");
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    89
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    90
            assertTrue(dialog.closeButton.hasFocus(), "the 1st Dialog button " +
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    91
                "gained the focus but lost it afterwards");
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
            if ((modalityType == Dialog.ModalityType.APPLICATION_MODAL) ||
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    94
                (modalityType == Dialog.ModalityType.DOCUMENT_MODAL) ||
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    95
                (modalityType == Dialog.ModalityType.TOOLKIT_MODAL) ||
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    96
                setModal)
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    97
            {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    98
                frame.checkBlockedFrame(robot,
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
    99
                    "Frame is the parent of a visible " + modalityType + " Dialog.");
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   100
            } else {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   101
                frame.checkUnblockedFrame(robot,
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   102
                    "Frame is the parent of a visible " + modalityType + " Dialog.");
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   103
            }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   104
            robot.waitForIdle(delay);
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   105
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   106
        } finally {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   107
            EventQueue.invokeAndWait(this::closeAll);
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
    }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   110
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   111
    private void closeAll() {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   112
        if (frame  != null) {  frame.dispose(); }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   113
        if (dialog != null) { dialog.dispose(); }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   114
    }
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
    class CustomFrame extends TestFrame {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   118
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   119
        @Override
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   120
        public void doOpenAction() {
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   121
            if (dialog != null) { dialog.setVisible(true); }
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
    }
f1c606e8b3f8 8049617: move awt automated tests from AWT_Modality to OpenJDK repository - part 3
avstepan
parents:
diff changeset
   124
}