Commit 96024224 authored by kelvinp's avatar kelvinp Committed by Commit bot

Remove Hangout Remote Desktop integration code from the webapp.

Cleaning the webapp as the Hangout Remote Desktop service has discontinued.

BUG=463322

Review URL: https://codereview.chromium.org/973333002

Cr-Commit-Position: refs/heads/master@{#319009}
parent e04a6768
...@@ -74,9 +74,6 @@ ...@@ -74,9 +74,6 @@
'webapp/unittests/event_hook_unittest.js', 'webapp/unittests/event_hook_unittest.js',
'webapp/unittests/fallback_signal_strategy_unittest.js', 'webapp/unittests/fallback_signal_strategy_unittest.js',
'webapp/unittests/ipc_unittest.js', 'webapp/unittests/ipc_unittest.js',
'webapp/unittests/it2me_helpee_channel_unittest.js',
'webapp/unittests/it2me_helper_channel_unittest.js',
'webapp/unittests/it2me_service_unittest.js',
'webapp/unittests/l10n_unittest.js', 'webapp/unittests/l10n_unittest.js',
'webapp/unittests/menu_button_unittest.js', 'webapp/unittests/menu_button_unittest.js',
'webapp/unittests/xhr_unittest.js', 'webapp/unittests/xhr_unittest.js',
...@@ -156,7 +153,6 @@ ...@@ -156,7 +153,6 @@
'webapp/crd/js/clipboard.js', 'webapp/crd/js/clipboard.js',
'webapp/crd/js/credentials_provider.js', 'webapp/crd/js/credentials_provider.js',
'webapp/crd/js/desktop_connected_view.js', 'webapp/crd/js/desktop_connected_view.js',
'webapp/crd/js/hangout_session.js',
'webapp/crd/js/host_desktop.js', 'webapp/crd/js/host_desktop.js',
'webapp/crd/js/session_connector.js', 'webapp/crd/js/session_connector.js',
'webapp/crd/js/session_connector_impl.js', 'webapp/crd/js/session_connector_impl.js',
...@@ -294,10 +290,7 @@ ...@@ -294,10 +290,7 @@
'webapp/crd/js/host_installer.js', 'webapp/crd/js/host_installer.js',
'webapp/crd/js/host_session.js', 'webapp/crd/js/host_session.js',
'webapp/crd/js/identity.js', 'webapp/crd/js/identity.js',
'webapp/crd/js/it2me_helpee_channel.js',
'webapp/crd/js/it2me_helper_channel.js',
'webapp/crd/js/it2me_host_facade.js', 'webapp/crd/js/it2me_host_facade.js',
'webapp/crd/js/it2me_service.js',
'webapp/crd/js/l10n.js', 'webapp/crd/js/l10n.js',
'webapp/crd/js/oauth2.js', 'webapp/crd/js/oauth2.js',
'webapp/crd/js/oauth2_api.js', 'webapp/crd/js/oauth2_api.js',
......
...@@ -1074,15 +1074,6 @@ For information about privacy, please see the Google Privacy Policy (http://goo. ...@@ -1074,15 +1074,6 @@ For information about privacy, please see the Google Privacy Policy (http://goo.
<message desc="Label for the Feedback button displayed in the Android Help screen. Pressing this button causes the Feedback screen to be shown." name="IDS_ACTIONBAR_FEEDBACK" formatter_data="android_java"> <message desc="Label for the Feedback button displayed in the Android Help screen. Pressing this button causes the Feedback screen to be shown." name="IDS_ACTIONBAR_FEEDBACK" formatter_data="android_java">
Feedback Feedback
</message> </message>
<message desc="Message displayed in the Hangouts confirm dialog. This message is shown to the Hangouts participant receiving remote assistance before the access code is generated. The dialog informs the user of the implications of accepting remote assistance. It also provides a way for the user to decline the assistance." name="IDS_HANGOUTS_CONFIRM_DIALOG_MESSAGE_1" >
A participant in this hangout has offered to help you by controlling your computer. If you accept:
</message>
<message desc="Message displayed in the Hangouts confirm dialog. This message is shown to the Hangouts participant receiving remote assistance before the access code is generated. The dialog informs the user of the implications of accepting remote assistance. It also provides a way for the user to decline the assistance." name="IDS_HANGOUTS_CONFIRM_DIALOG_MESSAGE_2" >
The person helping you will be able to control your mouse and keyboard.
</message>
<message desc="Message displayed in the Hangouts confirm dialog. This message is shown to the Hangouts participant receiving remote assistance before the access code is generated. The dialog informs the user of the implications of accepting remote assistance. It also provides a way for the user to decline the assistance." name="IDS_HANGOUTS_CONFIRM_DIALOG_MESSAGE_3" >
You can end at any time.
</message>
<message desc="Label for button to accept remote assistance. This button appears in the Hangouts confirm dialog." name="IDS_HANGOUTS_CONFIRM_DIALOG_ACCEPT" > <message desc="Label for button to accept remote assistance. This button appears in the Hangouts confirm dialog." name="IDS_HANGOUTS_CONFIRM_DIALOG_ACCEPT" >
Accept Accept
</message> </message>
......
...@@ -727,7 +727,3 @@ body:not(.connected) #session-mode { ...@@ -727,7 +727,3 @@ body:not(.connected) #session-mode {
position: absolute; position: absolute;
pointer-events: none; pointer-events: none;
} }
body.hangout-remote-desktop .home-screen {
display: none;
}
...@@ -106,10 +106,6 @@ remoting.Application.prototype.onConnected = function(clientSession) { ...@@ -106,10 +106,6 @@ remoting.Application.prototype.onConnected = function(clientSession) {
remoting.clipboard.startSession(); remoting.clipboard.startSession();
updateStatistics_(); updateStatistics_();
remoting.hangoutSessionEvents.raiseEvent(
remoting.hangoutSessionEvents.sessionStateChanged,
remoting.ClientSession.State.CONNECTED
);
this.delegate_.handleConnected(clientSession); this.delegate_.handleConnected(clientSession);
}; };
......
...@@ -9,8 +9,6 @@ var remoting = remoting || {}; ...@@ -9,8 +9,6 @@ var remoting = remoting || {};
'use strict'; 'use strict';
var ENABLE_HANGOUT_REMOTE_ASSISTANCE = false;
/** /**
* @constructor * @constructor
*/ */
...@@ -19,16 +17,7 @@ var BackgroundPage = function() { ...@@ -19,16 +17,7 @@ var BackgroundPage = function() {
this.appLauncher_ = null; this.appLauncher_ = null;
/** @private {remoting.ActivationHandler} */ /** @private {remoting.ActivationHandler} */
this.activationHandler_ = null; this.activationHandler_ = null;
/** @private {remoting.It2MeService} */
this.it2meService_ = null;
/** @private {base.Disposables} */
this.disposables_ = null;
this.preInit_(); this.preInit_();
this.onResumed_();
chrome.runtime.onSuspendCanceled.addListener(this.onResumed_.bind(this));
chrome.runtime.onSuspend.addListener(this.onSuspended_.bind(this));
}; };
/** /**
...@@ -56,21 +45,6 @@ BackgroundPage.prototype.preInit_ = function() { ...@@ -56,21 +45,6 @@ BackgroundPage.prototype.preInit_ = function() {
} }
}; };
/** @private */
BackgroundPage.prototype.onResumed_ = function() {
if (ENABLE_HANGOUT_REMOTE_ASSISTANCE) {
this.it2meService_ = new remoting.It2MeService(this.appLauncher_);
this.it2meService_.init();
this.disposables_ = new base.Disposables(this.it2meService_);
}
};
/** @private */
BackgroundPage.prototype.onSuspended_ = function() {
this.it2meService_ = null;
base.dispose(this.disposables_);
this.disposables_ = null;
};
window.addEventListener('load', function() { window.addEventListener('load', function() {
remoting.backgroundPage = new BackgroundPage(); remoting.backgroundPage = new BackgroundPage();
......
...@@ -73,9 +73,6 @@ function onClientStateChange_(state) { ...@@ -73,9 +73,6 @@ function onClientStateChange_(state) {
if (remoting.desktopConnectedView.getMode() == if (remoting.desktopConnectedView.getMode() ==
remoting.DesktopConnectedView.Mode.IT2ME) { remoting.DesktopConnectedView.Mode.IT2ME) {
remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_IT2ME); remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_IT2ME);
remoting.hangoutSessionEvents.raiseEvent(
remoting.hangoutSessionEvents.sessionStateChanged,
remoting.ClientSession.State.CLOSED);
} else { } else {
remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_ME2ME); remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_ME2ME);
} }
......
...@@ -62,22 +62,6 @@ remoting.initHostlist_ = function() { ...@@ -62,22 +62,6 @@ remoting.initHostlist_ = function() {
var hostId = urlParams['hostId']; var hostId = urlParams['hostId'];
remoting.connectMe2Me(hostId); remoting.connectMe2Me(hostId);
return; return;
} else if (urlParams['mode'] === 'hangout') {
getCurrentId().then(
/** @param {*} id */
function(id) {
/** @type {string} */
var accessCode = urlParams['accessCode'];
var connector = remoting.app.getSessionConnector();
remoting.setMode(remoting.AppMode.CLIENT_CONNECTING);
connector.connectIT2Me(accessCode);
document.body.classList.add('hangout-remote-desktop');
var senderId = /** @type {string} */ (String(id));
var hangoutSession = new remoting.HangoutSession(senderId);
hangoutSession.init();
});
return;
} }
} }
// No valid URL parameters, start up normally. // No valid URL parameters, start up normally.
......
...@@ -314,10 +314,6 @@ remoting.DesktopRemoting.prototype.handleError = function(errorTag) { ...@@ -314,10 +314,6 @@ remoting.DesktopRemoting.prototype.handleError = function(errorTag) {
: this.app_.getSessionConnector().getConnectionMode(); : this.app_.getSessionConnector().getConnectionMode();
if (mode == remoting.DesktopConnectedView.Mode.IT2ME) { if (mode == remoting.DesktopConnectedView.Mode.IT2ME) {
remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME); remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME);
remoting.hangoutSessionEvents.raiseEvent(
remoting.hangoutSessionEvents.sessionStateChanged,
remoting.ClientSession.State.FAILED
);
} else { } else {
remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_ME2ME); remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_ME2ME);
} }
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
* Class to communicate with the background scripts via chrome runtime
* messages to
* 1. Forward session state notifications
* 2. Closes the window when the session terminates
*/
'use strict';
/** @suppress {duplicate} */
var remoting = remoting || {};
/**
* @constructor
* @param {string} senderId id of the current tab or window.
*/
remoting.HangoutSession = function(senderId) {
/**
* @private
* @type {chrome.runtime.Port}
*/
this.port_ = null;
/**
* @private
* @type {string}
*/
this.senderId_ = senderId;
};
remoting.HangoutSession.prototype.init = function() {
var portName = 'it2me.helper.webapp@' + this.senderId_;
this.port_ = chrome.runtime.connect({name: portName});
remoting.hangoutSessionEvents.addEventListener(
remoting.hangoutSessionEvents.sessionStateChanged,
this.onSessionStateChanged_.bind(this));
};
/**
* @param {remoting.ClientSession.State=} state
*/
remoting.HangoutSession.prototype.onSessionStateChanged_ = function(state) {
var State = remoting.ClientSession.State;
try {
this.port_.postMessage({method: 'sessionStateChanged', state: state});
} catch (/** @type {Error} */ error) {
// postMessage will throw an exception if the port is disconnected.
// We can safely ignore this exception.
console.error(error);
} finally {
if (state === State.FAILED || state === State.CLOSED) {
// close the current window
if (base.isAppsV2()) {
chrome.app.window.current().close();
} else {
window.close();
}
}
}
};
/**
* remoting.clientSession does not exist until the session is connected.
* hangoutSessionEvents serves as a global event source to plumb session
* state changes until we cleanup clientSession and sessionConnector.
* @type {base.EventSourceImpl}
*/
remoting.hangoutSessionEvents = new base.EventSourceImpl();
/** @type {string} */
remoting.hangoutSessionEvents.sessionStateChanged = "sessionStateChanged";
remoting.hangoutSessionEvents.defineEvents(
[remoting.hangoutSessionEvents.sessionStateChanged]);
This diff is collapsed.
This diff is collapsed.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
* It2MeService listens to incoming connections requests from Hangouts
* and the webapp and creates a It2MeHelperChannel between them.
* It supports multiple helper sessions, but only a single helpee.
*/
'use strict';
/** @suppress {duplicate} */
var remoting = remoting || {};
/**
* @param {remoting.AppLauncher} appLauncher
*
* @constructor
* @implements {base.Disposable}
*/
remoting.It2MeService = function(appLauncher) {
/**
* @type {remoting.AppLauncher}
* @private
*/
this.appLauncher_ = appLauncher;
/**
* @type {Array<remoting.It2MeHelperChannel>}
* @private
*/
this.helpers_ = [];
/** @private */
this.helpee_ = null;
this.onWebappConnectRef_ = this.onWebappConnect_.bind(this);
this.onConnectExternalRef_ = this.onConnectExternal_.bind(this);
};
/** @enum {string} */
remoting.It2MeService.ConnectionTypes = {
HELPER_HANGOUT: 'it2me.helper.hangout',
HELPEE_HANGOUT: 'it2me.helpee.hangout',
HELPER_WEBAPP: 'it2me.helper.webapp'
};
/**
* Starts listening to external connection from Hangouts and the webapp.
*/
remoting.It2MeService.prototype.init = function() {
chrome.runtime.onConnect.addListener(this.onWebappConnectRef_);
chrome.runtime.onConnectExternal.addListener(this.onConnectExternalRef_);
};
remoting.It2MeService.prototype.dispose = function() {
chrome.runtime.onConnect.removeListener(this.onWebappConnectRef_);
chrome.runtime.onConnectExternal.removeListener(
this.onConnectExternalRef_);
};
/**
* This function is called when Hangouts connects via chrome.runtime.connect.
* Only web pages that are white-listed in the manifest are allowed to connect.
*
* @param {chrome.runtime.Port} port
* @private
*/
remoting.It2MeService.prototype.onConnectExternal_ = function(port) {
var ConnectionTypes = remoting.It2MeService.ConnectionTypes;
try {
switch (port.name) {
case ConnectionTypes.HELPER_HANGOUT:
this.handleExternalHelperConnection_(port);
return true;
case ConnectionTypes.HELPEE_HANGOUT:
this.handleExternalHelpeeConnection_(port);
return true;
default:
throw new Error('Unsupported port - ' + port.name);
}
} catch (/** @type {*} */ e) {
var error = /**@type {Error} */ (e);
console.error(error);
port.disconnect();
}
return false;
};
/**
* @param {chrome.runtime.Port} port
* @private
*/
remoting.It2MeService.prototype.onWebappConnect_ = function(port) {
try {
console.log('Incoming helper connection from webapp.');
// The senderId (tabId or windowId) of the webapp is embedded in the port
// name with the format port_name@senderId.
var parts = port.name.split('@');
var portName = parts[0];
var senderId = parts[1];
var ConnectionTypes = remoting.It2MeService.ConnectionTypes;
if (portName === ConnectionTypes.HELPER_WEBAPP && senderId !== undefined) {
for (var i = 0; i < this.helpers_.length; i++) {
var helper = this.helpers_[i];
if (helper.instanceId() === senderId) {
helper.onWebappConnect(port, senderId);
return;
}
}
}
throw new Error('No matching hangout connection found for ' + port.name);
} catch (/** @type {*} */ e) {
var error = /** @type {Error} */ (e);
console.error(error);
port.disconnect();
}
};
/**
* @param {remoting.It2MeHelperChannel} helper
*/
remoting.It2MeService.prototype.onHelperChannelDisconnected = function(helper) {
for (var i = 0; i < this.helpers_.length; i++) {
if (helper === this.helpers_[i]) {
this.helpers_.splice(i, 1);
}
}
};
remoting.It2MeService.prototype.onHelpeeChannelDisconnected = function() {
base.debug.assert(this.helpee_ !== null);
this.helpee_ = null;
};
/**
* @param {chrome.runtime.Port} port
* @private
*/
remoting.It2MeService.prototype.handleExternalHelperConnection_ =
function(port) {
if (this.helpee_) {
console.error(
'Cannot start a helper session while a helpee session is in process.');
port.disconnect();
return;
}
console.log('Incoming helper connection from Hangouts');
var helper = new remoting.It2MeHelperChannel(
this.appLauncher_, port, this.onHelperChannelDisconnected.bind(this));
helper.init();
this.helpers_.push(helper);
};
/**
* @param {chrome.runtime.Port} hangoutPort Represents a connection to Hangouts.
* @private
*/
remoting.It2MeService.prototype.handleExternalHelpeeConnection_ =
function(hangoutPort) {
if (this.helpee_) {
console.error('An existing helpee session is in process.');
hangoutPort.disconnect();
return;
}
console.log('Incoming helpee connection from Hangouts');
this.helpee_ = new remoting.It2MeHelpeeChannel(
hangoutPort,
new remoting.It2MeHostFacade(),
new remoting.HostInstaller(),
this.onHelpeeChannelDisconnected.bind(this));
this.helpee_.init();
};
...@@ -60,11 +60,6 @@ ...@@ -60,11 +60,6 @@
"pages": [ "wcs_sandbox.html" ] "pages": [ "wcs_sandbox.html" ]
}, },
{% endif %} {% endif %}
"externally_connectable": {
"matches": [
"https://*.google.com/hangouts*"
]
},
"permissions": [ "permissions": [
"{{ OAUTH2_ACCOUNTS_HOST }}/*", "{{ OAUTH2_ACCOUNTS_HOST }}/*",
"{{ OAUTH2_API_BASE_URL }}/*", "{{ OAUTH2_API_BASE_URL }}/*",
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
* @suppress {checkTypes|checkVars|reportUnknownTypes|visibility}
*/
(function() {
'use strict';
var hostInstaller = null;
var hangoutPort = null;
var host = null;
var helpeeChannel = null;
var onDisposedCallback = null;
module('It2MeHelpeeChannel', {
setup: function() {
// HangoutPort
hangoutPort = new chromeMocks.runtime.Port();
hangoutPort.postMessage = sinon.spy(hangoutPort, 'postMessage');
hangoutPort.disconnect = sinon.spy(hangoutPort, 'disconnect');
// onDisposedCallback callback
onDisposedCallback = sinon.spy();
// Host
host = {
initialize: function() {},
initialized: function() {},
connect: function() {},
disconnect: function() {},
getAccessCode: function() {},
unhookCallbacks: function() {}
};
// HostInstaller
hostInstaller = {
download: function() {}
};
// HelpeeChannel
helpeeChannel = new remoting.It2MeHelpeeChannel(
hangoutPort,
host,
hostInstaller,
onDisposedCallback);
helpeeChannel.init();
// remoting.settings
remoting.settings = new remoting.Settings();
remoting.identity = new remoting.Identity();
},
tearDown: function() {
remoting.settings = null;
remoting.identity = null;
}
});
test('hello() should return supportedFeatures', function() {
hangoutPort.onMessage.mock$fire(
{ method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.HELLO });
sinon.assert.calledWith(hangoutPort.postMessage, {
method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.HELLO_RESPONSE,
supportedFeatures: base.values(remoting.It2MeHelperChannel.Features)
});
});
QUnit.asyncTest(
'isHostInstalled() should return false if host is not installed',
function() {
sinon.stub(remoting.HostInstaller, 'isInstalled')
.returns(Promise.resolve(false));
var MessageTypes = remoting.It2MeHelpeeChannel.HangoutMessageTypes;
hangoutPort.onMessage.mock$fire({
method: MessageTypes.IS_HOST_INSTALLED
});
window.requestAnimationFrame(function() {
remoting.HostInstaller.isInstalled.restore();
sinon.assert.calledWith(hangoutPort.postMessage, {
method: MessageTypes.IS_HOST_INSTALLED_RESPONSE,
result: false
});
QUnit.start();
});
});
QUnit.asyncTest('isHostInstalled() should return true if host is installed',
function() {
sinon.stub(remoting.HostInstaller, 'isInstalled')
.returns(Promise.resolve(true));
var MessageTypes = remoting.It2MeHelpeeChannel.HangoutMessageTypes;
hangoutPort.onMessage.mock$fire({
method: MessageTypes.IS_HOST_INSTALLED
});
window.requestAnimationFrame(function() {
remoting.HostInstaller.isInstalled.restore();
sinon.assert.calledWith(hangoutPort.postMessage, {
method: MessageTypes.IS_HOST_INSTALLED_RESPONSE,
result: true
});
QUnit.start();
});
});
test('downloadHost() should trigger a host download',
function() {
sinon.stub(hostInstaller, 'download').returns(Promise.resolve(true));
hangoutPort.onMessage.mock$fire({
method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.DOWNLOAD_HOST
});
sinon.assert.called(hostInstaller.download);
});
QUnit.asyncTest('connect() should return access code',
function() {
// Stubs authentication.
sinon.stub(base, 'isAppsV2').returns(true);
sinon.stub(chrome.identity, 'getAuthToken')
.callsArgWith(1, 'token');
sinon.stub(remoting.identity, 'getToken')
.returns(Promise.resolve('token'));
sinon.stub(remoting.identity, 'getEmail')
.returns(Promise.resolve('test@chromium.org'));
// Stubs Host behavior.
sinon.stub(host, 'initialized').returns(true);
sinon.stub(host, 'connect')
.callsArgWith(2, remoting.HostSession.State.RECEIVED_ACCESS_CODE);
sinon.stub(host, 'getAccessCode').returns('accessCode');
var MessageTypes = remoting.It2MeHelpeeChannel.HangoutMessageTypes;
hangoutPort.onMessage.mock$fire({
method: MessageTypes.CONNECT,
hangoutBounds: {widht: 10, height: 10, left:10, top: 10}
});
window.requestAnimationFrame(function(){
// Verify that access code is correct in the response.
sinon.assert.calledWithMatch(hangoutPort.postMessage, {
method: MessageTypes.CONNECT_RESPONSE,
accessCode: 'accessCode'
});
chrome.identity.getAuthToken.restore();
base.isAppsV2.restore();
QUnit.start();
});
});
test('should disconnect the session if Hangout crashes', function() {
sinon.spy(host, 'disconnect');
hangoutPort.onDisconnect.mock$fire();
sinon.assert.called(onDisposedCallback);
sinon.assert.called(host.disconnect);
});
})();
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
* @suppress {checkTypes|checkVars|reportUnknownTypes|visibility}
*/
(function() {
'use strict';
var appLauncher = null;
var hangoutPort = null;
var webappPort = null;
var helperChannel = null;
var disconnectCallback = null;
module('It2MeHelperChannel', {
setup: function() {
// App Launcher.
appLauncher = {
launch: function () {
return promiseResolveSynchronous('tabId');
},
close: function () {}
};
appLauncher.launch = sinon.spy(appLauncher, 'launch');
appLauncher.close = sinon.spy(appLauncher, 'close');
// HangoutPort.
hangoutPort = new chromeMocks.runtime.Port();
hangoutPort.postMessage = sinon.spy(hangoutPort, 'postMessage');
hangoutPort.disconnect = sinon.spy(hangoutPort, 'disconnect');
// WebappPort.
webappPort = new chromeMocks.runtime.Port();
webappPort.sender = {
tab : {
id : 'tabId'
}
};
webappPort.postMessage = sinon.spy(webappPort, 'postMessage');
webappPort.disconnect = sinon.spy(webappPort, 'disconnect');
// disconnect callback
disconnectCallback = sinon.spy();
// HelperChannel.
helperChannel = new remoting.It2MeHelperChannel(
appLauncher, hangoutPort, disconnectCallback);
helperChannel.init();
hangoutPort.onMessage.mock$fire({
method: remoting.It2MeHelperChannel.HangoutMessageTypes.CONNECT,
accessCode: "123412341234"
});
},
});
function promiseResolveSynchronous(value) {
return {
then: function(callback) {
callback('tabId');
}
};
}
test('onHangoutMessage_("hello") should return supportedFeatures', function() {
hangoutPort.onMessage.mock$fire(
{ method: remoting.It2MeHelperChannel.HangoutMessageTypes.HELLO });
sinon.assert.calledWith(hangoutPort.postMessage, {
method: remoting.It2MeHelperChannel.HangoutMessageTypes.HELLO_RESPONSE,
supportedFeatures: base.values(remoting.It2MeHelperChannel.Features)
});
});
test('onHangoutMessage_(|connect|) should launch the webapp',
function() {
sinon.assert.called(appLauncher.launch);
QUnit.equal(helperChannel.instanceId(), 'tabId');
});
test('onWebappMessage() should forward messages to hangout', function() {
// Execute.
helperChannel.onWebappConnect(webappPort);
webappPort.onMessage.mock$fire({
method:'sessionStateChanged',
state:remoting.ClientSession.State.CONNECTING
});
webappPort.onMessage.mock$fire({
method:'sessionStateChanged',
state:remoting.ClientSession.State.CONNECTED
});
// Verify events are forwarded.
sinon.assert.calledWith(hangoutPort.postMessage, {
method:'sessionStateChanged',
state:remoting.ClientSession.State.CONNECTING
});
sinon.assert.calledWith(hangoutPort.postMessage, {
method:'sessionStateChanged',
state:remoting.ClientSession.State.CONNECTED
});
});
test('should notify hangout when the webapp crashes', function() {
// Execute.
helperChannel.onWebappConnect(webappPort);
webappPort.onDisconnect.mock$fire();
// Verify events are forwarded.
sinon.assert.calledWith(hangoutPort.postMessage, {
method:'sessionStateChanged',
state: remoting.ClientSession.State.FAILED
});
sinon.assert.called(hangoutPort.disconnect);
sinon.assert.calledOnce(disconnectCallback);
});
test('should notify hangout when the session is ended', function() {
// Execute.
helperChannel.onWebappConnect(webappPort);
webappPort.onMessage.mock$fire({
method:'sessionStateChanged',
state:remoting.ClientSession.State.CLOSED
});
webappPort.onDisconnect.mock$fire();
// Verify events are forwarded.
sinon.assert.calledWith(hangoutPort.postMessage, {
method:'sessionStateChanged',
state:remoting.ClientSession.State.CLOSED
});
sinon.assert.called(hangoutPort.disconnect);
sinon.assert.calledOnce(disconnectCallback);
});
test('should notify hangout when the session has error', function() {
helperChannel.onWebappConnect(webappPort);
webappPort.onMessage.mock$fire({
method:'sessionStateChanged',
state:remoting.ClientSession.State.FAILED
});
webappPort.onDisconnect.mock$fire();
// Verify events are forwarded.
sinon.assert.calledWith(hangoutPort.postMessage, {
method:'sessionStateChanged',
state:remoting.ClientSession.State.FAILED
});
sinon.assert.called(hangoutPort.disconnect);
sinon.assert.calledOnce(disconnectCallback);
});
test('onHangoutMessages_(disconnect) should close the webapp', function() {
// Execute.
helperChannel.onWebappConnect(webappPort);
hangoutPort.onMessage.mock$fire({
method: remoting.It2MeHelperChannel.HangoutMessageTypes.DISCONNECT
});
sinon.assert.calledOnce(appLauncher.close);
// Webapp will respond by disconnecting the port
webappPort.onDisconnect.mock$fire();
// Verify events are forwarded.
sinon.assert.calledWith(hangoutPort.postMessage, {
method:'sessionStateChanged',
state:remoting.ClientSession.State.CLOSED
});
sinon.assert.called(webappPort.disconnect);
sinon.assert.called(hangoutPort.disconnect);
});
test('should close the webapp when hangout crashes', function() {
// Execute.
helperChannel.onWebappConnect(webappPort);
hangoutPort.onDisconnect.mock$fire();
sinon.assert.calledOnce(appLauncher.close);
sinon.assert.calledOnce(disconnectCallback);
sinon.assert.called(hangoutPort.disconnect);
sinon.assert.called(webappPort.disconnect);
});
})();
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
* @suppress {checkTypes|checkVars|reportUnknownTypes|visibility}
*/
(function() {
'use strict';
var appLauncher = null;
var hangoutPort = null;
var webappPort = null;
var it2meService = null;
function createPort(name, senderId) {
var port = new chromeMocks.runtime.Port();
port.name = (senderId) ? name +'@' + senderId : name;
port.postMessage = sinon.spy(port, 'postMessage');
port.disconnect = sinon.spy(port, 'disconnect');
return port;
}
function promiseResolveSynchronous(value) {
return {
then: function(callback) {
callback(value);
}
};
}
module('It2MeService', {
setup: function() {
// App Launcher.
appLauncher = {
launch: function () {
return promiseResolveSynchronous('tabId');
},
close: function () {}
};
// HangoutPort.
hangoutPort = createPort('it2me.helper.hangout');
it2meService = new remoting.It2MeService(appLauncher);
it2meService.onConnectExternal_(hangoutPort);
webappPort = createPort('it2me.helper.webapp', 'tabId');
}
});
test('should establish a channel two way channel when the webapp connects',
function() {
// Hangout ---- connect ----> It2MeService.
hangoutPort.onMessage.mock$fire({
method: 'connect',
accessCode: "123412341234"
});
// Webapp ---- connect ----> It2MeService.
it2meService.onWebappConnect_(webappPort);
// Webapp ---- sessionStateChanged ----> It2MeService.
webappPort.onMessage.mock$fire({
method: 'sessionStateChanged',
state: remoting.ClientSession.State.CONNECTED
});
// verify that hangout can receive message events.
sinon.assert.calledWith(hangoutPort.postMessage, {
method: 'sessionStateChanged',
state: remoting.ClientSession.State.CONNECTED
});
hangoutPort.onDisconnect.mock$fire();
QUnit.equal(it2meService.helpers_.length, 0);
});
test('should handle multiple helper connections', function() {
// Hangout ---- connect ----> It2MeService.
hangoutPort.onMessage.mock$fire({
method: 'connect',
accessCode: "123412341234"
});
// Hangout2 ---- connect ----> It2MeService.
var hangoutPort2 = createPort('it2me.helper.hangout');
it2meService.onConnectExternal_(hangoutPort2);
appLauncher.launch = function () {
return promiseResolveSynchronous('tabId2');
};
hangoutPort2.onMessage.mock$fire({
method: 'connect',
accessCode: "123412341234"
});
it2meService.onWebappConnect_(webappPort);
var webappPort2 = createPort('it2me.helper.webapp', 'tabId2');
it2meService.onWebappConnect_(webappPort2);
webappPort.onMessage.mock$fire({
method: 'sessionStateChanged',
state: remoting.ClientSession.State.CONNECTED
});
// verify that hangout can receive message events from webapp 1
sinon.assert.calledWith(hangoutPort.postMessage, {
method: 'sessionStateChanged',
state: remoting.ClientSession.State.CONNECTED
});
webappPort2.onMessage.mock$fire({
method: 'sessionStateChanged',
state: remoting.ClientSession.State.CLOSED
});
// verify that hangout can receive message events from webapp 2.
sinon.assert.calledWith(hangoutPort2.postMessage, {
method: 'sessionStateChanged',
state: remoting.ClientSession.State.CLOSED
});
});
test('should reject unknown connection', function() {
it2meService.onWebappConnect_(webappPort);
sinon.assert.called(webappPort.disconnect);
var randomPort = createPort('unsupported.port.name');
it2meService.onConnectExternal_(randomPort);
sinon.assert.called(randomPort.disconnect);
});
})();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment