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

Unified Diff: chrome/browser/password_manager/password_manager_browsertest.cc

Issue 378643006: PasswordManager browser test: simplify checking for password prompt (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Just rebased Created 6 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..a3b9373b584fc8c4686c5d878189492e9d15dbec 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,91 @@ 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 the save password prompt (bubble or infobar) for a specified
+// WebContents, keeps track of whether or not it is currently shown, and allows
+// accepting saving passwords through it.
+class PromptObserver {
+ public:
+ virtual ~PromptObserver() {}
+
+ // Checks if the prompt is being currently shown.
+ virtual bool IsShowingPrompt() const = 0;
+
+ // Expecting that the prompt is shown, saves the password. Checks that the
+ // prompt is no longer visible afterwards.
+ void Accept() const {
+ EXPECT_TRUE(IsShowingPrompt());
+ AcceptImpl();
+ }
+
+ // Chooses the right implementation of PromptObserver and creates an instance
+ // of it.
+ static scoped_ptr<PromptObserver> Create(content::WebContents* web_contents);
+
+ protected:
+ PromptObserver() {}
- void disable_should_automatically_accept_infobar() {
- should_automatically_accept_infobar_ = false;
+ // Accepts the password. The implementation can assume that the prompt is
+ // currently shown, but is required to verify 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_being_shown_(false),
+ infobar_service_(InfoBarService::FromWebContents(web_contents)) {
+ infobar_service_->AddObserver(this);
}
- void Wait() {
- message_loop_runner_->Run();
+ virtual ~InfoBarObserver() {
+ if (infobar_service_)
+ infobar_service_->RemoveObserver(this);
}
private:
+ // PromptObserver:
+ virtual bool IsShowingPrompt() const OVERRIDE {
+ return infobar_is_being_shown_;
+ }
+
+ virtual void AcceptImpl() const OVERRIDE {
+ EXPECT_EQ(1u, infobar_service_->infobar_count());
+ if (!infobar_service_->infobar_count())
+ return; // Let the test finish to gather possibly more diagnostics.
+
+ // ConfirmInfoBarDelegate::Accept returning true means the infobar is
+ // immediately closed. Checking the return value is preferred to testing
+ // IsShowingPrompt() 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_being_shown_ = true;
}
virtual void OnInfoBarRemoved(infobars::InfoBar* infobar,
bool animate) OVERRIDE {
- infobar_removed_ = true;
+ infobar_is_being_shown_ = false;
}
virtual void OnManagerShuttingDown(
@@ -124,18 +175,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_being_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 IsShowingPrompt() const OVERRIDE {
+ return ui_controller_->PasswordPendingUserDecision();
+ }
+
+ virtual void AcceptImpl() const OVERRIDE {
+ ui_controller_->SavePassword();
+ EXPECT_FALSE(IsShowingPrompt());
+ }
+
+ 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 +275,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 +379,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->IsShowingPrompt());
}
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
@@ -324,17 +397,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->IsShowingPrompt());
}
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
@@ -345,17 +416,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->IsShowingPrompt());
}
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, LoginFailed) {
@@ -365,17 +434,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->IsShowingPrompt());
}
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, Redirects) {
@@ -384,29 +451,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->IsShowingPrompt());
// 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->IsShowingPrompt());
}
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
@@ -417,17 +477,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->IsShowingPrompt());
}
// Flaky: crbug.com/301547, observed on win and mac. Probably happens on all
@@ -438,6 +496,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 +507,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->IsShowingPrompt());
}
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptForNavigation) {
@@ -459,14 +515,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->IsShowingPrompt());
}
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
@@ -476,6 +530,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 +545,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->IsShowingPrompt());
}
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
@@ -503,6 +555,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 +571,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->IsShowingPrompt());
}
IN_PROC_BROWSER_TEST_F(
@@ -532,6 +582,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 +591,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->IsShowingPrompt());
}
IN_PROC_BROWSER_TEST_F(
@@ -550,6 +602,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 +614,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->IsShowingPrompt());
}
-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 +630,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->IsShowingPrompt());
}
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
@@ -597,37 +648,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->IsShowingPrompt());
}
-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->IsShowingPrompt());
}
// TODO(jam): http://crbug.com/350550
@@ -645,6 +691,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 +701,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->IsShowingPrompt());
+ prompt_observer->Accept();
// Now navigate to a login form that has similar HTML markup.
NavigateToFile("/password/password_form.html");
@@ -681,15 +725,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()));
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->IsShowingPrompt());
// 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 +754,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 +765,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->IsShowingPrompt());
}
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
@@ -735,17 +775,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->IsShowingPrompt());
}
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
@@ -755,17 +793,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->IsShowingPrompt());
}
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
@@ -775,6 +811,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 +822,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->IsShowingPrompt());
}
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, DeleteFrameBeforeSubmit) {
@@ -830,18 +864,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->IsShowingPrompt());
+ prompt_observer->Accept();
// Reload the original page to have the saved credentials autofilled.
NavigationObserver reload_observer(WebContents());
@@ -873,18 +905,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->IsShowingPrompt());
+ prompt_observer->Accept();
// Reload the original page to have the saved credentials autofilled.
NavigationObserver reload_observer(WebContents());
@@ -909,13 +939,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->IsShowingPrompt());
}
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
@@ -924,17 +952,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->IsShowingPrompt());
}
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
@@ -954,8 +980,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 +991,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->IsShowingPrompt());
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->IsShowingPrompt());
EXPECT_TRUE(password_store->IsEmpty());
}
}
@@ -990,16 +1011,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(&params);
observer.Wait();
- if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) {
- EXPECT_FALSE(ui_controller()->PasswordPendingUserDecision());
- } else {
- EXPECT_FALSE(observer.infobar_shown());
- }
+ EXPECT_FALSE(prompt_observer->IsShowingPrompt());
}
// Test that if a form gets dynamically added between the form parsing and
@@ -1010,6 +1029,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 +1038,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->IsShowingPrompt());
}
// Test that if there was no previous page load then the PasswordManagerDriver
@@ -1057,6 +1074,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 +1090,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->IsShowingPrompt());
+ prompt_observer->Accept();
+
// Spin the message loop to make sure the password store had a chance to save
// the password.
base::RunLoop run_loop;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698