Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ java/awt/print/PrinterJob/PrintTextTest.java 8148334 generic-all
java/awt/font/TextLayout/TestJustification.java 8250791 macosx-all
java/awt/TrayIcon/DragEventSource/DragEventSource.java 8252242 macosx-all
java/awt/FileDialog/DefaultFocusOwner/DefaultFocusOwner.java 7187728 macosx-all,linux-all
java/awt/FileDialog/DoubleActionESC.java 8356981 linux-all
java/awt/print/PageFormat/Orient.java 8016055 macosx-all
java/awt/TextArea/TextAreaCursorTest/HoveringAndDraggingTest.java 8024986 macosx-all,linux-all
java/awt/TextComponent/CorrectTextComponentSelectionTest.java 8237220 macosx-all
Expand Down
48 changes: 26 additions & 22 deletions test/jdk/java/awt/FileDialog/DoubleActionESC.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 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
Expand Down Expand Up @@ -34,12 +34,15 @@
import java.awt.event.KeyEvent;
import java.util.concurrent.CountDownLatch;

import static java.util.concurrent.TimeUnit.SECONDS;

/*
* @test
* @bug 5097243
* @summary Tests that FileDialog can be closed by ESC any time
* @key headful
* @run main DoubleActionESC
* @run main/othervm -Dsun.awt.disableGtkFileDialogs=true DoubleActionESC
*/

public class DoubleActionESC {
Expand All @@ -49,47 +52,48 @@ public class DoubleActionESC {
private static Robot robot;
private static volatile Point p;
private static volatile Dimension d;
private static volatile CountDownLatch latch;
private static final int REPEAT_COUNT = 2;
private static final long LATCH_TIMEOUT = 10;

public static void main(String[] args) throws Exception {
latch = new CountDownLatch(1);
private static final CountDownLatch latch = new CountDownLatch(REPEAT_COUNT);

public static void main(String[] args) throws Exception {
robot = new Robot();
robot.setAutoDelay(100);
robot.setAutoDelay(50);
try {
EventQueue.invokeAndWait(() -> {
createAndShowUI();
});

robot.waitForIdle();
robot.delay(1000);

EventQueue.invokeAndWait(() -> {
p = showBtn.getLocationOnScreen();
d = showBtn.getSize();
});

for (int i = 0; i < REPEAT_COUNT; ++i) {
Thread thread = new Thread(() -> {
robot.mouseMove(p.x + d.width / 2, p.y + d.height / 2);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
});
thread.start();
robot.delay(3000);
robot.mouseMove(p.x + d.width / 2, p.y + d.height / 2);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.waitForIdle();
robot.delay(1000);

Thread thread1 = new Thread(() -> {
robot.keyPress(KeyEvent.VK_ESCAPE);
robot.keyRelease(KeyEvent.VK_ESCAPE);
robot.waitForIdle();
});
thread1.start();
robot.delay(3000);
robot.keyPress(KeyEvent.VK_ESCAPE);
robot.keyRelease(KeyEvent.VK_ESCAPE);
robot.waitForIdle();
robot.delay(1000);
}

latch.await();
if (fd.isVisible()) {
throw new RuntimeException("File Dialog is not closed");
if (!latch.await(LATCH_TIMEOUT, SECONDS)) {
throw new RuntimeException("Test failed: Latch timeout reached");
}
EventQueue.invokeAndWait(() -> {
if (fd.isVisible()) {
throw new RuntimeException("File Dialog is not closed");
}
});
} finally {
EventQueue.invokeAndWait(() -> {
if (f != null) {
Expand Down