Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/FullScreen/8013581/bug8013581.java
38821 views
/*1* Copyright (c) 2013, 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* @bug 801358126* @summary [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow27* @author [email protected]28* @run main bug801358129*/3031import java.awt.*;32import java.awt.event.*;3334public class bug8013581 {35private static Frame frame;36private static volatile int listenerCallCounter = 0;3738public static void main(String[] args) throws Exception {39final GraphicsEnvironment ge = GraphicsEnvironment40.getLocalGraphicsEnvironment();41final GraphicsDevice[] devices = ge.getScreenDevices();4243final Robot robot = new Robot();44robot.setAutoDelay(50);4546createAndShowGUI();47robot.waitForIdle();4849Exception error = null;50for (final GraphicsDevice device : devices) {51if (!device.isFullScreenSupported()) {52continue;53}5455device.setFullScreenWindow(frame);56sleep(robot);5758robot.keyPress(KeyEvent.VK_A);59robot.keyRelease(KeyEvent.VK_A);60robot.waitForIdle();6162device.setFullScreenWindow(null);63sleep(robot);6465if (listenerCallCounter != 2) {66error = new Exception("Test failed: KeyListener called " + listenerCallCounter + " times instead of 2!");67break;68}6970listenerCallCounter = 0;71}7273frame.dispose();7475if (error != null) {76throw error;77}78}7980private static void createAndShowGUI() {81frame = new Frame("Test");82frame.addKeyListener(new KeyAdapter() {83@Override84public void keyPressed(KeyEvent e) {85listenerCallCounter++;86}8788@Override89public void keyReleased(KeyEvent e) {90listenerCallCounter++;91}92});9394frame.setUndecorated(true);95frame.setVisible(true);96}9798private static void sleep(Robot robot) {99robot.waitForIdle();100try {101Thread.sleep(2000);102} catch (InterruptedException ignored) {103}104}105}106107108