11/*
2- * Copyright (c) 2005, 2024 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2005, 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
3434import java .awt .event .KeyEvent ;
3535import java .util .concurrent .CountDownLatch ;
3636
37+ import static java .util .concurrent .TimeUnit .SECONDS ;
38+
3739/*
3840 * @test
3941 * @bug 5097243
4042 * @summary Tests that FileDialog can be closed by ESC any time
4143 * @key headful
4244 * @run main DoubleActionESC
45+ * @run main/othervm -Dsun.awt.disableGtkFileDialogs=true DoubleActionESC
4346 */
4447
4548public class DoubleActionESC {
@@ -49,47 +52,48 @@ public class DoubleActionESC {
4952 private static Robot robot ;
5053 private static volatile Point p ;
5154 private static volatile Dimension d ;
52- private static volatile CountDownLatch latch ;
5355 private static final int REPEAT_COUNT = 2 ;
56+ private static final long LATCH_TIMEOUT = 10 ;
5457
55- public static void main (String [] args ) throws Exception {
56- latch = new CountDownLatch (1 );
58+ private static final CountDownLatch latch = new CountDownLatch (REPEAT_COUNT );
5759
60+ public static void main (String [] args ) throws Exception {
5861 robot = new Robot ();
59- robot .setAutoDelay (100 );
62+ robot .setAutoDelay (50 );
6063 try {
6164 EventQueue .invokeAndWait (() -> {
6265 createAndShowUI ();
6366 });
6467
68+ robot .waitForIdle ();
6569 robot .delay (1000 );
70+
6671 EventQueue .invokeAndWait (() -> {
6772 p = showBtn .getLocationOnScreen ();
6873 d = showBtn .getSize ();
6974 });
7075
7176 for (int i = 0 ; i < REPEAT_COUNT ; ++i ) {
72- Thread thread = new Thread (() -> {
73- robot .mouseMove (p .x + d .width / 2 , p .y + d .height / 2 );
74- robot .mousePress (InputEvent .BUTTON1_DOWN_MASK );
75- robot .mouseRelease (InputEvent .BUTTON1_DOWN_MASK );
76- });
77- thread .start ();
78- robot .delay (3000 );
77+ robot .mouseMove (p .x + d .width / 2 , p .y + d .height / 2 );
78+ robot .mousePress (InputEvent .BUTTON1_DOWN_MASK );
79+ robot .mouseRelease (InputEvent .BUTTON1_DOWN_MASK );
80+ robot .waitForIdle ();
81+ robot .delay (1000 );
7982
80- Thread thread1 = new Thread (() -> {
81- robot .keyPress (KeyEvent .VK_ESCAPE );
82- robot .keyRelease (KeyEvent .VK_ESCAPE );
83- robot .waitForIdle ();
84- });
85- thread1 .start ();
86- robot .delay (3000 );
83+ robot .keyPress (KeyEvent .VK_ESCAPE );
84+ robot .keyRelease (KeyEvent .VK_ESCAPE );
85+ robot .waitForIdle ();
86+ robot .delay (1000 );
8787 }
8888
89- latch .await ();
90- if (fd .isVisible ()) {
91- throw new RuntimeException ("File Dialog is not closed" );
89+ if (!latch .await (LATCH_TIMEOUT , SECONDS )) {
90+ throw new RuntimeException ("Test failed: Latch timeout reached" );
9291 }
92+ EventQueue .invokeAndWait (() -> {
93+ if (fd .isVisible ()) {
94+ throw new RuntimeException ("File Dialog is not closed" );
95+ }
96+ });
9397 } finally {
9498 EventQueue .invokeAndWait (() -> {
9599 if (f != null ) {
0 commit comments