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

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

Issue 959963002: [Chromoting] Enable jscompile for webapp unittests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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/chrome_mocks.js
diff --git a/remoting/webapp/unittests/chrome_mocks.js b/remoting/webapp/unittests/chrome_mocks.js
index be557855636f670b96d606acda9d95a7bfee9855..18cce1b1bc11f798b05d8b0fe606141749eef940 100644
--- a/remoting/webapp/unittests/chrome_mocks.js
+++ b/remoting/webapp/unittests/chrome_mocks.js
@@ -9,22 +9,22 @@ Entry = function() {};
var chromeMocks = {};
-(function(){
+chromeMocks.reset = function() {
/**
* @constructor
*/
-chromeMocks.Event = function() {
+chrome.Event = function() {
this.listeners_ = [];
};
/** @param {Function} callback */
-chromeMocks.Event.prototype.addListener = function(callback) {
+chrome.Event.prototype.addListener = function(callback) {
this.listeners_.push(callback);
};
/** @param {Function} callback */
-chromeMocks.Event.prototype.removeListener = function(callback) {
+chrome.Event.prototype.removeListener = function(callback) {
for (var i = 0; i < this.listeners_.length; i++) {
if (this.listeners_[i] === callback) {
this.listeners_.splice(i, 1);
@@ -37,7 +37,7 @@ chromeMocks.Event.prototype.removeListener = function(callback) {
* @param {...*} var_args
* @return {void}
*/
-chromeMocks.Event.prototype.mock$fire = function(var_args) {
+chrome.Event.prototype.mock$fire = function(var_args) {
var params = Array.prototype.slice.call(arguments);
this.listeners_.forEach(
/** @param {Function} listener */
@@ -46,59 +46,37 @@ chromeMocks.Event.prototype.mock$fire = function(var_args) {
});
};
-/** @type {Object} */
-chromeMocks.runtime = {};
-
-/** @constructor */
-chromeMocks.runtime.Port = function() {
- this.onMessage = new chromeMocks.Event();
- this.onDisconnect = new chromeMocks.Event();
-
- /** @type {string} */
- this.name = '';
-
- /** @type {chrome.runtime.MessageSender} */
- this.sender = null;
-};
-
-chromeMocks.runtime.Port.prototype.disconnect = function() {};
-
-/**
- * @param {Object} message
- */
-chromeMocks.runtime.Port.prototype.postMessage = function(message) {};
-
-/** @type {chromeMocks.Event} */
-chromeMocks.runtime.onMessage = new chromeMocks.Event();
+/** @type {chrome.Event} */
+chrome.runtime.onMessage = new chrome.Event();
/**
+ * TODO(garykac): Function signature doesn't match chrome.runtime.sendMessage
+ * in chrome_proto.
+ *
* @param {string?} extensionId
* @param {*} message
* @param {function(*)=} responseCallback
*/
-chromeMocks.runtime.sendMessage = function(extensionId, message,
- responseCallback) {
+chrome.runtime.sendMessage = function(extensionId, message,
+ responseCallback) {
base.debug.assert(
extensionId === null,
'The mock only supports sending messages to the same extension.');
extensionId = chrome.runtime.id;
window.requestAnimationFrame(function() {
var message_copy = base.deepCopy(message);
- chromeMocks.runtime.onMessage.mock$fire(
+ chrome.runtime.onMessage.mock$fire(
message_copy, {id: extensionId}, responseCallback);
});
};
/** @type {string} */
-chromeMocks.runtime.id = 'extensionId';
-
-/** @type {Object} */
-chromeMocks.storage = {};
+chrome.runtime.id = 'extensionId';
// Sample implementation of chrome.StorageArea according to
// https://developer.chrome.com/apps/storage#type-StorageArea
/** @constructor */
-chromeMocks.StorageArea = function() {
+chrome.StorageArea = function() {
/** @type {Object} */
this.storage_ = {};
};
@@ -120,7 +98,7 @@ function getKeys(keys) {
* @param {!Object} keys
* @param {Function} onDone
*/
-chromeMocks.StorageArea.prototype.get = function(keys, onDone) {
+chrome.StorageArea.prototype.get = function(keys, onDone) {
if (!keys) {
onDone(base.deepCopy(this.storage_));
return;
@@ -138,7 +116,7 @@ chromeMocks.StorageArea.prototype.get = function(keys, onDone) {
};
/** @param {Object} value */
-chromeMocks.StorageArea.prototype.set = function(value) {
+chrome.StorageArea.prototype.set = function(value) {
for (var key in value) {
this.storage_[key] = base.deepCopy(value[key]);
}
@@ -147,7 +125,7 @@ chromeMocks.StorageArea.prototype.set = function(value) {
/**
* @param {!Object} keys
*/
-chromeMocks.StorageArea.prototype.remove = function(keys) {
+chrome.StorageArea.prototype.remove = function(keys) {
getKeys(keys).forEach(
/** @param {string} key */
function(key) {
@@ -155,41 +133,11 @@ chromeMocks.StorageArea.prototype.remove = function(keys) {
}, this);
};
-chromeMocks.StorageArea.prototype.clear = function() {
+chrome.StorageArea.prototype.clear = function() {
this.storage_ = null;
};
-/** @type {chromeMocks.StorageArea} */
-chromeMocks.storage.local = new chromeMocks.StorageArea();
+/** @type {chrome.StorageArea} */
+chrome.storage.local = new chrome.StorageArea();
-var originals_ = null;
-
-/**
- * Activates a list of Chrome components to mock
- * @param {Array<string>} components
- */
-chromeMocks.activate = function(components) {
- if (originals_) {
- throw new Error('chromeMocks.activate() can only be called once.');
- }
- originals_ = {};
- components.forEach(function(component) {
- if (!chromeMocks[component]) {
- throw new Error('No mocks defined for chrome.' + component);
- }
- originals_[component] = chrome[component];
- chrome[component] = chromeMocks[component];
- });
};
-
-chromeMocks.restore = function() {
- if (!originals_) {
- throw new Error('You must call activate() before restore().');
- }
- for (var components in originals_) {
- chrome[components] = originals_[components];
- }
- originals_ = null;
-};
-
-})();

Powered by Google App Engine
This is Rietveld 408576698