Index: chrome/renderer/autofill/password_autofill_manager_browsertest.cc |
=================================================================== |
--- chrome/renderer/autofill/password_autofill_manager_browsertest.cc (revision 133421) |
+++ chrome/renderer/autofill/password_autofill_manager_browsertest.cc (working copy) |
@@ -80,16 +80,17 @@ |
username3_ = ASCIIToUTF16(kCarolUsername); |
password3_ = ASCIIToUTF16(kCarolPassword); |
+ FormField password_field; |
+ password_field.name = ASCIIToUTF16(kPasswordName); |
+ password_field.value = password1_; |
+ fill_data_.basic_data.fields.push_back(password_field); |
+ fill_data_only_password_.basic_data.fields.push_back(password_field); |
+ |
FormField username_field; |
username_field.name = ASCIIToUTF16(kUsernameName); |
username_field.value = username1_; |
fill_data_.basic_data.fields.push_back(username_field); |
- FormField password_field; |
- password_field.name = ASCIIToUTF16(kPasswordName); |
- password_field.value = password1_; |
- fill_data_.basic_data.fields.push_back(password_field); |
- |
fill_data_.additional_logins[username2_] = password2_; |
fill_data_.additional_logins[username3_] = password3_; |
@@ -99,6 +100,8 @@ |
origin += kFormHTML; |
fill_data_.basic_data.origin = GURL(origin); |
fill_data_.basic_data.action = GURL("http://www.bidule.com"); |
+ fill_data_only_password_.basic_data.origin = GURL(origin); |
+ fill_data_only_password_.basic_data.action = GURL("http://www.bidule.com"); |
LoadHTML(kFormHTML); |
@@ -150,6 +153,13 @@ |
EXPECT_EQ(password_autofilled, password_element_.isAutofilled()); |
} |
+ void CheckPasswordTextFieldState(const std::string& password, |
+ bool password_autofilled) { |
+ EXPECT_EQ(password, |
+ static_cast<std::string>(password_element_.value().utf8())); |
+ EXPECT_EQ(password_autofilled, password_element_.isAutofilled()); |
+ } |
+ |
void CheckUsernameSelection(int start, int end) { |
EXPECT_EQ(start, username_element_.selectionStart()); |
EXPECT_EQ(end, username_element_.selectionEnd()); |
@@ -162,6 +172,7 @@ |
string16 password2_; |
string16 password3_; |
PasswordFormFillData fill_data_; |
+ PasswordFormFillData fill_data_only_password_; |
WebInputElement username_element_; |
WebInputElement password_element_; |
@@ -203,6 +214,17 @@ |
CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
} |
+// Tests that the password login is autocompleted as expected when the browser |
+// sends back the password info if there is only a password field. |
+TEST_F(PasswordAutofillManagerTest, InitialAutocompleteOnlyPassword) { |
+ // Simulate the browser sending back the login info, it triggers the |
+ // autocomplete. |
+ SimulateOnFillPasswordForm(fill_data_only_password_); |
+ |
+ // Only the password should have been autocompleted. |
+ CheckPasswordTextFieldState(kAlicePassword, true); |
+} |
+ |
// Tests that we correctly fill forms having an empty 'action' attribute. |
TEST_F(PasswordAutofillManagerTest, InitialAutocompleteForEmptyAction) { |
const char kEmptyActionFormHTML[] = |