forked from openjdk/jdk24u
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport 6f4fc82149b52dd91289fe42def7d1cacad31212
- Loading branch information
duke
committed
Feb 14, 2025
1 parent
e3d6b0a
commit cc33457
Showing
4 changed files
with
182 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2007, 2025, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
|
@@ -21,7 +21,14 @@ | |
* questions. | ||
*/ | ||
|
||
import java.awt.*; | ||
import jdk.test.lib.Platform; | ||
import jtreg.SkippedException; | ||
|
||
import java.awt.AWTException; | ||
import java.awt.EventQueue; | ||
import java.awt.Point; | ||
import java.awt.SystemTray; | ||
import java.awt.TrayIcon; | ||
import java.awt.image.BufferedImage; | ||
|
||
/* | ||
|
@@ -30,12 +37,18 @@ | |
* @summary Check the return value of the getActionCommand method | ||
* of the ActionEvent triggered when TrayIcon is double clicked | ||
* (single clicked, on Mac) | ||
* @author Dmitriy Ermashov ([email protected]) | ||
* @modules java.desktop/java.awt:open | ||
* @library /lib/client ../ | ||
* @library /java/awt/patchlib | ||
* @build java.desktop/java.awt.Helper | ||
* @build ExtendedRobot SystemTrayIconHelper | ||
* @library | ||
* /java/awt/patchlib | ||
* /java/awt/TrayIcon | ||
* /lib/client | ||
* /test/lib | ||
* @build | ||
* java.desktop/java.awt.Helper | ||
* jdk.test.lib.Platform | ||
* jtreg.SkippedException | ||
* ExtendedRobot | ||
* SystemTrayIconHelper | ||
* @run main ActionCommand | ||
*/ | ||
|
||
|
@@ -44,32 +57,38 @@ public class ActionCommand { | |
TrayIcon icon; | ||
ExtendedRobot robot; | ||
|
||
boolean actionPerformed = false; | ||
Object actionLock = new Object(); | ||
String actionCommand = null; | ||
volatile boolean actionPerformed = false; | ||
volatile String actionCommand = null; | ||
final Object actionLock = new Object(); | ||
|
||
static boolean isMacOS = false; | ||
|
||
public static void main(String[] args) throws Exception { | ||
if (! SystemTray.isSupported()) { | ||
System.out.println("SystemTray not supported on the platform under test. " + | ||
"Marking the test passed"); | ||
} else { | ||
if (System.getProperty("os.name").toLowerCase().startsWith("win")) { | ||
System.err.println("Test can fail if the icon hides to a tray icons pool " + | ||
"in Windows 7, which is behavior by default.\n" + | ||
"Set \"Right mouse click\" -> \"Customize notification icons\" -> " + | ||
"\"Always show all icons and notifications on the taskbar\" true to " + | ||
"avoid this problem. Or change behavior only for Java SE tray icon " + | ||
"and rerun test."); | ||
} else if (System.getProperty("os.name").toLowerCase().startsWith("mac")){ | ||
isMacOS = true; | ||
} else if (SystemTrayIconHelper.isOel7orLater()) { | ||
System.out.println("OEL 7 doesn't support double click in " + | ||
"systray. Skipped"); | ||
return; | ||
} | ||
new ActionCommand().doTest(); | ||
if (Platform.isOnWayland()) { | ||
// The current robot implementation does not support | ||
// clicking in the system tray area. | ||
throw new SkippedException("Skipped on Wayland"); | ||
} | ||
|
||
if (!SystemTray.isSupported()) { | ||
throw new SkippedException("SystemTray is not supported on this platform."); | ||
} | ||
|
||
if (Platform.isWindows()) { | ||
System.err.println("Test can fail if the icon hides to a tray icons pool " + | ||
"in Windows 7, which is behavior by default.\n" + | ||
"Set \"Right mouse click\" -> \"Customize notification icons\" -> " + | ||
"\"Always show all icons and notifications on the taskbar\" true to " + | ||
"avoid this problem. Or change behavior only for Java SE tray icon " + | ||
"and rerun test."); | ||
} else if (Platform.isOSX()){ | ||
isMacOS = true; | ||
} else if (SystemTrayIconHelper.isOel7orLater()) { | ||
System.out.println("OEL 7 doesn't support double click in " + | ||
"systray. Skipped"); | ||
throw new SkippedException("Skipped on OEL 7+"); | ||
} | ||
new ActionCommand().doTest(); | ||
} | ||
|
||
void doTest() throws Exception { | ||
|
@@ -95,7 +114,7 @@ void doTest() throws Exception { | |
|
||
icon.setActionCommand("Sample Command"); | ||
|
||
if (! "Sample Command".equals(icon.getActionCommand())) | ||
if (!"Sample Command".equals(icon.getActionCommand())) | ||
throw new RuntimeException("FAIL: getActionCommand did not return the correct value. " + | ||
icon.getActionCommand() + " Expected: Sample Command"); | ||
|
||
|
@@ -117,15 +136,15 @@ void doTest() throws Exception { | |
actionPerformed = false; | ||
SystemTrayIconHelper.doubleClick(robot); | ||
|
||
if (! actionPerformed) { | ||
if (!actionPerformed) { | ||
synchronized (actionLock) { | ||
try { | ||
actionLock.wait(3000); | ||
} catch (Exception e) { | ||
} | ||
} | ||
} | ||
if (! actionPerformed) { | ||
if (!actionPerformed) { | ||
throw new RuntimeException("FAIL: ActionEvent not triggered when TrayIcon is "+(isMacOS? "" : "double ")+"clicked"); | ||
} else if (! "Sample Command".equals(actionCommand)) { | ||
throw new RuntimeException("FAIL: ActionEvent.getActionCommand did not return the correct " + | ||
|
@@ -140,7 +159,7 @@ void doTest() throws Exception { | |
} | ||
}); | ||
|
||
robot.mouseMove(0, 0); | ||
robot.mouseMove(100, 0); | ||
robot.waitForIdle(); | ||
robot.mouseMove(iconPosition.x, iconPosition.y); | ||
robot.waitForIdle(); | ||
|
@@ -149,15 +168,15 @@ void doTest() throws Exception { | |
actionCommand = null; | ||
SystemTrayIconHelper.doubleClick(robot); | ||
|
||
if (! actionPerformed) { | ||
if (!actionPerformed) { | ||
synchronized (actionLock) { | ||
try { | ||
actionLock.wait(3000); | ||
} catch (Exception e) { | ||
} | ||
} | ||
} | ||
if (! actionPerformed) { | ||
if (!actionPerformed) { | ||
throw new RuntimeException("FAIL: ActionEvent not triggered when ActionCommand set to " + | ||
"null and then TrayIcon is "+(isMacOS? "" : "double ")+ "clicked"); | ||
} else if (actionCommand != null) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
|
@@ -20,14 +20,15 @@ | |
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
import jdk.test.lib.Platform; | ||
import jtreg.SkippedException; | ||
|
||
import java.awt.TrayIcon; | ||
import java.awt.SystemTray; | ||
import java.awt.EventQueue; | ||
import java.awt.Point; | ||
import java.awt.AWTException; | ||
import java.awt.event.MouseEvent; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.awt.event.InputEvent; | ||
import java.awt.event.MouseAdapter; | ||
import java.awt.image.BufferedImage; | ||
|
@@ -37,35 +38,48 @@ | |
* @key headful | ||
* @summary Check if a action performed event is received when TrayIcon display | ||
* message is clicked on. | ||
* @author Shashidhara Veerabhadraiah ([email protected]) | ||
* @modules java.desktop/java.awt:open | ||
* @library /java/awt/patchlib | ||
* @library /lib/client ../ | ||
* @build java.desktop/java.awt.Helper | ||
* @build ExtendedRobot SystemTrayIconHelper | ||
* @library | ||
* /java/awt/patchlib | ||
* /java/awt/TrayIcon | ||
* /lib/client | ||
* /test/lib | ||
* @build | ||
* java.desktop/java.awt.Helper | ||
* jdk.test.lib.Platform | ||
* jtreg.SkippedException | ||
* ExtendedRobot | ||
* SystemTrayIconHelper | ||
* @run main TrayIconPopupClickTest | ||
*/ | ||
|
||
public class TrayIconPopupClickTest { | ||
|
||
TrayIcon icon; | ||
ExtendedRobot robot; | ||
boolean actionPerformed = false; | ||
volatile boolean actionPerformed = false; | ||
|
||
public static void main(String[] args) throws Exception { | ||
if (Platform.isOnWayland()) { | ||
// The current robot implementation does not support | ||
// clicking in the system tray area. | ||
throw new SkippedException("Skipped on Wayland"); | ||
} | ||
|
||
if (!SystemTray.isSupported()) { | ||
System.out.println("SystemTray not supported on the platform under test. " + | ||
"Marking the test passed"); | ||
} else { | ||
if (System.getProperty("os.name").toLowerCase().startsWith("win")) | ||
System.err.println("Test can fail if the icon hides to a tray icons pool " + | ||
"in Windows 7/10, which is behavior by default.\n" + | ||
"Set \"Right mouse click\" -> \"Customize notification icons\" -> " + | ||
"\"Always show all icons and notifications on the taskbar\" true " + | ||
"to avoid this problem. Or change behavior only for Java SE " + | ||
"tray icon."); | ||
new TrayIconPopupClickTest().doTest(); | ||
throw new SkippedException("SystemTray is not supported on this platform."); | ||
} | ||
|
||
if (Platform.isWindows()) { | ||
System.err.println("Test can fail if the icon hides to a tray icons pool " + | ||
"in Windows 7/10, which is behavior by default.\n" + | ||
"Set \"Right mouse click\" -> \"Customize notification icons\" -> " + | ||
"\"Always show all icons and notifications on the taskbar\" true " + | ||
"to avoid this problem. Or change behavior only for Java SE " + | ||
"tray icon."); | ||
} | ||
|
||
new TrayIconPopupClickTest().doTest(); | ||
} | ||
|
||
TrayIconPopupClickTest() throws Exception { | ||
|
@@ -89,33 +103,26 @@ public void mousePressed(MouseEvent event) { | |
throw new RuntimeException(e); | ||
} | ||
|
||
icon.getActionCommand(); | ||
icon.addActionListener(new ActionListener() { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
actionPerformed = true; | ||
} | ||
}); | ||
icon.addActionListener(e -> actionPerformed = true); | ||
} | ||
|
||
void doTest() throws Exception { | ||
|
||
Point iconPosition = SystemTrayIconHelper.getTrayIconLocation(icon); | ||
if (iconPosition == null) | ||
throw new RuntimeException("Unable to find the icon location!"); | ||
|
||
robot.mouseMove(iconPosition.x, iconPosition.y); | ||
robot.waitForIdle(); | ||
robot.mousePress(InputEvent.BUTTON1_MASK); | ||
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); | ||
robot.delay(50); | ||
robot.mouseRelease(InputEvent.BUTTON1_MASK); | ||
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); | ||
robot.delay(50); | ||
|
||
robot.mouseMove(iconPosition.x, iconPosition.y + 10); | ||
robot.waitForIdle(); | ||
robot.mousePress(InputEvent.BUTTON1_MASK); | ||
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); | ||
robot.delay(50); | ||
robot.mouseRelease(InputEvent.BUTTON1_MASK); | ||
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); | ||
robot.delay(50); | ||
|
||
if (!actionPerformed) | ||
|
Oops, something went wrong.