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

Unified Diff: remoting/webapp/browser_test/mock_session_connector.js

Issue 593313003: Implement basic mocks for testing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reviewer feedback. Created 6 years, 3 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/browser_test/mock_session_connector.js
diff --git a/remoting/webapp/browser_test/mock_session_connector.js b/remoting/webapp/browser_test/mock_session_connector.js
new file mode 100644
index 0000000000000000000000000000000000000000..7ef5b50d64f174ea22c6ffce91d3825106be41ce
--- /dev/null
+++ b/remoting/webapp/browser_test/mock_session_connector.js
@@ -0,0 +1,120 @@
+// 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
+ * Mock implementation of SessionConnector for testing.
+ * @suppress {checkTypes}
+ */
+
+'use strict';
+
+/** @suppress {duplicate} */
+var remoting = remoting || {};
+
+/**
+ * @constructor
+ * @implements {remoting.SessionConnector}
+ */
+remoting.MockSessionConnector = function(clientContainer, onConnected, onError,
+ onExtensionMessage) {
+ this.clientContainer_ = clientContainer;
+ this.onConnected_ = onConnected;
+ this.onError = onError;
+ this.onExtensionMessage_ = onExtensionMessage;
+ this.reset();
+};
+
+remoting.MockSessionConnector.prototype.reset = function() {
+ this.pairingRequested_ = false;
+};
+
+remoting.MockSessionConnector.prototype.connectMe2Me =
+ function(host, fetchPin, fetchThirdPartyToken,
+ clientPairingId, clientPairedSecret) {
+ this.mode_ = remoting.ClientSession.Mode.ME2ME;
+ this.connect_();
+};
+
+remoting.MockSessionConnector.prototype.updatePairingInfo =
+ function(clientId, sharedSecret) {
+};
+
+remoting.MockSessionConnector.prototype.connectIT2Me =
+ function(accessCode) {
+ this.mode_ = remoting.ClientSession.Mode.ME2ME;
+ this.connect_();
+};
+
+remoting.MockSessionConnector.prototype.reconnect = function() {
+ base.debug.assert(this.mode_ == remoting.ClientSession.Mode.ME2ME);
+ this.connect_();
+};
+
+remoting.MockSessionConnector.prototype.cancel = function() {
+};
+
+remoting.MockSessionConnector.prototype.getConnectionMode = function() {
+ return this.mode_;
+};
+
+remoting.MockSessionConnector.prototype.getHostId = function() {
+ return this.hostId_;
+};
+
+remoting.MockSessionConnector.prototype.requestPairing = function() {
+ this.pairingRequested_ = true;
+};
+
+remoting.MockSessionConnector.prototype.pairingRequested = function() {
+ return this.pairingRequested_;
+};
+
+remoting.MockSessionConnector.prototype.connect_ = function() {
+ var signalling = new remoting.MockSignalStrategy();
+ var hostName = 'Mock host';
+ var accessCode = '';
+ var authenticationMethods = '';
+ var hostId = '';
+ var hostJid = '';
+ var hostPublicKey = '';
+ var clientPairingId = '';
+ var clientPairedSecret = '';
+ var fetchPin = function(offerPairing, callback) {
+ window.setTimeout(function() { callback('') }, 0);
+ };
+ var fetchThirdPartyToken = function(tokenUrl, scope, callback) {
+ window.setTimeout(function() { callback('', '') }, 0);
+ };
+
+ var clientSession = new remoting.ClientSession(
+ signalling, this.clientContainer_, hostName,
+ accessCode, fetchPin, fetchThirdPartyToken,
+ authenticationMethods, hostId, hostJid, hostPublicKey,
+ this.mode_, clientPairingId, clientPairedSecret);
+
+ var onStateChange = function(event) {
+ if (event.current == remoting.ClientSession.State.CONNECTED) {
+ this.onConnected_(clientSession);
+ }
+ }.bind(this);
+
+ clientSession.addEventListener(
+ remoting.ClientSession.Events.stateChanged,
+ onStateChange);
+ clientSession.createPluginAndConnect(this.onExtensionMessage_);
+};
+
+
+/**
+ * @constructor
+ * @extends {remoting.SessionConnectorFactory}
+ */
+remoting.MockSessionConnectorFactory = function() {};
+
+remoting.MockSessionConnectorFactory.prototype.createConnector =
+ function(clientContainer, onConnected, onError, onExtensionMessage) {
+ return new remoting.MockSessionConnector(
+ clientContainer, onConnected, onError, onExtensionMessage);
+};
« no previous file with comments | « remoting/webapp/browser_test/mock_client_plugin.js ('k') | remoting/webapp/browser_test/mock_signal_strategy.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698