jdk/test/javax/swing/JFrame/8016356/bug8016356.java
author bagiras
Mon, 25 Nov 2013 14:05:19 +0400
changeset 21791 e910f4c5176b
child 26750 d0d6c64a2e2b
permissions -rw-r--r--
8028995: Write regression test for JDK-8016356 Reviewed-by: serb, anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21791
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
     1
/*
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
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
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    24
/* @test
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    25
   @bug 8016356
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    26
   @summary Any swing frame resizes ugly.
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    27
   @run main bug8016356
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    28
   @author Oleg Pekhovskiy
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    29
*/
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    30
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    31
import java.awt.AWTException;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    32
import java.awt.Color;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    33
import java.awt.Dimension;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    34
import java.awt.GraphicsConfiguration;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    35
import java.awt.GraphicsEnvironment;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    36
import java.awt.Insets;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    37
import java.awt.Point;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    38
import java.awt.Rectangle;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    39
import java.awt.Robot;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    40
import java.awt.Toolkit;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    41
import java.awt.event.InputEvent;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    42
import javax.swing.JFrame;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    43
import javax.swing.JPanel;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    44
import javax.swing.SwingUtilities;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    45
import sun.awt.OSInfo;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    46
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    47
public class bug8016356 {
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    48
    private static JFrame frame;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    49
    private static Color color;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    50
    private static int scrTop;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    51
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    52
    private static Point frLoc;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    53
    private static Dimension frSize;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    54
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    55
    public static void main(String[] args) throws Exception {
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    56
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    57
        // Windows only test
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    58
        if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    59
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    60
            // Retrieving top edge of Desktop
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    61
            GraphicsConfiguration grConf = GraphicsEnvironment
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    62
                    .getLocalGraphicsEnvironment().getDefaultScreenDevice()
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    63
                    .getDefaultConfiguration();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    64
            Rectangle scrRect = grConf.getBounds();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    65
            Insets scrInsets = Toolkit.getDefaultToolkit().getScreenInsets(grConf);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    66
            scrTop = scrRect.y + scrInsets.top;
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    67
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    68
            color = new Color(0, 255, 0);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    69
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    70
            SwingUtilities.invokeAndWait(() -> {
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    71
                createAndShowUI();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    72
            });
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
            try {
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    75
                Robot robot = new Robot();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    76
                robot.setAutoDelay(500);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    77
                robot.setAutoWaitForIdle(true);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    78
                robot.delay(1000);
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
                // Resizing a window to invoke Windows Snap feature
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    81
                readFrameInfo();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    82
                robot.mouseMove(frLoc.x + frSize.width / 2, frLoc.y);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    83
                robot.mousePress(InputEvent.BUTTON1_MASK);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    84
                robot.mouseMove(frLoc.x + frSize.width / 2, scrTop);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    85
                robot.mouseRelease(InputEvent.BUTTON1_MASK);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    86
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    87
                // Retrieving the color of window expanded area
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    88
                readFrameInfo();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    89
                Insets insets = frame.getInsets();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    90
                Color bgColor = robot.getPixelColor(frLoc.x + frSize.width / 2,
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    91
                        frLoc.y + frSize.height - insets.bottom - 1);
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
                frame.dispose();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    94
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    95
                if (!bgColor.equals(color)) {
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    96
                    throw new RuntimeException("TEST FAILED: got "
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
    97
                            + bgColor + " instead of " + color);
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
                System.out.println("TEST PASSED!");
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   100
            } catch (AWTException ex) {
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   101
                throw new RuntimeException("TEST FAILED!");
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   102
            }
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   103
        }
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
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   106
    private static void createAndShowUI() {
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   107
        frame = new JFrame();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   108
        frame.setBounds(10, scrTop + 10, 300, 100);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   109
        JPanel panel = new JPanel();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   110
        panel.setBackground(color);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   111
        frame.getContentPane().add(panel);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   112
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   113
        frame.setVisible(true);
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   114
    }
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   115
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   116
    private static void readFrameInfo() throws Exception {
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   117
        SwingUtilities.invokeAndWait(() -> {
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   118
            frLoc = frame.getLocationOnScreen();
e910f4c5176b 8028995: Write regression test for JDK-8016356
bagiras
parents:
diff changeset
   119
            frSize = frame.getSize();
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
}