test/jdk/javax/swing/JPopupMenu/6583251/bug6583251.java
author ssadetsky
Wed, 03 Apr 2019 15:43:25 -0700
branchJDK-8200758-branch
changeset 57303 eff0cf668c29
parent 53671 9fb26c4d8eaa
permissions -rw-r--r--
8221876:[macOS] JPackage install takes long time Reviewed-by: almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27764
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
     1
/*
53671
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
     2
 * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
27764
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
     4
 *
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    10
 *
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    15
 * accompanied this code).
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    16
 *
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    20
 *
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    23
 * questions.
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    24
 */
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    25
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    26
/*
40128
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 27764
diff changeset
    27
 * @test
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 27764
diff changeset
    28
 * @key headful
53671
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    29
 * @bug 6583251 8217377
40128
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 27764
diff changeset
    30
 * @summary One more ClassCastException in Swing with TrayIcon
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 27764
diff changeset
    31
 * @author Alexander Potochkin
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 27764
diff changeset
    32
 * @run main bug6583251
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 27764
diff changeset
    33
 */
27764
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    34
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    35
import javax.swing.*;
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    36
import java.awt.*;
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    37
import java.awt.event.MouseEvent;
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    38
import java.awt.image.BufferedImage;
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    39
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    40
public class bug6583251 {
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    41
    private static JFrame frame;
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    42
    private static JPopupMenu menu;
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    43
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    44
    private static void createGui() {
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    45
        frame = new JFrame();
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    46
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    47
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    48
        JPanel panel = new JPanel();
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    49
        menu = new JPopupMenu();
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    50
        menu.add(new JMenuItem("item"));
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    51
        panel.setComponentPopupMenu(menu);
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    52
        frame.add(panel);
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    53
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    54
        frame.setSize(200, 200);
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    55
        frame.setLocationRelativeTo(null);
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    56
        frame.setVisible(true);
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    57
    }
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    58
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    59
    public static void main(String[] args) throws Exception {
53671
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    60
        if (SystemTray.isSupported()) {
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    61
            SwingUtilities.invokeAndWait(new Runnable() {
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    62
                public void run() {
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    63
                    createGui();
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    64
                }
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    65
            });
27764
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    66
53671
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    67
            Robot robot = new Robot();
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    68
            robot.waitForIdle();
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    69
            menu.show(frame, 0, 0);
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    70
            robot.waitForIdle();
27764
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    71
53671
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    72
            TrayIcon trayIcon = new TrayIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB));
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    73
            MouseEvent ev = new MouseEvent(
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    74
                    new JButton(), MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), 0, 0, 0, 1, false);
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    75
            ev.setSource(trayIcon);
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    76
            Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(ev);
27764
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    77
53671
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    78
            SwingUtilities.invokeAndWait(new Runnable() {
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    79
                public void run() {
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    80
                    frame.dispose();
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    81
                }
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    82
            });
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    83
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    84
        } else {
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    85
            System.out.println("SystemTray not supported. " + "Skipping the test.");
9fb26c4d8eaa 8217377: javax/swing/JPopupMenu/6583251/bug6583251.java failed with UnsupportedOperation exception
akolarkunnu
parents: 47216
diff changeset
    86
        }
27764
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    87
    }
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
diff changeset
    88
}