Skip to content

Commit a60e912

Browse files
author
Pankaj Bansal
committed
8198626: java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.html fails on mac
Reviewed-by: serb
1 parent dde959d commit a60e912

File tree

2 files changed

+42
-16
lines changed

2 files changed

+42
-16
lines changed

test/jdk/ProblemList.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ java/awt/Frame/ShapeNotSetSometimes/ShapeNotSetSometimes.java 8144030 macosx-all
145145
java/awt/grab/EmbeddedFrameTest1/EmbeddedFrameTest1.java 7080150 macosx-all
146146
java/awt/event/InputEvent/EventWhenTest/EventWhenTest.java 8168646 generic-all
147147
java/awt/KeyboardFocusmanager/TypeAhead/SubMenuShowTest/SubMenuShowTest.java 8273520 macosx-all
148-
java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.java 8198626 macosx-all
149148
java/awt/Mixing/AWT_Mixing/HierarchyBoundsListenerMixingTest.java 8049405 macosx-all
150149
java/awt/Mixing/AWT_Mixing/OpaqueOverlappingChoice.java 8048171 generic-all
151150
java/awt/Mixing/AWT_Mixing/JMenuBarOverlapping.java 8159451 linux-all,windows-all,macosx-all

test/jdk/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.java

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2021, 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
@@ -26,14 +26,29 @@
2626
@key headful
2727
@bug 4799136
2828
@summary Tests that type-ahead for dialog works and doesn't block program
29-
@library ../../regtesthelpers
30-
@modules java.desktop/sun.awt
31-
@build Util
3229
@run main TestDialogTypeAhead
3330
*/
3431

35-
import java.awt.*;
36-
import java.awt.event.*;
32+
33+
import java.awt.AWTEvent;
34+
import java.awt.Button;
35+
import java.awt.Component;
36+
import java.awt.DefaultKeyboardFocusManager;
37+
import java.awt.Dialog;
38+
import java.awt.Dimension;
39+
import java.awt.EventQueue;
40+
import java.awt.Frame;
41+
import java.awt.KeyboardFocusManager;
42+
import java.awt.Point;
43+
import java.awt.Robot;
44+
import java.awt.Toolkit;
45+
import java.awt.event.AWTEventListener;
46+
import java.awt.event.ActionEvent;
47+
import java.awt.event.ActionListener;
48+
import java.awt.event.FocusAdapter;
49+
import java.awt.event.FocusEvent;
50+
import java.awt.event.KeyAdapter;
51+
import java.awt.event.KeyEvent;
3752
import java.lang.reflect.InvocationTargetException;
3853

3954
public class TestDialogTypeAhead {
@@ -49,8 +64,17 @@ public class TestDialogTypeAhead {
4964

5065
public static void main(final String[] args) {
5166
TestDialogTypeAhead app = new TestDialogTypeAhead();
52-
app.init();
53-
app.start();
67+
try {
68+
app.init();
69+
app.start();
70+
} finally {
71+
if (d != null) {
72+
d.dispose();
73+
}
74+
if (f != null) {
75+
f.dispose();
76+
}
77+
}
5478
}
5579

5680
public void init()
@@ -73,13 +97,12 @@ public void eventDispatched(AWTEvent e) {
7397
ok.addKeyListener(new KeyAdapter() {
7498
public void keyPressed(KeyEvent e) {
7599
System.err.println("OK pressed");
76-
d.dispose();
77-
f.dispose();
78100
// Typed-ahead key events should only be accepted if
79101
// they arrive after FOCUS_GAINED
80102
if (gotFocus) {
81103
pressSema.raise();
82104
}
105+
83106
}
84107
});
85108
ok.addFocusListener(new FocusAdapter() {
@@ -112,6 +135,7 @@ public void start ()
112135
{
113136
try {
114137
robot = new Robot();
138+
robot.setAutoDelay(100);
115139
} catch (Exception e) {
116140
throw new RuntimeException("Can't create robot:" + e);
117141
}
@@ -128,6 +152,7 @@ public void start ()
128152

129153
robot.keyPress(KeyEvent.VK_SPACE);
130154
robot.keyRelease(KeyEvent.VK_SPACE);
155+
131156
try {
132157
robotSema.doWait(1000);
133158
} catch (InterruptedException ie) {
@@ -149,13 +174,13 @@ public void start ()
149174
if (!pressSema.getState()) {
150175
throw new RuntimeException("Type-ahead doesn't work");
151176
}
152-
153177
}// start()
154178

155-
private void moveMouseOver(Container c) {
179+
private void moveMouseOver(Component c) {
156180
Point p = c.getLocationOnScreen();
157181
Dimension d = c.getSize();
158-
robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + (int)(d.getHeight()/2));
182+
robot.mouseMove(p.x + (int)(d.getWidth()/2),
183+
p.y + (int)(d.getHeight()/2));
159184
}
160185
private void waitForIdle() {
161186
try {
@@ -209,7 +234,10 @@ public void focusGained(FocusEvent fe) {
209234
}
210235
comp.removeFocusListener(fa);
211236
if (!comp.isFocusOwner()) {
212-
throw new RuntimeException("Can't make " + comp + " focused, current owner is " + KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());
237+
throw new RuntimeException("Can't make " + comp + " focused,"
238+
+ "current owner is "
239+
+ KeyboardFocusManager
240+
.getCurrentKeyboardFocusManager().getFocusOwner());
213241
}
214242
}
215243

@@ -257,4 +285,3 @@ protected synchronized void enqueueKeyEvents(long after,
257285
}
258286
}
259287
}// class TestDialogTypeAhead
260-

0 commit comments

Comments
 (0)