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 isInstalled: function() {},
38 download: function() {}
42 helpeeChannel = new remoting.It2MeHelpeeChannel(
50 remoting.settings = new remoting.Settings();
54 test('hello() should return supportedFeatures', function() {
55 hangoutPort.onMessage.mock$fire(
56 { method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.HELLO });
58 sinon.assert.calledWith(hangoutPort.postMessage, {
59 method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.HELLO_RESPONSE,
60 supportedFeatures: base.values(remoting.It2MeHelperChannel.Features)
65 'isHostInstalled() should return false if host is not installed',
67 sinon.stub(hostInstaller, 'isInstalled').returns(Promise.resolve(false));
69 var MessageTypes = remoting.It2MeHelpeeChannel.HangoutMessageTypes;
70 hangoutPort.onMessage.mock$fire({
71 method: MessageTypes.IS_HOST_INSTALLED
74 window.requestAnimationFrame(function() {
75 sinon.assert.calledWith(hangoutPort.postMessage, {
76 method: MessageTypes.IS_HOST_INSTALLED_RESPONSE,
83 QUnit.asyncTest('isHostInstalled() should return true if host is installed',
85 sinon.stub(hostInstaller, 'isInstalled').returns(Promise.resolve(true));
87 var MessageTypes = remoting.It2MeHelpeeChannel.HangoutMessageTypes;
88 hangoutPort.onMessage.mock$fire({
89 method: MessageTypes.IS_HOST_INSTALLED
92 window.requestAnimationFrame(function() {
93 sinon.assert.calledWith(hangoutPort.postMessage, {
94 method: MessageTypes.IS_HOST_INSTALLED_RESPONSE,
101 test('downloadHost() should trigger a host download',
103 sinon.stub(hostInstaller, 'download').returns(Promise.resolve(true));
105 hangoutPort.onMessage.mock$fire({
106 method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.DOWNLOAD_HOST
109 sinon.assert.called(hostInstaller.download);
112 test('connect() should return error if email is missing',
114 var MessageTypes = remoting.It2MeHelpeeChannel.HangoutMessageTypes;
116 hangoutPort.onMessage.mock$fire({
117 method: MessageTypes.CONNECT
120 sinon.assert.calledWithMatch(hangoutPort.postMessage, {
121 method: MessageTypes.ERROR
125 QUnit.asyncTest('connect() should return access code',
127 // Stubs authentication.
128 sinon.stub(base, 'isAppsV2').returns(true);
129 sinon.stub(remoting.MessageWindow, 'showConfirmWindow')
130 .callsArgWith(4, 1 /* 1 for OK. */);
131 sinon.stub(chrome.identity, 'getAuthToken')
132 .callsArgWith(1, 'token');
133 // Stubs Host behavior.
134 sinon.stub(host, 'initialized').returns(true);
135 sinon.stub(host, 'connect')
136 .callsArgWith(2, remoting.HostSession.State.RECEIVED_ACCESS_CODE);
137 sinon.stub(host, 'getAccessCode').returns('accessCode');
139 var MessageTypes = remoting.It2MeHelpeeChannel.HangoutMessageTypes;
140 hangoutPort.onMessage.mock$fire({
141 method: MessageTypes.CONNECT,
142 email: 'test@chromium.org'
145 window.requestAnimationFrame(function(){
146 // Verify that access code is correct in the response.
147 sinon.assert.calledWithMatch(hangoutPort.postMessage, {
148 method: MessageTypes.CONNECT_RESPONSE,
149 accessCode: 'accessCode'
152 chrome.identity.getAuthToken.restore();
153 base.isAppsV2.restore();
154 remoting.MessageWindow.showConfirmWindow.restore();
159 test('should disconnect the session if Hangout crashes', function() {
160 sinon.spy(host, 'disconnect');
161 hangoutPort.onDisconnect.mock$fire();
163 sinon.assert.called(onDisposedCallback);
164 sinon.assert.called(host.disconnect);