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

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: Use makeAndRegisterMockHandler in new ChromeSendWebUITest. 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
« no previous file with comments | « chrome/test/data/webui/print_preview.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 baf629a6e8dd024f098540288b980cf4bc333fca..f5dbee4993e22996ee2a8690cb497b51d18adcc1 100644
--- a/chrome/test/data/webui/test_api.js
+++ b/chrome/test/data/webui/test_api.js
@@ -121,6 +121,31 @@ var testing = {};
extraLibraries: [],
/**
+ * 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|.
+ * @see registerMockGlobals
+ */
+ makeAndRegisterMockGlobals: function(functionNames) {
+ 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}
@@ -389,6 +414,7 @@ var testing = {};
* @param {string} name The name of the message to route to this |callback|.
* @param {Object} object Pass as |this| when calling the |callback|.
* @param {function(...)} callback Called by {@code chrome.send}.
+ * @see overrideGlobal
*/
function registerMockGlobal(name, object, callback) {
assertEquals(undefined, globalOverrides[name]);
@@ -402,12 +428,31 @@ 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.
* @param {Mock4JS.Mock} mockObject The mock to register callbacks against.
* @param {function(new:Object)} mockClass Constructor for the mocked class.
- * @see registerMessageCallback
+ * @see registerMockGlobal
*/
function registerMockGlobals(mockObject, mockClass) {
var mockProxy = mockObject.proxy();
« no previous file with comments | « 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