 Chromium Code Reviews
 Chromium Code Reviews Issue 243953002:
  Update PasswordManagerBrowserTest to use the new Observer class from InfoBarManager.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 243953002:
  Update PasswordManagerBrowserTest to use the new Observer class from InfoBarManager.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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..f33aaf676b1a831cc3bd6585f7ea454d157c9b30 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,11 @@ class NavigationObserver : public content::NotificationObserver, | 
| } | 
| private: | 
| + // InfoBarManager::Observer: | 
| + virtual void OnInfoBarAdded(InfoBar* infobar) OVERRIDE; | 
| + virtual void OnInfoBarRemoved(InfoBar* infobar, bool animate) OVERRIDE; | 
| + virtual void OnManagerShuttingDown(InfoBarManager* manager) OVERRIDE; | 
| + | 
| std::string wait_for_path_; | 
| scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 
| bool infobar_shown_; | 
| @@ -122,12 +104,29 @@ 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); | 
| }; | 
| +void NavigationObserver::OnInfoBarAdded(InfoBar* infobar) { | 
| + if (should_automatically_accept_infobar_) { | 
| + infobar_service_->infobar_at(0)->delegate()-> | 
| + AsConfirmInfoBarDelegate()->Accept(); | 
| + } | 
| + infobar_shown_ = true; | 
| +} | 
| + | 
| +void NavigationObserver::OnInfoBarRemoved(InfoBar* infobar, bool animate) { | 
| + infobar_removed_ = true; | 
| +} | 
| + | 
| +void NavigationObserver::OnManagerShuttingDown(InfoBarManager* manager) { | 
| + ASSERT_EQ(infobar_service_, manager); | 
| + infobar_service_->RemoveObserver(this); | 
| + infobar_service_ = NULL; | 
| +} | 
| 
Ilya Sherman
2014/04/19 19:46:04
nit: Please inline these implementations, to match
 
tfarina
2014/04/19 22:03:23
Done.
 | 
| + | 
| } // namespace |