jdk/test/java/awt/Frame/WindowDragTest/WindowDragTest.java
author vlivanov
Wed, 02 Mar 2016 15:42:03 +0300
changeset 36349 6cc8e6f596b2
parent 15635 1bb3df084c72
child 46151 5fa789776f7d
permissions -rw-r--r--
8151020: [TESTBUG] UnsafeGetStableArrayElement::testL_* fail intermittently Reviewed-by: zmajo, shade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12175
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
     1
/*
15635
1bb3df084c72 7161759: TEST_BUG: java/awt/Frame/WindowDragTest/WindowDragTest.java fails to compile, should be modified
kshefov
parents: 12175
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
12175
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
     4
 *
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
     8
 *
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    13
 * accompanied this code).
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    14
 *
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    18
 *
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    21
 * questions.
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    22
 */
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    23
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    24
/*
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    25
  @test
15635
1bb3df084c72 7161759: TEST_BUG: java/awt/Frame/WindowDragTest/WindowDragTest.java fails to compile, should be modified
kshefov
parents: 12175
diff changeset
    26
  @bug 7128738 7161759
12175
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    27
  @summary dragged dialog freezes system on dispose
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    28
  @author Oleg Pekhovskiy: area=awt.toplevel
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    29
  @library ../../regtesthelpers
15635
1bb3df084c72 7161759: TEST_BUG: java/awt/Frame/WindowDragTest/WindowDragTest.java fails to compile, should be modified
kshefov
parents: 12175
diff changeset
    30
  @build Util
12175
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    31
  @run main WindowDragTest
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    32
*/
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    33
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    34
import java.awt.Frame;
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    35
import java.awt.event.InputEvent;
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    36
import java.awt.AWTException;
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    37
import test.java.awt.regtesthelpers.Util;
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    38
import java.awt.Robot;
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    39
import java.awt.Point;
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    40
import java.awt.Dimension;
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    41
import java.awt.event.MouseAdapter;
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    42
import java.awt.event.MouseEvent;
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    43
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    44
public class WindowDragTest {
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    45
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    46
    static boolean passed = false;
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    47
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    48
    public static void main(String[] args) {
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    49
        try {
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    50
            Robot robot = new Robot();
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    51
            robot.setAutoDelay(1000);
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    52
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    53
            Frame frame1 = new Frame();
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    54
            frame1.setBounds(50, 50, 300, 200);
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    55
            frame1.setVisible(true);
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    56
            frame1.toFront();
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    57
            frame1.addMouseListener(new MouseAdapter() {
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    58
                @Override
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    59
                public void mouseClicked(MouseEvent e) {
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    60
                    // Clicking frame1 succeeded - mouse is not captured
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    61
                    passed = true;
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    62
                }
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    63
            });
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    64
            robot.delay(1000);
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    65
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    66
            Frame frame2 = new Frame();
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    67
            frame2.setBounds(100, 100, 300, 200);
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    68
            frame2.setVisible(true);
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    69
            frame2.toFront();
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    70
            robot.delay(1000);
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    71
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    72
            Point p = frame2.getLocationOnScreen();
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    73
            Dimension d = frame2.getSize();
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    74
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    75
            // Move cursor to frame2 title bar to drag
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    76
            robot.mouseMove(p.x + (int)(d.getWidth() / 2), p.y + (int)frame2.getInsets().top / 2);
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    77
            Util.waitForIdle(robot);
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    78
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    79
            // Start window dragging
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    80
            robot.mousePress(InputEvent.BUTTON1_MASK);
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    81
            Util.waitForIdle(robot);
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    82
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    83
            // Dispose window being dragged
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    84
            frame2.dispose();
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    85
            Util.waitForIdle(robot);
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    86
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    87
            // Release mouse button to be able to get MOUSE_CLICKED event on Util.clickOnComp()
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    88
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    89
            Util.waitForIdle(robot);
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    90
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    91
            // Click frame1 to check whether mouse is not captured by frame2
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    92
            Util.clickOnComp(frame1, robot);
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    93
            Util.waitForIdle(robot);
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    94
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    95
            frame1.dispose();
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    96
            if (passed) {
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    97
                System.out.println("Test passed.");
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    98
            }
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
    99
            else {
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
   100
                System.out.println("Test failed.");
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
   101
                throw new RuntimeException("Test failed.");
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
   102
            }
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
   103
        }
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
   104
        catch (AWTException e) {
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
   105
            throw new RuntimeException("AWTException occurred - problem creating robot!");
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
   106
        }
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
   107
    }
e832f6ea56e5 7128738: dragged dialog freezes system on dispose
bagiras
parents:
diff changeset
   108
}