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 25a0b57f4f79ecbaa7951c4fa068149d41f77e34..f49d46516ffe97bea4af773924a03c8c1eb2717b 100644 |
--- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc |
+++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc |
@@ -398,13 +398,11 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest { |
const std::string& password, |
bool password_autofilled, |
bool checkSuggestedValue) { |
- EXPECT_EQ(username, |
- static_cast<std::string>(username_element.value().utf8())); |
+ EXPECT_EQ(username, username_element.value().utf8()); |
EXPECT_EQ(username_autofilled, username_element.isAutofilled()); |
- EXPECT_EQ(password, |
- static_cast<std::string>( |
- checkSuggestedValue ? password_element.suggestedValue().utf8() |
- : password_element.value().utf8())) |
+ EXPECT_EQ(password, checkSuggestedValue |
+ ? password_element.suggestedValue().utf8() |
+ : password_element.value().utf8()) |
<< "checkSuggestedValue == " << checkSuggestedValue; |
EXPECT_EQ(password_autofilled, password_element.isAutofilled()); |
} |
@@ -997,6 +995,30 @@ TEST_F(PasswordAutofillAgentTest, FillSuggestion) { |
CheckUsernameSelection(username_length, username_length); |
} |
+// Tests that |FillSuggestion| properly fills the password if username is |
+// read-only. |
+TEST_F(PasswordAutofillAgentTest, FillSuggestionIfUsernameReadOnly) { |
+ // Simulate the browser sending the login info. |
+ SetElementReadOnly(username_element_, true); |
+ SimulateOnFillPasswordForm(fill_data_); |
+ |
+ // Neither field should have been autocompleted. |
+ CheckTextFieldsDOMState(std::string(), false, std::string(), false); |
+ |
+ // Username field is not autocompletable, it should not be affected. |
+ EXPECT_TRUE(password_autofill_agent_->FillSuggestion( |
+ password_element_, ASCIIToUTF16(kAliceUsername), |
+ ASCIIToUTF16(kAlicePassword))); |
+ CheckTextFieldsDOMState(std::string(), false, kAlicePassword, true); |
+ |
+ // Try Filling with a suggestion with password different from the one that was |
+ // initially sent to the renderer. |
+ EXPECT_TRUE(password_autofill_agent_->FillSuggestion( |
+ password_element_, ASCIIToUTF16(kBobUsername), |
+ ASCIIToUTF16(kCarolPassword))); |
+ CheckTextFieldsDOMState(std::string(), false, kCarolPassword, true); |
+} |
+ |
// Tests that |PreviewSuggestion| properly previews the username and password. |
TEST_F(PasswordAutofillAgentTest, PreviewSuggestion) { |
// Simulate the browser sending the login info, but set |wait_for_username| |
@@ -1021,13 +1043,9 @@ TEST_F(PasswordAutofillAgentTest, PreviewSuggestion) { |
// with suggested values. |
EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( |
username_element_, kAliceUsername, kAlicePassword)); |
- EXPECT_EQ( |
- kAliceUsername, |
- static_cast<std::string>(username_element_.suggestedValue().utf8())); |
+ EXPECT_EQ(kAliceUsername, username_element_.suggestedValue().utf8()); |
EXPECT_TRUE(username_element_.isAutofilled()); |
- EXPECT_EQ( |
- kAlicePassword, |
- static_cast<std::string>(password_element_.suggestedValue().utf8())); |
+ EXPECT_EQ(kAlicePassword, password_element_.suggestedValue().utf8()); |
EXPECT_TRUE(password_element_.isAutofilled()); |
int username_length = strlen(kAliceUsername); |
CheckUsernameSelection(0, username_length); |
@@ -1036,18 +1054,44 @@ TEST_F(PasswordAutofillAgentTest, PreviewSuggestion) { |
// sent to the renderer. |
EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( |
username_element_, kBobUsername, kCarolPassword)); |
- EXPECT_EQ( |
- kBobUsername, |
- static_cast<std::string>(username_element_.suggestedValue().utf8())); |
+ EXPECT_EQ(kBobUsername, username_element_.suggestedValue().utf8()); |
EXPECT_TRUE(username_element_.isAutofilled()); |
- EXPECT_EQ( |
- kCarolPassword, |
- static_cast<std::string>(password_element_.suggestedValue().utf8())); |
+ EXPECT_EQ(kCarolPassword, password_element_.suggestedValue().utf8()); |
EXPECT_TRUE(password_element_.isAutofilled()); |
username_length = strlen(kBobUsername); |
CheckUsernameSelection(0, username_length); |
} |
+// Tests that |PreviewSuggestion| properly previews the password if username is |
+// read-only. |
+TEST_F(PasswordAutofillAgentTest, PreviewSuggestionIfUsernameReadOnly) { |
+ // Simulate the browser sending the login info. |
+ SetElementReadOnly(username_element_, true); |
+ SimulateOnFillPasswordForm(fill_data_); |
+ |
+ // Neither field should have been autocompleted. |
+ CheckTextFieldsDOMState(std::string(), false, std::string(), false); |
+ |
+ // Username field is not autocompletable, it should not be affected. |
+ EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( |
+ password_element_, kAliceUsername, kAlicePassword)); |
+ EXPECT_EQ(std::string(), username_element_.suggestedValue().utf8()); |
+ EXPECT_FALSE(username_element_.isAutofilled()); |
+ |
+ // Password field must be autofilled. |
+ EXPECT_EQ(kAlicePassword, password_element_.suggestedValue().utf8()); |
+ EXPECT_TRUE(password_element_.isAutofilled()); |
+ |
+ // Try previewing with a password different from the one that was initially |
+ // sent to the renderer. |
+ EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( |
+ password_element_, kBobUsername, kCarolPassword)); |
+ EXPECT_EQ(std::string(), username_element_.suggestedValue().utf8()); |
+ EXPECT_FALSE(username_element_.isAutofilled()); |
+ EXPECT_EQ(kCarolPassword, password_element_.suggestedValue().utf8()); |
+ EXPECT_TRUE(password_element_.isAutofilled()); |
+} |
+ |
// Tests that |PreviewSuggestion| properly sets the username selection range. |
TEST_F(PasswordAutofillAgentTest, PreviewSuggestionSelectionRange) { |
username_element_.setValue(WebString::fromUTF8("ali")); |
@@ -1063,13 +1107,9 @@ TEST_F(PasswordAutofillAgentTest, PreviewSuggestionSelectionRange) { |
EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( |
username_element_, kAliceUsername, kAlicePassword)); |
- EXPECT_EQ( |
- kAliceUsername, |
- static_cast<std::string>(username_element_.suggestedValue().utf8())); |
+ EXPECT_EQ(kAliceUsername, username_element_.suggestedValue().utf8()); |
EXPECT_TRUE(username_element_.isAutofilled()); |
- EXPECT_EQ( |
- kAlicePassword, |
- static_cast<std::string>(password_element_.suggestedValue().utf8())); |
+ EXPECT_EQ(kAlicePassword, password_element_.suggestedValue().utf8()); |
EXPECT_TRUE(password_element_.isAutofilled()); |
int username_length = strlen(kAliceUsername); |
CheckUsernameSelection(3, username_length); |