Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java
47525 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import test.java.awt.regtesthelpers.Util;2425import javax.swing.*;26import java.awt.*;27import java.util.concurrent.atomic.AtomicReference;2829/**30* @test31* @bug 801202632* @summary Component.getMousePosition() does not work in an applet on MacOS33* @author Petr Pchelko34* @library ../../regtesthelpers35* @build Util36* @compile GetMousePositionWithOverlay.java37* @run main/othervm GetMousePositionWithOverlay38*/3940public class GetMousePositionWithOverlay {4142static Frame backFrame;43static Frame frontFrame;4445public static void main(String[] args) throws Throwable {46try {47SwingUtilities.invokeAndWait(new Runnable() {48@Override49public void run() {50constructTestUI();51}52});53Util.waitForIdle(null);5455Robot r = new Robot();56Util.pointOnComp(frontFrame, r);57Util.waitForIdle(null);5859Point pos = getMousePosition(backFrame);60if (pos != null) {61throw new RuntimeException("Test failed. Mouse position should be null but was" + pos);62}6364pos = getMousePosition(frontFrame);65if (pos == null) {66throw new RuntimeException("Test failed. Mouse position should not be null");67}6869r.mouseMove(189, 189);70Util.waitForIdle(null);7172pos = getMousePosition(backFrame);73if (pos == null) {74throw new RuntimeException("Test failed. Mouse position should not be null");75}76} finally {77SwingUtilities.invokeLater(new Runnable() {78@Override79public void run() {80backFrame.dispose();81frontFrame.dispose();82}83});84}85}8687private static Point getMousePosition(final Component component) throws Exception {88final AtomicReference<Point> pos = new AtomicReference<Point>();89SwingUtilities.invokeAndWait(new Runnable() {90@Override91public void run() {92pos.set(component.getMousePosition());93}94});95return pos.get();96}9798private static void constructTestUI() {99backFrame = new Frame();100backFrame.setBounds(100, 100, 100, 100);101backFrame.setVisible(true);102103frontFrame = new Frame();104frontFrame.setBounds(120, 120, 60, 60);105frontFrame.setVisible(true);106}107}108109110