@@ -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,16 +248,15 @@ 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 ( ) {
259
+ it ( 'should register callbacks before sending' , function ( ) {
284
260
// send() in IE6, IE7 is sync when serving from cache
285
261
function SyncXhr ( ) {
286
262
xhr = this ;
@@ -289,8 +265,7 @@ describe('$httpBackend', function() {
289
265
this . send = function ( ) {
290
266
this . status = 200 ;
291
267
this . responseText = 'response' ;
292
- this . readyState = 4 ;
293
- this . onreadystatechange ( ) ;
268
+ this . onload ( ) ;
294
269
} ;
295
270
296
271
this . getAllResponseHeaders = valueFn ( '' ) ;
@@ -326,8 +301,7 @@ describe('$httpBackend', function() {
326
301
} ) ;
327
302
328
303
xhrInstance . response = { some : 'object' } ;
329
- xhrInstance . readyState = 4 ;
330
- xhrInstance . onreadystatechange ( ) ;
304
+ xhrInstance . onload ( ) ;
331
305
332
306
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
333
307
} ) ;
@@ -347,8 +321,7 @@ describe('$httpBackend', function() {
347
321
} ) ;
348
322
349
323
xhrInstance . responseText = responseText ;
350
- xhrInstance . readyState = 4 ;
351
- xhrInstance . onreadystatechange ( ) ;
324
+ xhrInstance . onload ( ) ;
352
325
353
326
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
354
327
} ) ;
@@ -436,8 +409,7 @@ describe('$httpBackend', function() {
436
409
xhr = MockXhr . $$lastInstance ;
437
410
xhr . status = status ;
438
411
xhr . responseText = content ;
439
- xhr . readyState = 4 ;
440
- xhr . onreadystatechange ( ) ;
412
+ xhr . onload ( ) ;
441
413
}
442
414
443
415
0 commit comments