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..aa9e168c9a37c799ab25839ad62832126b1ea00e 100644 |
--- a/chrome/browser/password_manager/password_manager_browsertest.cc |
+++ b/chrome/browser/password_manager/password_manager_browsertest.cc |
@@ -19,6 +19,7 @@ |
#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" |
@@ -41,8 +42,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 +52,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 +67,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 +93,27 @@ class NavigationObserver : public content::NotificationObserver, |
} |
private: |
+ // InfoBarManager::Observer: |
+ virtual void OnInfoBarAdded(InfoBar* infobar) OVERRIDE { |
+ if (should_automatically_accept_infobar_) { |
+ infobar_service_->infobar_at(0) |
+ ->delegate() |
+ ->AsConfirmInfoBarDelegate() |
+ ->Accept(); |
Peter Kasting
2014/04/21 20:34:06
Nit: This still isn't wrapped like the old code wa
tfarina
2014/04/21 20:56:40
I managed to get this right in patch set 2, then I
|
+ } |
+ infobar_shown_ = true; |
+ } |
+ |
+ virtual void OnInfoBarRemoved(InfoBar* infobar, bool animate) OVERRIDE { |
+ infobar_removed_ = true; |
+ } |
+ |
+ virtual void OnManagerShuttingDown(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 +121,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); |