From c480462644b3b2b2fecf7bc112bedd2cc362f2f3 Mon Sep 17 00:00:00 2001 From: Guillaume Pannatier Date: Mon, 10 Nov 2014 11:53:28 +0100 Subject: [PATCH 1/2] fix($httpBackend): compare timeoutId with undefined in completeRequest httpBackend with ngMock browser.defer can never cancel the first deferredFn because the timeoutId returned by defer for the first fn is a zero value. Compare timeoutId with undefined fix this issue. --- src/ng/httpBackend.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index 742d7aa86a85..ec53fdd6331e 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -126,7 +126,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc function completeRequest(callback, status, response, headersString, statusText) { // cancel timeout and subsequent timeout promise resolution - timeoutId && $browserDefer.cancel(timeoutId); + timeoutId !== undefined && $browserDefer.cancel(timeoutId); jsonpDone = xhr = null; callback(status, response, headersString, statusText); From 78b026c13c91efbaeb780adca56746c0f0adda79 Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Mon, 10 Nov 2014 18:46:26 -0500 Subject: [PATCH 2/2] fix($httpBackend): fixup patch for #9979 --- src/ng/httpBackend.js | 4 +++- test/ng/httpBackendSpec.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index ec53fdd6331e..1a262b9cb8b6 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -126,7 +126,9 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc function completeRequest(callback, status, response, headersString, statusText) { // cancel timeout and subsequent timeout promise resolution - timeoutId !== undefined && $browserDefer.cancel(timeoutId); + if (timeoutId !== void 0) { + $browserDefer.cancel(timeoutId); + } jsonpDone = xhr = null; callback(status, response, headersString, statusText); diff --git a/test/ng/httpBackendSpec.js b/test/ng/httpBackendSpec.js index 2c1da6eba4bb..9b3116932d49 100644 --- a/test/ng/httpBackendSpec.js +++ b/test/ng/httpBackendSpec.js @@ -103,6 +103,19 @@ describe('$httpBackend', function() { }); + it('should cancel timeout on completeRequest()', function() { + fakeTimeout.ids.length = fakeTimeout.fns.length = fakeTimeout.delays.length = 0; + fakeTimeoutId = 0; + spyOn(fakeTimeout, 'cancel').andCallThrough(); + $backend('GET', '/some-url', null, callback, void 0, 100); + xhr = MockXhr.$$lastInstance; + expect(fakeTimeout.cancel).not.toHaveBeenCalled(); + xhr.status = 200; + xhr.onload(); + expect(fakeTimeout.cancel).toHaveBeenCalledWith(1); + }); + + it('should normalize IE\'s 1223 status code into 204', function() { callback.andCallFake(function(status) { expect(status).toBe(204);