summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/automation/automation_provider.cc224
-rw-r--r--chrome/browser/automation/automation_provider.h29
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc230
-rw-r--r--chrome/browser/automation/testing_automation_provider.h16
4 files changed, 252 insertions, 247 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 1f00aee..6ba2605 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -335,17 +335,6 @@ Extension* AutomationProvider::GetDisabledExtension(int extension_handle) {
void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
IPC_BEGIN_MESSAGE_MAP(AutomationProvider, message)
- 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(AutomationMsg_DeleteCookie, DeleteCookie)
- IPC_MESSAGE_HANDLER(AutomationMsg_ShowCollectedCookiesDialog,
- ShowCollectedCookiesDialog)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_NavigateToURL, NavigateToURL)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(
- AutomationMsg_NavigateToURLBlockUntilNavigationsComplete,
- NavigateToURLBlockUntilNavigationsComplete)
IPC_MESSAGE_HANDLER(AutomationMsg_NavigationAsync, NavigationAsync)
IPC_MESSAGE_HANDLER(AutomationMsg_NavigationAsyncWithDisposition,
NavigationAsyncWithDisposition)
@@ -584,36 +573,6 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
IPC_END_MESSAGE_MAP()
}
-void AutomationProvider::NavigateToURL(int handle, const GURL& url,
- IPC::Message* reply_message) {
- NavigateToURLBlockUntilNavigationsComplete(handle, url, 1, reply_message);
-}
-
-void AutomationProvider::NavigateToURLBlockUntilNavigationsComplete(
- int handle, const GURL& url, int number_of_navigations,
- IPC::Message* reply_message) {
- if (tab_tracker_->ContainsHandle(handle)) {
- NavigationController* tab = tab_tracker_->GetResource(handle);
-
- // Simulate what a user would do. Activate the tab and then navigate.
- // We could allow navigating in a background tab in future.
- Browser* browser = FindAndActivateTab(tab);
-
- if (browser) {
- AddNavigationStatusListener(tab, reply_message, number_of_navigations,
- false);
-
- // TODO(darin): avoid conversion to GURL
- browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED);
- return;
- }
- }
-
- AutomationMsg_NavigateToURL::WriteReplyParams(
- reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
- Send(reply_message);
-}
-
void AutomationProvider::NavigationAsync(int handle,
const GURL& url,
bool* status) {
@@ -779,14 +738,6 @@ void AutomationProvider::GetRedirectsFrom(int tab_handle,
Send(reply_message);
}
-void AutomationProvider::GetActiveTabIndex(int handle, int* active_tab_index) {
- *active_tab_index = -1; // -1 is the error code
- if (browser_tracker_->ContainsHandle(handle)) {
- Browser* browser = browser_tracker_->GetResource(handle);
- *active_tab_index = browser->selected_index();
- }
-}
-
void AutomationProvider::GetBrowserLocale(string16* locale) {
DCHECK(g_browser_process);
*locale = ASCIIToUTF16(g_browser_process->GetApplicationLocale());
@@ -1101,164 +1052,6 @@ Browser* AutomationProvider::FindAndActivateTab(
return browser;
}
-namespace {
-
-class GetCookiesTask : public Task {
- public:
- GetCookiesTask(const GURL& url,
- URLRequestContextGetter* context_getter,
- base::WaitableEvent* event,
- std::string* cookies)
- : url_(url),
- context_getter_(context_getter),
- event_(event),
- cookies_(cookies) {}
-
- virtual void Run() {
- *cookies_ = context_getter_->GetCookieStore()->GetCookies(url_);
- event_->Signal();
- }
-
- private:
- const GURL& url_;
- URLRequestContextGetter* const context_getter_;
- base::WaitableEvent* const event_;
- std::string* const cookies_;
-
- DISALLOW_COPY_AND_ASSIGN(GetCookiesTask);
-};
-
-std::string GetCookiesForURL(
- const GURL& url,
- URLRequestContextGetter* context_getter) {
- std::string cookies;
- base::WaitableEvent event(true /* manual reset */,
- false /* not initially signaled */);
- CHECK(ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- new GetCookiesTask(url, context_getter, &event, &cookies)));
- event.Wait();
- return cookies;
-}
-
-class SetCookieTask : public Task {
- public:
- SetCookieTask(const GURL& url,
- const std::string& value,
- URLRequestContextGetter* context_getter,
- base::WaitableEvent* event,
- bool* rv)
- : url_(url),
- value_(value),
- context_getter_(context_getter),
- event_(event),
- rv_(rv) {}
-
- virtual void Run() {
- *rv_ = context_getter_->GetCookieStore()->SetCookie(url_, value_);
- event_->Signal();
- }
-
- private:
- const GURL& url_;
- const std::string& value_;
- URLRequestContextGetter* const context_getter_;
- base::WaitableEvent* const event_;
- bool* const rv_;
-
- DISALLOW_COPY_AND_ASSIGN(SetCookieTask);
-};
-
-bool SetCookieForURL(
- const GURL& url,
- const std::string& value,
- URLRequestContextGetter* context_getter) {
- base::WaitableEvent event(true /* manual reset */,
- false /* not initially signaled */);
- bool rv = false;
- CHECK(ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- new SetCookieTask(url, value, context_getter, &event, &rv)));
- event.Wait();
- return rv;
-}
-
-class DeleteCookieTask : public Task {
- public:
- DeleteCookieTask(const GURL& url,
- const std::string& name,
- const scoped_refptr<URLRequestContextGetter>& context_getter)
- : url_(url),
- name_(name),
- context_getter_(context_getter) {}
-
- virtual void Run() {
- net::CookieStore* cookie_store = context_getter_->GetCookieStore();
- cookie_store->DeleteCookie(url_, name_);
- }
-
- private:
- const GURL url_;
- const std::string name_;
- const scoped_refptr<URLRequestContextGetter> context_getter_;
-
- DISALLOW_COPY_AND_ASSIGN(DeleteCookieTask);
-};
-
-} // namespace
-
-void AutomationProvider::GetCookies(const GURL& url, int handle,
- int* value_size,
- std::string* value) {
- *value_size = -1;
- if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) {
- NavigationController* tab = tab_tracker_->GetResource(handle);
-
- // Since we are running on the UI thread don't call GetURLRequestContext().
- *value = GetCookiesForURL(url, tab->profile()->GetRequestContext());
- *value_size = static_cast<int>(value->size());
- }
-}
-
-void AutomationProvider::SetCookie(const GURL& url,
- const std::string value,
- int handle,
- int* response_value) {
- *response_value = -1;
-
- if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) {
- NavigationController* tab = tab_tracker_->GetResource(handle);
-
- if (SetCookieForURL(url, value, tab->profile()->GetRequestContext()))
- *response_value = 1;
- }
-}
-
-void AutomationProvider::DeleteCookie(const GURL& url,
- const std::string& cookie_name,
- int handle, bool* success) {
- *success = false;
- if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) {
- NavigationController* tab = tab_tracker_->GetResource(handle);
- ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- new DeleteCookieTask(url, cookie_name,
- tab->profile()->GetRequestContext()));
- *success = true;
- }
-}
-
-void AutomationProvider::ShowCollectedCookiesDialog(
- int handle, bool* success) {
- *success = false;
- if (tab_tracker_->ContainsHandle(handle)) {
- TabContents* tab_contents =
- tab_tracker_->GetResource(handle)->tab_contents();
- tab_contents->delegate()->ShowCollectedCookiesDialog(tab_contents);
- *success = true;
- }
-}
-
void AutomationProvider::GetTabURL(int handle, bool* success, GURL* url) {
*success = false;
if (tab_tracker_->ContainsHandle(handle)) {
@@ -3535,23 +3328,6 @@ void AutomationProvider::HideInterstitialPage(int tab_handle,
}
}
-void AutomationProvider::CloseTab(int tab_handle,
- bool wait_until_closed,
- IPC::Message* reply_message) {
- if (tab_tracker_->ContainsHandle(tab_handle)) {
- NavigationController* controller = tab_tracker_->GetResource(tab_handle);
- int index;
- Browser* browser = Browser::GetBrowserForController(controller, &index);
- DCHECK(browser);
- new TabClosedNotificationObserver(this, wait_until_closed, reply_message);
- browser->CloseContents(controller->tab_contents());
- return;
- }
-
- AutomationMsg_CloseTab::WriteReplyParams(reply_message, false);
- Send(reply_message);
-}
-
void AutomationProvider::WaitForTabToBeRestored(int tab_handle,
IPC::Message* reply_message) {
if (tab_tracker_->ContainsHandle(tab_handle)) {
diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h
index c93c2c9..694f39a 100644
--- a/chrome/browser/automation/automation_provider.h
+++ b/chrome/browser/automation/automation_provider.h
@@ -154,23 +154,16 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
friend class PopupMenuWaiter;
virtual ~AutomationProvider();
+ // Helper function to find the browser window that contains a given
+ // NavigationController and activate that tab.
+ // Returns the Browser if found.
+ Browser* FindAndActivateTab(NavigationController* contents);
+
scoped_ptr<AutomationBrowserTracker> browser_tracker_;
+ scoped_ptr<AutomationTabTracker> tab_tracker_;
private:
// IPC Message callbacks.
- void CloseTab(int tab_handle, bool wait_until_closed,
- IPC::Message* reply_message);
-
- void GetActiveTabIndex(int handle, int* active_tab_index);
- 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 DeleteCookie(const GURL& url, const std::string& cookie_name,
- int handle, bool* success);
- void ShowCollectedCookiesDialog(int handle, bool* success);
void GetBrowserWindowCount(int* window_count);
void GetBrowserLocale(string16* locale);
void GetNormalBrowserWindowCount(int* window_count);
@@ -224,10 +217,6 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
void GetTabIndex(int handle, int* tabstrip_index);
void GetTabURL(int handle, bool* success, GURL* url);
void HandleUnused(const IPC::Message& message, int handle);
- void NavigateToURL(int handle, const GURL& url, IPC::Message* reply_message);
- void NavigateToURLBlockUntilNavigationsComplete(int handle, const GURL& url,
- int number_of_navigations,
- IPC::Message* reply_message);
void NavigationAsync(int handle, const GURL& url, bool* status);
void NavigationAsyncWithDisposition(int handle,
const GURL& url,
@@ -262,11 +251,6 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
void GetFocusedViewID(int handle, int* view_id);
- // Helper function to find the browser window that contains a given
- // NavigationController and activate that tab.
- // Returns the Browser if found.
- Browser* FindAndActivateTab(NavigationController* contents);
-
// Deprecated.
void ApplyAccelerator(int handle, int id);
@@ -930,7 +914,6 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
extension_test_result_observer_;
scoped_ptr<MetricEventDurationObserver> metric_event_duration_observer_;
scoped_ptr<AutomationExtensionTracker> extension_tracker_;
- scoped_ptr<AutomationTabTracker> tab_tracker_;
scoped_ptr<AutomationWindowTracker> window_tracker_;
scoped_ptr<AutomationAutocompleteEditTracker> autocomplete_edit_tracker_;
scoped_ptr<NavigationControllerRestoredObserver> restore_tracker_;
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index 92afdb9..2a21cda 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -8,10 +8,120 @@
#include "chrome/browser/automation/automation_browser_tracker.h"
#include "chrome/browser/automation/automation_provider_list.h"
#include "chrome/browser/automation/automation_provider_observers.h"
+#include "chrome/browser/automation/automation_tab_tracker.h"
#include "chrome/browser/browser_window.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/net/url_request_context_getter.h"
#include "chrome/common/notification_service.h"
#include "chrome/test/automation/automation_messages.h"
+#include "net/url_request/url_request_context.h"
+
+namespace {
+
+class GetCookiesTask : public Task {
+ public:
+ GetCookiesTask(const GURL& url,
+ URLRequestContextGetter* context_getter,
+ base::WaitableEvent* event,
+ std::string* cookies)
+ : url_(url),
+ context_getter_(context_getter),
+ event_(event),
+ cookies_(cookies) {}
+
+ virtual void Run() {
+ *cookies_ = context_getter_->GetCookieStore()->GetCookies(url_);
+ event_->Signal();
+ }
+
+ private:
+ const GURL& url_;
+ URLRequestContextGetter* const context_getter_;
+ base::WaitableEvent* const event_;
+ std::string* const cookies_;
+
+ DISALLOW_COPY_AND_ASSIGN(GetCookiesTask);
+};
+
+std::string GetCookiesForURL(
+ const GURL& url,
+ URLRequestContextGetter* context_getter) {
+ std::string cookies;
+ base::WaitableEvent event(true /* manual reset */,
+ false /* not initially signaled */);
+ CHECK(ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ new GetCookiesTask(url, context_getter, &event, &cookies)));
+ event.Wait();
+ return cookies;
+}
+
+class SetCookieTask : public Task {
+ public:
+ SetCookieTask(const GURL& url,
+ const std::string& value,
+ URLRequestContextGetter* context_getter,
+ base::WaitableEvent* event,
+ bool* rv)
+ : url_(url),
+ value_(value),
+ context_getter_(context_getter),
+ event_(event),
+ rv_(rv) {}
+
+ virtual void Run() {
+ *rv_ = context_getter_->GetCookieStore()->SetCookie(url_, value_);
+ event_->Signal();
+ }
+
+ private:
+ const GURL& url_;
+ const std::string& value_;
+ URLRequestContextGetter* const context_getter_;
+ base::WaitableEvent* const event_;
+ bool* const rv_;
+
+ DISALLOW_COPY_AND_ASSIGN(SetCookieTask);
+};
+
+bool SetCookieForURL(
+ const GURL& url,
+ const std::string& value,
+ URLRequestContextGetter* context_getter) {
+ base::WaitableEvent event(true /* manual reset */,
+ false /* not initially signaled */);
+ bool rv = false;
+ CHECK(ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ new SetCookieTask(url, value, context_getter, &event, &rv)));
+ event.Wait();
+ return rv;
+}
+
+class DeleteCookieTask : public Task {
+ public:
+ DeleteCookieTask(const GURL& url,
+ const std::string& name,
+ const scoped_refptr<URLRequestContextGetter>& context_getter)
+ : url_(url),
+ name_(name),
+ context_getter_(context_getter) {}
+
+ virtual void Run() {
+ net::CookieStore* cookie_store = context_getter_->GetCookieStore();
+ cookie_store->DeleteCookie(url_, name_);
+ }
+
+ private:
+ const GURL url_;
+ const std::string name_;
+ const scoped_refptr<URLRequestContextGetter> context_getter_;
+
+ DISALLOW_COPY_AND_ASSIGN(DeleteCookieTask);
+};
+
+} // namespace
+
TestingAutomationProvider::TestingAutomationProvider(Profile* profile)
: AutomationProvider(profile) {
@@ -32,6 +142,17 @@ void TestingAutomationProvider::OnMessageReceived(
CloseBrowserAsync)
IPC_MESSAGE_HANDLER(AutomationMsg_ActivateTab, ActivateTab)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_AppendTab, AppendTab)
+ 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(AutomationMsg_DeleteCookie, DeleteCookie)
+ IPC_MESSAGE_HANDLER(AutomationMsg_ShowCollectedCookiesDialog,
+ ShowCollectedCookiesDialog)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_NavigateToURL, NavigateToURL)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(
+ AutomationMsg_NavigateToURLBlockUntilNavigationsComplete,
+ NavigateToURLBlockUntilNavigationsComplete)
IPC_MESSAGE_UNHANDLED(AutomationProvider::OnMessageReceived(message));
IPC_END_MESSAGE_MAP()
@@ -106,6 +227,115 @@ void TestingAutomationProvider::AppendTab(int handle, const GURL& url,
}
}
+void TestingAutomationProvider::GetActiveTabIndex(int handle,
+ int* active_tab_index) {
+ *active_tab_index = -1; // -1 is the error code
+ if (browser_tracker_->ContainsHandle(handle)) {
+ Browser* browser = browser_tracker_->GetResource(handle);
+ *active_tab_index = browser->selected_index();
+ }
+}
+
+void TestingAutomationProvider::CloseTab(int tab_handle,
+ bool wait_until_closed,
+ IPC::Message* reply_message) {
+ if (tab_tracker_->ContainsHandle(tab_handle)) {
+ NavigationController* controller = tab_tracker_->GetResource(tab_handle);
+ int index;
+ Browser* browser = Browser::GetBrowserForController(controller, &index);
+ DCHECK(browser);
+ new TabClosedNotificationObserver(this, wait_until_closed, reply_message);
+ browser->CloseTabContents(controller->tab_contents());
+ return;
+ }
+
+ AutomationMsg_CloseTab::WriteReplyParams(reply_message, false);
+ Send(reply_message);
+}
+
+void TestingAutomationProvider::GetCookies(const GURL& url, int handle,
+ int* value_size,
+ std::string* value) {
+ *value_size = -1;
+ if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) {
+ NavigationController* tab = tab_tracker_->GetResource(handle);
+
+ // Since we are running on the UI thread don't call GetURLRequestContext().
+ *value = GetCookiesForURL(url, tab->profile()->GetRequestContext());
+ *value_size = static_cast<int>(value->size());
+ }
+}
+
+void TestingAutomationProvider::SetCookie(const GURL& url,
+ const std::string value,
+ int handle,
+ int* response_value) {
+ *response_value = -1;
+
+ if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) {
+ NavigationController* tab = tab_tracker_->GetResource(handle);
+
+ if (SetCookieForURL(url, value, tab->profile()->GetRequestContext()))
+ *response_value = 1;
+ }
+}
+
+void TestingAutomationProvider::DeleteCookie(const GURL& url,
+ const std::string& cookie_name,
+ int handle, bool* success) {
+ *success = false;
+ if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) {
+ NavigationController* tab = tab_tracker_->GetResource(handle);
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ new DeleteCookieTask(url, cookie_name,
+ tab->profile()->GetRequestContext()));
+ *success = true;
+ }
+}
+
+void TestingAutomationProvider::ShowCollectedCookiesDialog(
+ int handle, bool* success) {
+ *success = false;
+ if (tab_tracker_->ContainsHandle(handle)) {
+ TabContents* tab_contents =
+ tab_tracker_->GetResource(handle)->tab_contents();
+ tab_contents->delegate()->ShowCollectedCookiesDialog(tab_contents);
+ *success = true;
+ }
+}
+
+void TestingAutomationProvider::NavigateToURL(int handle,
+ const GURL& url,
+ IPC::Message* reply_message) {
+ NavigateToURLBlockUntilNavigationsComplete(handle, url, 1, reply_message);
+}
+
+void TestingAutomationProvider::NavigateToURLBlockUntilNavigationsComplete(
+ int handle, const GURL& url, int number_of_navigations,
+ IPC::Message* reply_message) {
+ if (tab_tracker_->ContainsHandle(handle)) {
+ NavigationController* tab = tab_tracker_->GetResource(handle);
+
+ // Simulate what a user would do. Activate the tab and then navigate.
+ // We could allow navigating in a background tab in future.
+ Browser* browser = FindAndActivateTab(tab);
+
+ if (browser) {
+ AddNavigationStatusListener(tab, reply_message, number_of_navigations,
+ false);
+
+ // TODO(darin): avoid conversion to GURL
+ browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED);
+ return;
+ }
+ }
+
+ AutomationMsg_NavigateToURL::WriteReplyParams(
+ reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
+ Send(reply_message);
+}
+
void TestingAutomationProvider::OnBrowserAdded(const Browser* browser) {
}
diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h
index 0050437..1da6e80 100644
--- a/chrome/browser/automation/testing_automation_provider.h
+++ b/chrome/browser/automation/testing_automation_provider.h
@@ -36,6 +36,22 @@ class TestingAutomationProvider : public AutomationProvider,
void CloseBrowserAsync(int browser_handle);
void ActivateTab(int handle, int at_index, int* status);
void AppendTab(int handle, const GURL& url, IPC::Message* reply_message);
+ void GetActiveTabIndex(int handle, int* active_tab_index);
+ void CloseTab(int tab_handle, bool wait_until_closed,
+ 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 DeleteCookie(const GURL& url, const std::string& cookie_name,
+ int handle, bool* success);
+ void ShowCollectedCookiesDialog(int handle, bool* success);
+ void NavigateToURL(int handle, const GURL& url, IPC::Message* reply_message);
+ void NavigateToURLBlockUntilNavigationsComplete(int handle, const GURL& url,
+ int number_of_navigations,
+ IPC::Message* reply_message);
virtual void Observe(NotificationType type,
const NotificationSource& source,