mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
fix($httpBackend): Ignore multiple calls to onreadystatechange with readyState=4
On mobile webkit `onreadystatechange` might by called multiple times with `readyState===4` caused by xhrs that are resolved while the app is in the background. Fixes #5426.
This commit is contained in:
parent
50bf029625
commit
4f57236614
2 changed files with 17 additions and 0 deletions
|
|
@ -70,6 +70,11 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument)
|
|||
// always async
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState == 4) {
|
||||
// onreadystatechange might by called multiple times
|
||||
// with readyState === 4 on mobile webkit caused by
|
||||
// xhrs that are resolved while the app is in the background (see #5426).
|
||||
xhr.onreadystatechange = undefined;
|
||||
|
||||
var responseHeaders = null,
|
||||
response = null;
|
||||
|
||||
|
|
|
|||
|
|
@ -90,6 +90,18 @@ describe('$httpBackend', function() {
|
|||
expect(callback).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
// onreadystatechange might by called multiple times
|
||||
// with readyState === 4 on mobile webkit caused by
|
||||
// xhrs that are resolved while the app is in the background (see #5426).
|
||||
it('should remove onreadystatechange when it is called with readyState=4 to ignore multiple calls', function() {
|
||||
$backend('GET', 'URL', null, callback);
|
||||
xhr = MockXhr.$$lastInstance;
|
||||
|
||||
xhr.status = 200;
|
||||
xhr.readyState = 4;
|
||||
xhr.onreadystatechange();
|
||||
expect(xhr.onreadystatechange).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should set only the requested headers', function() {
|
||||
$backend('POST', 'URL', null, noop, {'X-header1': 'value1', 'X-header2': 'value2'});
|
||||
|
|
|
|||
Loading…
Reference in a new issue