| OLD | NEW |
| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 /** @type {remoting.MockHostListApi} */ | 74 /** @type {remoting.MockHostListApi} */ |
| 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.activate(['identity', 'runtime']); | 79 chromeMocks.activate(['identity', 'runtime']); |
| 80 chromeMocks.identity.mock$setToken(FAKE_IDENTITY_TOKEN); | 80 chromeMocks.identity.mock$setToken(FAKE_IDENTITY_TOKEN); |
| 81 remoting.settings = new remoting.Settings(); | 81 remoting.settings = new remoting.Settings(); |
| 82 remoting.identity = new remoting.Identity(); | 82 remoting.identity = new remoting.Identity(); |
| 83 mockHostListApi = new remoting.MockHostListApi; | 83 mockHostListApi = new remoting.MockHostListApi; |
| 84 mockHostListApi.registerResult = FAKE_AUTH_CODE; | 84 mockHostListApi.authCodeFromRegister = FAKE_AUTH_CODE; |
| 85 mockHostListApi.emailFromRegister = ''; |
| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 assert.equal(e.getTag(), remoting.Error.Tag.UNEXPECTED); | 244 assert.equal(e.getTag(), remoting.Error.Tag.UNEXPECTED); |
| 244 assert.equal(unregisterHostByIdSpy.callCount, 0); | 245 assert.equal(unregisterHostByIdSpy.callCount, 0); |
| 245 assert.equal(onLocalHostStartedSpy.callCount, 0); | 246 assert.equal(onLocalHostStartedSpy.callCount, 0); |
| 246 assert.equal(startDaemonSpy.callCount, 0); | 247 assert.equal(startDaemonSpy.callCount, 0); |
| 247 }); | 248 }); |
| 248 }); | 249 }); |
| 249 | 250 |
| 250 // Check what happens when the registry returns an HTTP when we try to | 251 // Check what happens when the registry returns an HTTP when we try to |
| 251 // register a host. | 252 // register a host. |
| 252 QUnit.test('start with host registration failure', function(assert) { | 253 QUnit.test('start with host registration failure', function(assert) { |
| 253 mockHostListApi.registerResult = null; | 254 mockHostListApi.authCodeFromRegister = null; |
| 254 return controller.start(FAKE_HOST_PIN, true).then(function() { | 255 return controller.start(FAKE_HOST_PIN, true).then(function() { |
| 255 throw 'test failed'; | 256 throw 'test failed'; |
| 256 }, function(/** remoting.Error */ e) { | 257 }, function(/** remoting.Error */ e) { |
| 257 assert.equal(e.getTag(), remoting.Error.Tag.REGISTRATION_FAILED); | 258 assert.equal(e.getTag(), remoting.Error.Tag.REGISTRATION_FAILED); |
| 258 assert.equal(unregisterHostByIdSpy.callCount, 0); | 259 assert.equal(unregisterHostByIdSpy.callCount, 0); |
| 259 assert.equal(onLocalHostStartedSpy.callCount, 0); | 260 assert.equal(onLocalHostStartedSpy.callCount, 0); |
| 260 assert.equal(startDaemonSpy.callCount, 0); | 261 assert.equal(startDaemonSpy.callCount, 0); |
| 261 }); | 262 }); |
| 262 }); | 263 }); |
| 263 | 264 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 275 assert.equal(onLocalHostStartedSpy.callCount, 0); | 276 assert.equal(onLocalHostStartedSpy.callCount, 0); |
| 276 assert.equal(startDaemonSpy.callCount, 0); | 277 assert.equal(startDaemonSpy.callCount, 0); |
| 277 }); | 278 }); |
| 278 }); | 279 }); |
| 279 | 280 |
| 280 // Check what happens when the HostDaemonFacade's getPinHash method | 281 // Check what happens when the HostDaemonFacade's getPinHash method |
| 281 // fails, and verify that getPinHash is called when the registry | 282 // fails, and verify that getPinHash is called when the registry |
| 282 // does't return an auth code. | 283 // does't return an auth code. |
| 283 QUnit.test('start with getRefreshToken+getPinHash failure', function(assert) { | 284 QUnit.test('start with getRefreshToken+getPinHash failure', function(assert) { |
| 284 mockHostDaemonFacade.pinHashFunc = null; | 285 mockHostDaemonFacade.pinHashFunc = null; |
| 285 mockHostListApi.registerResult = ''; | 286 mockHostListApi.authCodeFromRegister = ''; |
| 286 return controller.start(FAKE_HOST_PIN, true).then(function() { | 287 return controller.start(FAKE_HOST_PIN, true).then(function() { |
| 287 throw 'test failed'; | 288 throw 'test failed'; |
| 288 }, function(/** remoting.Error */ e) { | 289 }, function(/** remoting.Error */ e) { |
| 289 assert.equal(e.getDetail(), 'getPinHash'); | 290 assert.equal(e.getDetail(), 'getPinHash'); |
| 290 assert.equal(e.getTag(), remoting.Error.Tag.UNEXPECTED); | 291 assert.equal(e.getTag(), remoting.Error.Tag.UNEXPECTED); |
| 291 assert.equal(onLocalHostStartedSpy.callCount, 0); | 292 assert.equal(onLocalHostStartedSpy.callCount, 0); |
| 292 assert.equal(startDaemonSpy.callCount, 0); | 293 assert.equal(startDaemonSpy.callCount, 0); |
| 293 }); | 294 }); |
| 294 }); | 295 }); |
| 295 | 296 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 }); | 388 }); |
| 388 }); | 389 }); |
| 389 }); | 390 }); |
| 390 | 391 |
| 391 // Check alternative host registration without a registry-supplied | 392 // Check alternative host registration without a registry-supplied |
| 392 // auth code. | 393 // auth code. |
| 393 [false, true].forEach(function(/** boolean */ consent) { | 394 [false, true].forEach(function(/** boolean */ consent) { |
| 394 QUnit.test('start without auth code, consent=' + consent, function(assert) { | 395 QUnit.test('start without auth code, consent=' + consent, function(assert) { |
| 395 /** @const */ | 396 /** @const */ |
| 396 var fakePinHash = fakePinHashFunc(FAKE_HOST_ID, FAKE_HOST_PIN); | 397 var fakePinHash = fakePinHashFunc(FAKE_HOST_ID, FAKE_HOST_PIN); |
| 397 mockHostListApi.registerResult = ''; | 398 mockHostListApi.authCodeFromRegister = ''; |
| 398 stubSignalStrategyConnect(true); | 399 stubSignalStrategyConnect(true); |
| 399 return controller.start(FAKE_HOST_PIN, consent).then(function() { | 400 return controller.start(FAKE_HOST_PIN, consent).then(function() { |
| 400 assert.equal(getCredentialsFromAuthCodeSpy.callCount, 0); | 401 assert.equal(getCredentialsFromAuthCodeSpy.callCount, 0); |
| 401 assert.equal(getPinHashSpy.callCount, 1); | 402 assert.equal(getPinHashSpy.callCount, 1); |
| 402 assert.deepEqual( | 403 assert.deepEqual( |
| 403 getPinHashSpy.args[0].slice(0, 2), | 404 getPinHashSpy.args[0].slice(0, 2), |
| 404 [FAKE_HOST_ID, FAKE_HOST_PIN]); | 405 [FAKE_HOST_ID, FAKE_HOST_PIN]); |
| 405 assert.equal(unregisterHostByIdSpy.callCount, 0); | 406 assert.equal(unregisterHostByIdSpy.callCount, 0); |
| 406 assert.equal(onLocalHostStartedSpy.callCount, 1); | 407 assert.equal(onLocalHostStartedSpy.callCount, 1); |
| 407 assert.equal(startDaemonSpy.callCount, 1); | 408 assert.equal(startDaemonSpy.callCount, 1); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 resolve(null); | 638 resolve(null); |
| 638 }); | 639 }); |
| 639 }); | 640 }); |
| 640 }); | 641 }); |
| 641 | 642 |
| 642 // Tests omitted for hasFeature, getPairedClients, deletePairedClient, | 643 // Tests omitted for hasFeature, getPairedClients, deletePairedClient, |
| 643 // and clearPairedClients because they simply call through to | 644 // and clearPairedClients because they simply call through to |
| 644 // HostDaemonFacade. | 645 // HostDaemonFacade. |
| 645 | 646 |
| 646 })(); | 647 })(); |
| OLD | NEW |