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

Unified Diff: chrome/renderer/autofill/password_autofill_agent_browsertest.cc

Issue 2865233003: Use an MutationObserver to check when a password form disappears after XHR (Closed)
Patch Set: updates Created 3 years, 7 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/renderer/autofill/password_autofill_agent_browsertest.cc
diff --git a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
index 6fc17ce723643e345c7b2bfdfc98f13d457c2ee3..05904390775c42fd8d1a2e6400d530c3b34224aa 100644
--- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
+++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
@@ -1678,8 +1678,12 @@ TEST_F(PasswordAutofillAgentTest, RememberFieldPropertiesOnInPageNavigation) {
SimulateUsernameChange("Bob");
SimulatePasswordChange("mypassword");
- username_element_.SetAttribute("style", "display:none;");
- password_element_.SetAttribute("style", "display:none;");
+ std::string hide_elements =
+ "var password = document.getElementById('password');"
+ "password.style = 'display:none';"
+ "var username = document.getElementById('username');"
+ "username.style = 'display:none';";
+ ExecuteJavaScriptForTests(hide_elements.c_str());
password_autofill_agent_->AJAXSucceeded();
@@ -1693,6 +1697,34 @@ TEST_F(PasswordAutofillAgentTest, RememberFieldPropertiesOnInPageNavigation) {
expected_properties_masks);
}
+TEST_F(PasswordAutofillAgentTest, RememberFieldPropertiesOnInPageNavigation_2) {
+ LoadHTML(kNoFormHTML);
+ UpdateUsernameAndPasswordElements();
+
+ SimulateUsernameChange("Bob");
+ SimulatePasswordChange("mypassword");
+
+ password_autofill_agent_->AJAXSucceeded();
+
+ std::string hide_elements =
+ "var password = document.getElementById('password');"
+ "password.style = 'display:none';"
+ "var username = document.getElementById('username');"
+ "username.style = 'display:none';";
+ ExecuteJavaScriptForTests(hide_elements.c_str());
+
+ base::RunLoop().RunUntilIdle();
+
+ std::map<base::string16, FieldPropertiesMask> expected_properties_masks;
+ expected_properties_masks[ASCIIToUTF16("username")] =
+ FieldPropertiesFlags::USER_TYPED;
+ expected_properties_masks[ASCIIToUTF16("password")] =
+ FieldPropertiesFlags::USER_TYPED | FieldPropertiesFlags::HAD_FOCUS;
+
+ ExpectFieldPropertiesMasks(PasswordFormInPageNavigation,
+ expected_properties_masks);
+}
+
// The username/password is autofilled by password manager then just before
// sending the form off, a script changes them. This test checks that
// PasswordAutofillAgent can still get the username and the password autofilled.
@@ -2248,8 +2280,12 @@ TEST_F(PasswordAutofillAgentTest, NoForm_PromptForAJAXSubmitWithoutNavigation) {
SimulateUsernameChange("Bob");
SimulatePasswordChange("mypassword");
- username_element_.SetAttribute("style", "display:none;");
- password_element_.SetAttribute("style", "display:none;");
+ std::string hide_elements =
+ "var password = document.getElementById('password');"
+ "password.style = 'display:none';"
+ "var username = document.getElementById('username');"
+ "username.style = 'display:none';";
+ ExecuteJavaScriptForTests(hide_elements.c_str());
password_autofill_agent_->AJAXSucceeded();
@@ -2258,6 +2294,30 @@ TEST_F(PasswordAutofillAgentTest, NoForm_PromptForAJAXSubmitWithoutNavigation) {
PasswordForm::SubmissionIndicatorEvent::XHR_SUCCEEDED);
}
+TEST_F(PasswordAutofillAgentTest,
+ NoForm_PromptForAJAXSubmitWithoutNavigation_2) {
+ LoadHTML(kNoFormHTML);
+ UpdateUsernameAndPasswordElements();
+
+ SimulateUsernameChange("Bob");
+ SimulatePasswordChange("mypassword");
+
+ password_autofill_agent_->AJAXSucceeded();
+
+ std::string hide_elements =
+ "var password = document.getElementById('password');"
+ "password.style = 'display:none';"
+ "var username = document.getElementById('username');"
+ "username.style = 'display:none';";
+ ExecuteJavaScriptForTests(hide_elements.c_str());
+
+ base::RunLoop().RunUntilIdle();
+
+ ExpectInPageNavigationWithUsernameAndPasswords(
+ "Bob", "mypassword", "",
+ PasswordForm::SubmissionIndicatorEvent::DOM_MUTATION_AFTER_XHR);
+}
+
TEST_F(PasswordAutofillAgentTest,
NoForm_NoPromptForAJAXSubmitWithoutNavigationAndElementsVisible) {
LoadHTML(kNoFormHTML);
@@ -2291,7 +2351,10 @@ TEST_F(PasswordAutofillAgentTest,
SimulatePasswordChange("mypassword");
// Simulate captcha element show up right before AJAX completed.
- captcha_element.SetAttribute("style", "display:inline;");
+ std::string show_captcha =
+ "var captcha = document.getElementById('captcha');"
+ "captcha.style = 'display:inline';";
+ ExecuteJavaScriptForTests(show_captcha.c_str());
password_autofill_agent_->AJAXSucceeded();
base::RunLoop().RunUntilIdle();
@@ -2299,6 +2362,35 @@ TEST_F(PasswordAutofillAgentTest,
EXPECT_FALSE(fake_driver_.called_password_form_submitted());
}
+TEST_F(PasswordAutofillAgentTest,
+ NoForm_NoPromptForAJAXSubmitWithoutNavigationAndNewElementAppeared_2) {
+ const char kNoFormHTMLWithHiddenField[] =
+ "<INPUT type='text' id='username'/>"
+ "<INPUT type='password' id='password'/>"
+ "<INPUT type='text' id='captcha' style='display:none'/>";
+ LoadHTML(kNoFormHTMLWithHiddenField);
+
+ UpdateUsernameAndPasswordElements();
+ WebElement captcha_element = GetMainFrame()->GetDocument().GetElementById(
+ WebString::FromUTF8("captcha"));
+ ASSERT_FALSE(captcha_element.IsNull());
+
+ SimulateUsernameChange("Bob");
+ SimulatePasswordChange("mypassword");
+
+ password_autofill_agent_->AJAXSucceeded();
+
+ // Simulate captcha element show up right after AJAX completed.
+ std::string show_captcha =
+ "var captcha = document.getElementById('captcha');"
+ "captcha.style = 'display:inline';";
+ ExecuteJavaScriptForTests(show_captcha.c_str());
+ base::RunLoop().RunUntilIdle();
+
+ EXPECT_FALSE(fake_driver_.called_inpage_navigation());
+ EXPECT_FALSE(fake_driver_.called_password_form_submitted());
+}
+
// Tests that no save promt is shown when a form with empty action URL is
// changed and AJAX completed but the form is still visible.
TEST_F(PasswordAutofillAgentTest,
@@ -2331,6 +2423,37 @@ TEST_F(PasswordAutofillAgentTest,
EXPECT_FALSE(fake_driver_.called_password_form_submitted());
}
+TEST_F(PasswordAutofillAgentTest,
+ NoAction_NoPromptForAJAXSubmitWithoutNavigationAndNewElementAppeared_2) {
+ // Form without an action URL.
+ const char kHTMLWithHiddenField[] =
+ "<FORM name='LoginTestForm'>"
+ " <INPUT type='text' id='username'/>"
+ " <INPUT type='password' id='password'/>"
+ " <INPUT type='text' id='captcha' style='display:none'/>"
+ " <INPUT type='submit' value='Login'/>"
+ "</FORM>";
+ // Set the valid URL so the form action URL can be generated properly.
+ LoadHTMLWithUrlOverride(kHTMLWithHiddenField, "https://www.example.com");
+
+ UpdateUsernameAndPasswordElements();
+ WebElement captcha_element = GetMainFrame()->GetDocument().GetElementById(
+ WebString::FromUTF8("captcha"));
+ ASSERT_FALSE(captcha_element.IsNull());
+
+ SimulateUsernameChange("Bob");
+ SimulatePasswordChange("mypassword");
+
+ password_autofill_agent_->AJAXSucceeded();
+
+ // Simulate captcha element show up right after AJAX completed.
+ captcha_element.SetAttribute("style", "display:inline;");
+
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(fake_driver_.called_inpage_navigation());
+ EXPECT_FALSE(fake_driver_.called_password_form_submitted());
+}
+
// Tests that credential suggestions are autofilled on a password (and change
// password) forms having either ambiguous or empty name.
TEST_F(PasswordAutofillAgentTest,
@@ -2541,8 +2664,12 @@ TEST_F(PasswordAutofillAgentTest,
SimulateUsernameChange("Alice");
// Hide form elements to simulate successful login.
- username_element_.SetAttribute("style", "display:none;");
- password_element_.SetAttribute("style", "display:none;");
+ std::string hide_elements =
+ "var password = document.getElementById('password');"
+ "password.style = 'display:none';"
+ "var username = document.getElementById('username');"
+ "username.style = 'display:none';";
+ ExecuteJavaScriptForTests(hide_elements.c_str());
password_autofill_agent_->AJAXSucceeded();
@@ -2551,6 +2678,31 @@ TEST_F(PasswordAutofillAgentTest,
PasswordForm::SubmissionIndicatorEvent::XHR_SUCCEEDED);
}
+TEST_F(PasswordAutofillAgentTest,
+ UsernameChangedAfterPasswordInput_InPageNavigation_2) {
+ LoadHTML(kNoFormHTML);
+ UpdateUsernameAndPasswordElements();
+
+ SimulateUsernameChange("Bob");
+ SimulatePasswordChange("mypassword");
+ SimulateUsernameChange("Alice");
+
+ password_autofill_agent_->AJAXSucceeded();
+
+ // Hide form elements to simulate successful login.
+ std::string hide_elements =
+ "var password = document.getElementById('password');"
+ "password.style = 'display:none';"
+ "var username = document.getElementById('username');"
+ "username.style = 'display:none';";
+ ExecuteJavaScriptForTests(hide_elements.c_str());
+ base::RunLoop().RunUntilIdle();
+
+ ExpectInPageNavigationWithUsernameAndPasswords(
+ "Alice", "mypassword", "",
+ PasswordForm::SubmissionIndicatorEvent::DOM_MUTATION_AFTER_XHR);
+}
+
TEST_F(PasswordAutofillAgentTest,
UsernameChangedAfterPasswordInput_FormSubmitted) {
SimulateUsernameChange("Bob");
« no previous file with comments | « no previous file | components/autofill/content/DEPS » ('j') | third_party/WebKit/public/web/modules/password_manager/OWNERS » ('J')

Powered by Google App Engine
This is Rietveld 408576698