summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc243
-rw-r--r--chrome/browser/automation/testing_automation_provider.h75
2 files changed, 245 insertions, 73 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index d3b4613..85cf92b 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -373,7 +373,6 @@ bool TestingAutomationProvider::OnMessageReceived(
IPC_MESSAGE_HANDLER(AutomationMsg_ActiveTabIndex, GetActiveTabIndex)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseTab, CloseTab)
IPC_MESSAGE_HANDLER(AutomationMsg_GetCookies, GetCookies)
- IPC_MESSAGE_HANDLER(AutomationMsg_SetCookie, SetCookie)
IPC_MESSAGE_HANDLER_DELAY_REPLY(
AutomationMsg_NavigateToURLBlockUntilNavigationsComplete,
NavigateToURLBlockUntilNavigationsComplete)
@@ -398,10 +397,8 @@ bool TestingAutomationProvider::OnMessageReceived(
IPC_MESSAGE_HANDLER(AutomationMsg_TabTitle, GetTabTitle)
IPC_MESSAGE_HANDLER(AutomationMsg_TabIndex, GetTabIndex)
IPC_MESSAGE_HANDLER(AutomationMsg_TabURL, GetTabURL)
- IPC_MESSAGE_HANDLER(AutomationMsg_ShelfVisibility, GetShelfVisibility)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_DomOperation,
ExecuteJavascript)
- IPC_MESSAGE_HANDLER(AutomationMsg_DownloadDirectory, GetDownloadDirectory)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindowOfType,
OpenNewBrowserWindowOfType)
IPC_MESSAGE_HANDLER(AutomationMsg_WindowForBrowser, GetWindowForBrowser)
@@ -414,8 +411,6 @@ bool TestingAutomationProvider::OnMessageReceived(
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ActionOnSSLBlockingPage,
ActionOnSSLBlockingPage)
IPC_MESSAGE_HANDLER(AutomationMsg_BringBrowserToFront, BringBrowserToFront)
- IPC_MESSAGE_HANDLER(AutomationMsg_IsMenuCommandEnabled,
- IsMenuCommandEnabled)
IPC_MESSAGE_HANDLER(AutomationMsg_OpenFindInPage,
HandleOpenFindInPageRequest)
IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowVisibility,
@@ -447,7 +442,6 @@ bool TestingAutomationProvider::OnMessageReceived(
IPC_MESSAGE_HANDLER_DELAY_REPLY(
AutomationMsg_GoForwardBlockUntilNavigationsComplete,
GoForwardBlockUntilNavigationsComplete)
- IPC_MESSAGE_HANDLER(AutomationMsg_SetShelfVisibility, SetShelfVisibility)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SendJSONRequest,
SendJSONRequestWithBrowserIndex)
IPC_MESSAGE_HANDLER_DELAY_REPLY(
@@ -575,15 +569,6 @@ void TestingAutomationProvider::GetCookies(const GURL& url, int handle,
automation_util::GetCookies(url, contents, value_size, value);
}
-void TestingAutomationProvider::SetCookie(const GURL& url,
- const std::string& value,
- int handle,
- int* response_value) {
- WebContents* contents = tab_tracker_->ContainsHandle(handle) ?
- tab_tracker_->GetResource(handle)->GetWebContents() : NULL;
- automation_util::SetCookie(url, value, contents, response_value);
-}
-
void TestingAutomationProvider::NavigateToURLBlockUntilNavigationsComplete(
int handle, const GURL& url, int number_of_navigations,
IPC::Message* reply_message) {
@@ -1100,17 +1085,6 @@ void TestingAutomationProvider::GetTabURL(int handle,
}
}
-void TestingAutomationProvider::GetShelfVisibility(int handle, bool* visible) {
- *visible = false;
-
- if (browser_tracker_->ContainsHandle(handle)) {
- Browser* browser = browser_tracker_->GetResource(handle);
- if (browser) {
- *visible = browser->window()->IsDownloadShelfVisible();
- }
- }
-}
-
void TestingAutomationProvider::ExecuteJavascriptInRenderViewFrame(
const string16& frame_xpath,
const string16& script,
@@ -1145,17 +1119,6 @@ void TestingAutomationProvider::ExecuteJavascript(
web_contents->GetRenderViewHost());
}
-void TestingAutomationProvider::GetDownloadDirectory(
- int handle, FilePath* download_directory) {
- if (tab_tracker_->ContainsHandle(handle)) {
- NavigationController* tab = tab_tracker_->GetResource(handle);
- DownloadManager* dlm =
- BrowserContext::GetDownloadManager(tab->GetBrowserContext());
- *download_directory =
- DownloadPrefs::FromDownloadManager(dlm)->DownloadPath();
- }
-}
-
// Sample json input: { "command": "OpenNewBrowserWindowWithNewProfile" }
// Sample output: {}
void TestingAutomationProvider::OpenNewBrowserWindowWithNewProfile(
@@ -1350,16 +1313,6 @@ void TestingAutomationProvider::BringBrowserToFront(int browser_handle,
}
}
-void TestingAutomationProvider::IsMenuCommandEnabled(int browser_handle,
- int message_num,
- bool* menu_item_enabled) {
- *menu_item_enabled = false;
- if (browser_tracker_->ContainsHandle(browser_handle)) {
- Browser* browser = browser_tracker_->GetResource(browser_handle);
- *menu_item_enabled = chrome::IsCommandEnabled(browser, message_num);
- }
-}
-
void TestingAutomationProvider::HandleOpenFindInPageRequest(
const IPC::Message& message, int handle) {
if (browser_tracker_->ContainsHandle(handle)) {
@@ -1639,18 +1592,6 @@ void TestingAutomationProvider::GoForwardBlockUntilNavigationsComplete(
Send(reply_message);
}
-void TestingAutomationProvider::SetShelfVisibility(int handle, bool visible) {
- if (browser_tracker_->ContainsHandle(handle)) {
- Browser* browser = browser_tracker_->GetResource(handle);
- if (browser) {
- if (visible)
- browser->window()->GetDownloadShelf()->Show();
- else
- browser->window()->GetDownloadShelf()->Close();
- }
- }
-}
-
void TestingAutomationProvider::BuildJSONHandlerMaps() {
// Map json commands to their handlers.
handler_map_["ApplyAccelerator"] =
@@ -1701,12 +1642,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_["GetCookiesInBrowserContext"] =
+ &TestingAutomationProvider::GetCookiesInBrowserContext;
+ handler_map_["DeleteCookieInBrowserContext"] =
+ &TestingAutomationProvider::DeleteCookieInBrowserContext;
+ handler_map_["SetCookieInBrowserContext"] =
+ &TestingAutomationProvider::SetCookieInBrowserContext;
handler_map_["GetTabIds"] =
&TestingAutomationProvider::GetTabIds;
handler_map_["GetViews"] =
@@ -2867,6 +2820,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)->DownloadPath().value());
+ reply.SendSuccess(&dict);
+}
+
// Sample JSON input { "command": "LoadSearchEngineInfo" }
void TestingAutomationProvider::LoadSearchEngineInfo(
Browser* browser,
@@ -6629,6 +6639,121 @@ void TestingAutomationProvider::SetCookieJSON(
automation_util::SetCookieJSON(this, args, reply_message);
}
+void TestingAutomationProvider::GetCookiesInBrowserContext(
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+ WebContents* web_contents;
+ std::string value, url_string;
+ int windex, value_size;
+ if (!args->GetInteger("windex", &windex)) {
+ reply.SendError("'windex' missing or invalid.");
+ return;
+ }
+ web_contents = automation_util::GetWebContentsAt(windex, 0);
+ if (!web_contents) {
+ reply.SendError("'windex' does not refer to a browser window.");
+ 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::DeleteCookieInBrowserContext(
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+ WebContents* web_contents;
+ std::string cookie_name, error, url_string;
+ int windex;
+ bool success = false;
+ if (!args->GetInteger("windex", &windex)) {
+ reply.SendError("'windex' missing or invalid.");
+ return;
+ }
+ web_contents = automation_util::GetWebContentsAt(windex, 0);
+ if (!web_contents) {
+ reply.SendError("'windex' does not refer to a browser window.");
+ 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::SetCookieInBrowserContext(
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+ WebContents* web_contents;
+ std::string value, error, url_string;
+ int windex, response_value = -1;
+ if (!args->GetInteger("windex", &windex)) {
+ reply.SendError("'windex' missing or invalid.");
+ return;
+ }
+ web_contents = automation_util::GetWebContentsAt(windex, 0);
+ if (!web_contents) {
+ reply.SendError("'windex' does not refer to a browser window.");
+ 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();
diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h
index fda8389..f2ea2a0 100644
--- a/chrome/browser/automation/testing_automation_provider.h
+++ b/chrome/browser/automation/testing_automation_provider.h
@@ -100,10 +100,6 @@ class TestingAutomationProvider : public AutomationProvider,
IPC::Message* reply_message);
void GetCookies(const GURL& url, int handle, int* value_size,
std::string* value);
- void SetCookie(const GURL& url,
- const std::string& value,
- int handle,
- int* response_value);
void NavigateToURLBlockUntilNavigationsComplete(int handle, const GURL& url,
int number_of_navigations,
IPC::Message* reply_message);
@@ -138,14 +134,11 @@ class TestingAutomationProvider : public AutomationProvider,
void GetTabTitle(int handle, int* title_string_size, std::wstring* title);
void GetTabIndex(int handle, int* tabstrip_index);
void GetTabURL(int handle, bool* success, GURL* url);
- void GetShelfVisibility(int handle, bool* visible);
void ExecuteJavascript(int handle,
const std::wstring& frame_xpath,
const std::wstring& script,
IPC::Message* reply_message);
- void GetDownloadDirectory(int handle, FilePath* download_directory);
-
// If |show| is true, call Show() on the new window after creating it.
void OpenNewBrowserWindowOfType(int type,
bool show,
@@ -181,11 +174,6 @@ class TestingAutomationProvider : public AutomationProvider,
// Brings the browser window to the front and activates it.
void BringBrowserToFront(int browser_handle, bool* success);
- // Checks to see if a command on the browser's CommandController is enabled.
- void IsMenuCommandEnabled(int browser_handle,
- int message_num,
- bool* menu_item_enabled);
-
// Responds to requests to open the FindInPage window.
void HandleOpenFindInPageRequest(const IPC::Message& message,
int handle);
@@ -240,8 +228,6 @@ class TestingAutomationProvider : public AutomationProvider,
int number_of_navigations,
IPC::Message* reply_message);
- void SetShelfVisibility(int handle, bool visible);
-
// Generic pattern for pyautolib
// Uses the JSON interface for input/output.
void SendJSONRequestWithBrowserHandle(int handle,
@@ -368,6 +354,31 @@ class TestingAutomationProvider : public AutomationProvider,
base::DictionaryValue* args,
IPC::Message* reply_message);
+ // Sets the visibility of the download shelf. Uses the JSON interface.
+ // Example:
+ // input: { "is_visible": true,
+ // "windex": 1,
+ // }
+ // output: none
+ void SetDownloadShelfVisibleJSON(base::DictionaryValue* args,
+ IPC::Message* reply_message);
+
+ // Gets the visibility of the download shelf. Uses the JSON interface.
+ // Example:
+ // input: { "windex": 1 }
+ // output: { "is_visible": true }
+ void IsDownloadShelfVisibleJSON(base::DictionaryValue* args,
+ IPC::Message* reply_message);
+
+ // Gets the download path of the given tab. Uses the JSON interface.
+ // Example:
+ // input: { "tab_index": 1,
+ // "windex": 1,
+ // }
+ // output: { "path": "/home/foobar/Downloads" }
+ void GetDownloadDirectoryJSON(base::DictionaryValue* args,
+ IPC::Message* reply_message);
+
// Get search engines list.
// Assumes that the profile's template url model is loaded.
// Uses the JSON interface for input/output.
@@ -1114,6 +1125,42 @@ class TestingAutomationProvider : public AutomationProvider,
// output: none
void SetCookieJSON(base::DictionaryValue* args, IPC::Message* reply_message);
+ // Gets the cookies for the given URL in the context of a given browser
+ // window. Uses the JSON interface.
+ // Example:
+ // input: { "url": "http://www.google.com",
+ // "tab_index": 1,
+ // "windex": 1,
+ // }
+ // output: { "cookies": "foo=bar" }
+ void GetCookiesInBrowserContext(base::DictionaryValue* args,
+ IPC::Message* reply_message);
+
+ // Deletes the cookie with the given name for the URL in the context of a
+ // given browser window. Uses the JSON interface.
+ // Example:
+ // input: { "url": "http://www.google.com",
+ // "cookie_name": "my_cookie"
+ // "tab_index": 1,
+ // "windex": 1,
+ // }
+ // output: none
+ void DeleteCookieInBrowserContext(base::DictionaryValue* args,
+ IPC::Message* reply_message);
+
+ // Sets a cookie for the given URL in the context of a given browser window.
+ // Uses the JSON interface.
+ //
+ // Example:
+ // input: { "url": "http://www.google.com",
+ // "value": "name=value; Expires=Wed, 09 Jun 2021 10:18:14 GMT",
+ // "tab_index": 1,
+ // "windex": 1,
+ // }
+ // output: none
+ void SetCookieInBrowserContext(base::DictionaryValue* args,
+ IPC::Message* reply_message);
+
// Gets the ID for every open tab. This ID is unique per session.
// Example:
// input: none