1 /* 2 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 @test 26 @key headful 27 @bug 4980161 7158623 8204860 8208125 28 @summary Setting focusable window state to false makes the maximized frame resizable 29 @compile UnfocusableMaximizedFrameResizablity.java 30 @run main UnfocusableMaximizedFrameResizablity 31 */ 32 33 import java.awt.Toolkit; 34 import java.awt.Frame; 35 import java.awt.Rectangle; 36 import java.awt.AWTException; 37 import java.awt.event.InputEvent; 38 import java.awt.Robot; 39 40 public class UnfocusableMaximizedFrameResizablity { 41 42 private static Frame frame; 43 private static Robot robot; 44 private static boolean isProgInterruption = false; 45 private static Thread mainThread = null; 46 private static int sleepTime = 300000; 47 48 private static void createAndShowFrame() throws Exception { 49 50 //The MAXIMIZED_BOTH state is not supported by the toolkit. Nothing to test. 51 if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) { 52 return; 53 } 54 55 Frame frame = new Frame("Unfocusable frame"); 56 frame.setMaximizedBounds(new Rectangle(0, 0, 300, 300)); 57 frame.setSize(200, 200); 58 frame.setVisible(true); 59 frame.setExtendedState(Frame.MAXIMIZED_BOTH); 60 frame.setFocusableWindowState(false); 61 62 try { 63 robot = new Robot(); 64 } catch (AWTException e) { 65 throw new RuntimeException("Robot creation failed"); 66 } 67 robot.delay(2000); 68 69 // The initial bounds of the frame 70 final Rectangle bounds = frame.getBounds(); 71 72 // Let's move the mouse pointer to the bottom-right coner of the frame (the "size-grip") 73 robot.mouseMove(bounds.x + bounds.width - 2, bounds.y + bounds.height - 2); 74 robot.waitForIdle(); 75 76 // ... and start resizing 77 robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); 78 robot.waitForIdle(); 79 robot.mouseMove(bounds.x + bounds.width + 20, bounds.y + bounds.height + 15); 80 robot.waitForIdle(); 81 82 robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); 83 robot.waitForIdle(); 84 85 // The bounds of the frame after the attempt of resizing is made 86 final Rectangle finalBounds = frame.getBounds(); 87 88 if (!finalBounds.equals(bounds)) { 89 cleanup(); 90 throw new RuntimeException("The maximized unfocusable frame can be resized."); 91 } 92 93 cleanup(); 94 } 95 96 private static void cleanup() { 97 frame.dispose(); 98 isProgInterruption = true; 99 mainThread.interrupt(); 100 } 101 102 public static void main(String args[]) throws Exception { 103 104 mainThread = Thread.currentThread(); 105 106 try { 107 createAndShowFrame(); 108 mainThread.sleep(sleepTime); 109 } catch (InterruptedException e) { 110 if (!isProgInterruption) { 111 throw e; 112 } 113 } 114 115 if (!isProgInterruption) { 116 throw new RuntimeException("Timed out after " + sleepTime / 1000 117 + " seconds"); 118 } 119 } 120 } 121