jdk/test/javax/swing/JPopupMenu/6694823/bug6694823.java
author ihse
Tue, 09 May 2017 12:57:30 +0200
changeset 45028 b0ea3c0bfb81
parent 40128 e635645d2a8a
permissions -rw-r--r--
8179889: Fix typographic errors in copyright headers Reviewed-by: erikj, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
     1
/*
45028
b0ea3c0bfb81 8179889: Fix typographic errors in copyright headers
ihse
parents: 40128
diff changeset
     2
 * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
     4
 *
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
     8
 *
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    13
 * accompanied this code).
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    14
 *
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 675
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 675
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 675
diff changeset
    21
 * questions.
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    22
 */
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    23
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    24
/*
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    25
 * @test
40128
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 27764
diff changeset
    26
 * @key headful
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    27
 * @bug 6694823
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    28
 * @summary Checks that popup menu cannot be partially hidden
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    29
 * by the task bar in applets.
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    30
 * @author Mikhail Lapshin
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    31
 * @run main bug6694823
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    32
 */
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    33
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    34
import javax.swing.*;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    35
import java.awt.*;
12828
8e71b2ed3d5f 7161766: [macosx] javax/swing/JPopupMenu/6694823/bug6694823.java failed on Mac OS X
alexsch
parents: 10315
diff changeset
    36
