Index: chrome/browser/resources/google_now/background_test_util.js |
diff --git a/chrome/browser/resources/google_now/background_test_util.js b/chrome/browser/resources/google_now/background_test_util.js |
index f59c34ed15c2f8198e9bc28ee0d921ddce174f23..62b6e5e04ddb4fdb3795e3429c0689081b848809 100644 |
--- a/chrome/browser/resources/google_now/background_test_util.js |
+++ b/chrome/browser/resources/google_now/background_test_util.js |
@@ -22,4 +22,63 @@ chrome['runtime'] = { |
onInstalled: emptyListener, |
onStartup: emptyListener |
}; |
+ |
var storage = {}; |
+ |
+/** |
+ * Syntactic sugar for use with will() on a Mock4JS.Mock. |
+ * Creates an action for will() that invokes a callback that the tested code |
+ * passes to a mocked function. |
+ * @param {SaveMockArguments} savedArgs Arguments that will contain the |
+ * callback once the mocked function is called. |
+ * @param {number} callbackParameter Index of the callback parameter in |
+ * |savedArgs|. |
+ * @param {...Object} var_args Arguments to pass to the callback. |
+ * @return {CallFunctionAction} Action for use in will(). |
+ */ |
+function invokeCallback(savedArgs, callbackParameter, var_args) { |
+ var callbackArguments = Array.prototype.slice.call(arguments, 2); |
+ return callFunction(function() { |
+ savedArgs.arguments[callbackParameter].apply(null, callbackArguments); |
+ }); |
+} |
+ |
+/** |
+ * Mock4JS matcher object that matches the actual agrument and the expected |
+ * value iff their JSON represenations are same. |
+ * @param {Object} expectedValue Expected value. |
+ * @constructor |
+ */ |
+function MatchJSON(expectedValue) { |
+ this._expectedValue = expectedValue; |
arv (Not doing code reviews)
2013/07/11 20:59:44
Google3 style is to use trailing underscore.
vadimt
2013/07/11 21:28:10
Done.
|
+} |
+ |
+MatchJSON.prototype = { |
+ /** |
+ * Checks that JSON represenation of the actual and expected arguments are |
+ * same. |
+ * @param {Object} actualArgument The argument to match. |
+ * @return {boolean} Result of the comparison. |
+ */ |
+ argumentMatches: function(actualArgument) { |
+ return ( |
+ JSON.stringify(this._expectedValue) === JSON.stringify(actualArgument)); |
+ }, |
+ |
+ /** |
+ * Describes the matcher. |
+ * @return {string} Description of this Mock4JS matcher. |
+ */ |
+ describe: function() { |
+ return 'eqJSON(' + JSON.stringify(this._expectedValue) + ')'; |
+ } |
+}; |
+ |
+/** |
+ * Builds a MatchJSON agrument matcher for a given expected value. |
+ * @param {Object} expectedValue Expected value. |
+ * @return {MatchJSON} Resulting Mock4JS matcher. |
+ */ |
+function eqJSON(expectedValue) { |
+ return new MatchJSON(expectedValue); |
+} |