Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Unified Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 8587004: Add PyAuto tests for triggering browser/page action. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Dennis's comments Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..acd15bc2ebf1567463c8ace53cfa97272e38f299 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -53,6 +53,7 @@
#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"
@@ -2478,9 +2479,10 @@ void TestingAutomationProvider::SendJSONRequest(int handle,
&TestingAutomationProvider::GetExtensionsInfo;
browser_handler_map["UninstallExtensionById"] =
&TestingAutomationProvider::UninstallExtensionById;
-
browser_handler_map["SetExtensionStateById"] =
&TestingAutomationProvider::SetExtensionStateById;
+ browser_handler_map["TriggerExtensionActionById"] =
+ &TestingAutomationProvider::TriggerExtensionActionById;
browser_handler_map["FindInPage"] = &TestingAutomationProvider::FindInPage;
@@ -4456,6 +4458,54 @@ void TestingAutomationProvider::SetExtensionStateById(
reply.SendSuccess(NULL);
}
+// See TriggerExtensionActionById() in chrome/test/pyautolib/pyauto.py
+// for sample json input.
+void TestingAutomationProvider::TriggerExtensionActionById(
+ Browser* browser,
kkania 2011/11/17 17:49:09 could you use the new non-browser style for this a
frankf 2011/11/21 02:01:46 Done.
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+
+ 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.",
+ id.c_str()));
+ return;
+ }
+
+ const Extension* extension = service->GetExtensionById(id, false);
+ if (!extension) {
+ reply.SendError("Extension is disabled or has crashed.");
+ return;
+ }
+
+ if (extension->page_action()) {
+ int tab_id = ExtensionTabUtil::GetTabId(browser->GetSelectedTabContents());
+ service->browser_event_router()->PageActionExecuted(
kkania 2011/11/17 17:49:09 I think you should throw an error if the page acti
frankf 2011/11/21 02:01:46 Done.
+ browser->profile(), id, "action", tab_id, "", 1);
+ reply.SendSuccess(NULL);
+ } else if (extension->browser_action()) {
+ service->browser_event_router()->BrowserActionExecuted(
kkania 2011/11/17 17:49:09 this doesn't work for popups
frankf 2011/11/21 02:01:46 Done.
+ browser->profile(), id, browser);
+ reply.SendSuccess(NULL);
+ } else {
+ reply.SendError("Extension doesn't have any page/browser action.");
+ }
+}
+
// Sample json input:
// { "command": "GetAutofillProfile" }
// Refer to GetAutofillProfile() in chrome/test/pyautolib/pyauto.py for sample

Powered by Google App Engine
This is Rietveld 408576698