changeset 5051:70bf12e0b82c

7161766: [macosx] javax/swing/JPopupMenu/6694823/bug6694823.java failed on Mac OS X Reviewed-by: rupashka
author alexsch
date Mon, 04 Jun 2012 15:25:36 +0400
parents 3335ab17d926
children 7aa3e08ba7c1
files test/javax/swing/JPopupMenu/6694823/bug6694823.java
diffstat 1 files changed, 21 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/test/javax/swing/JPopupMenu/6694823/bug6694823.java	Fri Jun 01 19:24:34 2012 +0400
+++ b/test/javax/swing/JPopupMenu/6694823/bug6694823.java	Mon Jun 04 15:25:36 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(){
 
-        // Emulate applet security restrictions
-        toolkit.realSync();
-        System.setSecurityManager(new SecurityManager());
+            private String allowsAlwaysOnTopPermission = SecurityConstants.AWT.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION.getName();
+
+            @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);
+        checkPopup();
 
-        toolkit.realSync();
-        System.out.println("Test passed!");
-
-        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();
             }
         });
     }