jdk/test/java/awt/GraphicsDevice/IncorrectDisplayModeExitFullscreen.java
author katleman
Thu, 03 Sep 2015 14:24:43 -0700
changeset 32450 f036508e86e7
parent 27763 1fba965925e8
child 39056 d99e63b6d962
permissions -rw-r--r--
Added tag jdk9-b80 for changeset 56a580f0c008
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
/*
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
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
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    33
 * @bug 8019587
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    34
 * @author Sergey Bylokhov
27763
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    35
 * @library ../../../lib/testlibrary/
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    36
 * @build ExtendedRobot
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    37
 * @run main IncorrectDisplayModeExitFullscreen
18758
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    38
 */
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    39
public class IncorrectDisplayModeExitFullscreen {
27763
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    40
    static ExtendedRobot robot;
18758
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    41
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    42
    public static void main(final String[] args) {
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    43
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    44
        final GraphicsDevice[] devices =
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    45
                GraphicsEnvironment.getLocalGraphicsEnvironment()
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    46
                                   .getScreenDevices();
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    47
        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
    48
                || !devices[0].isFullScreenSupported()
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    49
                || !devices[1].isFullScreenSupported()) {
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    50
            System.err.println("Testcase is not applicable");
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    51
            return;
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    52
        }
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    53
        final DisplayMode defaultDM = devices[0].getDisplayMode();
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    54
        final DisplayMode[] dms = devices[0].getDisplayModes();
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    55
        DisplayMode nonDefaultDM = null;
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    56
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    57
        for (final DisplayMode dm : dms) {
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    58
            if (!dm.equals(defaultDM)) {
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    59
                nonDefaultDM = dm;
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    60
                break;
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    61
            }
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
        if (nonDefaultDM == null) {
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    64
            System.err.println("Testcase is not applicable");
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    65
            return;
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    66
        }
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    67
27763
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    68
        try {
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    69
            robot = new ExtendedRobot();
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    70
        }catch(Exception ex) {
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    71
            ex.printStackTrace();
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    72
            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
    73
        }
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 18758
diff changeset
    74
18758
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    75
        final Frame frame = new Frame();
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    76
        frame.setBackground(Color.GREEN);
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    77
        frame.setUndecorated(true);
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    78
        try {
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    79
            devices[0].setFullScreenWindow(frame);
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    80
            sleep();
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    81
            devices[0].setDisplayMode(nonDefaultDM);
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    82
            sleep();
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    83
            devices[1].setFullScreenWindow(frame);
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    84
            sleep();
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    85
            if (!defaultDM.equals(devices[0].getDisplayMode())) {
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    86
                throw new RuntimeException("DisplayMode is not restored");
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    87
            }
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    88
        } finally {
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    89
            // cleaning up
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    90
            devices[0].setFullScreenWindow(null);
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    91
            devices[1].setFullScreenWindow(null);
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    92
            frame.dispose();
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    93
        }
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
    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
    96
        robot.waitForIdle(1500);
18758
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    97
    }
15c2b5596c57 8019587: [macosx] Possibility to set the same frame for the different screens
serb
parents:
diff changeset
    98
}