OLD | NEW |
---|---|
(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 QUnit.module('combined_host_list_api', { | |
kelvinp
2015/06/29 23:53:45
Nit: s/combined_host_list_api/CombinedHostListAPI
John Williams
2015/07/17 23:29:33
Done.
| |
27 beforeEach: function(/** QUnit.Assert */ assert) { | |
28 remoting.settings = new remoting.Settings(); | |
29 remoting.settings['USE_GCD'] = true; | |
30 remoting.mockIdentity.setAccessToken( | |
31 remoting.MockIdentity.AccessToken.VALID); | |
32 mockGcdApi = new remoting.MockHostListApi(); | |
33 mockGcdApi.addMockHost('gcd-host'); | |
34 var commonHostGcd = mockGcdApi.addMockHost('common-host'); | |
35 commonHostGcd.hostName = 'common-host-gcd'; | |
36 mockLegacyApi = new remoting.MockHostListApi(); | |
37 mockLegacyApi.addMockHost('legacy-host'); | |
38 var commonHostLegacy = mockLegacyApi.addMockHost('common-host'); | |
39 commonHostLegacy.hostName = 'common-host-legacy'; | |
40 combinedApi = new remoting.CombinedHostListApi(mockLegacyApi, mockGcdApi); | |
41 registerWithHostIdStub = | |
42 sinon.stub(remoting.LegacyHostListApi, 'registerWithHostId'); | |
43 }, | |
44 afterEach: function(/** QUnit.Assert */ assert) { | |
45 remoting.settings = null; | |
46 registerWithHostIdStub.restore(); | |
47 } | |
48 }); | |
49 | |
50 QUnit.test('register (GCD)', function(/** QUnit.Assert */ assert) { | |
51 registerWithHostIdStub.returns(Promise.resolve()); | |
52 | |
53 remoting.settings['PREFER_GCD'] = true; | |
54 mockGcdApi.authCodeFromRegister = '<fake_auth_code>'; | |
55 mockGcdApi.emailFromRegister = '<fake_email>'; | |
56 mockGcdApi.hostIdFromRegister = '<fake_host_id>'; | |
57 mockLegacyApi.authCodeFromRegister = '<wrong_fake_auth_code>'; | |
58 mockLegacyApi.emailFromRegister = '<wrong_fake_email>'; | |
59 mockLegacyApi.hostIdFromRegister = '<wrong_fake_host_id>'; | |
60 return combinedApi.register('', '', '').then(function(regResult) { | |
61 assert.equal(regResult.authCode, '<fake_auth_code>'); | |
62 assert.equal(regResult.email, '<fake_email>'); | |
63 assert.equal(regResult.hostId, '<fake_host_id>'); | |
64 }); | |
65 }); | |
66 | |
67 QUnit.test('register (legacy)', function(/** QUnit.Assert */ assert) { | |
68 remoting.settings['PREFER_GCD'] = false; | |
69 mockLegacyApi.authCodeFromRegister = '<fake_auth_code>'; | |
70 mockLegacyApi.emailFromRegister = '<fake_email>'; | |
71 mockLegacyApi.hostIdFromRegister = '<fake_host_id>'; | |
72 return combinedApi.register('', '', '').then(function(regResult) { | |
73 assert.equal(regResult.authCode, '<fake_auth_code>'); | |
74 assert.equal(regResult.email, '<fake_email>'); | |
75 assert.equal(regResult.hostId, '<fake_host_id>'); | |
76 }); | |
77 }); | |
78 | |
79 QUnit.test('get (GCD)', function(/** QUnit.Assert */ assert) { | |
80 remoting.settings['PREFER_GCD'] = true; | |
81 return combinedApi.get().then(function(hosts) { | |
82 assert.equal(hosts.length, 3); | |
83 var hostIds = new Set(); | |
84 hosts.forEach(function(host) { | |
85 hostIds.add(host.hostId); | |
86 if (host.hostId == 'common-host') { | |
87 assert.equal(host.hostName, 'common-host-gcd'); | |
88 }; | |
89 }); | |
90 assert.ok(hostIds.has('gcd-host')); | |
91 assert.ok(hostIds.has('legacy-host')); | |
92 assert.ok(hostIds.has('common-host')); | |
93 }); | |
94 }); | |
95 | |
96 QUnit.test('get (legacy)', function(/** QUnit.Assert */ assert) { | |
97 remoting.settings['PREFER_GCD'] = false; | |
98 return combinedApi.get().then(function(hosts) { | |
99 assert.equal(hosts.length, 3); | |
100 var hostIds = new Set(); | |
101 hosts.forEach(function(host) { | |
102 hostIds.add(host.hostId); | |
103 if (host.hostId == 'common-host') { | |
104 assert.equal(host.hostName, 'common-host-legacy'); | |
105 }; | |
106 }); | |
107 assert.ok(hostIds.has('gcd-host')); | |
108 assert.ok(hostIds.has('legacy-host')); | |
109 assert.ok(hostIds.has('common-host')); | |
110 }); | |
111 }); | |
112 | |
113 QUnit.test('put to legacy', function(/** QUnit.Assert */ assert) { | |
114 return combinedApi.get().then(function() { | |
115 return combinedApi.put('legacy-host', 'new host name', '').then( | |
116 function() { | |
117 assert.equal(mockLegacyApi.hosts[0].hostName, | |
118 'new host name'); | |
119 }); | |
120 }); | |
121 }); | |
122 | |
123 QUnit.test('put to GCD', function(/** QUnit.Assert */ assert) { | |
124 return combinedApi.get().then(function() { | |
125 return combinedApi.put('gcd-host', 'new host name', '').then( | |
126 function() { | |
127 assert.equal(mockGcdApi.hosts[0].hostName, | |
128 'new host name'); | |
129 }); | |
130 }); | |
131 }); | |
132 | |
133 | |
134 QUnit.test('put to both', function(/** QUnit.Assert */ assert) { | |
135 return combinedApi.get().then(function() { | |
136 return combinedApi.put('common-host', 'new host name', '').then( | |
137 function() { | |
138 assert.equal(mockGcdApi.hosts[1].hostName, | |
139 'new host name'); | |
140 assert.equal(mockLegacyApi.hosts[1].hostName, | |
141 'new host name'); | |
142 }); | |
143 }); | |
144 }); | |
145 | |
146 QUnit.test('remove from legacy', function(/** QUnit.Assert */ assert) { | |
147 return combinedApi.get().then(function() { | |
148 return combinedApi.remove('legacy-host').then(function() { | |
149 assert.equal(mockGcdApi.hosts.length, 2); | |
150 assert.equal(mockLegacyApi.hosts.length, 1); | |
151 assert.notEqual(mockLegacyApi.hosts[0].hostId, 'legacy-host'); | |
152 }); | |
153 }); | |
154 }); | |
155 | |
156 QUnit.test('remove from gcd', function(/** QUnit.Assert */ assert) { | |
157 return combinedApi.get().then(function() { | |
158 return combinedApi.remove('gcd-host').then(function() { | |
159 assert.equal(mockLegacyApi.hosts.length, 2); | |
160 assert.equal(mockGcdApi.hosts.length, 1); | |
161 assert.notEqual(mockGcdApi.hosts[0].hostId, 'gcd-host'); | |
162 }); | |
163 }); | |
164 }); | |
165 | |
166 QUnit.test('remove from both', function(/** QUnit.Assert */ assert) { | |
167 return combinedApi.get().then(function() { | |
168 return combinedApi.remove('common-host').then(function() { | |
169 assert.equal(mockGcdApi.hosts.length, 1); | |
170 assert.equal(mockLegacyApi.hosts.length, 1); | |
171 assert.notEqual(mockGcdApi.hosts[0].hostId, 'common-host'); | |
172 assert.notEqual(mockLegacyApi.hosts[0].hostId, 'common-host'); | |
173 }); | |
174 }); | |
175 }); | |
176 | |
177 })(); | |
OLD | NEW |