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

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

Issue 1055313002: Added mock_xhr module w/ unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
Index: remoting/webapp/crd/js/gcd_client_with_mock_xhr_unittest.js
diff --git a/remoting/webapp/crd/js/gcd_client_with_mock_xhr_unittest.js b/remoting/webapp/crd/js/gcd_client_with_mock_xhr_unittest.js
new file mode 100644
index 0000000000000000000000000000000000000000..2dedf52c910060f8ed43b0afcf410f03f29e9ec4
--- /dev/null
+++ b/remoting/webapp/crd/js/gcd_client_with_mock_xhr_unittest.js
@@ -0,0 +1,135 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+(function() {
+
+'use strict';
+
+/** @type {remoting.gcd.Client} */
+var client;
+
+/** @const */
+var FAKE_REGISTRATION_TICKET = {
+ kind: 'clouddevices#registrationTicket',
+ id: 'fake_ticket_id',
+ robotAccountEmail: 'fake@robotaccounts.com',
+ robotAccountAuthorizationCode: 'fake_robot_auth_code',
+ deviceDraft: {
+ id: 'fake_device_id'
+ }
+};
+
+/** @const */
+var FAKE_DEVICE = {
+ kind: 'clouddevices#device',
+ id: 'fake_device_id'
+};
+
+/** @const */
+var FAKE_DEVICE_PATCH = {
+ fake_patch: true
+};
+
+/** @const */
+var FAKE_DEVICE_LIST = {
+ kind: 'clouddevices#devicesListResponse',
+ devices: [FAKE_DEVICE]
+};
+
+QUnit.module('gcd_client with mock_xhr', {
+ beforeEach: function() {
+ remoting.MockXhr.activate();
+ remoting.identity = new remoting.Identity();
+ chromeMocks.activate(['identity']);
+ chromeMocks.identity.mock$setToken('fake_token');
+ client = new remoting.gcd.Client({
+ apiBaseUrl: 'https://fake.api',
+ apiKey: 'fake_key',
+ oauthClientId: 'fake_client_id'
+ });
+ },
+ afterEach: function() {
+ chromeMocks.restore();
+ remoting.identity = null;
+ remoting.MockXhr.restore();
+ }
+});
+
+QUnit.test('insertRegistrationTicket', function(assert) {
+ remoting.MockXhr.setResponseFor(
+ 'POST', 'https://fake.api/registrationTickets',
+ function(/** remoting.MockXhr */ xhr) {
+ assert.equal(xhr.params.useIdentity, true);
+ assert.deepEqual(
+ xhr.params.jsonContent,
+ { userEmail: 'me' });
+ xhr.setJsonResponse(200, FAKE_REGISTRATION_TICKET);
+ });
+ return client.insertRegistrationTicket().then(function(ticket) {
+ assert.deepEqual(ticket, FAKE_REGISTRATION_TICKET);
+ });
+});
+
+QUnit.test('patchRegistrationTicket', function(assert) {
+ remoting.MockXhr.setResponseFor(
+ 'POST', 'https://fake.api/registrationTickets/fake_ticket_id',
+ function(/** remoting.MockXhr */ xhr) {
+ assert.equal(xhr.params.useIdentity, true);
+ assert.deepEqual(
+ xhr.params.jsonContent, {
+ deviceDraft: { 'fake_device_draft': true },
+ oauthClientId: 'fake_client_id'
+ });
+ xhr.setJsonResponse(200, FAKE_REGISTRATION_TICKET);
+ });
+ return client.patchRegistrationTicket('fake_ticket_id', {
+ 'fake_device_draft': true
+ }).then(function(ticket) {
+ assert.deepEqual(ticket, FAKE_REGISTRATION_TICKET);
+ });
+});
+
+
+
+QUnit.test('finalizeRegistrationTicket', function(assert) {
+ remoting.MockXhr.setResponseFor(
+ 'POST', 'https://fake.api/registrationTickets/fake_ticket_id/finalize',
+ function(/** remoting.MockXhr */ xhr) {
+ assert.equal(xhr.params.urlParams['key'], 'fake_key');
+ assert.equal(xhr.params.useIdentity, false);
+ xhr.setJsonResponse(200, FAKE_REGISTRATION_TICKET);
+ });
+ return client.finalizeRegistrationTicket('fake_ticket_id').
+ then(function(ticket) {
+ assert.deepEqual(ticket, FAKE_REGISTRATION_TICKET);
+ });
+});
+
+QUnit.test('listDevices', function(assert) {
+ remoting.MockXhr.setResponseFor(
+ 'GET', 'https://fake.api/devices',
+ function(/** remoting.MockXhr */ xhr) {
+ assert.equal(xhr.params.useIdentity, true);
+ xhr.setJsonResponse(200, FAKE_DEVICE_LIST);
+ });
+ return client.listDevices().then(function(devices) {
+ assert.deepEqual(devices, [FAKE_DEVICE]);
+ });
+});
+
+QUnit.test('patchDevice', function(assert) {
+ remoting.MockXhr.setResponseFor(
+ 'PATCH', 'https://fake.api/devices/fake_device_id',
+ function(/** remoting.MockXhr */ xhr) {
+ assert.equal(xhr.params.useIdentity, true);
+ assert.deepEqual(xhr.params.jsonContent, FAKE_DEVICE_PATCH);
+ xhr.setJsonResponse(200, FAKE_DEVICE);
+ });
+ return client.patchDevice('fake_device_id', FAKE_DEVICE_PATCH).
+ then(function(device) {
+ assert.deepEqual(device, FAKE_DEVICE);
+ });
+});
+
+})();

Powered by Google App Engine
This is Rietveld 408576698