test/jdk/javax/swing/JFrame/NSTexturedJFrame/NSTexturedJFrame.java
author ssadetsky
Wed, 03 Apr 2019 15:43:25 -0700
branchJDK-8200758-branch
changeset 57303 eff0cf668c29
parent 52969 c00ce2c36143
permissions -rw-r--r--
8221876:[macOS] JPackage install takes long time Reviewed-by: almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21933
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
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.
21933
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
     4
 *
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
     8
 *
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    13
 * accompanied this code).
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    14
 *
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    18
 *
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    21
 * questions.
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    22
 */
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    23
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    24
import java.awt.Rectangle;
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    25
import java.awt.Toolkit;
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    26
import java.awt.image.BufferedImage;
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    27
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    28
import javax.swing.JFrame;
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    29
import javax.swing.SwingUtilities;
51637
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 47216
diff changeset
    30
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 47216
diff changeset
    31
import jdk.test.lib.Platform;
21933
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    32
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    33
/**
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    34
 * @test
46151
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 28071
diff changeset
    35
 * @key headful
21933
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    36
 * @bug 7124513
52540
a00f1403dbe9 8211822: Some tests fail after JDK-8210039
serb
parents: 51637
diff changeset
    37
 * @requires (os.family == "mac")
21933
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    38
 * @summary We should support NSTexturedBackgroundWindowMask style on OSX.
51637
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 47216
diff changeset
    39
 * @library /test/lib
52969
c00ce2c36143 8214943: PIT: javax/swing/JFrame/NSTexturedJFrame/NSTexturedJFrame.java errors out in mac
psadhukhan
parents: 52540
diff changeset
    40
 *          /lib/client
51637
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 47216
diff changeset
    41
 * @build ExtendedRobot jdk.test.lib.Platform
28071
3acb75b8df45 8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21933
diff changeset
    42
 * @run main NSTexturedJFrame
21933
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    43
 */
46151
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 28071
diff changeset
    44
21933
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    45
public final class NSTexturedJFrame {
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    46
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    47
    private static final String BRUSH = "apple.awt.brushMetalLook";
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    48
    private static final String STYLE = "Window.style";
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    49
    private static final BufferedImage[] images = new BufferedImage[3];
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    50
    private static Rectangle bounds;
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    51
    private static volatile int step;
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    52
    private static JFrame frame;
28071
3acb75b8df45 8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21933
diff changeset
    53
    private static ExtendedRobot robot;
21933
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    54
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    55
    public static void main(final String[] args) throws Exception {
51637
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 47216
diff changeset
    56
        if (!Platform.isOSX()) {
21933
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    57
            System.out.println("This test is for OSX, considered passed.");
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    58
            return;
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    59
        }
28071
3acb75b8df45 8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21933
diff changeset
    60
        robot = new ExtendedRobot();
3acb75b8df45 8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21933
diff changeset
    61
        robot.setAutoDelay(50);
21933
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    62
        // Default window appearance
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    63
        showFrame();
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    64
        step++;
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    65
        // apple.awt.brushMetalLook appearance
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    66
        showFrame();
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    67
        step++;
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    68
        // Window.style appearance
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    69
        showFrame();
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    70
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    71
        // images on step 1 and 2 should be same
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    72
        testImages(images[1], images[2], false);
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    73
        // images on step 1 and 2 should be different from default
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    74
        testImages(images[0], images[1], true);
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    75
        testImages(images[0], images[2], true);
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    76
    }
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    77
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    78
    private static void testImages(BufferedImage img1, BufferedImage img2,
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    79
                                   boolean shouldbeDifferent) {
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    80
        boolean different = false;
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    81
        for (int x = 0; x < img1.getWidth(); ++x) {
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    82
            for (int y = 0; y < img1.getHeight(); ++y) {
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    83
                if (img1.getRGB(x, y) != img2.getRGB(x, y)) {
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    84
                    different = true;
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    85
                }
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    86
            }
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    87
        }
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    88
        if (different != shouldbeDifferent) {
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    89
            throw new RuntimeException("Textured property does not work");
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    90
        }
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    91
    }
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    92
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    93
    private static void showFrame() throws Exception {
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    94
        createUI();
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    95
        images[step] = robot.createScreenCapture(bounds);
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    96
        SwingUtilities.invokeAndWait(frame::dispose);
28071
3acb75b8df45 8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21933
diff changeset
    97
        robot.waitForIdle(1000);
21933
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    98
    }
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
    99
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   100
    private static void createUI() throws Exception {
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   101
        SwingUtilities.invokeAndWait(() -> {
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   102
            frame = new JFrame();
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   103
            frame.setUndecorated(true);
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   104
            frame.setSize(400, 400);
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   105
            frame.setLocationRelativeTo(null);
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   106
            switch (step) {
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   107
                case 1:
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   108
                    frame.getRootPane().putClientProperty(BRUSH, true);
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   109
                    break;
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   110
                case 2:
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   111
                    frame.getRootPane().putClientProperty(STYLE, "textured");
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   112
            }
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   113
            frame.setVisible(true);
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   114
        });
28071
3acb75b8df45 8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21933
diff changeset
   115
        robot.waitForIdle(1000);
21933
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   116
        SwingUtilities.invokeAndWait(() -> {
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   117
            bounds = frame.getBounds();
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   118
        });
28071
3acb75b8df45 8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 21933
diff changeset
   119
        robot.waitForIdle(1000);
21933
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   120
    }
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   121
d314dba9821a 8029010: [macosx] Need test for JDK-7124513
serb
parents:
diff changeset
   122
}