Skip to content

Commit 117ce56

Browse files
committed
8348675: TrayIcon tests fail in Ubuntu 24.10 Wayland
Backport-of: 6f4fc82149b52dd91289fe42def7d1cacad31212
1 parent 4216ad6 commit 117ce56

File tree

4 files changed

+182
-113
lines changed

4 files changed

+182
-113
lines changed

test/jdk/java/awt/TrayIcon/ActionCommand/ActionCommand.java

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -21,7 +21,14 @@
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;
2532
import java.awt.image.BufferedImage;
2633

2734
/*
@@ -30,12 +37,18 @@
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 (dmitriy.ermashov@oracle.com)
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) {

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

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -21,6 +21,9 @@
2121
* questions.
2222
*/
2323

24+
import jdk.test.lib.Platform;
25+
import jtreg.SkippedException;
26+
2427
import java.awt.EventQueue;
2528
import java.awt.Point;
2629
import java.awt.SystemTray;
@@ -37,27 +40,36 @@
3740
* or single clicked with button 3 on Mac OS X
3841
* or single clicked with button 1 on rest.
3942
* @modules java.desktop/java.awt:open
40-
* @library /java/awt/patchlib
41-
* @library /lib/client ../
42-
* @build java.desktop/java.awt.Helper
43-
* @build ExtendedRobot SystemTrayIconHelper
43+
* @library
44+
* /java/awt/patchlib
45+
* /java/awt/TrayIcon
46+
* /lib/client
47+
* /test/lib
48+
* @build
49+
* java.desktop/java.awt.Helper
50+
* jdk.test.lib.Platform
51+
* jtreg.SkippedException
52+
* ExtendedRobot
53+
* SystemTrayIconHelper
4454
* @run main TrayIconMouseTest
4555
*/
4656

