1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
* Unit tests for host_controller.js.
*/
(function() {
'use strict';
/** @type {remoting.HostController} */
var controller;
/** @type {sinon.Mock} */
var hostListMock = null;
/** @type {sinon.TestStub} */
var generateUuidStub;
/** @type {remoting.MockHostDaemonFacade} */
var mockHostDaemonFacade;
/** @type {sinon.TestStub} */
var hostDaemonFacadeCtorStub;
/** @type {remoting.MockSignalStrategy} */
var mockSignalStrategy;
/** @type {sinon.TestStub} */
var signalStrategyCreateStub;
/** @type {sinon.TestStub|Function} */
var signalStrategyConnectStub;
var FAKE_HOST_PIN = '<FAKE_HOST_PIN>';
var FAKE_PIN_HASH = '<FAKE_PIN_HASH>';
var FAKE_NEW_HOST_PIN = '<FAKE_NEW_HOST_PIN>';
var FAKE_USER_EMAIL = '<FAKE_USER_EMAIL>';
var FAKE_XMPP_LOGIN = '<FAKE_XMPP_LOGIN>';
var FAKE_USER_NAME = '<FAKE_USER_NAME>';
var FAKE_HOST_ID = '0bad0bad-0bad-0bad-0bad-0bad0bad0bad';
var FAKE_DAEMON_VERSION = '1.2.3.4';
var FAKE_HOST_NAME = '<FAKE_HOST_NAME>';
var FAKE_PUBLIC_KEY = '<FAKE_PUBLIC_KEY>';
var FAKE_PRIVATE_KEY = '<FAKE_PRIVATE_KEY>';
var FAKE_AUTH_CODE = '<FAKE_AUTH_CODE>';
var FAKE_REFRESH_TOKEN = '<FAKE_REFRESH_TOKEN>';
var FAKE_HOST_CLIENT_ID = '<FAKE_HOST_CLIENT_ID>';
var FAKE_CLIENT_JID = '<FAKE_CLIENT_JID>';
var FAKE_CLIENT_BASE_JID = '<FAKE_CLIENT_BASE_JID>';
var FAKE_IDENTITY_TOKEN = '<FAKE_IDENTITY_TOKEN>';
/** @type {sinon.Spy|Function} */
var getCredentialsFromAuthCodeSpy;
/** @type {sinon.Spy|Function} */
var getPinHashSpy;
/** @type {sinon.Spy|Function} */
var startDaemonSpy;
/** @type {sinon.Spy|Function} */
var updateDaemonConfigSpy;
/** @type {sinon.Spy} */
var unregisterHostByIdSpy;
/** @type {sinon.Spy} */
var onLocalHostStartedSpy;
/** @type {remoting.MockHostListApi} */
var mockHostListApi;
QUnit.module('host_controller', {
beforeEach: function(/** QUnit.Assert */ assert) {
chromeMocks.activate(['identity', 'runtime']);
chromeMocks.identity.mock$setToken(FAKE_IDENTITY_TOKEN);
remoting.settings = new remoting.Settings();
remoting.identity = new remoting.Identity();
mockHostListApi = new remoting.MockHostListApi;
mockHostListApi.authCodeFromRegister = FAKE_AUTH_CODE;
mockHostListApi.emailFromRegister = '';
remoting.HostListApi.setInstance(mockHostListApi);
base.debug.assert(remoting.oauth2 === null);
remoting.oauth2 = new remoting.OAuth2();
base.debug.assert(remoting.hostList === null);
remoting.hostList = /** @type {remoting.HostList} */
(Object.create(remoting.HostList.prototype));
// When the HostList's unregisterHostById method is called, make
// sure the argument is correct.
unregisterHostByIdSpy =
sinon.stub(remoting.hostList, 'unregisterHostById', function(
/** string */ hostId, /** Function */ onDone) {
assert.equal(hostId, FAKE_HOST_ID);
if (onDone) {
onDone();
}
});
// When the HostList's onLocalHostStarted method is called, make
// sure the arguments are correct.
onLocalHostStartedSpy =
sinon.stub(
remoting.hostList, 'onLocalHostStarted', function(
/** string */ hostName,
/** string */ newHostId,
/** string */ publicKey) {
assert.equal(hostName, FAKE_HOST_NAME);
assert.equal(newHostId, FAKE_HOST_ID);
assert.equal(publicKey, FAKE_PUBLIC_KEY);
});
mockSignalStrategy = new remoting.MockSignalStrategy(
FAKE_CLIENT_JID + '/extra_junk',
remoting.SignalStrategy.Type.XMPP);
signalStrategyCreateStub = sinon.stub(remoting.SignalStrategy, 'create');
signalStrategyCreateStub.returns(mockSignalStrategy);
hostDaemonFacadeCtorStub = sinon.stub(remoting, 'HostDaemonFacade');
mockHostDaemonFacade = new remoting.MockHostDaemonFacade();
hostDaemonFacadeCtorStub.returns(mockHostDaemonFacade);
generateUuidStub = sinon.stub(base, 'generateUuid');
generateUuidStub.returns(FAKE_HOST_ID);
getCredentialsFromAuthCodeSpy = sinon.spy(
mockHostDaemonFacade, 'getCredentialsFromAuthCode');
getPinHashSpy = sinon.spy(mockHostDaemonFacade, 'getPinHash');
startDaemonSpy = sinon.spy(mockHostDaemonFacade, 'startDaemon');
updateDaemonConfigSpy =
sinon.spy(mockHostDaemonFacade, 'updateDaemonConfig');
// Set up successful responses from mockHostDaemonFacade.
// Individual tests override these values to create errors.
mockHostDaemonFacade.features =
[remoting.HostController.Feature.OAUTH_CLIENT];
mockHostDaemonFacade.daemonVersion = FAKE_DAEMON_VERSION;
mockHostDaemonFacade.hostName = FAKE_HOST_NAME;
mockHostDaemonFacade.privateKey = FAKE_PRIVATE_KEY;
mockHostDaemonFacade.publicKey = FAKE_PUBLIC_KEY;
mockHostDaemonFacade.hostClientId = FAKE_HOST_CLIENT_ID;
mockHostDaemonFacade.userEmail = FAKE_XMPP_LOGIN;
mockHostDaemonFacade.refreshToken = FAKE_REFRESH_TOKEN;
mockHostDaemonFacade.pinHashFunc = fakePinHashFunc;
mockHostDaemonFacade.startDaemonResult =
remoting.HostController.AsyncResult.OK;
mockHostDaemonFacade.stopDaemonResult =
remoting.HostController.AsyncResult.OK;
mockHostDaemonFacade.daemonConfig = {
host_id: FAKE_HOST_ID,
xmpp_login: FAKE_XMPP_LOGIN
};
mockHostDaemonFacade.updateDaemonConfigResult =
remoting.HostController.AsyncResult.OK;
mockHostDaemonFacade.daemonState =
remoting.HostController.State.STARTED;
sinon.stub(remoting.identity, 'getEmail').returns(
Promise.resolve(FAKE_USER_EMAIL));
sinon.stub(remoting.oauth2, 'getRefreshToken').returns(
FAKE_REFRESH_TOKEN);
controller = new remoting.HostController();
},
afterEach: function() {
controller = null;
getCredentialsFromAuthCodeSpy.restore();
generateUuidStub.restore();
hostDaemonFacadeCtorStub.restore();
signalStrategyCreateStub.restore();
remoting.hostList = null;
remoting.oauth2 = null;
chromeMocks.restore();
remoting.HostListApi.setInstance(null);
remoting.identity = null;
}
});
/**
* @param {string} hostId
* @param {string} pin
* @return {string}
*/
function fakePinHashFunc(hostId, pin) {
return '<FAKE_PIN:' + hostId + ':' + pin + '>';
}
/**
* @param {boolean} successful
*/
function stubSignalStrategyConnect(successful) {
sinon.stub(mockSignalStrategy, 'connect', function() {
Promise.resolve().then(function() {
mockSignalStrategy.setStateForTesting(
successful ?
remoting.SignalStrategy.State.CONNECTED :
remoting.SignalStrategy.State.FAILED);
});
});
}
// Check what happens when the HostDaemonFacade's getHostName method
// fails.
QUnit.test('start with getHostName failure', function(assert) {
mockHostDaemonFacade.hostName = null;
return controller.start(FAKE_HOST_PIN, true).then(function() {
throw 'test failed';
}, function(/** remoting.Error */ e) {
assert.equal(e.getDetail(), 'getHostName');
assert.equal(e.getTag(), remoting.Error.Tag.UNEXPECTED);
assert.equal(unregisterHostByIdSpy.callCount, 0);
assert.equal(onLocalHostStartedSpy.callCount, 0);
assert.equal(startDaemonSpy.callCount, 0);
});
});
// Check what happens when the HostDaemonFacade's generateKeyPair
// method fails.
QUnit.test('start with generateKeyPair failure', function(assert) {
mockHostDaemonFacade.publicKey = null;
mockHostDaemonFacade.privateKey = null;
return controller.start(FAKE_HOST_PIN, true).then(function() {
throw 'test failed';
}, function(/** remoting.Error */ e) {
assert.equal(e.getDetail(), 'generateKeyPair');
assert.equal(e.getTag(), remoting.Error.Tag.UNEXPECTED);
assert.equal(unregisterHostByIdSpy.callCount, 0);
assert.equal(onLocalHostStartedSpy.callCount, 0);
assert.equal(startDaemonSpy.callCount, 0);
});
});
// Check what happens when the HostDaemonFacade's getHostClientId
// method fails.
QUnit.test('start with getHostClientId failure', function(assert) {
mockHostDaemonFacade.hostClientId = null;
return controller.start(FAKE_HOST_PIN, true).then(function() {
throw 'test failed';
}, function(/** remoting.Error */ e) {
assert.equal(e.getDetail(), 'getHostClientId');
assert.equal(e.getTag(), remoting.Error.Tag.UNEXPECTED);
assert.equal(unregisterHostByIdSpy.callCount, 0);
assert.equal(onLocalHostStartedSpy.callCount, 0);
assert.equal(startDaemonSpy.callCount, 0);
});
});
// Check what happens when the registry returns an HTTP when we try to
// register a host.
QUnit.test('start with host registration failure', function(assert) {
mockHostListApi.authCodeFromRegister = null;
return controller.start(FAKE_HOST_PIN, true).then(function() {
throw 'test failed';
}, function(/** remoting.Error */ e) {
assert.equal(e.getTag(), remoting.Error.Tag.REGISTRATION_FAILED);
assert.equal(unregisterHostByIdSpy.callCount, 0);
assert.equal(onLocalHostStartedSpy.callCount, 0);
assert.equal(startDaemonSpy.callCount, 0);
});
});
// Check what happens when the HostDaemonFacade's
// getCredentialsFromAuthCode method fails.
QUnit.test('start with getCredentialsFromAuthCode failure', function(assert) {
mockHostDaemonFacade.useEmail = null;
mockHostDaemonFacade.refreshToken = null;
return controller.start(FAKE_HOST_PIN, true).then(function() {
throw 'test failed';
}, function(/** remoting.Error */ e) {
assert.equal(e.getDetail(), 'getCredentialsFromAuthCode');
assert.equal(e.getTag(), remoting.Error.Tag.UNEXPECTED);
assert.equal(getCredentialsFromAuthCodeSpy.callCount, 1);
assert.equal(onLocalHostStartedSpy.callCount, 0);
assert.equal(startDaemonSpy.callCount, 0);
});
});
// Check what happens when the SignalStrategy fails to connect.
QUnit.test('start with signalStrategy failure', function(assert) {
stubSignalStrategyConnect(false);
return controller.start(FAKE_HOST_PIN, true).then(function() {
throw 'test failed';
}, function(/** remoting.Error */ e) {
assert.equal(e.getDetail(), 'setStateForTesting');
assert.equal(e.getTag(), remoting.Error.Tag.UNEXPECTED);
assert.equal(unregisterHostByIdSpy.callCount, 1);
});
});
// Check what happens when the HostDaemonFacade's startDaemon method
// fails and calls its onError argument.
// TODO(jrw): Should startDaemon even have an onError callback?
QUnit.test('start with startDaemon failure', function(assert) {
stubSignalStrategyConnect(true);
mockHostDaemonFacade.startDaemonResult = null;
return controller.start(FAKE_HOST_PIN, true).then(function() {
throw 'test failed';
}, function(/** remoting.Error */ e) {
assert.equal(e.getDetail(), 'startDaemon');
assert.equal(e.getTag(), remoting.Error.Tag.UNEXPECTED);
assert.equal(unregisterHostByIdSpy.callCount, 1);
assert.equal(unregisterHostByIdSpy.args[0][0], FAKE_HOST_ID);
assert.equal(onLocalHostStartedSpy.callCount, 0);
});
});
// Check what happens when the HostDaemonFacade's startDaemon method
// calls is onDone method with a CANCELLED error code.
QUnit.test('start with startDaemon cancelled', function(assert) {
stubSignalStrategyConnect(true);
mockHostDaemonFacade.startDaemonResult =
remoting.HostController.AsyncResult.CANCELLED;
return controller.start(FAKE_HOST_PIN, true).then(function() {
throw 'test failed';
}, function(/** remoting.Error */ e) {
assert.equal(e.getTag(), remoting.Error.Tag.CANCELLED);
assert.equal(unregisterHostByIdSpy.callCount, 1);
assert.equal(unregisterHostByIdSpy.args[0][0], FAKE_HOST_ID);
assert.equal(onLocalHostStartedSpy.callCount, 0);
});
});
// Check what happens when the HostDaemonFacade's startDaemon method
// calls is onDone method with an async error code.
QUnit.test('start with startDaemon returning failure code', function(assert) {
stubSignalStrategyConnect(true);
mockHostDaemonFacade.startDaemonResult =
remoting.HostController.AsyncResult.FAILED;
return controller.start(FAKE_HOST_PIN, true).then(function() {
throw 'test failed';
}, function(/** remoting.Error */ e) {
assert.equal(e.getTag(), remoting.Error.Tag.UNEXPECTED);
assert.equal(unregisterHostByIdSpy.callCount, 1);
assert.equal(onLocalHostStartedSpy.callCount, 0);
});
});
// Check what happens when the entire host registration process
// succeeds.
[false, true].forEach(function(/** boolean */ consent) {
QUnit.test('start with consent=' + consent, function(assert) {
/** @const */
var fakePinHash = fakePinHashFunc(FAKE_HOST_ID, FAKE_HOST_PIN);
stubSignalStrategyConnect(true);
return controller.start(FAKE_HOST_PIN, consent).then(function() {
assert.equal(getCredentialsFromAuthCodeSpy.callCount, 1);
assert.deepEqual(
getCredentialsFromAuthCodeSpy.args[0][0],
FAKE_AUTH_CODE);
assert.equal(getPinHashSpy.callCount, 1);
assert.deepEqual(
getPinHashSpy.args[0].slice(0, 2),
[FAKE_HOST_ID, FAKE_HOST_PIN]);
assert.equal(unregisterHostByIdSpy.callCount, 0);
assert.equal(onLocalHostStartedSpy.callCount, 1);
assert.equal(startDaemonSpy.callCount, 1);
assert.deepEqual(
startDaemonSpy.args[0].slice(0, 2),
[{
xmpp_login: FAKE_XMPP_LOGIN,
oauth_refresh_token: FAKE_REFRESH_TOKEN,
host_owner: FAKE_CLIENT_JID.toLowerCase(),
host_owner_email: FAKE_USER_EMAIL,
host_id: FAKE_HOST_ID,
host_name: FAKE_HOST_NAME,
host_secret_hash: fakePinHash,
private_key: FAKE_PRIVATE_KEY
}, consent]);
});
});
});
// Check what happens when stopDaemon calls onError.
// TODO(jrw): Should stopDaemon even have an onError callback?
QUnit.test('stop with stopDaemon failure', function(assert) {
mockHostDaemonFacade.stopDaemonResult = null;
return new Promise(function(resolve, reject) {
controller.stop(function() {
reject('test failed');
}, function(/** remoting.Error */ e) {
assert.equal(e.getDetail(), 'stopDaemon');
// TODO(jrw): Is it really desirable to leave the host registered?
assert.equal(unregisterHostByIdSpy.callCount, 0);
resolve(null);
});
});
});
// Check what happens when stopDaemon returns FAILED.
QUnit.test('stop with stopDaemon cancelled', function(assert) {
mockHostDaemonFacade.stopDaemonResult =
remoting.HostController.AsyncResult.FAILED;
return new Promise(function(resolve, reject) {
controller.stop(function() {
reject('test failed');
}, function(/** remoting.Error */ e) {
// TODO(jrw): Is it really desirable to leave the host registered?
assert.equal(e.getTag(), remoting.Error.Tag.UNEXPECTED);
assert.equal(unregisterHostByIdSpy.callCount, 0);
resolve(null);
});
});
});
// Check what happens when stopDaemon returns CANCELLED.
QUnit.test('stop with stopDaemon cancelled', function(assert) {
mockHostDaemonFacade.stopDaemonResult =
remoting.HostController.AsyncResult.CANCELLED;
return new Promise(function(resolve, reject) {
controller.stop(function() {
reject('test failed');
}, function(/** remoting.Error */ e) {
assert.equal(e.getTag(), remoting.Error.Tag.CANCELLED);
assert.equal(unregisterHostByIdSpy.callCount, 0);
resolve(null);
});
});
});
// Check what happens when stopDaemon succeeds.
QUnit.test('stop succeeds', function(assert) {
sinon.stub(controller, 'getLocalHostId').callsArgWith(0, FAKE_HOST_ID);
return new Promise(function(resolve, reject) {
controller.stop(function() {
assert.equal(unregisterHostByIdSpy.callCount, 1);
assert.equal(unregisterHostByIdSpy.args[0][0], FAKE_HOST_ID);
resolve(null);
}, reject);
});
});
// Check what happens when the host reports an invalid config.
QUnit.test('updatePin where config is invalid', function(assert) {
mockHostDaemonFacade.daemonConfig = {};
return new Promise(function(resolve, reject) {
controller.updatePin(FAKE_NEW_HOST_PIN, function() {
reject('test failed');
}, function(/** remoting.Error */ e) {
assert.equal(e.getTag(), remoting.Error.Tag.UNEXPECTED);
resolve(null);
});
});
});
// Check what happens when getDaemonConfig calls onError.
QUnit.test('updatePin where getDaemonConfig fails', function(assert) {
mockHostDaemonFacade.daemonConfig = null;
return new Promise(function(resolve, reject) {
controller.updatePin(FAKE_NEW_HOST_PIN, function() {
reject('test failed');
}, function(/** remoting.Error */ e) {
assert.equal(e.getDetail(), 'getDaemonConfig');
assert.equal(e.getTag(), remoting.Error.Tag.UNEXPECTED);
resolve(null);
});
});
});
// Check what happens when updateDaemonConfig calls onError.
// TODO(jrw): Should updateDaemonConfig even have an onError callback?
QUnit.test('updatePin where updateDaemonConfig calls onError', function(
assert) {
mockHostDaemonFacade.updateDaemonConfigResult = null;
return new Promise(function(resolve, reject) {
controller.updatePin(FAKE_NEW_HOST_PIN, function() {
reject('test failed');
}, function(/** remoting.Error */ e) {
assert.equal(e.getDetail(), 'updateDaemonConfig');
assert.equal(e.getTag(), remoting.Error.Tag.UNEXPECTED);
resolve(null);
});
});
});
// Check what happens when updateDaemonConfig returns CANCELLED.
QUnit.test('updatePin where updateDaemonConfig is cancelled', function(
assert) {
mockHostDaemonFacade.updateDaemonConfigResult =
remoting.HostController.AsyncResult.CANCELLED;
return new Promise(function(resolve, reject) {
controller.updatePin(FAKE_NEW_HOST_PIN, function() {
reject('test failed');
}, function(/** remoting.Error */ e) {
assert.equal(e.getTag(), remoting.Error.Tag.CANCELLED);
resolve(null);
});
});
});
// Check what happens when updateDaemonConfig returns FAILED.
QUnit.test('updatePin where updateDaemonConfig is returns failure', function(
assert) {
mockHostDaemonFacade.updateDaemonConfigResult =
remoting.HostController.AsyncResult.FAILED;
return new Promise(function(resolve, reject) {
controller.updatePin(FAKE_NEW_HOST_PIN, function() {
reject('test failed');
}, function(/** remoting.Error */ e) {
assert.equal(e.getTag(), remoting.Error.Tag.UNEXPECTED);
resolve(null);
});
});
});
// Check what happens when updatePin succeeds.
QUnit.test('updatePin succeeds', function(assert) {
/** @const */
var fakePinHash = fakePinHashFunc(FAKE_HOST_ID, FAKE_NEW_HOST_PIN);
return new Promise(function(resolve, reject) {
controller.updatePin(FAKE_NEW_HOST_PIN, function() {
assert.equal(getPinHashSpy.callCount, 1);
assert.equal(getPinHashSpy.args[0][0], FAKE_HOST_ID);
assert.equal(getPinHashSpy.args[0][1], FAKE_NEW_HOST_PIN);
assert.equal(updateDaemonConfigSpy.callCount, 1);
assert.deepEqual(
updateDaemonConfigSpy.args[0][0], {
host_secret_hash: fakePinHash
});
resolve(null);
}, reject);
});
});
// Check what happens when getLocalHostState fails.
QUnit.test('getLocalHostState with error', function(assert) {
mockHostDaemonFacade.daemonState = null;
return new Promise(function(resolve, reject) {
controller.getLocalHostState(function(
/** remoting.HostController.State */ state) {
assert.equal(state, remoting.HostController.State.UNKNOWN);
resolve(null);
});
});
});
// Check what happens when getLocalHostState reports no plugin.
QUnit.test('getLocalHostState with no plugin', function(assert) {
sinon.stub(mockHostDaemonFacade, 'getDaemonState').returns(
Promise.reject(new remoting.Error(remoting.Error.Tag.MISSING_PLUGIN)));
return new Promise(function(resolve, reject) {
controller.getLocalHostState(function(
/** remoting.HostController.State */ state) {
assert.equal(state, remoting.HostController.State.NOT_INSTALLED);
resolve(null);
});
});
});
// Check what happens when getLocalHostState succeeds.
QUnit.test('getLocalHostState succeeds', function(assert) {
return new Promise(function(resolve, reject) {
controller.getLocalHostState(function(
/** remoting.HostController.State */ state) {
assert.equal(state, remoting.HostController.State.STARTED);
resolve(null);
});
});
});
// Check what happens to getLocalHostId when getDaemonConfig
// returns an invalid config.
QUnit.test('getLocalHostId with invalid daemon config', function(assert) {
mockHostDaemonFacade.daemonConfig = {};
return new Promise(function(resolve, reject) {
controller.getLocalHostId(function(/** ?string */ id) {
assert.strictEqual(id, null);
resolve(null);
});
});
});
// Check what happens to getLocalHostId when getDaemonConfig fails.
QUnit.test('getLocalHostId with getDaemonConfig failure', function(assert) {
mockHostDaemonFacade.daemonConfig = null;
return new Promise(function(resolve, reject) {
controller.getLocalHostId(function(/** ?string */ id) {
assert.strictEqual(id, null);
resolve(null);
});
});
});
// Check what happens when getLocalHostId succeeds.
QUnit.test('getLocalHostId succeeds', function(assert) {
return new Promise(function(resolve, reject) {
controller.getLocalHostId(function(/** ?string */ id) {
assert.equal(id, FAKE_HOST_ID);
resolve(null);
});
});
});
// Tests omitted for hasFeature, getPairedClients, deletePairedClient,
// and clearPairedClients because they simply call through to
// HostDaemonFacade.
})();
|