< prev index next >

test/java/awt/TrayIcon/TrayIconMouseTest/TrayIconMouseTest.java

Print this page




  49 
  50     int[] buttonTypes = {
  51         InputEvent.BUTTON1_MASK,
  52         InputEvent.BUTTON2_MASK,
  53         InputEvent.BUTTON3_MASK
  54     };
  55 
  56     String[] buttonNames = {
  57         "BUTTON1",
  58         "BUTTON2",
  59         "BUTTON3"
  60     };
  61 
  62     public static void main(String[] args) throws Exception {
  63         if (! SystemTray.isSupported()) {
  64             System.out.println("SystemTray not supported on the platform under test. " +
  65                     "Marking the test passed");
  66         } else {
  67             if (System.getProperty("os.name").toLowerCase().startsWith("mac")) {
  68                 isMacOS = true;




  69             }
  70             new TrayIconMouseTest().doTest();
  71         }
  72     }
  73 
  74     TrayIconMouseTest() throws Exception{
  75         robot = new ExtendedRobot();
  76         EventQueue.invokeAndWait(this::initializeGUI);
  77     }
  78 
  79     void initializeGUI() {
  80 
  81         SystemTray tray = SystemTray.getSystemTray();
  82         icon = new TrayIcon(new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB), caption);
  83         icon.addActionListener(event -> {
  84             actionPerformed = true;
  85             synchronized (actionLock) {
  86                 try {
  87                     actionLock.notifyAll();
  88                 } catch (Exception e) {


  91         });
  92         try {
  93             tray.add(icon);
  94         } catch (Exception e) {
  95             throw new RuntimeException(e);
  96         }
  97     }
  98 
  99     private void doTest() throws Exception {
 100 
 101         Point iconPosition = SystemTrayIconHelper.getTrayIconLocation(icon);
 102         if (iconPosition == null)
 103             throw new RuntimeException("Unable to find the icon location!");
 104 
 105         robot.mouseMove(iconPosition.x, iconPosition.y);
 106         robot.waitForIdle();
 107 
 108         for (int i = 0; i < buttonTypes.length; i++) {
 109             actionPerformed = false;
 110             robot.click(buttonTypes[i]);
 111             robot.waitForIdle(2000);
 112 
 113             if (isMacOS && actionPerformed && i == 2) {
 114 
 115             }else if (isMacOS && i == 2) {
 116                 throw new RuntimeException("FAIL: ActionEvent NOT triggered when " +
 117                         buttonNames[i] + " is single clicked on Mac OS");
 118             }else if (actionPerformed) {
 119                 throw new RuntimeException("FAIL: ActionEvent triggered when " +
 120                         buttonNames[i] + " is single clicked");
 121             }
 122         }
 123 
 124         if(!isMacOS) {
 125             for (int i = 0; i < buttonTypes.length; i++) {
 126                 for (int j = 0; j < buttonTypes.length; j++) {
 127                     if (j != i) {
 128                         actionPerformed = false;
 129                         robot.mousePress(buttonTypes[i]);
 130                         robot.mousePress(buttonTypes[j]);
 131                         robot.mouseRelease(buttonTypes[j]);


 138                                     buttonNames[i] + " and " + buttonNames[j] +
 139                                     " is clicked and released");
 140                     }
 141                 }
 142             }
 143 
 144             for (int i = 0; i < buttonTypes.length; i++) {
 145                 actionPerformed = false;
 146                 robot.mousePress(buttonTypes[i]);
 147                 robot.delay(50);
 148                 robot.mouseRelease(buttonTypes[i]);
 149                 robot.delay(50);
 150                 robot.mousePress(buttonTypes[i]);
 151                 robot.delay(50);
 152                 robot.mouseRelease(buttonTypes[i]);
 153 
 154                 if (i == 0) {
 155                     if (! actionPerformed) {
 156                         synchronized (actionLock) {
 157                             try {
 158                                 actionLock.wait(3000);
 159                             } catch (Exception e) {
 160                             }
 161                         }
 162                     }
 163                     if (! actionPerformed)
 164                         throw new RuntimeException("FAIL: ActionEvent not triggered when " +
 165                                 buttonNames[i] + " is double clicked");
 166                 } else {
 167                     robot.waitForIdle();
 168 
 169                     if (actionPerformed)
 170                         throw new RuntimeException("FAIL: ActionEvent triggered when " +
 171                                 buttonNames[i] + " is double clicked");
 172                 }
 173             }
 174         }
 175     }
 176 }


  49 
  50     int[] buttonTypes = {
  51         InputEvent.BUTTON1_MASK,
  52         InputEvent.BUTTON2_MASK,
  53         InputEvent.BUTTON3_MASK
  54     };
  55 
  56     String[] buttonNames = {
  57         "BUTTON1",
  58         "BUTTON2",
  59         "BUTTON3"
  60     };
  61 
  62     public static void main(String[] args) throws Exception {
  63         if (! SystemTray.isSupported()) {
  64             System.out.println("SystemTray not supported on the platform under test. " +
  65                     "Marking the test passed");
  66         } else {
  67             if (System.getProperty("os.name").toLowerCase().startsWith("mac")) {
  68                 isMacOS = true;
  69             } else if (SystemTrayIconHelper.isOel7()) {
  70                 System.out.println("OEL 7 doesn't support double click in " +
  71                         "systray. Skipped");
  72                 return;
  73             }
  74             new TrayIconMouseTest().doTest();
  75         }
  76     }
  77 
  78     TrayIconMouseTest() throws Exception{
  79         robot = new ExtendedRobot();
  80         EventQueue.invokeAndWait(this::initializeGUI);
  81     }
  82 
  83     void initializeGUI() {
  84 
  85         SystemTray tray = SystemTray.getSystemTray();
  86         icon = new TrayIcon(new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB), caption);
  87         icon.addActionListener(event -> {
  88             actionPerformed = true;
  89             synchronized (actionLock) {
  90                 try {
  91                     actionLock.notifyAll();
  92                 } catch (Exception e) {


  95         });
  96         try {
  97             tray.add(icon);
  98         } catch (Exception e) {
  99             throw new RuntimeException(e);
 100         }
 101     }
 102 
 103     private void doTest() throws Exception {
 104 
 105         Point iconPosition = SystemTrayIconHelper.getTrayIconLocation(icon);
 106         if (iconPosition == null)
 107             throw new RuntimeException("Unable to find the icon location!");
 108 
 109         robot.mouseMove(iconPosition.x, iconPosition.y);
 110         robot.waitForIdle();
 111 
 112         for (int i = 0; i < buttonTypes.length; i++) {
 113             actionPerformed = false;
 114             robot.click(buttonTypes[i]);
 115             robot.waitForIdle(6000);
 116 
 117             if (isMacOS && actionPerformed && i == 2) {
 118 
 119             }else if (isMacOS && i == 2) {
 120                 throw new RuntimeException("FAIL: ActionEvent NOT triggered when " +
 121                         buttonNames[i] + " is single clicked on Mac OS");
 122             }else if (actionPerformed) {
 123                 throw new RuntimeException("FAIL: ActionEvent triggered when " +
 124                         buttonNames[i] + " is single clicked");
 125             }
 126         }
 127 
 128         if(!isMacOS) {
 129             for (int i = 0; i < buttonTypes.length; i++) {
 130                 for (int j = 0; j < buttonTypes.length; j++) {
 131                     if (j != i) {
 132                         actionPerformed = false;
 133                         robot.mousePress(buttonTypes[i]);
 134                         robot.mousePress(buttonTypes[j]);
 135                         robot.mouseRelease(buttonTypes[j]);


 142                                     buttonNames[i] + " and " + buttonNames[j] +
 143                                     " is clicked and released");
 144                     }
 145                 }
 146             }
 147 
 148             for (int i = 0; i < buttonTypes.length; i++) {
 149                 actionPerformed = false;
 150                 robot.mousePress(buttonTypes[i]);
 151                 robot.delay(50);
 152                 robot.mouseRelease(buttonTypes[i]);
 153                 robot.delay(50);
 154                 robot.mousePress(buttonTypes[i]);
 155                 robot.delay(50);
 156                 robot.mouseRelease(buttonTypes[i]);
 157 
 158                 if (i == 0) {
 159                     if (! actionPerformed) {
 160                         synchronized (actionLock) {
 161                             try {
 162                                 actionLock.wait(6000);
 163                             } catch (Exception e) {
 164                             }
 165                         }
 166                     }
 167                     if (! actionPerformed)
 168                         throw new RuntimeException("FAIL: ActionEvent not triggered when " +
 169                                 buttonNames[i] + " is double clicked");
 170                 } else {
 171                     robot.waitForIdle();
 172 
 173                     if (actionPerformed)
 174                         throw new RuntimeException("FAIL: ActionEvent triggered when " +
 175                                 buttonNames[i] + " is double clicked");
 176                 }
 177             }
 178         }
 179     }
 180 }
< prev index next >