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

Unified Diff: chrome/browser/password_manager/password_manager_browsertest.cc

Issue 243953002: Update PasswordManagerBrowserTest to use the new Observer class from InfoBarManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/password_manager/password_manager_browsertest.cc
diff --git a/chrome/browser/password_manager/password_manager_browsertest.cc b/chrome/browser/password_manager/password_manager_browsertest.cc
index 435a43fa1fa2acf637b3305ed17e8c945bc7335e..6beb813e3e4400c8590b878aeacf890c3eccf68f 100644
--- a/chrome/browser/password_manager/password_manager_browsertest.cc
+++ b/chrome/browser/password_manager/password_manager_browsertest.cc
@@ -41,8 +41,8 @@ namespace {
// Observer that waits for navigation to complete and for the password infobar
// to be shown.
-class NavigationObserver : public content::NotificationObserver,
- public content::WebContentsObserver {
+class NavigationObserver : public content::WebContentsObserver,
+ public InfoBarManager::Observer {
public:
explicit NavigationObserver(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
@@ -51,15 +51,13 @@ class NavigationObserver : public content::NotificationObserver,
infobar_removed_(false),
should_automatically_accept_infobar_(true),
infobar_service_(InfoBarService::FromWebContents(web_contents)) {
- registrar_.Add(this,
- chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
- content::Source<InfoBarService>(infobar_service_));
- registrar_.Add(this,
- chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
- content::Source<InfoBarService>(infobar_service_));
+ infobar_service_->AddObserver(this);
}
- virtual ~NavigationObserver() {}
+ virtual ~NavigationObserver() {
+ if (infobar_service_)
+ infobar_service_->RemoveObserver(this);
+ }
// Normally Wait() will not return until a main frame navigation occurs.
// If a path is set, Wait() will return after this path has been seen,
@@ -68,27 +66,6 @@ class NavigationObserver : public content::NotificationObserver,
wait_for_path_ = path;
}
- // content::NotificationObserver:
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE {
- switch (type) {
- case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED:
- if (should_automatically_accept_infobar_) {
- infobar_service_->infobar_at(0)->delegate()->
- AsConfirmInfoBarDelegate()->Accept();
- }
- infobar_shown_ = true;
- return;
- case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED:
- infobar_removed_ = true;
- return;
- default:
- NOTREACHED();
- return;
- }
- }
-
// content::WebContentsObserver:
virtual void DidFinishLoad(
int64 frame_id,
@@ -115,6 +92,27 @@ class NavigationObserver : public content::NotificationObserver,
}
private:
+ // InfoBarManager::Observer
Peter Kasting 2014/04/18 23:52:39 Nit: Add trailing colon
tfarina 2014/04/19 18:43:10 Done.
+ virtual void OnInfoBarAdded(InfoBar* infobar) OVERRIDE {
+ if (should_automatically_accept_infobar_) {
+ infobar_service_->infobar_at(0)
+ ->delegate()
+ ->AsConfirmInfoBarDelegate()
+ ->Accept();
Peter Kasting 2014/04/18 23:52:39 Nit: Wrap like the old code did
tfarina 2014/04/19 18:43:10 Done.
+ }
+ infobar_shown_ = true;
+ }
Ilya Sherman 2014/04/19 04:21:27 nit: Please leave a blank line between method defi
+ virtual void OnInfoBarRemoved(InfoBar* infobar, bool animate) OVERRIDE {
+ infobar_removed_ = true;
+ }
+ virtual void OnInfoBarReplaced(InfoBar* old_infobar,
+ InfoBar* new_infobar) OVERRIDE {}
Peter Kasting 2014/04/18 23:52:39 Subclasses shouldn't need to override methods they
tfarina 2014/04/19 18:43:10 Done.
+ virtual void OnManagerShuttingDown(InfoBarManager* manager) OVERRIDE {
+ DCHECK_EQ(infobar_service_, manager);
Ilya Sherman 2014/04/19 04:21:27 nit: ASSERT_EQ is preferable in tests, as it doesn
tfarina 2014/04/19 18:43:10 Done.
+ infobar_service_->RemoveObserver(this);
+ infobar_service_ = NULL;
+ }
+
std::string wait_for_path_;
scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
bool infobar_shown_;
@@ -122,7 +120,6 @@ class NavigationObserver : public content::NotificationObserver,
// If |should_automatically_accept_infobar_| is true, then whenever the test
// sees an infobar added, it will click its accepting button. Default = true.
bool should_automatically_accept_infobar_;
- content::NotificationRegistrar registrar_;
InfoBarService* infobar_service_;
DISALLOW_COPY_AND_ASSIGN(NavigationObserver);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698