Commit 8e0666d3 authored by jamiewalch's avatar jamiewalch Committed by Commit bot

Implement basic mocks for testing.

These may need to be made more elaborate once we start using them in
browser tests, but I've verified that they can be used to mock a basic
connection with resize support.

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

Cr-Commit-Position: refs/heads/master@{#296624}
parent 32977338
...@@ -140,6 +140,9 @@ ...@@ -140,6 +140,9 @@
'webapp/browser_test/bump_scroll_browser_test.js', 'webapp/browser_test/bump_scroll_browser_test.js',
'webapp/browser_test/cancel_pin_browser_test.js', 'webapp/browser_test/cancel_pin_browser_test.js',
'webapp/browser_test/invalid_pin_browser_test.js', 'webapp/browser_test/invalid_pin_browser_test.js',
'webapp/browser_test/mock_client_plugin.js',
'webapp/browser_test/mock_session_connector.js',
'webapp/browser_test/mock_signal_strategy.js',
'webapp/browser_test/scrollbar_browser_test.js', 'webapp/browser_test/scrollbar_browser_test.js',
'webapp/browser_test/update_pin_browser_test.js', 'webapp/browser_test/update_pin_browser_test.js',
], ],
......
// 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 ClientPlugin for testing.
* @suppress {checkTypes}
*/
'use strict';
/** @suppress {duplicate} */
var remoting = remoting || {};
/**
* @constructor
* @implements {remoting.ClientPlugin}
*/
remoting.MockClientPlugin = function(container) {
this.container_ = container;
this.element_ = document.createElement('div');
this.element_.style.backgroundImage = 'linear-gradient(45deg, blue, red)';
this.width_ = 640;
this.height_ = 480;
this.connectionStatusUpdateHandler_ = null;
this.desktopSizeUpdateHandler_ = null;
this.container_.appendChild(this.element_);
};
remoting.MockClientPlugin.prototype.dispose = function() {
this.container_.removeChild(this.element_);
this.element_ = null;
this.connectionStatusUpdateHandler_ = null;
};
remoting.MockClientPlugin.prototype.getDesktopWidth = function() {
return this.width_;
};
remoting.MockClientPlugin.prototype.getDesktopHeight = function() {
return this.height_;
};
remoting.MockClientPlugin.prototype.getDesktopXDpi = function() {
return 96;
};
remoting.MockClientPlugin.prototype.getDesktopYDpi = function() {
return 96;
};
remoting.MockClientPlugin.prototype.element = function() {
return this.element_;
};
remoting.MockClientPlugin.prototype.initialize = function(onDone) {
window.setTimeout(onDone.bind(null, true), 0);
};
remoting.MockClientPlugin.prototype.connect = function(
hostJid, hostPublicKey, localJid, sharedSecret,
authenticationMethods, authenticationTag,
clientPairingId, clientPairedSecret) {
base.debug.assert(this.connectionStatusUpdateHandler_ != null);
window.setTimeout(
this.connectionStatusUpdateHandler_.bind(
this,
remoting.ClientSession.State.CONNECTED,
remoting.ClientSession.ConnectionError.NONE),
0);
};
remoting.MockClientPlugin.prototype.injectKeyEvent =
function(key, down) {};
remoting.MockClientPlugin.prototype.remapKey = function(from, to) {};
remoting.MockClientPlugin.prototype.releaseAllKeys = function() {};
remoting.MockClientPlugin.prototype.notifyClientResolution =
function(width, height, dpi) {
this.width_ = width;
this.height_ = height;
if (this.desktopSizeUpdateHandler_) {
window.setTimeout(this.desktopSizeUpdateHandler_, 0);
}
};
remoting.MockClientPlugin.prototype.onIncomingIq = function(iq) {};
remoting.MockClientPlugin.prototype.isSupportedVersion = function() {
return true;
};
remoting.MockClientPlugin.prototype.hasFeature = function(feature) {
return false;
};
remoting.MockClientPlugin.prototype.enableMediaSourceRendering =
function(mediaSourceRenderer) {};
remoting.MockClientPlugin.prototype.sendClipboardItem =
function(mimeType, item) {};
remoting.MockClientPlugin.prototype.useAsyncPinDialog = function() {};
remoting.MockClientPlugin.prototype.requestPairing =
function(clientName, onDone) {};
remoting.MockClientPlugin.prototype.onPinFetched = function(pin) {};
remoting.MockClientPlugin.prototype.onThirdPartyTokenFetched =
function(token, sharedSecret) {};
remoting.MockClientPlugin.prototype.pauseAudio = function(pause) {};
remoting.MockClientPlugin.prototype.pauseVideo = function(pause) {};
remoting.MockClientPlugin.prototype.getPerfStats = function() {
var result = new remoting.ClientSession.PerfStats;
result.videoBandwidth = 999;
result.videoFrameRate = 60;
result.captureLatency = 10;
result.encodeLatency = 10;
result.decodeLatency = 10;
result.renderLatency = 10;
result.roundtripLatency = 10;
return result;
};
remoting.MockClientPlugin.prototype.sendClientMessage =
function(name, data) {};
remoting.MockClientPlugin.prototype.setOnOutgoingIqHandler =
function(handler) {};
remoting.MockClientPlugin.prototype.setOnDebugMessageHandler =
function(handler) {};
remoting.MockClientPlugin.prototype.setConnectionStatusUpdateHandler =
function(handler) {
this.connectionStatusUpdateHandler_ = handler;
};
remoting.MockClientPlugin.prototype.setConnectionReadyHandler =
function(handler) {};
remoting.MockClientPlugin.prototype.setDesktopSizeUpdateHandler =
function(handler) {
this.desktopSizeUpdateHandler_ = handler;
};
remoting.MockClientPlugin.prototype.setCapabilitiesHandler =
function(handler) {};
remoting.MockClientPlugin.prototype.setGnubbyAuthHandler =
function(handler) {};
remoting.MockClientPlugin.prototype.setCastExtensionHandler =
function(handler) {};
remoting.MockClientPlugin.prototype.setMouseCursorHandler =
function(handler) {};
remoting.MockClientPlugin.prototype.setFetchThirdPartyTokenHandler =
function(handler) {};
remoting.MockClientPlugin.prototype.setFetchPinHandler =
function(handler) {};
/**
* @constructor
* @extends {remoting.ClientPluginFactory}
*/
remoting.MockClientPluginFactory = function() {};
remoting.MockClientPluginFactory.prototype.createPlugin =
function(container, onExtensionMessage) {
return new remoting.MockClientPlugin(container);
};
remoting.MockClientPluginFactory.prototype.preloadPlugin = function() {};
// 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 newline at end of file
// 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}
*/
'use strict';
/** @suppress {duplicate} */
var remoting = remoting || {};
/**
* @constructor
* @implements {remoting.SignalStrategy}
*/
remoting.MockSignalStrategy = function() {};
remoting.MockSignalStrategy.prototype.dispose = function() {};
remoting.MockSignalStrategy.prototype.setIncomingStanzaCallback =
function(onIncomingStanzaCallback) {};
remoting.MockSignalStrategy.prototype.connect =
function(server, username, authToken) {};
remoting.MockSignalStrategy.prototype.sendMessage = function(message) {};
remoting.MockSignalStrategy.prototype.getState = function() {
return remoting.SignalStrategy.State.CONNECTED;
};
remoting.MockSignalStrategy.prototype.getError = function() {
return remoting.Error.NONE;
};
remoting.MockSignalStrategy.prototype.getJid = function() {
return '';
};
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