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