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

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

Issue 1065733004: Added partial unit tests for host_controller.js. More to come. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hdf-unittest
Patch Set: added licenses to satisfy presubmit 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/crd/js/host_controller_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 /**
6 * @fileoverview A mock version of HostDaemonFacade. Internally all
7 * delays are implemented with promises, so SpyPromise can be used to
8 * wait out delays.
9 *
10 * By default, every method fails. Methods can be individually set to
11 * pass specific values to their onDone arguments by setting member
12 * variables of the mock object.
13 *
14 * When methods fail, they set the detail field of the remoting.Error
15 * object to the name of the method that failed.
16 */
17
18 /** @suppress {duplicate} */
19 var remoting = remoting || {};
20
21 (function() {
22
23 'use strict';
24
25 /**
26 * By default, all methods fail.
27 * @constructor
28 */
29 remoting.MockHostDaemonFacade = function() {
30 /** @type {Array<remoting.HostController.Feature>} */
31 this.features = [];
32
33 /** @type {?string} */
34 this.hostName = null;
35
36 /** @type {?string} */
37 this.pinHash = null;
38
39 /** @type {?string} */
40 this.privateKey = null;
41
42 /** @type {?string} */
43 this.publicKey = null;
44
45 /** @type {Object} */
46 this.daemonConfig = null;
47
48 /** @type {?string} */
49 this.daemonVersion = null;
50
51 /** @type {?boolean} */
52 this.consentSupported = null;
53
54 /** @type {?boolean} */
55 this.consentAllowed = null;
56
57 /** @type {?boolean} */
58 this.consentSetByPolicy = null;
59
60 /** @type {?remoting.HostController.AsyncResult} */
61 this.startDaemonResult = null;
62
63 /** @type {?remoting.HostController.AsyncResult} */
64 this.stopDaemonResult = null;
65
66 /** @type {?remoting.HostController.State} */
67 this.daemonState = null;
68
69 /** @type {Array<remoting.PairedClient>} */
70 this.pairedClients = null;
71
72 /** @type {?string} */
73 this.hostClientId = null;
74
75 /** @type {?string} */
76 this.userEmail = null;
77
78 /** @type {?string} */
79 this.refreshToken = null;
80 };
81
82 /**
83 * @param {remoting.HostController.Feature} feature
84 * @param {function(boolean):void} onDone
85 * @return {boolean}
86 */
87 remoting.MockHostDaemonFacade.prototype.hasFeature = function(feature, onDone) {
88 var that = this;
89 Promise.resolve().then(function() {
90 onDone(that.features.indexOf(feature) >= 0);
91 });
92 };
93
94 /**
95 * @param {function(string):void} onDone
96 * @param {function(!remoting.Error):void} onError
97 * @return {void}
98 */
99 remoting.MockHostDaemonFacade.prototype.getHostName =
100 function(onDone, onError) {
101 var that = this;
102 Promise.resolve().then(function() {
103 if (that.hostName === null) {
104 onError(remoting.Error.unexpected('getHostName'));
105 } else {
106 onDone(that.hostName);
107 }
108 });
109 };
110
111 /**
112 * @param {string} hostId
113 * @param {string} pin
114 * @param {function(string):void} onDone
115 * @param {function(!remoting.Error):void} onError
116 * @return {void}
117 */
118 remoting.MockHostDaemonFacade.prototype.getPinHash =
119 function(hostId, pin, onDone, onError) {
120 var that = this;
121 Promise.resolve().then(function() {
122 if (that.pinHash === null) {
123 onError(remoting.Error.unexpected('getPinHash'));
124 } else {
125 onDone(that.pinHash);
126 }
127 });
128 };
129
130 /**
131 * @param {function(string, string):void} onDone
132 * @param {function(!remoting.Error):void} onError
133 * @return {void}
134 */
135 remoting.MockHostDaemonFacade.prototype.generateKeyPair =
136 function(onDone, onError) {
137 var that = this;
138 Promise.resolve().then(function() {
139 if (that.privateKey === null || that.publicKey === null) {
140 onError(remoting.Error.unexpected('generateKeyPair'));
141 } else {
142 onDone(that.privateKey, that.publicKey);
143 }
144 });
145 };
146
147 /**
148 * @param {Object} config
149 * @param {function(remoting.HostController.AsyncResult):void} onDone
150 * @param {function(!remoting.Error):void} onError
151 * @return {void}
152 */
153 remoting.MockHostDaemonFacade.prototype.updateDaemonConfig =
154 function(config, onDone, onError) {
155 var that = this;
156 Promise.resolve().then(function() {
157 if (that.daemonConfig === null ||
158 'host_id' in config ||
159 'xmpp_login' in config) {
160 onError(remoting.Error.unexpected('updateDaemonConfig'));
161 } else {
162 base.mix(that.daemonConfig, config);
163 onDone(remoting.HostController.AsyncResult.OK);
164 }
165 });
166 };
167
168 /**
169 * @param {function(Object):void} onDone
170 * @param {function(!remoting.Error):void} onError
171 * @return {void}
172 */
173 remoting.MockHostDaemonFacade.prototype.getDaemonConfig =
174 function(onDone, onError) {
175 var that = this;
176 Promise.resolve().then(function() {
177 if (that.daemonConfig === null) {
178 onError(remoting.Error.unexpected('getDaemonConfig'));
179 } else {
180 onDone(that.daemonConfig);
181 }
182 });
183 };
184
185 /**
186 * @param {function(string):void} onDone
187 * @param {function(!remoting.Error):void} onError
188 * @return {void}
189 */
190 remoting.MockHostDaemonFacade.prototype.getDaemonVersion =
191 function(onDone, onError) {
192 var that = this;
193 Promise.resolve().then(function() {
194 if (that.daemonVersion === null) {
195 onError(remoting.Error.unexpected('getDaemonVersion'));
196 } else {
197 onDone(that.daemonVersion);
198 }
199 });
200 };
201
202 /**
203 * @param {function(boolean, boolean, boolean):void} onDone
204 * @param {function(!remoting.Error):void} onError
205 * @return {void}
206 */
207 remoting.MockHostDaemonFacade.prototype.getUsageStatsConsent =
208 function(onDone, onError) {
209 var that = this;
210 Promise.resolve().then(function() {
211 if (that.consentSupported === null ||
212 that.consentAllowed === null ||
213 that.consentSetByPolicy === null) {
214 onError(remoting.Error.unexpected('getUsageStatsConsent'));
215 } else {
216 onDone(
217 that.consentSupported,
218 that.consentAllowed,
219 that.consentSetByPolicy);
220 }
221 });
222 };
223
224 /**
225 * @param {Object} config
226 * @param {boolean} consent Consent to report crash dumps.
227 * @param {function(remoting.HostController.AsyncResult):void} onDone
228 * @param {function(!remoting.Error):void} onError
229 * @return {void}
230 */
231 remoting.MockHostDaemonFacade.prototype.startDaemon =
232 function(config, consent, onDone, onError) {
233 var that = this;
234 Promise.resolve().then(function() {
235 if (that.startDaemonResult === null) {
236 onError(remoting.Error.unexpected('startDaemon'));
237 } else {
238 onDone(that.startDaemonResult);
239 }
240 });
241 };
242
243 /**
244 * @param {function(remoting.HostController.AsyncResult):void} onDone
245 * @param {function(!remoting.Error):void} onError
246 * @return {void}
247 */
248 remoting.MockHostDaemonFacade.prototype.stopDaemon =
249 function(onDone, onError) {
250 var that = this;
251 Promise.resolve().then(function() {
252 if (that.stopDaemonResult === null) {
253 onError(remoting.Error.unexpected('stopDaemon'));
254 } else {
255 onDone(that.stopDaemonResult);
256 }
257 });
258 };
259
260 /**
261 * @param {function(remoting.HostController.State):void} onDone
262 * @param {function(!remoting.Error):void} onError
263 * @return {void}
264 */
265 remoting.MockHostDaemonFacade.prototype.getDaemonState =
266 function(onDone, onError) {
267 var that = this;
268 Promise.resolve().then(function() {
269 if (that.daemonState === null) {
270 onError(remoting.Error.unexpected('getDaemonState'));
271 } else {
272 onDone(that.daemonState);
273 }
274 });
275 };
276
277 /**
278 * @param {function(Array<remoting.PairedClient>):void} onDone
279 * @param {function(!remoting.Error):void} onError
280 */
281 remoting.MockHostDaemonFacade.prototype.getPairedClients =
282 function(onDone, onError) {
283 var that = this;
284 Promise.resolve().then(function() {
285 if (that.pairedClients === null) {
286 onError(remoting.Error.unexpected('getPairedClients'));
287 } else {
288 onDone(that.pairedClients);
289 }
290 });
291 };
292
293 /**
294 * @param {function(boolean):void} onDone
295 * @param {function(!remoting.Error):void} onError
296 */
297 remoting.MockHostDaemonFacade.prototype.clearPairedClients =
298 function(onDone, onError) {
299 var that = this;
300 Promise.resolve().then(function() {
301 if (that.pairedClients === null) {
302 onError(remoting.Error.unexpected('clearPairedClients'));
303 } else {
304 that.pairedClients = [];
305 onDone(true);
306 }
307 });
308 };
309
310 /**
311 * @param {string} client
312 * @param {function(boolean):void} onDone
313 * @param {function(!remoting.Error):void} onError
314 */
315 remoting.MockHostDaemonFacade.prototype.deletePairedClient =
316 function(client, onDone, onError) {
317 var that = this;
318 Promise.resolve().then(function() {
319 if (that.pairedClients === null) {
320 onError(remoting.Error.unexpected('deletePairedClient'));
321 } else {
322 that.pairedClients = that.pairedClients.filter(function(/** Object */ c) {
323 return c['clientId'] != client;
324 });
325 onDone(true);
326 }
327 });
328 };
329
330 /**
331 * @param {function(string):void} onDone
332 * @param {function(!remoting.Error):void} onError
333 * @return {void}
334 */
335 remoting.MockHostDaemonFacade.prototype.getHostClientId =
336 function(onDone, onError) {
337 var that = this;
338 Promise.resolve().then(function() {
339 if (that.hostClientId === null) {
340 onError(remoting.Error.unexpected('getHostClientId'));
341 } else {
342 onDone(that.hostClientId);
343 }
344 });
345 };
346
347 /**
348 * @param {string} authorizationCode
349 * @param {function(string, string):void} onDone
350 * @param {function(!remoting.Error):void} onError
351 * @return {void}
352 */
353 remoting.MockHostDaemonFacade.prototype.getCredentialsFromAuthCode =
354 function(authorizationCode, onDone, onError) {
355 var that = this;
356 Promise.resolve().then(function() {
357 if (that.userEmail === null || that.refreshToken === null) {
358 onError(remoting.Error.unexpected('getCredentialsFromAuthCode'));
359 } else {
360 onDone(that.userEmail, that.refreshToken);
361 }
362 });
363 };
364
365 })();
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/host_controller_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