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