Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: remoting/webapp/browser_test/mock_session_connector.js

Issue 927373005: [Chromoting] Enable jscompile for browser tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update all_browsertest var in gyp comment Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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() { 104 /**
80 this.pairingRequested_ = true; 105 * @suppress {reportUnknownTypes} Required by onStateChange.
Jamie 2015/02/18 00:51:33 Can you expand on why onStateChange needs this? Al
garykac 2015/02/18 02:06:49 I removed the bind() on onStateChange and switched
81 }; 106 */
82
83 remoting.MockSessionConnector.prototype.pairingRequested = function() {
84 return this.pairingRequested_;
85 };
86
87 remoting.MockSessionConnector.prototype.connect_ = function() { 107 remoting.MockSessionConnector.prototype.connect_ = function() {
88 var signalling = new remoting.MockSignalStrategy(); 108 var signalling = new remoting.MockSignalStrategy();
89 signalling.setStateForTesting(remoting.SignalStrategy.State.CONNECTED); 109 signalling.setStateForTesting(remoting.SignalStrategy.State.CONNECTED);
90 var hostName = 'Mock host'; 110 var hostName = 'Mock host';
91 var accessCode = ''; 111 var accessCode = '';
92 var authenticationMethods = ''; 112 var authenticationMethods = '';
93 var hostId = ''; 113 var hostId = '';
94 var hostJid = ''; 114 var hostJid = '';
95 var hostPublicKey = ''; 115 var hostPublicKey = '';
96 var clientPairingId = ''; 116 var clientPairingId = '';
97 var clientPairedSecret = ''; 117 var clientPairedSecret = '';
118
119 /**
120 * @param {boolean} offerPairing
121 * @param {function(string):void} callback
122 */
98 var fetchPin = function(offerPairing, callback) { 123 var fetchPin = function(offerPairing, callback) {
99 window.setTimeout(function() { callback('') }, 0); 124 window.setTimeout(function() { callback('') }, 0);
100 }; 125 };
101 var fetchThirdPartyToken = function(tokenUrl, scope, callback) { 126
127 /**
128 * @param {string} tokenUrl
129 * @param {string} hostPublicKey
130 * @param {string} scope
131 * @param {function(string, string):void} callback
132 */
133 var fetchThirdPartyToken = function(tokenUrl, hostPublicKey, scope,
134 callback) {
102 window.setTimeout(function() { callback('', '') }, 0); 135 window.setTimeout(function() { callback('', '') }, 0);
103 }; 136 };
104 137
105 var clientSession = new remoting.ClientSession( 138 var clientSession = new remoting.ClientSession(
106 signalling, this.clientContainer_, hostName, 139 signalling, this.clientContainer_, hostName,
107 accessCode, fetchPin, fetchThirdPartyToken, 140 accessCode, fetchPin, fetchThirdPartyToken,
108 authenticationMethods, hostId, hostJid, hostPublicKey, 141 authenticationMethods, hostId, hostJid, hostPublicKey,
109 this.mode_, clientPairingId, clientPairedSecret); 142 this.mode_, clientPairingId, clientPairedSecret);
110 143
144 /**
145 * @param {remoting.ClientSession.StateEvent} event
146 */
111 var onStateChange = function(event) { 147 var onStateChange = function(event) {
112 if (event.current == remoting.ClientSession.State.CONNECTED) { 148 if (event.current == remoting.ClientSession.State.CONNECTED) {
113 this.onConnected_(clientSession); 149 this.onConnected_(clientSession);
114 } 150 }
115 }.bind(this); 151 }.bind(this);
116 152
117 clientSession.addEventListener( 153 clientSession.addEventListener(
118 remoting.ClientSession.Events.stateChanged, 154 remoting.ClientSession.Events.stateChanged,
119 onStateChange); 155 onStateChange);
120 clientSession.createPluginAndConnect(this.onExtensionMessage_); 156 clientSession.createPluginAndConnect(this.onExtensionMessage_);
121 }; 157 };
122 158
123 159
124 /** 160 /**
125 * @constructor 161 * @constructor
126 * @extends {remoting.SessionConnectorFactory} 162 * @extends {remoting.SessionConnectorFactory}
127 */ 163 */
128 remoting.MockSessionConnectorFactory = function() {}; 164 remoting.MockSessionConnectorFactory = function() {};
129 165
166 /**
167 * @param {HTMLElement} clientContainer Container element for the client view.
168 * @param {function(remoting.ClientSession):void} onConnected Callback on
169 * success.
170 * @param {function(remoting.Error):void} onError Callback on error.
171 * @param {function(string, string):boolean} onExtensionMessage The handler for
172 * protocol extension messages. Returns true if a message is recognized;
173 * false otherwise.
174 * @param {function(remoting.Error):void} onConnectionFailed Callback for when
175 * the connection fails.
176 * @param {Array.<string>} requiredCapabilities Connector capabilities
177 * required by this application.
178 * @param {string} defaultRemapKeys The default set of key mappings to use
179 * in the client session.
180 * @return {remoting.MockSessionConnector}
181 */
130 remoting.MockSessionConnectorFactory.prototype.createConnector = 182 remoting.MockSessionConnectorFactory.prototype.createConnector =
131 function(clientContainer, onConnected, onError, onExtensionMessage) { 183 function(clientContainer, onConnected, onError, onExtensionMessage,
184 onConnectionFailed, requiredCapabilities, defaultRemapKeys) {
132 return new remoting.MockSessionConnector( 185 return new remoting.MockSessionConnector(
133 clientContainer, onConnected, onError, onExtensionMessage); 186 clientContainer, onConnected, onError, onExtensionMessage,
187 onConnectionFailed, requiredCapabilities, defaultRemapKeys);
134 }; 188 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698