Skip to content

Commit 4bc1dc3

Browse files
manukumarvsPaul Hohensee
authored andcommitted
8023263: [TESTBUG] Test closed/java/awt/Focus/InactiveWindowTest/InactiveFocusRace fails due to not enough time to initialize graphic components
Backport-of: 5271448b3a013b2e3edcd619a4a3b975b292dae1
1 parent c357a2f commit 4bc1dc3

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

test/jdk/ProblemList.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,6 @@ java/awt/Focus/FrameMinimizeTest/FrameMinimizeTest.java 8016266 linux-x64
824824
java/awt/Frame/SizeMinimizedTest.java 8305915 linux-x64
825825
java/awt/PopupMenu/PopupHangTest.java 8340022 windows-all
826826
java/awt/Focus/MinimizeNonfocusableWindowTest.java 8024487 windows-all
827-
java/awt/Focus/InactiveFocusRace.java 8023263 linux-all
828827
java/awt/List/HandlingKeyEventIfMousePressedTest.java 6848358 macosx-all,windows-all
829828
java/awt/List/ListScrollbarCursorTest.java 8066410 generic-all
830829
java/awt/Checkbox/CheckboxBoxSizeTest.java 8340870 windows-all

test/jdk/java/awt/Focus/InactiveFocusRace.java

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 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
@@ -30,6 +30,7 @@
3030
*/
3131

3232
import java.awt.Button;
33+
import java.awt.EventQueue;
3334
import java.awt.FlowLayout;
3435
import java.awt.Frame;
3536
import java.awt.KeyboardFocusManager;
@@ -48,19 +49,27 @@ public class InactiveFocusRace {
4849
Button activeButton, inactiveButton1, inactiveButton2;
4950
Semaphore sema;
5051
final static int TIMEOUT = 10000;
52+
private static Robot robot;
5153

5254
public static void main(String[] args) throws Exception {
5355
try {
56+
robot = new Robot();
5457
InactiveFocusRace test = new InactiveFocusRace();
55-
test.init();
58+
EventQueue.invokeAndWait(() -> {
59+
test.init();
60+
});
61+
robot.waitForIdle();
62+
robot.delay(1000);
5663
test.start();
5764
} finally {
58-
if (activeFrame != null) {
59-
activeFrame.dispose();
60-
}
61-
if (inactiveFrame != null) {
62-
inactiveFrame.dispose();
63-
}
65+
EventQueue.invokeAndWait(() -> {
66+
if (activeFrame != null) {
67+
activeFrame.dispose();
68+
}
69+
if (inactiveFrame != null) {
70+
inactiveFrame.dispose();
71+
}
72+
});
6473
}
6574
}
6675

@@ -91,24 +100,40 @@ public void focusGained(FocusEvent e) {
91100
sema.raise();
92101
}
93102
});
103+
inactiveFrame.addWindowListener(new WindowAdapter() {
104+
public void windowActivated(WindowEvent e) {
105+
System.err.println("inactive Window activated");
106+
sema.raise();
107+
}
108+
});
94109
activeFrame.addWindowListener(new WindowAdapter() {
95110
public void windowActivated(WindowEvent e) {
96111
System.err.println("Window activated");
97112
sema.raise();
98113
}
99114
});
115+
inactiveFrame.setVisible(true);
100116
}
101117

102118
public void start() {
103-
Robot robot = null;
119+
120+
121+
// Wait for inactive frame to become active
104122
try {
105-
robot = new Robot();
106-
} catch (Exception e) {
107-
throw new RuntimeException("Unable to create robot");
123+
sema.doWait(TIMEOUT);
124+
} catch (InterruptedException ie) {
125+
throw new RuntimeException("Wait was interrupted");
126+
}
127+
if (!sema.getState()) {
128+
throw new RuntimeException("Frame doesn't become active on show");
108129
}
130+
sema.setState(false);
109131

110-
inactiveFrame.setVisible(true);
111-
activeFrame.setVisible(true);
132+
try {
133+
EventQueue.invokeAndWait(() -> activeFrame.setVisible(true));
134+
} catch (Exception e) {
135+
throw new RuntimeException("Interrupted active frame rendering");
136+
}
112137

113138
// Wait for active frame to become active
114139
try {

0 commit comments

Comments
 (0)