@@ -87,27 +87,7 @@ describe('$httpBackend', function() {
87
87
$backend ( 'GET' , '/some-url' , null , callback ) ;
88
88
xhr = MockXhr . $$lastInstance ;
89
89
xhr . statusText = 'OK' ;
90
- xhr . readyState = 4 ;
91
- xhr . onreadystatechange ( ) ;
92
- expect ( callback ) . toHaveBeenCalledOnce ( ) ;
93
- } ) ;
94
-
95
- it ( 'should not touch xhr.statusText when request is aborted on IE9 or lower' , function ( ) {
96
- callback . andCallFake ( function ( status , response , headers , statusText ) {
97
- expect ( statusText ) . toBe ( ( ! msie || msie >= 10 ) ? 'OK' : '' ) ;
98
- } ) ;
99
-
100
- $backend ( 'GET' , '/url' , null , callback , { } , 2000 ) ;
101
- xhr = MockXhr . $$lastInstance ;
102
- spyOn ( xhr , 'abort' ) ;
103
-
104
- fakeTimeout . flush ( ) ;
105
- expect ( xhr . abort ) . toHaveBeenCalledOnce ( ) ;
106
-
107
- xhr . status = 0 ;
108
- xhr . readyState = 4 ;
109
- xhr . statusText = 'OK' ;
110
- xhr . onreadystatechange ( ) ;
90
+ xhr . onload ( ) ;
111
91
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
112
92
} ) ;
113
93
@@ -118,8 +98,7 @@ describe('$httpBackend', function() {
118
98
119
99
$backend ( 'GET' , '/some-url' , null , callback ) ;
120
100
xhr = MockXhr . $$lastInstance ;
121
- xhr . readyState = 4 ;
122
- xhr . onreadystatechange ( ) ;
101
+ xhr . onload ( ) ;
123
102
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
124
103
} ) ;
125
104
@@ -133,23 +112,7 @@ describe('$httpBackend', function() {
133
112
xhr = MockXhr . $$lastInstance ;
134
113
135
114
xhr . status = 1223 ;
136
- xhr . readyState = 4 ;
137
- xhr . onreadystatechange ( ) ;
138
-
139
- expect ( callback ) . toHaveBeenCalledOnce ( ) ;
140
- } ) ;
141
-
142
- // onreadystatechange might by called multiple times
143
- // with readyState === 4 on mobile webkit caused by
144
- // xhrs that are resolved while the app is in the background (see #5426).
145
- it ( 'should not process onreadystatechange callback with readyState == 4 more than once' , function ( ) {
146
- $backend ( 'GET' , 'URL' , null , callback ) ;
147
- xhr = MockXhr . $$lastInstance ;
148
-
149
- xhr . status = 200 ;
150
- xhr . readyState = 4 ;
151
- xhr . onreadystatechange ( ) ;
152
- xhr . onreadystatechange ( ) ;
115
+ xhr . onload ( ) ;
153
116
154
117
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
155
118
} ) ;
@@ -195,8 +158,7 @@ describe('$httpBackend', function() {
195
158
expect ( xhr . abort ) . toHaveBeenCalledOnce ( ) ;
196
159
197
160
xhr . status = 0 ;
198
- xhr . readyState = 4 ;
199
- xhr . onreadystatechange ( ) ;
161
+ xhr . onabort ( ) ;
200
162
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
201
163
} ) ;
202
164
@@ -215,8 +177,7 @@ describe('$httpBackend', function() {
215
177
expect ( xhr . abort ) . toHaveBeenCalledOnce ( ) ;
216
178
217
179
xhr . status = 0 ;
218
- xhr . readyState = 4 ;
219
- xhr . onreadystatechange ( ) ;
180
+ xhr . onabort ( ) ;
220
181
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
221
182
} ) ;
222
183
@@ -234,8 +195,7 @@ describe('$httpBackend', function() {
234
195
expect ( xhr . abort ) . toHaveBeenCalledOnce ( ) ;
235
196
236
197
xhr . status = 0 ;
237
- xhr . readyState = 4 ;
238
- xhr . onreadystatechange ( ) ;
198
+ xhr . onabort ( ) ;
239
199
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
240
200
} ) ) ;
241
201
@@ -250,8 +210,7 @@ describe('$httpBackend', function() {
250
210
spyOn ( xhr , 'abort' ) ;
251
211
252
212
xhr . status = 200 ;
253
- xhr . readyState = 4 ;
254
- xhr . onreadystatechange ( ) ;
213
+ xhr . onload ( ) ;
255
214
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
256
215
257
216
$timeout . flush ( ) ;
@@ -271,42 +230,14 @@ describe('$httpBackend', function() {
271
230
expect ( fakeTimeout . delays [ 0 ] ) . toBe ( 2000 ) ;
272
231
273
232
xhr . status = 200 ;
274
- xhr . readyState = 4 ;
275
- xhr . onreadystatechange ( ) ;
233
+ xhr . onload ( ) ;
276
234
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
277
235
278
236
expect ( fakeTimeout . delays . length ) . toBe ( 0 ) ;
279
237
expect ( xhr . abort ) . not . toHaveBeenCalled ( ) ;
280
238
} ) ;
281
239
282
240
283
- it ( 'should register onreadystatechange callback before sending' , function ( ) {
284
- // send() in IE6, IE7 is sync when serving from cache
285
- function SyncXhr ( ) {
286
- xhr = this ;
287
- this . open = this . setRequestHeader = noop ;
288
-
289
- this . send = function ( ) {
290
- this . status = 200 ;
291
- this . responseText = 'response' ;
292
- this . readyState = 4 ;
293
- this . onreadystatechange ( ) ;
294
- } ;
295
-
296
- this . getAllResponseHeaders = valueFn ( '' ) ;
297
- }
298
-
299
- callback . andCallFake ( function ( status , response ) {
300
- expect ( status ) . toBe ( 200 ) ;
301
- expect ( response ) . toBe ( 'response' ) ;
302
- } ) ;
303
-
304
- $backend = createHttpBackend ( $browser , function ( ) { return new SyncXhr ( ) ; } ) ;
305
- $backend ( 'GET' , '/url' , null , callback ) ;
306
- expect ( callback ) . toHaveBeenCalledOnce ( ) ;
307
- } ) ;
308
-
309
-
310
241
it ( 'should set withCredentials' , function ( ) {
311
242
$backend ( 'GET' , '/some.url' , null , callback , { } , null , true ) ;
312
243
expect ( MockXhr . $$lastInstance . withCredentials ) . toBe ( true ) ;
@@ -326,8 +257,7 @@ describe('$httpBackend', function() {
326
257
} ) ;
327
258
328
259
xhrInstance . response = { some : 'object' } ;
329
- xhrInstance . readyState = 4 ;
330
- xhrInstance . onreadystatechange ( ) ;
260
+ xhrInstance . onload ( ) ;
331
261
332
262
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
333
263
} ) ;
@@ -347,8 +277,7 @@ describe('$httpBackend', function() {
347
277
} ) ;
348
278
349
279
xhrInstance . responseText = responseText ;
350
- xhrInstance . readyState = 4 ;
351
- xhrInstance . onreadystatechange ( ) ;
280
+ xhrInstance . onload ( ) ;
352
281
353
282
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
354
283
} ) ;
@@ -436,8 +365,7 @@ describe('$httpBackend', function() {
436
365
xhr = MockXhr . $$lastInstance ;
437
366
xhr . status = status ;
438
367
xhr . responseText = content ;
439
- xhr . readyState = 4 ;
440
- xhr . onreadystatechange ( ) ;
368
+ xhr . onload ( ) ;
441
369
}
442
370
443
371
0 commit comments