1 // Copyright 2015 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.
9 /** @type {remoting.MockConnection} */
11 /** @type {remoting.ClientSessionFactory} */
13 /** @type {remoting.ClientSession.EventHandler} */
15 /** @type {remoting.SessionLogger} */
20 * @implements {remoting.ClientSession.EventHandler}
22 var SessionListener = function() {};
23 SessionListener.prototype.onConnectionFailed = function(error) {};
24 SessionListener.prototype.onConnected = function(connectionInfo) {};
25 SessionListener.prototype.onDisconnected = function(reason) {};
26 SessionListener.prototype.onError = function(error) {};
28 QUnit.module('ClientSessionFactory', {
29 beforeEach: function() {
30 chromeMocks.identity.mock$setToken('fake_token');
32 mockConnection = new remoting.MockConnection();
33 listener = new SessionListener();
34 logger = new remoting.SessionLogger(remoting.ChromotingEvent.Role.CLIENT,
36 factory = new remoting.ClientSessionFactory(
37 document.createElement('div'),
38 [remoting.ClientSession.Capability.VIDEO_RECORDER]);
40 afterEach: function() {
41 mockConnection.restore();
45 QUnit.test('createSession() should return a remoting.ClientSession',
47 return factory.createSession(listener, logger).then(
48 function(/** remoting.ClientSession */ session){
49 assert.ok(session instanceof remoting.ClientSession);
51 mockConnection.plugin().hasCapability(
52 remoting.ClientSession.Capability.VIDEO_RECORDER),
53 'Capability is set correctly.');
57 QUnit.test('createSession() should reject on signal strategy failure',
59 var mockSignalStrategy = mockConnection.signalStrategy();
60 mockSignalStrategy.connect = function() {
61 Promise.resolve().then(function () {
62 mockSignalStrategy.setStateForTesting(
63 remoting.SignalStrategy.State.FAILED);
67 var signalStrategyDispose = sinon.stub(mockSignalStrategy, 'dispose');
69 return factory.createSession(listener, logger).then(
70 assert.ok.bind(assert, false, 'Expect createSession() to fail.')
71 ).catch(function(/** remoting.Error */ error) {
73 signalStrategyDispose.called, 'SignalStrategy is disposed on failure.');
74 assert.equal(error.getDetail(), 'setStateForTesting',
75 'Error message is set correctly.');
79 QUnit.test('createSession() should reject on plugin initialization failure',
81 var mockSignalStrategy = mockConnection.signalStrategy();
82 function onPluginCreated(/** remoting.MockClientPlugin */ plugin) {
83 plugin.mock$initializationResult = false;
85 mockConnection.pluginFactory().mock$setPluginCreated(onPluginCreated);
87 var signalStrategyDispose = sinon.stub(mockSignalStrategy, 'dispose');
89 return factory.createSession(listener, logger).then(function() {
90 assert.ok(false, 'Expect createSession() to fail.');
91 }).catch(function(/** remoting.Error */ error) {
93 signalStrategyDispose.called, 'SignalStrategy is disposed on failure.');
94 assert.ok(error.hasTag(remoting.Error.Tag.MISSING_PLUGIN),
95 'Initialization failed with MISSING_PLUGIN.');