Path: blob/master/test/jdk/java/awt/FullScreen/FullscreenWindowProps/FullscreenWindowProps.java
41153 views
/*1* Copyright (c) 2020, 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*/2223import java.awt.Color;24import java.awt.DisplayMode;25import java.awt.Frame;26import java.awt.Graphics;27import java.awt.GraphicsConfiguration;28import java.awt.GraphicsDevice;29import java.awt.GraphicsEnvironment;30import java.awt.Rectangle;3132/**33* @test34* @bug 821199935* @key headful36* @summary verifies the full-screen window bounds and graphics configuration37*/38public final class FullscreenWindowProps {3940public static void main(String[] args) throws Exception {41var ge = GraphicsEnvironment.getLocalGraphicsEnvironment();42GraphicsDevice gd = ge.getDefaultScreenDevice();4344if (!gd.isFullScreenSupported()) {45return;46}4748Frame frame = new Frame() {49@Override50public void paint(Graphics g) {51super.paint(g);52g.setColor(Color.GREEN);53g.fillRect(0, 0, getWidth(), getHeight());54}55};56try {57frame.setUndecorated(true); // workaround JDK-825625758frame.setBackground(Color.MAGENTA);59frame.setVisible(true);60gd.setFullScreenWindow(frame);61Thread.sleep(4000);6263for (DisplayMode dm : gd.getDisplayModes()) {64if (dm.getWidth() == 1024 && dm.getHeight() == 768) {65gd.setDisplayMode(dm);66Thread.sleep(4000);67break;68}69}7071GraphicsConfiguration frameGC = frame.getGraphicsConfiguration();72Rectangle frameBounds = frame.getBounds();7374GraphicsConfiguration screenGC = gd.getDefaultConfiguration();75Rectangle screenBounds = screenGC.getBounds();7677if (frameGC != screenGC) {78System.err.println("Expected: " + screenGC);79System.err.println("Actual: " + frameGC);80throw new RuntimeException();81}8283checkSize(frameBounds.x, screenBounds.x, "x");84checkSize(frameBounds.y, screenBounds.y, "Y");85checkSize(frameBounds.width, screenBounds.width, "width");86checkSize(frameBounds.height, screenBounds.height, "height");87} finally {88gd.setFullScreenWindow(null);89frame.dispose();90Thread.sleep(10000);91}92}9394private static void checkSize(int actual, int expected, String prop) {95if (Math.abs(actual - expected) > 30) { // let's allow size variation,96// the bug is reproduced anyway97System.err.println("Expected: " + expected);98System.err.println("Actual: " + actual);99throw new RuntimeException(prop + " is wrong");100}101}102}103104105