jdk/test/java/awt/GraphicsDevice/IncorrectDisplayModeExitFullscreen.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 27763 1fba965925e8
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:
18758
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
     1
/*
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 27763
diff changeset
     2
 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
18758
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
     4
 *
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
     8
 *
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    13
 * accompanied this code).
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    14
 *
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    18
 *
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    21
 * questions.
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    22
 */
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    23
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    24
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    25
import java.awt.Color;
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    26
import java.awt.DisplayMode;
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    27
import java.awt.Frame;
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    28
import java.awt.GraphicsDevice;
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    29
import java.awt.GraphicsEnvironment;
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    30
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    31
/**
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    32
 * @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 27763
diff changeset
    33
 * @key headful
18758
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    34
 * @bug 8019587
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    35
 * @author Sergey Bylokhov
27763
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    36
 * @library ../../../lib/testlibrary/
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    37
 * @build ExtendedRobot
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    38
 * @run main IncorrectDisplayModeExitFullscreen
18758
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    39
 */
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    40
public class IncorrectDisplayModeExitFullscreen {
27763
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    41
    static ExtendedRobot robot;
18758
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    42
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    43
    public static void main(final String[] args) {
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    44
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    45
        final GraphicsDevice[] devices =
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    46
                GraphicsEnvironment.getLocalGraphicsEnvironment()
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    47
                                   .getScreenDevices();
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    48
        if (devices.length < 2 || devices[0].getDisplayModes().length < 2
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    49
                || !devices[0].isFullScreenSupported()
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    50
                || !devices[1].isFullScreenSupported()) {
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    51
            System.err.println("Testcase is not applicable");
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    52
            return;
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    53
        }
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    54
        final DisplayMode defaultDM = devices[0].getDisplayMode();
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    55
        final DisplayMode[] dms = devices[0].getDisplayModes();
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    56
        DisplayMode nonDefaultDM = null;
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    57
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    58
        for (final DisplayMode dm : dms) {
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    59
            if (!dm.equals(defaultDM)) {
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    60
                nonDefaultDM = dm;
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    61
                break;
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    62
            }
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    63
        }
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    64
        if (nonDefaultDM == null) {
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    65
            System.err.println("Testcase is not applicable");
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    66
            return;
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    67
        }
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    68
27763
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    69
        try {
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    70
            robot = new ExtendedRobot();
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    71
        }catch(Exception ex) {
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    72
            ex.printStackTrace();
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    73
            throw new RuntimeException("Unexpected failure");
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    74
        }
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    75
18758
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    76
        final Frame frame = new Frame();
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    77
        frame.setBackground(Color.GREEN);
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    78
        frame.setUndecorated(true);
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    79
        try {
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    80
            devices[0].setFullScreenWindow(frame);
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    81
            sleep();
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    82
            devices[0].setDisplayMode(nonDefaultDM);
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    83
            sleep();
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    84
            devices[1].setFullScreenWindow(frame);
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    85
            sleep();
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    86
            if (!defaultDM.equals(devices[0].getDisplayMode())) {
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    87
                throw new RuntimeException("DisplayMode is not restored");
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    88
            }
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    89
        } finally {
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    90
            // cleaning up
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    91
            devices[0].setFullScreenWindow(null);
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    92
            devices[1].setFullScreenWindow(null);
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    93
            frame.dispose();
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    94
        }
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    95
    }
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    96
    private static void sleep() {
27763
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    97
        robot.waitForIdle(1500);
18758
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    98
    }
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    99
}