| Index: remoting/webapp/unittests/xhr_unittest.js
|
| diff --git a/remoting/webapp/unittests/xhr_unittest.js b/remoting/webapp/unittests/xhr_unittest.js
|
| index 2e09519f69d08c66ecfeb4c6e503de68a9fca8b4..f4a62e43e97e74169dc6b721a1f60b46a51a504f 100644
|
| --- a/remoting/webapp/unittests/xhr_unittest.js
|
| +++ b/remoting/webapp/unittests/xhr_unittest.js
|
| @@ -28,115 +28,156 @@ test('urlencodeParamHash', function() {
|
| 'k1=v1&k2=v2');
|
| });
|
|
|
| -asyncTest('get', function() {
|
| +asyncTest('basic GET', function() {
|
| sinon.useFakeXMLHttpRequest();
|
| - var request = remoting.xhr.get('http://foo.com', function(xhr) {
|
| - QUnit.ok(xhr === request);
|
| - QUnit.equal(xhr.status, 200);
|
| - QUnit.equal(xhr.responseText, 'body');
|
| - QUnit.start();
|
| + var request = remoting.xhr.start({
|
| + method: 'GET',
|
| + url: 'http://foo.com',
|
| + onDone: function(xhr) {
|
| + QUnit.ok(xhr === request);
|
| + QUnit.equal(xhr.status, 200);
|
| + QUnit.equal(xhr.responseText, 'body');
|
| + QUnit.start();
|
| + }
|
| });
|
| QUnit.equal(request.method, 'GET');
|
| QUnit.equal(request.url, 'http://foo.com');
|
| QUnit.equal(request.withCredentials, false);
|
| QUnit.equal(request.requestBody, null);
|
| + QUnit.ok(!('Content-type' in request.requestHeaders));
|
| request.respond(200, {}, 'body');
|
| });
|
|
|
| -asyncTest('get with param string', function() {
|
| +asyncTest('GET with param string', function() {
|
| sinon.useFakeXMLHttpRequest();
|
| - var request = remoting.xhr.get('http://foo.com', function(xhr) {
|
| - QUnit.ok(xhr === request);
|
| - QUnit.equal(xhr.status, 200);
|
| - QUnit.equal(xhr.responseText, 'body');
|
| - QUnit.start();
|
| - }, 'the_param_string');
|
| + var request = remoting.xhr.start({
|
| + method: 'GET',
|
| + url: 'http://foo.com',
|
| + onDone: function(xhr) {
|
| + QUnit.ok(xhr === request);
|
| + QUnit.equal(xhr.status, 200);
|
| + QUnit.equal(xhr.responseText, 'body');
|
| + QUnit.start();
|
| + },
|
| + urlParams: 'the_param_string'
|
| + });
|
| QUnit.equal(request.method, 'GET');
|
| QUnit.equal(request.url, 'http://foo.com?the_param_string');
|
| QUnit.equal(request.withCredentials, false);
|
| QUnit.equal(request.requestBody, null);
|
| + QUnit.ok(!('Content-type' in request.requestHeaders));
|
| request.respond(200, {}, 'body');
|
| });
|
|
|
| -asyncTest('get with param object', function() {
|
| +asyncTest('GET with param object', function() {
|
| sinon.useFakeXMLHttpRequest();
|
| - var request = remoting.xhr.get('http://foo.com', function(xhr) {
|
| - QUnit.ok(xhr === request);
|
| - QUnit.equal(xhr.status, 200);
|
| - QUnit.equal(xhr.responseText, 'body');
|
| - QUnit.start();
|
| - }, {'a': 'b', 'c': 'd'});
|
| + var request = remoting.xhr.start({
|
| + method: 'GET',
|
| + url: 'http://foo.com',
|
| + onDone: function(xhr) {
|
| + QUnit.ok(xhr === request);
|
| + QUnit.equal(xhr.status, 200);
|
| + QUnit.equal(xhr.responseText, 'body');
|
| + QUnit.start();
|
| + },
|
| + urlParams: {'a': 'b', 'c': 'd'}
|
| + });
|
| QUnit.equal(request.method, 'GET');
|
| QUnit.equal(request.url, 'http://foo.com?a=b&c=d');
|
| QUnit.equal(request.withCredentials, false);
|
| QUnit.equal(request.requestBody, null);
|
| + QUnit.ok(!('Content-type' in request.requestHeaders));
|
| request.respond(200, {}, 'body');
|
| });
|
|
|
| -asyncTest('get with headers', function() {
|
| +asyncTest('GET with headers', function() {
|
| sinon.useFakeXMLHttpRequest();
|
| - var request = remoting.xhr.get('http://foo.com', function(xhr) {
|
| - QUnit.ok(xhr === request);
|
| - QUnit.equal(xhr.status, 200);
|
| - QUnit.equal(xhr.responseText, 'body');
|
| - QUnit.equal(
|
| - xhr.requestHeaders['Header1'],
|
| - 'headerValue1');
|
| - QUnit.equal(
|
| - xhr.requestHeaders['Header2'],
|
| - 'headerValue2');
|
| - QUnit.start();
|
| - }, undefined, {'Header1': 'headerValue1', 'Header2': 'headerValue2'});
|
| + var request = remoting.xhr.start({
|
| + method: 'GET',
|
| + url: 'http://foo.com',
|
| + onDone: function(xhr) {
|
| + QUnit.ok(xhr === request);
|
| + QUnit.equal(xhr.status, 200);
|
| + QUnit.equal(xhr.responseText, 'body');
|
| + QUnit.start();
|
| + },
|
| + headers: {'Header1': 'headerValue1', 'Header2': 'headerValue2'}
|
| + });
|
| QUnit.equal(request.method, 'GET');
|
| QUnit.equal(request.url, 'http://foo.com');
|
| QUnit.equal(request.withCredentials, false);
|
| QUnit.equal(request.requestBody, null);
|
| + QUnit.equal(
|
| + request.requestHeaders['Header1'],
|
| + 'headerValue1');
|
| + QUnit.equal(
|
| + request.requestHeaders['Header2'],
|
| + 'headerValue2');
|
| + QUnit.ok(!('Content-type' in request.requestHeaders));
|
| request.respond(200, {}, 'body');
|
| });
|
|
|
|
|
| -asyncTest('get with credentials', function() {
|
| +asyncTest('GET with credentials', function() {
|
| sinon.useFakeXMLHttpRequest();
|
| - var request = remoting.xhr.get('http://foo.com', function(xhr) {
|
| - QUnit.ok(xhr === request);
|
| - QUnit.equal(xhr.status, 200);
|
| - QUnit.equal(xhr.responseText, 'body');
|
| - QUnit.start();
|
| - }, undefined, undefined, true);
|
| + var request = remoting.xhr.start({
|
| + method: 'GET',
|
| + url: 'http://foo.com',
|
| + onDone: function(xhr) {
|
| + QUnit.ok(xhr === request);
|
| + QUnit.equal(xhr.status, 200);
|
| + QUnit.equal(xhr.responseText, 'body');
|
| + QUnit.start();
|
| + },
|
| + withCredentials: true
|
| + });
|
| QUnit.equal(request.method, 'GET');
|
| QUnit.equal(request.url, 'http://foo.com');
|
| QUnit.equal(request.withCredentials, true);
|
| QUnit.equal(request.requestBody, null);
|
| + QUnit.ok(!('Content-type' in request.requestHeaders));
|
| request.respond(200, {}, 'body');
|
| });
|
|
|
| -asyncTest('post with param string', function() {
|
| +asyncTest('POST with text content', function() {
|
| sinon.useFakeXMLHttpRequest();
|
| - var request = remoting.xhr.post('http://foo.com', function(xhr) {
|
| - QUnit.ok(xhr === request);
|
| - QUnit.equal(xhr.status, 200);
|
| - QUnit.equal(xhr.responseText, 'body');
|
| - QUnit.start();
|
| - }, 'the_param_string');
|
| + var request = remoting.xhr.start({
|
| + method: 'POST',
|
| + url: 'http://foo.com',
|
| + onDone: function(xhr) {
|
| + QUnit.ok(xhr === request);
|
| + QUnit.equal(xhr.status, 200);
|
| + QUnit.equal(xhr.responseText, 'body');
|
| + QUnit.start();
|
| + },
|
| + textContent: 'the_content_string'
|
| + });
|
| QUnit.equal(request.method, 'POST');
|
| QUnit.equal(request.url, 'http://foo.com');
|
| QUnit.equal(request.withCredentials, false);
|
| - QUnit.equal(request.requestBody, 'the_param_string');
|
| + QUnit.equal(request.requestBody, 'the_content_string');
|
| + QUnit.ok(!('Content-type' in request.requestHeaders));
|
| request.respond(200, {}, 'body');
|
| });
|
|
|
| -asyncTest('get with param object', function() {
|
| +asyncTest('POST with form content', function() {
|
| sinon.useFakeXMLHttpRequest();
|
| - var request = remoting.xhr.post('http://foo.com', function(xhr) {
|
| - QUnit.ok(xhr === request);
|
| - QUnit.equal(xhr.status, 200);
|
| - QUnit.equal(xhr.responseText, 'body');
|
| - QUnit.start();
|
| - }, {'a': 'b', 'c': 'd'});
|
| + var request = remoting.xhr.start({
|
| + method: 'POST',
|
| + url: 'http://foo.com',
|
| + onDone: function(xhr) {
|
| + QUnit.ok(xhr === request);
|
| + QUnit.equal(xhr.status, 200);
|
| + QUnit.equal(xhr.responseText, 'body');
|
| + QUnit.start();
|
| + },
|
| + formContent: {'a': 'b', 'c': 'd'}
|
| + });
|
| QUnit.equal(request.method, 'POST');
|
| QUnit.equal(request.url, 'http://foo.com');
|
| QUnit.equal(request.withCredentials, false);
|
| QUnit.equal(request.requestBody, 'a=b&c=d');
|
| + QUnit.equal(request.requestHeaders['Content-type'], 'application/x-www-form-urlencoded');
|
| request.respond(200, {}, 'body');
|
| });
|
|
|
| @@ -153,8 +194,11 @@ asyncTest('defaultResponse 200', function() {
|
| QUnit.start();
|
| };
|
|
|
| - var request = remoting.xhr.post(
|
| - 'http://foo.com', remoting.xhr.defaultResponse(onDone, onError));
|
| + var request = remoting.xhr.start({
|
| + method: 'POST',
|
| + url: 'http://foo.com',
|
| + onDone: remoting.xhr.defaultResponse(onDone, onError)
|
| + });
|
| request.respond(200);
|
| });
|
|
|
| @@ -172,8 +216,11 @@ asyncTest('defaultResponse 404', function() {
|
| QUnit.start();
|
| };
|
|
|
| - var request = remoting.xhr.post(
|
| - 'http://foo.com', remoting.xhr.defaultResponse(onDone, onError));
|
| + var request = remoting.xhr.start({
|
| + method: 'POST',
|
| + url: 'http://foo.com',
|
| + onDone: remoting.xhr.defaultResponse(onDone, onError)
|
| + });
|
| request.respond(404);
|
| });
|
|
|
|
|