fix($browser.xhr): respond with internal -2 status on jsonp error

If jsonp is not successfull, we return internal status -2.
This internal status should by normalized by $xhr into 0,
but $xhr needs to distinguish between jsonp-error/abort/timeout (all status 0).
This commit is contained in:
Vojta Jina 2011-08-10 16:03:26 +02:00 committed by Igor Minar
parent 45f47ff6cd
commit e9b57f9df8
3 changed files with 4 additions and 4 deletions

View file

@ -109,7 +109,7 @@ function Browser(window, document, body, XHR, $log, $sniffer) {
if (window[callbackId].data) {
completeOutstandingRequest(callback, 200, window[callbackId].data);
} else {
completeOutstandingRequest(callback);
completeOutstandingRequest(callback, -2);
}
delete window[callbackId];
body[0].removeChild(script);

View file

@ -165,7 +165,7 @@
function() {
element(':button:contains("Invalid JSONP")').click();
element(':button:contains("fetch")').click();
expect(binding('code')).toBe('code=');
expect(binding('code')).toBe('code=-2');
expect(binding('response')).toBe('response=Request failed');
});
</doc:scenario>

View file

@ -147,14 +147,14 @@ describe('browser', function() {
});
it('should call callback when script fails to load', function() {
it('should call callback with status -2 when script fails to load', function() {
browser.xhr('JSONP', 'http://example.org/path?cb=JSON_CALLBACK', null, callback);
var script = scripts[0];
expect(typeof script.onload).toBe('function');
expect(typeof script.onerror).toBe('function');
script.onerror();
expect(log).toEqual('undefined:undefined;');
expect(log).toEqual('-2:undefined;');
});