1
1
/*
2
- * Copyright (c) 2007, 2022 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2007, 2025 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
21
21
* questions.
22
22
*/
23
23
24
- import java .awt .*;
24
+ import jdk .test .lib .Platform ;
25
+ import jtreg .SkippedException ;
26
+
27
+ import java .awt .AWTException ;
28
+ import java .awt .EventQueue ;
29
+ import java .awt .Point ;
30
+ import java .awt .SystemTray ;
31
+ import java .awt .TrayIcon ;
25
32
import java .awt .image .BufferedImage ;
26
33
27
34
/*
30
37
* @summary Check the return value of the getActionCommand method
31
38
* of the ActionEvent triggered when TrayIcon is double clicked
32
39
* (single clicked, on Mac)
33
- * @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
34
40
* @modules java.desktop/java.awt:open
35
- * @library /lib/client ../
36
- * @library /java/awt/patchlib
37
- * @build java.desktop/java.awt.Helper
38
- * @build ExtendedRobot SystemTrayIconHelper
41
+ * @library
42
+ * /java/awt/patchlib
43
+ * /java/awt/TrayIcon
44
+ * /lib/client
45
+ * /test/lib
46
+ * @build
47
+ * java.desktop/java.awt.Helper
48
+ * jdk.test.lib.Platform
49
+ * jtreg.SkippedException
50
+ * ExtendedRobot
51
+ * SystemTrayIconHelper
39
52
* @run main ActionCommand
40
53
*/
41
54
@@ -44,32 +57,38 @@ public class ActionCommand {
44
57
TrayIcon icon ;
45
58
ExtendedRobot robot ;
46
59
47
- boolean actionPerformed = false ;
48
- Object actionLock = new Object ();
49
- String actionCommand = null ;
60
+ volatile boolean actionPerformed = false ;
61
+ volatile String actionCommand = null ;
62
+ final Object actionLock = new Object ();
63
+
50
64
static boolean isMacOS = false ;
51
65
52
66
public static void main (String [] args ) throws Exception {
53
- if (! SystemTray .isSupported ()) {
54
- System .out .println ("SystemTray not supported on the platform under test. " +
55
- "Marking the test passed" );
56
- } else {
57
- if (System .getProperty ("os.name" ).toLowerCase ().startsWith ("win" )) {
58
- System .err .println ("Test can fail if the icon hides to a tray icons pool " +
59
- "in Windows 7, which is behavior by default.\n " +
60
- "Set \" Right mouse click\" -> \" Customize notification icons\" -> " +
61
- "\" Always show all icons and notifications on the taskbar\" true to " +
62
- "avoid this problem. Or change behavior only for Java SE tray icon " +
63
- "and rerun test." );
64
- } else if (System .getProperty ("os.name" ).toLowerCase ().startsWith ("mac" )){
65
- isMacOS = true ;
66
- } else if (SystemTrayIconHelper .isOel7orLater ()) {
67
- System .out .println ("OEL 7 doesn't support double click in " +
68
- "systray. Skipped" );
69
- return ;
70
- }
71
- new ActionCommand ().doTest ();
67
+ if (Platform .isOnWayland ()) {
68
+ // The current robot implementation does not support
69
+ // clicking in the system tray area.
70
+ throw new SkippedException ("Skipped on Wayland" );
71
+ }
72
+
73
+ if (!SystemTray .isSupported ()) {
74
+ throw new SkippedException ("SystemTray is not supported on this platform." );
75
+ }
76
+
77
+ if (Platform .isWindows ()) {
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 to " +
82
+ "avoid this problem. Or change behavior only for Java SE tray icon " +
83
+ "and rerun test." );
84
+ } else if (Platform .isOSX ()){
85
+ isMacOS = true ;
86
+ } else if (SystemTrayIconHelper .isOel7orLater ()) {
87
+ System .out .println ("OEL 7 doesn't support double click in " +
88
+ "systray. Skipped" );
89
+ throw new SkippedException ("Skipped on OEL 7+" );
72
90
}
91
+ new ActionCommand ().doTest ();
73
92
}
74
93
75
94
void doTest () throws Exception {
@@ -95,7 +114,7 @@ void doTest() throws Exception {
95
114
96
115
icon .setActionCommand ("Sample Command" );
97
116
98
- if (! "Sample Command" .equals (icon .getActionCommand ()))
117
+ if (!"Sample Command" .equals (icon .getActionCommand ()))
99
118
throw new RuntimeException ("FAIL: getActionCommand did not return the correct value. " +
100
119
icon .getActionCommand () + " Expected: Sample Command" );
101
120
@@ -117,15 +136,15 @@ void doTest() throws Exception {
117
136
actionPerformed = false ;
118
137
SystemTrayIconHelper .doubleClick (robot );
119
138
120
- if (! actionPerformed ) {
139
+ if (!actionPerformed ) {
121
140
synchronized (actionLock ) {
122
141
try {
123
142
actionLock .wait (3000 );
124
143
} catch (Exception e ) {
125
144
}
126
145
}
127
146
}
128
- if (! actionPerformed ) {
147
+ if (!actionPerformed ) {
129
148
throw new RuntimeException ("FAIL: ActionEvent not triggered when TrayIcon is " +(isMacOS ? "" : "double " )+"clicked" );
130
149
} else if (! "Sample Command" .equals (actionCommand )) {
131
150
throw new RuntimeException ("FAIL: ActionEvent.getActionCommand did not return the correct " +
@@ -140,7 +159,7 @@ void doTest() throws Exception {
140
159
}
141
160
});
142
161
143
- robot .mouseMove (0 , 0 );
162
+ robot .mouseMove (100 , 0 );
144
163
robot .waitForIdle ();
145
164
robot .mouseMove (iconPosition .x , iconPosition .y );
146
165
robot .waitForIdle ();
@@ -149,15 +168,15 @@ void doTest() throws Exception {
149
168
actionCommand = null ;
150
169
SystemTrayIconHelper .doubleClick (robot );
151
170
152
- if (! actionPerformed ) {
171
+ if (!actionPerformed ) {
153
172
synchronized (actionLock ) {
154
173
try {
155
174
actionLock .wait (3000 );
156
175
} catch (Exception e ) {
157
176
}
158
177
}
159
178
}
160
- if (! actionPerformed ) {
179
+ if (!actionPerformed ) {
161
180
throw new RuntimeException ("FAIL: ActionEvent not triggered when ActionCommand set to " +
162
181
"null and then TrayIcon is " +(isMacOS ? "" : "double " )+ "clicked" );
163
182
} else if (actionCommand != null ) {
0 commit comments