| Index: remoting/webapp/unittests/xhr_unittest.js
|
| diff --git a/remoting/webapp/unittests/xhr_unittest.js b/remoting/webapp/unittests/xhr_unittest.js
|
| index ea32042abe9f6c60cbfc3322af9ee19b201febe2..69f423519ddf2f3df40c8e2a663cf83a927147f4 100644
|
| --- a/remoting/webapp/unittests/xhr_unittest.js
|
| +++ b/remoting/webapp/unittests/xhr_unittest.js
|
| @@ -11,224 +11,228 @@
|
|
|
| 'use strict';
|
|
|
| -module('xhr', {
|
| - setup: function() {
|
| +var fakeXhr;
|
| +
|
| +QUnit.module('xhr', {
|
| + beforeEach: function() {
|
| + fakeXhr = null;
|
| + sinon.useFakeXMLHttpRequest().onCreate = function(xhr) {
|
| + fakeXhr = xhr;
|
| + };
|
| },
|
| - teardown: function() {
|
| + afterEach: function() {
|
| }
|
| });
|
|
|
| -test('urlencodeParamHash', function() {
|
| +QUnit.test('urlencodeParamHash', function() {
|
| QUnit.equal(
|
| - remoting.xhr.urlencodeParamHash({}),
|
| + remoting.Xhr.urlencodeParamHash({}),
|
| '');
|
| QUnit.equal(
|
| - remoting.xhr.urlencodeParamHash({'key': 'value'}),
|
| + remoting.Xhr.urlencodeParamHash({'key': 'value'}),
|
| 'key=value');
|
| QUnit.equal(
|
| - remoting.xhr.urlencodeParamHash({'key /?=&': 'value /?=&'}),
|
| + remoting.Xhr.urlencodeParamHash({'key /?=&': 'value /?=&'}),
|
| 'key%20%2F%3F%3D%26=value%20%2F%3F%3D%26');
|
| QUnit.equal(
|
| - remoting.xhr.urlencodeParamHash({'k1': 'v1', 'k2': 'v2'}),
|
| + remoting.Xhr.urlencodeParamHash({'k1': 'v1', 'k2': 'v2'}),
|
| 'k1=v1&k2=v2');
|
| });
|
|
|
| -asyncTest('basic GET', function() {
|
| - sinon.useFakeXMLHttpRequest();
|
| - var request = remoting.xhr.start({
|
| +QUnit.test('basic GET', function(assert) {
|
| + var done = assert.async();
|
| +
|
| + new remoting.Xhr({
|
| 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();
|
| - }
|
| + responseType: 'text'
|
| + }).then(function(xhrr) {
|
| + QUnit.equal(xhrr.status, 200);
|
| + QUnit.equal(xhrr.responseText, 'body');
|
| + done();
|
| });
|
| - 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');
|
| + QUnit.equal(fakeXhr.method, 'GET');
|
| + QUnit.equal(fakeXhr.url, 'http://foo.com');
|
| + QUnit.equal(fakeXhr.withCredentials, false);
|
| + QUnit.equal(fakeXhr.requestBody, null);
|
| + QUnit.ok(!('Content-type' in fakeXhr.requestHeaders));
|
| + fakeXhr.respond(200, {}, 'body');
|
| });
|
|
|
| -asyncTest('GET with param string', function() {
|
| - sinon.useFakeXMLHttpRequest();
|
| - var request = remoting.xhr.start({
|
| +QUnit.test('GET with param string', function(assert) {
|
| + var done = assert.async();
|
| +
|
| + new remoting.Xhr({
|
| 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();
|
| - },
|
| + responseType: 'text',
|
| urlParams: 'the_param_string'
|
| + }).then(function(xhrr) {
|
| + QUnit.equal(xhrr.status, 200);
|
| + QUnit.equal(xhrr.responseText, 'body');
|
| + done();
|
| });
|
| - 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');
|
| + QUnit.equal(fakeXhr.method, 'GET');
|
| + QUnit.equal(fakeXhr.url, 'http://foo.com?the_param_string');
|
| + QUnit.equal(fakeXhr.withCredentials, false);
|
| + QUnit.equal(fakeXhr.requestBody, null);
|
| + QUnit.ok(!('Content-type' in fakeXhr.requestHeaders));
|
| + fakeXhr.respond(200, {}, 'body');
|
| });
|
|
|
| -asyncTest('GET with param object', function() {
|
| - sinon.useFakeXMLHttpRequest();
|
| - var request = remoting.xhr.start({
|
| +QUnit.test('GET with param object', function(assert) {
|
| + var done = assert.async();
|
| +
|
| + new remoting.Xhr({
|
| 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();
|
| - },
|
| + responseType: 'text',
|
| urlParams: {'a': 'b', 'c': 'd'}
|
| + }).then(function(xhrr) {
|
| + QUnit.equal(xhrr.status, 200);
|
| + QUnit.equal(xhrr.responseText, 'body');
|
| + done();
|
| });
|
| - 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');
|
| + QUnit.equal(fakeXhr.method, 'GET');
|
| + QUnit.equal(fakeXhr.url, 'http://foo.com?a=b&c=d');
|
| + QUnit.equal(fakeXhr.withCredentials, false);
|
| + QUnit.equal(fakeXhr.requestBody, null);
|
| + QUnit.ok(!('Content-type' in fakeXhr.requestHeaders));
|
| + fakeXhr.respond(200, {}, 'body');
|
| });
|
|
|
| -asyncTest('GET with headers', function() {
|
| - sinon.useFakeXMLHttpRequest();
|
| - var request = remoting.xhr.start({
|
| +QUnit.test('GET with headers', function(assert) {
|
| + var done = assert.async();
|
| +
|
| + new remoting.Xhr({
|
| 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();
|
| - },
|
| + responseType: 'text',
|
| headers: {'Header1': 'headerValue1', 'Header2': 'headerValue2'}
|
| + }).then(function(xhrr) {
|
| + QUnit.equal(xhrr.status, 200);
|
| + QUnit.equal(xhrr.responseText, 'body');
|
| + done();
|
| });
|
| - QUnit.equal(request.method, 'GET');
|
| - QUnit.equal(request.url, 'http://foo.com');
|
| - QUnit.equal(request.withCredentials, false);
|
| - QUnit.equal(request.requestBody, null);
|
| + QUnit.equal(fakeXhr.method, 'GET');
|
| + QUnit.equal(fakeXhr.url, 'http://foo.com');
|
| + QUnit.equal(fakeXhr.withCredentials, false);
|
| + QUnit.equal(fakeXhr.requestBody, null);
|
| QUnit.equal(
|
| - request.requestHeaders['Header1'],
|
| + fakeXhr.requestHeaders['Header1'],
|
| 'headerValue1');
|
| QUnit.equal(
|
| - request.requestHeaders['Header2'],
|
| + fakeXhr.requestHeaders['Header2'],
|
| 'headerValue2');
|
| - QUnit.ok(!('Content-type' in request.requestHeaders));
|
| - request.respond(200, {}, 'body');
|
| + QUnit.ok(!('Content-type' in fakeXhr.requestHeaders));
|
| + fakeXhr.respond(200, {}, 'body');
|
| });
|
|
|
|
|
| -asyncTest('GET with credentials', function() {
|
| - sinon.useFakeXMLHttpRequest();
|
| - var request = remoting.xhr.start({
|
| +QUnit.test('GET with credentials', function(assert) {
|
| + var done = assert.async();
|
| +
|
| + new remoting.Xhr({
|
| 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();
|
| - },
|
| + responseType: 'text',
|
| withCredentials: true
|
| + }).then(function(xhrr) {
|
| + QUnit.equal(xhrr.status, 200);
|
| + QUnit.equal(xhrr.responseText, 'body');
|
| + done();
|
| });
|
| - 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');
|
| + QUnit.equal(fakeXhr.method, 'GET');
|
| + QUnit.equal(fakeXhr.url, 'http://foo.com');
|
| + QUnit.equal(fakeXhr.withCredentials, true);
|
| + QUnit.equal(fakeXhr.requestBody, null);
|
| + QUnit.ok(!('Content-type' in fakeXhr.requestHeaders));
|
| + fakeXhr.respond(200, {}, 'body');
|
| });
|
|
|
| -asyncTest('POST with text content', function() {
|
| - sinon.useFakeXMLHttpRequest();
|
| - var request = remoting.xhr.start({
|
| +QUnit.test('POST with text content', function(assert) {
|
| + var done = assert.async();
|
| +
|
| + new remoting.Xhr({
|
| 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();
|
| - },
|
| + responseType: 'text',
|
| textContent: 'the_content_string'
|
| + }).then(function(xhrr) {
|
| + QUnit.equal(xhrr.status, 200);
|
| + QUnit.equal(xhrr.responseText, 'body');
|
| + done();
|
| });
|
| - QUnit.equal(request.method, 'POST');
|
| - QUnit.equal(request.url, 'http://foo.com');
|
| - QUnit.equal(request.withCredentials, false);
|
| - QUnit.equal(request.requestBody, 'the_content_string');
|
| - QUnit.ok(!('Content-type' in request.requestHeaders));
|
| - request.respond(200, {}, 'body');
|
| + QUnit.equal(fakeXhr.method, 'POST');
|
| + QUnit.equal(fakeXhr.url, 'http://foo.com');
|
| + QUnit.equal(fakeXhr.withCredentials, false);
|
| + QUnit.equal(fakeXhr.requestBody, 'the_content_string');
|
| + QUnit.ok(!('Content-type' in fakeXhr.requestHeaders));
|
| + fakeXhr.respond(200, {}, 'body');
|
| });
|
|
|
| -asyncTest('POST with form content', function() {
|
| - sinon.useFakeXMLHttpRequest();
|
| - var request = remoting.xhr.start({
|
| +QUnit.test('POST with form content', function(assert) {
|
| + var done = assert.async();
|
| +
|
| + new remoting.Xhr({
|
| 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();
|
| - },
|
| + responseType: 'text',
|
| formContent: {'a': 'b', 'c': 'd'}
|
| + }).then(function(xhrr) {
|
| + QUnit.equal(xhrr.status, 200);
|
| + QUnit.equal(xhrr.responseText, 'body');
|
| + done();
|
| });
|
| - 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(fakeXhr.method, 'POST');
|
| + QUnit.equal(fakeXhr.url, 'http://foo.com');
|
| + QUnit.equal(fakeXhr.withCredentials, false);
|
| + QUnit.equal(fakeXhr.requestBody, 'a=b&c=d');
|
| QUnit.equal(
|
| - request.requestHeaders['Content-type'],
|
| + fakeXhr.requestHeaders['Content-type'],
|
| 'application/x-www-form-urlencoded');
|
| - request.respond(200, {}, 'body');
|
| + fakeXhr.respond(200, {}, 'body');
|
| });
|
|
|
| -asyncTest('defaultResponse 200', function() {
|
| - sinon.useFakeXMLHttpRequest();
|
| +QUnit.test('defaultResponse 200', function(assert) {
|
| + var done = assert.async();
|
|
|
| var onDone = function() {
|
| QUnit.ok(true);
|
| - QUnit.start();
|
| + done();
|
| };
|
|
|
| var onError = function(error) {
|
| QUnit.ok(false);
|
| - QUnit.start();
|
| + done();
|
| };
|
|
|
| - var request = remoting.xhr.start({
|
| + new remoting.Xhr({
|
| method: 'POST',
|
| - url: 'http://foo.com',
|
| - onDone: remoting.xhr.defaultResponse(onDone, onError)
|
| - });
|
| - request.respond(200);
|
| + url: 'http://foo.com'
|
| + }).then(remoting.Xhr.defaultResponse(onDone, onError));
|
| + fakeXhr.respond(200);
|
| });
|
|
|
|
|
| -asyncTest('defaultResponse 404', function() {
|
| - sinon.useFakeXMLHttpRequest();
|
| +QUnit.test('defaultResponse 404', function(assert) {
|
| + var done = assert.async();
|
|
|
| var onDone = function() {
|
| QUnit.ok(false);
|
| - QUnit.start();
|
| + done();
|
| };
|
|
|
| var onError = function(error) {
|
| QUnit.ok(true);
|
| - QUnit.start();
|
| + done();
|
| };
|
|
|
| - var request = remoting.xhr.start({
|
| + new remoting.Xhr({
|
| method: 'POST',
|
| - url: 'http://foo.com',
|
| - onDone: remoting.xhr.defaultResponse(onDone, onError)
|
| - });
|
| - request.respond(404);
|
| + url: 'http://foo.com'
|
| + }).then(remoting.Xhr.defaultResponse(onDone, onError));
|
| + fakeXhr.respond(404);
|
| });
|
|
|
| })();
|
|
|