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

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

Issue 1012853002: [Password Manager] Use successful XHR submission as a signal for password saving (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments Created 5 years, 9 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 | chrome/test/data/password/password_xhr_submit.html » ('j') | 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 9f74eec7191ffea962e44fb7c095c54d16312974..235e1c6ee31bc9e587c6f1e439eb40aab91e6559 100644
--- a/chrome/browser/password_manager/password_manager_browsertest.cc
+++ b/chrome/browser/password_manager/password_manager_browsertest.cc
@@ -742,6 +742,120 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
EXPECT_TRUE(prompt_observer->IsShowingPrompt());
}
+IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
+ PromptForXHRSubmitWithoutNavigation) {
+ NavigateToFile("/password/password_xhr_submit.html");
+
+ // Need to pay attention for a message that XHR has finished since there
+ // is no navigation to wait for.
+ content::DOMMessageQueue message_queue;
+
+ // Verify that if XHR without navigation occurs and the form has been filled
+ // out we try and save the password. Note that in general the submission
+ // doesn't need to be via form.submit(), but for testing purposes it's
+ // necessary since we otherwise ignore changes made to the value of these
+ // fields by script.
+ scoped_ptr<PromptObserver> prompt_observer(
+ PromptObserver::Create(WebContents()));
+ std::string fill_and_submit =
+ "navigate = false;"
+ "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));
+ std::string message;
+ while (message_queue.WaitForMessage(&message)) {
+ if (message == "\"XHR_FINISHED\"")
+ break;
+ }
+
+ EXPECT_TRUE(prompt_observer->IsShowingPrompt());
+}
+
+IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
+ PromptForXHRSubmitWithoutNavigation_SignupForm) {
+ NavigateToFile("/password/password_xhr_submit.html");
+
+ // Need to pay attention for a message that XHR has finished since there
+ // is no navigation to wait for.
+ content::DOMMessageQueue message_queue;
+
+ // Verify that if XHR without navigation occurs and the form has been filled
+ // out we try and save the password. Note that in general the submission
+ // doesn't need to be via form.submit(), but for testing purposes it's
+ // necessary since we otherwise ignore changes made to the value of these
+ // fields by script.
+ scoped_ptr<PromptObserver> prompt_observer(
+ PromptObserver::Create(WebContents()));
+ std::string fill_and_submit =
+ "navigate = false;"
+ "document.getElementById('signup_username_field').value = 'temp';"
+ "document.getElementById('signup_password_field').value = 'random';"
+ "document.getElementById('confirmation_password_field').value = 'random';"
+ "document.getElementById('signup_submit_button').click();";
+ ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
+ std::string message;
+ while (message_queue.WaitForMessage(&message)) {
+ if (message == "\"XHR_FINISHED\"")
+ break;
+ }
+
+ EXPECT_TRUE(prompt_observer->IsShowingPrompt());
+}
+
+IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
+ NoPromptForXHRSubmitWithoutNavigationWithUnfilledForm) {
+ NavigateToFile("/password/password_xhr_submit.html");
+
+ // Need to pay attention for a message that XHR has finished since there
+ // is no navigation to wait for.
+ content::DOMMessageQueue message_queue;
+
+ // Verify that if XHR without navigation occurs and the form has NOT been
+ // filled out we don't prompt.
+ scoped_ptr<PromptObserver> prompt_observer(
+ PromptObserver::Create(WebContents()));
+ std::string fill_and_submit =
+ "navigate = false;"
+ "document.getElementById('username_field').value = 'temp';"
+ "document.getElementById('submit_button').click();";
+ ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
+ std::string message;
+ while (message_queue.WaitForMessage(&message)) {
+ if (message == "\"XHR_FINISHED\"")
+ break;
+ }
+
+ EXPECT_FALSE(prompt_observer->IsShowingPrompt());
+}
+
+IN_PROC_BROWSER_TEST_F(
+ PasswordManagerBrowserTest,
+ NoPromptForXHRSubmitWithoutNavigationWithUnfilledForm_SignupForm) {
+ NavigateToFile("/password/password_xhr_submit.html");
+
+ // Need to pay attention for a message that XHR has finished since there
+ // is no navigation to wait for.
+ content::DOMMessageQueue message_queue;
+
+ // Verify that if XHR without navigation occurs and the form has NOT been
+ // filled out we don't prompt.
+ scoped_ptr<PromptObserver> prompt_observer(
+ PromptObserver::Create(WebContents()));
+ std::string fill_and_submit =
+ "navigate = false;"
+ "document.getElementById('signup_username_field').value = 'temp';"
+ "document.getElementById('signup_submit_button').click();";
+ ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
+ std::string message;
+ while (message_queue.WaitForMessage(&message)) {
+ if (message == "\"XHR_FINISHED\"")
+ break;
+ }
+
+ EXPECT_FALSE(prompt_observer->IsShowingPrompt());
+}
+
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptIfLinkClicked) {
NavigateToFile("/password/password_form.html");
« no previous file with comments | « no previous file | chrome/test/data/password/password_xhr_submit.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698