Path: blob/master/test/jdk/java/awt/FullScreen/8013581/bug8013581.java
41155 views
/*1* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @key headful26* @bug 801358127* @summary [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow28* @author [email protected]29* @run main bug801358130*/3132import java.awt.*;33import java.awt.event.*;3435public class bug8013581 {36private static Frame frame;37private static volatile int listenerCallCounter = 0;3839public static void main(String[] args) throws Exception {40final GraphicsEnvironment ge = GraphicsEnvironment41.getLocalGraphicsEnvironment();42final GraphicsDevice[] devices = ge.getScreenDevices();4344final Robot robot = new Robot();45robot.setAutoDelay(50);4647createAndShowGUI();48robot.waitForIdle();4950Exception error = null;51for (final GraphicsDevice device : devices) {52if (!device.isFullScreenSupported()) {53continue;54}5556device.setFullScreenWindow(frame);57sleep(robot);5859robot.keyPress(KeyEvent.VK_A);60robot.keyRelease(KeyEvent.VK_A);61robot.waitForIdle();6263device.setFullScreenWindow(null);64sleep(robot);6566if (listenerCallCounter != 2) {67error = new Exception("Test failed: KeyListener called " + listenerCallCounter + " times instead of 2!");68break;69}7071listenerCallCounter = 0;72}7374frame.dispose();7576if (error != null) {77throw error;78}79}8081private static void createAndShowGUI() {82frame = new Frame("Test");83frame.addKeyListener(new KeyAdapter() {84@Override85public void keyPressed(KeyEvent e) {86listenerCallCounter++;87}8889@Override90public void keyReleased(KeyEvent e) {91listenerCallCounter++;92}93});9495frame.setUndecorated(true);96frame.setVisible(true);97}9899private static void sleep(Robot robot) {100robot.waitForIdle();101try {102Thread.sleep(2000);103} catch (InterruptedException ignored) {104}105}106}107108109