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

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

Issue 1161813006: Updated handling of GCD devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for review; fixed broken host reg. algorithm Created 5 years, 6 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * Unit tests for host_controller.js. 7 * Unit tests for host_controller.js.
8 */ 8 */
9 9
10 (function() { 10 (function() {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 var mockHostListApi; 75 var mockHostListApi;
76 76
77 QUnit.module('host_controller', { 77 QUnit.module('host_controller', {
78 beforeEach: function(/** QUnit.Assert */ assert) { 78 beforeEach: function(/** QUnit.Assert */ assert) {
79 chromeMocks.identity.mock$setToken(FAKE_IDENTITY_TOKEN); 79 chromeMocks.identity.mock$setToken(FAKE_IDENTITY_TOKEN);
80 remoting.settings = new remoting.Settings(); 80 remoting.settings = new remoting.Settings();
81 remoting.identity = new remoting.Identity(); 81 remoting.identity = new remoting.Identity();
82 mockHostListApi = new remoting.MockHostListApi; 82 mockHostListApi = new remoting.MockHostListApi;
83 mockHostListApi.authCodeFromRegister = FAKE_AUTH_CODE; 83 mockHostListApi.authCodeFromRegister = FAKE_AUTH_CODE;
84 mockHostListApi.emailFromRegister = ''; 84 mockHostListApi.emailFromRegister = '';
85 mockHostListApi.hostIdFromRegister = FAKE_HOST_ID;
85 remoting.HostListApi.setInstance(mockHostListApi); 86 remoting.HostListApi.setInstance(mockHostListApi);
86 base.debug.assert(remoting.oauth2 === null); 87 base.debug.assert(remoting.oauth2 === null);
87 remoting.oauth2 = new remoting.OAuth2(); 88 remoting.oauth2 = new remoting.OAuth2();
88 base.debug.assert(remoting.hostList === null); 89 base.debug.assert(remoting.hostList === null);
89 remoting.hostList = /** @type {remoting.HostList} */ 90 remoting.hostList = /** @type {remoting.HostList} */
90 (Object.create(remoting.HostList.prototype)); 91 (Object.create(remoting.HostList.prototype));
91 92
92 // When the HostList's unregisterHostById method is called, make 93 // When the HostList's unregisterHostById method is called, make
93 // sure the argument is correct. 94 // sure the argument is correct.
94 unregisterHostByIdSpy = 95 unregisterHostByIdSpy =
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 assert.equal(onLocalHostStartedSpy.callCount, 0); 259 assert.equal(onLocalHostStartedSpy.callCount, 0);
259 assert.equal(startDaemonSpy.callCount, 0); 260 assert.equal(startDaemonSpy.callCount, 0);
260 }); 261 });
261 }); 262 });
262 263
263 // Check what happens when the HostDaemonFacade's 264 // Check what happens when the HostDaemonFacade's
264 // getCredentialsFromAuthCode method fails. 265 // getCredentialsFromAuthCode method fails.
265 QUnit.test('start with getCredentialsFromAuthCode failure', function(assert) { 266 QUnit.test('start with getCredentialsFromAuthCode failure', function(assert) {
266 mockHostDaemonFacade.useEmail = null; 267 mockHostDaemonFacade.useEmail = null;
267 mockHostDaemonFacade.refreshToken = null; 268 mockHostDaemonFacade.refreshToken = null;
268 return controller.start(FAKE_HOST_PIN, true).then(function() { 269 return controller.start(FAKE_HOST_PIN, true).then(function(result) {
269 throw 'test failed'; 270 throw 'test failed';
270 }, function(/** remoting.Error */ e) { 271 }, function(/** remoting.Error */ e) {
271 assert.equal(e.getDetail(), 'getCredentialsFromAuthCode'); 272 assert.equal(e.getDetail(), 'getCredentialsFromAuthCode');
272 assert.equal(e.getTag(), remoting.Error.Tag.UNEXPECTED); 273 assert.equal(e.getTag(), remoting.Error.Tag.UNEXPECTED);
273 assert.equal(getCredentialsFromAuthCodeSpy.callCount, 1); 274 assert.equal(getCredentialsFromAuthCodeSpy.callCount, 1);
274 assert.equal(onLocalHostStartedSpy.callCount, 0); 275 assert.equal(onLocalHostStartedSpy.callCount, 0);
275 assert.equal(startDaemonSpy.callCount, 0); 276 assert.equal(startDaemonSpy.callCount, 0);
276 }); 277 });
277 }); 278 });
278 279
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 assert.deepEqual( 349 assert.deepEqual(
349 getCredentialsFromAuthCodeSpy.args[0][0], 350 getCredentialsFromAuthCodeSpy.args[0][0],
350 FAKE_AUTH_CODE); 351 FAKE_AUTH_CODE);
351 assert.equal(getPinHashSpy.callCount, 1); 352 assert.equal(getPinHashSpy.callCount, 1);
352 assert.deepEqual( 353 assert.deepEqual(
353 getPinHashSpy.args[0].slice(0, 2), 354 getPinHashSpy.args[0].slice(0, 2),
354 [FAKE_HOST_ID, FAKE_HOST_PIN]); 355 [FAKE_HOST_ID, FAKE_HOST_PIN]);
355 assert.equal(unregisterHostByIdSpy.callCount, 0); 356 assert.equal(unregisterHostByIdSpy.callCount, 0);
356 assert.equal(onLocalHostStartedSpy.callCount, 1); 357 assert.equal(onLocalHostStartedSpy.callCount, 1);
357 assert.equal(startDaemonSpy.callCount, 1); 358 assert.equal(startDaemonSpy.callCount, 1);
359 var expectedConfig = {
360 xmpp_login: FAKE_XMPP_LOGIN,
361 oauth_refresh_token: FAKE_REFRESH_TOKEN,
362 host_owner: FAKE_CLIENT_JID.toLowerCase(),
363 host_owner_email: FAKE_USER_EMAIL,
364 host_name: FAKE_HOST_NAME,
365 host_secret_hash: fakePinHash,
366 private_key: FAKE_PRIVATE_KEY
367 };
368 if (remoting.settings.USE_GCD) {
369 expectedConfig['gcd_device_id'] = FAKE_HOST_ID;
370 } else {
371 expectedConfig['host_id'] = FAKE_HOST_ID;
372 }
358 assert.deepEqual( 373 assert.deepEqual(
359 startDaemonSpy.args[0].slice(0, 2), 374 startDaemonSpy.args[0].slice(0, 2),
360 [{ 375 [expectedConfig, consent]);
361 xmpp_login: FAKE_XMPP_LOGIN,
362 oauth_refresh_token: FAKE_REFRESH_TOKEN,
363 host_owner: FAKE_CLIENT_JID.toLowerCase(),
364 host_owner_email: FAKE_USER_EMAIL,
365 host_id: FAKE_HOST_ID,
366 host_name: FAKE_HOST_NAME,
367 host_secret_hash: fakePinHash,
368 private_key: FAKE_PRIVATE_KEY
369 }, consent]);
370 }); 376 });
371 }); 377 });
372 }); 378 });
373 379
374 // Check what happens when stopDaemon calls onError. 380 // Check what happens when stopDaemon calls onError.
375 // TODO(jrw): Should stopDaemon even have an onError callback? 381 // TODO(jrw): Should stopDaemon even have an onError callback?
376 QUnit.test('stop with stopDaemon failure', function(assert) { 382 QUnit.test('stop with stopDaemon failure', function(assert) {
377 mockHostDaemonFacade.stopDaemonResult = null; 383 mockHostDaemonFacade.stopDaemonResult = null;
378 return new Promise(function(resolve, reject) { 384 return new Promise(function(resolve, reject) {
379 controller.stop(function() { 385 controller.stop(function() {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 resolve(null); 595 resolve(null);
590 }); 596 });
591 }); 597 });
592 }); 598 });
593 599
594 // Tests omitted for hasFeature, getPairedClients, deletePairedClient, 600 // Tests omitted for hasFeature, getPairedClients, deletePairedClient,
595 // and clearPairedClients because they simply call through to 601 // and clearPairedClients because they simply call through to
596 // HostDaemonFacade. 602 // HostDaemonFacade.
597 603
598 })(); 604 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698