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