jdk/test/java/awt/Mouse/MouseWheelAbsXY/MouseWheelAbsXY.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 32295 5ba453554637
permissions -rw-r--r--
8159690: [TESTBUG] Mark headful tests with @key headful. Reviewed-by: simonis, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32295
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
     1
/*
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
     4
 *
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
     8
 *
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    13
 * accompanied this code).
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    14
 *
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    18
 *
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    21
 * questions.
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    22
 */
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    23
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    24
import java.awt.AWTException;
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    25
import java.awt.Frame;
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    26
import java.awt.GraphicsConfiguration;
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    27
import java.awt.GraphicsDevice;
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    28
import java.awt.GraphicsEnvironment;
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    29
import java.awt.Robot;
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    30
import java.awt.Window;
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    31
import java.awt.event.InputEvent;
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    32
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    33
import static java.awt.GraphicsEnvironment.*;
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    34
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    35
/**
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    36
 * @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 32295
diff changeset
    37
 * @key headful
32295
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    38
 * @bug 6778087
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    39
 */
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    40
public final class MouseWheelAbsXY {
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    41
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    42
    private static boolean done;
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    43
    private static int wheelX;
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    44
    private static int wheelY;
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    45
    private static int mouseX;
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    46
    private static int mouseY;
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    47
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    48
    public static void main(final String[] args) throws AWTException {
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    49
        GraphicsEnvironment ge = getLocalGraphicsEnvironment();
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    50
        GraphicsDevice[] sds = ge.getScreenDevices();
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    51
        for (GraphicsDevice gd : sds) {
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    52
            test(gd.getDefaultConfiguration());
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    53
        }
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    54
    }
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    55
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    56
    private static void test(GraphicsConfiguration gc) throws AWTException {
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    57
        final Window frame = new Frame(gc);
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    58
        try {
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    59
            frame.addMouseWheelListener(e -> {
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    60
                wheelX = e.getXOnScreen();
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    61
                wheelY = e.getYOnScreen();
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    62
                done = true;
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    63
            });
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    64
            frame.setSize(300, 300);
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    65
            frame.setVisible(true);
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    66
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    67
            final Robot robot = new Robot();
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    68
            robot.setAutoDelay(50);
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    69
            robot.setAutoWaitForIdle(true);
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    70
            mouseX = frame.getX() + frame.getWidth() / 2;
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    71
            mouseY = frame.getY() + frame.getHeight() / 2;
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    72
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    73
            robot.mouseMove(mouseX, mouseY);
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    74
            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    75
            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    76
            robot.mouseWheel(10);
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    77
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    78
            validate();
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    79
        } finally {
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    80
            frame.dispose();
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    81
        }
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    82
    }
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    83
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    84
    private static void validate() {
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    85
        if (!done || wheelX != mouseX || wheelY != mouseY) {
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    86
            System.err.println("Expected X: " + mouseX);
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    87
            System.err.println("Expected Y: " + mouseY);
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    88
            System.err.println("Actual X: " + wheelX);
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    89
            System.err.println("Actual Y: " + wheelY);
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    90
            throw new RuntimeException("Test failed");
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    91
        }
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    92
    }
5ba453554637 6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
diff changeset
    93
}