@@ -244,7 +244,7 @@ describe('$httpBackend', function() {
244
244
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
245
245
} ) ;
246
246
247
- it ( 'should abort request on timeout' , function ( ) {
247
+ it ( 'should abort request on numerical timeout' , function ( ) {
248
248
callback . and . callFake ( function ( status , response ) {
249
249
expect ( status ) . toBe ( - 1 ) ;
250
250
} ) ;
@@ -264,9 +264,10 @@ describe('$httpBackend', function() {
264
264
} ) ;
265
265
266
266
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 ) {
269
269
expect ( status ) . toBe ( - 1 ) ;
270
+ expect ( xhrStatus ) . toBe ( 'timeout' ) ;
270
271
} ) ;
271
272
272
273
$backend ( 'GET' , '/url' , null , callback , { } , $timeout ( noop , 2000 ) ) ;
@@ -300,6 +301,24 @@ describe('$httpBackend', function() {
300
301
} ) ) ;
301
302
302
303
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
+
303
322
it ( 'should cancel timeout on completion' , function ( ) {
304
323
callback . and . callFake ( function ( status , response ) {
305
324
expect ( status ) . toBe ( 200 ) ;
@@ -320,6 +339,22 @@ describe('$httpBackend', function() {
320
339
} ) ;
321
340
322
341
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
+
323
358
it ( 'should set withCredentials' , function ( ) {
324
359
$backend ( 'GET' , '/some.url' , null , callback , { } , null , true ) ;
325
360
expect ( MockXhr . $$lastInstance . withCredentials ) . toBe ( true ) ;
0 commit comments