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

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

Issue 10804038: Convert cookie and download automation commands to the JSON interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months 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 629c0ab84d9b3e9abea09e975cf461952a44d138..758d1d09527e1c807ea017f7087ec240ef74e929 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -1697,12 +1697,24 @@ void TestingAutomationProvider::BuildJSONHandlerMaps() {
&TestingAutomationProvider::ReloadJSON;
handler_map_["CaptureEntirePage"] =
&TestingAutomationProvider::CaptureEntirePageJSON;
+ handler_map_["SetDownloadShelfVisible"] =
+ &TestingAutomationProvider::SetDownloadShelfVisibleJSON;
+ handler_map_["IsDownloadShelfVisible"] =
+ &TestingAutomationProvider::IsDownloadShelfVisibleJSON;
+ handler_map_["GetDownloadDirectory"] =
+ &TestingAutomationProvider::GetDownloadDirectoryJSON;
handler_map_["GetCookies"] =
&TestingAutomationProvider::GetCookiesJSON;
handler_map_["DeleteCookie"] =
&TestingAutomationProvider::DeleteCookieJSON;
handler_map_["SetCookie"] =
&TestingAutomationProvider::SetCookieJSON;
+ handler_map_["GetTabCookies"] =
+ &TestingAutomationProvider::GetTabCookiesJSON;
+ handler_map_["DeleteTabCookie"] =
+ &TestingAutomationProvider::DeleteTabCookieJSON;
+ handler_map_["SetTabCookie"] =
+ &TestingAutomationProvider::SetTabCookieJSON;
handler_map_["GetTabIds"] =
&TestingAutomationProvider::GetTabIds;
handler_map_["GetViews"] =
@@ -2845,6 +2857,63 @@ void TestingAutomationProvider::PerformActionOnDownload(
}
}
+void TestingAutomationProvider::SetDownloadShelfVisibleJSON(
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+ Browser* browser;
+ std::string error_msg;
+ bool is_visible;
+ if (!GetBrowserFromJSONArgs(args, &browser, &error_msg)) {
+ reply.SendError(error_msg);
+ return;
+ }
+ if (!args->GetBoolean("is_visible", &is_visible)) {
+ reply.SendError("'is_visible' missing or invalid.");
+ return;
+ }
+ if (is_visible) {
+ browser->window()->GetDownloadShelf()->Show();
+ } else {
+ browser->window()->GetDownloadShelf()->Close();
+ }
+ reply.SendSuccess(NULL);
+}
+
+void TestingAutomationProvider::IsDownloadShelfVisibleJSON(
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+ Browser* browser;
+ std::string error_msg;
+ if (!GetBrowserFromJSONArgs(args, &browser, &error_msg)) {
+ reply.SendError(error_msg);
+ return;
+ }
+ DictionaryValue dict;
+ dict.SetBoolean("is_visible", browser->window()->IsDownloadShelfVisible());
+ reply.SendSuccess(&dict);
+}
+
+void TestingAutomationProvider::GetDownloadDirectoryJSON(
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+ WebContents* web_contents;
+ std::string error;
+ if (!GetTabFromJSONArgs(args, &web_contents, &error)) {
+ reply.SendError(error);
+ return;
+ }
+ DownloadManager* dlm =
+ BrowserContext::GetDownloadManager(
+ web_contents->GetController().GetBrowserContext());
+ DictionaryValue dict;
+ dict.SetString("path",
+ DownloadPrefs::FromDownloadManager(dlm)->download_path().value());
+ reply.SendSuccess(&dict);
+}
+
// Sample JSON input { "command": "LoadSearchEngineInfo" }
void TestingAutomationProvider::LoadSearchEngineInfo(
Browser* browser,
@@ -6574,6 +6643,103 @@ void TestingAutomationProvider::SetCookieJSON(
automation_util::SetCookieJSON(this, args, reply_message);
}
+void TestingAutomationProvider::GetTabCookiesJSON(DictionaryValue* args,
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+ WebContents* web_contents;
+ std::string value, error, url_string;
+ int value_size = -1;
+ if (!GetTabFromJSONArgs(args, &web_contents, &error)) {
+ reply.SendError(error);
+ return;
+ }
+ if (!args->GetString("url", &url_string)) {
+ reply.SendError("'url' missing or invalid.");
+ return;
+ }
+ GURL url(url_string);
+ if (!url.is_valid()) {
+ reply.SendError("Invalid url.");
+ return;
+ }
+ automation_util::GetCookies(url, web_contents, &value_size, &value);
+ if (value_size == -1) {
+ reply.SendError(
+ StringPrintf("Unable to retrieve cookies for url=%s.",
+ url_string.c_str()));
+ return;
+ }
+ DictionaryValue dict;
+ dict.SetString("cookies", value);
+ reply.SendSuccess(&dict);
+}
+
+void TestingAutomationProvider::DeleteTabCookieJSON(
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+ WebContents* web_contents;
+ std::string cookie_name, error, url_string;
+ bool success = false;
+ if (!GetTabFromJSONArgs(args, &web_contents, &error)) {
+ reply.SendError(error);
+ return;
+ }
+ if (!args->GetString("cookie_name", &cookie_name)) {
+ reply.SendError("'cookie_name' missing or invalid.");
+ return;
+ }
+ if (!args->GetString("url", &url_string)) {
+ reply.SendError("'url' missing or invalid.");
+ return;
+ }
+ GURL url(url_string);
+ if (!url.is_valid()) {
+ reply.SendError("Invalid url.");
+ return;
+ }
+ automation_util::DeleteCookie(url, cookie_name, web_contents, &success);
+ if (!success) {
+ reply.SendError(
+ StringPrintf("Failed to delete cookie with name=%s for url=%s.",
+ cookie_name.c_str(), url_string.c_str()));
+ return;
+ }
+ reply.SendSuccess(NULL);
+}
+
+void TestingAutomationProvider::SetTabCookieJSON(DictionaryValue* args,
Nirnimesh 2012/07/20 02:19:46 What is setTabCookie for? I thought cookies were k
craigdh 2012/07/20 15:27:43 If you think of a better name, let me know. The na
craigdh 2012/07/20 18:49:59 How about 'SetCookieInTab'?
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+ WebContents* web_contents;
+ std::string value, error, url_string;
+ int response_value = -1;
+ if (!GetTabFromJSONArgs(args, &web_contents, &error)) {
+ reply.SendError(error);
+ return;
+ }
+ if (!args->GetString("value", &value)) {
+ reply.SendError("'value' missing or invalid.");
+ return;
+ }
+ if (!args->GetString("url", &url_string)) {
+ reply.SendError("'url' missing or invalid.");
+ return;
+ }
+ GURL url(url_string);
+ if (!url.is_valid()) {
+ reply.SendError("Invalid url.");
+ return;
+ }
+ automation_util::SetCookie(url, value, web_contents, &response_value);
+ if (response_value != 1) {
+ reply.SendError(
+ StringPrintf("Unable set cookie for url=%s.", url_string.c_str()));
+ return;
+ }
+ reply.SendSuccess(NULL);
+}
+
void TestingAutomationProvider::GetTabIds(
DictionaryValue* args, IPC::Message* reply_message) {
ListValue* id_list = new ListValue();

Powered by Google App Engine
This is Rietveld 408576698