jdk/test/java/awt/Modal/ModalDialogOrderingTest/ModalDialogOrderingTest.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 28087 622b2f420bc3
permissions -rw-r--r--
8159690: [TESTBUG] Mark headful tests with @key headful. Reviewed-by: simonis, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20135
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
     1
/*
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 28087
diff changeset
     2
 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
20135
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
     4
 *
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
     8
 *
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    13
 * accompanied this code).
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    14
 *
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    18
 *
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    21
 * questions.
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    22
 */
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    23
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    24
import java.awt.Color;
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    25
import java.awt.Dialog;
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    26
import java.awt.Frame;
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    27
import java.awt.Rectangle;
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    28
import java.awt.Robot;
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    29
import java.awt.Toolkit;
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    30
import java.awt.event.InputEvent;
21798
f4ab67a9cd68 8029024: [TEST_BUG] java/awt/Modal/ModalDialogOrderingTest/ModalDialogOrderingTest.java fails
serb
parents: 20135
diff changeset
    31
f4ab67a9cd68 8029024: [TEST_BUG] java/awt/Modal/ModalDialogOrderingTest/ModalDialogOrderingTest.java fails
serb
parents: 20135
diff changeset
    32
/**
20135
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    33
 * @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 28087
diff changeset
    34
 * @key headful
20135
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    35
 * @bug 8008728
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    36
 * @summary [macosx] Swing. JDialog. Modal dialog goes to background
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    37
 * @author Alexandr Scherbatiy
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21798
diff changeset
    38
 * @library ../../../../lib/testlibrary
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21798
diff changeset
    39
 * @build ExtendedRobot
20135
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    40
 * @run main ModalDialogOrderingTest
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    41
 */
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    42
public class ModalDialogOrderingTest {
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    43
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    44
    private static final Color DIALOG_COLOR = Color.GREEN;
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    45
    private static final Color FRAME_COLOR = Color.BLUE;
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    46
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    47
    public static void main(String[] args) {
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    48
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    49
        final Frame frame = new Frame("Test");
21798
f4ab67a9cd68 8029024: [TEST_BUG] java/awt/Modal/ModalDialogOrderingTest/ModalDialogOrderingTest.java fails
serb
parents: 20135
diff changeset
    50
        frame.setSize(400, 400);
20135
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    51
        frame.setBackground(FRAME_COLOR);
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    52
        frame.setVisible(true);
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    53
21798
f4ab67a9cd68 8029024: [TEST_BUG] java/awt/Modal/ModalDialogOrderingTest/ModalDialogOrderingTest.java fails
serb
parents: 20135
diff changeset
    54
        final Dialog modalDialog = new Dialog(null, true);
20135
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    55
        modalDialog.setTitle("Modal Dialog");
21798
f4ab67a9cd68 8029024: [TEST_BUG] java/awt/Modal/ModalDialogOrderingTest/ModalDialogOrderingTest.java fails
serb
parents: 20135
diff changeset
    56
        modalDialog.setSize(400, 200);
20135
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    57
        modalDialog.setBackground(DIALOG_COLOR);
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    58
        modalDialog.setModal(true);
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    59
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    60
        new Thread(new Runnable() {
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    61
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    62
            @Override
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    63
            public void run() {
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    64
                runTest(modalDialog, frame);
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    65
            }
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    66
        }).start();
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    67
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    68
        modalDialog.setVisible(true);
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    69
    }
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    70
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    71
    private static void runTest(Dialog dialog, Frame frame) {
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    72
        try {
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21798
diff changeset
    73
            ExtendedRobot robot = new ExtendedRobot();
21798
f4ab67a9cd68 8029024: [TEST_BUG] java/awt/Modal/ModalDialogOrderingTest/ModalDialogOrderingTest.java fails
serb
parents: 20135
diff changeset
    74
            robot.setAutoDelay(50);
20135
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    75
            robot.mouseMove(300, 300);
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    76
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    77
            while (!dialog.isVisible()) {
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21798
diff changeset
    78
                robot.waitForIdle(1000);
20135
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    79
            }
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    80
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    81
            Rectangle dialogBounds = dialog.getBounds();
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    82
            Rectangle frameBounds = frame.getBounds();
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    83
21798
f4ab67a9cd68 8029024: [TEST_BUG] java/awt/Modal/ModalDialogOrderingTest/ModalDialogOrderingTest.java fails
serb
parents: 20135
diff changeset
    84
            int y1 = dialogBounds.y + dialogBounds.height;
f4ab67a9cd68 8029024: [TEST_BUG] java/awt/Modal/ModalDialogOrderingTest/ModalDialogOrderingTest.java fails
serb
parents: 20135
diff changeset
    85
            int y2 = frameBounds.y + frameBounds.height;
20135
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    86
21798
f4ab67a9cd68 8029024: [TEST_BUG] java/awt/Modal/ModalDialogOrderingTest/ModalDialogOrderingTest.java fails
serb
parents: 20135
diff changeset
    87
            int clickX = frameBounds.x + frameBounds.width / 2;
f4ab67a9cd68 8029024: [TEST_BUG] java/awt/Modal/ModalDialogOrderingTest/ModalDialogOrderingTest.java fails
serb
parents: 20135
diff changeset
    88
            int clickY = y1 + (y2 - y1) / 2;
20135
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    89
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    90
            robot.mouseMove(clickX, clickY);
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    91
            robot.mousePress(InputEvent.BUTTON1_MASK);
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    92
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21798
diff changeset
    93
            robot.waitForIdle(1000);
20135
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    94
21798
f4ab67a9cd68 8029024: [TEST_BUG] java/awt/Modal/ModalDialogOrderingTest/ModalDialogOrderingTest.java fails
serb
parents: 20135
diff changeset
    95
            int colorX = dialogBounds.x + dialogBounds.width / 2;
f4ab67a9cd68 8029024: [TEST_BUG] java/awt/Modal/ModalDialogOrderingTest/ModalDialogOrderingTest.java fails
serb
parents: 20135
diff changeset
    96
            int colorY = dialogBounds.y + dialogBounds.height / 2;
20135
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    97
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    98
            Color color = robot.getPixelColor(colorX, colorY);
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
    99
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
   100
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
   101
            if (!DIALOG_COLOR.equals(color)) {
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
   102
                throw new RuntimeException("The frame is on top"
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
   103
                        + " of the modal dialog!");
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21798
diff changeset
   104
            }else{
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21798
diff changeset
   105
                frame.dispose();
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21798
diff changeset
   106
                dialog.dispose();
20135
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
   107
            }
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
   108
        } catch (Exception ex) {
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
   109
            throw new RuntimeException(ex);
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
   110
        }
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
   111
    }
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents:
diff changeset
   112
}