Path: blob/master/test/jdk/java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java
41153 views
/*1* Copyright (c) 2013, 2017, 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.awt.event.MouseEvent;28import java.awt.event.MouseMotionAdapter;2930/**31* @test32* @key headful33* @bug 8012026 802715434* @summary Component.getMousePosition() does not work in an applet on MacOS35* @author Petr Pchelko36* @library ../../regtesthelpers37* @build Util38* @compile GetMousePositionWithPopup.java39* @run main/othervm GetMousePositionWithPopup40*/4142public class GetMousePositionWithPopup {4344private static Frame frame1;45private static Frame frame2;4647public static void main(String[] args) throws Exception {48try {49Robot r = Util.createRobot();50r.mouseMove(0, 0);51Util.waitForIdle(null);5253SwingUtilities.invokeAndWait(new Runnable() {54@Override55public void run() {56constructTestUI();57}58});5960Util.waitForIdle(null);61r.mouseMove(149, 149);62Util.waitForIdle(null);63r.mouseMove(150, 150);64Util.waitForIdle(null);6566} finally {67SwingUtilities.invokeLater(new Runnable() {68@Override69public void run() {70frame1.dispose();71frame2.dispose();72}73});74}75}7677private static void constructTestUI() {78frame1 = new Frame();79frame1.setBounds(100, 100, 100, 100);80frame1.addMouseMotionListener(new MouseMotionAdapter() {8182@Override83public void mouseMoved(MouseEvent e) {84frame2 = new Frame();85frame2.setBounds(120, 120, 120, 120);8687frame2.addMouseMotionListener(new MouseMotionAdapter() {88@Override89public void mouseMoved(MouseEvent e)90{91Point positionInFrame2 = frame2.getMousePosition();92if (positionInFrame2.x != 30 || positionInFrame2.y != 30) {93throw new RuntimeException("Wrong position reported. Should be [30, 30] but was [" +94positionInFrame2.x + ", " + positionInFrame2.y + "]");95}9697Point positionInFrame1 = frame1.getMousePosition();98if (positionInFrame1 != null) {99throw new RuntimeException("Wrong position reported. Should be null");100}101}102});103104frame2.setVisible(true);105}106});107frame1.setVisible(true);108}109}110111