1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.awt.Point;
  25 import java.awt.Robot;
  26 import java.awt.event.FocusEvent;
  27 import java.awt.event.FocusListener;
  28 import java.awt.event.InputEvent;
  29 import java.awt.event.MouseEvent;
  30 import java.awt.event.MouseListener;
  31 
  32 import javax.swing.JFrame;
  33 import javax.swing.SwingUtilities;
  34 
  35 /**
  36  * @test
  37  * @key headful
  38  * @bug 8080405
  39  * @run main/othervm/policy=java.policy -Djava.security.manager PropertyPermissionOnEDT
  40  */
  41 public final class PropertyPermissionOnEDT {
  42 
  43     public static void main(final String[] args) throws Exception {
  44         SwingUtilities.invokeAndWait(PropertyPermissionOnEDT::test);
  45 
  46         JFrame frame = new JFrame();
  47         frame.addMouseListener(new MouseListener() {
  48             @Override
  49             public void mouseClicked(final MouseEvent e) {
  50                 test();
  51             }
  52 
  53             @Override
  54             public void mousePressed(MouseEvent e) {
  55                 test();
  56             }
  57 
  58             @Override
  59             public void mouseReleased(MouseEvent e) {
  60                 test();
  61             }
  62 
  63             @Override
  64             public void mouseEntered(MouseEvent e) {
  65                 test();
  66             }
  67 
  68             @Override
  69             public void mouseExited(MouseEvent e) {
  70                 test();
  71             }
  72         });
  73         frame.addFocusListener(new FocusListener() {
  74             @Override
  75             public void focusGained(FocusEvent e) {
  76                 test();
  77             }
  78 
  79             @Override
  80             public void focusLost(FocusEvent e) {
  81                 test();
  82             }
  83         });
  84         frame.addMouseWheelListener(e -> test());
  85         frame.addWindowStateListener(e -> test());
  86 
  87         frame.setSize(100, 100);
  88         frame.setLocationRelativeTo(null);
  89         frame.setVisible(true);
  90         Robot robot = new Robot();
  91         robot.setAutoWaitForIdle(true);
  92         robot.setAutoDelay(100);
  93         Point loc = frame.getLocationOnScreen();
  94         robot.mouseMove(loc.x + frame.getWidth() / 2,
  95                         loc.y + frame.getHeight() / 2);
  96         robot.mousePress(InputEvent.BUTTON1_MASK);
  97         robot.mouseRelease(InputEvent.BUTTON1_MASK);
  98         robot.mouseWheel(100);
  99         frame.dispose();
 100     }
 101 
 102     private static void test() {
 103         String property = System.getProperty("os.name");
 104         System.out.println("property = " + property);
 105     }
 106 }