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.*;
25 import java.awt.event.*;
26 import java.awt.image.BufferedImage;
27
28 /*
29 * @test
30 * @summary Check for MouseEvents with all mouse buttons
31 * @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
32 * @library ../../../../lib/testlibrary ../
33 * @build ExtendedRobot SystemTrayIconHelper
34 * @run main ModalityTest
35 */
36 public class ModalityTest {
37
38 TrayIcon icon;
39 ExtendedRobot robot;
40 Dialog d;
41
42 boolean actionPerformed = false;
43
44 private boolean dialogVisible = false;
45 private Object dialogLock = new Object();
46
47 Object actionLock = new Object();
48 Object pressLock = new Object();
49 Object releaseLock = new Object();
50 Object clickLock = new Object();
51 Object moveLock = new Object();
52 static final int clickDelay = 50;
53
54 boolean mousePressed = false;
55 boolean mouseReleased = false;
56 boolean mouseClicked = false;
57 boolean mouseMoved = false;
63 };
64
65 String[] buttonNames = {
66 "BUTTON1",
67 "BUTTON2",
68 "BUTTON3"
69 };
70
71 public static void main(String[] args) throws Exception {
72 if (! SystemTray.isSupported()) {
73 System.out.println("SystemTray not supported on the platform under test. " +
74 "Marking the test passed");
75 } else {
76 if (System.getProperty("os.name").toLowerCase().startsWith("win"))
77 System.err.println("Test can fail if the icon hides to a tray icons pool " +
78 "in Windows 7, which is behavior by default.\n" +
79 "Set \"Right mouse click\" -> \"Customize notification icons\" -> " +
80 "\"Always show all icons and notifications on the taskbar\" true " +
81 "to avoid this problem. Or change behavior only for Java SE tray " +
82 "icon and rerun test.");
83
84 new ModalityTest().doTest();
85 }
86 }
87
88 public ModalityTest() throws Exception {
89 robot = new ExtendedRobot();
90 EventQueue.invokeLater(this::initializeGUI);
91 }
92
93 void initializeGUI() {
94 SystemTray tray = SystemTray.getSystemTray();
95 icon = new TrayIcon(new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB), "Sample Icon");
96 icon.addActionListener(event -> {
97 actionPerformed = true;
98 synchronized (actionLock) {
99 try {
100 actionLock.notifyAll();
101 } catch (Exception e) {
102 }
103 }
208 d.setVisible(true);
209 }
210
211 void doTest() throws Exception {
212
213 if (! dialogVisible) {
214 synchronized (dialogLock) {
215 try {
216 dialogLock.wait(3000);
217 } catch (Exception e) {
218 }
219 }
220 }
221
222 if (! dialogVisible)
223 throw new RuntimeException("ERROR: TIMEOUT: The thread in EDT not yet complete");
224
225 Point iconPosition = SystemTrayIconHelper.getTrayIconLocation(icon);
226 if (iconPosition == null)
227 throw new RuntimeException("Unable to find the icon location!");
228
229 if (! d.isVisible())
230 throw new RuntimeException("FAIL: The modal dialog is not yet visible");
231
232 robot.mouseMove(iconPosition.x, iconPosition.y);
233 robot.waitForIdle(2000);
234
235 SystemTrayIconHelper.doubleClick(robot);
236
237 if (! actionPerformed) {
238 synchronized (actionLock) {
239 try {
240 actionLock.wait(3000);
241 } catch (Exception e) {
242 }
243 }
244 }
245 if (! actionPerformed)
246 throw new RuntimeException("FAIL: ActionEvent not triggered when TrayIcon is double clicked");
247
248 for (int i = 0; i < buttonTypes.length; i++) {
249 mousePressed = false;
250 robot.mousePress(buttonTypes[i]);
251
252 if (! mousePressed) {
253 synchronized (pressLock) {
254 try {
255 pressLock.wait(3000);
256 } catch (Exception e) {
257 }
258 }
259 }
260 if (! mousePressed)
261 if (! SystemTrayIconHelper.skip(buttonTypes[i]) )
262 throw new RuntimeException("FAIL: mousePressed not triggered when " +
263 buttonNames[i] + " pressed");
264
265 mouseReleased = false;
266 mouseClicked = false;
267 robot.mouseRelease(buttonTypes[i]);
268
269 if (! mouseReleased) {
270 synchronized (releaseLock) {
271 try {
272 releaseLock.wait(3000);
273 } catch (Exception e) {
274 }
275 }
276 }
277 if (! mouseReleased)
278 throw new RuntimeException("FAIL: mouseReleased not triggered when " +
279 buttonNames[i] + " released");
280
281 if (! mouseClicked) {
282 synchronized (clickLock) {
283 try {
284 clickLock.wait(3000);
285 } catch (Exception e) {
286 }
287 }
288 }
289 if (! mouseClicked)
290 throw new RuntimeException("FAIL: mouseClicked not triggered when " +
291 buttonNames[i] + " pressed & released");
292 }
293
294 mouseMoved = false;
295 robot.mouseMove(iconPosition.x, iconPosition.y);
296 robot.glide(iconPosition.x + 100, iconPosition.y);
297
298 if (! mouseMoved)
299 if (! SystemTrayIconHelper.skip(0) )
300 throw new RuntimeException("FAIL: mouseMoved not triggered even when mouse moved over the icon");
301 }
302 }
|
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.*;
25 import java.awt.event.*;
26 import java.awt.image.BufferedImage;
27
28 /*
29 * @test
30 * @summary Check for MouseEvents with all mouse buttons
31 * @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
32 * @library ../../../../lib/testlibrary ../
33 * @build ExtendedRobot SystemTrayIconHelper
34 * @run main ModalityTest
35 */
36 public class ModalityTest {
37
38 private static boolean isOEL7;
39 TrayIcon icon;
40 ExtendedRobot robot;
41 Dialog d;
42
43 boolean actionPerformed = false;
44
45 private boolean dialogVisible = false;
46 private Object dialogLock = new Object();
47
48 Object actionLock = new Object();
49 Object pressLock = new Object();
50 Object releaseLock = new Object();
51 Object clickLock = new Object();
52 Object moveLock = new Object();
53 static final int clickDelay = 50;
54
55 boolean mousePressed = false;
56 boolean mouseReleased = false;
57 boolean mouseClicked = false;
58 boolean mouseMoved = false;
64 };
65
66 String[] buttonNames = {
67 "BUTTON1",
68 "BUTTON2",
69 "BUTTON3"
70 };
71
72 public static void main(String[] args) throws Exception {
73 if (! SystemTray.isSupported()) {
74 System.out.println("SystemTray not supported on the platform under test. " +
75 "Marking the test passed");
76 } else {
77 if (System.getProperty("os.name").toLowerCase().startsWith("win"))
78 System.err.println("Test can fail if the icon hides to a tray icons pool " +
79 "in Windows 7, which is behavior by default.\n" +
80 "Set \"Right mouse click\" -> \"Customize notification icons\" -> " +
81 "\"Always show all icons and notifications on the taskbar\" true " +
82 "to avoid this problem. Or change behavior only for Java SE tray " +
83 "icon and rerun test.");
84 isOEL7 = System.getProperty("os.name").toLowerCase()
85 .contains("linux") && System.getProperty("os.version")
86 .toLowerCase().contains("el7");
87 new ModalityTest().doTest();
88 }
89 }
90
91 public ModalityTest() throws Exception {
92 robot = new ExtendedRobot();
93 EventQueue.invokeLater(this::initializeGUI);
94 }
95
96 void initializeGUI() {
97 SystemTray tray = SystemTray.getSystemTray();
98 icon = new TrayIcon(new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB), "Sample Icon");
99 icon.addActionListener(event -> {
100 actionPerformed = true;
101 synchronized (actionLock) {
102 try {
103 actionLock.notifyAll();
104 } catch (Exception e) {
105 }
106 }
211 d.setVisible(true);
212 }
213
214 void doTest() throws Exception {
215
216 if (! dialogVisible) {
217 synchronized (dialogLock) {
218 try {
219 dialogLock.wait(3000);
220 } catch (Exception e) {
221 }
222 }
223 }
224
225 if (! dialogVisible)
226 throw new RuntimeException("ERROR: TIMEOUT: The thread in EDT not yet complete");
227
228 Point iconPosition = SystemTrayIconHelper.getTrayIconLocation(icon);
229 if (iconPosition == null)
230 throw new RuntimeException("Unable to find the icon location!");
231 if (isOEL7) {
232 // close tray
233 robot.mouseMove(100,100);
234 robot.click(InputEvent.BUTTON1_MASK);
235 robot.waitForIdle(2000);
236 }
237
238 if (! d.isVisible())
239 throw new RuntimeException("FAIL: The modal dialog is not yet visible");
240
241 robot.mouseMove(iconPosition.x, iconPosition.y);
242 robot.waitForIdle(2000);
243
244 if(!isOEL7) {
245 SystemTrayIconHelper.doubleClick(robot);
246
247 if (!actionPerformed) {
248 synchronized (actionLock) {
249 try {
250 actionLock.wait(3000);
251 } catch (Exception e) {
252 }
253 }
254 }
255 if (!actionPerformed)
256 throw new RuntimeException("FAIL: ActionEvent not triggered when TrayIcon is double clicked");
257 }
258
259 for (int i = 0; i < buttonTypes.length; i++) {
260 mousePressed = false;
261 if(isOEL7) {
262 SystemTrayIconHelper.openTrayIfNeeded(robot);
263 robot.mouseMove(iconPosition.x, iconPosition.y);
264 robot.click(buttonTypes[i]);
265 } else {
266 robot.mousePress(buttonTypes[i]);
267 }
268
269 if (! mousePressed) {
270 synchronized (pressLock) {
271 try {
272 pressLock.wait(6000);
273 } catch (Exception e) {
274 }
275 }
276 }
277 if (! mousePressed)
278 if (! SystemTrayIconHelper.skip(buttonTypes[i]) )
279 throw new RuntimeException("FAIL: mousePressed not triggered when " +
280 buttonNames[i] + " pressed");
281
282 mouseReleased = false;
283 mouseClicked = false;
284 if(isOEL7) {
285 SystemTrayIconHelper.openTrayIfNeeded(robot);
286 robot.mouseMove(iconPosition.x, iconPosition.y);
287 robot.click(buttonTypes[i]);
288 } else {
289 robot.mouseRelease(buttonTypes[i]);
290 }
291
292 if (! mouseReleased) {
293 synchronized (releaseLock) {
294 try {
295 releaseLock.wait(6000);
296 } catch (Exception e) {
297 }
298 }
299 }
300 if (! mouseReleased)
301 throw new RuntimeException("FAIL: mouseReleased not triggered when " +
302 buttonNames[i] + " released");
303
304 if (! mouseClicked) {
305 synchronized (clickLock) {
306 try {
307 clickLock.wait(6000);
308 } catch (Exception e) {
309 }
310 }
311 }
312 if (! mouseClicked)
313 throw new RuntimeException("FAIL: mouseClicked not triggered when " +
314 buttonNames[i] + " pressed & released");
315 }
316 if (!isOEL7) {
317 mouseMoved = false;
318 robot.mouseMove(iconPosition.x, iconPosition.y);
319 robot.glide(iconPosition.x + 100, iconPosition.y);
320
321 if (!mouseMoved)
322 if (!SystemTrayIconHelper.skip(0))
323 throw new RuntimeException("FAIL: mouseMoved not triggered even when mouse moved over the icon");
324 }
325 }
326 }
|