Path: blob/master/test/jdk/java/awt/GraphicsDevice/IncorrectDisplayModeExitFullscreen.java
41149 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* @key headful33* @bug 801958734* @author Sergey Bylokhov35* @library /lib/client/36* @build ExtendedRobot37* @run main IncorrectDisplayModeExitFullscreen38*/39public class IncorrectDisplayModeExitFullscreen {40static ExtendedRobot robot;4142public static void main(final String[] args) {4344final GraphicsDevice[] devices =45GraphicsEnvironment.getLocalGraphicsEnvironment()46.getScreenDevices();47if (devices.length < 2 || devices[0].getDisplayModes().length < 248|| !devices[0].isDisplayChangeSupported()49|| !devices[0].isFullScreenSupported()50|| !devices[1].isFullScreenSupported()) {51System.err.println("Testcase is not applicable");52return;53}54final DisplayMode defaultDM = devices[0].getDisplayMode();55final DisplayMode[] dms = devices[0].getDisplayModes();56DisplayMode nonDefaultDM = null;5758for (final DisplayMode dm : dms) {59if (!dm.equals(defaultDM)) {60nonDefaultDM = dm;61break;62}63}64if (nonDefaultDM == null) {65System.err.println("Testcase is not applicable");66return;67}6869try {70robot = new ExtendedRobot();71}catch(Exception ex) {72ex.printStackTrace();73throw new RuntimeException("Unexpected failure");74}7576final Frame frame = new Frame();77frame.setBackground(Color.GREEN);78frame.setUndecorated(true);79try {80devices[0].setFullScreenWindow(frame);81sleep();82devices[0].setDisplayMode(nonDefaultDM);83sleep();84devices[1].setFullScreenWindow(frame);85sleep();86if (!defaultDM.equals(devices[0].getDisplayMode())) {87throw new RuntimeException("DisplayMode is not restored");88}89} finally {90// cleaning up91devices[0].setFullScreenWindow(null);92devices[1].setFullScreenWindow(null);93frame.dispose();94}95}96private static void sleep() {97robot.waitForIdle(1500);98}99}100101102