Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.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.awt.event.MouseEvent;28import java.awt.event.MouseMotionAdapter;2930/**31* @test32* @bug 801202633* @summary Component.getMousePosition() does not work in an applet on MacOS34* @author Petr Pchelko35* @library ../../regtesthelpers36* @build Util37* @compile GetMousePositionWithPopup.java38* @run main/othervm GetMousePositionWithPopup39*/4041public class GetMousePositionWithPopup {4243private static Frame frame1;44private static Frame frame2;4546public static void main(String[] args) throws Exception {47try {48Robot r = Util.createRobot();49r.mouseMove(0, 0);50Util.waitForIdle(null);5152SwingUtilities.invokeAndWait(new Runnable() {53@Override54public void run() {55constructTestUI();56}57});5859Util.waitForIdle(null);60r.mouseMove(149, 149);61Util.waitForIdle(null);62r.mouseMove(150, 150);63Util.waitForIdle(null);6465} finally {66SwingUtilities.invokeLater(new Runnable() {67@Override68public void run() {69frame1.dispose();70frame2.dispose();71}72});73}74}7576private static void constructTestUI() {77frame1 = new Frame();78frame1.setBounds(100, 100, 100, 100);79frame1.addMouseMotionListener(new MouseMotionAdapter() {8081private boolean shown = false;8283@Override84public void mouseMoved(MouseEvent e) {85if (shown) {86return;87}8889shown = true;9091frame2 = new Frame();92frame2.setBounds(120, 120, 120, 120);93frame2.setVisible(true);9495Point positionInFrame2 = frame2.getMousePosition();96if (positionInFrame2.x != 30 || positionInFrame2.y != 30) {97throw new RuntimeException("Wrong position reported. Should be [30, 30] but was [" +98positionInFrame2.x + ", " + positionInFrame2.y + "]");99}100101Point positionInFrame1 = frame1.getMousePosition();102if (positionInFrame1 != null) {103throw new RuntimeException("Wrong position reported. Should be null");104}105106}107});108frame1.setVisible(true);109}110}111112113