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

Side by Side 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: for submit 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 unified diff | Download patch
« no previous file with comments | « remoting/webapp/base/js/base_unittest.js ('k') | remoting/webapp/crd/js/mock_xhr.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 (function() {
6
7 'use strict';
8
9 /** @type {remoting.gcd.Client} */
10 var client;
11
12 /** @const */
13 var FAKE_REGISTRATION_TICKET = {
14 kind: 'clouddevices#registrationTicket',
15 id: 'fake_ticket_id',
16 robotAccountEmail: 'fake@robotaccounts.com',
17 robotAccountAuthorizationCode: 'fake_robot_auth_code',
18 deviceDraft: {
19 id: 'fake_device_id'
20 }
21 };
22
23 /** @const */
24 var FAKE_DEVICE = {
25 kind: 'clouddevices#device',
26 id: 'fake_device_id'
27 };
28
29 /** @const */
30 var FAKE_DEVICE_PATCH = {
31 fake_patch: true
32 };
33
34 /** @const */
35 var FAKE_DEVICE_LIST = {
36 kind: 'clouddevices#devicesListResponse',
37 devices: [FAKE_DEVICE]
38 };
39
40 QUnit.module('gcd_client with mock_xhr', {
41 beforeEach: function() {
42 remoting.MockXhr.activate();
43 remoting.identity = new remoting.Identity();
44 chromeMocks.activate(['identity']);
45 chromeMocks.identity.mock$setToken('fake_token');
46 client = new remoting.gcd.Client({
47 apiBaseUrl: 'https://fake.api',
48 apiKey: 'fake_key',
49 oauthClientId: 'fake_client_id'
50 });
51 },
52 afterEach: function() {
53 chromeMocks.restore();
54 remoting.identity = null;
55 remoting.MockXhr.restore();
56 }
57 });
58
59 QUnit.test('insertRegistrationTicket', function(assert) {
60 remoting.MockXhr.setResponseFor(
61 'POST', 'https://fake.api/registrationTickets',
62 function(/** remoting.MockXhr */ xhr) {
63 assert.equal(xhr.params.useIdentity, true);
64 assert.deepEqual(
65 xhr.params.jsonContent,
66 { userEmail: 'me' });
67 xhr.setJsonResponse(200, FAKE_REGISTRATION_TICKET);
68 });
69 return client.insertRegistrationTicket().then(function(ticket) {
70 assert.deepEqual(ticket, FAKE_REGISTRATION_TICKET);
71 });
72 });
73
74 QUnit.test('patchRegistrationTicket', function(assert) {
75 remoting.MockXhr.setResponseFor(
76 'POST', 'https://fake.api/registrationTickets/fake_ticket_id',
77 function(/** remoting.MockXhr */ xhr) {
78 assert.equal(xhr.params.useIdentity, true);
79 assert.deepEqual(
80 xhr.params.jsonContent, {
81 deviceDraft: { 'fake_device_draft': true },
82 oauthClientId: 'fake_client_id'
83 });
84 xhr.setJsonResponse(200, FAKE_REGISTRATION_TICKET);
85 });
86 return client.patchRegistrationTicket('fake_ticket_id', {
87 'fake_device_draft': true
88 }).then(function(ticket) {
89 assert.deepEqual(ticket, FAKE_REGISTRATION_TICKET);
90 });
91 });
92
93
94
95 QUnit.test('finalizeRegistrationTicket', function(assert) {
96 remoting.MockXhr.setResponseFor(
97 'POST', 'https://fake.api/registrationTickets/fake_ticket_id/finalize',
98 function(/** remoting.MockXhr */ xhr) {
99 assert.equal(xhr.params.urlParams['key'], 'fake_key');
100 assert.equal(xhr.params.useIdentity, false);
101 xhr.setJsonResponse(200, FAKE_REGISTRATION_TICKET);
102 });
103 return client.finalizeRegistrationTicket('fake_ticket_id').
104 then(function(ticket) {
105 assert.deepEqual(ticket, FAKE_REGISTRATION_TICKET);
106 });
107 });
108
109 QUnit.test('listDevices', function(assert) {
110 remoting.MockXhr.setResponseFor(
111 'GET', 'https://fake.api/devices',
112 function(/** remoting.MockXhr */ xhr) {
113 assert.equal(xhr.params.useIdentity, true);
114 xhr.setJsonResponse(200, FAKE_DEVICE_LIST);
115 });
116 return client.listDevices().then(function(devices) {
117 assert.deepEqual(devices, [FAKE_DEVICE]);
118 });
119 });
120
121 QUnit.test('patchDevice', function(assert) {
122 remoting.MockXhr.setResponseFor(
123 'PATCH', 'https://fake.api/devices/fake_device_id',
124 function(/** remoting.MockXhr */ xhr) {
125 assert.equal(xhr.params.useIdentity, true);
126 assert.deepEqual(xhr.params.jsonContent, FAKE_DEVICE_PATCH);
127 xhr.setJsonResponse(200, FAKE_DEVICE);
128 });
129 return client.patchDevice('fake_device_id', FAKE_DEVICE_PATCH).
130 then(function(device) {
131 assert.deepEqual(device, FAKE_DEVICE);
132 });
133 });
134
135 })();
OLDNEW
« no previous file with comments | « remoting/webapp/base/js/base_unittest.js ('k') | remoting/webapp/crd/js/mock_xhr.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698