test/javax/swing/JPopupMenu/6694823/bug6694823.java

Print this page

        

@@ -31,10 +31,12 @@
  */
 
 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;
     private static JPopupMenu popup;
     private static SunToolkit toolkit;

@@ -46,37 +48,36 @@
             public void run() {
                 createGui();
             }
         });
 
+        toolkit.realSync();
+
         // Get screen insets
         screenInsets = toolkit.getScreenInsets(frame.getGraphicsConfiguration());
         if (screenInsets.bottom == 0) {
             // This test is only for configurations with taskbar on the bottom
             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);
-
-        toolkit.realSync();
-        System.out.println("Test passed!");
+        checkPopup();
 
-        SwingUtilities.invokeAndWait(new Runnable() {
-            public void run() {
-                frame.dispose();
-            }
-        });
     }
 
     private static void createGui() {
         frame = new JFrame();
         frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

@@ -91,11 +92,11 @@
         frame.add(panel);
 
         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
                 Dimension screenSize = toolkit.getScreenSize();
                 frame.setLocation(screenSize.width / 2,

@@ -119,23 +120,17 @@
 
         // Ensure popup is visible
         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))) {
+                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");
-                    }
-                }
                 popup.setVisible(false);
+                frame.dispose();
             }
         });
     }
 }