Chromium Code Reviews| 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 b2b5b52d3366091e78c8ddb6ae596cf75c42bce8..42061ca6ddaa45550161bfb47696e7dfff039a9d 100644 |
| --- a/chrome/browser/password_manager/password_manager_browsertest.cc |
| +++ b/chrome/browser/password_manager/password_manager_browsertest.cc |
| @@ -55,23 +55,13 @@ namespace { |
| // Observer that waits for navigation to complete and for the password infobar |
| // to be shown. |
| -class NavigationObserver : public content::WebContentsObserver, |
| - public infobars::InfoBarManager::Observer { |
| +class NavigationObserver : public content::WebContentsObserver { |
| public: |
| explicit NavigationObserver(content::WebContents* web_contents) |
| : content::WebContentsObserver(web_contents), |
| - message_loop_runner_(new content::MessageLoopRunner), |
| - infobar_shown_(false), |
| - infobar_removed_(false), |
| - should_automatically_accept_infobar_(true), |
| - infobar_service_(InfoBarService::FromWebContents(web_contents)) { |
| - infobar_service_->AddObserver(this); |
| - } |
| + message_loop_runner_(new content::MessageLoopRunner) {} |
| - virtual ~NavigationObserver() { |
| - if (infobar_service_) |
| - infobar_service_->RemoveObserver(this); |
| - } |
| + virtual ~NavigationObserver() {} |
| // 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, |
| @@ -91,30 +81,88 @@ class NavigationObserver : public content::WebContentsObserver, |
| } |
| } |
| - bool infobar_shown() const { return infobar_shown_; } |
| - bool infobar_removed() const { return infobar_removed_; } |
| + void Wait() { |
| + message_loop_runner_->Run(); |
| + } |
| + |
| + private: |
| + |
| + std::string wait_for_path_; |
| + scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(NavigationObserver); |
| +}; |
| + |
| +// Observes save password prompt (bubble or infobar) for a specified |
|
engedy
2014/07/11 18:07:26
nits: Observes *the* save password prompt (bubble
vabr (Chromium)
2014/07/11 18:48:01
Done.
|
| +// WebContents, keeps track if it is currently shown, and allows accepting |
| +// passwords through it. |
| +class PromptObserver { |
| + public: |
| + virtual ~PromptObserver() {} |
| - void disable_should_automatically_accept_infobar() { |
| - should_automatically_accept_infobar_ = false; |
| + // Check if the prompt is being currently shown. |
|
engedy
2014/07/11 18:07:27
nits: Please use third person in comments. (3 verb
vabr (Chromium)
2014/07/11 18:48:02
Done.
|
| + virtual bool IsPromptShown() const = 0; |
|
engedy
2014/07/11 18:07:26
nit: IsShowingPrompt
vabr (Chromium)
2014/07/11 18:48:02
Done.
|
| + |
| + // Expecting that the prompt is shown, save the password. Check that the |
| + // prompt is no more visible. |
|
engedy
2014/07/11 18:07:27
nit: no longer visible afterwards.
vabr (Chromium)
2014/07/11 18:48:02
Done.
|
| + void Accept() const { |
| + EXPECT_TRUE(IsPromptShown()); |
| + AcceptImpl(); |
| } |
| - void Wait() { |
| - message_loop_runner_->Run(); |
| + // Chooses the right implementation of PromptObserver and creates an instance |
| + // of it. |
| + static scoped_ptr<PromptObserver> Create(content::WebContents* web_contents); |
|
engedy
2014/07/11 18:07:26
Nice!
vabr (Chromium)
2014/07/11 18:48:02
Acknowledged.
(And thanks! :))
|
| + |
| + protected: |
| + PromptObserver() {} |
| + |
| + // Accepts the password. Can assume that the prompt is currently shown, makes |
|
engedy
2014/07/11 18:07:26
Nit: the implementation can assume ... but is requ
vabr (Chromium)
2014/07/11 18:48:02
Done.
|
| + // sure that the prompt is eventually closed. |
| + virtual void AcceptImpl() const = 0; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(PromptObserver); |
| +}; |
| + |
| +class InfoBarObserver : public PromptObserver, |
| + public infobars::InfoBarManager::Observer { |
| + public: |
| + explicit InfoBarObserver(content::WebContents* web_contents) |
| + : infobar_is_shown_(false), |
|
engedy
2014/07/11 18:07:27
nit: infobar_is_showing_ or is_infobar_showing_.
vabr (Chromium)
2014/07/11 18:48:01
Done, with a change to infobar_is_being_shown_, wh
|
| + infobar_service_(InfoBarService::FromWebContents(web_contents)) { |
| + infobar_service_->AddObserver(this); |
| + } |
| + |
| + virtual ~InfoBarObserver() { |
| + if (infobar_service_) |
| + infobar_service_->RemoveObserver(this); |
| } |
| private: |
| + // PromptObserver: |
| + virtual bool IsPromptShown() const OVERRIDE { return infobar_is_shown_; } |
| + |
| + virtual void AcceptImpl() const OVERRIDE { |
| + EXPECT_EQ(1u, infobar_service_->infobar_count()); |
|
engedy
2014/07/11 18:07:26
I would assert here instead. (Or your if-solution,
vabr (Chromium)
2014/07/11 18:48:01
Done.
I don't think it would hang because of this.
|
| + // ConfirmInfoBarDelegate::Accept returning true means the infobar is |
| + // immediately closed. Checking the return value is preferred to testing |
| + // IsPromptShown() here, for it avoids the delay until the closing |
| + // notification is received. |
| + EXPECT_TRUE(infobar_service_->infobar_at(0) |
| + ->delegate() |
| + ->AsConfirmInfoBarDelegate() |
| + ->Accept()); |
| + } |
| + |
| // 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; |
| + infobar_is_shown_ = true; |
| } |
| virtual void OnInfoBarRemoved(infobars::InfoBar* infobar, |
| bool animate) OVERRIDE { |
| - infobar_removed_ = true; |
| + infobar_is_shown_ = false; |
| } |
| virtual void OnManagerShuttingDown( |
| @@ -124,18 +172,46 @@ class NavigationObserver : public content::WebContentsObserver, |
| infobar_service_ = NULL; |
| } |
| - std::string wait_for_path_; |
| - scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| - bool infobar_shown_; |
| - bool infobar_removed_; |
| - // 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_; |
| + bool infobar_is_shown_; |
| InfoBarService* infobar_service_; |
| - DISALLOW_COPY_AND_ASSIGN(NavigationObserver); |
| + DISALLOW_COPY_AND_ASSIGN(InfoBarObserver); |
| +}; |
| + |
| +class BubbleObserver : public PromptObserver { |
| + public: |
| + explicit BubbleObserver(content::WebContents* web_contents) |
| + : ui_controller_( |
| + ManagePasswordsUIController::FromWebContents(web_contents)) {} |
| + |
| + virtual ~BubbleObserver() {} |
| + |
| + private: |
| + // PromptObserver: |
| + virtual bool IsPromptShown() const OVERRIDE { |
| + return ui_controller_->PasswordPendingUserDecision(); |
| + } |
| + |
| + virtual void AcceptImpl() const OVERRIDE { |
| + ui_controller_->SavePassword(); |
| + EXPECT_FALSE(IsPromptShown()); |
| + } |
| + |
| + ManagePasswordsUIController* const ui_controller_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BubbleObserver); |
| }; |
| +// static |
| +scoped_ptr<PromptObserver> PromptObserver::Create( |
| + content::WebContents* web_contents) { |
| + if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| + return scoped_ptr<PromptObserver>(new BubbleObserver(web_contents)); |
| + } else { |
| + return scoped_ptr<PromptObserver>(new InfoBarObserver(web_contents)); |
| + } |
| +} |
| + |
| // Handles |request| to "/basic_auth". If "Authorization" header is present, |
| // responds with a non-empty HTTP 200 page (regardless of its value). Otherwise |
| // serves a Basic Auth challenge. |
| @@ -196,10 +272,6 @@ class PasswordManagerBrowserTest : public InProcessBrowserTest { |
| return WebContents()->GetRenderViewHost(); |
| } |
| - ManagePasswordsUIController* ui_controller() { |
| - return ManagePasswordsUIController::FromWebContents(WebContents()); |
| - } |
| - |
| // Wrapper around ui_test_utils::NavigateToURL that waits until |
| // DidFinishLoad() fires. Normally this function returns after |
| // DidStopLoading(), which caused flakiness as the NavigationObserver |
| @@ -304,17 +376,15 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| // Fill a form and submit through a <input type="submit"> button. Nothing |
| // special. |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string fill_and_submit = |
| "document.getElementById('username_field').value = 'temp';" |
| "document.getElementById('password_field').value = 'random';" |
| "document.getElementById('input_submit_button').click()"; |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_TRUE(observer.infobar_shown()); |
| - } |
| + EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| } |
| IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| @@ -324,17 +394,15 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| // Fill a form and submit through a <input type="submit"> button. Nothing |
| // special. The form does an in-page navigation before submitting. |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string fill_and_submit = |
| "document.getElementById('username_field').value = 'temp';" |
| "document.getElementById('password_field').value = 'random';" |
| "document.getElementById('input_submit_button').click()"; |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_TRUE(observer.infobar_shown()); |
| - } |
| + EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| } |
| IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| @@ -345,17 +413,15 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| NavigateToFile("/password/password_form.html"); |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string fill_and_submit = |
| "document.getElementById('username_unrelated').value = 'temp';" |
| "document.getElementById('password_unrelated').value = 'random';" |
| "document.getElementById('submit_unrelated').click()"; |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_TRUE(observer.infobar_shown()); |
| - } |
| + EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| } |
| IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, LoginFailed) { |
| @@ -365,17 +431,15 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, LoginFailed) { |
| NavigateToFile("/password/password_form.html"); |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string fill_and_submit = |
| "document.getElementById('username_failed').value = 'temp';" |
| "document.getElementById('password_failed').value = 'random';" |
| "document.getElementById('submit_failed').click()"; |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_FALSE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_FALSE(observer.infobar_shown()); |
| - } |
| + EXPECT_FALSE(prompt_observer->IsPromptShown()); |
| } |
| IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, Redirects) { |
| @@ -384,29 +448,22 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, Redirects) { |
| // Fill a form and submit through a <input type="submit"> button. The form |
| // points to a redirection page. |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string fill_and_submit = |
| "document.getElementById('username_redirect').value = 'temp';" |
| "document.getElementById('password_redirect').value = 'random';" |
| "document.getElementById('submit_redirect').click()"; |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| - observer.disable_should_automatically_accept_infobar(); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_TRUE(observer.infobar_shown()); |
| - } |
| + EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| // The redirection page now redirects via Javascript. We check that the |
| // infobar stays. |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), |
| "window.location.href = 'done.html';")); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_FALSE(observer.infobar_removed()); |
| - } |
| + EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| } |
| IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| @@ -417,17 +474,15 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| // This should work regardless of the type of element, as long as submit() is |
| // called. |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string fill_and_submit = |
| "document.getElementById('username_field').value = 'temp';" |
| "document.getElementById('password_field').value = 'random';" |
| "document.getElementById('submit_button').click()"; |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_TRUE(observer.infobar_shown()); |
| - } |
| + EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| } |
| // Flaky: crbug.com/301547, observed on win and mac. Probably happens on all |
| @@ -438,6 +493,8 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| // Fill the dynamic password form and submit. |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string fill_and_submit = |
| "document.getElementById('create_form_button').click();" |
| "window.setTimeout(function() {" |
| @@ -447,11 +504,7 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| "}, 0)"; |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_TRUE(observer.infobar_shown()); |
| - } |
| + EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| } |
| IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptForNavigation) { |
| @@ -459,14 +512,12 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptForNavigation) { |
| // Don't fill the password form, just navigate away. Shouldn't prompt. |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), |
| "window.location.href = 'done.html';")); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_FALSE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_FALSE(observer.infobar_shown()); |
| - } |
| + EXPECT_FALSE(prompt_observer->IsPromptShown()); |
| } |
| IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| @@ -476,6 +527,8 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| // If you are filling out a password form in one frame and a different frame |
| // navigates, this should not trigger the infobar. |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| observer.SetPathToWaitFor("/password/done.html"); |
| std::string fill = |
| "var first_frame = document.getElementById('first_frame');" |
| @@ -489,11 +542,7 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill)); |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame)); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_FALSE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_FALSE(observer.infobar_shown()); |
| - } |
| + EXPECT_FALSE(prompt_observer->IsPromptShown()); |
| } |
| IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| @@ -503,6 +552,8 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| // Make sure that we prompt to save password even if a sub-frame navigation |
| // happens first. |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| observer.SetPathToWaitFor("/password/done.html"); |
| std::string navigate_frame = |
| "var second_iframe = document.getElementById('second_frame');" |
| @@ -517,11 +568,7 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame)); |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_TRUE(observer.infobar_shown()); |
| - } |
| + EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| } |
| IN_PROC_BROWSER_TEST_F( |
| @@ -532,6 +579,8 @@ IN_PROC_BROWSER_TEST_F( |
| // Make sure that we don't prompt to save the password for a failed login |
| // from the main frame with multiple frames in the same page. |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string fill_and_submit = |
| "document.getElementById('username_failed').value = 'temp';" |
| "document.getElementById('password_failed').value = 'random';" |
| @@ -539,7 +588,7 @@ IN_PROC_BROWSER_TEST_F( |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| observer.Wait(); |
| - EXPECT_FALSE(observer.infobar_shown()); |
| + EXPECT_FALSE(prompt_observer->IsPromptShown()); |
| } |
| IN_PROC_BROWSER_TEST_F( |
| @@ -550,6 +599,8 @@ IN_PROC_BROWSER_TEST_F( |
| // Make sure that we don't prompt to save the password for a failed login |
| // from a sub-frame with multiple frames in the same page. |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string fill_and_submit = |
| "var first_frame = document.getElementById('first_frame');" |
| "var frame_doc = first_frame.contentDocument;" |
| @@ -560,11 +611,10 @@ IN_PROC_BROWSER_TEST_F( |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| observer.Wait(); |
| - EXPECT_FALSE(observer.infobar_shown()); |
| + EXPECT_FALSE(prompt_observer->IsPromptShown()); |
| } |
| -IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| - PromptForXHRSubmit) { |
| +IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PromptForXHRSubmit) { |
| #if defined(OS_WIN) && defined(USE_ASH) |
| // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
| @@ -577,17 +627,15 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| // Note that calling 'submit()' on a form with javascript doesn't call |
| // the onsubmit handler, so we click the submit button instead. |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string fill_and_submit = |
| "document.getElementById('username_field').value = 'temp';" |
| "document.getElementById('password_field').value = 'random';" |
| "document.getElementById('submit_button').click()"; |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_TRUE(observer.infobar_shown()); |
| - } |
| + EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| } |
| IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| @@ -597,37 +645,32 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| // Verify that if XHR navigation occurs and the form is properly filled out, |
| // we try and save the password even though onsubmit hasn't been called. |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string fill_and_navigate = |
| "document.getElementById('username_field').value = 'temp';" |
| "document.getElementById('password_field').value = 'random';" |
| "send_xhr()"; |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate)); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_TRUE(observer.infobar_shown()); |
| - } |
| + EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| } |
| -IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| - NoPromptIfLinkClicked) { |
| +IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptIfLinkClicked) { |
| NavigateToFile("/password/password_form.html"); |
| // Verify that if the user takes a direct action to leave the page, we don't |
| // prompt to save the password even if the form is already filled out. |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string fill_and_click_link = |
| "document.getElementById('username_field').value = 'temp';" |
| "document.getElementById('password_field').value = 'random';" |
| "document.getElementById('link').click();"; |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_click_link)); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_FALSE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_FALSE(observer.infobar_shown()); |
| - } |
| + EXPECT_FALSE(prompt_observer->IsPromptShown()); |
| } |
| // TODO(jam): http://crbug.com/350550 |
| @@ -645,6 +688,8 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| // Enter a password and save it. |
| NavigationObserver first_observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string fill_and_submit = |
| "document.getElementById('other_info').value = 'stuff';" |
| "document.getElementById('username_field').value = 'my_username';" |
| @@ -653,12 +698,8 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| first_observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - ASSERT_TRUE(ui_controller()->PasswordPendingUserDecision()); |
| - ui_controller()->SavePassword(); |
| - } else { |
| - ASSERT_TRUE(first_observer.infobar_shown()); |
| - } |
| + EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| + prompt_observer->Accept(); |
| // Now navigate to a login form that has similar HTML markup. |
| NavigateToFile("/password/password_form.html"); |
| @@ -681,15 +722,13 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| // Submit the form and verify that there is no infobar (as the password |
| // has already been saved). |
| NavigationObserver second_observer(WebContents()); |
| + scoped_ptr<PromptObserver> second_prompt_observer( |
| + PromptObserver::Create(WebContents())); |
|
engedy
2014/07/11 18:07:26
Could you please confirm that this really a differ
vabr (Chromium)
2014/07/11 18:48:01
The thing is that I'm not sure -- it should be the
|
| std::string submit_form = |
| "document.getElementById('input_submit_button').click()"; |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), submit_form)); |
| second_observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_FALSE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_FALSE(second_observer.infobar_shown()); |
| - } |
| + EXPECT_FALSE(second_prompt_observer->IsPromptShown()); |
| // Verify that we sent a ping to Autofill saying that the original form |
| // was likely an account creation form since it has more than 2 text input |
| @@ -712,6 +751,8 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PromptForSubmitFromIframe) { |
| // user gesture. We expect the save password prompt to be shown here, because |
| // some pages use such iframes for login forms. |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string fill_and_submit = |
| "var iframe = document.getElementById('test_iframe');" |
| "var iframe_doc = iframe.contentDocument;" |
| @@ -721,11 +762,7 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PromptForSubmitFromIframe) { |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_TRUE(observer.infobar_shown()); |
| - } |
| + EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| } |
| IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| @@ -735,17 +772,15 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| NavigateToFile("/password/password_form.html"); |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string fill_and_submit = |
| "document.getElementById('username_field_no_name').value = 'temp';" |
| "document.getElementById('password_field_no_name').value = 'random';" |
| "document.getElementById('input_submit_button_no_name').click()"; |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_TRUE(observer.infobar_shown()); |
| - } |
| + EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| } |
| IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| @@ -755,17 +790,15 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| NavigateToFile("/password/password_form.html"); |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string fill_and_submit = |
| "document.getElementsByName('username_field_no_id')[0].value = 'temp';" |
| "document.getElementsByName('password_field_no_id')[0].value = 'random';" |
| "document.getElementsByName('input_submit_button_no_id')[0].click()"; |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_TRUE(observer.infobar_shown()); |
| - } |
| + EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| } |
| IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| @@ -775,6 +808,8 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| NavigateToFile("/password/password_form.html"); |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string fill_and_submit = |
| "var form = document.getElementById('testform_elements_no_id_no_name');" |
| "var username = form.children[0];" |
| @@ -784,11 +819,7 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| "form.children[2].click()"; // form.children[2] is the submit button. |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_FALSE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_FALSE(observer.infobar_shown()); |
| - } |
| + EXPECT_FALSE(prompt_observer->IsPromptShown()); |
| } |
| IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, DeleteFrameBeforeSubmit) { |
| @@ -830,18 +861,16 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PasswordValueAccessible) { |
| // Fill in the credentials, and make sure they are saved. |
| NavigationObserver form_submit_observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string fill_and_submit = |
| "document.getElementById('username_field').value = 'temp';" |
| "document.getElementById('password_field').value = 'random';" |
| "document.getElementById('input_submit_button').click();"; |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| form_submit_observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); |
| - ui_controller()->SavePassword(); |
| - } else { |
| - EXPECT_TRUE(form_submit_observer.infobar_shown()); |
| - } |
| + EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| + prompt_observer->Accept(); |
| // Reload the original page to have the saved credentials autofilled. |
| NavigationObserver reload_observer(WebContents()); |
| @@ -873,18 +902,16 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| // Fill in the credentials, and make sure they are saved. |
| NavigationObserver form_submit_observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string fill_and_submit = |
| "document.getElementById('username_field').value = 'temp';" |
| "document.getElementById('password_field').value = 'random_secret';" |
| "document.getElementById('input_submit_button').click();"; |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| form_submit_observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); |
| - ui_controller()->SavePassword(); |
| - } else { |
| - EXPECT_TRUE(form_submit_observer.infobar_shown()); |
| - } |
| + EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| + prompt_observer->Accept(); |
| // Reload the original page to have the saved credentials autofilled. |
| NavigationObserver reload_observer(WebContents()); |
| @@ -909,13 +936,11 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| // Don't prompt if we navigate away even if there is a password value since |
| // it's not coming from the user. |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| NavigateToFile("/password/done.html"); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_FALSE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_FALSE(observer.infobar_shown()); |
| - } |
| + EXPECT_FALSE(prompt_observer->IsPromptShown()); |
| } |
| IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| @@ -924,17 +949,15 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| // Fill a form and submit through a <input type="submit"> button. |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string fill_and_submit = |
| "document.getElementById('username_field').value = 'temp';" |
| "document.getElementById('password_field').value = 'random';" |
| "document.getElementById('input_submit_button').click()"; |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_TRUE(observer.infobar_shown()); |
| - } |
| + EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| } |
| IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| @@ -954,8 +977,9 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| // Fill a form and submit through a <input type="submit"> button. |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| // Make sure that the only passwords saved are the auto-saved ones. |
| - observer.disable_should_automatically_accept_infobar(); |
| std::string fill_and_submit = |
| "document.getElementById('username_field').value = 'temp';" |
| "document.getElementById('password_field').value = 'random';" |
| @@ -964,18 +988,12 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| observer.Wait(); |
| if (chrome::VersionInfo::GetChannel() == |
| chrome::VersionInfo::CHANNEL_UNKNOWN) { |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_FALSE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_FALSE(observer.infobar_shown()); |
| - } |
| + // Passwords getting auto-saved, no prompt. |
| + EXPECT_FALSE(prompt_observer->IsPromptShown()); |
| EXPECT_FALSE(password_store->IsEmpty()); |
| } else { |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_TRUE(observer.infobar_shown()); |
| - } |
| + // Prompt shown, and no passwords saved automatically. |
| + EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| EXPECT_TRUE(password_store->IsEmpty()); |
| } |
| } |
| @@ -990,16 +1008,14 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptWhenReloading) { |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill)); |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| GURL url = embedded_test_server()->GetURL("/password/password_form.html"); |
| chrome::NavigateParams params(browser(), url, |
| content::PAGE_TRANSITION_RELOAD); |
| ui_test_utils::NavigateToURL(¶ms); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_FALSE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_FALSE(observer.infobar_shown()); |
| - } |
| + EXPECT_FALSE(prompt_observer->IsPromptShown()); |
| } |
| // Test that if a form gets dynamically added between the form parsing and |
| @@ -1010,6 +1026,8 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| NavigateToFile("/password/between_parsing_and_rendering.html"); |
| NavigationObserver observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| std::string submit = |
| "document.getElementById('username').value = 'temp';" |
| "document.getElementById('password').value = 'random';" |
| @@ -1017,11 +1035,7 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), submit)); |
| observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); |
| - } else { |
| - EXPECT_TRUE(observer.infobar_shown()); |
| - } |
| + EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| } |
| // Test that if there was no previous page load then the PasswordManagerDriver |
| @@ -1057,6 +1071,8 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoLastLoadGoodLastLoad) { |
| content::NavigationController* nav_controller = |
| &WebContents()->GetController(); |
| NavigationObserver nav_observer(WebContents()); |
| + scoped_ptr<PromptObserver> prompt_observer( |
| + PromptObserver::Create(WebContents())); |
| WindowedAuthNeededObserver auth_needed_observer(nav_controller); |
| auth_needed_observer.Wait(); |
| @@ -1071,12 +1087,9 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoLastLoadGoodLastLoad) { |
| // The password manager should be working correctly. |
| nav_observer.Wait(); |
| - if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { |
| - EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); |
| - ui_controller()->SavePassword(); |
| - } else { |
| - EXPECT_TRUE(nav_observer.infobar_shown()); |
| - } |
| + EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| + prompt_observer->Accept(); |
| + |
| // Spin the message loop to make sure the password store had a chance to save |
| // the password. |
| base::RunLoop run_loop; |