--- old/test/jdk/java/awt/Frame/SetMaximizedBounds/SetMaximizedBounds.java 2018-02-02 09:58:57.145333200 +0530 +++ new/test/jdk/java/awt/Frame/SetMaximizedBounds/SetMaximizedBounds.java 2018-02-02 09:58:55.824387500 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,11 +22,13 @@ */ import java.awt.*; +import java.lang.Math; /** * @test * @key headful - * @bug 8065739 8131339 + * @bug 8065739 8131339 8196006 + * @requires (os.family == "windows" | os.family == "mac") * @summary When Frame.setExtendedState(Frame.MAXIMIZED_BOTH) * is called for a Frame after been called setMaximizedBounds() with * certain value, Frame bounds must equal to this value. @@ -38,30 +40,16 @@ public static void main(String[] args) throws Exception { - //Supported platforms are Windows and OS X. - String os = System.getProperty("os.name").toLowerCase(); - if (!os.contains("windows") && !os.contains("os x")) { - return; - } - if (!Toolkit.getDefaultToolkit(). isFrameStateSupported(Frame.MAXIMIZED_BOTH)) { return; } - GraphicsEnvironment ge = GraphicsEnvironment. - getLocalGraphicsEnvironment(); + GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment() + .getDefaultScreenDevice().getDefaultConfiguration(); - if (ge.isHeadlessInstance()) { - return; - } - - for (GraphicsDevice gd : ge.getScreenDevices()) { - for (GraphicsConfiguration gc : gd.getConfigurations()) { - testMaximizedBounds(gc, false); - testMaximizedBounds(gc, true); - } - } + testMaximizedBounds(gc, false); + testMaximizedBounds(gc, true); } static void testMaximizedBounds(GraphicsConfiguration gc, boolean undecorated) @@ -69,7 +57,6 @@ Frame frame = null; try { - Rectangle maxArea = getMaximizedScreenArea(gc); Robot robot = new Robot(); @@ -92,9 +79,10 @@ robot.delay(1000); Rectangle bounds = frame.getBounds(); - if (!bounds.equals(maximizedBounds)) { + applyScale(bounds, gc.getDefaultTransform().getScaleX(), gc.getDefaultTransform().getScaleY()); + if (!compare(bounds, maximizedBounds)) { throw new RuntimeException("The bounds of the Frame do not equal to what" - + " is specified when the frame is in Frame.MAXIMIZED_BOTH state"); + + " is specified when the frame is in Frame.MAXIMIZED_BOTH"); } frame.setExtendedState(Frame.NORMAL); @@ -112,9 +100,10 @@ robot.delay(1000); bounds = frame.getBounds(); - if (!bounds.equals(maximizedBounds)) { + applyScale(bounds, gc.getDefaultTransform().getScaleX(), gc.getDefaultTransform().getScaleY()); + if (!compare(bounds, maximizedBounds)) { throw new RuntimeException("The bounds of the Frame do not equal to what" - + " is specified when the frame is in Frame.MAXIMIZED_BOTH state"); + + " is specified when the frame is in Frame.MAXIMIZED_BOTH"); } } finally { if (frame != null) { @@ -132,4 +121,18 @@ bounds.width - insets.left - insets.right, bounds.height - insets.top - insets.bottom); } + + static void applyScale(Rectangle rect, double scaleX, double scaleY) { + rect.x = (int)Math.ceil(((double)rect.x * scaleX)); + rect.y = (int)Math.ceil(((double)rect.y * scaleY)); + rect.width = (int)Math.ceil(((double)rect.width * scaleX)); + rect.height = (int)Math.ceil(((double)rect.height * scaleY)); + } + + static boolean compare(Rectangle r1, Rectangle r2) { + return (Math.abs(r1.x - r2.x) <= 2 && + Math.abs(r1.y - r2.y) <= 2 && + Math.abs(r1.width - r2.width) <= 2 && + Math.abs(r1.height - r2.height) <= 2); + } }