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

Unified Diff: chrome/test/data/webui/test_api.js

Issue 8503003: Seed test for SyncUI: sign in successfully with mocks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Made some utility methods to make mockHandler and mockGlobals generation simpler. Created 9 years, 1 month 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: chrome/test/data/webui/test_api.js
diff --git a/chrome/test/data/webui/test_api.js b/chrome/test/data/webui/test_api.js
index 140efe7d4b5d9c1743d9ac1f96e095b6b39ba325..e5556d699435c5fd9f8cf35822c8c9ddd58b1672 100644
--- a/chrome/test/data/webui/test_api.js
+++ b/chrome/test/data/webui/test_api.js
@@ -110,6 +110,30 @@ var testing = {};
testShouldFail: false,
/**
+ * Create a new class to handle |messageNames|, assign it to
+ * |this.mockHandler|, register its messages and return it.
+ * @return {Mock} Mock handler class assigned to |this.mockHandler|.
+ */
+ makeAndRegisterMockHandler: function(messageNames) {
+ var MockClass = makeMockClass(messageNames);
+ this.mockHandler = mock(MockClass);
+ registerMockMessageCallbacks(this.mockHandler, MockClass);
+ return this.mockHandler;
+ },
+
+ /**
+ * Create a new class to handle |functionNames|, assign it to
+ * |this.mockGlobals|, register its global overrides, and return it.
+ * @return {Mock} Mock handler class assigned to |this.mockGlobals|.
+ */
+ makeAndRegisterMockGlobals: function(functionNames) {
James Hawkins 2011/11/09 17:15:56 Is this referring to JS globals? Why are we mocki
James Hawkins 2011/11/10 00:24:43 Still not answered.
Sheridan Rawlins 2011/11/10 02:02:12 Yes. This gives the facility to stub out an exist
+ var MockClass = makeMockClass(functionNames);
+ this.mockGlobals = mock(MockClass);
+ registerMockGlobals(this.mockGlobals, MockClass);
+ return this.mockGlobals;
+ },
+
+ /**
* Override this method to perform initialization during preload (such as
* creating mocks and registering handlers).
* @type {Function}
@@ -388,6 +412,25 @@ var testing = {};
}
/**
+ * Empty function for use in making mocks.
+ * @const
+ */
+ function emptyFunction() {}
+
+ /**
+ * Make a mock from the supplied |methodNames| array.
+ * @param {Array.<string>} methodNames Array of names of methods to mock.
+ * @return {Function} Constructor with prototype filled in with methods
+ * matching |methodNames|.
+ */
+ function makeMockClass(methodNames) {
+ function MockConstructor() {}
+ for(var i = 0; i < methodNames.length; i++)
+ MockConstructor.prototype[methodNames[i]] = emptyFunction;
+ return MockConstructor;
+ }
+
+ /**
* Register all methods of {@code mockClass.prototype} as overrides to global
* functions of the same name as the method, using the proxy of the
* |mockObject| to handle the functions.
« chrome/test/data/webui/async_gen.js ('K') | « chrome/test/data/webui/print_preview.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698