Path: blob/jdk8u272-b10-aarch32-20201026/jdk/test/java/awt/GraphicsDevice/IncorrectDisplayModeExitFullscreen.java
48795 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*/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].isFullScreenSupported()48|| !devices[1].isFullScreenSupported()) {49System.err.println("Testcase is not applicable");50return;51}52final DisplayMode defaultDM = devices[0].getDisplayMode();53final DisplayMode[] dms = devices[0].getDisplayModes();54DisplayMode nonDefaultDM = null;5556for (final DisplayMode dm : dms) {57if (!dm.equals(defaultDM)) {58nonDefaultDM = dm;59break;60}61}62if (nonDefaultDM == null) {63System.err.println("Testcase is not applicable");64return;65}6667try {68robot = new ExtendedRobot();69}catch(Exception ex) {70ex.printStackTrace();71throw new RuntimeException("Unexpected failure");72}7374final Frame frame = new Frame();75frame.setBackground(Color.GREEN);76frame.setUndecorated(true);77try {78devices[0].setFullScreenWindow(frame);79sleep();80devices[0].setDisplayMode(nonDefaultDM);81sleep();82devices[1].setFullScreenWindow(frame);83sleep();84if (!defaultDM.equals(devices[0].getDisplayMode())) {85throw new RuntimeException("DisplayMode is not restored");86}87} finally {88// cleaning up89devices[0].setFullScreenWindow(null);90devices[1].setFullScreenWindow(null);91frame.dispose();92}93}94private static void sleep() {95robot.waitForIdle(1500);96}97}9899100