aboutsummaryrefslogtreecommitdiffstats
path: root/test/service/httpBackendSpec.js
diff options
context:
space:
mode:
authorVojta Jina2011-11-03 17:14:03 -0700
committerIgor Minar2011-11-30 11:17:24 -0500
commitcaeb1bf899bfcc10b5860ad1b6632a3fe7b0b85f (patch)
tree3c3a34be238f3cbcd68905b6558b309747e57749 /test/service/httpBackendSpec.js
parent9b4efa73f9eef7c22895ca269760eb11ecb54b30 (diff)
downloadangular.js-caeb1bf899bfcc10b5860ad1b6632a3fe7b0b85f.tar.bz2
feat($httpBackend): fix 0 status code when "file" protocol
Browsers return always 0 status code for "file" protocol, so we convert them into 200/404.
Diffstat (limited to 'test/service/httpBackendSpec.js')
-rw-r--r--test/service/httpBackendSpec.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/service/httpBackendSpec.js b/test/service/httpBackendSpec.js
index e609eea6..ccd9e4b6 100644
--- a/test/service/httpBackendSpec.js
+++ b/test/service/httpBackendSpec.js
@@ -175,5 +175,60 @@ describe('$httpBackend', function() {
// TODO(vojta): test whether it fires "async-start"
// TODO(vojta): test whether it fires "async-end" on both success and error
});
+
+ describe('file protocol', function() {
+
+ function respond(status, content) {
+ xhr = MockXhr.$$lastInstance;
+ xhr.status = status;
+ xhr.responseText = content;
+ xhr.readyState = 4;
+ xhr.onreadystatechange();
+ }
+
+
+ it('should convert 0 to 200 if content', function() {
+ $backend = createHttpBackend($browser, MockXhr, null, null, null, 'http');
+
+ $backend('GET', 'file:///whatever/index.html', null, callback);
+ respond(0, 'SOME CONTENT');
+
+ expect(callback).toHaveBeenCalled();
+ expect(callback.mostRecentCall.args[0]).toBe(200);
+ });
+
+
+ it('should convert 0 to 200 if content - relative url', function() {
+ $backend = createHttpBackend($browser, MockXhr, null, null, null, 'file');
+
+ $backend('GET', '/whatever/index.html', null, callback);
+ respond(0, 'SOME CONTENT');
+
+ expect(callback).toHaveBeenCalled();
+ expect(callback.mostRecentCall.args[0]).toBe(200);
+ });
+
+
+ it('should convert 0 to 404 if no content', function() {
+ $backend = createHttpBackend($browser, MockXhr, null, null, null, 'http');
+
+ $backend('GET', 'file:///whatever/index.html', null, callback);
+ respond(0, '');
+
+ expect(callback).toHaveBeenCalled();
+ expect(callback.mostRecentCall.args[0]).toBe(404);
+ });
+
+
+ it('should convert 0 to 200 if content - relative url', function() {
+ $backend = createHttpBackend($browser, MockXhr, null, null, null, 'file');
+
+ $backend('GET', '/whatever/index.html', null, callback);
+ respond(0, '');
+
+ expect(callback).toHaveBeenCalled();
+ expect(callback.mostRecentCall.args[0]).toBe(404);
+ });
+ });
});