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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « remoting/webapp/crd/js/xhr.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 */ 7 */
8 8
9 (function() { 9 (function() {
10 10
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 // 175 //
176 // The typical case. 176 // The typical case.
177 // 177 //
178 178
179 QUnit.test('successful GET', function(assert) { 179 QUnit.test('successful GET', function(assert) {
180 var promise = new remoting.Xhr({ 180 var promise = new remoting.Xhr({
181 method: 'GET', 181 method: 'GET',
182 url: 'http://foo.com' 182 url: 'http://foo.com'
183 }).start().then(function(response) { 183 }).start().then(function(response) {
184 assert.ok(!response.isError());
184 assert.equal(response.status, 200); 185 assert.equal(response.status, 200);
185 assert.equal(response.getText(), 'body'); 186 assert.equal(response.getText(), 'body');
186 }); 187 });
187 assert.equal(fakeXhr.method, 'GET'); 188 assert.equal(fakeXhr.method, 'GET');
188 assert.equal(fakeXhr.url, 'http://foo.com'); 189 assert.equal(fakeXhr.url, 'http://foo.com');
189 assert.equal(fakeXhr.withCredentials, false); 190 assert.equal(fakeXhr.withCredentials, false);
190 assert.equal(fakeXhr.requestBody, null); 191 assert.equal(fakeXhr.requestBody, null);
191 assert.ok(!('Content-type' in fakeXhr.requestHeaders)); 192 assert.ok(!('Content-type' in fakeXhr.requestHeaders));
192 fakeXhr.respond(200, {}, 'body'); 193 fakeXhr.respond(200, {}, 'body');
193 return promise; 194 return promise;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 }); 336 });
336 337
337 QUnit.test('GET with useIdentity', function(assert) { 338 QUnit.test('GET with useIdentity', function(assert) {
338 var xhr = new remoting.Xhr({ 339 var xhr = new remoting.Xhr({
339 method: 'GET', 340 method: 'GET',
340 url: 'http://foo.com', 341 url: 'http://foo.com',
341 useIdentity: true 342 useIdentity: true
342 }); 343 });
343 344
344 xhr.start(); 345 xhr.start();
345
346 var done = assert.async(); 346 var done = assert.async();
347 fakeXhr.addEventListener('loadstart', function() { 347 fakeXhr.addEventListener('loadstart', function() {
348 assert.equal(fakeXhr.requestHeaders['Authorization'], 348 assert.equal(fakeXhr.requestHeaders['Authorization'],
349 'Bearer my_token'); 349 'Bearer my_token');
350 done(); 350 done();
351 }); 351 });
352 }); 352 });
353 353
354 //
355 // Error responses.
356 //
357 QUnit.test('GET with error response', function(assert) {
358 var promise = new remoting.Xhr({
359 method: 'GET',
360 url: 'http://foo.com'
361 }).start().then(function(response) {
362 assert.ok(response.isError());
363 assert.equal(response.status, 500);
364 assert.equal(response.getText(), 'body');
365 });
366 fakeXhr.respond(500, {}, 'body');
367 return promise;
368 });
369
370 QUnit.test('204 is not an error', function(assert) {
371 var promise = new remoting.Xhr({
372 method: 'GET',
373 url: 'http://foo.com'
374 }).start().then(function(response) {
375 assert.ok(!response.isError());
376 assert.equal(response.status, 204);
377 assert.equal(response.getText(), '');
378 });
379 fakeXhr.respond(204, {}, null);
380 return promise;
381 });
382
383 QUnit.test('GET with non-HTTP response', function(assert) {
384 var promise = new remoting.Xhr({
385 method: 'GET',
386 url: 'http://foo.com'
387 }).start().then(function(response) {
388 assert.ok(response.isError());
389 });
390 fakeXhr.respond(0, {}, null);
391 return promise;
392 });
393
354 })(); 394 })();
OLDNEW
« 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