Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / remoting / webapp / crd / js / mock_client_plugin.js
blob68be5e161fbda229f763b2d36d157e836e8fde5b
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.
5 /**
6  * @fileoverview
7  * Mock implementation of ClientPlugin for testing.
8  */
10 /** @suppress {duplicate} */
11 var remoting = remoting || {};
13 (function() {
15 'use strict';
17 /**
18  * @constructor
19  * @implements {remoting.ClientPlugin}
20  */
21 remoting.MockClientPlugin = function() {
22   /** @private {Element} */
23   this.container_ = null;
24   /** @private */
25   this.element_ = /** @type {HTMLElement} */ (document.createElement('div'));
26   this.element_.style.backgroundImage = 'linear-gradient(45deg, blue, red)';
27   /** @private */
28   this.hostDesktop_ =
29       new remoting.ClientPlugin.HostDesktopImpl(this, base.doNothing);
30   /** @private */
31   this.extensions_ = new remoting.ProtocolExtensionManager(base.doNothing);
33   /** @private {remoting.CredentialsProvider} */
34   this.credentials_ = null;
36   /** @private {remoting.ClientPlugin.ConnectionEventHandler} */
37   this.connectionEventHandler_ = null;
39   // Fake initialization result to return.
40   this.mock$initializationResult = true;
42   // Fake capabilities to return.
43   this.mock$capabilities = [
44       remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION,
45       remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS
46   ];
48   /** @private */
49   this.onConnectDeferred_ = new base.Deferred();
52 remoting.MockClientPlugin.prototype.dispose = function() {
53   this.container_.removeChild(this.element_);
54   this.element_ = null;
55   this.connectionStatusUpdateHandler_ = null;
58 remoting.MockClientPlugin.prototype.extensions = function() {
59   return this.extensions_;
62 remoting.MockClientPlugin.prototype.hostDesktop = function() {
63   return this.hostDesktop_;
66 remoting.MockClientPlugin.prototype.element = function() {
67   return this.element_;
70 remoting.MockClientPlugin.prototype.initialize = function(onDone) {
71   var that = this;
72   Promise.resolve().then(function() {
73     onDone(that.mock$initializationResult);
74   });
78 remoting.MockClientPlugin.prototype.connect =
79     function(host, localJid, credentialsProvider) {
80   this.credentials_ = credentialsProvider;
81   this.onConnectDeferred_.resolve();
84 remoting.MockClientPlugin.prototype.injectKeyCombination = function(keys) {};
86 remoting.MockClientPlugin.prototype.injectKeyEvent =
87     function(key, down) {};
89 remoting.MockClientPlugin.prototype.setRemapKeys = function(remappings) {};
91 remoting.MockClientPlugin.prototype.remapKey = function(from, to) {};
93 remoting.MockClientPlugin.prototype.releaseAllKeys = function() {};
95 remoting.MockClientPlugin.prototype.onIncomingIq = function(iq) {};
97 remoting.MockClientPlugin.prototype.isSupportedVersion = function() {
98   return true;
101 remoting.MockClientPlugin.prototype.hasFeature = function(feature) {
102   return false;
105 remoting.MockClientPlugin.prototype.hasCapability = function(capability) {
106   return this.mock$capabilities.indexOf(capability) !== -1;
109 remoting.MockClientPlugin.prototype.sendClipboardItem =
110     function(mimeType, item) {};
112 remoting.MockClientPlugin.prototype.requestPairing =
113     function(clientName, onDone) {};
115 remoting.MockClientPlugin.prototype.allowMouseLock = function() {};
117 remoting.MockClientPlugin.prototype.pauseAudio = function(pause) {};
119 remoting.MockClientPlugin.prototype.pauseVideo = function(pause) {};
121 remoting.MockClientPlugin.prototype.getPerfStats = function() {
122   var result = new remoting.ClientSession.PerfStats;
123   result.videoBandwidth = 999;
124   result.videoFrameRate = 60;
125   result.captureLatency = 10;
126   result.encodeLatency = 10;
127   result.decodeLatency = 10;
128   result.renderLatency = 10;
129   result.roundtripLatency = 10;
130   return result;
133 remoting.MockClientPlugin.prototype.setConnectionEventHandler =
134     function(handler) {
135   this.connectionEventHandler_ = handler;
138 remoting.MockClientPlugin.prototype.setMouseCursorHandler =
139     function(handler) {};
141 remoting.MockClientPlugin.prototype.setClipboardHandler = function(handler) {};
143 remoting.MockClientPlugin.prototype.setDebugDirtyRegionHandler =
144     function(handler) {};
146 /** @param {Element} container */
147 remoting.MockClientPlugin.prototype.mock$setContainer = function(container) {
148   this.container_ = container;
149   this.container_.appendChild(this.element_);
152 /** @return {Promise} */
153 remoting.MockClientPlugin.prototype.mock$onConnect = function() {
154   this.onConnectDeferred_ = new base.Deferred();
155   return this.onConnectDeferred_.promise();
159  * @param {remoting.ClientSession.State} status
160  * @param {remoting.ClientSession.ConnectionError=} opt_error
161  */
162 remoting.MockClientPlugin.prototype.mock$setConnectionStatus = function(
163     status, opt_error) {
164   base.debug.assert(this.connectionEventHandler_ !== null);
165   var PluginError = remoting.ClientSession.ConnectionError;
166   var error = opt_error ? opt_error : PluginError.NONE;
167   this.connectionEventHandler_.onConnectionStatusUpdate(status, error);
171  * @param {remoting.MockClientPlugin.AuthMethod} authMethod
172  * @return {Promise}
173  */
174 remoting.MockClientPlugin.prototype.mock$authenticate = function(authMethod) {
175   var AuthMethod = remoting.MockClientPlugin.AuthMethod;
176   var deferred = new base.Deferred();
178   var that = this;
179   switch(authMethod) {
180     case AuthMethod.PIN:
181     case AuthMethod.ACCESS_CODE:
182       this.credentials_.getPIN(true).then(function() {
183         deferred.resolve();
184       });
185       break;
186     case AuthMethod.THIRD_PARTY:
187       this.credentials_.getThirdPartyToken(
188           'fake_token_url', 'fake_host_publicKey', 'fake_scope'
189       ).then(function() {
190         deferred.resolve();
191       });
192       break;
193     case AuthMethod.PAIRING:
194       deferred.resolve();
195   }
196   return deferred.promise();
200  * @param {remoting.MockClientPlugin.AuthMethod} authMethod
201  */
202 remoting.MockClientPlugin.prototype.mock$useDefaultBehavior =
203     function(authMethod) {
204   var that = this;
205   var State = remoting.ClientSession.State;
206   this.mock$onConnect().then(function() {
207     that.mock$setConnectionStatus(State.CONNECTING);
208     return that.mock$authenticate(authMethod);
209   }).then(function() {
210     that.mock$setConnectionStatus(State.CONNECTED);
211   });
215  * @constructor
216  * @implements {remoting.ClientPluginFactory}
217  */
218 remoting.MockClientPluginFactory = function() {
219   /** @private */
220   this.plugin_ = new remoting.MockClientPlugin();
223 remoting.MockClientPluginFactory.prototype.createPlugin =
224     function(container, capabilities) {
225   this.plugin_.mock$setContainer(container);
226   this.plugin_.mock$capabilities = capabilities;
227   return this.plugin_;
230 /** @return {remoting.MockClientPlugin} */
231 remoting.MockClientPluginFactory.prototype.plugin = function() {
232   return this.plugin_;
235 remoting.MockClientPluginFactory.prototype.preloadPlugin = function() {};
238  * A class that sets up all the dependencies required for mocking a connection.
240  * @constructor
241  */
242 remoting.MockConnection = function() {
243   /** @private */
244   this.originalPluginFactory_ = remoting.ClientPlugin.factory;
246   /** @private */
247   this.pluginFactory_ = new remoting.MockClientPluginFactory();
248   remoting.ClientPlugin.factory = this.pluginFactory_;
250   /** @private */
251   this.mockSignalStrategy_ = new remoting.MockSignalStrategy(
252       'fake_jid', remoting.SignalStrategy.Type.XMPP);
254   /** @private {sinon.TestStub} */
255   this.createSignalStrategyStub_ =
256       sinon.stub(remoting.SignalStrategy, 'create');
257   this.createSignalStrategyStub_.returns(this.mockSignalStrategy_);
259   /** @private */
260   this.originalIdentity_ = remoting.identity;
261   remoting.identity = new remoting.Identity();
262   var identityStub = sinon.stub(remoting.identity, 'getUserInfo');
263   identityStub.returns(Promise.resolve({email: 'email', userName: 'userName'}));
265   /** @private */
266   this.originalSettings_ = remoting.settings;
267   remoting.settings = new remoting.Settings();
270 /** @return {remoting.MockClientPlugin} */
271 remoting.MockConnection.prototype.plugin = function() {
272   return this.pluginFactory_.plugin();
275 /** @return {remoting.MockSignalStrategy} */
276 remoting.MockConnection.prototype.signalStrategy = function() {
277   return this.mockSignalStrategy_;
280 remoting.MockConnection.prototype.restore = function() {
281   remoting.settings = this.originalSettings_;
282   remoting.identity = this.originalIdentity_;
283   remoting.ClientPlugin.factory = this.originalPluginFactory_;
284   this.createSignalStrategyStub_.restore();
287 })();
289 /** @enum {string} */
290 remoting.MockClientPlugin.AuthMethod = {
291   ACCESS_CODE: 'accessCode',
292   PIN: 'pin',
293   THIRD_PARTY: 'thirdParty',
294   PAIRING: 'pairing'