@@ -244,7 +244,7 @@ describe('$httpBackend', function() {
244244 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
245245 } ) ;
246246
247- it ( 'should abort request on timeout' , function ( ) {
247+ it ( 'should abort request on numerical timeout' , function ( ) {
248248 callback . and . callFake ( function ( status , response ) {
249249 expect ( status ) . toBe ( - 1 ) ;
250250 } ) ;
@@ -264,9 +264,10 @@ describe('$httpBackend', function() {
264264 } ) ;
265265
266266
267- it ( 'should abort request on timeout promise resolution' , inject ( function ( $timeout ) {
268- callback . and . callFake ( function ( status , response ) {
267+ it ( 'should abort request on $ timeout promise resolution' , inject ( function ( $timeout ) {
268+ callback . and . callFake ( function ( status , response , headers , statusText , xhrStatus ) {
269269 expect ( status ) . toBe ( - 1 ) ;
270+ expect ( xhrStatus ) . toBe ( 'timeout' ) ;
270271 } ) ;
271272
272273 $backend ( 'GET' , '/url' , null , callback , { } , $timeout ( noop , 2000 ) ) ;
@@ -300,6 +301,24 @@ describe('$httpBackend', function() {
300301 } ) ) ;
301302
302303
304+ it ( 'should abort request on canceler promise resolution' , inject ( function ( $q , $browser ) {
305+ var canceler = $q . defer ( ) ;
306+
307+ callback . and . callFake ( function ( status , response , headers , statusText , xhrStatus ) {
308+ expect ( status ) . toBe ( - 1 ) ;
309+ expect ( xhrStatus ) . toBe ( 'abort' ) ;
310+ } ) ;
311+
312+ $backend ( 'GET' , '/url' , null , callback , { } , canceler . promise ) ;
313+ xhr = MockXhr . $$lastInstance ;
314+
315+ canceler . resolve ( ) ;
316+ $browser . defer . flush ( ) ;
317+
318+ expect ( callback ) . toHaveBeenCalledOnce ( ) ;
319+ } ) ) ;
320+
321+
303322 it ( 'should cancel timeout on completion' , function ( ) {
304323 callback . and . callFake ( function ( status , response ) {
305324 expect ( status ) . toBe ( 200 ) ;
@@ -320,6 +339,22 @@ describe('$httpBackend', function() {
320339 } ) ;
321340
322341
342+ it ( 'should call callback with xhrStatus "abort" on explicit xhr.abort() when $timeout is set' , inject ( function ( $timeout ) {
343+ callback . and . callFake ( function ( status , response , headers , statusText , xhrStatus ) {
344+ expect ( status ) . toBe ( - 1 ) ;
345+ expect ( xhrStatus ) . toBe ( 'abort' ) ;
346+ } ) ;
347+
348+ $backend ( 'GET' , '/url' , null , callback , { } , $timeout ( noop , 2000 ) ) ;
349+ xhr = MockXhr . $$lastInstance ;
350+ spyOn ( xhr , 'abort' ) . and . callThrough ( ) ;
351+
352+ xhr . abort ( ) ;
353+
354+ expect ( callback ) . toHaveBeenCalledOnce ( ) ;
355+ } ) ) ;
356+
357+
323358 it ( 'should set withCredentials' , function ( ) {
324359 $backend ( 'GET' , '/some.url' , null , callback , { } , null , true ) ;
325360 expect ( MockXhr . $$lastInstance . withCredentials ) . toBe ( true ) ;
0 commit comments