@@ -87,8 +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 ( ) ;
90
+ xhr . onload ( ) ;
92
91
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
93
92
} ) ;
94
93
@@ -105,9 +104,8 @@ describe('$httpBackend', function() {
105
104
expect ( xhr . abort ) . toHaveBeenCalledOnce ( ) ;
106
105
107
106
xhr . status = 0 ;
108
- xhr . readyState = 4 ;
109
107
xhr . statusText = 'OK' ;
110
- xhr . onreadystatechange ( ) ;
108
+ xhr . onload ( ) ;
111
109
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
112
110
} ) ;
113
111
@@ -118,8 +116,7 @@ describe('$httpBackend', function() {
118
116
119
117
$backend ( 'GET' , '/some-url' , null , callback ) ;
120
118
xhr = MockXhr . $$lastInstance ;
121
- xhr . readyState = 4 ;
122
- xhr . onreadystatechange ( ) ;
119
+ xhr . onload ( ) ;
123
120
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
124
121
} ) ;
125
122
@@ -133,23 +130,7 @@ describe('$httpBackend', function() {
133
130
xhr = MockXhr . $$lastInstance ;
134
131
135
132
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 ( ) ;
133
+ xhr . onload ( ) ;
153
134
154
135
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
155
136
} ) ;
@@ -195,8 +176,7 @@ describe('$httpBackend', function() {
195
176
expect ( xhr . abort ) . toHaveBeenCalledOnce ( ) ;
196
177
197
178
xhr . status = 0 ;
198
- xhr . readyState = 4 ;
199
- xhr . onreadystatechange ( ) ;
179
+ xhr . onabort ( ) ;
200
180
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
201
181
} ) ;
202
182
@@ -215,8 +195,7 @@ describe('$httpBackend', function() {
215
195
expect ( xhr . abort ) . toHaveBeenCalledOnce ( ) ;
216
196
217
197
xhr . status = 0 ;
218
- xhr . readyState = 4 ;
219
- xhr . onreadystatechange ( ) ;
198
+ xhr . onabort ( ) ;
220
199
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
221
200
} ) ;
222
201
@@ -234,8 +213,7 @@ describe('$httpBackend', function() {
234
213
expect ( xhr . abort ) . toHaveBeenCalledOnce ( ) ;
235
214
236
215
xhr . status = 0 ;
237
- xhr . readyState = 4 ;
238
- xhr . onreadystatechange ( ) ;
216
+ xhr . onabort ( ) ;
239
217
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
240
218
} ) ) ;
241
219
@@ -250,8 +228,7 @@ describe('$httpBackend', function() {
250
228
spyOn ( xhr , 'abort' ) ;
251
229
252
230
xhr . status = 200 ;
253
- xhr . readyState = 4 ;
254
- xhr . onreadystatechange ( ) ;
231
+ xhr . onload ( ) ;
255
232
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
256
233
257
234
$timeout . flush ( ) ;
@@ -271,42 +248,14 @@ describe('$httpBackend', function() {
271
248
expect ( fakeTimeout . delays [ 0 ] ) . toBe ( 2000 ) ;
272
249
273
250
xhr . status = 200 ;
274
- xhr . readyState = 4 ;
275
- xhr . onreadystatechange ( ) ;
251
+ xhr . onload ( ) ;
276
252
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
277
253
278
254
expect ( fakeTimeout . delays . length ) . toBe ( 0 ) ;
279
255
expect ( xhr . abort ) . not . toHaveBeenCalled ( ) ;
280
256
} ) ;
281
257
282
258
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
259
it ( 'should set withCredentials' , function ( ) {
311
260
$backend ( 'GET' , '/some.url' , null , callback , { } , null , true ) ;
312
261
expect ( MockXhr . $$lastInstance . withCredentials ) . toBe ( true ) ;
@@ -326,8 +275,7 @@ describe('$httpBackend', function() {
326
275
} ) ;
327
276
328
277
xhrInstance . response = { some : 'object' } ;
329
- xhrInstance . readyState = 4 ;
330
- xhrInstance . onreadystatechange ( ) ;
278
+ xhrInstance . onload ( ) ;
331
279
332
280
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
333
281
} ) ;
@@ -347,8 +295,7 @@ describe('$httpBackend', function() {
347
295
} ) ;
348
296
349
297
xhrInstance . responseText = responseText ;
350
- xhrInstance . readyState = 4 ;
351
- xhrInstance . onreadystatechange ( ) ;
298
+ xhrInstance . onload ( ) ;
352
299
353
300
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
354
301
} ) ;
@@ -436,8 +383,7 @@ describe('$httpBackend', function() {
436
383
xhr = MockXhr . $$lastInstance ;
437
384
xhr . status = status ;
438
385
xhr . responseText = content ;
439
- xhr . readyState = 4 ;
440
- xhr . onreadystatechange ( ) ;
386
+ xhr . onload ( ) ;
441
387
}
442
388
443
389
0 commit comments