Skip to content

Commit 21e67e5

Browse files
author
Pankaj Bansal
committedOct 20, 2020
8225790: Two NestedDialogs tests fail on Ubuntu
Reviewed-by: serb
1 parent 017d151 commit 21e67e5

File tree

4 files changed

+178
-707
lines changed

4 files changed

+178
-707
lines changed
 

‎test/jdk/java/awt/Dialog/NestedDialogs/Modal/NestedModalDialogTest.java

+86-149
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2020, 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
@@ -23,15 +23,10 @@
2323

2424
/**
2525
* @test
26-
* @bug 8155740
26+
* @bug 8160266 8225790
2727
* @key headful
2828
* @summary See <rdar://problem/3429130>: Events: actionPerformed() method not
2929
* called when it is button is clicked (system load related)
30-
* @summary com.apple.junit.java.awt.Frame
31-
* @library ../../../regtesthelpers
32-
* @build VisibilityValidator
33-
* @build Util
34-
* @build Waypoint
3530
* @run main NestedModalDialogTest
3631
*/
3732

@@ -44,140 +39,103 @@
4439
//////////////////////////////////////////////////////////////////////////////
4540
// classes necessary for this test
4641

47-
import java.awt.*;
48-
import java.awt.event.*;
49-
import java.util.Enumeration;
50-
51-
import test.java.awt.regtesthelpers.Waypoint;
52-
import test.java.awt.regtesthelpers.VisibilityValidator;
53-
import test.java.awt.regtesthelpers.Util;
42+
import java.awt.Button;
43+
import java.awt.Component;
44+
import java.awt.Dialog;
45+
import java.awt.Frame;
46+
import java.awt.GridBagLayout;
47+
import java.awt.Panel;
48+
import java.awt.Point;
49+
import java.awt.Rectangle;
50+
import java.awt.Robot;
51+
import java.awt.TextField;
52+
import java.awt.event.ActionEvent;
53+
import java.awt.event.InputEvent;
54+
import java.awt.event.KeyEvent;
5455

