Chromium Code Reviews| Index: remoting/webapp/browser_test/mock_session_connector.js |
| diff --git a/remoting/webapp/browser_test/mock_session_connector.js b/remoting/webapp/browser_test/mock_session_connector.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..13d6525f37c67589c045b078baf2f8ef6f1fc749 |
| --- /dev/null |
| +++ b/remoting/webapp/browser_test/mock_session_connector.js |
| @@ -0,0 +1,120 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
|
Sergey Ulanov
2014/09/24 01:26:59
year
Jamie
2014/09/24 17:03:45
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @fileoverview |
| + * @suppress {checkTypes} |
| + */ |
| + |
| +'use strict'; |
| + |
| +/** @suppress {duplicate} */ |
| +var remoting = remoting || {}; |
| + |
| +/** |
| + * @constructor |
| + * @implements {remoting.SessionConnector} |
| + */ |
| +remoting.MockSessionConnector = function(clientContainer, onConnected, onError, |
| + onExtensionMessage) { |
| + this.clientContainer_ = clientContainer; |
| + this.onConnected_ = onConnected; |
| + this.onError = onError; |
| + this.onExtensionMessage_ = onExtensionMessage; |
| + this.reset(); |
| +}; |
| + |
| +remoting.MockSessionConnector.prototype.reset = function() { |
| + this.pairingRequested_ = false; |
| +}; |
| + |
| +remoting.MockSessionConnector.prototype.connectMe2Me = |
| + function(host, fetchPin, fetchThirdPartyToken, |
| + clientPairingId, clientPairedSecret) { |
| + this.mode_ = remoting.ClientSession.Mode.ME2ME; |
| + this.connect_(); |
| +}; |
| + |
| +remoting.MockSessionConnector.prototype.updatePairingInfo = |
| + function(clientId, sharedSecret) { |
| +}; |
| + |
| +remoting.MockSessionConnector.prototype.connectIT2Me = |
| + function(accessCode) { |
| + this.mode_ = remoting.ClientSession.Mode.ME2ME; |
| + this.connect_(); |
| +}; |
| + |
| +remoting.MockSessionConnector.prototype.reconnect = function() { |
| + base.debug.assert(this.mode_ == remoting.ClientSession.Mode.ME2ME); |
| + this.connect_(); |
| +}; |
| + |
| +remoting.MockSessionConnector.prototype.cancel = function() { |
| +}; |
| + |
| +remoting.MockSessionConnector.prototype.getConnectionMode = function() { |
| + return this.mode_; |
| +}; |
| + |
| +remoting.MockSessionConnector.prototype.getHostId = function() { |
| + return this.hostId_; |
| +}; |
| + |
| +remoting.MockSessionConnector.prototype.requestPairing = function() { |
| + this.pairingRequested_ = true; |
| +}; |
| + |
| +remoting.MockSessionConnector.prototype.pairingRequested = function() { |
| + return this.pairingRequested_; |
| +}; |
| + |
| +remoting.MockSessionConnector.prototype.connect_ = function() { |
| + var signalling = new remoting.MockSignalStrategy(); |
| + var hostName = 'Mock host'; |
| + var accessCode = ''; |
| + var authenticationMethods = ''; |
| + var hostId = ''; |
| + var hostJid = ''; |
| + var hostPublicKey = ''; |
| + var clientPairingId = ''; |
| + var clientPairedSecret = ''; |
| + var fetchPin = function(offerPairing, callback) { |
| + window.setTimeout(function() { callback('') }, 0); |
| + }; |
| + var fetchThirdPartyToken = function(tokenUrl, scope, callback) { |
| + window.setTimeout(function() { callback('', '') }, 0); |
| + }; |
| + |
| + var clientSession = new remoting.ClientSession( |
|
Sergey Ulanov
2014/09/24 01:26:59
Why do you need to create real ClientSession here
Jamie
2014/09/24 17:03:45
ClientSession contains most of the application log
|
| + signalling, this.clientContainer_, hostName, |
| + accessCode, fetchPin, fetchThirdPartyToken, |
| + authenticationMethods, hostId, hostJid, hostPublicKey, |
| + this.mode_, clientPairingId, clientPairedSecret); |
| + |
| + var onStateChange = function(event) { |
| + if (event.current == remoting.ClientSession.State.CONNECTED) { |
| + this.onConnected_(clientSession); |
|
Jamie
2014/09/23 23:53:55
Part of the API contract for SessionConnector is t
|
| + } |
| + }.bind(this); |
| + |
| + clientSession.addEventListener( |
| + remoting.ClientSession.Events.stateChanged, |
| + onStateChange); |
| + clientSession.createPluginAndConnect(this.onExtensionMessage_); |
| +}; |
| + |
| + |
|
Sergey Ulanov
2014/09/24 01:26:59
nit:remove extra empty lines
Jamie
2014/09/24 17:03:45
I've removed one of them. I prefer to leave two bl
|
| + |
| +/** |
| + * @constructor |
| + * @extends {remoting.SessionConnectorFactory} |
| + */ |
| +remoting.MockSessionConnectorFactory = function() {}; |
| + |
| +remoting.MockSessionConnectorFactory.prototype.createConnector = |
| + function(clientContainer, onConnected, onError, onExtensionMessage) { |
| + return new remoting.MockSessionConnector( |
| + clientContainer, onConnected, onError, onExtensionMessage); |
| +}; |