Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(895)

Unified Diff: remoting/webapp/crd/js/xhr_unittest.js

Issue 1039853002: Added isError method to remoting.Xhr.Error to check for HTTP errors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/webapp/crd/js/xhr.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/crd/js/xhr_unittest.js
diff --git a/remoting/webapp/crd/js/xhr_unittest.js b/remoting/webapp/crd/js/xhr_unittest.js
index c8e96e0fc995516d054bbf2fb659f36dec5ec3b3..f5cb772b45f856f3c830075032be39521887d309 100644
--- a/remoting/webapp/crd/js/xhr_unittest.js
+++ b/remoting/webapp/crd/js/xhr_unittest.js
@@ -181,6 +181,7 @@ QUnit.test('successful GET', function(assert) {
method: 'GET',
url: 'http://foo.com'
}).start().then(function(response) {
+ assert.ok(!response.isError());
assert.equal(response.status, 200);
assert.equal(response.getText(), 'body');
});
@@ -342,7 +343,6 @@ QUnit.test('GET with useIdentity', function(assert) {
});
xhr.start();
-
var done = assert.async();
fakeXhr.addEventListener('loadstart', function() {
assert.equal(fakeXhr.requestHeaders['Authorization'],
@@ -351,4 +351,44 @@ QUnit.test('GET with useIdentity', function(assert) {
});
});
+//
+// Error responses.
+//
+QUnit.test('GET with error response', function(assert) {
+ var promise = new remoting.Xhr({
+ method: 'GET',
+ url: 'http://foo.com'
+ }).start().then(function(response) {
+ assert.ok(response.isError());
+ assert.equal(response.status, 500);
+ assert.equal(response.getText(), 'body');
+ });
+ fakeXhr.respond(500, {}, 'body');
+ return promise;
+});
+
+QUnit.test('204 is not an error', function(assert) {
+ var promise = new remoting.Xhr({
+ method: 'GET',
+ url: 'http://foo.com'
+ }).start().then(function(response) {
+ assert.ok(!response.isError());
+ assert.equal(response.status, 204);
+ assert.equal(response.getText(), '');
+ });
+ fakeXhr.respond(204, {}, null);
+ return promise;
+});
+
+QUnit.test('GET with non-HTTP response', function(assert) {
+ var promise = new remoting.Xhr({
+ method: 'GET',
+ url: 'http://foo.com'
+ }).start().then(function(response) {
+ assert.ok(response.isError());
+ });
+ fakeXhr.respond(0, {}, null);
+ return promise;
+});
+
})();
« no previous file with comments | « remoting/webapp/crd/js/xhr.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698