Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/FullScreen/FullScreenInsets/FullScreenInsets.java
38828 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*/2223import java.awt.AWTException;24import java.awt.Color;25import java.awt.Dimension;26import java.awt.DisplayMode;27import java.awt.Frame;28import java.awt.GraphicsDevice;29import java.awt.GraphicsEnvironment;30import java.awt.Insets;31import java.awt.Robot;32import java.awt.Window;33import java.awt.image.BufferedImage;3435/**36* @test37* @bug 8003173 701905538* @summary Full-screen windows should have the proper insets.39* @author Sergey Bylokhov40*/41public final class FullScreenInsets {4243private static boolean passed = true;44private static Robot robot = null;4546public static void main(final String[] args) {47final GraphicsEnvironment ge = GraphicsEnvironment48.getLocalGraphicsEnvironment();49final GraphicsDevice[] devices = ge.getScreenDevices();5051final Window wGreen = new Frame();52wGreen.setBackground(Color.GREEN);53wGreen.setSize(300, 300);54wGreen.setVisible(true);55sleep();56final Insets iGreen = wGreen.getInsets();57final Dimension sGreen = wGreen.getSize();5859final Window wRed = new Frame();60wRed.setBackground(Color.RED);61wRed.setSize(300, 300);62wRed.setVisible(true);63sleep();64final Insets iRed = wGreen.getInsets();65final Dimension sRed = wGreen.getSize();6667for (final GraphicsDevice device : devices) {68if (!device.isFullScreenSupported()) {69continue;70}71device.setFullScreenWindow(wGreen);72sleep();73testWindowBounds(device.getDisplayMode(), wGreen);74testColor(wGreen, Color.GREEN);7576device.setFullScreenWindow(wRed);77sleep();78testWindowBounds(device.getDisplayMode(), wRed);79testColor(wRed, Color.RED);8081device.setFullScreenWindow(null);82sleep();83testInsets(wGreen.getInsets(), iGreen);84testInsets(wRed.getInsets(), iRed);85testSize(wGreen.getSize(), sGreen);86testSize(wRed.getSize(), sRed);87}88wGreen.dispose();89wRed.dispose();90if (!passed) {91throw new RuntimeException("Test failed");92}93}9495private static void testSize(final Dimension actual, final Dimension exp) {96if (!exp.equals(actual)) {97System.err.println(" Wrong window size:" +98" Expected: " + exp + " Actual: " + actual);99passed = false;100}101}102103private static void testInsets(final Insets actual, final Insets exp) {104if (!actual.equals(exp)) {105System.err.println(" Wrong window insets:" +106" Expected: " + exp + " Actual: " + actual);107passed = false;108}109}110111private static void testWindowBounds(final DisplayMode dm, final Window w) {112if (w.getWidth() != dm.getWidth() || w.getHeight() != dm.getHeight()) {113System.err.println(" Wrong window bounds:" +114" Expected: width = " + dm.getWidth()115+ ", height = " + dm.getHeight() + " Actual: "116+ w.getSize());117passed = false;118}119}120121private static void testColor(final Window w, final Color color) {122final Robot r;123try {124r = new Robot(w.getGraphicsConfiguration().getDevice());125} catch (AWTException e) {126e.printStackTrace();127passed = false;128return;129}130final BufferedImage bi = r.createScreenCapture(w.getBounds());131for (int y = 0; y < bi.getHeight(); y++) {132for (int x = 0; x < bi.getWidth(); x++) {133if (bi.getRGB(x, y) != color.getRGB()) {134System.err.println(135"Incorrect pixel at " + x + "x" + y + " : " +136Integer.toHexString(bi.getRGB(x, y)) +137" ,expected : " + Integer.toHexString(138color.getRGB()));139passed = false;140return;141}142}143}144}145146private static void sleep() {147if(robot == null) {148try {149robot = new Robot();150}catch(AWTException ae) {151ae.printStackTrace();152throw new RuntimeException("Cannot create Robot.");153}154}155robot.waitForIdle();156try {157Thread.sleep(2000);158} catch (InterruptedException ignored) {159}160}161}162163164