diff --git a/test/jdk/java/awt/TrayIcon/DisposeInActionEventTest/DisposeInActionEventTest.html b/test/jdk/java/awt/TrayIcon/DisposeInActionEventTest/DisposeInActionEventTest.html deleted file mode 100644 index fde3c620a01..00000000000 --- a/test/jdk/java/awt/TrayIcon/DisposeInActionEventTest/DisposeInActionEventTest.html +++ /dev/null @@ -1,49 +0,0 @@ - - - - - -
-See the dialog box (usually in upper left corner) for instructions
- - - - diff --git a/test/jdk/java/awt/TrayIcon/DisposeInActionEventTest/DisposeInActionEventTest.java b/test/jdk/java/awt/TrayIcon/DisposeInActionEventTest/DisposeInActionEventTest.java index 1d9ff597d6b..6f17541cbe5 100644 --- a/test/jdk/java/awt/TrayIcon/DisposeInActionEventTest/DisposeInActionEventTest.java +++ b/test/jdk/java/awt/TrayIcon/DisposeInActionEventTest/DisposeInActionEventTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024, 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,76 +21,78 @@ * questions. */ - -/* - test - @bug 6299866 - @summary Tests that no NPE is thrown when the tray icon is disposed from the - handler of action event caused by clicking on this icon. - @library ../../regtesthelpers - @build Sysout - @author artem.ananiev: area=awt.tray - @run applet/manual=yesno DisposeInActionEventTest.html -*/ - -import java.applet.*; - -import java.awt.*; -import java.awt.image.*; +import java.awt.AWTException; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.SystemTray; +import java.awt.TrayIcon; +import java.awt.image.BufferedImage; +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; import jdk.test.lib.Platform; -import test.java.awt.regtesthelpers.Sysout; -public class DisposeInActionEventTest extends Applet { - private boolean traySupported; +/* + * @test + * @bug 6299866 8316931 + * @summary Tests that no NPE is thrown when the tray icon is disposed from the + * handler of action event caused by clicking on this icon. + * @library ../../regtesthelpers /test/lib + * @build PassFailJFrame jtreg.SkippedException + * @run main/manual DisposeInActionEventTest + */ - private SystemTray systemTray; - private TrayIcon trayIcon; +public class DisposeInActionEventTest { + private static JTextArea textArea; + private static SystemTray systemTray; + private static TrayIcon trayIcon; - public void init() { - this.setLayout(new BorderLayout()); - - String[] instructions; - traySupported = SystemTray.isSupported(); - if (!traySupported) { - instructions = new String[]{ - "The test cannot be run because SystemTray is not supported.", - "Simply press PASS button." - }; - } else { - String clickInstruction; - if (Platform.isOSX()) { - clickInstruction = "right"; - } else { - clickInstruction = "left"; - } - instructions = new String[]{ - "When the test starts, it adds the icon to the tray aread. If you", - " don't see a tray icon, please, make sure that the tray area", - " (also called Taskbar Status Area on MS Windows, Notification", - " Area on Gnome or System Tray on KDE) is visible.", - "Double-click with " + clickInstruction + " button on the tray icon to trigger the", - " action event. Brief information about action events is printed", - " below. After each action event the tray icon is removed from", - " the tray and then added back in a second.", - "The test performs some automatic checks when removing the icon. If", - " something is wrong the corresponding message is displayed below.", - " Repeat double-clicks several times. If no 'Test FAILED' messages", - " are printed, press PASS button else FAIL button." - }; + public static void main(String[] args) throws Exception { + if (!SystemTray.isSupported()) { + throw new jtreg.SkippedException("The test cannot be run because " + + "SystemTray is not supported."); + } + String clickInstruction = + (Platform.isOSX()) ? "Right-click" : "Double click (left mouse button)"; + + String instructions = "When the test starts, it adds the icon to the tray area. If you\n" + + " don't see a tray icon, please, make sure that the tray area\n" + + " (also called Taskbar Status Area on MS Windows, Notification\n" + + " Area on Gnome or System Tray on KDE) is visible.\n\n" + + clickInstruction + " the tray icon to trigger the\n" + + " action event. Brief information about action events is printed\n" + + " in the frame. After each action event, the tray icon is removed from\n" + + " the tray and then added back in a second.\n\n" + + "The test checks if any exceptions are thrown when removing and\n" + + " re-adding the icon. If something is wrong, the test will automatically fail.\n" + + " Repeat clicks several times Then press PASS button."; + + try { + PassFailJFrame.builder() + .title("DisposeInActionEventTest") + .instructions(instructions) + .testTimeOut(10) + .rows(15) + .columns(45) + .testUI(DisposeInActionEventTest::showFrameAndIcon) + .build() + .awaitAndCheck(); + } finally { + if (systemTray != null) { + systemTray.remove(trayIcon); + } } - Sysout.createDialogWithInstructions(instructions); } - @Override - public void start() { - setSize(200, 200); - setVisible(true); - validate(); + private static JFrame showFrameAndIcon() { + JFrame frame = new JFrame("Event Message Display"); + frame.setLayout(new BorderLayout()); - if (!traySupported) return; - - System.setProperty("sun.awt.exception.handler", "DisposeInActionEventTest$EDTExceptionHandler"); + textArea = new JTextArea(); + frame.getContentPane().add(new JScrollPane(textArea)); + frame.setSize(400, 200); BufferedImage img = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB); Graphics g = img.createGraphics(); @@ -104,26 +106,26 @@ public class DisposeInActionEventTest extends Applet { trayIcon = new TrayIcon(img); trayIcon.setImageAutoSize(true); trayIcon.addActionListener(ev -> { - Sysout.println(ev.toString()); + textArea.append(ev + "\n"); systemTray.remove(trayIcon); new Thread(() -> { try { Thread.sleep(1000); systemTray.add(trayIcon); } catch (AWTException | InterruptedException e) { - Sysout.println(e.toString()); - Sysout.println("!!! The test coudn't be performed !!!"); + e.printStackTrace(); + PassFailJFrame.forceFail("Exception caught: " + e.getMessage()); } - } - ).start(); - } - ); + }).start(); + }); try { systemTray.add(trayIcon); } catch (AWTException e) { - Sysout.println(e.toString()); - Sysout.println("!!! The test coudn't be performed !!!"); + e.printStackTrace(); + PassFailJFrame.forceFail("Exception caught: " + e.getMessage()); } + + return frame; } } diff --git a/test/jdk/java/awt/TrayIcon/ShowAfterDisposeTest/ShowAfterDisposeTest.java b/test/jdk/java/awt/TrayIcon/ShowAfterDisposeTest/ShowAfterDisposeTest.java index 7b1d917c710..cfa01be92b3 100644 --- a/test/jdk/java/awt/TrayIcon/ShowAfterDisposeTest/ShowAfterDisposeTest.java +++ b/test/jdk/java/awt/TrayIcon/ShowAfterDisposeTest/ShowAfterDisposeTest.java @@ -21,15 +21,6 @@ * questions. */ -/* - * @test - * @bug 6384984 8004032 - * @library ../../regtesthelpers /test/lib - * @build PassFailJFrame jtreg.SkippedException - * @summary TrayIcon try to dispay a tooltip when is not visible - * @run main/manual ShowAfterDisposeTest -*/ - import java.awt.AWTException; import java.awt.BorderLayout; import java.awt.Color; @@ -42,7 +33,18 @@ import java.awt.image.BufferedImage; import javax.swing.JFrame; import javax.swing.SwingUtilities; +/* + * @test + * @bug 6384984 8004032 8316931 + * @library ../../regtesthelpers /test/lib + * @build PassFailJFrame jtreg.SkippedException + * @summary TrayIcon try to dispay a tooltip when is not visible + * @run main/manual ShowAfterDisposeTest + */ public class ShowAfterDisposeTest { + private static SystemTray tray; + private static TrayIcon icon; + public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { throw new jtreg.SkippedException("The test cannot be run because SystemTray is not supported."); @@ -64,15 +66,21 @@ public class ShowAfterDisposeTest { "3) If the bug is reproducible then the test will fail without assistance.\n" + "4) Just press the 'pass' button."; - PassFailJFrame.builder() - .title("Test Instructions Frame") - .instructions(instructions) - .testTimeOut(10) - .rows(10) - .columns(45) - .testUI(ShowAfterDisposeTest::showFrameAndIcon) - .build() - .awaitAndCheck(); + try { + PassFailJFrame.builder() + .title("Test Instructions Frame") + .instructions(instructions) + .testTimeOut(10) + .rows(10) + .columns(45) + .testUI(ShowAfterDisposeTest::showFrameAndIcon) + .build() + .awaitAndCheck(); + } finally { + if (tray != null) { + tray.remove(icon); + } + } } private static JFrame showFrameAndIcon() { @@ -87,8 +95,8 @@ public class ShowAfterDisposeTest { g.fillRect(6, 6, 20, 20); g.dispose(); - final SystemTray tray = SystemTray.getSystemTray(); - final TrayIcon icon = new TrayIcon(img); + tray = SystemTray.getSystemTray(); + icon = new TrayIcon(img); icon.setImageAutoSize(true); icon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) {