@@ -87,27 +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 ( ) ;
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 ( ) ;
11191 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
11292 } ) ;
11393
@@ -118,8 +98,7 @@ describe('$httpBackend', function() {
11898
11999 $backend ( 'GET' , '/some-url' , null , callback ) ;
120100 xhr = MockXhr . $$lastInstance ;
121- xhr . readyState = 4 ;
122- xhr . onreadystatechange ( ) ;
101+ xhr . onload ( ) ;
123102 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
124103 } ) ;
125104
@@ -133,23 +112,7 @@ describe('$httpBackend', function() {
133112 xhr = MockXhr . $$lastInstance ;
134113
135114 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 ( ) ;
153116
154117 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
155118 } ) ;
@@ -195,8 +158,7 @@ describe('$httpBackend', function() {
195158 expect ( xhr . abort ) . toHaveBeenCalledOnce ( ) ;
196159
197160 xhr . status = 0 ;
198- xhr . readyState = 4 ;
199- xhr . onreadystatechange ( ) ;
161+ xhr . onabort ( ) ;
200162 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
201163 } ) ;
202164
@@ -215,8 +177,7 @@ describe('$httpBackend', function() {
215177 expect ( xhr . abort ) . toHaveBeenCalledOnce ( ) ;
216178
217179 xhr . status = 0 ;
218- xhr . readyState = 4 ;
219- xhr . onreadystatechange ( ) ;
180+ xhr . onabort ( ) ;
220181 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
221182 } ) ;
222183
@@ -234,8 +195,7 @@ describe('$httpBackend', function() {
234195 expect ( xhr . abort ) . toHaveBeenCalledOnce ( ) ;
235196
236197 xhr . status = 0 ;
237- xhr . readyState = 4 ;
238- xhr . onreadystatechange ( ) ;
198+ xhr . onabort ( ) ;
239199 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
240200 } ) ) ;
241201
@@ -250,8 +210,7 @@ describe('$httpBackend', function() {
250210 spyOn ( xhr , 'abort' ) ;
251211
252212 xhr . status = 200 ;
253- xhr . readyState = 4 ;
254- xhr . onreadystatechange ( ) ;
213+ xhr . onload ( ) ;
255214 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
256215
257216 $timeout . flush ( ) ;
@@ -271,42 +230,14 @@ describe('$httpBackend', function() {
271230 expect ( fakeTimeout . delays [ 0 ] ) . toBe ( 2000 ) ;
272231
273232 xhr . status = 200 ;
274- xhr . readyState = 4 ;
275- xhr . onreadystatechange ( ) ;
233+ xhr . onload ( ) ;
276234 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
277235
278236 expect ( fakeTimeout . delays . length ) . toBe ( 0 ) ;
279237 expect ( xhr . abort ) . not . toHaveBeenCalled ( ) ;
280238 } ) ;
281239
282240
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-
310241 it ( 'should set withCredentials' , function ( ) {
311242 $backend ( 'GET' , '/some.url' , null , callback , { } , null , true ) ;
312243 expect ( MockXhr . $$lastInstance . withCredentials ) . toBe ( true ) ;
@@ -326,8 +257,7 @@ describe('$httpBackend', function() {
326257 } ) ;
327258
328259 xhrInstance . response = { some : 'object' } ;
329- xhrInstance . readyState = 4 ;
330- xhrInstance . onreadystatechange ( ) ;
260+ xhrInstance . onload ( ) ;
331261
332262 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
333263 } ) ;
@@ -347,8 +277,7 @@ describe('$httpBackend', function() {
347277 } ) ;
348278
349279 xhrInstance . responseText = responseText ;
350- xhrInstance . readyState = 4 ;
351- xhrInstance . onreadystatechange ( ) ;
280+ xhrInstance . onload ( ) ;
352281
353282 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
354283 } ) ;
@@ -436,8 +365,7 @@ describe('$httpBackend', function() {
436365 xhr = MockXhr . $$lastInstance ;
437366 xhr . status = status ;
438367 xhr . responseText = content ;
439- xhr . readyState = 4 ;
440- xhr . onreadystatechange ( ) ;
368+ xhr . onload ( ) ;
441369 }
442370
443371
0 commit comments