1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 * Mock implementation of SessionConnector for testing.
8 * @suppress {checkTypes}
13 /** @suppress {duplicate} */
14 var remoting = remoting || {};
18 * @implements {remoting.SessionConnector}
20 remoting.MockSessionConnector = function(clientContainer, onConnected, onError,
22 this.clientContainer_ = clientContainer;
23 this.onConnected_ = onConnected;
24 this.onError = onError;
25 this.onExtensionMessage_ = onExtensionMessage;
29 remoting.MockSessionConnector.prototype.reset = function() {
30 this.pairingRequested_ = false;
33 remoting.MockSessionConnector.prototype.connectMe2Me =
34 function(host, fetchPin, fetchThirdPartyToken,
35 clientPairingId, clientPairedSecret) {
36 this.mode_ = remoting.ClientSession.Mode.ME2ME;
40 remoting.MockSessionConnector.prototype.updatePairingInfo =
41 function(clientId, sharedSecret) {
44 remoting.MockSessionConnector.prototype.connectIT2Me =
45 function(accessCode) {
46 this.mode_ = remoting.ClientSession.Mode.ME2ME;
50 remoting.MockSessionConnector.prototype.reconnect = function() {
51 base.debug.assert(this.mode_ == remoting.ClientSession.Mode.ME2ME);
55 remoting.MockSessionConnector.prototype.cancel = function() {
58 remoting.MockSessionConnector.prototype.getConnectionMode = function() {
62 remoting.MockSessionConnector.prototype.getHostId = function() {
66 remoting.MockSessionConnector.prototype.requestPairing = function() {
67 this.pairingRequested_ = true;
70 remoting.MockSessionConnector.prototype.pairingRequested = function() {
71 return this.pairingRequested_;
74 remoting.MockSessionConnector.prototype.connect_ = function() {
75 var signalling = new remoting.MockSignalStrategy();
76 var hostName = 'Mock host';
78 var authenticationMethods = '';
81 var hostPublicKey = '';
82 var clientPairingId = '';
83 var clientPairedSecret = '';
84 var fetchPin = function(offerPairing, callback) {
85 window.setTimeout(function() { callback('') }, 0);
87 var fetchThirdPartyToken = function(tokenUrl, scope, callback) {
88 window.setTimeout(function() { callback('', '') }, 0);
91 var clientSession = new remoting.ClientSession(
92 signalling, this.clientContainer_, hostName,
93 accessCode, fetchPin, fetchThirdPartyToken,
94 authenticationMethods, hostId, hostJid, hostPublicKey,
95 this.mode_, clientPairingId, clientPairedSecret);
97 var onStateChange = function(event) {
98 if (event.current == remoting.ClientSession.State.CONNECTED) {
99 this.onConnected_(clientSession);
103 clientSession.addEventListener(
104 remoting.ClientSession.Events.stateChanged,
106 clientSession.createPluginAndConnect(this.onExtensionMessage_);
112 * @extends {remoting.SessionConnectorFactory}
114 remoting.MockSessionConnectorFactory = function() {};
116 remoting.MockSessionConnectorFactory.prototype.createConnector =
117 function(clientContainer, onConnected, onError, onExtensionMessage) {
118 return new remoting.MockSessionConnector(
119 clientContainer, onConnected, onError, onExtensionMessage);