Path: blob/master/test/jdk/java/awt/Frame/MaximizedByPlatform/MaximizedByPlatform.java
41154 views
/*1* Copyright (c) 2013, 2018, 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/**24* @test25* @key headful26* @bug 802614327* @summary [macosx] Maximized state could be inconsistent between peer and frame28* @author Petr Pchelko29* @library /test/lib30* @build jdk.test.lib.Platform31* @run main MaximizedByPlatform32*/3334import jdk.test.lib.Platform;3536import java.awt.*;3738public class MaximizedByPlatform {39private static Frame frame;40private static Rectangle availableScreenBounds;4142public static void main(String[] args) {43if (!Platform.isOSX()) {44// Test only for macosx. Pass45return;46}4748Robot robot;49try {50robot = new Robot();51}catch(Exception ex) {52ex.printStackTrace();53throw new RuntimeException("Unexpected failure");54}55availableScreenBounds = getAvailableScreenBounds();5657// Test 1. The maximized state is set in setBounds58try {59frame = new Frame();60frame.setBounds(100, 100, 100, 100);61frame.setVisible(true);6263robot.waitForIdle();6465frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,66availableScreenBounds.width, availableScreenBounds.height);6768robot.waitForIdle();6970if (frame.getExtendedState() != Frame.MAXIMIZED_BOTH) {71throw new RuntimeException("Maximized state was not set for frame in setBounds");72}73} finally {74if (frame != null) frame.dispose();75}767778// Test 2. The maximized state is set in setVisible79try {80frame = new Frame();81frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,82availableScreenBounds.width + 100, availableScreenBounds.height);83frame.setVisible(true);8485robot.waitForIdle();8687if (frame.getExtendedState() != Frame.MAXIMIZED_BOTH) {88throw new RuntimeException("Maximized state was not set for frame in setVisible");89}90} finally {91if (frame != null) frame.dispose();92}93}9495private static Rectangle getAvailableScreenBounds() {96final Toolkit toolkit = Toolkit.getDefaultToolkit();97final GraphicsEnvironment graphicsEnvironment =98GraphicsEnvironment.getLocalGraphicsEnvironment();99final GraphicsDevice graphicsDevice =100graphicsEnvironment.getDefaultScreenDevice();101102final Dimension screenSize = toolkit.getScreenSize();103final Insets screenInsets = toolkit.getScreenInsets(104graphicsDevice.getDefaultConfiguration());105106final Rectangle availableScreenBounds = new Rectangle(screenSize);107108availableScreenBounds.x += screenInsets.left;109availableScreenBounds.y += screenInsets.top;110availableScreenBounds.width -= (screenInsets.left + screenInsets.right);111availableScreenBounds.height -= (screenInsets.top + screenInsets.bottom);112return availableScreenBounds;113}114}115116117