4905N/A/*
5769N/A * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
4905N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4905N/A *
4905N/A * This code is free software; you can redistribute it and/or modify it
4905N/A * under the terms of the GNU General Public License version 2 only, as
4905N/A * published by the Free Software Foundation.
4905N/A *
4905N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4905N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4905N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4905N/A * version 2 for more details (a copy is included in the LICENSE file that
4905N/A * accompanied this code).
4905N/A *
4905N/A * You should have received a copy of the GNU General Public License version
4905N/A * 2 along with this work; if not, write to the Free Software Foundation,
4905N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4905N/A *
4905N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4905N/A * or visit www.oracle.com if you need additional information or have any
4905N/A * questions.
4905N/A */
4905N/A
4905N/A/*
4905N/A @test
5769N/A @bug 7128738 7161759
4905N/A @summary dragged dialog freezes system on dispose
4905N/A @author Oleg Pekhovskiy: area=awt.toplevel
4905N/A @library ../../regtesthelpers
5769N/A @build Util
4905N/A @run main WindowDragTest
4905N/A*/
4905N/A
4905N/Aimport java.awt.Frame;
4905N/Aimport java.awt.event.InputEvent;
4905N/Aimport java.awt.AWTException;
4905N/Aimport test.java.awt.regtesthelpers.Util;
4905N/Aimport java.awt.Robot;
4905N/Aimport java.awt.Point;
4905N/Aimport java.awt.Dimension;
4905N/Aimport java.awt.event.MouseAdapter;
4905N/Aimport java.awt.event.MouseEvent;
4905N/A
4905N/Apublic class WindowDragTest {
4905N/A
4905N/A static boolean passed = false;
4905N/A
4905N/A public static void main(String[] args) {
4905N/A try {
4905N/A Robot robot = new Robot();
4905N/A robot.setAutoDelay(1000);
4905N/A
4905N/A Frame frame1 = new Frame();
4905N/A frame1.setBounds(50, 50, 300, 200);
4905N/A frame1.setVisible(true);
4905N/A frame1.toFront();
4905N/A frame1.addMouseListener(new MouseAdapter() {
4905N/A @Override
4905N/A public void mouseClicked(MouseEvent e) {
4905N/A // Clicking frame1 succeeded - mouse is not captured
4905N/A passed = true;
4905N/A }
4905N/A });
4905N/A robot.delay(1000);
4905N/A
4905N/A Frame frame2 = new Frame();
4905N/A frame2.setBounds(100, 100, 300, 200);
4905N/A frame2.setVisible(true);
4905N/A frame2.toFront();
4905N/A robot.delay(1000);
4905N/A
4905N/A Point p = frame2.getLocationOnScreen();
4905N/A Dimension d = frame2.getSize();
4905N/A
4905N/A // Move cursor to frame2 title bar to drag
4905N/A robot.mouseMove(p.x + (int)(d.getWidth() / 2), p.y + (int)frame2.getInsets().top / 2);
4905N/A Util.waitForIdle(robot);
4905N/A
4905N/A // Start window dragging
4905N/A robot.mousePress(InputEvent.BUTTON1_MASK);
4905N/A Util.waitForIdle(robot);
4905N/A
4905N/A // Dispose window being dragged
4905N/A frame2.dispose();
4905N/A Util.waitForIdle(robot);
4905N/A
4905N/A // Release mouse button to be able to get MOUSE_CLICKED event on Util.clickOnComp()
4905N/A robot.mouseRelease(InputEvent.BUTTON1_MASK);
4905N/A Util.waitForIdle(robot);
4905N/A
4905N/A // Click frame1 to check whether mouse is not captured by frame2
4905N/A Util.clickOnComp(frame1, robot);
4905N/A Util.waitForIdle(robot);
4905N/A
4905N/A frame1.dispose();
4905N/A if (passed) {
4905N/A System.out.println("Test passed.");
4905N/A }
4905N/A else {
4905N/A System.out.println("Test failed.");
4905N/A throw new RuntimeException("Test failed.");
4905N/A }
4905N/A }
4905N/A catch (AWTException e) {
4905N/A throw new RuntimeException("AWTException occurred - problem creating robot!");
4905N/A }
4905N/A }
4905N/A}