4757
public class TrayIconMouseTest {
4858

4959
TrayIcon icon;
5060
ExtendedRobot robot;
51-
boolean actionPerformed = false;
52-
Object actionLock = new Object();
61+
62+
volatile boolean actionPerformed = false;
63+
final Object actionLock = new Object();
64+
5365
static boolean isMacOS = false;
5466
static boolean isWinOS = false;
5567
static boolean isOelOS = false;
5668
String caption = "Sample Icon";
5769
int[] buttonTypes = {
58-
InputEvent.BUTTON1_MASK,
59-
InputEvent.BUTTON2_MASK,
60-
InputEvent.BUTTON3_MASK
70+
InputEvent.BUTTON1_DOWN_MASK,
71+
InputEvent.BUTTON2_DOWN_MASK,
72+
InputEvent.BUTTON3_DOWN_MASK
6173
};
6274
String[] buttonNames = {
6375
"BUTTON1",
@@ -66,20 +78,24 @@ public class TrayIconMouseTest {
6678
};
6779

6880
public static void main(String[] args) throws Exception {
81+
if (Platform.isOnWayland()) {
82+
// The current robot implementation does not support
83+
// clicking in the system tray area.
84+
throw new SkippedException("Skipped on Wayland");
85+
}
86+
6987
if (!SystemTray.isSupported()) {
70-
System.out.println("SystemTray not supported on the platform "
71-
+ "under test. Marking the test passed");
88+
throw new SkippedException("SystemTray is not supported on this platform.");
89+
}
90+
91+
if (Platform.isOSX()) {
92+
isMacOS = true;
93+
} else if (Platform.isWindows()) {
94+
isWinOS = true;
7295
} else {
73-
String osName = System.getProperty("os.name").toLowerCase();
74-
if (osName.startsWith("mac")) {
75-
isMacOS = true;
76-
} else if (osName.startsWith("win")) {
77-
isWinOS = true;
78-
} else {
79-
isOelOS = SystemTrayIconHelper.isOel7orLater();
80-
}
81-
new TrayIconMouseTest().doTest();
96+
isOelOS = SystemTrayIconHelper.isOel7orLater();
8297
}
98+
new TrayIconMouseTest().doTest();
8399
}
84100

85101
TrayIconMouseTest() throws Exception {

test/jdk/java/awt/TrayIcon/TrayIconPopup/TrayIconPopupClickTest.java

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 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
@@ -20,14 +20,15 @@
2020
* or visit www.oracle.com if you need additional information or have any
2121
* questions.
2222
*/
23+
import jdk.test.lib.Platform;
24+
import jtreg.SkippedException;
25+
2326
import java.awt.TrayIcon;
2427
import java.awt.SystemTray;
2528
import java.awt.EventQueue;
2629
import java.awt.Point;
2730
import java.awt.AWTException;
2831
import java.awt.event.MouseEvent;
29-
import java.awt.event.ActionEvent;
30-
import java.awt.event.ActionListener;
3132
import java.awt.event.InputEvent;
3233
import java.awt.event.MouseAdapter;
3334
import java.awt.image.BufferedImage;
@@ -37,35 +38,48 @@
3738
* @key headful
3839
* @summary Check if a action performed event is received when TrayIcon display
3940
* message is clicked on.
40-
* @author Shashidhara Veerabhadraiah (shashidhara.veerabhadraiah@oracle.com)
4141
* @modules java.desktop/java.awt:open
42-
* @library /java/awt/patchlib
43-
* @library /lib/client ../
44-
* @build java.desktop/java.awt.Helper
45-
* @build ExtendedRobot SystemTrayIconHelper
42+
* @library
43+
* /java/awt/patchlib
44+
* /java/awt/TrayIcon
45+
* /lib/client
46+
* /test/lib
47+
* @build
48+
* java.desktop/java.awt.Helper
49+
* jdk.test.lib.Platform
50+
* jtreg.SkippedException
51+
* ExtendedRobot
52+
* SystemTrayIconHelper
4653
* @run main TrayIconPopupClickTest
4754
*/
4855

4956
public class TrayIconPopupClickTest {
5057

5158
TrayIcon icon;
5259
ExtendedRobot robot;
53-
boolean actionPerformed = false;
60+
volatile boolean actionPerformed = false;
5461

5562
public static void main(String[] args) throws Exception {
63+
if (Platform.isOnWayland()) {
64+
// The current robot implementation does not support
65+
// clicking in the system tray area.
66+
throw new SkippedException("Skipped on Wayland");
67+
}
68+
5669
if (!SystemTray.isSupported()) {
57-
System.out.println("SystemTray not supported on the platform under test. " +
58-
"Marking the test passed");
59-
} else {
60-
if (System.getProperty("os.name").toLowerCase().startsWith("win"))
61-
System.err.println("Test can fail if the icon hides to a tray icons pool " +
62-
"in Windows 7/10, which is behavior by default.\n" +
63-
"Set \"Right mouse click\" -> \"Customize notification icons\" -> " +
64-
"\"Always show all icons and notifications on the taskbar\" true " +
65-
"to avoid this problem. Or change behavior only for Java SE " +
66-
"tray icon.");
67-
new TrayIconPopupClickTest().doTest();
70+
throw new SkippedException("SystemTray is not supported on this platform.");
71+
}
72+
73+
if (Platform.isWindows()) {
74+
System.err.println("Test can fail if the icon hides to a tray icons pool " +
75+
"in Windows 7/10, which is behavior by default.\n" +
76+
"Set \"Right mouse click\" -> \"Customize notification icons\" -> " +
77+
"\"Always show all icons and notifications on the taskbar\" true " +
78+
"to avoid this problem. Or change behavior only for Java SE " +
79+
"tray icon.");
6880
}
81+
82+
new TrayIconPopupClickTest().doTest();
6983
}
7084

7185
TrayIconPopupClickTest() throws Exception {
@@ -89,33 +103,26 @@ public void mousePressed(MouseEvent event) {
89103
throw new RuntimeException(e);
90104
}
91105

92-
icon.getActionCommand();
93-
icon.addActionListener(new ActionListener() {
94-
@Override
95-
public void actionPerformed(ActionEvent e) {
96-
actionPerformed = true;
97-
}
98-
});
106+
icon.addActionListener(e -> actionPerformed = true);
99107
}
100108

101109
void doTest() throws Exception {
102-
103110
Point iconPosition = SystemTrayIconHelper.getTrayIconLocation(icon);
104111
if (iconPosition == null)
105112
throw new RuntimeException("Unable to find the icon location!");
106113

107114
robot.mouseMove(iconPosition.x, iconPosition.y);
108115
robot.waitForIdle();
109-
robot.mousePress(InputEvent.BUTTON1_MASK);
116+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
110117
robot.delay(50);
111-
robot.mouseRelease(InputEvent.BUTTON1_MASK);
118+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
112119
robot.delay(50);
113120

114121
robot.mouseMove(iconPosition.x, iconPosition.y + 10);
115122
robot.waitForIdle();
116-
robot.mousePress(InputEvent.BUTTON1_MASK);
123+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
117124
robot.delay(50);
118-
robot.mouseRelease(InputEvent.BUTTON1_MASK);
125+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
119126
robot.delay(50);
120127

121128
if (!actionPerformed)

0 commit comments

Comments
 (0)