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

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

Issue 56653002: [Password Autofill] Make better use of prefilled usernames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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/renderer/password_autofill_agent.h » ('j') | no next file with comments »
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 6f83caa5c02c40fb1db4dfd9473294d95e50aaa6..b8794dfda589863c533f5edcfedddfb756a14f50 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_), false,
+ 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,28 @@ TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForFilledField) {
CheckTextFieldsState("bogus", false, std::string(), false);
}
+// Don't try to complete a prefilled value even if it's a partial match
+// to a username.
+TEST_F(PasswordAutofillAgentTest, NoPartialMatchForPrefilledUsername) {
+ username_element_.setValue(WebString::fromUTF8("ali"));
+
+ SimulateOnFillPasswordForm(fill_data_);
+
+ CheckTextFieldsState("ali", false, std::string(), false);
+}
+
+TEST_F(PasswordAutofillAgentTest, InputWithNoForms) {
+ const char kNoFormInputs[] =
+ "<input type='text' id='username'/>"
+ "<input type='password' id='password'/>";
+ LoadHTML(kNoFormInputs);
+
+ SimulateOnFillPasswordForm(fill_data_);
+
+ // Input elements that aren't in a <form> won't autofill.
+ CheckTextFieldsState(std::string(), false, std::string(), false);
+}
+
// Tests that we do not autofill username/passwords if marked as
// autocomplete="off".
TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForAutocompleteOff) {
« no previous file with comments | « no previous file | components/autofill/content/renderer/password_autofill_agent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698