test/jdk/java/awt/Frame/UnfocusableMaximizedFrameResizablity/UnfocusableMaximizedFrameResizablity.java
author mhalder
Wed, 16 Jan 2019 23:56:32 +0530
changeset 53358 659b004b6a1b
parent 51449 cb672967bd9b
permissions -rw-r--r--
8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH Reviewed-by: serb, kaddepalli
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
53358
659b004b6a1b 8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents: 51449
diff changeset
     2
 * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
  @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 5506
diff changeset
    26
  @key headful
53358
659b004b6a1b 8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents: 51449
diff changeset
    27
  @bug 4980161 7158623 8204860 8208125 8215280
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
  @summary Setting focusable window state to false makes the maximized frame resizable
49305
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    29
  @compile UnfocusableMaximizedFrameResizablity.java
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
  @run main UnfocusableMaximizedFrameResizablity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
49305
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    33
import java.awt.Toolkit;
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    34
import java.awt.Frame;
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    35
import java.awt.Rectangle;
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    36
import java.awt.AWTException;
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    37
import java.awt.event.InputEvent;
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    38
import java.awt.Robot;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
49305
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    40
public class UnfocusableMaximizedFrameResizablity {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
49305
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    42
    private static Frame frame;
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    43
    private static Robot robot;
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    44
    private static boolean isProgInterruption = false;
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    45
    private static Thread mainThread = null;
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    46
    private static int sleepTime = 300000;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
51065
20a772d8ded0 8204860: The frame could be resized by dragging a corner of the frame with the mouse
mhalder
parents: 49305
diff changeset
    48
    private static void createAndShowFrame() throws Exception {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
53358
659b004b6a1b 8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents: 51449
diff changeset
    50
        //MAXIMIZED_BOTH frame is resizable on Mac OS by default. Nothing to test.
659b004b6a1b 8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents: 51449
diff changeset
    51
        if (System.getProperty("os.name").toLowerCase().startsWith("mac")) {
659b004b6a1b 8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents: 51449
diff changeset
    52
            cleanup();
659b004b6a1b 8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents: 51449
diff changeset
    53
            return;
659b004b6a1b 8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents: 51449
diff changeset
    54
        }
659b004b6a1b 8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents: 51449
diff changeset
    55
49305
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    56
        //The MAXIMIZED_BOTH state is not supported by the toolkit. Nothing to test.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
53358
659b004b6a1b 8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents: 51449
diff changeset
    58
            cleanup();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
51449
cb672967bd9b 8208125: Cannot input text into JOptionPane Text Input Dialog
mhalder
parents: 51065
diff changeset
    62
        frame = new Frame("Unfocusable frame");
49305
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    63
        frame.setMaximizedBounds(new Rectangle(0, 0, 300, 300));
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    64
        frame.setSize(200, 200);
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    65
        frame.setVisible(true);
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    66
        frame.setExtendedState(Frame.MAXIMIZED_BOTH);
51449
cb672967bd9b 8208125: Cannot input text into JOptionPane Text Input Dialog
mhalder
parents: 51065
diff changeset
    67
        frame.setFocusableWindowState(false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
49305
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    69
        try {
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    70
            robot = new Robot();
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    71
        } catch (AWTException e) {
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    72
            throw new RuntimeException("Robot creation failed");
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    73
        }
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    74
        robot.delay(2000);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        // The initial bounds of the frame
49305
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    77
        final Rectangle bounds = frame.getBounds();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        // Let's move the mouse pointer to the bottom-right coner of the frame (the "size-grip")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        robot.mouseMove(bounds.x + bounds.width - 2, bounds.y + bounds.height - 2);
49305
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    81
        robot.waitForIdle();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        // ... and start resizing
49305
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    84
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    85
        robot.waitForIdle();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        robot.mouseMove(bounds.x + bounds.width + 20, bounds.y + bounds.height + 15);
49305
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    87
        robot.waitForIdle();
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    88
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    89
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    90
        robot.waitForIdle();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        // The bounds of the frame after the attempt of resizing is made
49305
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    93
        final Rectangle finalBounds = frame.getBounds();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (!finalBounds.equals(bounds)) {
49305
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    96
            cleanup();
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
    97
            throw new RuntimeException("The maximized unfocusable frame can be resized.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
51449
cb672967bd9b 8208125: Cannot input text into JOptionPane Text Input Dialog
mhalder
parents: 51065
diff changeset
    99
        cleanup();
49305
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
   100
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
49305
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
   102
    private static void cleanup() {
53358
659b004b6a1b 8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents: 51449
diff changeset
   103
        if (frame != null) {
659b004b6a1b 8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents: 51449
diff changeset
   104
            frame.dispose();
659b004b6a1b 8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents: 51449
diff changeset
   105
        }
49305
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
   106
        isProgInterruption = true;
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
   107
        mainThread.interrupt();
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
   108
    }
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
   109
51065
20a772d8ded0 8204860: The frame could be resized by dragging a corner of the frame with the mouse
mhalder
parents: 49305
diff changeset
   110
    public static void main(String args[]) throws Exception {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
49305
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
   112
        mainThread = Thread.currentThread();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
49305
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
   114
        try {
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
   115
            createAndShowFrame();
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
   116
            mainThread.sleep(sleepTime);
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
   117
        } catch (InterruptedException e) {
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
   118
            if (!isProgInterruption) {
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
   119
                throw e;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
49305
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
   123
        if (!isProgInterruption) {
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
   124
            throw new RuntimeException("Timed out after " + sleepTime / 1000
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 47216
diff changeset
   125
                    + " seconds");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129