Chromium Code Reviews| 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..5a3a08271676c572208b5cf7a0c824dda37444e4 100644 |
| --- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc |
| +++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc |
| @@ -997,6 +997,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| |
| @@ -1048,6 +1072,40 @@ TEST_F(PasswordAutofillAgentTest, PreviewSuggestion) { |
| 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, |
| + static_cast<std::string>(password_element_.suggestedValue().utf8())); |
|
vabr (Chromium)
2016/09/07 08:32:53
Does this really need the cast? utf8() should alre
sense (YandexTeam)
2016/09/07 11:40:14
Yes, I also thought about this cast, but to be con
|
| + 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, |
| + static_cast<std::string>(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")); |