import java.security.Permission;
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    37
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    38
public class bug6694823 {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    39
    private static JFrame frame;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    40
    private static JPopupMenu popup;
27764
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 23328
diff changeset
    41
    private static Toolkit toolkit;
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    42
    private static Insets screenInsets;
27764
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 23328
diff changeset
    43
    private static Robot robot;
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    44
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    45
    public static void main(String[] args) throws Exception {
27764
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 23328
diff changeset
    46
        robot = new Robot();
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 23328
diff changeset
    47
        toolkit = Toolkit.getDefaultToolkit();
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    48
        SwingUtilities.invokeAndWait(new Runnable() {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    49
            public void run() {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    50
                createGui();
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    51
            }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    52
        });
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    53
27764
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 23328
diff changeset
    54
        robot.waitForIdle();
12828
8e71b2ed3d5f 7161766: [macosx] javax/swing/JPopupMenu/6694823/bug6694823.java failed on Mac OS X
alexsch
parents: 10315
diff changeset
    55
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    56
        // Get screen insets
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    57
        screenInsets = toolkit.getScreenInsets(frame.getGraphicsConfiguration());
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    58
        if (screenInsets.bottom == 0) {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    59
            // This test is only for configurations with taskbar on the bottom
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    60
            return;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    61
        }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    62
12828
8e71b2ed3d5f 7161766: [macosx] javax/swing/JPopupMenu/6694823/bug6694823.java failed on Mac OS X
alexsch
parents: 10315
diff changeset
    63
        System.setSecurityManager(new SecurityManager(){
8e71b2ed3d5f 7161766: [macosx] javax/swing/JPopupMenu/6694823/bug6694823.java failed on Mac OS X
alexsch
parents: 10315
diff changeset
    64
8e71b2ed3d5f 7161766: [macosx] javax/swing/JPopupMenu/6694823/bug6694823.java failed on Mac OS X
alexsch
parents: 10315
diff changeset
    65
            @Override
8e71b2ed3d5f 7161766: [macosx] javax/swing/JPopupMenu/6694823/bug6694823.java failed on Mac OS X
alexsch
parents: 10315
diff changeset
    66
            public void checkPermission(Permission perm) {
27764
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 23328
diff changeset
    67
                if (perm.getName().equals("setWindowAlwaysOnTop") ) {
12828
8e71b2ed3d5f 7161766: [macosx] javax/swing/JPopupMenu/6694823/bug6694823.java failed on Mac OS X
alexsch
parents: 10315
diff changeset
    68
                    throw new SecurityException();
8e71b2ed3d5f 7161766: [macosx] javax/swing/JPopupMenu/6694823/bug6694823.java failed on Mac OS X
alexsch
parents: 10315
diff changeset
    69
                }
8e71b2ed3d5f 7161766: [macosx] javax/swing/JPopupMenu/6694823/bug6694823.java failed on Mac OS X
alexsch
parents: 10315
diff changeset
    70
            }
8e71b2ed3d5f 7161766: [macosx] javax/swing/JPopupMenu/6694823/bug6694823.java failed on Mac OS X
alexsch
parents: 10315
diff changeset
    71
8e71b2ed3d5f 7161766: [macosx] javax/swing/JPopupMenu/6694823/bug6694823.java failed on Mac OS X
alexsch
parents: 10315
diff changeset
    72
        });
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    73
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    74
        // Show popup as if from an applet
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    75
        // The popup shouldn't overlap the task bar. It should be shifted up.
12828
8e71b2ed3d5f 7161766: [macosx] javax/swing/JPopupMenu/6694823/bug6694823.java failed on Mac OS X
alexsch
parents: 10315
diff changeset
    76
        checkPopup();
10315
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
    77
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    78
    }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    79
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    80
    private static void createGui() {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    81
        frame = new JFrame();
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    82
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    83
        frame.setUndecorated(true);
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    84
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    85
        popup = new JPopupMenu("Menu");
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    86
        for (int i = 0; i < 7; i++) {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    87
            popup.add(new JMenuItem("MenuItem"));
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    88
        }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    89
        JPanel panel = new JPanel();
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    90
        panel.setComponentPopupMenu(popup);
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    91
        frame.add(panel);
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    92
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    93
        frame.setSize(200, 200);
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    94
    }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    95
12828
8e71b2ed3d5f 7161766: [macosx] javax/swing/JPopupMenu/6694823/bug6694823.java failed on Mac OS X
alexsch
parents: 10315
diff changeset
    96
    private static void checkPopup() throws Exception {
10315
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
    97
        SwingUtilities.invokeAndWait(new Runnable() {
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    98
            public void run() {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    99
                // Place frame just above the task bar
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   100
                Dimension screenSize = toolkit.getScreenSize();
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   101
                frame.setLocation(screenSize.width / 2,
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   102
                        screenSize.height - frame.getHeight() - screenInsets.bottom);
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   103
                frame.setVisible(true);
10315
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   104
            }
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   105
        });
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   106
10315
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   107
        // Ensure frame is visible
27764
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 23328
diff changeset
   108
        robot.waitForIdle();
10315
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   109
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   110
        final Point point = new Point();
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   111
        SwingUtilities.invokeAndWait(new Runnable() {
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   112
            public void run() {
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   113
                // Place popup over the task bar
10315
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   114
                point.x = 0;
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   115
                point.y = frame.getHeight() - popup.getPreferredSize().height + screenInsets.bottom;
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   116
                popup.show(frame, point.x, point.y);
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   117
            }
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   118
        });
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   119
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   120
        // Ensure popup is visible
27764
4e79ff3e0602 8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 23328
diff changeset
   121
        robot.waitForIdle();
10315
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   122
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   123
        SwingUtilities.invokeAndWait(new Runnable() {
12828
8e71b2ed3d5f 7161766: [macosx] javax/swing/JPopupMenu/6694823/bug6694823.java failed on Mac OS X
alexsch
parents: 10315
diff changeset
   124
10315
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   125
            public void run() {
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   126
                Point frameLoc = frame.getLocationOnScreen();
12828
8e71b2ed3d5f 7161766: [macosx] javax/swing/JPopupMenu/6694823/bug6694823.java failed on Mac OS X
alexsch
parents: 10315
diff changeset
   127
                if (popup.getLocationOnScreen().equals(new Point(frameLoc.x, frameLoc.y + point.y))) {
8e71b2ed3d5f 7161766: [macosx] javax/swing/JPopupMenu/6694823/bug6694823.java failed on Mac OS X
alexsch
parents: 10315
diff changeset
   128
                    throw new RuntimeException("Popup is not shifted");
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   129
                }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   130
                popup.setVisible(false);
12828
8e71b2ed3d5f 7161766: [macosx] javax/swing/JPopupMenu/6694823/bug6694823.java failed on Mac OS X
alexsch
parents: 10315
diff changeset
   131
                frame.dispose();
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   132
            }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   133
        });
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   134
    }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   135
}