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
|| {};
17 * @param {HTMLElement} clientContainer Container element for the client view.
18 * @param {function(remoting.ClientSession):void} onConnected Callback on
20 * @param {function(remoting.Error):void} onError Callback on error.
21 * @param {function(string, string):boolean} onExtensionMessage The handler for
22 * protocol extension messages. Returns true if a message is recognized;
24 * @param {function(remoting.Error):void} onConnectionFailed Callback for when
25 * the connection fails.
26 * @param {Array<string>} requiredCapabilities Connector capabilities
27 * required by this application.
28 * @param {string} defaultRemapKeys The default set of key mappings for the
29 * client session to use.
31 * @implements {remoting.SessionConnector}
33 remoting
.MockSessionConnector = function(clientContainer
, onConnected
, onError
,
38 this.clientContainer_
= clientContainer
;
39 /** @type {function(remoting.ClientSession):void} */
40 this.onConnected_
= onConnected
;
41 this.onError
= onError
;
42 this.onExtensionMessage_
= onExtensionMessage
;
43 this.onConnectionFailed_
= onConnectionFailed
;
44 this.requiredCapabilities_
= requiredCapabilities
;
45 this.defaultRemapKeys_
= defaultRemapKeys
;
47 /** @type {remoting.DesktopConnectedView.Mode} */
48 this.mode_
= remoting
.DesktopConnectedView
.Mode
.ME2ME
;
53 remoting
.MockSessionConnector
.prototype.reset = function() {
54 /** @type {string} @private */
58 remoting
.MockSessionConnector
.prototype.connectMe2Me
=
59 function(host
, fetchPin
, fetchThirdPartyToken
,
60 clientPairingId
, clientPairedSecret
) {
61 this.mode_
= remoting
.DesktopConnectedView
.Mode
.ME2ME
;
65 remoting
.MockSessionConnector
.prototype.retryConnectMe2Me
=
66 function(host
, fetchPin
, fetchThirdPartyToken
,
67 clientPairingId
, clientPairedSecret
) {
68 this.mode_
= remoting
.DesktopConnectedView
.Mode
.ME2ME
;
72 remoting
.MockSessionConnector
.prototype.connectMe2App
=
73 function(host
, fetchThirdPartyToken
) {
74 this.mode_
= remoting
.DesktopConnectedView
.Mode
.APP_REMOTING
;
78 remoting
.MockSessionConnector
.prototype.updatePairingInfo
=
79 function(clientId
, sharedSecret
) {
82 remoting
.MockSessionConnector
.prototype.connectIT2Me
=
83 function(accessCode
) {
84 this.mode_
= remoting
.DesktopConnectedView
.Mode
.ME2ME
;
88 remoting
.MockSessionConnector
.prototype.reconnect = function() {
89 base
.debug
.assert(this.mode_
== remoting
.DesktopConnectedView
.Mode
.ME2ME
);
93 remoting
.MockSessionConnector
.prototype.cancel = function() {
96 remoting
.MockSessionConnector
.prototype.getConnectionMode = function() {
100 remoting
.MockSessionConnector
.prototype.getHostId = function() {
104 remoting
.MockSessionConnector
.prototype.connect_ = function() {
105 var signalling
= new remoting
.MockSignalStrategy();
106 signalling
.setStateForTesting(remoting
.SignalStrategy
.State
.CONNECTED
);
107 var hostName
= 'Mock host';
109 var authenticationMethods
= '';
112 var hostPublicKey
= '';
113 var clientPairingId
= '';
114 var clientPairedSecret
= '';
117 * @param {boolean} offerPairing
118 * @param {function(string):void} callback
120 var fetchPin = function(offerPairing
, callback
) {
121 window
.setTimeout(function() { callback('') }, 0);
125 * @param {string} tokenUrl
126 * @param {string} hostPublicKey
127 * @param {string} scope
128 * @param {function(string, string):void} callback
130 var fetchThirdPartyToken = function(tokenUrl
, hostPublicKey
, scope
,
132 window
.setTimeout(function() { callback('', '') }, 0);
135 var clientSession
= new remoting
.ClientSession(
136 signalling
, this.clientContainer_
, hostName
,
137 accessCode
, fetchPin
, fetchThirdPartyToken
,
138 authenticationMethods
, hostId
, hostJid
, hostPublicKey
,
139 this.mode_
, clientPairingId
, clientPairedSecret
);
142 /** @param {remoting.ClientSession.StateEvent} event */
143 var onStateChange = function(event
) {
144 if (event
.current
== remoting
.ClientSession
.State
.CONNECTED
) {
145 that
.onConnected_(clientSession
);
149 clientSession
.addEventListener(
150 remoting
.ClientSession
.Events
.stateChanged
,
152 clientSession
.createPluginAndConnect(this.onExtensionMessage_
);
158 * @extends {remoting.SessionConnectorFactory}
160 remoting
.MockSessionConnectorFactory = function() {};
163 * @param {HTMLElement} clientContainer Container element for the client view.
164 * @param {function(remoting.ClientSession):void} onConnected Callback on
166 * @param {function(remoting.Error):void} onError Callback on error.
167 * @param {function(string, string):boolean} onExtensionMessage The handler for
168 * protocol extension messages. Returns true if a message is recognized;
170 * @param {function(remoting.Error):void} onConnectionFailed Callback for when
171 * the connection fails.
172 * @param {Array<string>} requiredCapabilities Connector capabilities
173 * required by this application.
174 * @param {string} defaultRemapKeys The default set of key mappings to use
175 * in the client session.
176 * @return {remoting.MockSessionConnector}
178 remoting
.MockSessionConnectorFactory
.prototype.createConnector
=
179 function(clientContainer
, onConnected
, onError
, onExtensionMessage
,
180 onConnectionFailed
, requiredCapabilities
, defaultRemapKeys
) {
181 return new remoting
.MockSessionConnector(
182 clientContainer
, onConnected
, onError
, onExtensionMessage
,
183 onConnectionFailed
, requiredCapabilities
, defaultRemapKeys
);