34 * @run main/othervm/policy=tray.policy -Djava.security.manager FunctionalityCheck 35 */ 36 37 public class FunctionalityCheck { 38 39 TrayIcon icon; 40 ExtendedRobot robot; 41 42 boolean actionPerformed = false; 43 Object actionLock = new Object(); 44 Object pressLock = new Object(); 45 Object releaseLock = new Object(); 46 Object clickLock = new Object(); 47 Object moveLock = new Object(); 48 49 String caption = "Sample Icon"; 50 boolean mousePressed = false; 51 boolean mouseReleased = false; 52 boolean mouseClicked = false; 53 boolean mouseMoved = false; 54 55 static final int[] buttonTypes = { 56 InputEvent.BUTTON1_MASK, 57 InputEvent.BUTTON2_MASK, 58 InputEvent.BUTTON3_MASK 59 }; 60 61 static final String[] buttonNames = { 62 "BUTTON1", 63 "BUTTON2", 64 "BUTTON3" 65 }; 66 67 public static void main(String[] args) throws Exception { 68 if (! SystemTray.isSupported()) { 69 System.out.println("SystemTray not supported on the platform under test. " + 70 "Marking the test passed"); 71 } else { 72 new FunctionalityCheck().doTest(); 73 } 74 } 75 76 FunctionalityCheck() throws Exception { 77 robot = new ExtendedRobot(); 78 EventQueue.invokeAndWait(this::initializeGUI); 79 } 80 81 void initializeGUI() { 82 SystemTray tray = SystemTray.getSystemTray(); 83 icon = new TrayIcon(new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB), caption); 84 icon.addActionListener(event -> { 85 actionPerformed = true; 86 synchronized (actionLock) { 87 try { 88 actionLock.notifyAll(); 89 } catch (Exception e) { 90 } 91 } 171 } catch (Exception e) { 172 } 173 } 174 } 175 }); 176 177 try { 178 tray.add(icon); 179 } catch (Exception e) { 180 throw new RuntimeException(e); 181 } 182 } 183 184 private void doTest() throws Exception { 185 186 187 188 Point iconPosition = SystemTrayIconHelper.getTrayIconLocation(icon); 189 if (iconPosition == null) 190 throw new RuntimeException("Unable to find the icon location!"); 191 192 robot.mouseMove(iconPosition.x, iconPosition.y); 193 robot.waitForIdle(2000); 194 195 SystemTrayIconHelper.doubleClick(robot); 196 197 if (! actionPerformed) { 198 synchronized (actionLock) { 199 try { 200 actionLock.wait(3000); 201 } catch (Exception e) { 202 } 203 } 204 } 205 if (! actionPerformed) 206 throw new RuntimeException("FAIL: ActionEvent not triggered when TrayIcon is double clicked"); 207 208 for (int i = 0; i < buttonTypes.length; i++) { 209 mousePressed = false; 210 robot.mousePress(buttonTypes[i]); 211 212 if (! mousePressed) { 213 synchronized (pressLock) { 214 try { 215 pressLock.wait(3000); 216 } catch (Exception e) { 217 } 218 } 219 } 220 if (! mousePressed) 221 if (! SystemTrayIconHelper.skip(buttonTypes[i]) ) 222 throw new RuntimeException("FAIL: mousePressed not triggered when " + 223 buttonNames[i] + " pressed"); 224 225 mouseReleased = false; 226 mouseClicked = false; 227 robot.mouseRelease(buttonTypes[i]); 228 229 if (! mouseReleased) { 230 synchronized (releaseLock) { 231 try { 232 releaseLock.wait(3000); 233 } catch (Exception e) { 234 } 235 } 236 } 237 if (! mouseReleased) 238 if (! SystemTrayIconHelper.skip(buttonTypes[i]) ) 239 throw new RuntimeException("FAIL: mouseReleased not triggered when " + 240 buttonNames[i] + " released"); 241 242 if (! mouseClicked) { 243 synchronized (clickLock) { 244 try { 245 clickLock.wait(3000); 246 } catch (Exception e) { 247 } 248 } 249 } 250 if (! mouseClicked) 251 throw new RuntimeException("FAIL: mouseClicked not triggered when " + 252 buttonNames[i] + " pressed & released"); 253 } 254 255 mouseMoved = false; 256 robot.mouseMove(iconPosition.x + 100, iconPosition.y); 257 robot.glide(iconPosition.x, iconPosition.y); 258 259 if (! mouseMoved) 260 if (! SystemTrayIconHelper.skip(0) ) 261 throw new RuntimeException("FAIL: mouseMoved not triggered even when mouse moved over the icon"); 262 } 263 } | 34 * @run main/othervm/policy=tray.policy -Djava.security.manager FunctionalityCheck 35 */ 36 37 public class FunctionalityCheck { 38 39 TrayIcon icon; 40 ExtendedRobot robot; 41 42 boolean actionPerformed = false; 43 Object actionLock = new Object(); 44 Object pressLock = new Object(); 45 Object releaseLock = new Object(); 46 Object clickLock = new Object(); 47 Object moveLock = new Object(); 48 49 String caption = "Sample Icon"; 50 boolean mousePressed = false; 51 boolean mouseReleased = false; 52 boolean mouseClicked = false; 53 boolean mouseMoved = false; 54 static boolean isOEL7; 55 56 static final int[] buttonTypes = { 57 InputEvent.BUTTON1_MASK, 58 InputEvent.BUTTON2_MASK, 59 InputEvent.BUTTON3_MASK 60 }; 61 62 static final String[] buttonNames = { 63 "BUTTON1", 64 "BUTTON2", 65 "BUTTON3" 66 }; 67 68 public static void main(String[] args) throws Exception { 69 if (! SystemTray.isSupported()) { 70 System.out.println("SystemTray not supported on the platform under test. " + 71 "Marking the test passed"); 72 } else { 73 isOEL7 = SystemTrayIconHelper.isOel7(); 74 new FunctionalityCheck().doTest(); 75 } 76 } 77 78 FunctionalityCheck() throws Exception { 79 robot = new ExtendedRobot(); 80 EventQueue.invokeAndWait(this::initializeGUI); 81 } 82 83 void initializeGUI() { 84 SystemTray tray = SystemTray.getSystemTray(); 85 icon = new TrayIcon(new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB), caption); 86 icon.addActionListener(event -> { 87 actionPerformed = true; 88 synchronized (actionLock) { 89 try { 90 actionLock.notifyAll(); 91 } catch (Exception e) { 92 } 93 } 173 } catch (Exception e) { 174 } 175 } 176 } 177 }); 178 179 try { 180 tray.add(icon); 181 } catch (Exception e) { 182 throw new RuntimeException(e); 183 } 184 } 185 186 private void doTest() throws Exception { 187 188 189 190 Point iconPosition = SystemTrayIconHelper.getTrayIconLocation(icon); 191 if (iconPosition == null) 192 throw new RuntimeException("Unable to find the icon location!"); 193 if (isOEL7) { 194 // close tray 195 robot.mouseMove(100,100); 196 robot.click(InputEvent.BUTTON1_MASK); 197 robot.waitForIdle(2000); 198 } 199 200 robot.mouseMove(iconPosition.x, iconPosition.y); 201 robot.waitForIdle(); 202 if(!isOEL7) { 203 SystemTrayIconHelper.doubleClick(robot); 204 205 if (!actionPerformed) { 206 synchronized (actionLock) { 207 try { 208 actionLock.wait(3000); 209 } catch (Exception e) { 210 } 211 } 212 } 213 if (!actionPerformed) 214 throw new RuntimeException("FAIL: ActionEvent not triggered when TrayIcon is double clicked"); 215 } 216 217 for (int i = 0; i < buttonTypes.length; i++) { 218 mousePressed = false; 219 if(isOEL7) { 220 SystemTrayIconHelper.openTrayIfNeeded(robot); 221 robot.mouseMove(iconPosition.x, iconPosition.y); 222 robot.click(buttonTypes[i]); 223 } else { 224 robot.mousePress(buttonTypes[i]); 225 } 226 227 if (! mousePressed) { 228 synchronized (pressLock) { 229 try { 230 pressLock.wait(6000); 231 } catch (Exception e) { 232 } 233 } 234 } 235 if (! mousePressed) 236 if (! SystemTrayIconHelper.skip(buttonTypes[i]) ) 237 throw new RuntimeException("FAIL: mousePressed not triggered when " + 238 buttonNames[i] + " pressed"); 239 240 mouseReleased = false; 241 mouseClicked = false; 242 if(isOEL7) { 243 SystemTrayIconHelper.openTrayIfNeeded(robot); 244 robot.mouseMove(iconPosition.x, iconPosition.y); 245 robot.click(buttonTypes[i]); 246 } else { 247 robot.mouseRelease(buttonTypes[i]); 248 } 249 if (! mouseReleased) { 250 synchronized (releaseLock) { 251 try { 252 releaseLock.wait(6000); 253 } catch (Exception e) { 254 } 255 } 256 } 257 if (! mouseReleased) 258 if (! SystemTrayIconHelper.skip(buttonTypes[i]) ) 259 throw new RuntimeException("FAIL: mouseReleased not triggered when " + 260 buttonNames[i] + " released"); 261 262 if (! mouseClicked) { 263 synchronized (clickLock) { 264 try { 265 clickLock.wait(6000); 266 } catch (Exception e) { 267 } 268 } 269 } 270 if (! mouseClicked) 271 throw new RuntimeException("FAIL: mouseClicked not triggered when " + 272 buttonNames[i] + " pressed & released"); 273 } 274 if(!isOEL7) { 275 mouseMoved = false; 276 robot.mouseMove(iconPosition.x + 100, iconPosition.y); 277 robot.glide(iconPosition.x, iconPosition.y); 278 279 if (!mouseMoved) 280 if (!SystemTrayIconHelper.skip(0)) 281 throw new RuntimeException("FAIL: mouseMoved not triggered even when mouse moved over the icon"); 282 } 283 } 284 } |