summaryrefslogtreecommitdiffstats
path: root/chrome/browser/automation
diff options
context:
space:
mode:
authorfinnur@google.com <finnur@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-28 16:31:57 +0000
committerfinnur@google.com <finnur@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-28 16:31:57 +0000
commit20e93d1f20dc0e3c626a2500c96f85e89cf184c9 (patch)
tree80307da7589ce802e88ca79c6b60493496770e80 /chrome/browser/automation
parent50664fdc92a8d1db14d83c902f67b7a8dce76480 (diff)
downloadchromium_src-20e93d1f20dc0e3c626a2500c96f85e89cf184c9.zip
chromium_src-20e93d1f20dc0e3c626a2500c96f85e89cf184c9.tar.gz
chromium_src-20e93d1f20dc0e3c626a2500c96f85e89cf184c9.tar.bz2
Adding a test to catch regressions where the Find box moves when you open and close a tab. Test is disabled until we fix the bug.
Also made the error message for when tests fails because crash_service isn't running a bit explicit (unrelated to the rest of this change). BUG=1343052 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1488 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation')
-rw-r--r--chrome/browser/automation/automation_provider.cc140
-rw-r--r--chrome/browser/automation/automation_provider.h11
2 files changed, 89 insertions, 62 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 09a243e..5158c80 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -751,6 +751,10 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
OnMessageFromExternalHost)
IPC_MESSAGE_HANDLER(AutomationMsg_FindRequest,
HandleFindRequest)
+ IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowVisibilityRequest,
+ GetFindWindowVisibility)
+ IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowLocationRequest,
+ HandleFindWindowLocationRequest)
IPC_END_MESSAGE_MAP()
}
@@ -1553,25 +1557,20 @@ void AutomationProvider::ExecuteJavascript(const IPC::Message& message,
const std::wstring& frame_xpath,
const std::wstring& script) {
bool succeeded = false;
- if (tab_tracker_->ContainsHandle(handle)) {
- NavigationController* tab = tab_tracker_->GetResource(handle);
- TabContents* tab_contents = tab->active_contents();
- if (tab_contents && tab_contents->type() == TAB_CONTENTS_WEB) {
- WebContents* web_contents = tab_contents->AsWebContents();
-
- // Set the routing id of this message with the controller.
- // This routing id needs to be remembered for the reverse
- // communication while sending back the response of
- // this javascript execution.
- std::wstring url;
- SStringPrintf(&url,
- L"javascript:void(window.domAutomationController.setAutomationId(%d));",
- message.routing_id());
-
- web_contents->ExecuteJavascriptInWebFrame(frame_xpath, url);
- web_contents->ExecuteJavascriptInWebFrame(frame_xpath, script);
- succeeded = true;
- }
+ WebContents* web_contents = GetWebContentsForHandle(handle, NULL);
+ if (web_contents) {
+ // Set the routing id of this message with the controller.
+ // This routing id needs to be remembered for the reverse
+ // communication while sending back the response of
+ // this javascript execution.
+ std::wstring url;
+ SStringPrintf(&url,
+ L"javascript:void(window.domAutomationController.setAutomationId(%d));",
+ message.routing_id());
+
+ web_contents->ExecuteJavascriptInWebFrame(frame_xpath, url);
+ web_contents->ExecuteJavascriptInWebFrame(frame_xpath, script);
+ succeeded = true;
}
if (!succeeded) {
@@ -1582,14 +1581,10 @@ void AutomationProvider::ExecuteJavascript(const IPC::Message& message,
void AutomationProvider::GetShelfVisibility(const IPC::Message& message,
int handle) {
bool visible = false;
- if (tab_tracker_->ContainsHandle(handle)) {
- NavigationController* tab = tab_tracker_->GetResource(handle);
- TabContents* tab_contents = tab->active_contents();
- if (tab_contents && tab_contents->type() == TAB_CONTENTS_WEB) {
- WebContents* web_contents = tab_contents->AsWebContents();
- visible = web_contents->IsDownloadShelfVisible();
- }
- }
+
+ WebContents* web_contents = GetWebContentsForHandle(handle, NULL);
+ if (web_contents)
+ visible = web_contents->IsDownloadShelfVisible();
Send(new AutomationMsg_ShelfVisibilityResponse(message.routing_id(),
visible));
@@ -1695,27 +1690,40 @@ void AutomationProvider::HandleFindRequest(const IPC::Message& message,
void AutomationProvider::HandleOpenFindInPageRequest(
const IPC::Message& message, int handle) {
- if (tab_tracker_->ContainsHandle(handle)) {
- NavigationController* tab = tab_tracker_->GetResource(handle);
+ NavigationController* tab = NULL;
+ WebContents* web_contents = GetWebContentsForHandle(handle, &tab);
+ if (web_contents) {
Browser* browser = Browser::GetBrowserForController(tab, NULL);
- if (tab->active_contents()->AsWebContents()) {
- WebContents* web_contents = tab->active_contents()->AsWebContents();
- web_contents->OpenFindInPageWindow(*browser);
- }
+ web_contents->OpenFindInPageWindow(*browser);
}
}
+void AutomationProvider::GetFindWindowVisibility(const IPC::Message& message,
+ int handle) {
+ bool visible = false;
+ WebContents* web_contents = GetWebContentsForHandle(handle, NULL);
+ if (web_contents)
+ visible = web_contents->IsFindWindowFullyVisible();
+
+ Send(new AutomationMsg_FindWindowVisibilityResponse(message.routing_id(),
+ visible));
+}
+
+void AutomationProvider::HandleFindWindowLocationRequest(
+ const IPC::Message& message, int handle) {
+ int x = -1, y = -1;
+ WebContents* web_contents = GetWebContentsForHandle(handle, NULL);
+ if (web_contents)
+ web_contents->GetFindInPageWindowLocation(&x, &y);
+
+ Send(new AutomationMsg_FindWindowLocationResponse(message.routing_id(),
+ x, y));
+}
+
void AutomationProvider::HandleInspectElementRequest(
const IPC::Message& message, int handle, int x, int y) {
- if (!tab_tracker_->ContainsHandle(handle)) {
- Send(new AutomationMsg_InspectElementResponse(message.routing_id(), -1));
- return;
- }
-
- NavigationController* nav = tab_tracker_->GetResource(handle);
- TabContents* tab_contents = nav->active_contents();
- if (tab_contents->type() == TAB_CONTENTS_WEB) {
- WebContents* web_contents = tab_contents->AsWebContents();
+ WebContents* web_contents = GetWebContentsForHandle(handle, NULL);
+ if (web_contents) {
web_contents->InspectElementAt(x, y);
inspect_element_routing_id_ = message.routing_id();
} else {
@@ -1863,16 +1871,12 @@ void AutomationProvider::ShowInterstitialPage(const IPC::Message& message,
void AutomationProvider::HideInterstitialPage(const IPC::Message& message,
int tab_handle) {
- if (tab_tracker_->ContainsHandle(tab_handle)) {
- NavigationController* controller = tab_tracker_->GetResource(tab_handle);
- TabContents* tab_contents = controller->active_contents();
- if (tab_contents->type() == TAB_CONTENTS_WEB) {
- WebContents* web_contents = tab_contents->AsWebContents();
- web_contents->HideInterstitialPage(false, false);
- Send(new AutomationMsg_HideInterstitialPageResponse(message.routing_id(),
- true));
- return;
- }
+ WebContents* web_contents = GetWebContentsForHandle(tab_handle, NULL);
+ if (web_contents) {
+ web_contents->HideInterstitialPage(false, false);
+ Send(new AutomationMsg_HideInterstitialPageResponse(message.routing_id(),
+ true));
+ return;
}
Send(new AutomationMsg_HideInterstitialPageResponse(message.routing_id(),
false));
@@ -2080,16 +2084,14 @@ void AutomationProvider::IsPageMenuCommandEnabled(const IPC::Message& message,
}
void AutomationProvider::PrintNow(const IPC::Message& message, int tab_handle) {
- if (tab_tracker_->ContainsHandle(tab_handle)) {
- NavigationController* tab = tab_tracker_->GetResource(tab_handle);
+ NavigationController* tab = NULL;
+ WebContents* web_contents = GetWebContentsForHandle(tab_handle, &tab);
+ if (web_contents) {
FindAndActivateTab(tab);
- WebContents* const web_contents = tab->active_contents()->AsWebContents();
- if (web_contents) {
- notification_observer_list_.AddObserver(
- new DocumentPrintedNotificationObserver(this, message.routing_id()));
- if (web_contents->PrintNow())
- return;
- }
+ notification_observer_list_.AddObserver(
+ new DocumentPrintedNotificationObserver(this, message.routing_id()));
+ if (web_contents->PrintNow())
+ return;
}
Send(new AutomationMsg_PrintNowResponse(message.routing_id(), false));
}
@@ -2218,6 +2220,21 @@ void AutomationProvider::OnMessageFromExternalHost(
}
}
+WebContents* AutomationProvider::GetWebContentsForHandle(
+ int handle, NavigationController** tab) {
+ WebContents* web_contents = NULL;
+ if (tab_tracker_->ContainsHandle(handle)) {
+ NavigationController* nav_controller = tab_tracker_->GetResource(handle);
+ TabContents* tab_contents = nav_controller->active_contents();
+ if (tab_contents && tab_contents->type() == TAB_CONTENTS_WEB) {
+ web_contents = tab_contents->AsWebContents();
+ if (tab)
+ *tab = nav_controller;
+ }
+ }
+ return web_contents;
+}
+
TestingAutomationProvider::TestingAutomationProvider(Profile* profile)
: AutomationProvider(profile) {
BrowserList::AddObserver(this);
@@ -2260,4 +2277,3 @@ void TestingAutomationProvider::Observe(NotificationType type,
void TestingAutomationProvider::OnRemoveProvider() {
AutomationProviderList::GetInstance()->RemoveProvider(this);
}
-
diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h
index 0b08627..24b335e 100644
--- a/chrome/browser/automation/automation_provider.h
+++ b/chrome/browser/automation/automation_provider.h
@@ -202,6 +202,12 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
void HandleOpenFindInPageRequest(const IPC::Message& message,
int handle);
+ // Get the visibility state of the Find window.
+ void GetFindWindowVisibility(const IPC::Message& message, int handle);
+
+ // Responds to requests to find the location of the Find window.
+ void HandleFindWindowLocationRequest(const IPC::Message& message, int handle);
+
// Responds to InspectElement request
void HandleInspectElementRequest(const IPC::Message& message,
int handle,
@@ -295,6 +301,11 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
void OnMessageFromExternalHost(int handle, const std::string& target,
const std::string& message);
+ // Convert a tab handle into a WebContents. If |tab| is specified a pointer
+ // to the tab is returned. Returns NULL in case of failure or if the tab is
+ // not of the WebContents type.
+ WebContents* GetWebContentsForHandle(int handle, NavigationController** tab);
+
// Callback for history redirect queries.
virtual void OnRedirectQueryComplete(
HistoryService::Handle request_handle,