jdk/test/java/awt/FullScreen/8013581/bug8013581.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:
21282
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
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.
21282
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
     4
 *
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
     8
 *
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    13
 * accompanied this code).
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    14
 *
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    18
 *
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    21
 * questions.
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    22
 */
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    23
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    24
/*
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    25
 * @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 28087
diff changeset
    26
 * @key headful
21282
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    27
 * @bug 8013581
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    28
 * @summary [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    29
 * @author leonid.romanov@oracle.com
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    30
 * @run main bug8013581
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    31
 */
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    32
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    33
import java.awt.*;
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    34
import java.awt.event.*;
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    35
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    36
public class bug8013581 {
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    37
    private static Frame frame;
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    38
    private static volatile int listenerCallCounter = 0;
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    39
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    40
    public static void main(String[] args) throws Exception {
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    41
        final GraphicsEnvironment ge = GraphicsEnvironment
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    42
                .getLocalGraphicsEnvironment();
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    43
        final GraphicsDevice[] devices = ge.getScreenDevices();
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    44
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    45
        final Robot robot = new Robot();
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    46
        robot.setAutoDelay(50);
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    47
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    48
        createAndShowGUI();
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21282
diff changeset
    49
        robot.waitForIdle();
21282
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    50
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    51
        Exception error = null;
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    52
        for (final GraphicsDevice device : devices) {
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    53
            if (!device.isFullScreenSupported()) {
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    54
                continue;
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    55
            }
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    56
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    57
            device.setFullScreenWindow(frame);
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21282
diff changeset
    58
            sleep(robot);
21282
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    59
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    60
            robot.keyPress(KeyEvent.VK_A);
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    61
            robot.keyRelease(KeyEvent.VK_A);
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21282
diff changeset
    62
            robot.waitForIdle();
21282
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    63
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    64
            device.setFullScreenWindow(null);
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21282
diff changeset
    65
            sleep(robot);
21282
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    66
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    67
            if (listenerCallCounter != 2) {
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    68
                error = new Exception("Test failed: KeyListener called " + listenerCallCounter + " times instead of 2!");
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    69
                break;
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    70
            }
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    71
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    72
            listenerCallCounter = 0;
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    73
        }
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    74
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    75
        frame.dispose();
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    76
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    77
        if (error != null) {
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    78
            throw error;
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    79
        }
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    80
     }
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    81
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    82
    private static void createAndShowGUI() {
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    83
        frame = new Frame("Test");
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    84
        frame.addKeyListener(new KeyAdapter() {
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    85
            @Override
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    86
            public void keyPressed(KeyEvent e) {
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    87
                listenerCallCounter++;
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    88
            }
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    89
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    90
            @Override
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    91
            public void keyReleased(KeyEvent e) {
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    92
                listenerCallCounter++;
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    93
            }
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    94
        });
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    95
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    96
        frame.setUndecorated(true);
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    97
        frame.setVisible(true);
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    98
    }
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
    99
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21282
diff changeset
   100
    private static void sleep(Robot robot) {
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21282
diff changeset
   101
        robot.waitForIdle();
21282
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
   102
        try {
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
   103
            Thread.sleep(2000);
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
   104
        } catch (InterruptedException ignored) {
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
   105
        }
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
   106
    }
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents:
diff changeset
   107
}