summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorkelvinp <kelvinp@chromium.org>2015-04-22 19:24:07 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-23 02:25:13 +0000
commit2128aa35a6416b0f4683d07c8b6bb604eba87b94 (patch)
treee2bb238fcb4d84ef47bbbb56581c7fc3455f5a3f /remoting
parent11d7908b2ebbe965b9f4c73e47470f118439ff36 (diff)
downloadchromium_src-2128aa35a6416b0f4683d07c8b6bb604eba87b94.zip
chromium_src-2128aa35a6416b0f4683d07c8b6bb604eba87b94.tar.gz
chromium_src-2128aa35a6416b0f4683d07c8b6bb604eba87b94.tar.bz2
[Webapp Refactor] Implement Unittest for ClientSession.
Summary of changes: 1. Introduces a new class MockConnection for mocking the components required for a connection. 2. Implements unit tests for ClientSession. 3. Fixes bugs found by the unit tests. 4. Cleans up remoting.MockClientPlugin BUG=478331 Review URL: https://codereview.chromium.org/1095063003 Cr-Commit-Position: refs/heads/master@{#326427}
Diffstat (limited to 'remoting')
-rw-r--r--remoting/remoting_webapp_files.gypi1
-rw-r--r--remoting/webapp/crd/js/client_plugin_host_desktop_impl.js2
-rw-r--r--remoting/webapp/crd/js/client_session.js10
-rw-r--r--remoting/webapp/crd/js/client_session_factory_unittest.js85
-rw-r--r--remoting/webapp/crd/js/client_session_unittest.js177
-rw-r--r--remoting/webapp/crd/js/dns_blackhole_checker_unittest.js2
-rw-r--r--remoting/webapp/crd/js/mock_client_plugin.js166
-rw-r--r--remoting/webapp/crd/js/mock_signal_strategy.js9
-rw-r--r--remoting/webapp/files.gni1
9 files changed, 332 insertions, 121 deletions
diff --git a/remoting/remoting_webapp_files.gypi b/remoting/remoting_webapp_files.gypi
index c427474..2e98b04 100644
--- a/remoting/remoting_webapp_files.gypi
+++ b/remoting/remoting_webapp_files.gypi
@@ -72,6 +72,7 @@
'webapp/base/js/ipc_unittest.js',
'webapp/base/js/protocol_extension_manager_unittest.js',
'webapp/crd/js/apps_v2_migration_unittest.js',
+ 'webapp/crd/js/client_session_unittest.js',
'webapp/crd/js/desktop_viewport_unittest.js',
'webapp/crd/js/client_session_factory_unittest.js',
'webapp/crd/js/dns_blackhole_checker_unittest.js',
diff --git a/remoting/webapp/crd/js/client_plugin_host_desktop_impl.js b/remoting/webapp/crd/js/client_plugin_host_desktop_impl.js
index 74ba989..94ed9d2 100644
--- a/remoting/webapp/crd/js/client_plugin_host_desktop_impl.js
+++ b/remoting/webapp/crd/js/client_plugin_host_desktop_impl.js
@@ -15,7 +15,7 @@ remoting.ClientPlugin = remoting.ClientPlugin || {};
'use strict';
/**
- * @param {remoting.ClientPluginImpl} plugin
+ * @param {remoting.ClientPlugin} plugin
* @param {function(Object):void} postMessageCallback Callback to post a message
* to the Client Plugin.
*
diff --git a/remoting/webapp/crd/js/client_session.js b/remoting/webapp/crd/js/client_session.js
index 2737658..8a6bdb8 100644
--- a/remoting/webapp/crd/js/client_session.js
+++ b/remoting/webapp/crd/js/client_session.js
@@ -302,10 +302,6 @@ remoting.ClientSession.prototype.disconnect = function(error) {
var state = error.isNone() ?
remoting.ClientSession.State.CLOSED :
remoting.ClientSession.State.FAILED;
-
- // The plugin won't send a state change notification, so we explicitly log
- // the fact that the connection has closed.
- this.logToServer_.logClientSessionStateChange(state, error);
this.error_ = error;
this.setState_(state);
};
@@ -496,6 +492,7 @@ remoting.ClientSession.prototype.isFinished = function() {
var finishedStates = [
remoting.ClientSession.State.CLOSED,
remoting.ClientSession.State.FAILED,
+ remoting.ClientSession.State.CONNECTION_CANCELED,
remoting.ClientSession.State.CONNECTION_DROPPED
];
return finishedStates.indexOf(this.getState()) !== -1;
@@ -557,9 +554,12 @@ remoting.ClientSession.prototype.notifyStateChanges_ =
this.listener_.onDisconnected();
break;
+ case remoting.ClientSession.State.CONNECTION_CANCELED:
case remoting.ClientSession.State.FAILED:
error = this.getError();
- console.error('Connection failed: ' + error.toString());
+ if (!error.isNone()) {
+ console.error('Connection failed: ' + error.toString());
+ }
this.listener_.onConnectionFailed(error);
break;
diff --git a/remoting/webapp/crd/js/client_session_factory_unittest.js b/remoting/webapp/crd/js/client_session_factory_unittest.js
index f0e884c..819378c 100644
--- a/remoting/webapp/crd/js/client_session_factory_unittest.js
+++ b/remoting/webapp/crd/js/client_session_factory_unittest.js
@@ -6,18 +6,12 @@
'use strict';
-var originalPluginFactory;
-var originalIdentity;
-var originalSettings;
-
-/** @type {remoting.MockSignalStrategy} */
-var mockSignalStrategy;
+/** @type {remoting.MockConnection} */
+var mockConnection;
/** @type {remoting.ClientSessionFactory} */
var factory;
/** @type {remoting.ClientSession.EventHandler} */
var listener;
-/** @type {sinon.TestStub} */
-var createSignalStrategyStub;
/**
* @constructor
@@ -31,69 +25,70 @@ SessionListener.prototype.onError = function(error) {};
QUnit.module('ClientSessionFactory', {
beforeEach: function() {
- originalPluginFactory = remoting.ClientPlugin.factory;
- remoting.ClientPlugin.factory = new remoting.MockClientPluginFactory();
-
- mockSignalStrategy = new remoting.MockSignalStrategy(
- 'jid', remoting.SignalStrategy.Type.XMPP);
- createSignalStrategyStub = sinon.stub(remoting.SignalStrategy, 'create');
- createSignalStrategyStub.returns(mockSignalStrategy);
- listener = new SessionListener();
-
- originalIdentity = remoting.identity;
- remoting.identity = new remoting.Identity();
chromeMocks.activate(['identity']);
chromeMocks.identity.mock$setToken('fake_token');
- originalSettings = remoting.settings;
- remoting.settings = new remoting.Settings();
-
- remoting.identity.getUserInfo = function() {
- return { email: 'email', userName: 'userName'};
- };
-
+ mockConnection = new remoting.MockConnection();
+ listener = new SessionListener();
factory = new remoting.ClientSessionFactory(
- document.createElement('div'), ['fake_capability']);
+ document.createElement('div'),
+ [remoting.ClientSession.Capability.VIDEO_RECORDER]);
},
afterEach: function() {
- remoting.settings = originalSettings;
- remoting.identity = originalIdentity;
+ mockConnection.restore();
chromeMocks.restore();
- remoting.identity = null;
- remoting.ClientPlugin.factory = originalPluginFactory;
- createSignalStrategyStub.restore();
}
});
QUnit.test('createSession() should return a remoting.ClientSession',
function(assert) {
-
- mockSignalStrategy.connect = function() {
- mockSignalStrategy.setStateForTesting(
- remoting.SignalStrategy.State.CONNECTED);
- };
-
return factory.createSession(listener).then(
function(/** remoting.ClientSession */ session){
assert.ok(session instanceof remoting.ClientSession);
+ assert.ok(
+ mockConnection.plugin().hasCapability(
+ remoting.ClientSession.Capability.VIDEO_RECORDER),
+ 'Capability is set correctly.');
});
});
QUnit.test('createSession() should reject on signal strategy failure',
function(assert) {
-
+ var mockSignalStrategy = mockConnection.signalStrategy();
mockSignalStrategy.connect = function() {
- mockSignalStrategy.setStateForTesting(remoting.SignalStrategy.State.FAILED);
+ Promise.resolve().then(function () {
+ mockSignalStrategy.setStateForTesting(
+ remoting.SignalStrategy.State.FAILED);
+ });
};
- var signalStrategyDispose =
- /** @type {sinon.Spy} */ (sinon.spy(mockSignalStrategy, 'dispose'));
+ var signalStrategyDispose = sinon.stub(mockSignalStrategy, 'dispose');
return factory.createSession(listener).then(
- assert.ok.bind(assert, false, 'Expect createSession to fail')
+ assert.ok.bind(assert, false, 'Expect createSession() to fail.')
).catch(function(/** remoting.Error */ error) {
- assert.ok(signalStrategyDispose.called);
- assert.equal(error.getDetail(), 'setStateForTesting');
+ assert.ok(
+ signalStrategyDispose.called, 'SignalStrategy is disposed on failure.');
+ assert.equal(error.getDetail(), 'setStateForTesting',
+ 'Error message is set correctly.');
+ });
+});
+
+QUnit.test('createSession() should reject on plugin initialization failure',
+ function(assert) {
+ var mockSignalStrategy = mockConnection.signalStrategy();
+ var plugin = mockConnection.plugin();
+ plugin.mock$initializationResult = false;
+
+ var signalStrategyDispose = sinon.stub(mockSignalStrategy, 'dispose');
+
+ return factory.createSession(listener).then(function() {
+ assert.ok(false, 'Expect createSession() to fail.');
+ }).catch(function(/** remoting.Error */ error) {
+ assert.ok(
+ signalStrategyDispose.called, 'SignalStrategy is disposed on failure.');
+ assert.ok(error.hasTag(remoting.Error.Tag.MISSING_PLUGIN),
+ 'Initialization failed with MISSING_PLUGIN.');
});
});
diff --git a/remoting/webapp/crd/js/client_session_unittest.js b/remoting/webapp/crd/js/client_session_unittest.js
new file mode 100644
index 0000000..503b83d
--- /dev/null
+++ b/remoting/webapp/crd/js/client_session_unittest.js
@@ -0,0 +1,177 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+(function() {
+
+'use strict';
+
+/** @type {remoting.MockConnection} */
+var mockConnection;
+/** @type {remoting.ClientSession} */
+var session;
+/** @type {remoting.ClientSession.EventHandler} */
+var listener;
+/** @type {sinon.TestStub} */
+var logToServerStub;
+
+/**
+ * @constructor
+ * @implements {remoting.ClientSession.EventHandler}
+ */
+var SessionListener = function() {};
+SessionListener.prototype.onConnectionFailed = function(error) {};
+SessionListener.prototype.onConnected = function(connectionInfo) {};
+SessionListener.prototype.onDisconnected = function() {};
+SessionListener.prototype.onError = function(error) {};
+
+/**
+ * @param {remoting.ClientSession.ConnectionError=} opt_error
+ * @return {Promise}
+ */
+function connect(opt_error) {
+ var deferred = new base.Deferred();
+ var host = new remoting.Host('fake_hostId');
+ host.jabberId = 'fake_jid';
+
+ var plugin = mockConnection.plugin();
+ var State = remoting.ClientSession.State;
+
+ plugin.mock$onConnect().then(function() {
+ plugin.mock$setConnectionStatus(State.CONNECTING);
+ }).then(function() {
+ var status = (opt_error) ? State.FAILED : State.CONNECTED;
+ plugin.mock$setConnectionStatus(status, opt_error);
+ });
+
+ session.connect(host, new remoting.CredentialsProvider({
+ pairingInfo: { clientId: 'fake_clientId', sharedSecret: 'fake_secret' }
+ }));
+
+ listener.onConnected = function() {
+ deferred.resolve();
+ };
+
+ listener.onConnectionFailed = function(/** remoting.Error */ error) {
+ deferred.reject(error);
+ };
+
+ return deferred.promise();
+}
+
+QUnit.module('ClientSession', {
+ beforeEach: function() {
+ chromeMocks.activate(['identity']);
+ chromeMocks.identity.mock$setToken('fake_token');
+
+ mockConnection = new remoting.MockConnection();
+ listener = new SessionListener();
+
+ var sessionFactory = new remoting.ClientSessionFactory(
+ document.createElement('div'), ['fake_capability']);
+
+ return sessionFactory.createSession(listener).then(function(clientSession) {
+ session = clientSession;
+ logToServerStub =
+ sinon.stub(session.getLogger(), 'logClientSessionStateChange');
+ });
+ },
+ afterEach: function() {
+ session.dispose();
+ mockConnection.restore();
+ chromeMocks.restore();
+ }
+});
+
+QUnit.test('should raise CONNECTED event on connected', function(assert) {
+ return connect().then(function(){
+ assert.ok(true, 'Expect session to connect.');
+ });
+});
+
+QUnit.test('onOutgoingIq() should send Iq to signalStrategy', function(assert) {
+ var sendMessage = sinon.stub(mockConnection.signalStrategy(), 'sendMessage');
+ return connect().then(function(){
+ session.onOutgoingIq('sample message');
+ assert.ok(sendMessage.calledWith('sample message'));
+ });
+});
+
+QUnit.test('should foward Iq from signalStrategy to plugin', function(assert) {
+ var onIncomingIq = sinon.stub(mockConnection.plugin(), 'onIncomingIq');
+ return connect().then(function() {
+ var stanza = new DOMParser()
+ .parseFromString('<iq>sample</iq>', 'text/xml')
+ .firstElementChild;
+ mockConnection.signalStrategy().mock$onIncomingStanza(stanza);
+ assert.ok(onIncomingIq.calledWith('<iq>sample</iq>'));
+ });
+});
+
+QUnit.test('logHostOfflineErrors(false) should suppress offline errors',
+ function(assert) {
+
+ session.logHostOfflineErrors(false);
+
+ var PluginError = remoting.ClientSession.ConnectionError;
+ var State = remoting.ClientSession.State;
+
+ return connect(PluginError.HOST_IS_OFFLINE).then(function() {
+ assert.ok(false, 'Expect connection to fail');
+ }).catch(function(/** remoting.Error */ error) {
+ assert.ok(error.hasTag(remoting.Error.Tag.HOST_IS_OFFLINE));
+ assert.equal(logToServerStub.args[1][0], State.CONNECTION_CANCELED);
+ var errorLogged = /** @type {remoting.Error} */(logToServerStub.args[1][1]);
+ assert.equal(errorLogged.getTag(), remoting.Error.Tag.HOST_IS_OFFLINE);
+
+ });
+});
+
+QUnit.test('disconnect() should raise the CLOSED event', function(assert) {
+ return connect().then(function() {
+ var onDisconnected = sinon.stub(listener, 'onDisconnected');
+ session.disconnect(remoting.Error.none());
+ assert.equal(onDisconnected.callCount, 1);
+ });
+});
+
+QUnit.test(
+ 'Connection error after CONNECTED should raise the CONNECTION_DROPPED event',
+ function(assert) {
+
+ var State = remoting.ClientSession.State;
+
+ return connect().then(function() {
+ var onError = sinon.stub(listener, 'onError');
+ session.disconnect(new remoting.Error(remoting.Error.Tag.P2P_FAILURE));
+ assert.equal(onError.callCount, 1);
+ assert.equal(logToServerStub.args[2][0], State.CONNECTION_DROPPED);
+ });
+});
+
+QUnit.test(
+ 'Connection error before CONNECTED should raise the CONNECTION_FAILED event',
+ function(assert) {
+
+ session.logHostOfflineErrors(true);
+
+ var PluginError = remoting.ClientSession.ConnectionError;
+ var State = remoting.ClientSession.State;
+
+ return connect(PluginError.SESSION_REJECTED).then(function() {
+ assert.ok(false, 'Expect connection to fail');
+ }).catch(function(/** remoting.Error */ error) {
+ assert.ok(error.hasTag(remoting.Error.Tag.INVALID_ACCESS_CODE));
+ assert.equal(logToServerStub.args[1][0], State.FAILED);
+ var errorLogged = /** @type {remoting.Error} */(logToServerStub.args[1][1]);
+ assert.equal(errorLogged.getTag(), remoting.Error.Tag.INVALID_ACCESS_CODE);
+ });
+});
+
+QUnit.test('dispose() should dispose the plugin', function(assert) {
+ var pluginDispose = sinon.stub(mockConnection.plugin(), 'dispose');
+ session.dispose();
+ assert.equal(pluginDispose.callCount, 1);
+});
+
+})();
diff --git a/remoting/webapp/crd/js/dns_blackhole_checker_unittest.js b/remoting/webapp/crd/js/dns_blackhole_checker_unittest.js
index 601157b..46abdd4 100644
--- a/remoting/webapp/crd/js/dns_blackhole_checker_unittest.js
+++ b/remoting/webapp/crd/js/dns_blackhole_checker_unittest.js
@@ -37,7 +37,7 @@ QUnit.module('dns_blackhole_checker', {
onStateChange = sinon.spy();
onIncomingStanzaCallback = sinon.spy();
signalStrategy = new remoting.MockSignalStrategy();
- sinon.spy(signalStrategy, 'connect');
+ sinon.stub(signalStrategy, 'connect', base.doNothing);
checker = new remoting.DnsBlackholeChecker(signalStrategy);
checker.setStateChangedCallback(onStateChange);
diff --git a/remoting/webapp/crd/js/mock_client_plugin.js b/remoting/webapp/crd/js/mock_client_plugin.js
index 6980147..1f2ba5c 100644
--- a/remoting/webapp/crd/js/mock_client_plugin.js
+++ b/remoting/webapp/crd/js/mock_client_plugin.js
@@ -7,25 +7,30 @@
* Mock implementation of ClientPlugin for testing.
*/
-'use strict';
-
/** @suppress {duplicate} */
var remoting = remoting || {};
+(function() {
+
+'use strict';
+
/**
- * @param {Element} container
* @constructor
* @implements {remoting.ClientPlugin}
*/
-remoting.MockClientPlugin = function(container) {
- this.container_ = container;
+remoting.MockClientPlugin = function() {
+ /** @private {Element} */
+ this.container_ = null;
+ /** @private */
this.element_ = /** @type {HTMLElement} */ (document.createElement('div'));
this.element_.style.backgroundImage = 'linear-gradient(45deg, blue, red)';
- this.container_.appendChild(this.element_);
- this.hostDesktop_ = new remoting.MockClientPlugin.HostDesktop();
+ /** @private */
+ this.hostDesktop_ =
+ new remoting.ClientPlugin.HostDesktopImpl(this, base.doNothing);
+ /** @private */
this.extensions_ = new remoting.ProtocolExtensionManager(base.doNothing);
- /** @type {remoting.ClientPlugin.ConnectionEventHandler} */
- this.connectionEventHandler = null;
+ /** @private {remoting.ClientPlugin.ConnectionEventHandler} */
+ this.connectionEventHandler_ = null;
// Fake initialization result to return.
this.mock$initializationResult = true;
@@ -35,6 +40,9 @@ remoting.MockClientPlugin = function(container) {
remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION,
remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS
];
+
+ /** @private */
+ this.onConnectDeferred_ = new base.Deferred();
};
remoting.MockClientPlugin.prototype.dispose = function() {
@@ -65,13 +73,7 @@ remoting.MockClientPlugin.prototype.initialize = function(onDone) {
remoting.MockClientPlugin.prototype.connect =
function(host, localJid, credentialsProvider) {
- base.debug.assert(this.connectionEventHandler !== null);
- var that = this;
- window.requestAnimationFrame(function() {
- that.connectionEventHandler.onConnectionStatusUpdate(
- remoting.ClientSession.State.CONNECTED,
- remoting.ClientSession.ConnectionError.NONE);
- });
+ this.onConnectDeferred_.resolve();
};
remoting.MockClientPlugin.prototype.injectKeyCombination = function(keys) {};
@@ -125,7 +127,7 @@ remoting.MockClientPlugin.prototype.getPerfStats = function() {
remoting.MockClientPlugin.prototype.setConnectionEventHandler =
function(handler) {
- this.connetionEventHandler = handler;
+ this.connectionEventHandler_ = handler;
};
remoting.MockClientPlugin.prototype.setMouseCursorHandler =
@@ -136,60 +138,28 @@ remoting.MockClientPlugin.prototype.setClipboardHandler = function(handler) {};
remoting.MockClientPlugin.prototype.setDebugDirtyRegionHandler =
function(handler) {};
-/**
- * @constructor
- * @implements {remoting.HostDesktop}
- * @extends {base.EventSourceImpl}
- */
-remoting.MockClientPlugin.HostDesktop = function() {
- base.inherits(this, base.EventSourceImpl);
- /** @private */
- this.width_ = 0;
- /** @private */
- this.height_ = 0;
- /** @private */
- this.xDpi_ = 96;
- /** @private */
- this.yDpi_ = 96;
- /** @private */
- this.resizable_ = true;
- this.defineEvents(base.values(remoting.HostDesktop.Events));
-};
-
-/**
- * @return {{width:number, height:number, xDpi:number, yDpi:number}}
- * @override
- */
-remoting.MockClientPlugin.HostDesktop.prototype.getDimensions = function() {
- return {
- width: this.width_,
- height: this.height_,
- xDpi: this.xDpi_,
- yDpi: this.yDpi_
- };
+/** @param {Element} container */
+remoting.MockClientPlugin.prototype.mock$setContainer = function(container) {
+ this.container_ = container;
+ this.container_.appendChild(this.element_);
};
-/**
- * @return {boolean}
- * @override
- */
-remoting.MockClientPlugin.HostDesktop.prototype.isResizable = function() {
- return this.resizable_;
+/** @return {Promise} */
+remoting.MockClientPlugin.prototype.mock$onConnect = function() {
+ this.onConnectDeferred_ = new base.Deferred();
+ return this.onConnectDeferred_.promise();
};
/**
- * @param {number} width
- * @param {number} height
- * @param {number} deviceScale
- * @override
+ * @param {remoting.ClientSession.State} status
+ * @param {remoting.ClientSession.ConnectionError=} opt_error
*/
-remoting.MockClientPlugin.HostDesktop.prototype.resize =
- function(width, height, deviceScale) {
- this.width_ = width;
- this.height_ = height;
- this.xDpi_ = this.yDpi_ = Math.floor(deviceScale * 96);
- this.raiseEvent(remoting.HostDesktop.Events.sizeChanged,
- this.getDimensions());
+remoting.MockClientPlugin.prototype.mock$setConnectionStatus = function(
+ status, opt_error) {
+ base.debug.assert(this.connectionEventHandler_ !== null);
+ var PluginError = remoting.ClientSession.ConnectionError;
+ var error = opt_error ? opt_error : PluginError.NONE;
+ this.connectionEventHandler_.onConnectionStatusUpdate(status, error);
};
/**
@@ -197,14 +167,72 @@ remoting.MockClientPlugin.HostDesktop.prototype.resize =
* @implements {remoting.ClientPluginFactory}
*/
remoting.MockClientPluginFactory = function() {
- /** @private {remoting.MockClientPlugin} */
- this.plugin_ = null;
+ /** @private */
+ this.plugin_ = new remoting.MockClientPlugin();
};
remoting.MockClientPluginFactory.prototype.createPlugin =
- function(container, onExtensionMessage) {
- this.plugin_ = new remoting.MockClientPlugin(container);
+ function(container, capabilities) {
+ this.plugin_.mock$setContainer(container);
+ this.plugin_.mock$capabilities = capabilities;
+ return this.plugin_;
+};
+
+/** @return {remoting.MockClientPlugin} */
+remoting.MockClientPluginFactory.prototype.plugin = function() {
return this.plugin_;
};
remoting.MockClientPluginFactory.prototype.preloadPlugin = function() {};
+
+/**
+ * A class that sets up all the dependencies required for mocking a connection.
+ *
+ * @constructor
+ */
+remoting.MockConnection = function() {
+ /** @private */
+ this.originalPluginFactory_ = remoting.ClientPlugin.factory;
+
+ /** @private */
+ this.pluginFactory_ = new remoting.MockClientPluginFactory();
+ remoting.ClientPlugin.factory = this.pluginFactory_;
+
+ /** @private */
+ this.mockSignalStrategy_ = new remoting.MockSignalStrategy(
+ 'fake_jid', remoting.SignalStrategy.Type.XMPP);
+
+ /** @private {sinon.TestStub} */
+ this.createSignalStrategyStub_ =
+ sinon.stub(remoting.SignalStrategy, 'create');
+ this.createSignalStrategyStub_.returns(this.mockSignalStrategy_);
+
+ /** @private */
+ this.originalIdentity_ = remoting.identity;
+ remoting.identity = new remoting.Identity();
+ var identityStub = sinon.stub(remoting.identity, 'getUserInfo');
+ identityStub.returns(Promise.resolve({email: 'email', userName: 'userName'}));
+
+ /** @private */
+ this.originalSettings_ = remoting.settings;
+ remoting.settings = new remoting.Settings();
+};
+
+/** @return {remoting.MockClientPlugin} */
+remoting.MockConnection.prototype.plugin = function() {
+ return this.pluginFactory_.plugin();
+};
+
+/** @return {remoting.MockSignalStrategy} */
+remoting.MockConnection.prototype.signalStrategy = function() {
+ return this.mockSignalStrategy_;
+};
+
+remoting.MockConnection.prototype.restore = function() {
+ remoting.settings = this.originalSettings_;
+ remoting.identity = this.originalIdentity_;
+ remoting.ClientPlugin.factory = this.originalPluginFactory_;
+ this.createSignalStrategyStub_.restore();
+};
+
+})(); \ No newline at end of file
diff --git a/remoting/webapp/crd/js/mock_signal_strategy.js b/remoting/webapp/crd/js/mock_signal_strategy.js
index 56b41c0..8fee7ad 100644
--- a/remoting/webapp/crd/js/mock_signal_strategy.js
+++ b/remoting/webapp/crd/js/mock_signal_strategy.js
@@ -35,6 +35,10 @@ remoting.MockSignalStrategy.prototype.dispose = function() {
/** @override */
remoting.MockSignalStrategy.prototype.connect = function() {
+ var that = this;
+ Promise.resolve().then(function() {
+ that.setStateForTesting(remoting.SignalStrategy.State.CONNECTED);
+ });
};
/** @override */
@@ -65,6 +69,11 @@ remoting.MockSignalStrategy.prototype.setIncomingStanzaCallback =
: function() {};
};
+/** @param {Element} stanza */
+remoting.MockSignalStrategy.prototype.mock$onIncomingStanza = function(stanza) {
+ this.onIncomingStanzaCallback_(stanza);
+};
+
/** @return {remoting.SignalStrategy.State} */
remoting.MockSignalStrategy.prototype.getState = function() {
return this.state_;
diff --git a/remoting/webapp/files.gni b/remoting/webapp/files.gni
index 895ad5a..1a006c0 100644
--- a/remoting/webapp/files.gni
+++ b/remoting/webapp/files.gni
@@ -72,6 +72,7 @@ remoting_webapp_unittests_js_files = [
"base/js/ipc_unittest.js",
"base/js/protocol_extension_manager_unittest.js",
"crd/js/apps_v2_migration_unittest.js",
+ "crd/js/client_session_unittest.js",
"crd/js/desktop_viewport_unittest.js",
"crd/js/dns_blackhole_checker_unittest.js",
"crd/js/error_unittest.js",