test/jdk/java/awt/Focus/AutoRequestFocusTest/AutoRequestFocusToFrontTest.java
author serb
Wed, 27 Feb 2019 18:46:55 -0800
changeset 54231 e4813eded7cb
parent 50834 9cf279436b9d
permissions -rw-r--r--
8213110: Remove the use of applets in automatic tests Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
50834
9cf279436b9d 8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents: 47216
diff changeset
     2
 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
  @test
40128
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 36511
diff changeset
    26
  @key headful
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
  @bug       6187066
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
  @summary   Tests the Window.autoRequestFocus property for the Window.toFront() method.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 5506
diff changeset
    29
  @library /java/awt/patchlib     ../../regtesthelpers
9d0388c6b336 8142968: Module System implementation
alanb
parents: 5506
diff changeset
    30
  @build java.desktop/java.awt.Helper
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
  @build      Util
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
  @run       main AutoRequestFocusToFrontTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import test.java.awt.regtesthelpers.Util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
54231
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    38
public class AutoRequestFocusToFrontTest {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    static boolean haveDelays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    static Frame auxFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    static Frame frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    static Button frameButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    static Frame frame2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    static Button frameButton2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static Frame frame3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    static Button frameButton3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    static Window window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    static Button winButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    static Dialog dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    static Button dlgButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    static Window ownedWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static Button ownWinButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    static Dialog ownedDialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    static Button ownDlgButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    static Dialog modalDialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static Button modalDlgButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static String toolkitClassName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    static Robot robot = Util.createRobot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        if (args.length != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            haveDelays = "delay".equals(args[0]) ? true : false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        AutoRequestFocusToFrontTest app = new AutoRequestFocusToFrontTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        app.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        app.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        toolkitClassName = Toolkit.getDefaultToolkit().getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    static void recreateGUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        if (auxFrame != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            auxFrame.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            frame.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            frame2.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            frame3.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            window.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            dialog.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            ownedWindow.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            ownedDialog.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            modalDialog.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        auxFrame = new Frame("Auxiliary Frame");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        frame = new Frame("Test Frame");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        frameButton = new Button("button");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        frame2 = new Frame("Test Frame 2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        frameButton2 = new Button("button");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        frame3 = new Frame("Test Frame 3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        frameButton3 = new Button("button");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        window = new Window(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        winButton = new Button("button");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        dialog = new Dialog((Frame)null, "Test Dialog");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        dlgButton = new Button("button");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        ownedWindow = new Window(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        ownWinButton = new Button("button");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        ownedDialog = new Dialog(frame2, "Test Owned Dialog");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        ownDlgButton = new Button("button");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        modalDialog = new Dialog(frame3, "Test Modal Dialog");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        modalDlgButton = new Button("button");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        auxFrame.setBounds(100, 100, 300, 300);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        frame.setBounds(120, 120, 260, 260);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        frame.add(frameButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        frame2.setBounds(120, 120, 260, 260);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        frame2.add(frameButton2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        frame3.setBounds(120, 120, 260, 260);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        frame3.add(frameButton3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        window.setBounds(120, 120, 260, 260);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        window.add(winButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        dialog.setBounds(120, 120, 260, 260);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        dialog.add(dlgButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        ownedWindow.setBounds(140, 140, 220, 220);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        ownedWindow.add(ownWinButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        ownedDialog.setBounds(140, 140, 220, 220);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        ownedDialog.add(ownDlgButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        modalDialog.setBounds(140, 140, 220, 220);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        modalDialog.add(modalDlgButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        modalDialog.setModal(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public void start() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        // 1. Simple Frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        //////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        recreateGUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        Test.setWindows(frame, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        Test.test("Test stage 1 in progress", frameButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        // 2. Ownerless Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        //////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        recreateGUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        Test.setWindows(window, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        Test.test("Test stage 2 in progress", winButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        // 3. Ownerless Dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        //////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        recreateGUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        Test.setWindows(dialog, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        Test.test("Test stage 3 in progress", dlgButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        // 4.1. Owner Frame (with owned Window).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        ///////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        recreateGUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        Test.setWindows(frame, null, new Window[] {ownedWindow, frame});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        Test.test("Test stage 4.1 in progress", ownWinButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        // 4.2. Owned Window (with owner Frame).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        ///////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        recreateGUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        Test.setWindows(ownedWindow, null, new Window[] {ownedWindow, frame});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        Test.test("Test stage 4.2 in progress", ownWinButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        // 5.1. Owner Frame (with owned Dialog).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        ///////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        recreateGUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        Test.setWindows(frame2, null, new Window[] {ownedDialog, frame2});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        Test.test("Test stage 5.1 in progress", ownDlgButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        // 5.2. Owned Dialog (with owner Frame).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        ///////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        recreateGUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        Test.setWindows(ownedDialog, null, new Window[] {ownedDialog, frame2});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        Test.test("Test stage 5.2 in progress", ownDlgButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        ////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        // 6.1. Owned modal Dialog (with owner Frame).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        //      Focused frame is excluded from modality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        ////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (!"sun.awt.motif.MToolkit".equals(toolkitClassName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            recreateGUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            auxFrame.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            Test.setWindows(modalDialog, modalDialog, new Window[] {modalDialog, frame3});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            Test.test("Test stage 6.1 in progress", modalDlgButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        // 6.2. Owner Frame (with owned modal Dialog).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        //      Focused frame is excluded from modality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        ////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (!"sun.awt.motif.MToolkit".equals(toolkitClassName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            recreateGUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            auxFrame.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            Test.setWindows(frame3, modalDialog, new Window[] {modalDialog, frame3});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            Test.test("Test stage 6.2 in progress", modalDlgButton, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        ///////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        // 7. Calling setVisible(true) for the shown Frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        ///////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        recreateGUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        Test.setWindows(frame, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        Test.setTestSetVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        Test.test("Test stage 7 in progress", frameButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
50834
9cf279436b9d 8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents: 47216
diff changeset
   236
        System.out.println("Test passed.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    static class Test {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        static Window testWindow; // a window to move to front with autoRequestFocus set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        static Window focusWindow; // a window to gain focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        static Window[] showWindows; // windows to show, or null if only testWindow should be shown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        static boolean testSetVisible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        static void setWindows(Window _testWindow, Window _focusWindow, Window[] _showWindows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            testWindow = _testWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            focusWindow = _focusWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            showWindows = _showWindows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        static void setTestSetVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            testSetVisible = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
         * @param msg notifies test stage number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
         * @param testButton a button of the window (owner or owned) that is to be on the top of stack order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
         * @param shouldFocusChange true for modal dialogs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        static void test(String msg, final Button testButton, boolean shouldFocusChange) {
50834
9cf279436b9d 8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents: 47216
diff changeset
   261
            System.out.println(msg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            showWindows(testWindow, showWindows, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            pause(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            /////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            // Test that calling toFront() doesn't cause focus change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            // when 'autoRequestFocus' is false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            /////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            Runnable action = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                        testWindow.setAutoRequestFocus(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                        if (testSetVisible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                            setVisible(testWindow, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                            toFront(testWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            if (shouldFocusChange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                action.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                if (!focusWindow.isFocused()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                    throw new TestFailedException("the window must gain focus on moving to front but it didn't!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            } else if (TestHelper.trackFocusChangeFor(action, robot)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                throw new TestFailedException("the window shouldn't gain focus on moving to front but it did!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            pause(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            ///////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            // Test that the window (or its owned window) is on top.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            ///////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            // The latest versions of Metacity (e.g. 2.16) have problems with moving a window to the front.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            if (Util.getWMID() != Util.METACITY_WM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                boolean performed = Util.trackActionPerformed(testButton, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                            Util.clickOnComp(testButton, robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    }, 1000, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                if (!performed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                    // For the case when the robot failed to trigger ACTION_EVENT.
50834
9cf279436b9d 8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents: 47216
diff changeset
   310
                    System.out.println("(ACTION_EVENT was not generated. One more attemp.)");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                    performed = Util.trackActionPerformed(testButton, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                                Util.clickOnComp(testButton, robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                        }, 1000, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                    if (!performed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                        throw new TestFailedException("the window moved to front is not on the top!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            showWindows(testWindow, showWindows, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            /////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            // Test that calling toFront() focuses the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            // when 'autoRequestFocus' is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            /////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            // Skip this stage for unfocusable window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            if (!testWindow.isFocusableWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            showWindows(testWindow, showWindows, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            pause(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            boolean gained = Util.trackWindowGainedFocus(testWindow, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                        testWindow.setAutoRequestFocus(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                        if (testSetVisible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                            setVisible(testWindow, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                            toFront(testWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                }, 1000, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            // Either the window or its owned window must be focused
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            if (!gained && !testButton.hasFocus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                throw new TestFailedException("the window should gain focus automatically but it didn't!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            showWindows(testWindow, showWindows, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        static void test(String msg, Button testButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            test(msg, testButton, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        private static void showWindows(Window win, Window[] wins, final boolean visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            pause(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            if (wins == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                wins = new Window[] {win}; // operate with 'win'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            for (final Window w: wins) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                if (visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    if ((w instanceof Dialog) && ((Dialog)w).isModal()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                        TestHelper.invokeLaterAndWait(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                                    w.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                            }, robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                        setVisible(w, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                    w.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            setVisible(auxFrame, visible);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            if (visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                if (!auxFrame.isFocused()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    Util.clickOnTitle(auxFrame, robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                    if (!auxFrame.isFocused()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                        throw new Error("Test error: the frame couldn't be focused.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    private static void setVisible(Window w, boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        w.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        } catch (RuntimeException rte) { // InfiniteLoop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            rte.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        robot.delay(200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    private static void toFront(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        w.toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        robot.delay(200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    private static void pause(int msec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if (haveDelays) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            robot.delay(msec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
class TestFailedException extends RuntimeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    TestFailedException(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        super("Test failed: " + msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425