--- /dev/null 2018-09-21 16:33:24.000000000 +0530 +++ new/test/jdk/java/awt/Frame/MaximizedFrameResizibility/MaximizedFrameResizibility.java 2018-09-21 16:33:24.000000000 +0530 @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + @test + @key headful + @bug 8209123 + @summary Maximized frame is resizable on Mac but not on Windows and Ubuntu + @compile MaximizedFrameResizibility.java + @run main MaximizedFrameResizibility +*/ + +import java.awt.Toolkit; +import java.awt.Frame; +import java.awt.Rectangle; +import java.awt.AWTException; +import java.awt.event.InputEvent; +import java.awt.Robot; + +public class MaximizedFrameResizibility { + + private static Frame frame; + private static Robot robot; + private static boolean isProgInterruption = false; + private static Thread mainThread = null; + private static int sleepTime = 300000; + + private static void createAndShowFrame() { + + //The MAXIMIZED_BOTH state is not supported by the toolkit. Nothing to test. + if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) { + return; + } + + //Case 1: Setting state to MAXIMIZED_BOTH for resizable frame. + frame = new Frame("MAXIMIZED_BOTH Resizable frame"); + setFrameState(Frame.MAXIMIZED_BOTH); + frame.setResizable(true); + frame.setVisible(true); + resizeFrame(); + + //Case 2: Setting state to MAXIMIZED_BOTH from NORMAL for non-resizable frame. + frame = new Frame("MAXIMIZED_BOTH non-Resizable frame"); + setFrameState(Frame.NORMAL); + setFrameState(Frame.MAXIMIZED_BOTH); + frame.setResizable(false); + frame.setVisible(true); + resizeFrame(); + + //Case 3: Setting resizable frame state to MAXIMIZED_BOTH from NORMAL state. + frame = new Frame("Resizable MAXIMIZED_BOTH frame"); + setFrameState(Frame.NORMAL); + frame.setResizable(true); + setFrameState(Frame.MAXIMIZED_BOTH); + frame.setVisible(true); + resizeFrame(); + + //Case 4: Setting non-resizable frame state to MAXIMIZED_BOTH from NORMAL state. + frame = new Frame("Non-resizable MAXIMIZED_BOTH frame"); + setFrameState(Frame.NORMAL); + frame.setResizable(false); + setFrameState(Frame.MAXIMIZED_BOTH); + frame.setVisible(true); + resizeFrame(); + + cleanup(); + } + + private static void setFrameState(int frameState) { + frame.setSize(200, 200); + + switch(frameState) { + case Frame.MAXIMIZED_BOTH: + frame.setMaximizedBounds(new Rectangle(0, 0, 400, 400)); + frame.setExtendedState(Frame.MAXIMIZED_BOTH); + break; + case Frame.NORMAL: + frame.setExtendedState(Frame.NORMAL); + default: + } + } + + private static void resizeFrame() { + try { + robot = new Robot(); + robot.delay(2000); + + // The initial bounds of the frame + final Rectangle bounds = frame.getBounds(); + + // Move the mouse pointer to the bottom-right corner of the frame + robot.mouseMove(bounds.x + bounds.width - 2, bounds.y + bounds.height - 2); + robot.waitForIdle(); + + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.waitForIdle(); + robot.mouseMove(bounds.x + bounds.width + 20, bounds.y + bounds.height + 15); + robot.waitForIdle(); + + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + robot.waitForIdle(); + + // The bounds of the frame after the attempt of resizing is made + final Rectangle finalBounds = frame.getBounds(); + + int frameState = frame.getExtendedState(); + if ((frameState & Frame.ICONIFIED) != 0) { + // Treat all state bit masks with ICONIFIED bit as ICONIFIED state. + frameState = Frame.ICONIFIED; + } + switch (frameState) { + case Frame.MAXIMIZED_BOTH: + if (!finalBounds.equals(bounds)) { + throw new RuntimeException("MAXIMIZED_BOTH frame is resizable"); + } + break; + case Frame.NORMAL: + if (!frame.isResizable() && !finalBounds.equals(bounds)) { + throw new RuntimeException("NORMAL non-resizable frame is resizable"); + } + if (frame.isResizable() && finalBounds.equals(bounds)) { + throw new RuntimeException("NORMAL resizable frame is not resizable"); + } + break; + default: //ICONIFIED + break; + } + } catch (AWTException e) { + throw new RuntimeException("Robot creation failed"); + } finally { + frame.dispose(); + } + } + + private static void cleanup() { + isProgInterruption = true; + mainThread.interrupt(); + } + + public static void main(String args[]) throws InterruptedException { + + mainThread = Thread.currentThread(); + try { + createAndShowFrame(); + mainThread.sleep(sleepTime); + } catch (InterruptedException e) { + if (!isProgInterruption) { + throw e; + } + } + + if (!isProgInterruption) { + throw new RuntimeException("Timed out after " + sleepTime / 1000 + + " seconds"); + } + } +} +