summaryrefslogtreecommitdiffstats
path: root/chrome/test
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/test
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/test')
-rw-r--r--chrome/test/automation/automation_messages_internal.h20
-rw-r--r--chrome/test/automation/automation_proxy.cc6
-rw-r--r--chrome/test/automation/automation_proxy.h17
-rw-r--r--chrome/test/automation/tab_proxy.cc9
-rw-r--r--chrome/test/automation/tab_proxy.h24
-rw-r--r--chrome/test/data/extensions/uitest/roundtrip_api_call/background.html11
-rw-r--r--chrome/test/data/extensions/uitest/roundtrip_api_call/manifest.json3
-rw-r--r--chrome/test/data/extensions/uitest/roundtrip_api_call/test.html9
8 files changed, 63 insertions, 36 deletions
diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h
index f7ded561..0616aea 100644
--- a/chrome/test/automation/automation_messages_internal.h
+++ b/chrome/test/automation/automation_messages_internal.h
@@ -905,13 +905,19 @@ IPC_BEGIN_MESSAGES(Automation)
// value is the number of windows.
IPC_SYNC_MESSAGE_ROUTED0_1(AutomationMsg_NormalBrowserWindowCount, int)
- // Used to put the browser into "extension automation mode" for the
- // current profile, or turn off the mode.
- IPC_MESSAGE_ROUTED1(AutomationMsg_SetEnableExtensionAutomation,
- std::vector<std::string> /* empty to disable automation,
- non-empty to enable automation
- of the specified API
- functions */)
+ // Used to put the browser into "extension automation mode" for a given
+ // set of Chrome Extensions API functions for the current profile, or turn
+ // off automation mode. The specified tab is used as the conduit for all
+ // automated API functions. It must be an external tab (as in
+ // AutomationMsg_CreateExternalTab).
+ IPC_MESSAGE_ROUTED2(AutomationMsg_SetEnableExtensionAutomation,
+ // Tab handle.
+ int,
+ // Empty to disable automation, non-empty to enable
+ // automation of the specified API functions, single
+ // entry of "*" to enable automation of all API
+ // functions.
+ std::vector<std::string>)
// This message tells the browser to start using the new proxy configuration
// represented by the given JSON string. The parameters used in the JSON
diff --git a/chrome/test/automation/automation_proxy.cc b/chrome/test/automation/automation_proxy.cc
index 698f969..6dd8032 100644
--- a/chrome/test/automation/automation_proxy.cc
+++ b/chrome/test/automation/automation_proxy.cc
@@ -220,12 +220,6 @@ bool AutomationProxy::SavePackageShouldPromptUser(bool should_prompt) {
return Send(new AutomationMsg_SavePackageShouldPromptUser(0, should_prompt));
}
-bool AutomationProxy::SetEnableExtensionAutomation(
- const std::vector<std::string>& functions_enabled) {
- return Send(
- new AutomationMsg_SetEnableExtensionAutomation(0, functions_enabled));
-}
-
bool AutomationProxy::GetBrowserWindowCount(int* num_windows) {
if (!num_windows) {
NOTREACHED();
diff --git a/chrome/test/automation/automation_proxy.h b/chrome/test/automation/automation_proxy.h
index 5c2d8ab..312c4b0 100644
--- a/chrome/test/automation/automation_proxy.h
+++ b/chrome/test/automation/automation_proxy.h
@@ -181,23 +181,6 @@ class AutomationProxy : public IPC::Channel::Listener,
// sent.
bool SavePackageShouldPromptUser(bool should_prompt);
- // 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.
- //
- // 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.
const std::string& channel_id() const { return channel_id_; }
diff --git a/chrome/test/automation/tab_proxy.cc b/chrome/test/automation/tab_proxy.cc
index 1852375..43246ea 100644
--- a/chrome/test/automation/tab_proxy.cc
+++ b/chrome/test/automation/tab_proxy.cc
@@ -356,6 +356,15 @@ bool TabProxy::ExecuteAndExtractValue(const std::wstring& frame_xpath,
return *value != NULL;
}
+bool TabProxy::SetEnableExtensionAutomation(
+ const std::vector<std::string>& functions_enabled) {
+ if (!is_valid())
+ return false;
+
+ return sender_->Send(new AutomationMsg_SetEnableExtensionAutomation(
+ 0, handle_, functions_enabled));
+}
+
bool TabProxy::GetConstrainedWindowCount(int* count) const {
if (!is_valid())
return false;
diff --git a/chrome/test/automation/tab_proxy.h b/chrome/test/automation/tab_proxy.h
index 1eaabea..7693e60 100644
--- a/chrome/test/automation/tab_proxy.h
+++ b/chrome/test/automation/tab_proxy.h
@@ -83,6 +83,30 @@ class TabProxy : public AutomationResourceProxy {
const std::wstring& jscript,
Value** value);
+ // 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.
+ //
+ // Note that API calls in _any_ extension view will be routed to the current
+ // tab. This is to enable UI testing of e.g. extension background pages.
+ //
+ // Enabling extension automation from more than one tab is an error.
+ //
+ // You must disable extension automation before destroying the tab.
+ //
+ // 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);
+
// Navigates to a url. This method accepts the same kinds of URL input that
// can be passed to Chrome on the command line. This is a synchronous call and
// hence blocks until the navigation completes.
diff --git a/chrome/test/data/extensions/uitest/roundtrip_api_call/background.html b/chrome/test/data/extensions/uitest/roundtrip_api_call/background.html
new file mode 100644
index 0000000..0c4cdb4
--- /dev/null
+++ b/chrome/test/data/extensions/uitest/roundtrip_api_call/background.html
@@ -0,0 +1,11 @@
+YOU SHOULD NOT BE SEEING THIS, IT'S A BACKGROUND PAGE!!!
+
+<script type="text/javascript">
+function doStuff() {
+ function getSelectedCallback(tab) {
+ chrome.tabs.remove(tab.id);
+ }
+
+ chrome.tabs.getSelected(undefined, getSelectedCallback);
+}
+</script>
diff --git a/chrome/test/data/extensions/uitest/roundtrip_api_call/manifest.json b/chrome/test/data/extensions/uitest/roundtrip_api_call/manifest.json
index 67f9e13..ef87bfe 100644
--- a/chrome/test/data/extensions/uitest/roundtrip_api_call/manifest.json
+++ b/chrome/test/data/extensions/uitest/roundtrip_api_call/manifest.json
@@ -3,5 +3,6 @@
"version": "1.0.0.0",
"name": "Roundtrip ApiCall Test Extension",
"description": "An extension for an extension UITest.",
- "permissions": ["tabs"]
+ "permissions": ["tabs"],
+ "background_page": "background.html"
}
diff --git a/chrome/test/data/extensions/uitest/roundtrip_api_call/test.html b/chrome/test/data/extensions/uitest/roundtrip_api_call/test.html
index a81b9a2..247e934 100644
--- a/chrome/test/data/extensions/uitest/roundtrip_api_call/test.html
+++ b/chrome/test/data/extensions/uitest/roundtrip_api_call/test.html
@@ -1,9 +1,8 @@
HOWDIE!!!
<script type="text/javascript">
- function getSelectedCallback(tab) {
- chrome.tabs.remove(tab.id);
- }
-
- chrome.tabs.getSelected(undefined, getSelectedCallback);
+// Do things in the background page to test that API call
+// routing works from extension views not directly
+// attached to the automation client.
+chrome.extension.getBackgroundPage().doStuff();
</script>