Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Frame/WindowDragTest/WindowDragTest.java
38828 views
/*1* Copyright (c) 2012, 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*/2223/*24@test25@bug 7128738 716175926@summary dragged dialog freezes system on dispose27@author Oleg Pekhovskiy: area=awt.toplevel28@library ../../regtesthelpers29@build Util30@run main WindowDragTest31*/3233import java.awt.Frame;34import java.awt.event.InputEvent;35import java.awt.AWTException;36import test.java.awt.regtesthelpers.Util;37import java.awt.Robot;38import java.awt.Point;39import java.awt.Dimension;40import java.awt.event.MouseAdapter;41import java.awt.event.MouseEvent;4243public class WindowDragTest {4445static boolean passed = false;4647public static void main(String[] args) {48try {49Robot robot = new Robot();50robot.setAutoDelay(1000);5152Frame frame1 = new Frame();53frame1.setBounds(50, 50, 300, 200);54frame1.setVisible(true);55frame1.toFront();56frame1.addMouseListener(new MouseAdapter() {57@Override58public void mouseClicked(MouseEvent e) {59// Clicking frame1 succeeded - mouse is not captured60passed = true;61}62});63robot.delay(1000);6465Frame frame2 = new Frame();66frame2.setBounds(100, 100, 300, 200);67frame2.setVisible(true);68frame2.toFront();69robot.delay(1000);7071Point p = frame2.getLocationOnScreen();72Dimension d = frame2.getSize();7374// Move cursor to frame2 title bar to drag75robot.mouseMove(p.x + (int)(d.getWidth() / 2), p.y + (int)frame2.getInsets().top / 2);76Util.waitForIdle(robot);7778// Start window dragging79robot.mousePress(InputEvent.BUTTON1_MASK);80Util.waitForIdle(robot);8182// Dispose window being dragged83frame2.dispose();84Util.waitForIdle(robot);8586// Release mouse button to be able to get MOUSE_CLICKED event on Util.clickOnComp()87robot.mouseRelease(InputEvent.BUTTON1_MASK);88Util.waitForIdle(robot);8990// Click frame1 to check whether mouse is not captured by frame291Util.clickOnComp(frame1, robot);92Util.waitForIdle(robot);9394frame1.dispose();95if (passed) {96System.out.println("Test passed.");97}98else {99System.out.println("Test failed.");100throw new RuntimeException("Test failed.");101}102}103catch (AWTException e) {104throw new RuntimeException("AWTException occurred - problem creating robot!");105}106}107}108109110