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 ee8e2b41b2b4e0cc39a18543a4d037c6751f66b4..995c35db1391964c817be61cc02d4ae272576065 100644 |
--- a/chrome/browser/password_manager/password_manager_browsertest.cc |
+++ b/chrome/browser/password_manager/password_manager_browsertest.cc |
@@ -19,10 +19,8 @@ |
#include "chrome/test/base/ui_test_utils.h" |
#include "components/autofill/core/browser/autofill_test_utils.h" |
#include "components/infobars/core/infobar.h" |
+#include "components/infobars/core/infobar_manager.h" |
#include "components/password_manager/core/browser/test_password_store.h" |
-#include "content/public/browser/notification_observer.h" |
-#include "content/public/browser/notification_registrar.h" |
-#include "content/public/browser/notification_service.h" |
#include "content/public/browser/render_view_host.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/browser/web_contents_observer.h" |
@@ -41,8 +39,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 infobars::InfoBarManager::Observer { |
public: |
explicit NavigationObserver(content::WebContents* web_contents) |
: content::WebContentsObserver(web_contents), |
@@ -51,15 +49,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 +64,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 +90,27 @@ class NavigationObserver : public content::NotificationObserver, |
} |
private: |
+ // infobars::InfoBarManager::Observer: |
+ virtual void OnInfoBarAdded(infobars::InfoBar* infobar) OVERRIDE { |
+ if (should_automatically_accept_infobar_) { |
+ infobar_service_->infobar_at(0)->delegate()-> |
+ AsConfirmInfoBarDelegate()->Accept(); |
+ } |
+ infobar_shown_ = true; |
+ } |
+ |
+ virtual void OnInfoBarRemoved(infobars::InfoBar* infobar, |
+ bool animate) OVERRIDE { |
+ infobar_removed_ = true; |
+ } |
+ |
+ virtual void OnManagerShuttingDown( |
+ infobars::InfoBarManager* manager) OVERRIDE { |
+ ASSERT_EQ(infobar_service_, manager); |
+ infobar_service_->RemoveObserver(this); |
+ infobar_service_ = NULL; |
+ } |
+ |
std::string wait_for_path_; |
scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
bool infobar_shown_; |
@@ -122,7 +118,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); |