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

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: Rebase 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
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..a4f1073c1005f90e56c3cc7b32605d86380edb8f 100644
--- a/chrome/browser/password_manager/password_manager_browsertest.cc
+++ b/chrome/browser/password_manager/password_manager_browsertest.cc
@@ -742,6 +742,62 @@ 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,
+ NoPromptForXHXSubmitWithoutNavigationWithUnfilledForm) {
+ 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, NoPromptIfLinkClicked) {
NavigateToFile("/password/password_form.html");

Powered by Google App Engine
This is Rietveld 408576698