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 ClientPlugin for testing. | 7 * Mock implementation of ClientPlugin for testing. |
8 */ | 8 */ |
9 | 9 |
10 /** @suppress {duplicate} */ | 10 /** @suppress {duplicate} */ |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 '|connectionEventHandler_| is null.'); | 189 '|connectionEventHandler_| is null.'); |
190 var PluginError = remoting.ClientSession.ConnectionError; | 190 var PluginError = remoting.ClientSession.ConnectionError; |
191 var error = opt_error ? opt_error : PluginError.NONE; | 191 var error = opt_error ? opt_error : PluginError.NONE; |
192 this.connectionEventHandler_.onConnectionStatusUpdate(status, error); | 192 this.connectionEventHandler_.onConnectionStatusUpdate(status, error); |
193 if (this.mock$onPluginStatusChanged_) { | 193 if (this.mock$onPluginStatusChanged_) { |
194 this.mock$onPluginStatusChanged_(this, status); | 194 this.mock$onPluginStatusChanged_(this, status); |
195 } | 195 } |
196 }; | 196 }; |
197 | 197 |
198 /** | 198 /** |
199 * @param {remoting.MockClientPlugin.AuthMethod} authMethod | 199 * @param {remoting.ChromotingEvent.AuthMethod} authMethod |
200 * @return {Promise} | 200 * @return {Promise} |
201 */ | 201 */ |
202 remoting.MockClientPlugin.prototype.mock$authenticate = function(authMethod) { | 202 remoting.MockClientPlugin.prototype.mock$authenticate = function(authMethod) { |
203 var AuthMethod = remoting.MockClientPlugin.AuthMethod; | 203 var AuthMethod = remoting.ChromotingEvent.AuthMethod; |
204 var deferred = new base.Deferred(); | 204 var deferred = new base.Deferred(); |
205 | 205 |
206 var that = this; | 206 var that = this; |
207 switch(authMethod) { | 207 switch(authMethod) { |
208 case AuthMethod.PIN: | 208 case AuthMethod.PIN: |
209 case AuthMethod.ACCESS_CODE: | 209 case AuthMethod.ACCESS_CODE: |
210 this.credentials_.getPIN(true).then(function() { | 210 this.credentials_.getPIN(true).then(function() { |
211 deferred.resolve(); | 211 deferred.resolve(); |
212 }); | 212 }); |
213 break; | 213 break; |
214 case AuthMethod.THIRD_PARTY: | 214 case AuthMethod.THIRD_PARTY: |
215 this.credentials_.getThirdPartyToken( | 215 this.credentials_.getThirdPartyToken( |
216 'fake_token_url', 'fake_host_publicKey', 'fake_scope' | 216 'fake_token_url', 'fake_host_publicKey', 'fake_scope' |
217 ).then(function() { | 217 ).then(function() { |
218 deferred.resolve(); | 218 deferred.resolve(); |
219 }); | 219 }); |
220 break; | 220 break; |
221 case AuthMethod.PAIRING: | 221 case AuthMethod.PINLESS: |
| 222 this.credentials_.getPairingInfo(); |
222 deferred.resolve(); | 223 deferred.resolve(); |
223 } | 224 } |
224 return deferred.promise(); | 225 return deferred.promise(); |
225 }; | 226 }; |
226 | 227 |
227 /** | 228 /** |
228 * @param {?function(remoting.MockClientPlugin, remoting.ClientSession.State)} | 229 * @param {?function(remoting.MockClientPlugin, remoting.ClientSession.State)} |
229 * callback | 230 * callback |
230 */ | 231 */ |
231 remoting.MockClientPlugin.prototype.mock$setPluginStatusChanged = | 232 remoting.MockClientPlugin.prototype.mock$setPluginStatusChanged = |
232 function(callback) { | 233 function(callback) { |
233 this.mock$onPluginStatusChanged_ = callback; | 234 this.mock$onPluginStatusChanged_ = callback; |
234 }; | 235 }; |
235 | 236 |
236 /** | 237 /** |
237 * @param {remoting.MockClientPlugin.AuthMethod} authMethod | 238 * @param {remoting.ChromotingEvent.AuthMethod} authMethod |
238 */ | 239 */ |
239 remoting.MockClientPlugin.prototype.mock$useDefaultBehavior = | 240 remoting.MockClientPlugin.prototype.mock$useDefaultBehavior = |
240 function(authMethod) { | 241 function(authMethod) { |
241 var that = this; | 242 var that = this; |
242 var State = remoting.ClientSession.State; | 243 var State = remoting.ClientSession.State; |
243 this.mock$onConnect().then(function() { | 244 this.mock$onConnect().then(function() { |
244 that.mock$setConnectionStatus(State.CONNECTING); | 245 that.mock$setConnectionStatus(State.CONNECTING); |
245 return that.mock$authenticate(authMethod); | 246 return that.mock$authenticate(authMethod); |
246 }).then(function() { | 247 }).then(function() { |
247 that.mock$setConnectionStatus(State.AUTHENTICATED); | 248 that.mock$setConnectionStatus(State.AUTHENTICATED); |
248 }).then(function() { | 249 }).then(function() { |
249 that.mock$setConnectionStatus(State.CONNECTED); | 250 that.mock$setConnectionStatus(State.CONNECTED); |
250 }); | 251 }); |
251 }; | 252 }; |
252 | 253 |
253 /** | 254 /** |
254 * @param {remoting.ClientSession.ConnectionError} error | 255 * @param {remoting.ClientSession.ConnectionError} error |
| 256 * @param {remoting.ChromotingEvent.AuthMethod=} opt_authMethod |
255 */ | 257 */ |
256 remoting.MockClientPlugin.prototype.mock$returnErrorOnConnect = function(error){ | 258 remoting.MockClientPlugin.prototype.mock$returnErrorOnConnect = |
| 259 function(error, opt_authMethod){ |
257 var that = this; | 260 var that = this; |
258 var State = remoting.ClientSession.State; | 261 var State = remoting.ClientSession.State; |
259 this.mock$onConnect().then(function() { | 262 this.mock$onConnect().then(function() { |
260 that.mock$setConnectionStatus(State.CONNECTING); | 263 that.mock$setConnectionStatus(State.CONNECTING); |
| 264 var authMethod = opt_authMethod ? opt_authMethod : |
| 265 remoting.ChromotingEvent.AuthMethod.PIN; |
| 266 return that.mock$authenticate(authMethod); |
261 }).then(function() { | 267 }).then(function() { |
262 that.mock$setConnectionStatus(State.FAILED, error); | 268 that.mock$setConnectionStatus(State.FAILED, error); |
263 }); | 269 }); |
264 }; | 270 }; |
265 | 271 |
266 /** | 272 /** |
267 * @constructor | 273 * @constructor |
268 * @implements {remoting.ClientPluginFactory} | 274 * @implements {remoting.ClientPluginFactory} |
269 */ | 275 */ |
270 remoting.MockClientPluginFactory = function() { | 276 remoting.MockClientPluginFactory = function() { |
(...skipping 16 matching lines...) Expand all Loading... |
287 function(container, capabilities) { | 293 function(container, capabilities) { |
288 this.plugin_ = new remoting.MockClientPlugin(); | 294 this.plugin_ = new remoting.MockClientPlugin(); |
289 this.plugin_.mock$setContainer(container); | 295 this.plugin_.mock$setContainer(container); |
290 this.plugin_.mock$capabilities = capabilities; | 296 this.plugin_.mock$capabilities = capabilities; |
291 | 297 |
292 // Notify the listeners on plugin creation. | 298 // Notify the listeners on plugin creation. |
293 if (Boolean(this.onPluginCreated_)) { | 299 if (Boolean(this.onPluginCreated_)) { |
294 this.onPluginCreated_(this.plugin_); | 300 this.onPluginCreated_(this.plugin_); |
295 } else { | 301 } else { |
296 this.plugin_.mock$useDefaultBehavior( | 302 this.plugin_.mock$useDefaultBehavior( |
297 remoting.MockClientPlugin.AuthMethod.PIN); | 303 remoting.ChromotingEvent.AuthMethod.PIN); |
298 } | 304 } |
299 | 305 |
300 // Listens for plugin status changed. | 306 // Listens for plugin status changed. |
301 if (this.onPluginStatusChanged_) { | 307 if (this.onPluginStatusChanged_) { |
302 this.plugin_.mock$setPluginStatusChanged(this.onPluginStatusChanged_); | 308 this.plugin_.mock$setPluginStatusChanged(this.onPluginStatusChanged_); |
303 } | 309 } |
304 return this.plugin_; | 310 return this.plugin_; |
305 }; | 311 }; |
306 | 312 |
307 /** | 313 /** |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 }; | 387 }; |
382 | 388 |
383 remoting.MockConnection.prototype.restore = function() { | 389 remoting.MockConnection.prototype.restore = function() { |
384 remoting.settings = this.originalSettings_; | 390 remoting.settings = this.originalSettings_; |
385 remoting.identity = this.originalIdentity_; | 391 remoting.identity = this.originalIdentity_; |
386 remoting.ClientPlugin.factory = this.originalPluginFactory_; | 392 remoting.ClientPlugin.factory = this.originalPluginFactory_; |
387 this.createSignalStrategyStub_.restore(); | 393 this.createSignalStrategyStub_.restore(); |
388 }; | 394 }; |
389 | 395 |
390 })(); | 396 })(); |
391 | |
392 /** @enum {string} */ | |
393 remoting.MockClientPlugin.AuthMethod = { | |
394 ACCESS_CODE: 'accessCode', | |
395 PIN: 'pin', | |
396 THIRD_PARTY: 'thirdParty', | |
397 PAIRING: 'pairing' | |
398 }; | |
OLD | NEW |