diff options
| author | Vojta Jina | 2011-08-18 23:43:25 +0200 |
|---|---|---|
| committer | Igor Minar | 2011-11-30 11:03:42 -0500 |
| commit | 3ae3ccf3dab95793c868d626a4560aacf3cae796 (patch) | |
| tree | c199b2f45b729f9858a9ab153c35c15f1ee237ba /test | |
| parent | e9b57f9df8eb4aaa2c1657d303c78dc68828091b (diff) | |
| download | angular.js-3ae3ccf3dab95793c868d626a4560aacf3cae796.tar.bz2 | |
fix($browser.xhr): fix IE6, IE7 bug - sync xhr when serving from cache
IE6, IE7 is sync when serving content from cache.
We want consistent api, so we have to use setTimeout to make it async.
Diffstat (limited to 'test')
| -rw-r--r-- | test/service/browserSpecs.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/service/browserSpecs.js b/test/service/browserSpecs.js index a3ec6486..05c1dec0 100644 --- a/test/service/browserSpecs.js +++ b/test/service/browserSpecs.js @@ -227,6 +227,35 @@ describe('browser', function() { it('should return raw xhr object', function() { expect(browser.xhr('GET', '/url', null, noop)).toBe(xhr); }); + + it('should be async even if xhr.send() is sync', function() { + // IE6, IE7 is sync when serving from cache + var xhr; + function FakeXhr() { + xhr = this; + this.open = this.setRequestHeader = noop; + this.send = function() { + this.status = 200; + this.responseText = 'response'; + this.readyState = 4; + }; + } + + var callback = jasmine.createSpy('done').andCallFake(function(status, response) { + expect(status).toBe(200); + expect(response).toBe('response'); + }); + + browser = new Browser(fakeWindow, jqLite(window.document), null, FakeXhr, null); + browser.xhr('GET', '/url', null, callback); + expect(callback).not.toHaveBeenCalled(); + + fakeWindow.setTimeout.flush(); + expect(callback).toHaveBeenCalledOnce(); + + (xhr.onreadystatechange || noop)(); + expect(callback).toHaveBeenCalledOnce(); + }); }); describe('defer', function() { |
