Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Unified Diff: remoting/webapp/unittests/it2me_helper_channel_unittest.js

Issue 450383003: Hangout remote desktop part II - background.html and AppLauncher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/webapp/unittests/it2me_helper_channel_unittest.js
diff --git a/remoting/webapp/unittests/it2me_helper_channel_unittest.js b/remoting/webapp/unittests/it2me_helper_channel_unittest.js
new file mode 100644
index 0000000000000000000000000000000000000000..7b03ae85f35731d20e48ea616d1791df5800a467
--- /dev/null
+++ b/remoting/webapp/unittests/it2me_helper_channel_unittest.js
@@ -0,0 +1,179 @@
+// 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.
+
+(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 chrome.runtime.Port();
+ hangoutPort.postMessage = sinon.spy(hangoutPort, 'postMessage');
+ hangoutPort.disconnect = sinon.spy(hangoutPort, 'disconnect');
+
+ // WebappPort.
+ webappPort = new chrome.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_(|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);
+});
+
+})();

Powered by Google App Engine
This is Rietveld 408576698