Path: blob/master/test/jdk/java/awt/FullScreen/FullScreenInsets/FullScreenInsets.java
41153 views
/*1* Copyright (c) 2013, 2016, 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* @key headful38* @bug 8003173 701905539* @summary Full-screen windows should have the proper insets.40* @author Sergey Bylokhov41*/42public final class FullScreenInsets {4344private static boolean passed = true;45private static Robot robot = null;4647public static void main(final String[] args) {48final GraphicsEnvironment ge = GraphicsEnvironment49.getLocalGraphicsEnvironment();50final GraphicsDevice[] devices = ge.getScreenDevices();5152final Window wGreen = new Frame();53wGreen.setBackground(Color.GREEN);54wGreen.setSize(300, 300);55wGreen.setVisible(true);56sleep();57final Insets iGreen = wGreen.getInsets();58final Dimension sGreen = wGreen.getSize();5960final Window wRed = new Frame();61wRed.setBackground(Color.RED);62wRed.setSize(300, 300);63wRed.setVisible(true);64sleep();65final Insets iRed = wGreen.getInsets();66final Dimension sRed = wGreen.getSize();6768for (final GraphicsDevice device : devices) {69if (!device.isFullScreenSupported()) {70continue;71}72device.setFullScreenWindow(wGreen);73sleep();74testWindowBounds(device.getDisplayMode(), wGreen);75testColor(wGreen, Color.GREEN);7677device.setFullScreenWindow(wRed);78sleep();79testWindowBounds(device.getDisplayMode(), wRed);80testColor(wRed, Color.RED);8182device.setFullScreenWindow(null);83sleep();84testInsets(wGreen.getInsets(), iGreen);85testInsets(wRed.getInsets(), iRed);86testSize(wGreen.getSize(), sGreen);87testSize(wRed.getSize(), sRed);88}89wGreen.dispose();90wRed.dispose();91if (!passed) {92throw new RuntimeException("Test failed");93}94}9596private static void testSize(final Dimension actual, final Dimension exp) {97if (!exp.equals(actual)) {98System.err.println(" Wrong window size:" +99" Expected: " + exp + " Actual: " + actual);100passed = false;101}102}103104private static void testInsets(final Insets actual, final Insets exp) {105if (!actual.equals(exp)) {106System.err.println(" Wrong window insets:" +107" Expected: " + exp + " Actual: " + actual);108passed = false;109}110}111112private static void testWindowBounds(final DisplayMode dm, final Window w) {113if (w.getWidth() != dm.getWidth() || w.getHeight() != dm.getHeight()) {114System.err.println(" Wrong window bounds:" +115" Expected: width = " + dm.getWidth()116+ ", height = " + dm.getHeight() + " Actual: "117+ w.getSize());118passed = false;119}120}121122private static void testColor(final Window w, final Color color) {123final Robot r;124try {125r = new Robot(w.getGraphicsConfiguration().getDevice());126} catch (AWTException e) {127e.printStackTrace();128passed = false;129return;130}131final BufferedImage bi = r.createScreenCapture(w.getBounds());132for (int y = 0; y < bi.getHeight(); y++) {133for (int x = 0; x < bi.getWidth(); x++) {134if (bi.getRGB(x, y) != color.getRGB()) {135System.err.println(136"Incorrect pixel at " + x + "x" + y + " : " +137Integer.toHexString(bi.getRGB(x, y)) +138" ,expected : " + Integer.toHexString(139color.getRGB()));140passed = false;141return;142}143}144}145}146147private static void sleep() {148if(robot == null) {149try {150robot = new Robot();151}catch(AWTException ae) {152ae.printStackTrace();153throw new RuntimeException("Cannot create Robot.");154}155}156robot.waitForIdle();157try {158Thread.sleep(2000);159} catch (InterruptedException ignored) {160}161}162}163164165