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} */
18 * @implements {remoting.ClientSession.EventHandler}
20 var SessionListener = function() {};
21 SessionListener.prototype.onConnectionFailed = function(error) {};
22 SessionListener.prototype.onConnected = function(connectionInfo) {};
23 SessionListener.prototype.onDisconnected = function(reason) {};
24 SessionListener.prototype.onError = function(error) {};
26 QUnit.module('ClientSessionFactory', {
27 beforeEach: function() {
28 chromeMocks.identity.mock$setToken('fake_token');
30 mockConnection = new remoting.MockConnection();
31 listener = new SessionListener();
32 factory = new remoting.ClientSessionFactory(
33 document.createElement('div'),
34 [remoting.ClientSession.Capability.VIDEO_RECORDER]);
36 afterEach: function() {
37 mockConnection.restore();
41 QUnit.test('createSession() should return a remoting.ClientSession',
43 return factory.createSession(listener).then(
44 function(/** remoting.ClientSession */ session){
45 assert.ok(session instanceof remoting.ClientSession);
47 mockConnection.plugin().hasCapability(
48 remoting.ClientSession.Capability.VIDEO_RECORDER),
49 'Capability is set correctly.');
53 QUnit.test('createSession() should reject on signal strategy failure',
55 var mockSignalStrategy = mockConnection.signalStrategy();
56 mockSignalStrategy.connect = function() {
57 Promise.resolve().then(function () {
58 mockSignalStrategy.setStateForTesting(
59 remoting.SignalStrategy.State.FAILED);
63 var signalStrategyDispose = sinon.stub(mockSignalStrategy, 'dispose');
65 return factory.createSession(listener).then(
66 assert.ok.bind(assert, false, 'Expect createSession() to fail.')
67 ).catch(function(/** remoting.Error */ error) {
69 signalStrategyDispose.called, 'SignalStrategy is disposed on failure.');
70 assert.equal(error.getDetail(), 'setStateForTesting',
71 'Error message is set correctly.');
75 QUnit.test('createSession() should reject on plugin initialization failure',
77 var mockSignalStrategy = mockConnection.signalStrategy();
78 var plugin = mockConnection.plugin();
79 plugin.mock$initializationResult = false;
81 var signalStrategyDispose = sinon.stub(mockSignalStrategy, 'dispose');
83 return factory.createSession(listener).then(function() {
84 assert.ok(false, 'Expect createSession() to fail.');
85 }).catch(function(/** remoting.Error */ error) {
87 signalStrategyDispose.called, 'SignalStrategy is disposed on failure.');
88 assert.ok(error.hasTag(remoting.Error.Tag.MISSING_PLUGIN),
89 'Initialization failed with MISSING_PLUGIN.');