jdk/test/java/awt/Modal/ModalFocusTransferTests/FocusTransferWDFTest.java
author avstepan
Wed, 09 Jul 2014 12:56:03 +0400
changeset 25759 625be49758c1
permissions -rw-r--r--
8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2 Reviewed-by: pchelko
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25759
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
     1
/*
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
     2
 * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
     4
 *
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
     8
 *
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    13
 * accompanied this code).
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    14
 *
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    18
 *
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    21
 * questions.
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    22
 */
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    23
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    24
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    25
import java.awt.*;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    26
import static jdk.testlibrary.Asserts.*;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    27
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    28
// WDF: Window -> Dialog -> Frame
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    29
public class FocusTransferWDFTest {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    30
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    31
    class CustomDialog extends TestDialog {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    32
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    33
        public CustomDialog(Frame f) {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    34
            super(f);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    35
        }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    36
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    37
        public CustomDialog(Dialog d) {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    38
            super(d);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    39
        }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    40
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    41
        @Override
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    42
        public void doOpenAction() {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    43
            if (frame != null) {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    44
                frame.setVisible(true);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    45
            }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    46
        }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    47
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    48
        @Override
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    49
        public void doCloseAction() {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    50
            this.dispose();
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    51
        }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    52
    }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    53
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    54
    class CustomFrame extends TestFrame {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    55
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    56
        @Override
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    57
        public void doCloseAction() {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    58
            this.dispose();
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    59
        }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    60
    }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    61
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    62
    class CustomWindow extends TestWindow {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    63
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    64
        public CustomWindow(Frame f) {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    65
            super(f);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    66
        }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    67
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    68
        @Override
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    69
        public void doOpenAction() {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    70
            if (dialog != null) {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    71
                dialog.setVisible(true);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    72
            }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    73
        }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    74
    }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    75
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    76
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    77
    private TestDialog dialog;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    78
    private TestFrame  frame;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    79
    private TestWindow window;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    80
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    81
    private Frame  parentFrame;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    82
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    83
    private static final int delay = 1000;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    84
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    85
    private final ExtendedRobot robot;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    86
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    87
    private Dialog.ModalityType modalityType;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    88
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    89
    public enum DialogParent {FRAME, NULL_DIALOG};
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    90
    private DialogParent dialogParent;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    91
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    92
    public enum WindowParent {FRAME, NEW_FRAME};
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    93
    private WindowParent windowParent;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    94
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    95
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    96
    FocusTransferWDFTest(Dialog.ModalityType modType,
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    97
                         DialogParent        dlgParent,
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    98
                         WindowParent        winParent) throws Exception {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
    99
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   100
        modalityType = modType;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   101
        dialogParent = dlgParent;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   102
        windowParent = winParent;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   103
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   104
        robot = new ExtendedRobot();
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   105
        EventQueue.invokeLater( this::createGUI );
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   106
    }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   107
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   108
    private void createGUI() {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   109
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   110
        frame = new CustomFrame();
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   111
        frame.setLocation(50, 50);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   112
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   113
        switch (dialogParent) {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   114
            case FRAME:
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   115
                dialog = new CustomDialog(frame);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   116
                break;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   117
            case NULL_DIALOG:
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   118
                dialog = new CustomDialog((Dialog) null);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   119
                break;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   120
        }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   121
        assertTrue(dialog != null, "error: null dialog");
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   122
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   123
        if (modalityType == null) {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   124
            modalityType = Dialog.ModalityType.MODELESS;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   125
        } else {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   126
            dialog.setModalityType(modalityType);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   127
        }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   128
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   129
        dialog.setLocation(250, 50);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   130
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   131
        switch (windowParent) {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   132
            case FRAME:
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   133
                window = new CustomWindow(frame);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   134
                break;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   135
            case NEW_FRAME:
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   136
                parentFrame = new Frame();
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   137
                window = new CustomWindow(parentFrame);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   138
                break;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   139
        }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   140
        assertTrue(window != null, "error: null window");
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   141
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   142
        window.setLocation(450, 50);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   143
        window.setVisible(true);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   144
    }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   145
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   146
    private void closeAll() {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   147
        if (dialog != null) { dialog.dispose(); }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   148
        if ( frame != null) {  frame.dispose(); }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   149
        if (window != null) { window.dispose(); }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   150
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   151
        if (parentFrame  != null) {  parentFrame.dispose(); }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   152
    }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   153
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   154
    private void ModalTest() throws Exception {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   155
        frame.checkCloseButtonFocusGained(false, 10);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   156
        dialog.checkOpenButtonFocusLost(false, 10);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   157
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   158
        dialog.clickCloseButton(robot);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   159
        robot.waitForIdle(delay);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   160
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   161
        frame.checkCloseButtonFocusGained(true);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   162
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   163
        window.openGained.reset();
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   164
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   165
        frame.clickCloseButton(robot);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   166
        robot.waitForIdle(delay);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   167
    }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   168
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   169
    public void doTest() throws Exception {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   170
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   171
        try {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   172
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   173
            robot.waitForIdle(delay);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   174
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   175
            window.checkCloseButtonFocusGained(false, 10);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   176
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   177
            window.clickOpenButton(robot);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   178
            robot.waitForIdle(delay);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   179
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   180
            dialog.checkCloseButtonFocusGained(true);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   181
            window.checkOpenButtonFocusLost(false, 10);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   182
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   183
            dialog.clickOpenButton(robot);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   184
            robot.waitForIdle(delay);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   185
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   186
            switch (modalityType) {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   187
                case APPLICATION_MODAL:
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   188
                    ModalTest();
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   189
                    if (windowParent == WindowParent.FRAME) {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   190
                        assertFalse(window.isVisible(),
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   191
                            "window shouldn't be visible");
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   192
                    } else { // WindowParent.NEW_FRAME
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   193
                        window.checkOpenButtonFocusGained(false, 10);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   194
                    }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   195
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   196
                    break;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   197
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   198
                case DOCUMENT_MODAL:
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   199
                    if (dialogParent == DialogParent.FRAME) {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   200
                        ModalTest();
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   201
                        if (windowParent == WindowParent.FRAME) { // 10
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   202
                            assertFalse(window.isVisible(),
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   203
                                "window shouldn't be visible");
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   204
                        } else { // WindowParent.NEW_FRAME
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   205
                            window.checkOpenButtonFocusGained(false, 10);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   206
                        }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   207
                    } else { // DialogParent.NULL_DIALOG
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   208
                        frame.checkCloseButtonFocusGained(true);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   209
                        dialog.checkOpenButtonFocusLost(true);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   210
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   211
                        dialog.openGained.reset();
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   212
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   213
                        frame.clickCloseButton(robot);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   214
                        robot.waitForIdle(delay);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   215
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   216
                        dialog.checkOpenButtonFocusGained(true);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   217
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   218
                        window.openGained.reset();
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   219
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   220
                        dialog.clickCloseButton(robot);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   221
                        robot.waitForIdle(delay);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   222
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   223
                        window.checkOpenButtonFocusGained(false, 10);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   224
                    }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   225
                    break;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   226
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   227
                case MODELESS:
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   228
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   229
                    frame.checkCloseButtonFocusGained(true);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   230
                    dialog.checkOpenButtonFocusLost(true);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   231
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   232
                    dialog.openGained.reset();
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   233
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   234
                    frame.clickCloseButton(robot);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   235
                    robot.waitForIdle(delay);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   236
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   237
                    if (dialogParent == DialogParent.NULL_DIALOG) {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   238
                        dialog.checkOpenButtonFocusGained(true);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   239
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   240
                        window.openGained.reset();
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   241
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   242
                        dialog.clickCloseButton(robot);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   243
                        robot.waitForIdle(delay);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   244
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   245
                        window.checkOpenButtonFocusGained(false, 10);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   246
                    } else {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   247
                        assertFalse(dialog.isVisible(),
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   248
                            "dialog shouldn't be visible");
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   249
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   250
                        if (windowParent == WindowParent.FRAME) {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   251
                            assertFalse(window.isVisible(),
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   252
                                "window shouldn't be visible");
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   253
                        }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   254
                    }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   255
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   256
                    break;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   257
            }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   258
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   259
        } catch (Exception e) {
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   260
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   261
            // make screenshot before exit
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   262
            Rectangle rect = new Rectangle(0, 0, 650, 250);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   263
            java.awt.image.BufferedImage img = robot.createScreenCapture(rect);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   264
            javax.imageio.ImageIO.write(img, "jpg", new java.io.File("NOK.jpg"));
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   265
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   266
            throw e;
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   267
        }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   268
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   269
        robot.waitForIdle(delay);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   270
        EventQueue.invokeAndWait(this::closeAll);
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   271
    }
625be49758c1 8047367: move awt automated tests from AWT_Modality to OpenJDK repository - part 2
avstepan
parents:
diff changeset
   272
}