test/jdk/java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java
author jdv
Wed, 15 May 2019 10:10:53 +0530
branchmetal-prototype-branch
changeset 57357 f3beca8f19fc
parent 47216 71c04702a3d5
permissions -rw-r--r--
Merge
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
/*
47167
6141bf8d9d85 8027154: [TESTBUG] Test java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java fails
pkbalakr
parents: 40128
diff changeset
     2
 * Copyright (c) 2013, 2017, 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
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    24
import test.java.awt.regtesthelpers.Util;
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    25
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    26
import javax.swing.*;
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    27
import java.awt.*;
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    28
import java.awt.event.MouseEvent;
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    29
import java.awt.event.MouseMotionAdapter;
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    30
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    31
/**
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    32
 * @test
40128
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 20134
diff changeset
    33
 * @key headful
47167
6141bf8d9d85 8027154: [TESTBUG] Test java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java fails
pkbalakr
parents: 40128
diff changeset
    34
 * @bug 8012026 8027154
20134
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    35
 * @summary Component.getMousePosition() does not work in an applet on MacOS
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    36
 * @author Petr Pchelko
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    37
 * @library ../../regtesthelpers
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    38
 * @build Util
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    39
 * @compile GetMousePositionWithPopup.java
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    40
 * @run main/othervm GetMousePositionWithPopup
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    41
 */
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 class GetMousePositionWithPopup {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    44
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    45
    private static Frame frame1;
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    46
    private static Frame frame2;
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    47
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    48
    public static void main(String[] args) throws Exception {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    49
        try {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    50
        Robot r = Util.createRobot();
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    51
        r.mouseMove(0, 0);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    52
        Util.waitForIdle(null);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    53
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    54
        SwingUtilities.invokeAndWait(new Runnable() {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    55
            @Override
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    56
            public void run() {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    57
                constructTestUI();
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    58
            }
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    59
        });
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    60
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    61
        Util.waitForIdle(null);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    62
        r.mouseMove(149, 149);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    63
        Util.waitForIdle(null);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    64
        r.mouseMove(150, 150);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    65
        Util.waitForIdle(null);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    66
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    67
        } finally {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    68
            SwingUtilities.invokeLater(new Runnable() {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    69
                @Override
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    70
                public void run() {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    71
                    frame1.dispose();
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    72
                    frame2.dispose();
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    73
                }
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    74
            });
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    75
        }
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    76
    }
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    77
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    78
    private static void constructTestUI() {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    79
        frame1 = new Frame();
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    80
        frame1.setBounds(100, 100, 100, 100);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    81
        frame1.addMouseMotionListener(new MouseMotionAdapter() {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    82
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    83
            @Override
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    84
            public void mouseMoved(MouseEvent e) {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    85
                frame2 = new Frame();
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    86
                frame2.setBounds(120, 120, 120, 120);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    87
47167
6141bf8d9d85 8027154: [TESTBUG] Test java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java fails
pkbalakr
parents: 40128
diff changeset
    88
                frame2.addMouseMotionListener(new MouseMotionAdapter() {
6141bf8d9d85 8027154: [TESTBUG] Test java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java fails
pkbalakr
parents: 40128
diff changeset
    89
                    @Override
6141bf8d9d85 8027154: [TESTBUG] Test java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java fails
pkbalakr
parents: 40128
diff changeset
    90
                    public void mouseMoved(MouseEvent e)
6141bf8d9d85 8027154: [TESTBUG] Test java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java fails
pkbalakr
parents: 40128
diff changeset
    91
                    {
6141bf8d9d85 8027154: [TESTBUG] Test java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java fails
pkbalakr
parents: 40128
diff changeset
    92
                        Point positionInFrame2 = frame2.getMousePosition();
6141bf8d9d85 8027154: [TESTBUG] Test java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java fails
pkbalakr
parents: 40128
diff changeset
    93
                        if (positionInFrame2.x != 30 || positionInFrame2.y != 30) {
6141bf8d9d85 8027154: [TESTBUG] Test java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java fails
pkbalakr
parents: 40128
diff changeset
    94
                            throw new RuntimeException("Wrong position reported. Should be [30, 30] but was [" +
6141bf8d9d85 8027154: [TESTBUG] Test java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java fails
pkbalakr
parents: 40128
diff changeset
    95
                                    positionInFrame2.x + ", " + positionInFrame2.y + "]");
6141bf8d9d85 8027154: [TESTBUG] Test java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java fails
pkbalakr
parents: 40128
diff changeset
    96
                        }
20134
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    97
47167
6141bf8d9d85 8027154: [TESTBUG] Test java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java fails
pkbalakr
parents: 40128
diff changeset
    98
                        Point positionInFrame1 = frame1.getMousePosition();
6141bf8d9d85 8027154: [TESTBUG] Test java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java fails
pkbalakr
parents: 40128
diff changeset
    99
                        if (positionInFrame1 != null) {
6141bf8d9d85 8027154: [TESTBUG] Test java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java fails
pkbalakr
parents: 40128
diff changeset
   100
                            throw new RuntimeException("Wrong position reported. Should be null");
6141bf8d9d85 8027154: [TESTBUG] Test java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java fails
pkbalakr
parents: 40128
diff changeset
   101
                        }
6141bf8d9d85 8027154: [TESTBUG] Test java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java fails
pkbalakr
parents: 40128
diff changeset
   102
                    }
6141bf8d9d85 8027154: [TESTBUG] Test java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java fails
pkbalakr
parents: 40128
diff changeset
   103
                });
20134
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   104
47167
6141bf8d9d85 8027154: [TESTBUG] Test java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java fails
pkbalakr
parents: 40128
diff changeset
   105
                frame2.setVisible(true);
20134
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   106
            }
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
        frame1.setVisible(true);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   109
    }
47167
6141bf8d9d85 8027154: [TESTBUG] Test java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java fails
pkbalakr
parents: 40128
diff changeset
   110
}