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

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: include infobar_manager.h it is now in components/infobars/ 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
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);
« no previous file with comments | « no previous file | components/infobars/core/infobar_manager.h » ('j') | components/infobars/core/infobar_manager.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698