diff options
author | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-23 19:16:20 +0000 |
---|---|---|
committer | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-23 19:16:20 +0000 |
commit | 50f53164ebbceb30b69578e96e863375f5cb4f9b (patch) | |
tree | 853541075c0a2ac5adb3d4f3a389401d92405edf /chrome | |
parent | 117fd71c37c932c5ffcbf59eb42d118d3dfb431f (diff) | |
download | chromium_src-50f53164ebbceb30b69578e96e863375f5cb4f9b.zip chromium_src-50f53164ebbceb30b69578e96e863375f5cb4f9b.tar.gz chromium_src-50f53164ebbceb30b69578e96e863375f5cb4f9b.tar.bz2 |
Enhance extension UI testing by enabling you to select which extension
APIs to forward (and thus stub out in your test), while others will
keep being fulfilled as per usual. This lets you build tests that
stub out one piece of behavior while testing that some side effects of
another API happen as expected.
BUG=none
TEST=Run ui_tests.exe
Review URL: http://codereview.chromium.org/314015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29919 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/automation/automation_extension_function.cc | 13 | ||||
-rw-r--r-- | chrome/browser/automation/automation_extension_function.h | 12 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 5 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider.h | 3 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_uitest.cc | 27 | ||||
-rw-r--r-- | chrome/test/automation/automation_messages_internal.h | 7 | ||||
-rw-r--r-- | chrome/test/automation/automation_proxy.cc | 5 | ||||
-rw-r--r-- | chrome/test/automation/automation_proxy.h | 15 |
8 files changed, 68 insertions, 19 deletions
diff --git a/chrome/browser/automation/automation_extension_function.cc b/chrome/browser/automation/automation_extension_function.cc index 4bbc89f..70e886a 100644 --- a/chrome/browser/automation/automation_extension_function.cc +++ b/chrome/browser/automation/automation_extension_function.cc @@ -51,10 +51,15 @@ ExtensionFunction* AutomationExtensionFunction::Factory() { return new AutomationExtensionFunction(); } -void AutomationExtensionFunction::SetEnabled(bool enabled) { - if (enabled) { +void AutomationExtensionFunction::SetEnabled( + const std::vector<std::string>& functions_enabled) { + if (functions_enabled.size() > 0) { std::vector<std::string> function_names; - ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names); + if (functions_enabled.size() == 1 && functions_enabled[0] == "*") { + ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names); + } else { + function_names = functions_enabled; + } for (std::vector<std::string>::iterator it = function_names.begin(); it != function_names.end(); it++) { @@ -64,7 +69,7 @@ void AutomationExtensionFunction::SetEnabled(bool enabled) { // current profile is not that. bool result = ExtensionFunctionDispatcher::OverrideFunction( *it, AutomationExtensionFunction::Factory); - DCHECK(result); + LOG_IF(WARNING, !result) << "Failed to override API function: " << *it; } } else { ExtensionFunctionDispatcher::ResetFunctions(); diff --git a/chrome/browser/automation/automation_extension_function.h b/chrome/browser/automation/automation_extension_function.h index f48adff..d6fac7d 100644 --- a/chrome/browser/automation/automation_extension_function.h +++ b/chrome/browser/automation/automation_extension_function.h @@ -27,10 +27,14 @@ class AutomationExtensionFunction : public ExtensionFunction { static ExtensionFunction* Factory(); - // If enabled, we set an instance of this function as the functor - // for all function names in ExtensionFunctionFactoryRegistry. - // If disabled, we restore the initial functions. - static void SetEnabled(bool enabled); + // If the list of enabled functions is non-empty, we enable according to the + // list ("*" means enable all, otherwise we enable individual named + // functions). If empty, we restore the initial functions. + // + // Note that all calls to this function, except a call with the empty list, + // are additive. Functions previously enabled will remain enabled until + // you clear all function forwarding by specifying the empty list. + static void SetEnabled(const std::vector<std::string>& functions_enabled); // Intercepts messages sent from the external host to check if they // are actually responses to extension API calls. If they are, redirects diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 891b6b7..c28322f 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -1901,8 +1901,9 @@ void AutomationProvider::SavePackageShouldPromptUser(bool should_prompt) { SavePackage::SetShouldPromptUser(should_prompt); } -void AutomationProvider::SetEnableExtensionAutomation(bool automation_enabled) { - AutomationExtensionFunction::SetEnabled(automation_enabled); +void AutomationProvider::SetEnableExtensionAutomation( + const std::vector<std::string>& functions_enabled) { + AutomationExtensionFunction::SetEnabled(functions_enabled); } void AutomationProvider::GetWindowTitle(int handle, string16* text) { diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index 1b5ee7d..44ee790 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -456,7 +456,8 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, void SavePackageShouldPromptUser(bool should_prompt); // Enables extension automation (for e.g. UITests). - void SetEnableExtensionAutomation(bool automation_enabled); + void SetEnableExtensionAutomation( + const std::vector<std::string>& functions_enabled); void GetWindowTitle(int handle, string16* text); diff --git a/chrome/browser/extensions/extension_uitest.cc b/chrome/browser/extensions/extension_uitest.cc index 5972f9e..4a16cc8 100644 --- a/chrome/browser/extensions/extension_uitest.cc +++ b/chrome/browser/extensions/extension_uitest.cc @@ -33,6 +33,10 @@ static const char kTestDirectoryBrowserEvent[] = // extension API calls so that behavior can be tested deterministically // through code, instead of having to contort the browser into a state // suitable for testing. +// +// By default, makes Chrome forward all Chrome Extension API function calls +// via the automation interface. To override this, call set_functions_enabled() +// with a list of function names that should be forwarded, template <class ParentTestType> class ExtensionUITest : public ParentTestType { public: @@ -41,15 +45,21 @@ class ExtensionUITest : public ParentTestType { filename = filename.AppendASCII(extension_path); launch_arguments_.AppendSwitchWithValue(switches::kLoadExtension, filename.value()); + functions_enabled_.push_back("*"); + } + + void set_functions_enabled( + const std::vector<std::string>& functions_enabled) { + functions_enabled_ = functions_enabled; } void SetUp() { ParentTestType::SetUp(); - automation()->SetEnableExtensionAutomation(true); + automation()->SetEnableExtensionAutomation(functions_enabled_); } void TearDown() { - automation()->SetEnableExtensionAutomation(false); + automation()->SetEnableExtensionAutomation(std::vector<std::string>()); ParentTestType::TearDown(); } @@ -84,6 +94,10 @@ class ExtensionUITest : public ParentTestType { virtual void DoAdditionalPreNavigateSetup(TabProxy* tab) { } + protected: + // Extension API functions that we want to take over. Defaults to all. + std::vector<std::string> functions_enabled_; + private: DISALLOW_COPY_AND_ASSIGN(ExtensionUITest); }; @@ -103,6 +117,15 @@ class SimpleApiCallExtensionTest : public SingleMessageExtensionUITest { : SingleMessageExtensionUITest(kTestDirectorySimpleApiCall) { } + void SetUp() { + // Set just this one function explicitly to be forwarded, as a test of + // the selective forwarding. The next test will leave the default to test + // universal forwarding. + functions_enabled_.clear(); + functions_enabled_.push_back("tabs.remove"); + SingleMessageExtensionUITest::SetUp(); + } + private: DISALLOW_COPY_AND_ASSIGN(SimpleApiCallExtensionTest); }; diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h index 174e1d0..69e9c51 100644 --- a/chrome/test/automation/automation_messages_internal.h +++ b/chrome/test/automation/automation_messages_internal.h @@ -906,7 +906,10 @@ IPC_BEGIN_MESSAGES(Automation) // Used to put the browser into "extension automation mode" for the // current profile, or turn off the mode. IPC_MESSAGE_ROUTED1(AutomationMsg_SetEnableExtensionAutomation, - bool /* true to enable extension automation */) + std::vector<std::string> /* empty to disable automation, + non-empty to enable automation + of the specified API + functions */) // This message tells the browser to start using the new proxy configuration // represented by the given JSON string. The parameters used in the JSON @@ -1065,7 +1068,7 @@ IPC_BEGIN_MESSAGES(Automation) AutomationMsg_GoForwardBlockUntilNavigationsComplete, int, int, AutomationMsg_NavigationResponseValues) - // This message is used by automaton clients to upload histogram data to the + // This message is used by automation clients to upload histogram data to the // browser process. IPC_MESSAGE_ROUTED1(AutomationMsg_RecordHistograms, std::vector<std::string> /* histogram_list */) diff --git a/chrome/test/automation/automation_proxy.cc b/chrome/test/automation/automation_proxy.cc index 28cfe37..4658bf3 100644 --- a/chrome/test/automation/automation_proxy.cc +++ b/chrome/test/automation/automation_proxy.cc @@ -220,9 +220,10 @@ bool AutomationProxy::SavePackageShouldPromptUser(bool should_prompt) { return Send(new AutomationMsg_SavePackageShouldPromptUser(0, should_prompt)); } -bool AutomationProxy::SetEnableExtensionAutomation(bool enable_automation) { +bool AutomationProxy::SetEnableExtensionAutomation( + const std::vector<std::string>& functions_enabled) { return Send( - new AutomationMsg_SetEnableExtensionAutomation(0, enable_automation)); + new AutomationMsg_SetEnableExtensionAutomation(0, functions_enabled)); } bool AutomationProxy::GetBrowserWindowCount(int* num_windows) { diff --git a/chrome/test/automation/automation_proxy.h b/chrome/test/automation/automation_proxy.h index 1e02cff..cf40606 100644 --- a/chrome/test/automation/automation_proxy.h +++ b/chrome/test/automation/automation_proxy.h @@ -180,11 +180,22 @@ class AutomationProxy : public IPC::Channel::Listener, // sent. bool SavePackageShouldPromptUser(bool should_prompt); - // Turn extension automation mode on and off. When extension automation + // Configure extension automation mode. When extension automation // mode is turned on, the automation host can overtake extension API calls // e.g. to make UI tests for extensions easier to write. Returns true if // the message is successfully sent. - bool SetEnableExtensionAutomation(bool enable_automation); + // + // The parameter can take the following types of values: + // a) An empty list to turn off extension automation. + // b) A list with one item, "*", to turn extension automation on for all + // functions. + // c) A list with one or more items which are the names of Chrome Extension + // API functions that should be forwarded over the automation interface. + // Other functions will continue to be fulfilled as normal. This lets you + // write tests where some functionality continues to function as normal, + // and other functionality is mocked out by the test. + bool SetEnableExtensionAutomation( + const std::vector<std::string>& functions_enabled); // Returns the ID of the automation IPC channel, so that it can be // passed to the app as a launch parameter. |