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 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() { 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 //Case 1: Setting frame resizable to true followed by focusable to false 56 frame = createFrame("Resizable Unfocusable frame"); 57 frame.setResizable(true); 58 frame.setFocusableWindowState(false); 59 tryToResizeFrame(frame); 60 61 //Case 2: Setting frame focusable to false followed by resizable to true 62 frame = createFrame("Unfocusable Resizable frame"); 63 frame.setFocusableWindowState(false); 64 frame.setResizable(true); 65 tryToResizeFrame(frame); 66 67 cleanup(); 68 } 69 70 private static Frame createFrame(String title) { 71 Frame frame = new Frame(title); 72 frame.setMaximizedBounds(new Rectangle(0, 0, 300, 300)); 73 frame.setSize(200, 200); 74 frame.setVisible(true); 75 frame.setExtendedState(Frame.MAXIMIZED_BOTH); 76 77 return frame; 78 } 79 80 private static void tryToResizeFrame(Frame frame) { 81 try { 82 robot = new Robot(); 83 } catch (AWTException e) { 84 throw new RuntimeException("Robot creation failed"); 85 } 86 robot.delay(2000); 87 88 // The initial bounds of the frame 89 final Rectangle bounds = frame.getBounds(); 90 91 // Let's move the mouse pointer to the bottom-right coner of the frame (the "size-grip") 92 robot.mouseMove(bounds.x + bounds.width - 2, bounds.y + bounds.height - 2); 93 robot.waitForIdle(); 94 95 // ... and start resizing 96 robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); 97 robot.waitForIdle(); 98 robot.mouseMove(bounds.x + bounds.width + 20, bounds.y + bounds.height + 15); 99 robot.waitForIdle(); 100 101 robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); 102 robot.waitForIdle(); 103 104 // The bounds of the frame after the attempt of resizing is made 105 final Rectangle finalBounds = frame.getBounds(); 106 107 if (!finalBounds.equals(bounds)) { 108 cleanup(); 109 throw new RuntimeException("The maximized unfocusable frame can be resized."); 110 } 111 112 frame.dispose(); 113 } 114 115 private static void cleanup() { 116 isProgInterruption = true; 117 mainThread.interrupt(); 118 } 119 120 public static void main(String args[]) throws InterruptedException { 121 122 mainThread = Thread.currentThread(); 123 124 try { 125 createAndShowFrame(); 126 mainThread.sleep(sleepTime); 127 } catch (InterruptedException e) { 128 if (!isProgInterruption) { 129 throw e; 130 } 131 } 132 133 if (!isProgInterruption) { 134 throw new RuntimeException("Timed out after " + sleepTime / 1000 135 + " seconds"); 136 } 137 } 138 } 139