test/jdk/javax/swing/JFrame/8016356/bug8016356.java
author ssadetsky
Wed, 03 Apr 2019 15:43:25 -0700
branchJDK-8200758-branch
changeset 57303 eff0cf668c29
parent 51637 e9177e7749e7
permissions -rw-r--r--
8221876:[macOS] JPackage install takes long time Reviewed-by: almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21791
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
     1
/*
51637
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 47216
diff changeset
     2
 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
21791
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
     4
 *
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
     8
 *
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    13
 * accompanied this code).
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    14
 *
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    18
 *
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    21
 * questions.
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    22
 */
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    23
46151
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 26750
diff changeset
    24
/**
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 26750
diff changeset
    25
 * @test
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 26750
diff changeset
    26
 * @key headful
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 26750
diff changeset
    27
 * @bug 8016356
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 26750
diff changeset
    28
 * @summary Any swing frame resizes ugly.
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 26750
diff changeset
    29
 * @author Oleg Pekhovskiy
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 26750
diff changeset
    30
 * @requires (os.family == "windows")
51637
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 47216
diff changeset
    31
 * @library /test/lib
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 47216
diff changeset
    32
 * @build jdk.test.lib.Platform
46151
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 26750
diff changeset
    33
 * @run main bug8016356
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 26750
diff changeset
    34
 */
21791
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    35
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    36
import java.awt.AWTException;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    37
import java.awt.Color;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    38
import java.awt.Dimension;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    39
import java.awt.GraphicsConfiguration;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    40
import java.awt.GraphicsEnvironment;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    41
import java.awt.Insets;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    42
import java.awt.Point;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    43
import java.awt.Rectangle;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    44
import java.awt.Robot;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    45
import java.awt.Toolkit;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    46
import java.awt.event.InputEvent;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    47
import javax.swing.JFrame;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    48
import javax.swing.JPanel;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    49
import javax.swing.SwingUtilities;
51637
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 47216
diff changeset
    50
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 47216
diff changeset
    51
import jdk.test.lib.Platform;
21791
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    52
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    53
public class bug8016356 {
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    54
    private static JFrame frame;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    55
    private static Color color;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    56
    private static int scrTop;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    57
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    58
    private static Point frLoc;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    59
    private static Dimension frSize;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    60
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    61
    public static void main(String[] args) throws Exception {
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    62
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    63
        // Windows only test
51637
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 47216
diff changeset
    64
        if (Platform.isWindows()) {
21791
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    65
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    66
            // Retrieving top edge of Desktop
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    67
            GraphicsConfiguration grConf = GraphicsEnvironment
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    68
                    .getLocalGraphicsEnvironment().getDefaultScreenDevice()
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    69
                    .getDefaultConfiguration();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    70
            Rectangle scrRect = grConf.getBounds();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    71
            Insets scrInsets = Toolkit.getDefaultToolkit().getScreenInsets(grConf);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    72
            scrTop = scrRect.y + scrInsets.top;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    73
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    74
            color = new Color(0, 255, 0);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    75
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    76
            SwingUtilities.invokeAndWait(() -> {
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    77
                createAndShowUI();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    78
            });
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    79
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    80
            try {
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    81
                Robot robot = new Robot();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    82
                robot.setAutoDelay(500);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    83
                robot.setAutoWaitForIdle(true);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    84
                robot.delay(1000);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    85
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    86
                // Resizing a window to invoke Windows Snap feature
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    87
                readFrameInfo();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    88
                robot.mouseMove(frLoc.x + frSize.width / 2, frLoc.y);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    89
                robot.mousePress(InputEvent.BUTTON1_MASK);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    90
                robot.mouseMove(frLoc.x + frSize.width / 2, scrTop);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    91
                robot.mouseRelease(InputEvent.BUTTON1_MASK);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    92
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    93
                // Retrieving the color of window expanded area
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    94
                readFrameInfo();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    95
                Insets insets = frame.getInsets();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    96
                Color bgColor = robot.getPixelColor(frLoc.x + frSize.width / 2,
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    97
                        frLoc.y + frSize.height - insets.bottom - 1);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    98
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    99
                frame.dispose();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   100
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   101
                if (!bgColor.equals(color)) {
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   102
                    throw new RuntimeException("TEST FAILED: got "
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   103
                            + bgColor + " instead of " + color);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   104
                }
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   105
                System.out.println("TEST PASSED!");
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   106
            } catch (AWTException ex) {
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   107
                throw new RuntimeException("TEST FAILED!");
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   108
            }
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   109
        }
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   110
    }
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   111
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   112
    private static void createAndShowUI() {
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   113
        frame = new JFrame();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   114
        frame.setBounds(10, scrTop + 10, 300, 100);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   115
        JPanel panel = new JPanel();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   116
        panel.setBackground(color);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   117
        frame.getContentPane().add(panel);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   118
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   119
        frame.setVisible(true);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   120
    }
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   121
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   122
    private static void readFrameInfo() throws Exception {
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   123
        SwingUtilities.invokeAndWait(() -> {
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   124
            frLoc = frame.getLocationOnScreen();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   125
            frSize = frame.getSize();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   126
        });
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   127
    }
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   128
}