jdk/test/javax/swing/JPopupMenu/6800513/bug6800513.java
author juh
Tue, 25 Jun 2013 14:41:46 -0700
changeset 18552 005e115dc6ee
parent 12825 8dda01ae38f4
child 28071 3acb75b8df45
permissions -rw-r--r--
8017326: Cleanup of the javadoc <code> tag in java.security.spec Summary: Convert javadoc <code> and <tt> tags to {@code ...} Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12825
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
     1
/*
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
     2
 * Copyright 2012 Red Hat, Inc.  All Rights Reserved.
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
     3
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
     5
 *
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
     8
 * published by the Free Software Foundation.
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
     9
 *
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    14
 * accompanied this code).
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    15
 *
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    19
 *
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    22
 * questions.
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    23
 */
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    24
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    25
/*
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    26
 * @test
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    27
 * @bug 6800513
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    28
 * @summary GTK-LaF renders menus incompletely
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    29
 * @author Mario Torre
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    30
 * @library ../../regtesthelpers/
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    31
 * @build Util
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    32
 * @run main bug6800513
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    33
 */
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    34
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    35
import sun.awt.SunToolkit;
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    36
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    37
import javax.swing.*;
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    38
import java.awt.*;
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    39
import java.awt.event.InputEvent;
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    40
import java.beans.PropertyChangeEvent;
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    41
import java.beans.PropertyChangeListener;
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    42
import java.lang.reflect.Field;
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    43
import java.util.concurrent.Callable;
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    44
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    45
public class bug6800513 {
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    46
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    47
    private static JPopupMenu popupMenu;
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    48
    private static JMenu menu;
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    49
    private static JFrame frame;
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    50
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    51
    public static void testFrame(final boolean defaultLightWeightPopupEnabled,
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    52
            String expectedPopupClass) throws Exception {
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    53
        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    54
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    55
        SwingUtilities.invokeAndWait(new Runnable() {
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    56
            public void run() {
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    57
                JPopupMenu.setDefaultLightWeightPopupEnabled(defaultLightWeightPopupEnabled);
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    58
                createAndShowUI();
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    59
            }
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    60
        });
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    61
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    62
        toolkit.realSync();
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    63
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    64
        clickOnMenu();
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    65
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    66
        toolkit.realSync();
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    67
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    68
        Field getPopup = JPopupMenu.class.getDeclaredField("popup");
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    69
        getPopup.setAccessible(true);
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    70
        Popup popup = (Popup) getPopup.get(popupMenu);
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    71
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    72
        if (popup == null) {
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    73
            throw new Exception("popup is null!");
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    74
        }
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    75
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    76
        String className = popup.getClass().getName();
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    77
        if (!className.equals(expectedPopupClass)) {
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    78
            throw new Exception("popup class is: " + className +
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    79
                    ", expected: " + expectedPopupClass);
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    80
        }
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    81
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    82
        SwingUtilities.invokeAndWait(new Runnable() {
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    83
            @Override
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    84
            public void run() {
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    85
                frame.dispose();
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    86
                popupMenu = null;
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    87
            }
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    88
        });
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    89
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    90
        toolkit.realSync();
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    91
    }
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    92
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    93
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    94
    public static void clickOnMenu() throws Exception {
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    95
        Rectangle bounds = Util.invokeOnEDT(new Callable<Rectangle>() {
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    96
            @Override
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    97
            public Rectangle call() throws Exception {
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    98
                return new Rectangle(menu.getLocationOnScreen(), menu.getSize());
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
    99
            }
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   100
        });
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   101
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   102
        Robot robot = new Robot();
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   103
        robot.setAutoDelay(100);
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   104
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   105
        robot.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   106
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   107
        robot.mousePress(InputEvent.BUTTON1_MASK);
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   108
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   109
    }
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   110
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   111
    private static class PopupListener implements PropertyChangeListener {
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   112
        @Override
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   113
        public void propertyChange(PropertyChangeEvent evt) {
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   114
            if (evt.toString().contains("visible") && ((Boolean) evt.getNewValue() == true)) {
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   115
                popupMenu = (JPopupMenu) evt.getSource();
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   116
            }
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   117
        }
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   118
    }
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   119
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   120
    public static void createAndShowUI() {
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   121
        frame = new JFrame();
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   122
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   123
        JMenuBar menuBar = new JMenuBar();
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   124
        menu = new JMenu("Menu");
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   125
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   126
        menu.add(new JMenuItem("Menu Item #1"));
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   127
        menu.add(new JMenuItem("Menu Item #2"));
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   128
        menu.add(new JMenuItem("Menu Item #3"));
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   129
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   130
        menuBar.add(menu);
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   131
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   132
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   133
        frame.setJMenuBar(menuBar);
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   134
        frame.setSize(500, 500);
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   135
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   136
        PopupListener listener = new PopupListener();
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   137
        menu.getPopupMenu().addPropertyChangeListener(listener);
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   138
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   139
        frame.setVisible(true);
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   140
    }
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   141
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   142
    public static void main(String[] args) throws Exception {
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   143
        testFrame(false, "javax.swing.PopupFactory$HeavyWeightPopup");
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   144
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   145
        testFrame(true, "javax.swing.PopupFactory$LightWeightPopup");
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   146
    }
8dda01ae38f4 7171806: Missing test for bug ID 6800513 fix
neugens
parents:
diff changeset
   147
}