Chromium Code Reviews| Index: remoting/webapp/unittests/chrome_mocks.js |
| diff --git a/remoting/webapp/unittests/chrome_mocks.js b/remoting/webapp/unittests/chrome_mocks.js |
| index 6bdd7b5c15011b482c99174bce5f1fe9995a9eb6..e1d8b469c354698c7b56e30ea021479d9f0910e8 100644 |
| --- a/remoting/webapp/unittests/chrome_mocks.js |
| +++ b/remoting/webapp/unittests/chrome_mocks.js |
| @@ -7,18 +7,23 @@ |
| Entry = function() {}; |
| -(function(scope){ |
| +(function(){ |
| var chromeMocks = {}; |
| +/** |
| + * @constructor |
| + */ |
| chromeMocks.Event = function() { |
| this.listeners_ = []; |
| }; |
| +/** @param {Function} callback */ |
| chromeMocks.Event.prototype.addListener = function(callback) { |
| this.listeners_.push(callback); |
| }; |
| +/** @param {Function} callback */ |
| chromeMocks.Event.prototype.removeListener = function(callback) { |
| for (var i = 0; i < this.listeners_.length; i++) { |
| if (this.listeners_[i] === callback) { |
| @@ -28,28 +33,51 @@ chromeMocks.Event.prototype.removeListener = function(callback) { |
| } |
| }; |
| +/** |
| + * @param {...*} var_args |
| + * @return {void} |
| + */ |
| chromeMocks.Event.prototype.mock$fire = function(var_args) { |
| var params = Array.prototype.slice.call(arguments); |
| - this.listeners_.forEach(function(listener){ |
| - listener.apply(null, params); |
| - }); |
| + this.listeners_.forEach( |
| + /** @param {Function} listener */ |
| + function(listener){ |
| + listener.apply(null, params); |
| + }); |
| }; |
| +/** @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() {}; |
| -chromeMocks.runtime.Port.prototype.postMessage = function() {}; |
| +/** |
| + * @param {Object} message |
| + */ |
| +chromeMocks.runtime.Port.prototype.postMessage = function(message) {}; |
| + |
| +/** @type {chromeMocks.Event} */ |
| chromeMocks.runtime.onMessage = new chromeMocks.Event(); |
| -chromeMocks.runtime.sendMessage = function(extensionId, message, |
| + |
| +/** |
| + * @param {string?} extensionId |
| + * @param {*} message |
| + * @param {Object=} options |
| + * @param {function(*)=} responseCallback |
| + */ |
| +chromeMocks.runtime.sendMessage = function(extensionId, message, options, |
| responseCallback) { |
| base.debug.assert( |
| extensionId === null, |
| @@ -62,16 +90,24 @@ chromeMocks.runtime.sendMessage = function(extensionId, message, |
| }); |
| }; |
| +/** @type {string} */ |
| chromeMocks.runtime.id = 'extensionId'; |
| +/** @type {Object} */ |
| chromeMocks.storage = {}; |
| // Sample implementation of chrome.StorageArea according to |
| // https://developer.chrome.com/apps/storage#type-StorageArea |
| +/** @constructor */ |
| chromeMocks.StorageArea = function() { |
| + /** @type {Object} */ |
| this.storage_ = {}; |
| }; |
| +/** |
| + * @param {!Object} keys |
| + * @return {Array.<string>} |
|
kelvinp
2015/02/18 18:41:30
dbeam recently switch all Array.<string> into Arra
garykac
2015/02/19 01:48:45
Done.
|
| + */ |
| function getKeys(keys) { |
| if (typeof keys === 'string') { |
| return [keys]; |
| @@ -81,6 +117,10 @@ function getKeys(keys) { |
| return []; |
| } |
| +/** |
| + * @param {!Object} keys |
| + * @param {Function} onDone |
| + */ |
| chromeMocks.StorageArea.prototype.get = function(keys, onDone) { |
| if (!keys) { |
| onDone(base.deepCopy(this.storage_)); |
| @@ -88,30 +128,39 @@ chromeMocks.StorageArea.prototype.get = function(keys, onDone) { |
| } |
| var result = (typeof keys === 'object') ? keys : {}; |
| - getKeys(keys).forEach(function(key) { |
| - if (key in this.storage_) { |
| - result[key] = base.deepCopy(this.storage_[key]); |
| - } |
| - }, this); |
| + getKeys(keys).forEach( |
| + /** @param {string} key */ |
| + function(key) { |
| + if (key in this.storage_) { |
| + result[key] = base.deepCopy(this.storage_[key]); |
| + } |
| + }, this); |
| onDone(result); |
| }; |
| +/** @param {Object} value */ |
| chromeMocks.StorageArea.prototype.set = function(value) { |
| for (var key in value) { |
| this.storage_[key] = base.deepCopy(value[key]); |
| } |
| }; |
| +/** |
| + * @param {!Object} keys |
| + */ |
| chromeMocks.StorageArea.prototype.remove = function(keys) { |
| - getKeys(keys).forEach(function(key) { |
| - delete this.storage_[key]; |
| - }, this); |
| + getKeys(keys).forEach( |
| + /** @param {string} key */ |
| + function(key) { |
| + delete this.storage_[key]; |
| + }, this); |
| }; |
| chromeMocks.StorageArea.prototype.clear = function() { |
| this.storage_ = null; |
| }; |
| +/** @type {chromeMocks.StorageArea} */ |
| chromeMocks.storage.local = new chromeMocks.StorageArea(); |
| var originals_ = null; |
| @@ -144,6 +193,4 @@ chromeMocks.restore = function() { |
| originals_ = null; |
| }; |
| -scope.chromeMocks = chromeMocks; |
| - |
| -})(window); |
| +})(); |