Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Frame/MaximizedByPlatform/MaximizedByPlatform.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*/2223/* @test24* @bug 802614325* @summary [macosx] Maximized state could be inconsistent between peer and frame26* @author Petr Pchelko27* @library ../../../../lib/testlibrary28* @build jdk.testlibrary.OSInfo29* @run main MaximizedByPlatform30*/3132import jdk.testlibrary.OSInfo;3334import java.awt.*;3536public class MaximizedByPlatform {37private static Frame frame;38private static Rectangle availableScreenBounds;3940public static void main(String[] args) {41if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {42// Test only for macosx. Pass43return;44}4546Robot robot;47try {48robot = new Robot();49}catch(Exception ex) {50ex.printStackTrace();51throw new RuntimeException("Unexpected failure");52}53availableScreenBounds = getAvailableScreenBounds();5455// Test 1. The maximized state is set in setBounds56try {57frame = new Frame();58frame.setBounds(100, 100, 100, 100);59frame.setVisible(true);6061robot.waitForIdle();6263frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,64availableScreenBounds.width, availableScreenBounds.height);6566robot.waitForIdle();6768if (frame.getExtendedState() != Frame.MAXIMIZED_BOTH) {69throw new RuntimeException("Maximized state was not set for frame in setBounds");70}71} finally {72frame.dispose();73}747576// Test 2. The maximized state is set in setVisible77try {78frame = new Frame();79frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,80availableScreenBounds.width + 100, availableScreenBounds.height);81frame.setVisible(true);8283robot.waitForIdle();8485if (frame.getExtendedState() != Frame.MAXIMIZED_BOTH) {86throw new RuntimeException("Maximized state was not set for frame in setVisible");87}88} finally {89frame.dispose();90}91}9293private static Rectangle getAvailableScreenBounds() {94final Toolkit toolkit = Toolkit.getDefaultToolkit();95final GraphicsEnvironment graphicsEnvironment =96GraphicsEnvironment.getLocalGraphicsEnvironment();97final GraphicsDevice graphicsDevice =98graphicsEnvironment.getDefaultScreenDevice();99100final Dimension screenSize = toolkit.getScreenSize();101final Insets screenInsets = toolkit.getScreenInsets(102graphicsDevice.getDefaultConfiguration());103104final Rectangle availableScreenBounds = new Rectangle(screenSize);105106availableScreenBounds.x += screenInsets.left;107availableScreenBounds.y += screenInsets.top;108availableScreenBounds.width -= (screenInsets.left + screenInsets.right);109availableScreenBounds.height -= (screenInsets.top + screenInsets.bottom);110return availableScreenBounds;111}112}113114115