summaryrefslogtreecommitdiffstats
path: root/chrome/browser/automation/automation_extension_function.h
diff options
context:
space:
mode:
authorjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-08 14:02:58 +0000
committerjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-08 14:02:58 +0000
commit4cfc1d9243eaf01a3b736fa13f55b7400a891fb4 (patch)
tree8f8da34f968fdf547aefc55b3f5d9e210b1a03b3 /chrome/browser/automation/automation_extension_function.h
parentbb76183f666753f186e5234ddea409971753c784 (diff)
downloadchromium_src-4cfc1d9243eaf01a3b736fa13f55b7400a891fb4.zip
chromium_src-4cfc1d9243eaf01a3b736fa13f55b7400a891fb4.tar.gz
chromium_src-4cfc1d9243eaf01a3b736fa13f55b7400a891fb4.tar.bz2
Modifying extension automation so that it is done through a particular
tab for all extension views. Previously, API routing to the automation client would only work for extension views that were contained in the particular ExternalTab instance being automated. This meant you couldn't test API calls from e.g. background pages. Also using async functions instead of the previous RVH-based hack. Updating one of the UI tests to make the API calls from a background page, to provide an end-to-end test of the new routing. This makes AutomationProvider::SetEnableAutomationExtension Windows-only, but it effectively always was since it was already dependent on ExternalTabContainer (indirectly, to provide a non-empty implementation of TabContentsDelegate::ForwardMessageToExternalHost). BUG=none TEST=ui_tests.exe, chrome_frame_tests.exe, chrome_frame_unittests.exe Review URL: http://codereview.chromium.org/366025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31403 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation/automation_extension_function.h')
-rw-r--r--chrome/browser/automation/automation_extension_function.h42
1 files changed, 31 insertions, 11 deletions
diff --git a/chrome/browser/automation/automation_extension_function.h b/chrome/browser/automation/automation_extension_function.h
index ed57ca1..faf125e 100644
--- a/chrome/browser/automation/automation_extension_function.h
+++ b/chrome/browser/automation/automation_extension_function.h
@@ -8,38 +8,49 @@
#define CHROME_BROWSER_AUTOMATION_AUTOMATION_EXTENSION_FUNCTION_H_
#include <string>
+#include <map>
#include "chrome/browser/extensions/extension_function.h"
class RenderViewHost;
+class TabContents;
// An extension function that pipes the extension API call through the
// automation interface, so that extensions can be tested using UITests.
-class AutomationExtensionFunction : public ExtensionFunction {
+class AutomationExtensionFunction : public AsyncExtensionFunction {
public:
AutomationExtensionFunction() { }
// ExtensionFunction implementation.
virtual void SetArgs(const Value* args);
virtual const std::string GetResult();
- virtual const std::string GetError();
- virtual void Run();
+ virtual bool RunImpl();
static ExtensionFunction* Factory();
+ // Enable API automation of selected APIs. Overridden extension API messages
+ // will be routed to the automation client attached to |api_handler_tab|.
+ //
// 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.
+ // functions). An empty list makes this function a no-op.
+ //
+ // Note that all calls to this function are additive. Functions previously
+ // enabled will remain enabled until you call Disable().
//
- // 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);
+ // Calling this function after enabling one or more functions with a
+ // tab other than the one previously used is an error.
+ static void Enable(TabContents* api_handler_tab,
+ const std::vector<std::string>& functions_enabled);
+
+ // Restore the default API function implementations and reset the stored
+ // API handler.
+ static void Disable();
// Intercepts messages sent from the external host to check if they
// are actually responses to extension API calls. If they are, redirects
- // the message to view_host->SendExtensionResponse and returns true,
- // otherwise returns false to indicate the message was not intercepted.
+ // the message to respond to the pending asynchronous API call and returns
+ // true, otherwise returns false to indicate the message was not intercepted.
static bool InterceptMessageFromExternalHost(RenderViewHost* view_host,
const std::string& message,
const std::string& origin,
@@ -48,8 +59,17 @@ class AutomationExtensionFunction : public ExtensionFunction {
private:
~AutomationExtensionFunction() {}
- static bool enabled_;
+ // Weak reference, lifetime managed by the ExternalTabContainer instance
+ // owning the TabContents in question.
+ static TabContents* api_handler_tab_;
+
+ typedef std::map<int, scoped_refptr<AutomationExtensionFunction> >
+ PendingFunctionsMap;
+ static PendingFunctionsMap pending_functions_;
+
std::string args_;
+ std::string json_result_;
+
DISALLOW_COPY_AND_ASSIGN(AutomationExtensionFunction);
};