11/*
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.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2121 * questions.
2222 */
2323
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 ;
2532import java .awt .image .BufferedImage ;
2633
2734/*
3037 * @summary Check the return value of the getActionCommand method
3138 * of the ActionEvent triggered when TrayIcon is double clicked
3239 * (single clicked, on Mac)
33- * @author Dmitriy Ermashov ([email protected] ) 3440 * @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
3952 * @run main ActionCommand
4053 */
4154
@@ -44,32 +57,38 @@ public class ActionCommand {
4457 TrayIcon icon ;
4558 ExtendedRobot robot ;
4659
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+
5064 static boolean isMacOS = false ;
5165
5266 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+" );
7290 }
91+ new ActionCommand ().doTest ();
7392 }
7493
7594 void doTest () throws Exception {
@@ -95,7 +114,7 @@ void doTest() throws Exception {
95114
96115 icon .setActionCommand ("Sample Command" );
97116
98- if (! "Sample Command" .equals (icon .getActionCommand ()))
117+ if (!"Sample Command" .equals (icon .getActionCommand ()))
99118 throw new RuntimeException ("FAIL: getActionCommand did not return the correct value. " +
100119 icon .getActionCommand () + " Expected: Sample Command" );
101120
@@ -117,15 +136,15 @@ void doTest() throws Exception {
117136 actionPerformed = false ;
118137 SystemTrayIconHelper .doubleClick (robot );
119138
120- if (! actionPerformed ) {
139+ if (!actionPerformed ) {
121140 synchronized (actionLock ) {
122141 try {
123142 actionLock .wait (3000 );
124143 } catch (Exception e ) {
125144 }
126145 }
127146 }
128- if (! actionPerformed ) {
147+ if (!actionPerformed ) {
129148 throw new RuntimeException ("FAIL: ActionEvent not triggered when TrayIcon is " +(isMacOS ? "" : "double " )+"clicked" );
130149 } else if (! "Sample Command" .equals (actionCommand )) {
131150 throw new RuntimeException ("FAIL: ActionEvent.getActionCommand did not return the correct " +
@@ -140,7 +159,7 @@ void doTest() throws Exception {
140159 }
141160 });
142161
143- robot .mouseMove (0 , 0 );
162+ robot .mouseMove (100 , 0 );
144163 robot .waitForIdle ();
145164 robot .mouseMove (iconPosition .x , iconPosition .y );
146165 robot .waitForIdle ();
@@ -149,15 +168,15 @@ void doTest() throws Exception {
149168 actionCommand = null ;
150169 SystemTrayIconHelper .doubleClick (robot );
151170
152- if (! actionPerformed ) {
171+ if (!actionPerformed ) {
153172 synchronized (actionLock ) {
154173 try {
155174 actionLock .wait (3000 );
156175 } catch (Exception e ) {
157176 }
158177 }
159178 }
160- if (! actionPerformed ) {
179+ if (!actionPerformed ) {
161180 throw new RuntimeException ("FAIL: ActionEvent not triggered when ActionCommand set to " +
162181 "null and then TrayIcon is " +(isMacOS ? "" : "double " )+ "clicked" );
163182 } else if (actionCommand != null ) {
0 commit comments