| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview | |
| 7 * Mock implementation of SessionConnector for testing. | |
| 8 * @suppress {checkTypes} | |
| 9 */ | |
| 10 | |
| 11 'use strict'; | |
| 12 | |
| 13 /** @suppress {duplicate} */ | |
| 14 var remoting = remoting || {}; | |
| 15 | |
| 16 /** | |
| 17 * @param {HTMLElement} clientContainer Container element for the client view. | |
| 18 * @param {function(remoting.ClientSession):void} onConnected Callback on | |
| 19 * success. | |
| 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; | |
| 23 * false otherwise. | |
| 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. | |
| 30 * @constructor | |
| 31 * @implements {remoting.SessionConnector} | |
| 32 */ | |
| 33 remoting.MockSessionConnector = function(clientContainer, onConnected, onError, | |
| 34 onExtensionMessage, | |
| 35 onConnectionFailed, | |
| 36 requiredCapabilities, | |
| 37 defaultRemapKeys) { | |
| 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; | |
| 46 | |
| 47 /** @type {remoting.DesktopConnectedView.Mode} */ | |
| 48 this.mode_ = remoting.DesktopConnectedView.Mode.ME2ME; | |
| 49 | |
| 50 this.reset(); | |
| 51 }; | |
| 52 | |
| 53 remoting.MockSessionConnector.prototype.reset = function() { | |
| 54 /** @type {string} @private */ | |
| 55 this.hostId_ = ''; | |
| 56 }; | |
| 57 | |
| 58 remoting.MockSessionConnector.prototype.connectMe2Me = | |
| 59 function(host, fetchPin, fetchThirdPartyToken, | |
| 60 clientPairingId, clientPairedSecret) { | |
| 61 this.mode_ = remoting.DesktopConnectedView.Mode.ME2ME; | |
| 62 this.connect_(); | |
| 63 }; | |
| 64 | |
| 65 remoting.MockSessionConnector.prototype.retryConnectMe2Me = | |
| 66 function(host, fetchPin, fetchThirdPartyToken, | |
| 67 clientPairingId, clientPairedSecret) { | |
| 68 this.mode_ = remoting.DesktopConnectedView.Mode.ME2ME; | |
| 69 this.connect_(); | |
| 70 }; | |
| 71 | |
| 72 remoting.MockSessionConnector.prototype.connectMe2App = | |
| 73 function(host, fetchThirdPartyToken) { | |
| 74 this.mode_ = remoting.DesktopConnectedView.Mode.APP_REMOTING; | |
| 75 this.connect_(); | |
| 76 }; | |
| 77 | |
| 78 remoting.MockSessionConnector.prototype.updatePairingInfo = | |
| 79 function(clientId, sharedSecret) { | |
| 80 }; | |
| 81 | |
| 82 remoting.MockSessionConnector.prototype.connectIT2Me = | |
| 83 function(accessCode) { | |
| 84 this.mode_ = remoting.DesktopConnectedView.Mode.ME2ME; | |
| 85 this.connect_(); | |
| 86 }; | |
| 87 | |
| 88 remoting.MockSessionConnector.prototype.reconnect = function() { | |
| 89 base.debug.assert(this.mode_ == remoting.DesktopConnectedView.Mode.ME2ME); | |
| 90 this.connect_(); | |
| 91 }; | |
| 92 | |
| 93 remoting.MockSessionConnector.prototype.cancel = function() { | |
| 94 }; | |
| 95 | |
| 96 remoting.MockSessionConnector.prototype.getConnectionMode = function() { | |
| 97 return this.mode_; | |
| 98 }; | |
| 99 | |
| 100 remoting.MockSessionConnector.prototype.getHostId = function() { | |
| 101 return this.hostId_; | |
| 102 }; | |
| 103 | |
| 104 remoting.MockSessionConnector.prototype.connect_ = function() { | |
| 105 var signalling = new remoting.MockSignalStrategy(); | |
| 106 signalling.setStateForTesting(remoting.SignalStrategy.State.CONNECTED); | |
| 107 var hostName = 'Mock host'; | |
| 108 var accessCode = ''; | |
| 109 var authenticationMethods = ''; | |
| 110 var hostId = ''; | |
| 111 var hostJid = ''; | |
| 112 var hostPublicKey = ''; | |
| 113 var clientPairingId = ''; | |
| 114 var clientPairedSecret = ''; | |
| 115 | |
| 116 /** | |
| 117 * @param {boolean} offerPairing | |
| 118 * @param {function(string):void} callback | |
| 119 */ | |
| 120 var fetchPin = function(offerPairing, callback) { | |
| 121 window.setTimeout(function() { callback('') }, 0); | |
| 122 }; | |
| 123 | |
| 124 /** | |
| 125 * @param {string} tokenUrl | |
| 126 * @param {string} hostPublicKey | |
| 127 * @param {string} scope | |
| 128 * @param {function(string, string):void} callback | |
| 129 */ | |
| 130 var fetchThirdPartyToken = function(tokenUrl, hostPublicKey, scope, | |
| 131 callback) { | |
| 132 window.setTimeout(function() { callback('', '') }, 0); | |
| 133 }; | |
| 134 | |
| 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); | |
| 140 | |
| 141 var that = this; | |
| 142 /** @param {remoting.ClientSession.StateEvent} event */ | |
| 143 var onStateChange = function(event) { | |
| 144 if (event.current == remoting.ClientSession.State.CONNECTED) { | |
| 145 that.onConnected_(clientSession); | |
| 146 } | |
| 147 }; | |
| 148 | |
| 149 clientSession.addEventListener( | |
| 150 remoting.ClientSession.Events.stateChanged, | |
| 151 onStateChange); | |
| 152 }; | |
| 153 | |
| 154 | |
| 155 /** | |
| 156 * @constructor | |
| 157 * @extends {remoting.SessionConnectorFactory} | |
| 158 */ | |
| 159 remoting.MockSessionConnectorFactory = function() {}; | |
| 160 | |
| 161 /** | |
| 162 * @param {HTMLElement} clientContainer Container element for the client view. | |
| 163 * @param {function(remoting.ClientSession):void} onConnected Callback on | |
| 164 * success. | |
| 165 * @param {function(!remoting.Error):void} onError Callback on error. | |
| 166 * @param {function(string, string):boolean} onExtensionMessage The handler for | |
| 167 * protocol extension messages. Returns true if a message is recognized; | |
| 168 * false otherwise. | |
| 169 * @param {function(!remoting.Error):void} onConnectionFailed Callback for when | |
| 170 * the connection fails. | |
| 171 * @param {Array<string>} requiredCapabilities Connector capabilities | |
| 172 * required by this application. | |
| 173 * @param {string} defaultRemapKeys The default set of key mappings to use | |
| 174 * in the client session. | |
| 175 * @return {remoting.MockSessionConnector} | |
| 176 */ | |
| 177 remoting.MockSessionConnectorFactory.prototype.createConnector = | |
| 178 function(clientContainer, onConnected, onError, onExtensionMessage, | |
| 179 onConnectionFailed, requiredCapabilities, defaultRemapKeys) { | |
| 180 return new remoting.MockSessionConnector( | |
| 181 clientContainer, onConnected, onError, onExtensionMessage, | |
| 182 onConnectionFailed, requiredCapabilities, defaultRemapKeys); | |
| 183 }; | |
| OLD | NEW |