test/jdk/java/awt/Focus/NonFocusableBlockedOwnerTest/NonFocusableBlockedOwnerTest.java
author serb
Sun, 24 Jun 2018 16:35:21 -0700
changeset 50834 9cf279436b9d
parent 47216 71c04702a3d5
child 54231 e4813eded7cb
permissions -rw-r--r--
8205153: Delete "standard instructions" machinery in the open automated tests Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29731
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
     1
/*
50834
9cf279436b9d 8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents: 47216
diff changeset
     2
 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
29731
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
     4
 *
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
     8
 *
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    13
 * accompanied this code).
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    14
 *
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    18
 *
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    21
 * questions.
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    22
 */
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    23
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    24
/*
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    25
  test
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    26
  @bug       6272324
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    27
  @summary   Modal excluded Window which decorated parent is blocked should be non-focusable.
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    28
  @author    anton.tarasov@sun.com: area=awt.focus
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    29
  @run       applet NonFocusableBlockedOwnerTest.html
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    30
*/
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    31
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    32
import java.applet.Applet;
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    33
import java.awt.*;
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    34
import java.awt.event.*;
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    35
import java.lang.reflect.*;
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    36
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    37
public class NonFocusableBlockedOwnerTest extends Applet {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    38
    Robot robot;
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    39
    Frame frame = new Frame("Modal Blocked Frame");
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    40
    Dialog dialog = new Dialog(frame, "Modal Dialog", true);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    41
    Window excluded = new Window(frame);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    42
    Button button = new Button("button");
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    43
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    44
    public static void main(String[] args) {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    45
        NonFocusableBlockedOwnerTest app = new NonFocusableBlockedOwnerTest();
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    46
        app.init();
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    47
        app.start();
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    48
    }
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    49
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    50
    public void init() {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    51
        try {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    52
            robot = new Robot();
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    53
        } catch (AWTException e) {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    54
            throw new RuntimeException("Error: unable to create robot", e);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    55
        }
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    56
        // Create instructions for the user here, as well as set up
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    57
        // the environment -- set the layout manager, add buttons,
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    58
        // etc.
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    59
        this.setLayout (new BorderLayout ());
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    60
    }
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    61
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    62
    public void start() {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    63
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    64
        if ("sun.awt.motif.MToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) {
50834
9cf279436b9d 8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents: 47216
diff changeset
    65
            System.out.println("No testing on MToolkit.");
29731
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    66
            return;
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    67
        }
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    68
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    69
        try {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    70
            EventQueue.invokeLater(new Runnable() {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    71
                public void run() {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    72
                    frame.setSize(300, 200);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    73
                    frame.setVisible(true);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    74
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    75
                    excluded.setSize(300, 200);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    76
                    excluded.setLocation(0, 400);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    77
                    excluded.setModalExclusionType(Dialog.ModalExclusionType.TOOLKIT_EXCLUDE);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    78
                    excluded.setLayout(new FlowLayout());
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    79
                    excluded.add(button);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    80
                    excluded.setVisible(true);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    81
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    82
                    dialog.setSize(200, 100);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    83
                    dialog.setLocation(0, 250);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    84
                    dialog.setVisible(true);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    85
                }
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    86
            });
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    87
        } catch (Exception e) {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    88
            e.printStackTrace();
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    89
        }
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    90
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    91
        waitTillShown(dialog);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    92
        clickOn(button);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    93
        if (frame == KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow()) {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    94
            throw new RuntimeException("Test failed!");
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    95
        }
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    96
        if (excluded == KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow()) {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    97
            throw new RuntimeException("Test failed!");
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    98
        }
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
    99
        if (button == KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   100
            throw new RuntimeException("Test failed!");
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   101
        }
50834
9cf279436b9d 8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents: 47216
diff changeset
   102
        System.out.println("Test passed.");
29731
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   103
    }
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   104
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   105
    void clickOn(Component c) {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   106
        Point p = c.getLocationOnScreen();
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   107
        Dimension d = c.getSize();
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   108
50834
9cf279436b9d 8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents: 47216
diff changeset
   109
        System.out.println("Clicking " + c);
29731
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   110
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   111
        if (c instanceof Frame) {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   112
            robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + ((Frame)c).getInsets().top/2);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   113
        } else {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   114
            robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + (int)(d.getHeight()/2));
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   115
        }
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   116
        robot.mousePress(InputEvent.BUTTON1_MASK);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   117
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   118
        waitForIdle();
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   119
    }
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   120
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   121
    void waitTillShown(Component c) {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   122
        while (true) {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   123
            try {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   124
                Thread.sleep(100);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   125
                c.getLocationOnScreen();
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   126
                break;
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   127
            } catch (InterruptedException e) {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   128
                throw new RuntimeException(e);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   129
            } catch (IllegalComponentStateException e) {}
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   130
        }
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   131
    }
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   132
    void waitForIdle() {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   133
        try {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   134
            robot.waitForIdle();
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   135
            EventQueue.invokeAndWait( new Runnable() {
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   136
                    public void run() {} // Dummy implementation
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   137
                });
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   138
        } catch(InterruptedException ie) {
50834
9cf279436b9d 8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents: 47216
diff changeset
   139
            System.out.println("waitForIdle, non-fatal exception caught:");
29731
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   140
            ie.printStackTrace();
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   141
        } catch(InvocationTargetException ite) {
50834
9cf279436b9d 8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents: 47216
diff changeset
   142
            System.out.println("waitForIdle, non-fatal exception caught:");
29731
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   143
            ite.printStackTrace();
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   144
        }
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   145
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   146
        // wait longer...
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   147
        robot.delay(200);
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   148
    }
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents:
diff changeset
   149
}