jdk/test/java/awt/TrayIcon/ActionEventTest/ActionEventTest.java
changeset 38405 ca9b02b01e18
parent 37572 7b0c62fdb5d8
child 42338 a60f280f803c
equal deleted inserted replaced
38404:13564d79068f 38405:ca9b02b01e18
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 6191390
    26  * @bug 6191390 8154328
    27  * @summary Verify that ActionEvent is received with correct modifiers set.
    27  * @summary Verify that ActionEvent is received with correct modifiers set.
    28  * @library ../../../../lib/testlibrary ../
    28  * @library ../../../../lib/testlibrary ../
       
    29  * @library /java/awt/patchlib
       
    30  * @build java.desktop/java.awt.Helper
    29  * @build ExtendedRobot SystemTrayIconHelper
    31  * @build ExtendedRobot SystemTrayIconHelper
       
    32  * @run main ActionEventTest
    30  */
    33  */
    31 
    34 
    32 import java.awt.Image;
    35 import java.awt.Image;
    33 import java.awt.TrayIcon;
    36 import java.awt.TrayIcon;
    34 import java.awt.SystemTray;
    37 import java.awt.SystemTray;
    44 public class ActionEventTest {
    47 public class ActionEventTest {
    45 
    48 
    46     Image image;
    49     Image image;
    47     TrayIcon icon;
    50     TrayIcon icon;
    48     Robot robot;
    51     Robot robot;
       
    52     boolean actionPerformed;
    49 
    53 
    50     public static void main(String[] args) throws Exception {
    54     public static void main(String[] args) throws Exception {
    51         if (!SystemTray.isSupported()) {
    55         if (!SystemTray.isSupported()) {
    52             System.out.println("SystemTray not supported on the platform." +
    56             System.out.println("SystemTray not supported on the platform." +
    53                 " Marking the test passed.");
    57                 " Marking the test passed.");
    80         icon = new TrayIcon(
    84         icon = new TrayIcon(
    81             new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB), "ti");
    85             new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB), "ti");
    82         icon.addActionListener(new ActionListener() {
    86         icon.addActionListener(new ActionListener() {
    83             @Override
    87             @Override
    84             public void actionPerformed(ActionEvent ae) {
    88             public void actionPerformed(ActionEvent ae) {
       
    89                 actionPerformed = true;
    85                 int md = ae.getModifiers();
    90                 int md = ae.getModifiers();
    86                 int expectedMask = ActionEvent.ALT_MASK | ActionEvent.CTRL_MASK
    91                 int expectedMask = ActionEvent.ALT_MASK | ActionEvent.CTRL_MASK
    87                         | ActionEvent.SHIFT_MASK;
    92                         | ActionEvent.SHIFT_MASK;
    88 
    93 
    89                 if ((md & expectedMask) != expectedMask) {
    94                 if ((md & expectedMask) != expectedMask) {
   100             throw new RuntimeException(e);
   105             throw new RuntimeException(e);
   101         }
   106         }
   102     }
   107     }
   103 
   108 
   104     public void clear() {
   109     public void clear() {
       
   110         robot.keyRelease(KeyEvent.VK_ALT);
       
   111         robot.keyRelease(KeyEvent.VK_SHIFT);
       
   112         robot.keyRelease(KeyEvent.VK_CONTROL);
   105         SystemTray.getSystemTray().remove(icon);
   113         SystemTray.getSystemTray().remove(icon);
   106     }
   114     }
   107 
   115 
   108     void doTest() throws Exception {
   116     void doTest() throws Exception {
   109         robot.keyPress(KeyEvent.VK_ALT);
   117         robot.keyPress(KeyEvent.VK_ALT);
   121         robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
   129         robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
   122         robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
   130         robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
   123         robot.delay(100);
   131         robot.delay(100);
   124         robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
   132         robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
   125         robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
   133         robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
   126         robot.delay(100);
       
   127         robot.waitForIdle();
   134         robot.waitForIdle();
   128         robot.keyRelease(KeyEvent.VK_ALT);
   135         if (!actionPerformed) {
   129         robot.keyRelease(KeyEvent.VK_SHIFT);
   136             robot.delay(500);
   130         robot.keyRelease(KeyEvent.VK_CONTROL);
   137         }
   131     }
   138     }
   132 }
   139 }