summaryrefslogtreecommitdiffstats
path: root/chrome/browser/automation
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-24 17:42:42 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-24 17:42:42 +0000
commit8a3422c9488ce79e305973d29a01811762e35465 (patch)
tree7fc94cb7aa013f7bb2afaf4100b1a8f45208cc00 /chrome/browser/automation
parent5eb64653873981c7dbf693a9aba7c7da011b14a3 (diff)
downloadchromium_src-8a3422c9488ce79e305973d29a01811762e35465.zip
chromium_src-8a3422c9488ce79e305973d29a01811762e35465.tar.gz
chromium_src-8a3422c9488ce79e305973d29a01811762e35465.tar.bz2
This CL adds new UI tests for the SSL UI.
Some more info: SSL UI Tests: Added new tests for redirects and frames. Also improved the mixed-content test to exercise the "block mixed-contents" preference and the show info-bar. Automation: For the new UI tests, added methods to tab_proxy and browser_proxy. The ones of most interest are GetLastNavigatinTime and WaitForNavigation that ensures we wait for a navigation to occur or have occured when taking actions that asynchronously trigger navigations. Resource loading: Added a flag to the response we get when loading a resource that indicates whether that resource was filtered (blocked or altered) by the security peer. We use this flag to notify back the browser when we report a load has been committed. This is so the SSL manager knows a frame has been filtered (in which case we have no cert info but should not consider that as unsafe). BUG=2004 Review URL: http://codereview.chromium.org/3165 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2553 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation')
-rw-r--r--chrome/browser/automation/automation_provider.cc113
-rw-r--r--chrome/browser/automation/automation_provider.h28
-rw-r--r--chrome/browser/automation/automation_tab_tracker.h47
3 files changed, 185 insertions, 3 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 4c1ed49..8c2da33 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -21,11 +21,13 @@
#include "chrome/browser/navigation_entry.h"
#include "chrome/browser/printing/print_job.h"
#include "chrome/browser/render_view_host.h"
+#include "chrome/browser/ssl_manager.h"
#include "chrome/browser/ssl_blocking_page.h"
#include "chrome/browser/web_contents.h"
#include "chrome/browser/views/bookmark_bar_view.h"
#include "chrome/browser/views/location_bar_view.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/common/pref_service.h"
#include "chrome/test/automation/automation_messages.h"
#include "net/base/cookie_monster.h"
#include "net/url_request/url_request_filter.h"
@@ -182,7 +184,6 @@ class NavigationControllerRestoredObserver : public NotificationObserver {
DISALLOW_COPY_AND_ASSIGN(NavigationControllerRestoredObserver);
};
-
class NavigationNotificationObserver : public NotificationObserver {
public:
NavigationNotificationObserver(NavigationController* controller,
@@ -195,6 +196,8 @@ class NavigationNotificationObserver : public NotificationObserver {
controller_(controller),
navigation_started_(false) {
NotificationService* service = NotificationService::current();
+ service->AddObserver(this, NOTIFY_NAV_ENTRY_COMMITTED,
+ Source<NavigationController>(controller_));
service->AddObserver(this, NOTIFY_LOAD_START,
Source<NavigationController>(controller_));
service->AddObserver(this, NOTIFY_LOAD_STOP,
@@ -222,6 +225,8 @@ class NavigationNotificationObserver : public NotificationObserver {
void Unregister() {
NotificationService* service = NotificationService::current();
+ service->RemoveObserver(this, NOTIFY_NAV_ENTRY_COMMITTED,
+ Source<NavigationController>(controller_));
service->RemoveObserver(this, NOTIFY_LOAD_START,
Source<NavigationController>(controller_));
service->RemoveObserver(this, NOTIFY_LOAD_STOP,
@@ -235,7 +240,14 @@ class NavigationNotificationObserver : public NotificationObserver {
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
- if (type == NOTIFY_LOAD_START) {
+ // We listen for 2 events to determine when the navigation started because:
+ // - when this is used by the WaitForNavigation method, we might be invoked
+ // afer the load has started (but not after the entry was committed, as
+ // WaitForNavigation compares times of the last navigation).
+ // - when this is used with a page requiring authentication, we will not get
+ // a NOTIFY_NAV_ENTRY_COMMITTED until after we authenticate, so we need the
+ // NOTIFY_LOAD_START.
+ if (type == NOTIFY_NAV_ENTRY_COMMITTED || type == NOTIFY_LOAD_START) {
navigation_started_ = true;
} else if (type == NOTIFY_LOAD_STOP) {
if (navigation_started_) {
@@ -758,6 +770,16 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
HandleFindWindowLocationRequest)
IPC_MESSAGE_HANDLER(AutomationMsg_BookmarkBarVisibilityRequest,
GetBookmarkBarVisitility)
+ IPC_MESSAGE_HANDLER(AutomationMsg_GetSSLInfoBarCountRequest,
+ GetSSLInfoBarCount)
+ IPC_MESSAGE_HANDLER(AutomationMsg_ClickSSLInfoBarLinkRequest,
+ ClickSSLInfoBarLink)
+ IPC_MESSAGE_HANDLER(AutomationMsg_GetLastNavigationTimeRequest,
+ GetLastNavigationTime)
+ IPC_MESSAGE_HANDLER(AutomationMsg_WaitForNavigationRequest,
+ WaitForNavigation)
+ IPC_MESSAGE_HANDLER(AutomationMsg_SetIntPreferenceRequest,
+ SetIntPreference)
IPC_END_MESSAGE_MAP()
}
@@ -2294,3 +2316,90 @@ void TestingAutomationProvider::Observe(NotificationType type,
void TestingAutomationProvider::OnRemoveProvider() {
AutomationProviderList::GetInstance()->RemoveProvider(this);
}
+
+void AutomationProvider::GetSSLInfoBarCount(const IPC::Message& message,
+ int handle) {
+ int count = -1; // -1 means error.
+ if (tab_tracker_->ContainsHandle(handle)) {
+ NavigationController* nav_controller = tab_tracker_->GetResource(handle);
+ if (nav_controller) {
+ count = static_cast<int>(nav_controller->ssl_manager()->
+ visible_info_bars_.size());
+ }
+ }
+ Send(new AutomationMsg_GetSSLInfoBarCountResponse(message.routing_id(),
+ count));
+}
+
+void AutomationProvider::ClickSSLInfoBarLink(const IPC::Message& message,
+ int handle,
+ int info_bar_index,
+ bool wait_for_navigation) {
+ bool success = false;
+ if (tab_tracker_->ContainsHandle(handle)) {
+ NavigationController* nav_controller = tab_tracker_->GetResource(handle);
+ if (nav_controller) {
+ int count = static_cast<int>(nav_controller->ssl_manager()->
+ visible_info_bars_.size());
+ if (info_bar_index >= 0 && info_bar_index < count) {
+ if (wait_for_navigation) {
+ AddNavigationStatusListener(nav_controller,
+ new AutomationMsg_ClickSSLInfoBarLinkResponse(
+ message.routing_id(), true),
+ new AutomationMsg_ClickSSLInfoBarLinkResponse(
+ message.routing_id(), true));
+ }
+ SSLManager::SSLInfoBar* info_bar =
+ nav_controller->ssl_manager()->visible_info_bars_.
+ GetElementAt(info_bar_index);
+ info_bar->LinkActivated(NULL, 0); // Parameters are not used.
+ success = true;
+ }
+ }
+ }
+ if (!wait_for_navigation || !success)
+ Send(new AutomationMsg_ClickSSLInfoBarLinkResponse(message.routing_id(),
+ success));
+}
+
+void AutomationProvider::GetLastNavigationTime(const IPC::Message& message,
+ int handle) {
+ Time time = tab_tracker_->GetLastNavigationTime(handle);
+ Send(new AutomationMsg_GetLastNavigationTimeResponse(message.routing_id(),
+ time.ToInternalValue()));
+}
+
+void AutomationProvider::WaitForNavigation(const IPC::Message& message,
+ int handle,
+ int64 last_navigation_time) {
+ NavigationController* controller = NULL;
+ if (tab_tracker_->ContainsHandle(handle))
+ controller = tab_tracker_->GetResource(handle);
+
+ Time time = tab_tracker_->GetLastNavigationTime(handle);
+ if (time.ToInternalValue() > last_navigation_time || !controller) {
+ Send(new AutomationMsg_WaitForNavigationResponse(message.routing_id(),
+ controller != NULL));
+ return;
+ }
+
+ AddNavigationStatusListener(controller,
+ new AutomationMsg_WaitForNavigationResponse(message.routing_id(),
+ true),
+ new AutomationMsg_WaitForNavigationResponse(message.routing_id(),
+ true));
+}
+
+void AutomationProvider::SetIntPreference(const IPC::Message& message,
+ int handle,
+ std::wstring name,
+ int value) {
+ bool success = false;
+ if (browser_tracker_->ContainsHandle(handle)) {
+ Browser* browser = browser_tracker_->GetResource(handle);
+ browser->profile()->GetPrefs()->SetInteger(name.c_str(), value);
+ success = true;
+ }
+ Send(new AutomationMsg_SetIntPreferenceResponse(message.routing_id(),
+ success));
+}
diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h
index 674565c..d67615f 100644
--- a/chrome/browser/automation/automation_provider.h
+++ b/chrome/browser/automation/automation_provider.h
@@ -294,7 +294,7 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
// Retrieves if a query to an autocomplete provider is in progress.
void AutocompleteEditIsQueryInProgress(const IPC::Message& message,
- int autocomplete_edit_handle);
+ int autocomplete_edit_handle);
// Retrieves the individual autocomplete matches displayed by the popup.
void AutocompleteEditGetMatches(const IPC::Message& message,
@@ -304,6 +304,32 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
void OnMessageFromExternalHost(int handle, const std::string& target,
const std::string& message);
+ // Retrieves the number of SSL related info-bars currently showing in |count|.
+ void GetSSLInfoBarCount(const IPC::Message& message, int handle);
+
+ // Causes a click on the link of the info-bar at |info_bar_index|. If
+ // |wait_for_navigation| is true, it sends the reply after a navigation has
+ // occurred.
+ void ClickSSLInfoBarLink(const IPC::Message& message,
+ int handle,
+ int info_bar_index,
+ bool wait_for_navigation);
+
+ // Retrieves the last time a navigation occurred for the tab.
+ void GetLastNavigationTime(const IPC::Message& message, int handle);
+
+ // Waits for a new navigation in the tab if none has happened since
+ // |last_navigation_time|.
+ void WaitForNavigation(const IPC::Message& message,
+ int handle,
+ int64 last_navigation_time);
+
+ // Sets the int value for preference with name |name|.
+ void SetIntPreference(const IPC::Message& message,
+ int handle,
+ std::wstring name,
+ int value);
+
// Convert a tab handle into a WebContents. If |tab| is non-NULL a pointer
// to the tab is also returned. Returns NULL in case of failure or if the tab
// is not of the WebContents type.
diff --git a/chrome/browser/automation/automation_tab_tracker.h b/chrome/browser/automation/automation_tab_tracker.h
index 5cda520..bb9ac24 100644
--- a/chrome/browser/automation/automation_tab_tracker.h
+++ b/chrome/browser/automation/automation_tab_tracker.h
@@ -28,6 +28,11 @@ public:
NotificationService::current()->AddObserver(
this, NOTIFY_EXTERNAL_TAB_CLOSED,
Source<NavigationController>(resource));
+ // We also want to know about navigations so we can keep track of the last
+ // navigation time.
+ NotificationService::current()->AddObserver(
+ this, NOTIFY_NAV_ENTRY_COMMITTED,
+ Source<NavigationController>(resource));
}
virtual void RemoveObserver(NavigationController* resource) {
@@ -36,7 +41,49 @@ public:
NotificationService::current()->RemoveObserver(
this, NOTIFY_EXTERNAL_TAB_CLOSED,
Source<NavigationController>(resource));
+ NotificationService::current()->RemoveObserver(
+ this, NOTIFY_NAV_ENTRY_COMMITTED,
+ Source<NavigationController>(resource));
+ }
+
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ switch (type) {
+ case NOTIFY_NAV_ENTRY_COMMITTED:
+ last_navigation_times_[Source<NavigationController>(source).ptr()] =
+ Time::Now();
+ return;
+ case NOTIFY_EXTERNAL_TAB_CLOSED:
+ case NOTIFY_TAB_CLOSING:
+ std::map<NavigationController*, Time>::iterator iter =
+ last_navigation_times_.find(
+ Source<NavigationController>(source).ptr());
+ if (iter != last_navigation_times_.end())
+ last_navigation_times_.erase(iter);
+ break;
+ }
+ AutomationResourceTracker::Observe(type, source, details);
+ }
+
+ Time GetLastNavigationTime(int handle) {
+ if (ContainsHandle(handle)) {
+ NavigationController* controller = GetResource(handle);
+ if (controller) {
+ std::map<NavigationController*, Time>::const_iterator iter =
+ last_navigation_times_.find(controller);
+ if (iter != last_navigation_times_.end())
+ return iter->second;
+ }
+ }
+ return Time();
}
+
+ private:
+ // Last time a navigation occurred.
+ std::map<NavigationController*, Time> last_navigation_times_;
+
+ DISALLOW_COPY_AND_ASSIGN(AutomationTabTracker);
};
#endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_TAB_TRACKER_H__