1
1
/*
2
2
* Copyright 2012 Google Inc.
3
- *
3
+ *
4
4
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
5
* use this file except in compliance with the License. You may obtain a copy of
6
6
* the License at
7
- *
7
+ *
8
8
* http://www.apache.org/licenses/LICENSE-2.0
9
- *
9
+ *
10
10
* Unless required by applicable law or agreed to in writing, software
11
11
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
12
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
15
*/
16
16
package com .google .gwt .junit .client ;
17
17
18
- import com .google .gwt .dom .client .ButtonElement ;
19
- import com .google .gwt .dom .client .Document ;
20
18
import com .google .gwt .junit .ExpectedFailure ;
21
- import com .google .gwt .user .client .DOM ;
22
- import com .google .gwt .user .client .Event ;
23
- import com .google .gwt .user .client .EventListener ;
24
19
import com .google .gwt .user .client .Timer ;
25
20
26
21
/**
27
22
* This class tests GwtTestCase in async mode.
28
23
*
29
24
* Note: This test requires some test methods to be executed in a specific order.
30
25
*/
31
- public class GWTTestCaseAsyncTest extends GWTTestCase {
32
-
33
- public String getModuleName () {
34
- return "com.google.gwt.junit.JUnit" ;
35
- }
26
+ public class GWTTestCaseAsyncTest extends GWTTestCaseTestBase {
36
27
37
28
// The following tests (all prefixed with test_) are intended to test the
38
29
// interaction of synchronous failures (within event handlers) with various
@@ -41,86 +32,75 @@ public String getModuleName() {
41
32
//
42
33
// Nomenclature for these tests:
43
34
// DTF => delayTestFinish()
44
- // SF => synchronous failure (from event handler)
35
+ // SF => synchronous failure (from event handler using failViaUncaughtException )
45
36
// FT => finishTest()
46
37
// F => fail()
47
38
// R => return;
48
39
49
40
@ ExpectedFailure (withMessage = "test_dtf_sf" )
50
41
public void test_dtf_sf () {
51
42
delayTestFinish ();
52
- synchronousFailure ("test_dtf_sf" );
43
+ failViaUncaughtException ("test_dtf_sf" );
53
44
}
54
45
55
46
@ ExpectedFailure (withMessage = "test_dtf_sf_f" )
56
47
public void test_dtf_sf_f () {
57
48
delayTestFinish ();
58
- synchronousFailure ("test_dtf_sf_f" );
49
+ failViaUncaughtException ("test_dtf_sf_f" );
59
50
failNow ("test_dtf_sf_f" );
60
51
}
61
52
62
53
@ ExpectedFailure (withMessage = "test_dtf_sf_ft" )
63
54
public void test_dtf_sf_ft () {
64
55
delayTestFinish ();
65
- synchronousFailure ("test_dtf_sf_ft" );
56
+ failViaUncaughtException ("test_dtf_sf_ft" );
66
57
finishTest ();
67
58
}
68
59
69
60
// Issue: http://code.google.com/p/google-web-toolkit/issues/detail?id=7846
70
61
@ ExpectedFailure (withMessage = "test_dtf_sf_r_f" )
71
62
public void _suppressed_test_dtf_sf_r_f () {
72
63
delayTestFinish ();
73
- synchronousFailure ("test_dtf_sf_r_f" );
64
+ failViaUncaughtException ("test_dtf_sf_r_f" );
74
65
failLater ("test_dtf_sf_r_f" );
75
66
}
76
67
77
68
@ ExpectedFailure (withMessage = "test_dtf_sf_r_ft" )
78
69
public void test_dtf_sf_r_ft () {
79
70
delayTestFinish ();
80
- synchronousFailure ("test_dtf_sf_r_ft" );
71
+ failViaUncaughtException ("test_dtf_sf_r_ft" );
81
72
finishTestLater ();
82
73
}
83
74
84
- @ ExpectedFailure (withMessage = "test_sf" )
85
- public void test_sf () {
86
- synchronousFailure ("test_sf" );
87
- }
88
-
89
75
@ ExpectedFailure (withMessage = "test_sf_dtf_f" )
90
76
public void test_sf_dtf_f () {
91
- synchronousFailure ("test_sf_dtf_f" );
77
+ failViaUncaughtException ("test_sf_dtf_f" );
92
78
delayTestFinish ();
93
79
failNow ("test_sf_dtf_f" );
94
80
}
95
81
96
82
@ ExpectedFailure (withMessage = "test_sf_dtf_ft" )
97
83
public void test_sf_dtf_ft () {
98
- synchronousFailure ("test_sf_dtf_ft" );
84
+ failViaUncaughtException ("test_sf_dtf_ft" );
99
85
delayTestFinish ();
100
86
finishTest ();
101
87
}
102
88
103
89
// Issue: http://code.google.com/p/google-web-toolkit/issues/detail?id=7846
104
90
@ ExpectedFailure (withMessage = "test_sf_dtf_r_f" )
105
91
public void _suppressed_test_sf_dtf_r_f () {
106
- synchronousFailure ("test_sf_dtf_r_f" );
92
+ failViaUncaughtException ("test_sf_dtf_r_f" );
107
93
delayTestFinish ();
108
94
failLater ("test_sf_dtf_r_f" );
109
95
}
110
96
111
97
@ ExpectedFailure (withMessage = "test_sf_dtf_r_ft" )
112
98
public void test_sf_dtf_r_ft () {
113
- synchronousFailure ("test_sf_dtf_r_ft" );
99
+ failViaUncaughtException ("test_sf_dtf_r_ft" );
114
100
delayTestFinish ();
115
101
finishTestLater ();
116
102
}
117
103
118
- @ ExpectedFailure (withMessage = "test_sf_f" )
119
- public void test_sf_f () {
120
- synchronousFailure ("test_sf_f" );
121
- failNow ("test_sf_f" );
122
- }
123
-
124
104
/**
125
105
* Fails normally.
126
106
*/
@@ -179,6 +159,7 @@ public void testSpuriousFinishTest() {
179
159
finishTest ();
180
160
fail ("finishTest should have failed" );
181
161
} catch (IllegalStateException e ) {
162
+ // Expected
182
163
}
183
164
}
184
165
@@ -227,10 +208,6 @@ public void run() {
227
208
}.schedule (delay );
228
209
}
229
210
230
- private void failNow (String failMsg ) {
231
- fail ("Expected failure (" + failMsg + ")" );
232
- }
233
-
234
211
private void finishTestLater () {
235
212
finishTestLater (1 );
236
213
}
@@ -243,21 +220,4 @@ public void run() {
243
220
}
244
221
}.schedule (delay );
245
222
}
246
-
247
- // Trigger a test failure synchronously, but from within an event handler.
248
- // (The exception thrown from fail() will get caught by the GWT UncaughtExceptionHandler).
249
- private void synchronousFailure (final String failMsg ) {
250
- ButtonElement btn = Document .get ().createPushButtonElement ();
251
- Document .get ().getBody ().appendChild (btn );
252
- Event .sinkEvents (btn , Event .ONCLICK );
253
-
254
- EventListener listener = new EventListener () {
255
- public void onBrowserEvent (Event event ) {
256
- failNow (failMsg );
257
- }
258
- };
259
-
260
- DOM .setEventListener (btn .<com .google .gwt .user .client .Element >cast (), listener );
261
- btn .click ();
262
- }
263
223
}
0 commit comments