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 * @constructor |
| 18 * @implements {remoting.SessionConnector} |
| 19 */ |
| 20 remoting.MockSessionConnector = function(clientContainer, onConnected, onError, |
| 21 onExtensionMessage) { |
| 22 this.clientContainer_ = clientContainer; |
| 23 this.onConnected_ = onConnected; |
| 24 this.onError = onError; |
| 25 this.onExtensionMessage_ = onExtensionMessage; |
| 26 this.reset(); |
| 27 }; |
| 28 |
| 29 remoting.MockSessionConnector.prototype.reset = function() { |
| 30 this.pairingRequested_ = false; |
| 31 }; |
| 32 |
| 33 remoting.MockSessionConnector.prototype.connectMe2Me = |
| 34 function(host, fetchPin, fetchThirdPartyToken, |
| 35 clientPairingId, clientPairedSecret) { |
| 36 this.mode_ = remoting.ClientSession.Mode.ME2ME; |
| 37 this.connect_(); |
| 38 }; |
| 39 |
| 40 remoting.MockSessionConnector.prototype.updatePairingInfo = |
| 41 function(clientId, sharedSecret) { |
| 42 }; |
| 43 |
| 44 remoting.MockSessionConnector.prototype.connectIT2Me = |
| 45 function(accessCode) { |
| 46 this.mode_ = remoting.ClientSession.Mode.ME2ME; |
| 47 this.connect_(); |
| 48 }; |
| 49 |
| 50 remoting.MockSessionConnector.prototype.reconnect = function() { |
| 51 base.debug.assert(this.mode_ == remoting.ClientSession.Mode.ME2ME); |
| 52 this.connect_(); |
| 53 }; |
| 54 |
| 55 remoting.MockSessionConnector.prototype.cancel = function() { |
| 56 }; |
| 57 |
| 58 remoting.MockSessionConnector.prototype.getConnectionMode = function() { |
| 59 return this.mode_; |
| 60 }; |
| 61 |
| 62 remoting.MockSessionConnector.prototype.getHostId = function() { |
| 63 return this.hostId_; |
| 64 }; |
| 65 |
| 66 remoting.MockSessionConnector.prototype.requestPairing = function() { |
| 67 this.pairingRequested_ = true; |
| 68 }; |
| 69 |
| 70 remoting.MockSessionConnector.prototype.pairingRequested = function() { |
| 71 return this.pairingRequested_; |
| 72 }; |
| 73 |
| 74 remoting.MockSessionConnector.prototype.connect_ = function() { |
| 75 var signalling = new remoting.MockSignalStrategy(); |
| 76 var hostName = 'Mock host'; |
| 77 var accessCode = ''; |
| 78 var authenticationMethods = ''; |
| 79 var hostId = ''; |
| 80 var hostJid = ''; |
| 81 var hostPublicKey = ''; |
| 82 var clientPairingId = ''; |
| 83 var clientPairedSecret = ''; |
| 84 var fetchPin = function(offerPairing, callback) { |
| 85 window.setTimeout(function() { callback('') }, 0); |
| 86 }; |
| 87 var fetchThirdPartyToken = function(tokenUrl, scope, callback) { |
| 88 window.setTimeout(function() { callback('', '') }, 0); |
| 89 }; |
| 90 |
| 91 var clientSession = new remoting.ClientSession( |
| 92 signalling, this.clientContainer_, hostName, |
| 93 accessCode, fetchPin, fetchThirdPartyToken, |
| 94 authenticationMethods, hostId, hostJid, hostPublicKey, |
| 95 this.mode_, clientPairingId, clientPairedSecret); |
| 96 |
| 97 var onStateChange = function(event) { |
| 98 if (event.current == remoting.ClientSession.State.CONNECTED) { |
| 99 this.onConnected_(clientSession); |
| 100 } |
| 101 }.bind(this); |
| 102 |
| 103 clientSession.addEventListener( |
| 104 remoting.ClientSession.Events.stateChanged, |
| 105 onStateChange); |
| 106 clientSession.createPluginAndConnect(this.onExtensionMessage_); |
| 107 }; |
| 108 |
| 109 |
| 110 /** |
| 111 * @constructor |
| 112 * @extends {remoting.SessionConnectorFactory} |
| 113 */ |
| 114 remoting.MockSessionConnectorFactory = function() {}; |
| 115 |
| 116 remoting.MockSessionConnectorFactory.prototype.createConnector = |
| 117 function(clientContainer, onConnected, onError, onExtensionMessage) { |
| 118 return new remoting.MockSessionConnector( |
| 119 clientContainer, onConnected, onError, onExtensionMessage); |
| 120 }; |
OLD | NEW |