Index: chrome/browser/password_manager/password_manager_browsertest.cc |
=================================================================== |
--- chrome/browser/password_manager/password_manager_browsertest.cc (revision 212931) |
+++ chrome/browser/password_manager/password_manager_browsertest.cc (working copy) |
@@ -24,52 +24,33 @@ |
#include "testing/gmock/include/gmock/gmock.h" |
#include "ui/base/keycodes/keyboard_codes.h" |
+ |
+// NavigationObserver --------------------------------------------------------- |
+ |
namespace { |
class NavigationObserver : public content::NotificationObserver, |
public content::WebContentsObserver { |
public: |
- explicit NavigationObserver(content::WebContents* web_contents) |
- : content::WebContentsObserver(web_contents), |
- message_loop_runner_(new content::MessageLoopRunner), |
- info_bar_shown_(false), |
- infobar_service_(InfoBarService::FromWebContents(web_contents)) { |
- registrar_.Add(this, |
- chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
- content::Source<InfoBarService>(infobar_service_)); |
- } |
+ explicit NavigationObserver(content::WebContents* web_contents); |
+ virtual ~NavigationObserver(); |
- virtual ~NavigationObserver() {} |
- |
- void Wait() { |
- message_loop_runner_->Run(); |
- } |
- |
- bool InfoBarWasShown() { |
- return info_bar_shown_; |
- } |
- |
// content::NotificationObserver: |
virtual void Observe(int type, |
const content::NotificationSource& source, |
- const content::NotificationDetails& details) OVERRIDE { |
- // Accept in the infobar. |
- InfoBarDelegate* infobar = infobar_service_->infobar_at(0); |
- ConfirmInfoBarDelegate* confirm_infobar = |
- infobar->AsConfirmInfoBarDelegate(); |
- confirm_infobar->Accept(); |
- info_bar_shown_ = true; |
- } |
+ const content::NotificationDetails& details) OVERRIDE; |
// content::WebContentsObserver |
virtual void DidFinishLoad( |
int64 frame_id, |
const GURL& validated_url, |
bool is_main_frame, |
- content::RenderViewHost* render_view_host) OVERRIDE { |
- message_loop_runner_->Quit(); |
- } |
+ content::RenderViewHost* render_view_host) OVERRIDE; |
+ bool infobar_shown() { return info_bar_shown_; } |
+ |
+ void Wait(); |
+ |
private: |
scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
bool info_bar_shown_; |
@@ -77,30 +58,76 @@ |
InfoBarService* infobar_service_; |
}; |
+NavigationObserver::NavigationObserver(content::WebContents* web_contents) |
+ : content::WebContentsObserver(web_contents), |
+ message_loop_runner_(new content::MessageLoopRunner), |
+ info_bar_shown_(false), |
+ infobar_service_(InfoBarService::FromWebContents(web_contents)) { |
+ registrar_.Add(this, |
+ chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
+ content::Source<InfoBarService>(infobar_service_)); |
+} |
+ |
+NavigationObserver::~NavigationObserver() { |
+} |
+ |
+void NavigationObserver::Observe(int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) { |
+ // Accept in the infobar. |
+ InfoBarDelegate* infobar = infobar_service_->infobar_at(0); |
+ ConfirmInfoBarDelegate* confirm_infobar = |
+ infobar->AsConfirmInfoBarDelegate(); |
+ confirm_infobar->Accept(); |
+ info_bar_shown_ = true; |
+} |
+ |
+void NavigationObserver::DidFinishLoad( |
+ int64 frame_id, |
+ const GURL& validated_url, |
+ bool is_main_frame, |
+ content::RenderViewHost* render_view_host) { |
+ message_loop_runner_->Quit(); |
+} |
+ |
+void NavigationObserver::Wait() { |
+ message_loop_runner_->Run(); |
+} |
+ |
} // namespace |
+ |
+// PasswordManagerBrowserTest ------------------------------------------------- |
+ |
class PasswordManagerBrowserTest : public InProcessBrowserTest { |
public: |
- virtual void SetUpOnMainThread() OVERRIDE { |
- // Use TestPasswordStore to remove a possible race. Normally the |
- // PasswordStore does it's database manipulation on the DB thread, which |
- // creates a possible race during navigation. Specifically the |
- // PasswordManager will ignore any forms in a page if the load from the |
- // PasswordStore has not completed. |
- PasswordStoreFactory::GetInstance()->SetTestingFactory( |
- browser()->profile(), &TestPasswordStore::Create); |
- } |
+ virtual void SetUpOnMainThread() OVERRIDE; |
protected: |
- content::WebContents* WebContents() { |
- return browser()->tab_strip_model()->GetActiveWebContents(); |
- } |
- |
- content::RenderViewHost* RenderViewHost() { |
- return WebContents()->GetRenderViewHost(); |
- } |
+ content::WebContents* WebContents(); |
+ content::RenderViewHost* RenderViewHost(); |
}; |
+void PasswordManagerBrowserTest::SetUpOnMainThread() { |
+ // Use TestPasswordStore to remove a possible race. Normally the PasswordStore |
+ // does its database manipulation on the DB thread, which creates a possible |
+ // race during navigation. Specifically the PasswordManager will ignore any |
+ // forms in a page if the load from the PasswordStore has not completed. |
+ PasswordStoreFactory::GetInstance()->SetTestingFactory( |
+ browser()->profile(), &TestPasswordStore::Create); |
+} |
+ |
+content::WebContents* PasswordManagerBrowserTest::WebContents() { |
+ return browser()->tab_strip_model()->GetActiveWebContents(); |
+} |
+ |
+content::RenderViewHost* PasswordManagerBrowserTest::RenderViewHost() { |
+ return WebContents()->GetRenderViewHost(); |
+} |
+ |
+ |
+// Actual tests --------------------------------------------------------------- |
+ |
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PromptForXHRSubmit) { |
ASSERT_TRUE(test_server()->Start()); |
@@ -118,7 +145,7 @@ |
"document.getElementById('submit_button').click()"; |
ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
observer.Wait(); |
- EXPECT_TRUE(observer.InfoBarWasShown()); |
+ EXPECT_TRUE(observer.infobar_shown()); |
} |
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptForOtherXHR) { |
@@ -139,5 +166,5 @@ |
"send_xhr()"; |
ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate)); |
observer.Wait(); |
- EXPECT_FALSE(observer.InfoBarWasShown()); |
+ EXPECT_FALSE(observer.infobar_shown()); |
} |