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

Side by Side Diff: remoting/webapp/crd/js/combined_host_list_api_unittest.js

Issue 1217643002: Added HostListApl implementation to connect to legacy directory and GCD. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gcd-e2e
Patch Set: yet another rewrite of host merging logic Created 5 years, 5 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
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 /**
6 * @fileoverview
7 * Unit tests for combined_host_list_api.js.
8 */
9
10 (function() {
11
12 'use strict';
13
14 /** @type {!remoting.MockHostListApi} */
15 var mockGcdApi;
16
17 /** @type {!remoting.MockHostListApi} */
18 var mockLegacyApi;
19
20 /** @type {!remoting.CombinedHostListApi} */
21 var combinedApi;
22
23 /** @type {sinon.TestStub} */
24 var registerWithHostIdStub;
25
26 /** @type {!remoting.Host} */
27 var commonHostGcd;
28
29 /** @type {!remoting.Host} */
30 var commonHostLegacy;
31
32 QUnit.module('CombinedHostListApi', {
33 beforeEach: function(/** QUnit.Assert */ assert) {
34 remoting.settings = new remoting.Settings();
35 remoting.settings['USE_GCD'] = true;
36 remoting.mockIdentity.setAccessToken(
37 remoting.MockIdentity.AccessToken.VALID);
38 mockGcdApi = new remoting.MockHostListApi();
39 mockGcdApi.addMockHost('gcd-host');
40 commonHostGcd = mockGcdApi.addMockHost('common-host');
41 commonHostGcd.hostName = 'common-host-gcd';
42 mockLegacyApi = new remoting.MockHostListApi();
43 mockLegacyApi.addMockHost('legacy-host');
44 commonHostLegacy = mockLegacyApi.addMockHost('common-host');
45 commonHostLegacy.hostName = 'common-host-legacy';
46 combinedApi = new remoting.CombinedHostListApi(mockLegacyApi, mockGcdApi);
47 registerWithHostIdStub =
48 sinon.stub(remoting.LegacyHostListApi, 'registerWithHostId');
49 },
50 afterEach: function(/** QUnit.Assert */ assert) {
51 remoting.settings = null;
52 registerWithHostIdStub.restore();
53 }
54 });
55
56 QUnit.test('register', function(/** QUnit.Assert */ assert) {
57 registerWithHostIdStub.returns(Promise.resolve());
58
59 mockGcdApi.authCodeFromRegister = '<fake_auth_code>';
60 mockGcdApi.emailFromRegister = '<fake_email>';
61 mockGcdApi.hostIdFromRegister = '<fake_host_id>';
62 mockLegacyApi.authCodeFromRegister = '<wrong_fake_auth_code>';
63 mockLegacyApi.emailFromRegister = '<wrong_fake_email>';
64 mockLegacyApi.hostIdFromRegister = '<wrong_fake_host_id>';
65 return combinedApi.register('', '', '').then(function(regResult) {
66 assert.equal(regResult.authCode, '<fake_auth_code>');
67 assert.equal(regResult.email, '<fake_email>');
68 assert.equal(regResult.hostId, '<fake_host_id>');
69 });
70 });
71
72 QUnit.test('get', function(/** QUnit.Assert */ assert) {
73 return combinedApi.get().then(function(hosts) {
74 assert.equal(hosts.length, 3);
75 var hostIds = new Set();
76 hosts.forEach(function(host) {
77 hostIds.add(host.hostId);
78 if (host.hostId == 'common-host') {
79 assert.equal(host.hostName, 'common-host-gcd');
80 };
81 });
82 assert.ok(hostIds.has('gcd-host'));
83 assert.ok(hostIds.has('legacy-host'));
84 assert.ok(hostIds.has('common-host'));
85 });
86 });
87
88 QUnit.test('get w/ GCD newer', function(/** QUnit.Assert */ assert) {
89 commonHostGcd.updatedTime = '1970-01-02';
90 commonHostLegacy.updatedTime = '1970-01-01';
91 return combinedApi.get().then(function(hosts) {
92 hosts.forEach(function(host) {
93 if (host.hostId == 'common-host') {
94 assert.equal(host.hostName, 'common-host-gcd');
95 };
96 });
97 });
98 });
99
100 QUnit.test('get w/ legacy newer', function(/** QUnit.Assert */ assert) {
101 commonHostGcd.updatedTime = '1970-01-01';
102 commonHostLegacy.updatedTime = '1970-01-02';
103 return combinedApi.get().then(function(hosts) {
104 hosts.forEach(function(host) {
105 if (host.hostId == 'common-host') {
106 assert.equal(host.hostName, 'common-host-legacy');
107 };
108 });
109 });
110 });
111
112 QUnit.test('put to legacy', function(/** QUnit.Assert */ assert) {
113 return combinedApi.get().then(function() {
114 return combinedApi.put('legacy-host', 'new host name', '').then(
115 function() {
116 assert.equal(mockLegacyApi.hosts[0].hostName,
117 'new host name');
118 });
119 });
120 });
121
122 QUnit.test('put to GCD', function(/** QUnit.Assert */ assert) {
123 return combinedApi.get().then(function() {
124 return combinedApi.put('gcd-host', 'new host name', '').then(
125 function() {
126 assert.equal(mockGcdApi.hosts[0].hostName,
127 'new host name');
128 });
129 });
130 });
131
132
133 QUnit.test('put to both', function(/** QUnit.Assert */ assert) {
134 return combinedApi.get().then(function() {
135 return combinedApi.put('common-host', 'new host name', '').then(
136 function() {
137 assert.equal(mockGcdApi.hosts[1].hostName,
138 'new host name');
139 assert.equal(mockLegacyApi.hosts[1].hostName,
140 'new host name');
141 });
142 });
143 });
144
145 QUnit.test('remove from legacy', function(/** QUnit.Assert */ assert) {
146 return combinedApi.get().then(function() {
147 return combinedApi.remove('legacy-host').then(function() {
148 assert.equal(mockGcdApi.hosts.length, 2);
149 assert.equal(mockLegacyApi.hosts.length, 1);
150 assert.notEqual(mockLegacyApi.hosts[0].hostId, 'legacy-host');
151 });
152 });
153 });
154
155 QUnit.test('remove from gcd', function(/** QUnit.Assert */ assert) {
156 return combinedApi.get().then(function() {
157 return combinedApi.remove('gcd-host').then(function() {
158 assert.equal(mockLegacyApi.hosts.length, 2);
159 assert.equal(mockGcdApi.hosts.length, 1);
160 assert.notEqual(mockGcdApi.hosts[0].hostId, 'gcd-host');
161 });
162 });
163 });
164
165 QUnit.test('remove from both', function(/** QUnit.Assert */ assert) {
166 return combinedApi.get().then(function() {
167 return combinedApi.remove('common-host').then(function() {
168 assert.equal(mockGcdApi.hosts.length, 1);
169 assert.equal(mockLegacyApi.hosts.length, 1);
170 assert.notEqual(mockGcdApi.hosts[0].hostId, 'common-host');
171 assert.notEqual(mockLegacyApi.hosts[0].hostId, 'common-host');
172 });
173 });
174 });
175
176 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698