5556
public class NestedModalDialogTest {
56-
57-
Waypoint[] event_checkpoint = new Waypoint[3];
58-
VisibilityValidator[] win_checkpoint = new VisibilityValidator[2];
59-
60-
IntermediateDialog interDiag;
61-
TextDialog txtDiag;
57+
private static Frame frame;
58+
private static IntermediateDialog interDiag;
59+
private static TextDialog txtDiag;
6260

6361
// Global variables so the robot thread can locate things.
64-
Button[] robot_button = new Button[2];
65-
TextField robot_text = null;
66-
static Robot _robot = null;
67-
68-
/*
69-
* @throws InterruptedException
70-
* @throws WaypointException
71-
*/
72-
public void testModalDialogs() throws Exception {
73-
Frame frame = null;
74-
String result = "";
75-
Robot robot = getRobot();
62+
private static Button[] robot_button = new Button[2];
63+
private static TextField robot_text = null;
64+
private static Robot robot = null;
7665

77-
event_checkpoint[0] = new Waypoint(); // "-Launch 1-"
78-
event_checkpoint[1] = new Waypoint(); // "-Launch 2-"
79-
80-
// Thread.currentThread().setName("NestedModalDialogTest Thread");
81-
// launch first frame with firstButton
82-
frame = new StartFrame();
83-
VisibilityValidator.setVisibleAndConfirm(frame);
84-
Util.clickOnComp(robot_button[0], robot);
85-
86-
// Dialog must be created and onscreen before we proceed.
87-
// The event_checkpoint waits for the Dialog to be created.
88-
// The win_checkpoint waits for the Dialog to be visible.
89-
event_checkpoint[0].requireClear("TestFrame actionPerformed() never "
90-
+ "called, see <rdar://problem/3429130>");
91-
win_checkpoint[0].requireVisible();
92-
Util.clickOnComp(robot_button[1], robot);
93-
94-
// Again, the Dialog must be created and onscreen before we proceed.
95-
// The event_checkpoint waits for the Dialog to be created.
96-
// The win_checkpoint waits for the Dialog to be visible.
97-
event_checkpoint[1].requireClear("IntermediateDialog actionPerformed() "
98-
+ "never called, see <rdar://problem/3429130>");
99-
win_checkpoint[1].requireVisible();
100-
Util.clickOnComp(robot_text, robot);
101-
102-
// I'm really not sure whether the click is needed for focus
103-
// but since it's asynchronous, as is the actually gaining of focus
104-
// we might as well do our best
105-
try {
106-
EventQueue.invokeAndWait(new Runnable() {
107-
public void run() {
66+
private static void blockTillDisplayed(Component comp) {
67+
Point p = null;
68+
while (p == null) {
69+
try {
70+
p = comp.getLocationOnScreen();
71+
} catch (IllegalStateException e) {
72+
try {
73+
Thread.sleep(500);
74+
} catch (InterruptedException ie) {
10875
}
109-
});
110-
} catch (Exception e) {
76+
}
11177
}
78+
}
11279

113-
robot.keyPress(KeyEvent.VK_SHIFT);
114-
115-
robot.keyPress(KeyEvent.VK_H);
116-
robot.waitForIdle();
117-
robot.keyRelease(KeyEvent.VK_H);
118-
119-
robot.keyRelease(KeyEvent.VK_SHIFT);
120-
121-
robot.keyPress(KeyEvent.VK_E);
122-
robot.waitForIdle();
123-
robot.keyRelease(KeyEvent.VK_E);
124-
125-
robot.keyPress(KeyEvent.VK_L);
80+
private static void clickOnComp(Component comp) {
81+
Rectangle bounds = new Rectangle(comp.getLocationOnScreen(), comp.getSize());
82+
robot.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
12683
robot.waitForIdle();
127-
robot.keyRelease(KeyEvent.VK_L);
128-
129-
robot.keyPress(KeyEvent.VK_L);
84+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
85+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
13086
robot.waitForIdle();
131-
robot.keyRelease(KeyEvent.VK_L);
132-
133-
robot.keyPress(KeyEvent.VK_O);
134-
robot.waitForIdle();
135-
robot.keyRelease(KeyEvent.VK_O);
136-
137-
//
138-
// NOTE THAT WE MAY HAVE MORE SYNCHRONIZATION WORK TO DO HERE.
139-
// CURRENTLY THERE IS NO GUARANTEE THAT THE KEYEVENT THAT THAT
140-
// TYPES THE 'O' HAS BEEN PROCESSED BEFORE WE GET THE RESULT
141-
//
142-
// This is a (lame) attempt at waiting for the last typeKey events to
143-
// propagate. It's not quite right because robot uses
144-
// CGRemoteOperations, which are asynchronous. But that's why I put in
145-
// the pause
146-
try {
147-
EventQueue.invokeAndWait(new Runnable() {
148-
public void run() {
149-
}
150-
});
151-
} catch (Exception e) {
152-
}
153-
154-
// Need to call this before the dialog that robot_text is in is disposed
155-
result = robot_text.getText();
156-
157-
Thread.sleep(50); // shouldn't need this, but pause adds stability
158-
// Click Close box of modal dialog with textField
159-
Util.clickOnComp(txtDiag, robot);
160-
161-
Thread.sleep(50); // shouldn't need this, but pause adds stability
162-
// Click Close box of intermediate modal dialog
163-
Util.clickOnComp(interDiag, robot);
164-
165-
Thread.sleep(50); // shouldn't need this, but pause adds stability
166-
// Click Close box of intermediate modal dialog
167-
Util.clickOnComp(frame, robot);
168-
169-
String expected = "Hello";
17087
}
17188

172-
private static Robot getRobot() {
173-
if (_robot == null) {
174-
try {
175-
_robot = new Robot();
176-
} catch (AWTException e) {
177-
throw new RuntimeException("Robot creation failed");
89+
public void testModalDialogs() throws Exception {
90+
try {
91+
robot = new Robot();
92+
robot.setAutoDelay(100);
93+
94+
// launch first frame with firstButton
95+
frame = new StartFrame();
96+
blockTillDisplayed(frame);
97+
clickOnComp(robot_button[0]);
98+
99+
// Dialog must be created and onscreen before we proceed.
100+
blockTillDisplayed(interDiag);
101+
clickOnComp(robot_button[1]);
102+
103+
// Again, the Dialog must be created and onscreen before we proceed.
104+
blockTillDisplayed(robot_text);
105+
clickOnComp(robot_text);
106+
107+
robot.keyPress(KeyEvent.VK_SHIFT);
108+
robot.keyPress(KeyEvent.VK_H);
109+
robot.keyRelease(KeyEvent.VK_H);
110+
robot.keyRelease(KeyEvent.VK_SHIFT);
111+
robot.waitForIdle();
112+
113+
robot.keyPress(KeyEvent.VK_E);
114+
robot.keyRelease(KeyEvent.VK_E);
115+
robot.waitForIdle();
116+
117+
robot.keyPress(KeyEvent.VK_L);
118+
robot.keyRelease(KeyEvent.VK_L);
119+
robot.waitForIdle();
120+
121+
robot.keyPress(KeyEvent.VK_L);
122+
robot.keyRelease(KeyEvent.VK_L);
123+
robot.waitForIdle();
124+
125+
robot.keyPress(KeyEvent.VK_O);
126+
robot.keyRelease(KeyEvent.VK_O);
127+
robot.waitForIdle();
128+
} finally {
129+
if (frame != null) {
130+
frame.dispose();
131+
}
132+
if (interDiag != null) {
133+
interDiag.dispose();
134+
}
135+
if (txtDiag != null) {
136+
txtDiag.dispose();
178137
}
179138
}
180-
return _robot;
181139
}
182140

183141
//////////////////// Start Frame ///////////////////
@@ -198,26 +156,19 @@ public StartFrame() {
198156
but.addActionListener(new java.awt.event.ActionListener() {
199157
public void actionPerformed(ActionEvent e) {
200158
interDiag = new IntermediateDialog(StartFrame.this);
201-
win_checkpoint[0] = new VisibilityValidator(interDiag);
202159
interDiag.setSize(300, 200);
203160

204161
// may need listener to watch this move.
205162
interDiag.setLocation(getLocationOnScreen());
206163
interDiag.pack();
207-
event_checkpoint[0].clear();
208164
interDiag.setVisible(true);
209165
}
210166
});
211167
Panel pan = new Panel();
212168
pan.add(but);
213169
add(pan);
170+
setVisible(true);
214171
robot_button[0] = but;
215-
addWindowListener(new WindowAdapter() {
216-
public void windowClosing(WindowEvent e) {
217-
setVisible(false);
218-
dispose();
219-
}
220-
});
221172
}
222173
}
223174

@@ -234,22 +185,14 @@ public IntermediateDialog(Frame parent) {
234185
but.addActionListener(new java.awt.event.ActionListener() {
235186
public void actionPerformed(ActionEvent e) {
236187
txtDiag = new TextDialog(m_parent);
237-
win_checkpoint[1] = new VisibilityValidator(txtDiag);
238188
txtDiag.setSize(300, 100);
239-
event_checkpoint[1].clear();
240189
txtDiag.setVisible(true);
241190
}
242191
});
243192
Panel pan = new Panel();
244193
pan.add(but);
245194
add(pan);
246195
pack();
247-
addWindowListener(new WindowAdapter() {
248-
public void windowClosing(WindowEvent e) {
249-
setVisible(false);
250-
dispose();
251-
}
252-
});
253196

254197
// The robot needs to know about us, so set global
255198
robot_button[1] = but;
@@ -266,12 +209,6 @@ public TextDialog(Dialog parent) {
266209
pan.add(txt);
267210
add(pan);
268211
pack();
269-
addWindowListener(new WindowAdapter() {
270-
public void windowClosing(WindowEvent e) {
271-
setVisible(false);
272-
dispose();
273-
}
274-
});
275212

276213
// The robot needs to know about us, so set global
277214
robot_text = txt;

‎test/jdk/java/awt/Dialog/NestedDialogs/Modeless/NestedModelessDialogTest.java

+92-146
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2020, 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
@@ -23,16 +23,11 @@
2323

2424
/**
2525
* @test
26-
* @bug 8155740
26+
* @bug 8160266 8225790
2727
* @key headful
2828
* @summary See <rdar://problem/3429130>: Events: actionPerformed() method not
2929
* called when it is button is clicked (system load related)
30-
* @summary com.apple.junit.java.awt.Frame
31-
* @library ../../../regtesthelpers
32-
* @build VisibilityValidator
33-
* @build Util
34-
* @build Waypoint
35-
* @run main NestedModelessDialogTest -Xlog:exception
30+
* @run main NestedModelessDialogTest
3631
*/
3732

3833
/////////////////////////////////////////////////////////////////////////////
@@ -43,138 +38,110 @@
4338
// are successfully able to write into this Nested Modeless Dialog
4439
/////////////////////////////////////////////////////////////////////////////
4540
// classes necessary for this test
46-
import java.awt.*;
47-
import java.awt.event.*;
48-
import java.util.Enumeration;
4941

50-
import test.java.awt.regtesthelpers.Util;
51-
import test.java.awt.regtesthelpers.VisibilityValidator;
52-
import test.java.awt.regtesthelpers.Waypoint;
42+
import java.awt.Button;
43+
import java.awt.Component;
44+
import java.awt.Dialog;
45+
import java.awt.Frame;
46+
import java.awt.GridBagLayout;
47+
import java.awt.Panel;
48+
import java.awt.Point;
49+
import java.awt.Rectangle;
50+
import java.awt.Robot;
51+
import java.awt.TextField;
52+
import java.awt.event.ActionEvent;
53+
import java.awt.event.InputEvent;
54+
import java.awt.event.KeyEvent;
5355

5456
public class NestedModelessDialogTest {
57+
private static Frame frame;
58+
private static IntermediateDialog interDiag;
59+
private static TextDialog txtDiag;
5560

56-
Waypoint[] event_checkpoint = new Waypoint[3];
57-
VisibilityValidator[] win_checkpoint = new VisibilityValidator[2];
61+
// Global variables so the robot thread can locate things.
62+
private static Button[] robot_button = new Button[2];
63+
private static TextField robot_text = null;
64+
private static Robot robot;
5865

59-
IntermediateDialog interDiag;
60-
TextDialog txtDiag;
66+
private static void blockTillDisplayed(Component comp) {
67+
Point p = null;
68+
while (p == null) {
69+
try {
70+
p = comp.getLocationOnScreen();
71+
} catch (IllegalStateException e) {
72+
try {
73+
Thread.sleep(500);
74+
} catch (InterruptedException ie) {
75+
}
76+
}
77+
}
78+
}
6179

62-
// Global variables so the robot thread can locate things.
63-
Button[] robot_button = new Button[2];
64-
TextField robot_text = null;
65-
static Robot _robot = null;
80+
private static void clickOnComp(Component comp) {
81+
Rectangle bounds = new Rectangle(comp.getLocationOnScreen(), comp.getSize());
82+
robot.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
83+
robot.waitForIdle();
84+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
85+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
86+
robot.waitForIdle();
87+
}
6688

6789
/**
6890
* Get called by test harness
6991
*
7092
* @throws Exception
7193
*/
7294
public void testModelessDialogs() throws Exception {
73-
Frame frame = null;
74-
String result = "";
75-
Robot robot = getRobot();
76-
77-
event_checkpoint[0] = new Waypoint(); // "-Launch 1-"
78-
event_checkpoint[1] = new Waypoint(); // "-Launch 2-"
79-
80-
// launch first frame with fistButton
81-
frame = new StartFrame();
82-
VisibilityValidator.setVisibleAndConfirm(frame);
83-
Util.clickOnComp(robot_button[0], robot);
84-
85-
// Dialog must be created and onscreen before we proceed.
86-
// The event_checkpoint waits for the Dialog to be created.
87-
// The win_checkpoint waits for the Dialog to be visible.
88-
event_checkpoint[0].requireClear();
89-
win_checkpoint[0].requireVisible();
90-
Util.clickOnComp(robot_button[1], robot);
91-
92-
// Again, the Dialog must be created and onscreen before we proceed.
93-
// The event_checkpoint waits for the Dialog to be created.
94-
// The win_checkpoint waits for the Dialog to be visible.
95-
event_checkpoint[1].requireClear();
96-
win_checkpoint[1].requireVisible();
97-
Util.clickOnComp(robot_text, robot);
98-
99-
// I'm really not sure whether the click is needed for focus
100-
// but since it's asynchronous, as is the actually gaining of focus
101-
// we might as well do our best
10295
try {
103-
EventQueue.invokeAndWait(new Runnable() {
104-
public void run() {
105-
}
106-
});
107-
} catch (Exception e) {
108-
}
109-
110-
robot.keyPress(KeyEvent.VK_SHIFT);
111-
112-
robot.keyPress(KeyEvent.VK_H);
113-
robot.waitForIdle();
114-
robot.keyRelease(KeyEvent.VK_H);
115-
116-
robot.keyRelease(KeyEvent.VK_SHIFT);
117-
118-
robot.keyPress(KeyEvent.VK_E);
119-
robot.waitForIdle();
120-
robot.keyRelease(KeyEvent.VK_E);
121-
122-
robot.keyPress(KeyEvent.VK_L);
123-
robot.waitForIdle();
124-
robot.keyRelease(KeyEvent.VK_L);
125-
126-
robot.keyPress(KeyEvent.VK_L);
127-
robot.waitForIdle();
128-
robot.keyRelease(KeyEvent.VK_L);
129-
130-
robot.keyPress(KeyEvent.VK_O);
131-
robot.waitForIdle();
132-
robot.keyRelease(KeyEvent.VK_O);
133-
134-
//
135-
// NOTE THAT WE MAY HAVE MORE SYNCHRONIZATION WORK TO DO HERE.
136-
// CURRENTLY THERE IS NO GUARANTEE THAT THE KEYEVENT THAT THAT
137-
// TYPES THE 'O' HAS BEEN PROCESSED BEFORE WE GET THE RESULT
138-
//
139-
// This is a (lame) attempt at waiting for the last typeKey events to
140-
// propagate. It's not quite right because robot uses
141-
// CGRemoteOperations, which are asynchronous. But that's why I put in
142-
// the Thread.sleep
143-
try {
144-
EventQueue.invokeAndWait(new Runnable() {
145-
public void run() {
146-
}
147-
});
148-
} catch (Exception e) {
149-
}
150-
151-
// Need to call this before the dialog that robot_text is in is disposed
152-
result = robot_text.getText();
153-
154-
Thread.sleep(50); // Thread.sleep adds stability
155-
// Click Close box of modeless dialog with textField
156-
Util.clickOnComp(txtDiag, robot);
157-
158-
Thread.sleep(50); // Thread.sleep adds stability
159-
// Click Close box of intermediate modal dialog
160-
Util.clickOnComp(interDiag, robot);
161-
162-
Thread.sleep(50); // Thread.sleep adds stability
163-
// Click Close box of intermediate modal dialog
164-
Util.clickOnComp(frame, robot);
165-
166-
String expected = "Hello";
167-
}
168-
169-
private static Robot getRobot() {
170-
if (_robot == null) {
171-
try {
172-
_robot = new Robot();
173-
} catch (AWTException e) {
174-
throw new RuntimeException("Robot creation failed");
96+
robot = new Robot();
97+
robot.setAutoDelay(100);
98+
99+
// launch first frame with fistButton
100+
frame = new StartFrame();
101+
robot.waitForIdle();
102+
blockTillDisplayed(frame);
103+
clickOnComp(robot_button[0]);
104+
105+
// Dialog must be created and onscreen before we proceed.
106+
blockTillDisplayed(interDiag);
107+
clickOnComp(robot_button[1]);
108+
109+
// Again, the Dialog must be created and onscreen before we proceed.
110+
blockTillDisplayed(robot_text);
111+
clickOnComp(robot_text);
112+
113+
robot.keyPress(KeyEvent.VK_SHIFT);
114+
robot.keyPress(KeyEvent.VK_H);
115+
robot.keyRelease(KeyEvent.VK_H);
116+
robot.keyRelease(KeyEvent.VK_SHIFT);
117+
robot.waitForIdle();
118+
119+
robot.keyPress(KeyEvent.VK_E);
120+
robot.keyRelease(KeyEvent.VK_E);
121+
robot.waitForIdle();
122+
123+
robot.keyPress(KeyEvent.VK_L);
124+
robot.keyRelease(KeyEvent.VK_L);
125+
robot.waitForIdle();
126+
127+
robot.keyPress(KeyEvent.VK_L);
128+
robot.keyRelease(KeyEvent.VK_L);
129+
robot.waitForIdle();
130+
131+
robot.keyPress(KeyEvent.VK_O);
132+
robot.keyRelease(KeyEvent.VK_O);
133+
robot.waitForIdle();
134+
} finally {
135+
if (frame != null) {
136+
frame.dispose();
137+
}
138+
if (interDiag != null) {
139+
interDiag.dispose();
140+
}
141+
if (txtDiag != null) {
142+
txtDiag.dispose();
175143
}
176144
}
177-
return _robot;
178145
}
179146

180147
//////////////////// Start Frame ///////////////////
@@ -195,26 +162,19 @@ public StartFrame() {
195162
but.addActionListener(new java.awt.event.ActionListener() {
196163
public void actionPerformed(ActionEvent e) {
197164
interDiag = new IntermediateDialog(StartFrame.this);
198-
win_checkpoint[0] = new VisibilityValidator(interDiag);
199165
interDiag.setSize(300, 200);
200166

201167
// may need listener to watch this move.
202168
interDiag.setLocation(getLocationOnScreen());
203169
interDiag.pack();
204-
event_checkpoint[0].clear();
205170
interDiag.setVisible(true);
206171
}
207172
});
208173
Panel pan = new Panel();
209174
pan.add(but);
210175
add(pan);
176+
setVisible(true);
211177
robot_button[0] = but;
212-
addWindowListener(new WindowAdapter() {
213-
public void windowClosing(WindowEvent e) {
214-
setVisible(false);
215-
dispose();
216-
}
217-
});
218178
}
219179
}
220180

@@ -231,22 +191,14 @@ public IntermediateDialog(Frame parent) {
231191
but.addActionListener(new java.awt.event.ActionListener() {
232192
public void actionPerformed(ActionEvent e) {
233193
txtDiag = new TextDialog(m_parent);
234-
win_checkpoint[1] = new VisibilityValidator(txtDiag);
235194
txtDiag.setSize(300, 100);
236-
event_checkpoint[1].clear();
237195
txtDiag.setVisible(true);
238196
}
239197
});
240198
Panel pan = new Panel();
241199
pan.add(but);
242200
add(pan);
243201
pack();
244-
addWindowListener(new WindowAdapter() {
245-
public void windowClosing(WindowEvent e) {
246-
setVisible(false);
247-
dispose();
248-
}
249-
});
250202

251203
// The robot needs to know about us, so set global
252204
robot_button[1] = but;
@@ -263,12 +215,6 @@ public TextDialog(Dialog parent) {
263215
pan.add(txt);
264216
add(pan);
265217
pack();
266-
addWindowListener(new WindowAdapter() {
267-
public void windowClosing(WindowEvent e) {
268-
setVisible(false);
269-
dispose();
270-
}
271-
});
272218

273219
// The robot needs to know about us, so set global
274220
robot_text = txt;

‎test/jdk/java/awt/regtesthelpers/VisibilityValidator.java

-307
This file was deleted.

‎test/jdk/java/awt/regtesthelpers/Waypoint.java

-105
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.