Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/GraphicsDevice/IncorrectDisplayModeExitFullscreen.java
38812 views
/*1* Copyright (c) 2013, 2019, 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*/222324import java.awt.Color;25import java.awt.DisplayMode;26import java.awt.Frame;27import java.awt.GraphicsDevice;28import java.awt.GraphicsEnvironment;2930/**31* @test32* @bug 801958733* @author Sergey Bylokhov34* @library ../../../lib/testlibrary/35* @build ExtendedRobot36* @run main IncorrectDisplayModeExitFullscreen37*/38public class IncorrectDisplayModeExitFullscreen {39static ExtendedRobot robot;4041public static void main(final String[] args) {4243final GraphicsDevice[] devices =44GraphicsEnvironment.getLocalGraphicsEnvironment()45.getScreenDevices();46if (devices.length < 2 || devices[0].getDisplayModes().length < 247|| !devices[0].isDisplayChangeSupported()48|| !devices[0].isFullScreenSupported()49|| !devices[1].isFullScreenSupported()) {50System.err.println("Testcase is not applicable");51return;52}53final DisplayMode defaultDM = devices[0].getDisplayMode();54final DisplayMode[] dms = devices[0].getDisplayModes();55DisplayMode nonDefaultDM = null;5657for (final DisplayMode dm : dms) {58if (!dm.equals(defaultDM)) {59nonDefaultDM = dm;60break;61}62}63if (nonDefaultDM == null) {64System.err.println("Testcase is not applicable");65return;66}6768try {69robot = new ExtendedRobot();70}catch(Exception ex) {71ex.printStackTrace();72throw new RuntimeException("Unexpected failure");73}7475final Frame frame = new Frame();76frame.setBackground(Color.GREEN);77frame.setUndecorated(true);78try {79devices[0].setFullScreenWindow(frame);80sleep();81devices[0].setDisplayMode(nonDefaultDM);82sleep();83devices[1].setFullScreenWindow(frame);84sleep();85if (!defaultDM.equals(devices[0].getDisplayMode())) {86throw new RuntimeException("DisplayMode is not restored");87}88} finally {89// cleaning up90devices[0].setFullScreenWindow(null);91devices[1].setFullScreenWindow(null);92frame.dispose();93}94}95private static void sleep() {96robot.waitForIdle(1500);97}98}99100101