7161766: [macosx] javax/swing/JPopupMenu/6694823/bug6694823.java failed on Mac OS X
authoralexsch
Mon, 04 Jun 2012 14:11:26 +0400
changeset 12828 8e71b2ed3d5f
parent 12827 c75cdabbd34b
child 12829 506020af237a
7161766: [macosx] javax/swing/JPopupMenu/6694823/bug6694823.java failed on Mac OS X Reviewed-by: rupashka
jdk/test/javax/swing/JPopupMenu/6694823/bug6694823.java
--- a/jdk/test/javax/swing/JPopupMenu/6694823/bug6694823.java	Fri Jun 01 17:08:18 2012 +0400
+++ b/jdk/test/javax/swing/JPopupMenu/6694823/bug6694823.java	Mon Jun 04 14:11:26 2012 +0400
@@ -33,6 +33,8 @@
 import javax.swing.*;
 import java.awt.*;
 import sun.awt.SunToolkit;
+import java.security.Permission;
+import sun.security.util.SecurityConstants;
 
 public class bug6694823 {
     private static JFrame frame;
@@ -48,6 +50,8 @@
             }
         });
 
+        toolkit.realSync();
+
         // Get screen insets
         screenInsets = toolkit.getScreenInsets(frame.getGraphicsConfiguration());
         if (screenInsets.bottom == 0) {
@@ -55,26 +59,23 @@
             return;
         }
 
-        // Show popup as if from a standalone application
-        // The popup should be able to overlap the task bar
-        showPopup(false);
+        System.setSecurityManager(new SecurityManager(){
+
+            private String allowsAlwaysOnTopPermission = SecurityConstants.AWT.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION.getName();
 
-        // Emulate applet security restrictions
-        toolkit.realSync();
-        System.setSecurityManager(new SecurityManager());
+            @Override
+            public void checkPermission(Permission perm) {
+                if (allowsAlwaysOnTopPermission.equals(perm.getName())) {
+                    throw new SecurityException();
+                }
+            }
+
+        });
 
         // Show popup as if from an applet
         // The popup shouldn't overlap the task bar. It should be shifted up.
-        showPopup(true);
-
-        toolkit.realSync();
-        System.out.println("Test passed!");
+        checkPopup();
 
-        SwingUtilities.invokeAndWait(new Runnable() {
-            public void run() {
-                frame.dispose();
-            }
-        });
     }
 
     private static void createGui() {
@@ -93,7 +94,7 @@
         frame.setSize(200, 200);
     }
 
-    private static void showPopup(final boolean shouldBeShifted) throws Exception {
+    private static void checkPopup() throws Exception {
         SwingUtilities.invokeAndWait(new Runnable() {
             public void run() {
                 // Place frame just above the task bar
@@ -121,20 +122,14 @@
         toolkit.realSync();
 
         SwingUtilities.invokeAndWait(new Runnable() {
+
             public void run() {
                 Point frameLoc = frame.getLocationOnScreen();
-                if (shouldBeShifted) {
-                    if (popup.getLocationOnScreen()
-                            .equals(new Point(frameLoc.x, frameLoc.y + point.y))) {
-                        throw new RuntimeException("Popup is not shifted");
-                    }
-                } else {
-                    if (!popup.getLocationOnScreen()
-                            .equals(new Point(frameLoc.x, frameLoc.y + point.y))) {
-                        throw new RuntimeException("Popup is unexpectedly shifted");
-                    }
+                if (popup.getLocationOnScreen().equals(new Point(frameLoc.x, frameLoc.y + point.y))) {
+                    throw new RuntimeException("Popup is not shifted");
                 }
                 popup.setVisible(false);
+                frame.dispose();
             }
         });
     }