Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / remoting / webapp / base / js / client_session_factory_unittest.js
blob1a42fb2afa25ab74d7d2ef794b67fe4cbfcc9b3b
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;
16 /**
17  * @constructor
18  * @implements {remoting.ClientSession.EventHandler}
19  */
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]);
35   },
36   afterEach: function() {
37     mockConnection.restore();
38   }
39 });
41 QUnit.test('createSession() should return a remoting.ClientSession',
42     function(assert) {
43   return factory.createSession(listener).then(
44     function(/** remoting.ClientSession */ session){
45       assert.ok(session instanceof remoting.ClientSession);
46       assert.ok(
47           mockConnection.plugin().hasCapability(
48               remoting.ClientSession.Capability.VIDEO_RECORDER),
49           'Capability is set correctly.');
50   });
51 });
53 QUnit.test('createSession() should reject on signal strategy failure',
54     function(assert) {
55   var mockSignalStrategy = mockConnection.signalStrategy();
56   mockSignalStrategy.connect = function() {
57     Promise.resolve().then(function () {
58       mockSignalStrategy.setStateForTesting(
59           remoting.SignalStrategy.State.FAILED);
60     });
61   };
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) {
68     assert.ok(
69         signalStrategyDispose.called, 'SignalStrategy is disposed on failure.');
70     assert.equal(error.getDetail(), 'setStateForTesting',
71                  'Error message is set correctly.');
72   });
73 });
75 QUnit.test('createSession() should reject on plugin initialization failure',
76     function(assert) {
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) {
86     assert.ok(
87         signalStrategyDispose.called, 'SignalStrategy is disposed on failure.');
88     assert.ok(error.hasTag(remoting.Error.Tag.MISSING_PLUGIN),
89         'Initialization failed with MISSING_PLUGIN.');
90   });
91 });
93 })();