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 6f83caa5c02c40fb1db4dfd9473294d95e50aaa6..9fa40efa8e01a1bc50084d8733d55dda05425ab1 100644 |
--- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc |
+++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc |
@@ -340,9 +340,9 @@ TEST_F(PasswordAutofillAgentTest, InitialAutocompleteForEmptyAction) { |
CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
} |
-// Tests that if a password or input element is marked as readonly, neither |
-// field is autofilled on page load. |
-TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForReadOnly) { |
+// Tests that if a password is marked as readonly, neither field is autofilled |
+// on page load. |
+TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForReadOnlyPassword) { |
password_element_.setAttribute(WebString::fromUTF8("readonly"), |
WebString::fromUTF8("true")); |
@@ -353,8 +353,33 @@ TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForReadOnly) { |
CheckTextFieldsState(std::string(), false, std::string(), false); |
} |
+// Can still fill a password field if the username is set to a value that |
+// matches. |
+TEST_F(PasswordAutofillAgentTest, |
+ AutocompletePasswordForReadonlyUsernameMatched) { |
+ username_element_.setValue(username3_); |
+ username_element_.setAttribute(WebString::fromUTF8("readonly"), |
+ WebString::fromUTF8("true")); |
+ |
+ // Filled even though username is not the preferred match. |
+ SimulateOnFillPasswordForm(fill_data_); |
+ CheckTextFieldsState(UTF16ToUTF8(username3_), true, |
+ UTF16ToUTF8(password3_), true); |
+} |
+ |
+// If a username field is empty and readonly, don't autofill. |
+TEST_F(PasswordAutofillAgentTest, |
+ NoAutocompletePasswordForReadonlyUsernameUnmatched) { |
+ username_element_.setValue(WebString::fromUTF8("")); |
+ username_element_.setAttribute(WebString::fromUTF8("readonly"), |
+ WebString::fromUTF8("true")); |
+ |
+ SimulateOnFillPasswordForm(fill_data_); |
+ CheckTextFieldsState(std::string(), false, std::string(), false); |
+} |
+ |
// Tests that having a non-matching username precludes the autocomplete. |
-TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForFilledField) { |
+TEST_F(PasswordAutofillAgentTest, NoAutocompleteForFilledFieldUnmatched) { |
username_element_.setValue(WebString::fromUTF8("bogus")); |
// Simulate the browser sending back the login info, it triggers the |
@@ -365,6 +390,16 @@ TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForFilledField) { |
CheckTextFieldsState("bogus", false, std::string(), false); |
} |
+// Don't try and complete a prefilled value even if it's a partial match |
Ilya Sherman
2013/11/05 01:25:12
nit: "try and" -> "try to".
Garrett Casto
2013/11/05 01:56:39
Done.
|
+// to a username. |
+TEST_F(PasswordAutofillAgentTest, NoPartialMatchForPrefilledUsername) { |
+ username_element_.setValue(WebString::fromUTF8("ali")); |
+ |
+ SimulateOnFillPasswordForm(fill_data_); |
+ |
+ CheckTextFieldsState("ali", false, std::string(), false); |
+} |
+ |
// Tests that we do not autofill username/passwords if marked as |
// autocomplete="off". |
TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForAutocompleteOff) { |