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 /** @suppress {duplicate} */ | 6 /** @suppress {duplicate} */ |
7 var remoting = remoting || {}; | 7 var remoting = remoting || {}; |
8 | 8 |
9 (function() { | 9 (function() { |
10 | 10 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 }); | 277 }); |
278 | 278 |
279 var count = 0; | 279 var count = 0; |
280 function onPluginCreated(/** remoting.MockClientPlugin */ plugin) { | 280 function onPluginCreated(/** remoting.MockClientPlugin */ plugin) { |
281 count++; | 281 count++; |
282 if (count == 1) { | 282 if (count == 1) { |
283 plugin.mock$returnErrorOnConnect( | 283 plugin.mock$returnErrorOnConnect( |
284 remoting.ClientSession.ConnectionError.HOST_IS_OFFLINE); | 284 remoting.ClientSession.ConnectionError.HOST_IS_OFFLINE); |
285 } else if (count == 2) { | 285 } else if (count == 2) { |
286 plugin.mock$useDefaultBehavior( | 286 plugin.mock$useDefaultBehavior( |
287 remoting.MockClientPlugin.AuthMethod.PIN); | 287 remoting.ChromotingEvent.AuthMethod.PIN); |
288 } | 288 } |
289 } | 289 } |
290 | 290 |
291 /** | 291 /** |
292 * @param {remoting.MockClientPlugin} plugin | 292 * @param {remoting.MockClientPlugin} plugin |
293 * @param {remoting.ClientSession.State} state | 293 * @param {remoting.ClientSession.State} state |
294 */ | 294 */ |
295 function onStatusChanged(plugin, state) { | 295 function onStatusChanged(plugin, state) { |
296 if (state == remoting.ClientSession.State.CONNECTED) { | 296 if (state == remoting.ClientSession.State.CONNECTED) { |
297 testDriver.me2meActivity().stop(); | 297 testDriver.me2meActivity().stop(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 } | 399 } |
400 } | 400 } |
401 } | 401 } |
402 | 402 |
403 testDriver.mockConnection().pluginFactory().mock$setPluginStatusChanged( | 403 testDriver.mockConnection().pluginFactory().mock$setPluginStatusChanged( |
404 onStatusChanged); | 404 onStatusChanged); |
405 | 405 |
406 return testDriver.startTest(); | 406 return testDriver.startTest(); |
407 }); | 407 }); |
408 | 408 |
| 409 |
| 410 /** |
| 411 * @param {remoting.Me2MeTestDriver} testDriver |
| 412 * @param {remoting.ChromotingEvent.AuthMethod} authMethod |
| 413 * @param {boolean} connected |
| 414 * @return {Promise} |
| 415 */ |
| 416 function createAuthMethodTest(testDriver, authMethod, connected) { |
| 417 var ChromotingEvent = remoting.ChromotingEvent; |
| 418 var baseEvent = { |
| 419 session_entry_point: ChromotingEvent.SessionEntryPoint.CONNECT_BUTTON, |
| 420 role: ChromotingEvent.Role.CLIENT, |
| 421 mode: ChromotingEvent.Mode.ME2ME, |
| 422 }; |
| 423 |
| 424 expectSequence( |
| 425 testDriver, baseEvent, [ |
| 426 ChromotingEvent.SessionState.STARTED, |
| 427 ChromotingEvent.SessionState.SIGNALING, |
| 428 ChromotingEvent.SessionState.CREATING_PLUGIN, |
| 429 ChromotingEvent.SessionState.CONNECTING, |
| 430 ]); |
| 431 |
| 432 var copy = /** @type{Object} */ (base.deepCopy(baseEvent)); |
| 433 copy.auth_method = authMethod; |
| 434 if (connected) { |
| 435 expectSequence( |
| 436 testDriver, copy, [ |
| 437 ChromotingEvent.SessionState.AUTHENTICATED, |
| 438 ChromotingEvent.SessionState.CONNECTED, |
| 439 ChromotingEvent.SessionState.CLOSED |
| 440 ]); |
| 441 } else { |
| 442 testDriver.expectEvents([{ |
| 443 session_entry_point: ChromotingEvent.SessionEntryPoint.CONNECT_BUTTON, |
| 444 role: ChromotingEvent.Role.CLIENT, |
| 445 mode: ChromotingEvent.Mode.ME2ME, |
| 446 auth_method: authMethod, |
| 447 session_state: ChromotingEvent.SessionState.CONNECTION_FAILED, |
| 448 connection_error: ChromotingEvent.ConnectionError.INVALID_ACCESS_CODE, |
| 449 }]); |
| 450 } |
| 451 |
| 452 /** |
| 453 * @param {remoting.MockClientPlugin} plugin |
| 454 * @param {remoting.ClientSession.State} state |
| 455 */ |
| 456 function onStatusChanged(plugin, state) { |
| 457 if (state == remoting.ClientSession.State.CONNECTED || |
| 458 state == remoting.ClientSession.State.FAILED) { |
| 459 testDriver.me2meActivity().stop(); |
| 460 testDriver.endTest(); |
| 461 } |
| 462 } |
| 463 function onPluginCreated(/** remoting.MockClientPlugin */ plugin) { |
| 464 if (connected) { |
| 465 plugin.mock$useDefaultBehavior(authMethod); |
| 466 } else { |
| 467 plugin.mock$returnErrorOnConnect( |
| 468 remoting.ClientSession.ConnectionError.SESSION_REJECTED, authMethod); |
| 469 } |
| 470 } |
| 471 |
| 472 testDriver.mockConnection().pluginFactory().mock$setPluginCreated( |
| 473 onPluginCreated); |
| 474 testDriver.mockConnection().pluginFactory().mock$setPluginStatusChanged( |
| 475 onStatusChanged); |
| 476 |
| 477 return testDriver.startTest(); |
| 478 } |
| 479 |
| 480 QUnit.test('Auth method - THIRD_PARTY (connected)', function() { |
| 481 return createAuthMethodTest( |
| 482 testDriver, remoting.ChromotingEvent.AuthMethod.THIRD_PARTY, true); |
| 483 }); |
| 484 |
| 485 QUnit.test('Auth method - PINLESS (connected)', function() { |
| 486 return createAuthMethodTest( |
| 487 testDriver, remoting.ChromotingEvent.AuthMethod.PINLESS, true); |
| 488 }); |
| 489 |
| 490 QUnit.test('Auth method - PIN (connected)', function() { |
| 491 return createAuthMethodTest( |
| 492 testDriver, remoting.ChromotingEvent.AuthMethod.PIN, true); |
| 493 }); |
| 494 |
| 495 QUnit.test('Auth method - THIRD_PARTY (failed)', function() { |
| 496 return createAuthMethodTest( |
| 497 testDriver, remoting.ChromotingEvent.AuthMethod.THIRD_PARTY, false); |
| 498 }); |
| 499 |
| 500 QUnit.test('Auth method - PINLESS (failed)', function() { |
| 501 return createAuthMethodTest( |
| 502 testDriver, remoting.ChromotingEvent.AuthMethod.PINLESS, false); |
| 503 }); |
| 504 |
| 505 QUnit.test('Auth method - PIN (failed)', function() { |
| 506 return createAuthMethodTest( |
| 507 testDriver, remoting.ChromotingEvent.AuthMethod.PIN, false); |
| 508 }); |
| 509 |
409 })(); | 510 })(); |
OLD | NEW |