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

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: tests 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
« no previous file with comments | « no previous file | components/autofill/content/DEPS » ('j') | components/autofill/content/DEPS » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 5b666d88c1c0ffd379b2faccb970fe43e51e4fec..d1d3c96680747349aed20fa374dddf6d7582b173 100644
--- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
+++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
@@ -1674,8 +1674,12 @@ TEST_F(PasswordAutofillAgentTest, RememberFieldPropertiesOnInPageNavigation) {
SimulateUsernameChange("Bob");
SimulatePasswordChange("mypassword");
- username_element_.SetAttribute("style", "display:none;");
- password_element_.SetAttribute("style", "display:none;");
jochen (gone - plz use gerrit) 2017/05/10 11:45:41 These methods don't actually spin Blink's message
+ 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();
@@ -1689,6 +1693,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.
@@ -2244,14 +2276,40 @@ 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();
ExpectInPageNavigationWithUsernameAndPasswords("Bob", "mypassword", "");
}
+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", "");
+}
+
TEST_F(PasswordAutofillAgentTest,
NoForm_NoPromptForAJAXSubmitWithoutNavigationAndElementsVisible) {
LoadHTML(kNoFormHTML);
@@ -2285,7 +2343,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();
@@ -2293,6 +2354,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,
@@ -2325,6 +2415,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,
@@ -2535,11 +2656,38 @@ 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();
+
+ ExpectInPageNavigationWithUsernameAndPasswords("Alice", "mypassword", "");
+}
+
+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", "");
}
« no previous file with comments | « no previous file | components/autofill/content/DEPS » ('j') | components/autofill/content/DEPS » ('J')

Powered by Google App Engine
This is Rietveld 408576698