Path: blob/master/test/jdk/java/awt/Frame/UnfocusableMaximizedFrameResizablity/UnfocusableMaximizedFrameResizablity.java
41153 views
/*1* Copyright (c) 2007, 2019, 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 4980161 7158623 8204860 8208125 821528027@summary Setting focusable window state to false makes the maximized frame resizable28@compile UnfocusableMaximizedFrameResizablity.java29@run main UnfocusableMaximizedFrameResizablity30*/3132import java.awt.Toolkit;33import java.awt.Frame;34import java.awt.Rectangle;35import java.awt.AWTException;36import java.awt.event.InputEvent;37import java.awt.Robot;3839public class UnfocusableMaximizedFrameResizablity {4041private static Frame frame;42private static Robot robot;43private static boolean isProgInterruption = false;44private static Thread mainThread = null;45private static int sleepTime = 300000;4647private static void createAndShowFrame() throws Exception {4849//MAXIMIZED_BOTH frame is resizable on Mac OS by default. Nothing to test.50if (System.getProperty("os.name").toLowerCase().startsWith("mac")) {51cleanup();52return;53}5455//The MAXIMIZED_BOTH state is not supported by the toolkit. Nothing to test.56if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {57cleanup();58return;59}6061frame = new Frame("Unfocusable frame");62frame.setMaximizedBounds(new Rectangle(0, 0, 300, 300));63frame.setSize(200, 200);64frame.setVisible(true);65frame.setExtendedState(Frame.MAXIMIZED_BOTH);66frame.setFocusableWindowState(false);6768try {69robot = new Robot();70} catch (AWTException e) {71throw new RuntimeException("Robot creation failed");72}73robot.delay(2000);7475// The initial bounds of the frame76final Rectangle bounds = frame.getBounds();7778// Let's move the mouse pointer to the bottom-right coner of the frame (the "size-grip")79robot.mouseMove(bounds.x + bounds.width - 2, bounds.y + bounds.height - 2);80robot.waitForIdle();8182// ... and start resizing83robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);84robot.waitForIdle();85robot.mouseMove(bounds.x + bounds.width + 20, bounds.y + bounds.height + 15);86robot.waitForIdle();8788robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);89robot.waitForIdle();9091// The bounds of the frame after the attempt of resizing is made92final Rectangle finalBounds = frame.getBounds();9394if (!finalBounds.equals(bounds)) {95cleanup();96throw new RuntimeException("The maximized unfocusable frame can be resized.");97}98cleanup();99}100101private static void cleanup() {102if (frame != null) {103frame.dispose();104}105isProgInterruption = true;106mainThread.interrupt();107}108109public static void main(String args[]) throws Exception {110111mainThread = Thread.currentThread();112113try {114createAndShowFrame();115mainThread.sleep(sleepTime);116} catch (InterruptedException e) {117if (!isProgInterruption) {118throw e;119}120}121122if (!isProgInterruption) {123throw new RuntimeException("Timed out after " + sleepTime / 1000124+ " seconds");125}126}127}128129130131