Index: chrome/browser/automation/testing_automation_provider.cc |
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc |
index 696baa0982c6bcfc6e8591ba9afe6a306082ce5e..035282856c6748e42c4b81de289f871d4d372374 100644 |
--- a/chrome/browser/automation/testing_automation_provider.cc |
+++ b/chrome/browser/automation/testing_automation_provider.cc |
@@ -49,10 +49,12 @@ |
#include "chrome/browser/download/download_service.h" |
#include "chrome/browser/download/download_service_factory.h" |
#include "chrome/browser/download/save_package_file_picker.h" |
+#include "chrome/browser/extensions/browser_action_test_util.h" |
#include "chrome/browser/extensions/extension_browser_event_router.h" |
#include "chrome/browser/extensions/extension_host.h" |
#include "chrome/browser/extensions/extension_process_manager.h" |
#include "chrome/browser/extensions/extension_service.h" |
+#include "chrome/browser/extensions/extension_tab_util.h" |
#include "chrome/browser/extensions/extension_updater.h" |
#include "chrome/browser/history/top_sites.h" |
#include "chrome/browser/importer/importer_host.h" |
@@ -2329,6 +2331,10 @@ void TestingAutomationProvider::SendJSONRequest(int handle, |
&TestingAutomationProvider::SetPolicies; |
handler_map["GetPolicyDefinitionList"] = |
&TestingAutomationProvider::GetPolicyDefinitionList; |
+ handler_map["TriggerPageActionById"] = |
kkania
2011/11/21 18:53:58
thanks!
|
+ &TestingAutomationProvider::TriggerPageActionById; |
+ handler_map["TriggerBrowserActionById"] = |
+ &TestingAutomationProvider::TriggerBrowserActionById; |
#if defined(OS_CHROMEOS) |
handler_map["GetLoginInfo"] = &TestingAutomationProvider::GetLoginInfo; |
handler_map["ShowCreateAccountUI"] = |
@@ -2478,7 +2484,6 @@ void TestingAutomationProvider::SendJSONRequest(int handle, |
&TestingAutomationProvider::GetExtensionsInfo; |
browser_handler_map["UninstallExtensionById"] = |
&TestingAutomationProvider::UninstallExtensionById; |
- |
browser_handler_map["SetExtensionStateById"] = |
&TestingAutomationProvider::SetExtensionStateById; |
@@ -4456,6 +4461,118 @@ void TestingAutomationProvider::SetExtensionStateById( |
reply.SendSuccess(NULL); |
} |
+// See TriggerPageActionById() in chrome/test/pyautolib/pyauto.py |
+// for sample json input. |
+void TestingAutomationProvider::TriggerPageActionById( |
+ DictionaryValue* args, |
+ IPC::Message* reply_message) { |
+ AutomationJSONReply reply(this, reply_message); |
+ |
+ std::string error; |
+ Browser* browser; |
+ if (!GetBrowserFromJSONArgs(args, &browser, &error)) { |
+ reply.SendError(error); |
+ return; |
+ } |
+ std::string id; |
+ if (!args->GetString("id", &id)) { |
+ reply.SendError("Missing or invalid key: id"); |
+ return; |
+ } |
+ |
+ ExtensionService* service = browser->profile()->GetExtensionService(); |
+ if (!service) { |
+ reply.SendError("No extensions service."); |
+ return; |
+ } |
+ if (!service->GetInstalledExtension(id)) { |
+ // The extension ID does not correspond to any extension, whether crashed |
+ // or not. |
+ reply.SendError(base::StringPrintf("Extension does not exist: %s.", |
kkania
2011/11/21 18:53:58
how about 'Extension %s is not installed'?
frankf
2011/11/22 22:26:10
Done.
|
+ id.c_str())); |
+ return; |
+ } |
+ const Extension* extension = service->GetExtensionById(id, false); |
+ if (!extension) { |
+ reply.SendError("Extension is disabled or has crashed."); |
+ return; |
+ } |
+ |
+ if (ExtensionAction* page_action = extension->page_action()) { |
+ LocationBarTesting* loc_bar = |
+ browser->window()->GetLocationBar()->GetLocationBarForTesting(); |
+ size_t page_action_visible_count = |
+ static_cast<size_t>(loc_bar->PageActionVisibleCount()); |
+ for (size_t i = 0; i < page_action_visible_count; i++) { |
+ if (loc_bar->GetVisiblePageAction(i) == page_action) { |
+ loc_bar->TestPageActionPressed(i); |
+ reply.SendSuccess(NULL); |
+ return; |
+ } |
+ } |
+ reply.SendError("Extension doesn't have any visible page action icon."); |
+ } else { |
+ reply.SendError("Extension doesn't have any page action."); |
+ } |
+} |
+ |
+// See TriggerBrowserActionById() in chrome/test/pyautolib/pyauto.py |
+// for sample json input. |
+void TestingAutomationProvider::TriggerBrowserActionById( |
+ DictionaryValue* args, |
+ IPC::Message* reply_message) { |
+ AutomationJSONReply reply(this, reply_message); |
+ |
+ std::string error; |
+ Browser* browser; |
+ if (!GetBrowserFromJSONArgs(args, &browser, &error)) { |
+ reply.SendError(error); |
+ return; |
+ } |
+ std::string id; |
kkania
2011/11/21 18:53:58
Maybe move this and below to GetEnabledExtensionFr
frankf
2011/11/22 22:26:10
Have to revisit in a different CL for refactoring
|
+ if (!args->GetString("id", &id)) { |
+ reply.SendError("Missing or invalid key: id"); |
+ return; |
+ } |
+ |
+ ExtensionService* service = browser->profile()->GetExtensionService(); |
+ if (!service) { |
+ reply.SendError("No extensions service."); |
+ return; |
+ } |
+ if (!service->GetInstalledExtension(id)) { |
+ // The extension ID does not correspond to any extension, whether crashed |
+ // or not. |
+ reply.SendError(base::StringPrintf("Extension does not exist: %s.", |
+ id.c_str())); |
+ return; |
+ } |
+ const Extension* extension = service->GetExtensionById(id, false); |
+ if (!extension) { |
+ reply.SendError("Extension is disabled or has crashed."); |
+ return; |
+ } |
+ |
+ if (extension->browser_action()) { |
+ BrowserActionTestUtil browser_actions(browser); |
+ int num_browser_actions = browser_actions.NumberOfBrowserActions(); |
+ // TODO: Implement the platform-specific GetExtensionId() in |
+ // BrowserActionTestUtil |
+ if (num_browser_actions != 1) { |
+ reply.SendError(StringPrintf( |
+ "Found %d browser actions. Only one browser action can be active.", |
+ num_browser_actions)); |
+ return; |
+ } |
+ browser_actions.Press(0); |
+ reply.SendSuccess(NULL); |
+ return; |
+ } else { |
+ reply.SendError("Extension doesn't have any browser action."); |
+ return; |
+ } |
+} |
+ |
// Sample json input: |
// { "command": "GetAutofillProfile" } |
// Refer to GetAutofillProfile() in chrome/test/pyautolib/pyauto.py for sample |