summaryrefslogtreecommitdiffstats
path: root/chrome/test/data
diff options
context:
space:
mode:
authorscr@chromium.org <scr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-15 01:32:35 +0000
committerscr@chromium.org <scr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-15 01:32:35 +0000
commit63f79cd61463e60b18b3d4208a4ff3922b286818 (patch)
treefcbf47c3584f8842004fca692e44ef131b2ad42b /chrome/test/data
parentde876eb21e86909393f56c2a0025fc73660073d3 (diff)
downloadchromium_src-63f79cd61463e60b18b3d4208a4ff3922b286818.zip
chromium_src-63f79cd61463e60b18b3d4208a4ff3922b286818.tar.gz
chromium_src-63f79cd61463e60b18b3d4208a4ff3922b286818.tar.bz2
Seed test for SyncUI: sign in successfully with mocks.
R=binji@chromium.org BUG=102750 TEST=browser_tests --gtest_filter=SyncSetupWebUITest.* Review URL: http://codereview.chromium.org/8503003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110006 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/data')
-rw-r--r--chrome/test/data/webui/async_gen.js56
-rw-r--r--chrome/test/data/webui/chrome_send_browsertest.js8
-rw-r--r--chrome/test/data/webui/print_preview.js79
-rw-r--r--chrome/test/data/webui/test_api.js47
4 files changed, 83 insertions, 107 deletions
diff --git a/chrome/test/data/webui/async_gen.js b/chrome/test/data/webui/async_gen.js
index bf29772..13929b8 100644
--- a/chrome/test/data/webui/async_gen.js
+++ b/chrome/test/data/webui/async_gen.js
@@ -101,25 +101,13 @@ TEST_F('WebUIBrowserAsyncGenTest', 'TestContinue', function() {
// Test that runAllActionsAsync can be called with multiple functions, and with
// bound, saved, or mixed arguments.
TEST_F('WebUIBrowserAsyncGenTest', 'TestRunAllActionsAsyncMock', function() {
- /**
- * Create a handler class with empty methods to allow mocking to register
- * expectations and for registration of handlers with chrome.send.
- * @constructor
- */
- function MockHandler() {}
-
- MockHandler.prototype = {
- testBoundArgs: function() {},
- testSavedArgs: function() {},
- testMixedArgs: function() {},
- };
-
- var mockHandler = mock(MockHandler);
- registerMockMessageCallbacks(mockHandler, MockHandler);
-
+ this.makeAndRegisterMockHandler(['testBoundArgs',
+ 'testSavedArgs',
+ 'testMixedArgs',
+ ]);
// Bind some arguments.
var var1, var2;
- mockHandler.expects(once()).testBoundArgs().
+ this.mockHandler.expects(once()).testBoundArgs().
will(runAllActionsAsync(WhenTestDone.DEFAULT,
callFunction(function(args) {
var1 = args[0];
@@ -132,7 +120,7 @@ TEST_F('WebUIBrowserAsyncGenTest', 'TestRunAllActionsAsyncMock', function() {
var var3, var4;
var savedArgs = new SaveMockArguments();
var savedArgs2 = new SaveMockArguments();
- mockHandler.expects(once()).testSavedArgs(
+ this.mockHandler.expects(once()).testSavedArgs(
savedArgs.match(savedArgs2.match(eq(['passedVal1'])))).
will(runAllActionsAsync(
WhenTestDone.DEFAULT,
@@ -145,7 +133,7 @@ TEST_F('WebUIBrowserAsyncGenTest', 'TestRunAllActionsAsyncMock', function() {
// Receive some saved arguments and some bound arguments.
var var5, var6, var7, var8;
- mockHandler.expects(once()).testMixedArgs(
+ this.mockHandler.expects(once()).testMixedArgs(
savedArgs.match(savedArgs2.match(eq('passedVal2')))).
will(runAllActionsAsync(
WhenTestDone.DEFAULT,
@@ -198,20 +186,10 @@ function setTestRanTrue() {
// Test overriding globals.
TEST_F('WebUIBrowserAsyncGenTest', 'TestRegisterMockGlobals', function() {
- /**
- * Create a mock class to describe the globals to mock.
- * @constructor
- */
- function MockGlobals() {}
-
- MockGlobals.prototype = {
- setTestRanTrue: function() {},
- };
+ this.makeAndRegisterMockGlobals(['setTestRanTrue']);
// Mock the setTestRanTrue global function.
- var mockGlobals = mock(MockGlobals);
- registerMockGlobals(mockGlobals, MockGlobals);
- mockGlobals.expects(once()).setTestRanTrue().
+ this.mockGlobals.expects(once()).setTestRanTrue().
will(runAllActionsAsync(
WhenTestDone.ALWAYS,
callGlobalWithSavedArgs(null, 'setTestRanTrue'),
@@ -288,20 +266,8 @@ WebUIBrowserAsyncGenDeferredToGlobalTest.prototype = {
/** @inheritDoc */
setUp: function() {
- /**
- * Create a mock class to describe the globals to mock.
- * @constructor
- */
- function MockGlobals() {}
-
- MockGlobals.prototype = {
- setTestRanTrue: function() {},
- };
-
- // Mock the setTestRanTrue global function.
- var mockGlobals = mock(MockGlobals);
- registerMockGlobals(mockGlobals, MockGlobals);
- mockGlobals.expects(once()).setTestRanTrue().
+ this.makeAndRegisterMockGlobals(['setTestRanTrue']);
+ this.mockGlobals.expects(once()).setTestRanTrue().
will(runAllActionsAsync(
WhenTestDone.ALWAYS,
callGlobalWithSavedArgs(null, 'setTestRanTrue'),
diff --git a/chrome/test/data/webui/chrome_send_browsertest.js b/chrome/test/data/webui/chrome_send_browsertest.js
index a20eb5f..c1e8933 100644
--- a/chrome/test/data/webui/chrome_send_browsertest.js
+++ b/chrome/test/data/webui/chrome_send_browsertest.js
@@ -32,13 +32,7 @@ ChromeSendWebUITest.prototype = {
/** @inheritDoc */
setUp: function() {
- // Set up a mock handler class to catch the 'checkSend' message.
- function MockHandler() {}
- MockHandler.prototype = {
- checkSend: function() {},
- };
- this.mockHandler = mock(MockHandler);
- registerMockMessageCallbacks(this.mockHandler, MockHandler);
+ this.makeAndRegisterMockHandler(['checkSend']);
}
};
diff --git a/chrome/test/data/webui/print_preview.js b/chrome/test/data/webui/print_preview.js
index 7b0ce33..596e8f0 100644
--- a/chrome/test/data/webui/print_preview.js
+++ b/chrome/test/data/webui/print_preview.js
@@ -26,43 +26,30 @@ PrintPreviewWebUITest.prototype = {
* @override
*/
preLoad: function() {
- // TODO(scr) remove this after tests pass consistently.
- console.info('preLoad');
-
- /**
- * Create a handler class with empty methods to allow mocking to register
- * expectations and for registration of handlers with chrome.send.
- * @constructor
- */
- function MockPrintPreviewHandler() {}
-
- MockPrintPreviewHandler.prototype = {
- getDefaultPrinter: function() {},
- getPrinters: function() {},
- getPreview: function(settings, draft_page_count, modifiable) {},
- print: function(settings) {},
- getPrinterCapabilities: function(printerName) {},
- showSystemDialog: function() {},
- morePrinters: function() {},
- signIn: function() {},
- addCloudPrinter: function() {},
- manageCloudPrinters: function() {},
- manageLocalPrinters: function() {},
- closePrintPreviewTab: function() {},
- hidePreview: function() {},
- cancelPendingPrintRequest: function() {},
- saveLastPrinter: function(name, cloud_print_data) {},
- };
-
- // Create the actual mock and register stubs for methods expected to be
- // called before tests run. Specific expectations can be made in the
- // tests themselves.
- var mockHandler = this.mockHandler = mock(MockPrintPreviewHandler);
- mockHandler.stubs().getDefaultPrinter().
+ this.makeAndRegisterMockHandler(['getDefaultPrinter',
+ 'getPrinters',
+ 'getPreview',
+ 'print',
+ 'getPrinterCapabilities',
+ 'showSystemDialog',
+ 'morePrinters',
+ 'signIn',
+ 'addCloudPrinter',
+ 'manageCloudPrinters',
+ 'manageLocalPrinters',
+ 'closePrintPreviewTab',
+ 'hidePreview',
+ 'cancelPendingPrintRequest',
+ 'saveLastPrinter',
+ ]);
+
+ // Register stubs for methods expected to be called before tests
+ // run. Specific expectations can be made in the tests themselves.
+ this.mockHandler.stubs().getDefaultPrinter().
will(callFunction(function() {
setDefaultPrinter('FooDevice');
}));
- mockHandler.stubs().getPrinterCapabilities(NOT_NULL).
+ this.mockHandler.stubs().getPrinterCapabilities(NOT_NULL).
will(callFunction(function() {
updateWithPrinterCapabilities({
disableColorOption: true,
@@ -72,12 +59,12 @@ PrintPreviewWebUITest.prototype = {
});
}));
var savedArgs = new SaveMockArguments();
- mockHandler.stubs().getPreview(savedArgs.match(NOT_NULL)).
+ this.mockHandler.stubs().getPreview(savedArgs.match(NOT_NULL)).
will(callFunctionWithSavedArgs(savedArgs, function(args) {
updatePrintPreview(1, JSON.parse(args[0]).requestID);
}));
- mockHandler.stubs().getPrinters().
+ this.mockHandler.stubs().getPrinters().
will(callFunction(function() {
setPrinters([{
printerName: 'FooName',
@@ -89,28 +76,12 @@ PrintPreviewWebUITest.prototype = {
]);
}));
- // Register mock as a handler of the chrome.send messages.
- registerMockMessageCallbacks(mockHandler, MockPrintPreviewHandler);
-
- /**
- * Create a class to hold global functions to watch for.
- * @constructor
- */
- function MockGlobals() {}
-
- MockGlobals.prototype = {
- updateWithPrinterCapabilities: function(settingInfo) {},
- };
-
- var mockGlobals = this.mockGlobals = mock(MockGlobals);
- mockGlobals.stubs().updateWithPrinterCapabilities(
+ this.makeAndRegisterMockGlobals(['updateWithPrinterCapabilities']);
+ this.mockGlobals.stubs().updateWithPrinterCapabilities(
savedArgs.match(ANYTHING)).
will(callGlobalWithSavedArgs(
savedArgs, 'updateWithPrinterCapabilities'));
- // Register globals to mock out for us.
- registerMockGlobals(mockGlobals, MockGlobals);
-
// Override checkCompatiblePluginExists to return a value consistent with
// the state being tested and stub out the pdf viewer if it doesn't exist,
// such as on non-official builds. When the plugin exists, use the real
diff --git a/chrome/test/data/webui/test_api.js b/chrome/test/data/webui/test_api.js
index baf629a..f5dbee4 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();