Chromium Code Reviews| 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..8c0815f0c8b806bcca46805e82bc0961686cac80 100644 |
| --- a/chrome/browser/automation/testing_automation_provider.cc |
| +++ b/chrome/browser/automation/testing_automation_provider.cc |
| @@ -49,10 +49,11 @@ |
| #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/extension_browser_event_router.h" |
| +#include "chrome/browser/extensions/browser_action_test_util.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" |
| @@ -105,6 +106,7 @@ |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/chrome_view_types.h" |
| #include "chrome/common/extensions/extension.h" |
| +#include "chrome/common/extensions/extension_action.h" |
| #include "chrome/common/extensions/url_pattern.h" |
| #include "chrome/common/extensions/url_pattern_set.h" |
| #include "chrome/common/pref_names.h" |
| @@ -2329,6 +2331,10 @@ void TestingAutomationProvider::SendJSONRequest(int handle, |
| &TestingAutomationProvider::SetPolicies; |
| handler_map["GetPolicyDefinitionList"] = |
| &TestingAutomationProvider::GetPolicyDefinitionList; |
| + handler_map["TriggerPageActionById"] = |
| + &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; |
| @@ -2805,6 +2810,17 @@ void TestingAutomationProvider::GetBrowserInfo( |
| browser_item->SetInteger("height", rect.height()); |
| browser_item->SetBoolean("fullscreen", |
| browser->window()->IsFullscreen()); |
| + ListValue* visible_page_actions = new ListValue; |
| + 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++) { |
|
dennis_jeffrey
2011/11/23 21:54:54
nit: other chrome code generally uses '++i' in the
|
| + StringValue* extension_id = new StringValue( |
| + loc_bar->GetVisiblePageAction(i)->extension_id()); |
| + visible_page_actions->Append(extension_id); |
| + } |
| + browser_item->Set("visible_page_actions", visible_page_actions); |
| browser_item->SetInteger("selected_tab", browser->active_index()); |
| browser_item->SetBoolean("incognito", |
| browser->profile()->IsOffTheRecord()); |
| @@ -4456,6 +4472,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 %s is not installed.", |
| + 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++) { |
|
dennis_jeffrey
2011/11/23 21:54:54
nit: '++i' instead of '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; |
| + 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 %s is not installed.", |
| + 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); |
|
kkania
2011/11/29 19:25:03
fix indent
|
| + int num_browser_actions = browser_actions.NumberOfBrowserActions(); |
| + // TODO: Implement the platform-specific GetExtensionId() in |
| + // BrowserActionTestUtil |
|
dennis_jeffrey
2011/11/23 21:54:54
nit: period at end of sentence
|
| + if (num_browser_actions != 1) { |
| + reply.SendError(StringPrintf( |
| + "Found %d browser actions. Only one browser action must 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 |