| 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 1723480a6b8fa2195a2f660fd0d43664434a0af0..b842348cfb5f2d21c5b9422d39c590c1a4da9a51 100644
|
| --- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
|
| +++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
|
| @@ -254,14 +254,17 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
|
| void SimulateUsernameChangeForElement(const std::string& username,
|
| bool move_caret_to_end,
|
| WebFrame* input_frame,
|
| - WebInputElement& username_input) {
|
| - username_input.setValue(WebString::fromUTF8(username));
|
| + WebInputElement& username_input,
|
| + bool is_user_input) {
|
| + username_input.setValue(WebString::fromUTF8(username), is_user_input);
|
| // The field must have focus or AutofillAgent will think the
|
| // change should be ignored.
|
| while (!username_input.focused())
|
| input_frame->document().frame()->view()->advanceFocus(false);
|
| if (move_caret_to_end)
|
| username_input.setSelectionRange(username.length(), username.length());
|
| + if (is_user_input)
|
| + password_autofill_->set_user_gesture_occurred(true);
|
| autofill_agent_->textFieldDidChange(username_input);
|
| // Processing is delayed because of a Blink bug:
|
| // https://bugs.webkit.org/show_bug.cgi?id=16976
|
| @@ -276,14 +279,29 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
|
| base::MessageLoop::current()->RunUntilIdle();
|
| }
|
|
|
| + void SimulateSuggestionChoice(const std::string& username,
|
| + WebInputElement& username_input) {
|
| + blink::WebString blink_username = blink::WebString::fromUTF8(username);
|
| +
|
| + // This call is necessary to setup the autofill agent appropriate for the
|
| + // user selection; simulates the menu actually popping up.
|
| + autofill_agent_->InputElementClicked(username_input, false, true);
|
| +
|
| + autofill_agent_->OnAcceptPasswordAutofillSuggestion(blink_username);
|
| + }
|
| +
|
| void LayoutMainFrame() {
|
| GetMainFrame()->view()->layout();
|
| }
|
|
|
| void SimulateUsernameChange(const std::string& username,
|
| - bool move_caret_to_end) {
|
| - SimulateUsernameChangeForElement(username, move_caret_to_end,
|
| - GetMainFrame(), username_element_);
|
| + bool move_caret_to_end,
|
| + bool is_user_input = false) {
|
| + SimulateUsernameChangeForElement(username,
|
| + move_caret_to_end,
|
| + GetMainFrame(),
|
| + username_element_,
|
| + is_user_input);
|
| }
|
|
|
| // Tests that no suggestion popup is generated when the username_element_ is
|
| @@ -310,7 +328,7 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
|
| // permanently ignored.
|
| if (!ShouldIgnoreAutocompleteOffForPasswordFields()) {
|
| EXPECT_TRUE(autofill_agent_->password_autofill_agent_->ShowSuggestions(
|
| - username_element_));
|
| + username_element_, false));
|
|
|
| EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
|
| AutofillHostMsg_ShowPasswordSuggestions::ID));
|
| @@ -330,7 +348,7 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
|
| const WebInputElement& password_element,
|
| const std::string& password,
|
| bool password_autofilled,
|
| - bool checkSuggestedValue = true) {
|
| + bool checkSuggestedValue) {
|
| EXPECT_EQ(username,
|
| static_cast<std::string>(username_element.value().utf8()));
|
| EXPECT_EQ(username_autofilled, username_element.isAutofilled());
|
| @@ -347,9 +365,13 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
|
| bool username_autofilled,
|
| const std::string& password,
|
| bool password_autofilled) {
|
| - CheckTextFieldsStateForElements(username_element_, username,
|
| - username_autofilled, password_element_,
|
| - password, password_autofilled);
|
| + CheckTextFieldsStateForElements(username_element_,
|
| + username,
|
| + username_autofilled,
|
| + password_element_,
|
| + password,
|
| + password_autofilled,
|
| + true);
|
| }
|
|
|
| // Checks the DOM-accessible value of the username element and the
|
| @@ -645,10 +667,10 @@ TEST_F(PasswordAutofillAgentTest, InlineAutocomplete) {
|
| // Simulate the browser sending back the login info.
|
| SimulateOnFillPasswordForm(fill_data_);
|
|
|
| - // Clear the text fields to start fresh.
|
| ClearUsernameAndPasswordFields();
|
|
|
| - // Simulate the user typing in the first letter of 'alice', a stored username.
|
| + // Simulate the user typing in the first letter of 'alice', a stored
|
| + // username.
|
| SimulateUsernameChange("a", true);
|
| // Both the username and password text fields should reflect selection of the
|
| // stored login.
|
| @@ -822,16 +844,23 @@ TEST_F(PasswordAutofillAgentTest, IframeNoFillTest) {
|
| WebInputElement password_input = password_element.to<WebInputElement>();
|
| ASSERT_FALSE(username_element.isNull());
|
|
|
| - CheckTextFieldsStateForElements(username_input, "", false,
|
| - password_input, "", false);
|
| -
|
| - // Simulate the user typing in the username in the iframe, which should cause
|
| - // an autofill.
|
| - SimulateUsernameChangeForElement(kAliceUsername, true,
|
| - iframe, username_input);
|
| + CheckTextFieldsStateForElements(
|
| + username_input, "", false, password_input, "", false, false);
|
|
|
| - CheckTextFieldsStateForElements(username_input, kAliceUsername, true,
|
| - password_input, kAlicePassword, true);
|
| + // Simulate the user typing in the username in the iframe and then selecting
|
| + // the autofill choice from the dropdown, thus causing an autofill.
|
| + SimulateUsernameChangeForElement(
|
| + kAliceUsername, true, iframe, username_input, false);
|
| + SimulateElementClick(kUsernameName);
|
| + SimulateSuggestionChoice(kAliceUsername, username_input);
|
| +
|
| + CheckTextFieldsStateForElements(username_input,
|
| + kAliceUsername,
|
| + true,
|
| + password_input,
|
| + kAlicePassword,
|
| + true,
|
| + false);
|
| }
|
|
|
| // Tests that a password will only be filled as a suggested and will not be
|
| @@ -993,9 +1022,10 @@ TEST_F(PasswordAutofillAgentTest,
|
| // set directly.
|
| SimulateElementClick(kUsernameName);
|
|
|
| - // Simulate the user entering her username.
|
| - username_element_.setValue(ASCIIToUTF16(kAliceUsername), true);
|
| - autofill_agent_->textFieldDidEndEditing(username_element_);
|
| + // Simulate the user entering her username and selecting the matching autofill
|
| + // from the dropdown.
|
| + SimulateUsernameChange(kAliceUsername, true, true);
|
| + SimulateSuggestionChoice(kAliceUsername, username_element_);
|
|
|
| // The username and password should now have been autocompleted.
|
| CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
|
| @@ -1016,4 +1046,19 @@ TEST_F(PasswordAutofillAgentTest,
|
| EXPECT_EQ(1, password_onchange_called);
|
| }
|
|
|
| +// Tests that autocomplete works when the user clicks on an element and chooses
|
| +// a suggestion from the autofill suggestion list. {
|
| +TEST_F(PasswordAutofillAgentTest, ClickAndSelect) {
|
| + // Simulate the browser sending back the login info.
|
| + SimulateOnFillPasswordForm(fill_data_);
|
| +
|
| + // Clear the text fields to start fresh.
|
| + ClearUsernameAndPasswordFields();
|
| +
|
| + SimulateElementClick(kUsernameName);
|
| + SimulateSuggestionChoice(kAliceUsername, username_element_);
|
| +
|
| + CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
|
| +}
|
| +
|
| } // namespace autofill
|
|
|