Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / remoting / webapp / base / js / client_session_factory_unittest.js
blobcd53d1cdc07668e66f4d74033195853fa4bac61f
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.
5 (function() {
7 'use strict';
9 /** @type {remoting.MockConnection} */
10 var mockConnection;
11 /** @type {remoting.ClientSessionFactory} */
12 var factory;
13 /** @type {remoting.ClientSession.EventHandler} */
14 var listener;
15 /** @type {remoting.SessionLogger} */
16 var logger;
18 /**
19 * @constructor
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,
35 base.doNothing);
36 factory = new remoting.ClientSessionFactory(
37 document.createElement('div'),
38 [remoting.ClientSession.Capability.VIDEO_RECORDER]);
40 afterEach: function() {
41 mockConnection.restore();
43 });
45 QUnit.test('createSession() should return a remoting.ClientSession',
46 function(assert) {
47 return factory.createSession(listener, logger).then(
48 function(/** remoting.ClientSession */ session){
49 assert.ok(session instanceof remoting.ClientSession);
50 assert.ok(
51 mockConnection.plugin().hasCapability(
52 remoting.ClientSession.Capability.VIDEO_RECORDER),
53 'Capability is set correctly.');
54 });
55 });
57 QUnit.test('createSession() should reject on signal strategy failure',
58 function(assert) {
59 var mockSignalStrategy = mockConnection.signalStrategy();
60 mockSignalStrategy.connect = function() {
61 Promise.resolve().then(function () {
62 mockSignalStrategy.setStateForTesting(
63 remoting.SignalStrategy.State.FAILED);
64 });
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) {
72 assert.ok(
73 signalStrategyDispose.called, 'SignalStrategy is disposed on failure.');
74 assert.equal(error.getDetail(), 'setStateForTesting',
75 'Error message is set correctly.');
76 });
77 });
79 QUnit.test('createSession() should reject on plugin initialization failure',
80 function(assert) {
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) {
92 assert.ok(
93 signalStrategyDispose.called, 'SignalStrategy is disposed on failure.');
94 assert.ok(error.hasTag(remoting.Error.Tag.MISSING_PLUGIN),
95 'Initialization failed with MISSING_PLUGIN.');
96 });
97 });
99 })();