Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit e9b57f9

Browse files
vojtajinaIgorMinar
authored andcommitted
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).
1 parent 45f47ff commit e9b57f9

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/service/browser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function Browser(window, document, body, XHR, $log, $sniffer) {
109109
if (window[callbackId].data) {
110110
completeOutstandingRequest(callback, 200, window[callbackId].data);
111111
} else {
112-
completeOutstandingRequest(callback);
112+
completeOutstandingRequest(callback, -2);
113113
}
114114
delete window[callbackId];
115115
body[0].removeChild(script);

src/service/xhr.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
function() {
166166
element(':button:contains("Invalid JSONP")').click();
167167
element(':button:contains("fetch")').click();
168-
expect(binding('code')).toBe('code=');
168+
expect(binding('code')).toBe('code=-2');
169169
expect(binding('response')).toBe('response=Request failed');
170170
});
171171
</doc:scenario>

test/service/browserSpecs.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ describe('browser', function() {
147147
});
148148

149149

150-
it('should call callback when script fails to load', function() {
150+
it('should call callback with status -2 when script fails to load', function() {
151151
browser.xhr('JSONP', 'http://example.org/path?cb=JSON_CALLBACK', null, callback);
152152
var script = scripts[0];
153153
expect(typeof script.onload).toBe('function');
154154
expect(typeof script.onerror).toBe('function');
155155
script.onerror();
156156

157-
expect(log).toEqual('undefined:undefined;');
157+
expect(log).toEqual('-2:undefined;');
158158
});
159159

160160

0 commit comments

Comments
 (0)