1 // Copyright 2014 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 var hostInstaller = null;
10 var hangoutPort = null;
12 var helpeeChannel = null;
13 var onDisposedCallback = null;
15 module('It2MeHelpeeChannel', {
18 hangoutPort = new chromeMocks.runtime.Port();
19 hangoutPort.postMessage = sinon.spy(hangoutPort, 'postMessage');
20 hangoutPort.disconnect = sinon.spy(hangoutPort, 'disconnect');
22 // onDisposedCallback callback
23 onDisposedCallback = sinon.spy();
27 initialize: function() {},
28 initialized: function() {},
29 connect: function() {},
30 disconnect: function() {},
31 getAccessCode: function() {},
32 unhookCallbacks: function() {}
37 download: function() {}
41 helpeeChannel = new remoting.It2MeHelpeeChannel(
49 remoting.settings = new remoting.Settings();
50 remoting.identity = new remoting.Identity();
52 tearDown: function() {
53 remoting.settings = null;
54 remoting.identity = null;
58 test('hello() should return supportedFeatures', function() {
59 hangoutPort.onMessage.mock$fire(
60 { method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.HELLO });
62 sinon.assert.calledWith(hangoutPort.postMessage, {
63 method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.HELLO_RESPONSE,
64 supportedFeatures: base.values(remoting.It2MeHelperChannel.Features)
69 'isHostInstalled() should return false if host is not installed',
71 sinon.stub(remoting.HostInstaller, 'isInstalled')
72 .returns(Promise.resolve(false));
74 var MessageTypes = remoting.It2MeHelpeeChannel.HangoutMessageTypes;
75 hangoutPort.onMessage.mock$fire({
76 method: MessageTypes.IS_HOST_INSTALLED
79 window.requestAnimationFrame(function() {
80 remoting.HostInstaller.isInstalled.restore();
81 sinon.assert.calledWith(hangoutPort.postMessage, {
82 method: MessageTypes.IS_HOST_INSTALLED_RESPONSE,
89 QUnit.asyncTest('isHostInstalled() should return true if host is installed',
91 sinon.stub(remoting.HostInstaller, 'isInstalled')
92 .returns(Promise.resolve(true));
94 var MessageTypes = remoting.It2MeHelpeeChannel.HangoutMessageTypes;
95 hangoutPort.onMessage.mock$fire({
96 method: MessageTypes.IS_HOST_INSTALLED
99 window.requestAnimationFrame(function() {
100 remoting.HostInstaller.isInstalled.restore();
101 sinon.assert.calledWith(hangoutPort.postMessage, {
102 method: MessageTypes.IS_HOST_INSTALLED_RESPONSE,
109 test('downloadHost() should trigger a host download',
111 sinon.stub(hostInstaller, 'download').returns(Promise.resolve(true));
113 hangoutPort.onMessage.mock$fire({
114 method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.DOWNLOAD_HOST
117 sinon.assert.called(hostInstaller.download);
120 QUnit.asyncTest('connect() should return access code',
122 // Stubs authentication.
123 sinon.stub(base, 'isAppsV2').returns(true);
124 sinon.stub(remoting.HangoutConsentDialog, 'getInstance').returns({
126 return Promise.resolve();
129 sinon.stub(chrome.identity, 'getAuthToken')
130 .callsArgWith(1, 'token');
131 sinon.stub(remoting.identity, 'getToken')
132 .returns(Promise.resolve('token'));
133 sinon.stub(remoting.identity, 'getEmail')
134 .returns(Promise.resolve('test@chromium.org'));
135 // Stubs Host behavior.
136 sinon.stub(host, 'initialized').returns(true);
137 sinon.stub(host, 'connect')
138 .callsArgWith(2, remoting.HostSession.State.RECEIVED_ACCESS_CODE);
139 sinon.stub(host, 'getAccessCode').returns('accessCode');
141 var MessageTypes = remoting.It2MeHelpeeChannel.HangoutMessageTypes;
142 hangoutPort.onMessage.mock$fire({
143 method: MessageTypes.CONNECT,
144 hangoutBounds: {widht: 10, height: 10, left:10, top: 10}
147 window.requestAnimationFrame(function(){
148 // Verify that access code is correct in the response.
149 sinon.assert.calledWithMatch(hangoutPort.postMessage, {
150 method: MessageTypes.CONNECT_RESPONSE,
151 accessCode: 'accessCode'
154 chrome.identity.getAuthToken.restore();
155 base.isAppsV2.restore();
160 test('should disconnect the session if Hangout crashes', function() {
161 sinon.spy(host, 'disconnect');
162 hangoutPort.onDisconnect.mock$fire();
164 sinon.assert.called(onDisposedCallback);
165 sinon.assert.called(host.disconnect);