Chromium Code Reviews| Index: chrome/test/data/webui/mock_controller.js |
| diff --git a/chrome/test/data/webui/mock_controller.js b/chrome/test/data/webui/mock_controller.js |
| index 378fdc353967085027d07a0cb999b4ff059158af..23c038c12bb8e328584f165278378c129f4cc0ce 100644 |
| --- a/chrome/test/data/webui/mock_controller.js |
| +++ b/chrome/test/data/webui/mock_controller.js |
| @@ -10,8 +10,20 @@ |
| function MockMethod() { |
| var fn = function() { |
| var args = Array.prototype.slice.call(arguments); |
| + var callbacks = |
| + args.filter(function(arg) { return (typeof arg == 'function'); }); |
| + |
| + if (callbacks.length > 1) { |
| + console.error('Only support mocking function with at most one callback.'); |
| + return; |
| + } |
| + |
| fn.recordCall(args); |
| - return this.returnValue; |
| + if (callbacks.length == 1) { |
| + callbacks[0].apply(undefined, fn.callbackData); |
| + return; |
| + } |
| + return fn.returnValue; |
| }; |
| /** |
| @@ -34,6 +46,13 @@ function MockMethod() { |
| */ |
| fn.returnValue = undefined; |
| + /** |
| + * List of arguments for callback function. |
| + * @type {!Array.<!Array>} |
| + * @private |
|
kevers
2014/09/30 18:12:03
Based on direct access from test case, this is not
bshe
2014/09/30 21:59:48
Dooh. It should not be private.
|
| + */ |
| + fn.callbackData = []; |
| + |
| fn.__proto__ = MockMethod.prototype; |
| return fn; |
| } |
| @@ -45,7 +64,7 @@ MockMethod.prototype = { |
| */ |
| addExpectation: function() { |
| var args = Array.prototype.slice.call(arguments); |
| - this.expectations_.push(args); |
| + this.expectations_.push(args.filter(this.notFunction_)); |
| }, |
| /** |
| @@ -53,7 +72,7 @@ MockMethod.prototype = { |
| * @param {!Array} args. |
| */ |
| recordCall: function(args) { |
| - this.calls_.push(args); |
| + this.calls_.push(args.filter(this.notFunction_)); |
| }, |
| /** |
| @@ -84,6 +103,15 @@ MockMethod.prototype = { |
| validateCall: function(index, expected, observed) { |
| assertDeepEquals(expected, observed); |
| }, |
| + |
| + /** |
| + * Test if arg is a function. |
| + * @param {*} arg The argument to test. |
| + * @return True if arg is not function type. |
| + */ |
| + notFunction_: function(arg) { |
| + return typeof arg != 'function'; |
| + } |
| }; |
| /** |