test/jdk/java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java
author pkbalakr
Wed, 07 Mar 2018 16:52:19 +0530
changeset 49222 eb15e0ca2208
parent 47216 71c04702a3d5
permissions -rw-r--r--
8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails Reviewed-by: mhalder, ssadetsky, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20134
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
     1
/*
49222
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
     2
 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
20134
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
     4
 *
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
     8
 *
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    13
 * accompanied this code).
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    14
 *
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    18
 *
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    21
 * questions.
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    22
 */
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    23
49222
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    24
import java.awt.Frame;
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    25
import java.awt.Point;
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    26
import java.awt.Robot;
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    27
import java.awt.Rectangle;
20134
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    28
49222
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    29
/*
20134
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    30
 * @test
40128
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 20134
diff changeset
    31
 * @key headful
49222
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    32
 * @bug 8012026 8196435
20134
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    33
 * @summary Component.getMousePosition() does not work in an applet on MacOS
49222
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    34
 * @run main GetMousePositionWithOverlay
20134
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    35
 */
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    36
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    37
public class GetMousePositionWithOverlay {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    38
49222
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    39
    private static Frame backFrame;
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    40
    private static Frame frontFrame;
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    41
    private static Robot robot;
20134
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    42
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    43
    public static void main(String[] args) throws Throwable {
49222
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    44
        robot = new Robot();
20134
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    45
49222
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    46
        try{
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    47
            constructTestUI();
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    48
        } catch (Exception e) {
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    49
            dispose();
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    50
            throw new RuntimeException("Unexpected Exception!");
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    51
        }
20134
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    52
49222
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    53
        robot.waitForIdle();
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    54
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    55
        doTest();
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    56
        dispose();
20134
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    57
    }
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    58
49222
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    59
    private static void doTest() {
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    60
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    61
        frontFrame.toFront();
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    62
        robot.waitForIdle();
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    63
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    64
        Rectangle bounds = new Rectangle(frontFrame.getLocationOnScreen(), frontFrame.getSize());
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    65
        robot.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    66
        robot.waitForIdle();
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    67
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    68
        Point pos = backFrame.getMousePosition();
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    69
        if (pos != null) {
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    70
            dispose();
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    71
            throw new RuntimeException("Test failed. Mouse position should be null but was " + pos);
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    72
        }
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    73
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    74
        pos = frontFrame.getMousePosition();
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    75
        if (pos == null) {
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    76
            dispose();
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    77
            throw new RuntimeException("Test failed. Mouse position should not be null");
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    78
        }
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    79
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    80
        robot.mouseMove(189, 189);
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    81
        robot.waitForIdle();
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    82
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    83
        pos = backFrame.getMousePosition();
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    84
        if (pos == null) {
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    85
            dispose();
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    86
            throw new RuntimeException("Test failed. Mouse position should not be null");
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    87
        }
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    88
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    89
    }
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    90
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    91
    private static void dispose() {
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    92
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    93
        if (backFrame != null) {
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    94
            backFrame.dispose();
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    95
        }
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    96
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    97
        if (frontFrame != null) {
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    98
            frontFrame.dispose();
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
    99
        }
20134
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   100
    }
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   101
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   102
    private static void constructTestUI() {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   103
        backFrame = new Frame();
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   104
        backFrame.setBounds(100, 100, 100, 100);
49222
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
   105
        backFrame.setResizable(false);
20134
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   106
        backFrame.setVisible(true);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   107
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   108
        frontFrame = new Frame();
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   109
        frontFrame.setBounds(120, 120, 60, 60);
49222
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
   110
        frontFrame.setResizable(false);
20134
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   111
        frontFrame.setVisible(true);
49222
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
   112
20134
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   113
    }
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   114
}
49222
eb15e0ca2208 8196435: Regression automated Test 'java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java' fails
pkbalakr
parents: 47216
diff changeset
   115