@@ -87,8 +87,7 @@ describe('$httpBackend', function() {
8787 $backend ( 'GET' , '/some-url' , null , callback ) ;
8888 xhr = MockXhr . $$lastInstance ;
8989 xhr . statusText = 'OK' ;
90- xhr . readyState = 4 ;
91- xhr . onreadystatechange ( ) ;
90+ xhr . onload ( ) ;
9291 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
9392 } ) ;
9493
@@ -105,9 +104,8 @@ describe('$httpBackend', function() {
105104 expect ( xhr . abort ) . toHaveBeenCalledOnce ( ) ;
106105
107106 xhr . status = 0 ;
108- xhr . readyState = 4 ;
109107 xhr . statusText = 'OK' ;
110- xhr . onreadystatechange ( ) ;
108+ xhr . onload ( ) ;
111109 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
112110 } ) ;
113111
@@ -118,8 +116,7 @@ describe('$httpBackend', function() {
118116
119117 $backend ( 'GET' , '/some-url' , null , callback ) ;
120118 xhr = MockXhr . $$lastInstance ;
121- xhr . readyState = 4 ;
122- xhr . onreadystatechange ( ) ;
119+ xhr . onload ( ) ;
123120 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
124121 } ) ;
125122
@@ -133,23 +130,7 @@ describe('$httpBackend', function() {
133130 xhr = MockXhr . $$lastInstance ;
134131
135132 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 ( ) ;
153134
154135 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
155136 } ) ;
@@ -195,8 +176,7 @@ describe('$httpBackend', function() {
195176 expect ( xhr . abort ) . toHaveBeenCalledOnce ( ) ;
196177
197178 xhr . status = 0 ;
198- xhr . readyState = 4 ;
199- xhr . onreadystatechange ( ) ;
179+ xhr . onabort ( ) ;
200180 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
201181 } ) ;
202182
@@ -215,8 +195,7 @@ describe('$httpBackend', function() {
215195 expect ( xhr . abort ) . toHaveBeenCalledOnce ( ) ;
216196
217197 xhr . status = 0 ;
218- xhr . readyState = 4 ;
219- xhr . onreadystatechange ( ) ;
198+ xhr . onabort ( ) ;
220199 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
221200 } ) ;
222201
@@ -234,8 +213,7 @@ describe('$httpBackend', function() {
234213 expect ( xhr . abort ) . toHaveBeenCalledOnce ( ) ;
235214
236215 xhr . status = 0 ;
237- xhr . readyState = 4 ;
238- xhr . onreadystatechange ( ) ;
216+ xhr . onabort ( ) ;
239217 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
240218 } ) ) ;
241219
@@ -250,8 +228,7 @@ describe('$httpBackend', function() {
250228 spyOn ( xhr , 'abort' ) ;
251229
252230 xhr . status = 200 ;
253- xhr . readyState = 4 ;
254- xhr . onreadystatechange ( ) ;
231+ xhr . onload ( ) ;
255232 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
256233
257234 $timeout . flush ( ) ;
@@ -271,42 +248,14 @@ describe('$httpBackend', function() {
271248 expect ( fakeTimeout . delays [ 0 ] ) . toBe ( 2000 ) ;
272249
273250 xhr . status = 200 ;
274- xhr . readyState = 4 ;
275- xhr . onreadystatechange ( ) ;
251+ xhr . onload ( ) ;
276252 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
277253
278254 expect ( fakeTimeout . delays . length ) . toBe ( 0 ) ;
279255 expect ( xhr . abort ) . not . toHaveBeenCalled ( ) ;
280256 } ) ;
281257
282258
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-
310259 it ( 'should set withCredentials' , function ( ) {
311260 $backend ( 'GET' , '/some.url' , null , callback , { } , null , true ) ;
312261 expect ( MockXhr . $$lastInstance . withCredentials ) . toBe ( true ) ;
@@ -326,8 +275,7 @@ describe('$httpBackend', function() {
326275 } ) ;
327276
328277 xhrInstance . response = { some : 'object' } ;
329- xhrInstance . readyState = 4 ;
330- xhrInstance . onreadystatechange ( ) ;
278+ xhrInstance . onload ( ) ;
331279
332280 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
333281 } ) ;
@@ -347,8 +295,7 @@ describe('$httpBackend', function() {
347295 } ) ;
348296
349297 xhrInstance . responseText = responseText ;
350- xhrInstance . readyState = 4 ;
351- xhrInstance . onreadystatechange ( ) ;
298+ xhrInstance . onload ( ) ;
352299
353300 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
354301 } ) ;
@@ -436,8 +383,7 @@ describe('$httpBackend', function() {
436383 xhr = MockXhr . $$lastInstance ;
437384 xhr . status = status ;
438385 xhr . responseText = content ;
439- xhr . readyState = 4 ;
440- xhr . onreadystatechange ( ) ;
386+ xhr . onload ( ) ;
441387 }
442388
443389
0 commit comments