1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
23
23
24
24
/**
25
25
* @test
26
- * @bug 8155740
26
+ * @bug 8160266 8225790
27
27
* @key headful
28
28
* @summary See <rdar://problem/3429130>: Events: actionPerformed() method not
29
29
* 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
30
* @run main NestedModalDialogTest
36
31
*/
37
32
44
39
//////////////////////////////////////////////////////////////////////////////
45
40
// classes necessary for this test
46
41
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 ;
54
55
55
56
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 ;
62
60
63
61
// 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 ;
76
65
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 ) {
108
75
}
109
- });
110
- } catch (Exception e ) {
76
+ }
111
77
}
78
+ }
112
79
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 );
126
83
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 );
130
86
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" ;
170
87
}
171
88
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 ();
178
137
}
179
138
}
180
- return _robot ;
181
139
}
182
140
183
141
//////////////////// Start Frame ///////////////////
@@ -198,26 +156,19 @@ public StartFrame() {
198
156
but .addActionListener (new java .awt .event .ActionListener () {
199
157
public void actionPerformed (ActionEvent e ) {
200
158
interDiag = new IntermediateDialog (StartFrame .this );
201
- win_checkpoint [0 ] = new VisibilityValidator (interDiag );
202
159
interDiag .setSize (300 , 200 );
203
160
204
161
// may need listener to watch this move.
205
162
interDiag .setLocation (getLocationOnScreen ());
206
163
interDiag .pack ();
207
- event_checkpoint [0 ].clear ();
208
164
interDiag .setVisible (true );
209
165
}
210
166
});
211
167
Panel pan = new Panel ();
212
168
pan .add (but );
213
169
add (pan );
170
+ setVisible (true );
214
171
robot_button [0 ] = but ;
215
- addWindowListener (new WindowAdapter () {
216
- public void windowClosing (WindowEvent e ) {
217
- setVisible (false );
218
- dispose ();
219
- }
220
- });
221
172
}
222
173
}
223
174
@@ -234,22 +185,14 @@ public IntermediateDialog(Frame parent) {
234
185
but .addActionListener (new java .awt .event .ActionListener () {
235
186
public void actionPerformed (ActionEvent e ) {
236
187
txtDiag = new TextDialog (m_parent );
237
- win_checkpoint [1 ] = new VisibilityValidator (txtDiag );
238
188
txtDiag .setSize (300 , 100 );
239
- event_checkpoint [1 ].clear ();
240
189
txtDiag .setVisible (true );
241
190
}
242
191
});
243
192
Panel pan = new Panel ();
244
193
pan .add (but );
245
194
add (pan );
246
195
pack ();
247
- addWindowListener (new WindowAdapter () {
248
- public void windowClosing (WindowEvent e ) {
249
- setVisible (false );
250
- dispose ();
251
- }
252
- });
253
196
254
197
// The robot needs to know about us, so set global
255
198
robot_button [1 ] = but ;
@@ -266,12 +209,6 @@ public TextDialog(Dialog parent) {
266
209
pan .add (txt );
267
210
add (pan );
268
211
pack ();
269
- addWindowListener (new WindowAdapter () {
270
- public void windowClosing (WindowEvent e ) {
271
- setVisible (false );
272
- dispose ();
273
- }
274
- });
275
212
276
213
// The robot needs to know about us, so set global
277
214
robot_text = txt ;
0 commit comments