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

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

Issue 208453002: Add "previewing on hover" support for password field. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improve rebased code. Created 6 years, 7 months 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
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 7d061db21d2d0849ceaa8070f3313ee5c0d36e4e..7eed5d8205d31528f081128ac7b0b3b4ead9893f 100644
--- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
+++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
@@ -1056,6 +1056,84 @@ TEST_F(PasswordAutofillAgentTest, AcceptSuggestion) {
CheckUsernameSelection(username_length, username_length);
}
+// Tests that |SelectSuggestion| properly previews the username and password.
+TEST_F(PasswordAutofillAgentTest, SelectSuggestion) {
+ // Simulate the browser sending the login info, but set |wait_for_username|
+ // to prevent the form from being immediately filled.
+ fill_data_.wait_for_username = true;
+ SimulateOnFillPasswordForm(fill_data_);
+
+ // Neither field should have been autocompleted.
+ CheckTextFieldsDOMState(std::string(), false, std::string(), false);
+
+ // If the password field is not autocompletable, it should not be affected.
+ SetElementReadOnly(password_element_, true);
+ EXPECT_FALSE(password_autofill_->SelectSuggestion(
+ username_element_, kAliceUsername, kAlicePassword));
+ EXPECT_EQ(std::string(), username_element_.suggestedValue().utf8());
+ EXPECT_FALSE(username_element_.isAutofilled());
+ EXPECT_EQ(std::string(), password_element_.suggestedValue().utf8());
+ EXPECT_FALSE(password_element_.isAutofilled());
+ SetElementReadOnly(password_element_, false);
+
+ // After selecting the suggestion, both fields should be previewed
+ // with suggested values.
+ EXPECT_TRUE(password_autofill_->SelectSuggestion(
+ username_element_, kAliceUsername, kAlicePassword));
+ EXPECT_EQ(
+ kAliceUsername,
+ static_cast<std::string>(username_element_.suggestedValue().utf8()));
+ EXPECT_TRUE(username_element_.isAutofilled());
+ EXPECT_EQ(
+ kAlicePassword,
+ static_cast<std::string>(password_element_.suggestedValue().utf8()));
+ EXPECT_TRUE(password_element_.isAutofilled());
+ int username_length = strlen(kAliceUsername);
+ // Selection range starts from the end of matching characters between
+ // username_element value and suggestedValue. value lenght is 0 in this case.
+ CheckUsernameSelection(0, username_length);
+
+ // Try selecting a suggestion with a password different from the one that was
+ // initially sent to the renderer.
+ EXPECT_TRUE(password_autofill_->SelectSuggestion(
+ username_element_, kBobUsername, kCarolPassword));
+ EXPECT_EQ(
+ kBobUsername,
+ static_cast<std::string>(username_element_.suggestedValue().utf8()));
+ EXPECT_TRUE(username_element_.isAutofilled());
+ EXPECT_EQ(
+ kCarolPassword,
+ static_cast<std::string>(password_element_.suggestedValue().utf8()));
+ EXPECT_TRUE(password_element_.isAutofilled());
+ username_length = strlen(kBobUsername);
+ CheckUsernameSelection(0, username_length);
+}
+
+// Tests that |SelectSuggestion| properly sets the username selection range.
+TEST_F(PasswordAutofillAgentTest, SelectSuggestionSelectionRange) {
+ username_element_.setValue(WebString::fromUTF8("ali"));
+
+ // Simulate the browser sending the login info, but set |wait_for_username|
+ // to prevent the form from being immediately filled.
+ fill_data_.wait_for_username = true;
+ SimulateOnFillPasswordForm(fill_data_);
+
+ EXPECT_TRUE(password_autofill_->SelectSuggestion(
+ username_element_, kAliceUsername, kAlicePassword));
+ EXPECT_EQ(
+ kAliceUsername,
+ static_cast<std::string>(username_element_.suggestedValue().utf8()));
+ EXPECT_TRUE(username_element_.isAutofilled());
+ EXPECT_EQ(
+ kAlicePassword,
+ static_cast<std::string>(password_element_.suggestedValue().utf8()));
+ EXPECT_TRUE(password_element_.isAutofilled());
+ int username_length = strlen(kAliceUsername);
+ // Selection range starts from the end of matching characters between
+ // username_element value and suggestedValue.
+ CheckUsernameSelection(3, username_length);
+}
+
// Tests that logging is off by default.
TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) {
render_thread_->sink().ClearMessages();

Powered by Google App Engine
This is Rietveld 408576698