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

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

Issue 8804011: WebDriver extension support in TestingAutomationProvider. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: ... Created 9 years 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 efa27213fff627aab42b3456dc998fbe009367c6..8403b3b411bcaaf58f7a74d1ef65aa3ab1b2de07 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -2242,7 +2242,7 @@ void TestingAutomationProvider::SendJSONRequest(int handle,
// Map json commands to their handlers.
std::map<std::string, JsonHandler> handler_map;
handler_map["WaitForAllTabsToStopLoading"] =
dennis_jeffrey 2011/12/06 00:49:08 Do you think it's worthwhile to change the name of
kkania 2011/12/12 17:10:06 This isn't used on the python side yet, just C++.
- &TestingAutomationProvider::WaitForAllTabsToStopLoading;
+ &TestingAutomationProvider::WaitForAllViewsToStopLoading;
handler_map["GetIndicesFromTab"] =
&TestingAutomationProvider::GetIndicesFromTab;
handler_map["NavigateToURL"] =
@@ -2307,6 +2307,8 @@ void TestingAutomationProvider::SendJSONRequest(int handle,
&TestingAutomationProvider::GetChromeDriverAutomationVersion;
handler_map["UpdateExtensionsNow"] =
&TestingAutomationProvider::UpdateExtensionsNow;
+ handler_map["IsPageActionVisible"] =
+ &TestingAutomationProvider::IsPageActionVisible;
handler_map["CreateNewAutomationProvider"] =
&TestingAutomationProvider::CreateNewAutomationProvider;
handler_map["GetBrowserInfo"] =
@@ -4428,10 +4430,10 @@ void TestingAutomationProvider::GetExtensionsInfo(
void TestingAutomationProvider::UninstallExtensionById(
DictionaryValue* args,
IPC::Message* reply_message) {
- std::string id;
- if (!args->GetString("id", &id)) {
- AutomationJSONReply(this, reply_message).SendError(
- "Must include string id.");
+ const Extension* extension;
+ std::string error;
+ if (!GetExtensionFromJSONArgs(args, "id", profile(), &extension, &error)) {
+ AutomationJSONReply(this, reply_message).SendError(error);
return;
}
ExtensionService* service = profile()->GetExtensionService();
@@ -4441,19 +4443,10 @@ void TestingAutomationProvider::UninstallExtensionById(
return;
}
- if (!service->GetExtensionById(id, true) &&
- !service->GetTerminatedExtension(id)) {
- // The extension ID does not correspond to any extension, whether crashed
- // or not.
- AutomationJSONReply(this, reply_message).SendError(base::StringPrintf(
- "Extension does not exist: %s.", id.c_str()));
- return;
- }
-
// Wait for a notification indicating that the extension with the given ID
// has been uninstalled. This observer will delete itself.
- new ExtensionUninstallObserver(this, reply_message, id);
- service->UninstallExtension(id, false, NULL);
+ new ExtensionUninstallObserver(this, reply_message, extension->id());
+ service->UninstallExtension(extension->id(), false, NULL);
}
// See SetExtensionStateById() in chrome/test/pyautolib/pyauto.py
@@ -4461,10 +4454,10 @@ void TestingAutomationProvider::UninstallExtensionById(
void TestingAutomationProvider::SetExtensionStateById(
DictionaryValue* args,
IPC::Message* reply_message) {
- std::string id;
- if (!args->GetString("id", &id)) {
- AutomationJSONReply(this, reply_message)
- .SendError("Missing or invalid key: id");
+ const Extension* extension;
+ std::string error;
+ if (!GetExtensionFromJSONArgs(args, "id", profile(), &extension, &error)) {
+ AutomationJSONReply(this, reply_message).SendError(error);
return;
}
@@ -4497,30 +4490,21 @@ void TestingAutomationProvider::SetExtensionStateById(
return;
}
- if (!service->GetExtensionById(id, true) &&
- !service->GetTerminatedExtension(id)) {
- // The extension ID does not correspond to any extension, whether crashed
- // or not.
- AutomationJSONReply(this, reply_message).SendError(
- base::StringPrintf("Extension does not exist: %s.", id.c_str()));
- return;
- }
-
- service->SetIsIncognitoEnabled(id, allow_in_incognito);
+ service->SetIsIncognitoEnabled(extension->id(), allow_in_incognito);
if (enable) {
- if (!service->IsExtensionEnabled(id)) {
+ if (!service->IsExtensionEnabled(extension->id())) {
new ExtensionReadyNotificationObserver(
manager,
service,
this,
reply_message);
- service->EnableExtension(id);
+ service->EnableExtension(extension->id());
} else {
AutomationJSONReply(this, reply_message).SendSuccess(NULL);
}
} else {
- service->DisableExtension(id);
+ service->DisableExtension(extension->id());
AutomationJSONReply(this, reply_message).SendSuccess(NULL);
}
}
@@ -4530,53 +4514,49 @@ void TestingAutomationProvider::SetExtensionStateById(
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);
+ TabContents* tab;
+ if (!GetBrowserAndTabFromJSONArgs(args, &browser, &tab, &error)) {
+ AutomationJSONReply(this, reply_message).SendError(error);
return;
}
- std::string id;
- if (!args->GetString("id", &id)) {
- reply.SendError("Missing or invalid key: id");
+ const Extension* extension;
+ if (!GetEnabledExtensionFromJSONArgs(
+ args, "id", profile(), &extension, &error)) {
+ AutomationJSONReply(this, reply_message).SendError(error);
return;
}
-
- ExtensionService* service = browser->profile()->GetExtensionService();
- if (!service) {
- reply.SendError("No extensions service.");
+ ExtensionAction* page_action = extension->page_action();
+ if (!page_action) {
+ AutomationJSONReply(this, reply_message).SendError(
+ "Extension doesn't have any page action.");
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;
+
+ bool pressed = false;
+ 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);
+ pressed = true;
+ break;
+ }
}
- const Extension* extension = service->GetExtensionById(id, false);
- if (!extension) {
- reply.SendError("Extension is disabled or has crashed.");
+ if (!pressed) {
+ AutomationJSONReply(this, reply_message).SendError(
+ "Extension's page action is not visible.");
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.");
+ if (page_action->HasPopup(ExtensionTabUtil::GetTabId(tab))) {
+ new ExtensionPopupObserver(
+ this, reply_message, extension->id());
dennis_jeffrey 2011/12/06 00:49:08 maybe add a comment to explicitly say that this ob
kkania 2011/12/12 17:10:06 Done.
} else {
- reply.SendError("Extension doesn't have any page action.");
+ AutomationJSONReply(this, reply_message).SendSuccess(NULL);
}
}
@@ -4585,55 +4565,61 @@ void TestingAutomationProvider::TriggerPageActionById(
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);
+ TabContents* tab;
+ if (!GetBrowserAndTabFromJSONArgs(args, &browser, &tab, &error)) {
+ AutomationJSONReply(this, reply_message).SendError(error);
return;
}
- std::string id;
- if (!args->GetString("id", &id)) {
- reply.SendError("Missing or invalid key: id");
+ const Extension* extension;
+ if (!GetEnabledExtensionFromJSONArgs(
+ args, "id", profile(), &extension, &error)) {
+ AutomationJSONReply(this, reply_message).SendError(error);
return;
}
-
- ExtensionService* service = browser->profile()->GetExtensionService();
- if (!service) {
- reply.SendError("No extensions service.");
+ ExtensionAction* action = extension->browser_action();
+ if (!action) {
+ AutomationJSONReply(this, reply_message).SendError(
+ "Extension doesn't have any browser action.");
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()));
+
+ BrowserActionTestUtil browser_actions(browser);
+ int num_browser_actions = browser_actions.NumberOfBrowserActions();
+ int action_index = -1;
+#if defined(TOOLKIT_VIEWS)
+ for (int i = 0; i < num_browser_actions; ++i) {
+ if (extension->id() == browser_actions.GetExtensionId(i)) {
+ action_index = i;
+ break;
+ }
+ }
+#else
+ // TODO: Implement the platform-specific GetExtensionId() in
dennis_jeffrey 2011/12/06 00:49:08 username for the TODO?
kkania 2011/12/12 17:10:06 Frank originally put this here, but I'm willing to
+ // BrowserActionTestUtil.
+ if (num_browser_actions != 1) {
+ AutomationJSONReply(this, reply_message).SendError(StringPrintf(
+ "Found %d browser actions. Only one browser action must be active.",
+ num_browser_actions));
return;
}
- const Extension* extension = service->GetExtensionById(id, false);
- if (!extension) {
- reply.SendError("Extension is disabled or has crashed.");
+ // This extension has a browser action, and there's only one action, so this
+ // must be the first one.
+ action_index = 0;
+#endif
+ if (action_index == -1) {
+ AutomationJSONReply(this, reply_message).SendError(
+ "Extension's browser action is not visible.");
return;
}
+ browser_actions.Press(action_index);
- 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 must be active.",
- num_browser_actions));
- return;
- }
- browser_actions.Press(0);
- reply.SendSuccess(NULL);
- return;
+ if (action->HasPopup(ExtensionTabUtil::GetTabId(tab))) {
+ new ExtensionPopupObserver(
+ this, reply_message, extension->id());
dennis_jeffrey 2011/12/06 00:49:08 maybe add a comment to explicitly say that this ob
kkania 2011/12/12 17:10:06 Done.
} else {
- reply.SendError("Extension doesn't have any browser action.");
- return;
+ AutomationJSONReply(this, reply_message).SendSuccess(NULL);
}
}
@@ -5878,7 +5864,7 @@ void TestingAutomationProvider::SetAppLaunchType(
reply.SendSuccess(NULL);
}
-void TestingAutomationProvider::WaitForAllTabsToStopLoading(
+void TestingAutomationProvider::WaitForAllViewsToStopLoading(
DictionaryValue* args,
IPC::Message* reply_message) {
if (AppModalDialogQueue::GetInstance()->HasActiveDialog()) {
@@ -5887,7 +5873,8 @@ void TestingAutomationProvider::WaitForAllTabsToStopLoading(
}
// This class will send the message immediately if no tab is loading.
- new AllTabsStoppedLoadingObserver(this, reply_message);
+ new AllViewsStoppedLoadingObserver(
+ this, reply_message, profile()->GetExtensionProcessManager());
}
void TestingAutomationProvider::SetPolicies(
@@ -6296,8 +6283,7 @@ void TestingAutomationProvider::GetViews(
if (!id.is_valid())
continue;
dict->Set("auto_id", id.ToValue());
- dict->Set("extension_id", automation_util::GetIdForExtension(
- host->extension()).ToValue());
+ dict->SetString("extension_id", host->extension_id());
view_list->Append(dict);
}
DictionaryValue dict;
@@ -6411,6 +6397,50 @@ void TestingAutomationProvider::UpdateExtensionsNow(
updater->CheckNow();
}
+void TestingAutomationProvider::IsPageActionVisible(
+ base::DictionaryValue* args,
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+
+ TabContents* tab;
+ std::string error;
+ if (!GetTabFromJSONArgs(args, &tab, &error)) {
+ reply.SendError(error);
+ return;
+ }
+ const Extension* extension;
+ if (!GetEnabledExtensionFromJSONArgs(
+ args, "extension_id", profile(), &extension, &error)) {
+ reply.SendError(error);
+ return;
+ }
+ ExtensionAction* page_action = extension->page_action();
+ if (!page_action) {
+ reply.SendError("Extension doesn't have any page action");
+ return;
+ }
+ Browser* browser = automation_util::GetBrowserForTab(tab);
+ if (!browser) {
+ reply.SendError("Tab does not belong to an open browser");
+ return;
+ }
+
+ bool is_visible = false;
+ 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) {
+ is_visible = true;
+ break;
+ }
+ }
+ DictionaryValue dict;
+ dict.SetBoolean("is_visible", is_visible);
+ reply.SendSuccess(&dict);
+}
+
void TestingAutomationProvider::GetChromeDriverAutomationVersion(
DictionaryValue* args,
IPC::Message* reply_message) {

Powered by Google App Engine
This is Rietveld 408576698