Path: blob/master/test/jdk/java/awt/Frame/WindowDragTest/WindowDragTest.java
41154 views
/*1* Copyright (c) 2012, 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*/2223/**24* @test25* @key headful26* @bug 7128738 716175927* @summary dragged dialog freezes system on dispose28* @author Oleg Pekhovskiy: area=awt.toplevel29* @library ../../regtesthelpers30* @build Util31* @run main WindowDragTest32*/3334import java.awt.Frame;35import java.awt.event.InputEvent;36import java.awt.AWTException;37import test.java.awt.regtesthelpers.Util;38import java.awt.Robot;39import java.awt.Point;40import java.awt.Dimension;41import java.awt.event.MouseAdapter;42import java.awt.event.MouseEvent;4344public class WindowDragTest {4546static boolean passed = false;4748public static void main(String[] args) {49try {50Robot robot = new Robot();51robot.setAutoDelay(1000);5253Frame frame1 = new Frame();54frame1.setBounds(50, 50, 300, 200);55frame1.setVisible(true);56frame1.toFront();57frame1.addMouseListener(new MouseAdapter() {58@Override59public void mouseClicked(MouseEvent e) {60// Clicking frame1 succeeded - mouse is not captured61passed = true;62}63});64robot.delay(1000);6566Frame frame2 = new Frame();67frame2.setBounds(100, 100, 300, 200);68frame2.setVisible(true);69frame2.toFront();70robot.delay(1000);7172Point p = frame2.getLocationOnScreen();73Dimension d = frame2.getSize();7475// Move cursor to frame2 title bar to drag76robot.mouseMove(p.x + (int)(d.getWidth() / 2), p.y + (int)frame2.getInsets().top / 2);77Util.waitForIdle(robot);7879// Start window dragging80robot.mousePress(InputEvent.BUTTON1_MASK);81Util.waitForIdle(robot);8283// Dispose window being dragged84frame2.dispose();85Util.waitForIdle(robot);8687// Release mouse button to be able to get MOUSE_CLICKED event on Util.clickOnComp()88robot.mouseRelease(InputEvent.BUTTON1_MASK);89Util.waitForIdle(robot);9091// Click frame1 to check whether mouse is not captured by frame292Util.clickOnComp(frame1, robot);93Util.waitForIdle(robot);9495frame1.dispose();96if (passed) {97System.out.println("Test passed.");98}99else {100System.out.println("Test failed.");101throw new RuntimeException("Test failed.");102}103}104catch (AWTException e) {105throw new RuntimeException("AWTException occurred - problem creating robot!");106}107}108}109110111