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

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

Issue 414013003: Password autofill should not override explicitly typed password (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't give up autocompletion completely Created 6 years, 5 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 d228ca28a520424f16080e9e205491e365aacd16..8433372b05a8acc068f6989f1ede0d497f3d0064 100644
--- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
+++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
@@ -261,21 +261,26 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
password_element_.setAutofilled(false);
}
- void SimulateUsernameChangeForElement(const std::string& username,
- bool move_caret_to_end,
- WebFrame* input_frame,
- WebInputElement& username_input,
- bool is_user_input) {
- username_input.setValue(WebString::fromUTF8(username), is_user_input);
+ void SimulateDidEndEditingWithNoChangeForElement(WebFrame* input_frame,
+ WebInputElement& input) {
+ autofill_agent_->textFieldDidEndEditing(input);
+ }
+
+ void SimulateInputChangeForElement(const std::string& new_value,
+ bool move_caret_to_end,
+ WebFrame* input_frame,
+ WebInputElement& input,
+ bool is_user_input) {
+ input.setValue(WebString::fromUTF8(new_value), is_user_input);
// The field must have focus or AutofillAgent will think the
// change should be ignored.
- while (!username_input.focused())
+ while (!input.focused())
input_frame->document().frame()->view()->advanceFocus(false);
if (move_caret_to_end)
- username_input.setSelectionRange(username.length(), username.length());
+ input.setSelectionRange(new_value.length(), new_value.length());
if (is_user_input)
- autofill_agent_->password_autofill_agent_->gatekeeper_.OnUserGesture();
- autofill_agent_->textFieldDidChange(username_input);
+ autofill_agent_->password_autofill_agent_->FirstUserGestureObserved();
+ autofill_agent_->textFieldDidChange(input);
// Processing is delayed because of a Blink bug:
// https://bugs.webkit.org/show_bug.cgi?id=16976
// See PasswordAutofillAgent::TextDidChangeInTextField() for details.
@@ -310,11 +315,11 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
void SimulateUsernameChange(const std::string& username,
bool move_caret_to_end,
bool is_user_input = false) {
- SimulateUsernameChangeForElement(username,
- move_caret_to_end,
- GetMainFrame(),
- username_element_,
- is_user_input);
+ SimulateInputChangeForElement(username,
+ move_caret_to_end,
+ GetMainFrame(),
+ username_element_,
+ is_user_input);
}
// Tests that no suggestion popup is generated when the username_element_ is
@@ -904,7 +909,7 @@ TEST_F(PasswordAutofillAgentTest, IframeNoFillTest) {
// Simulate the user typing in the username in the iframe which should cause
// an autofill.
- SimulateUsernameChangeForElement(
+ SimulateInputChangeForElement(
kAliceUsername, true, iframe, username_input, true);
CheckTextFieldsStateForElements(username_input,
@@ -1474,4 +1479,42 @@ TEST_F(PasswordAutofillAgentTest, CredentialsOnClick) {
ExpectAllCredentials();
}
+// The user first accepts a suggestion, but then overwrites the password. This
+// test checks that the overwritten password is not reverted back by the user
+// triggering autofill through focusing (but not changing) the username again.
+TEST_F(PasswordAutofillAgentTest, PasswordNotOverwritten) {
+ // Simulate having credentials which needed to wait until the user starts
+ // typing the username to be filled (e.g., PSL-matched credentials). Those are
+ // the ones which can be filled as a result of TextFieldDidEndEditing.
+ fill_data_.wait_for_username = true;
+ // Simulate that the user typed her name to make the autofill work.
+ SimulateInputChangeForElement(kAliceUsername,
+ /*move_caret_to_end=*/true,
+ GetMainFrame(),
+ username_element_,
+ /*is_user_input=*/true);
+ SimulateOnFillPasswordForm(fill_data_);
+
+ const std::string old_username(username_element_.value().utf8());
+ const std::string old_password(password_element_.value().utf8());
+ const std::string new_password(old_password + "modify");
+
+ // The user changes the password.
+ SimulateInputChangeForElement(new_password,
+ /*move_caret_to_end=*/true,
+ GetMainFrame(),
+ password_element_,
+ /*is_user_input=*/true);
+
+ // The user switches back into the username field, but leaves that without
+ // changes.
+ SimulateDidEndEditingWithNoChangeForElement(GetMainFrame(),
+ username_element_);
+
+ // The password should have stayed as the user changed it.
+ CheckTextFieldsDOMState(old_username, false, new_password, false);
+ // The password should not have a suggested value.
+ CheckTextFieldsState(old_username, false, std::string(), false);
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698