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 beb842f02ca8206d1e71f1d35cfbc03879508290..e96323a6ff36883cf7fcf68bd3937b094dbd2f34 100644 |
--- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc |
+++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc |
@@ -302,22 +302,15 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest { |
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 (!input.focused()) |
- input_frame->document().frame()->view()->advanceFocus(false); |
- if (move_caret_to_end) |
- input.setSelectionRange(new_value.length(), new_value.length()); |
- if (is_user_input) { |
- AutofillMsg_FirstUserGestureObservedInTab msg(0); |
- content::RenderFrame::FromWebFrame(input_frame)->OnMessageReceived(msg); |
- |
- // Also pass the message to the testing object. |
- if (input_frame == GetMainFrame()) |
- password_autofill_agent_->FirstUserGestureObserved(); |
- } |
- input_frame->toWebLocalFrame()->autofillClient()->textFieldDidChange(input); |
+ if (is_user_input) |
+ SimulateUserInputChangeForElement(&input, input_frame, new_value); |
+ else |
+ input.setValue(WebString::fromUTF8(new_value), false); |
+ |
+ ProcessEvents(); |
+ } |
+ |
+ void ProcessEvents() { |
// Processing is delayed because of a Blink bug: |
// https://bugs.webkit.org/show_bug.cgi?id=16976 |
// See PasswordAutofillAgent::TextDidChangeInTextField() for details. |
@@ -367,14 +360,6 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest { |
is_user_input); |
} |
- void SimulateKeyDownEvent(const WebInputElement& element, |
- ui::KeyboardCode key_code) { |
- blink::WebKeyboardEvent key_event; |
- key_event.windowsKeyCode = key_code; |
- static_cast<blink::WebAutofillClient*>(autofill_agent_) |
- ->textFieldDidReceiveKeyDown(element, key_event); |
- } |
- |
void CheckTextFieldsStateForElements(const WebInputElement& username_element, |
const std::string& username, |
bool username_autofilled, |
@@ -688,7 +673,7 @@ TEST_F(PasswordAutofillAgentTest, PasswordClearOnEdit) { |
SimulateOnFillPasswordForm(fill_data_); |
// Simulate the user changing the username to some unknown username. |
- SimulateUsernameChange("alicia", true); |
+ SimulateUsernameChange("alicia", true, true); |
// The password should have been cleared. |
CheckTextFieldsState("alicia", false, std::string(), false); |
@@ -705,31 +690,31 @@ TEST_F(PasswordAutofillAgentTest, WaitUsername) { |
CheckTextFieldsState(std::string(), false, std::string(), false); |
// No autocomplete should happen when text is entered in the username. |
- SimulateUsernameChange("a", true); |
+ SimulateUsernameChange("a", true, true); |
CheckTextFieldsState("a", false, std::string(), false); |
- SimulateUsernameChange("al", true); |
+ SimulateUsernameChange("al", true, true); |
CheckTextFieldsState("al", false, std::string(), false); |
- SimulateUsernameChange(kAliceUsername, true); |
+ SimulateUsernameChange(kAliceUsername, true, true); |
CheckTextFieldsState(kAliceUsername, false, std::string(), false); |
// Autocomplete should happen only when the username textfield is blurred with |
// a full match. |
- username_element_.setValue("a"); |
+ SimulateUsernameChange("a", true, true); |
static_cast<blink::WebAutofillClient*>(autofill_agent_) |
->textFieldDidEndEditing(username_element_); |
CheckTextFieldsState("a", false, std::string(), false); |
- username_element_.setValue("al"); |
+ SimulateUsernameChange("al", true, true); |
static_cast<blink::WebAutofillClient*>(autofill_agent_) |
->textFieldDidEndEditing(username_element_); |
CheckTextFieldsState("al", false, std::string(), false); |
- username_element_.setValue("alices"); |
+ SimulateUsernameChange("alices", true, true); |
static_cast<blink::WebAutofillClient*>(autofill_agent_) |
->textFieldDidEndEditing(username_element_); |
CheckTextFieldsState("alices", false, std::string(), false); |
- username_element_.setValue(ASCIIToUTF16(kAliceUsername)); |
+ SimulateUsernameChange(kAliceUsername, true, true); |
static_cast<blink::WebAutofillClient*>(autofill_agent_) |
->textFieldDidEndEditing(username_element_); |
- CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
+ CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); |
} |
// Tests that inline autocompletion works properly. |
@@ -741,57 +726,58 @@ TEST_F(PasswordAutofillAgentTest, InlineAutocomplete) { |
// Simulate the user typing in the first letter of 'alice', a stored |
// username. |
- SimulateUsernameChange("a", true); |
+ SimulateUsernameChange("a", true, true); |
// Both the username and password text fields should reflect selection of the |
// stored login. |
- CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
+ CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); |
// And the selection should have been set to 'lice', the last 4 letters. |
CheckUsernameSelection(1, 5); |
// Now the user types the next letter of the same username, 'l'. |
- SimulateUsernameChange("al", true); |
+ SimulateUserTypingASCIICharacter('l'); |
+ ProcessEvents(); |
// Now the fields should have the same value, but the selection should have a |
// different start value. |
- CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
+ CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); |
CheckUsernameSelection(2, 5); |
- // Test that deleting does not trigger autocomplete. |
- SimulateKeyDownEvent(username_element_, ui::VKEY_BACK); |
- SimulateUsernameChange("alic", true); |
- CheckTextFieldsState("alic", false, std::string(), false); |
- CheckUsernameSelection(4, 4); // No selection. |
- // Reset the last pressed key to something other than backspace. |
- SimulateKeyDownEvent(username_element_, ui::VKEY_A); |
+ // Test that backspace will erase the selection and will stop autocompletion. |
+ SimulateUserTypingKeyCodeWithShift(ui::VKEY_BACK, false); |
+ ProcessEvents(); |
+ CheckTextFieldsState("al", false, std::string(), false); |
+ CheckUsernameSelection(2, 2); // No selection. |
// Now lets say the user goes astray from the stored username and types the |
// letter 'f', spelling 'alf'. We don't know alf (that's just sad), so in |
// practice the username should no longer be 'alice' and the selected range |
// should be empty. |
- SimulateUsernameChange("alf", true); |
+ SimulateUserTypingASCIICharacter('f'); |
+ ProcessEvents(); |
CheckTextFieldsState("alf", false, std::string(), false); |
CheckUsernameSelection(3, 3); // No selection. |
// Ok, so now the user removes all the text and enters the letter 'b'. |
- SimulateUsernameChange("b", true); |
+ SimulateUsernameChange("b", true, true); |
// The username and password fields should match the 'bob' entry. |
- CheckTextFieldsState(kBobUsername, true, kBobPassword, true); |
+ CheckTextFieldsDOMState(kBobUsername, true, kBobPassword, true); |
CheckUsernameSelection(1, 3); |
// Then, the user again removes all the text and types an uppercase 'C'. |
- SimulateUsernameChange("C", true); |
+ SimulateUsernameChange("C", true, true); |
// The username and password fields should match the 'Carol' entry. |
- CheckTextFieldsState(kCarolUsername, true, kCarolPassword, true); |
+ CheckTextFieldsDOMState(kCarolUsername, true, kCarolPassword, true); |
CheckUsernameSelection(1, 5); |
+ |
// The user removes all the text and types a lowercase 'c'. We only |
// want case-sensitive autocompletion, so the username and the selected range |
// should be empty. |
- SimulateUsernameChange("c", true); |
+ SimulateUsernameChange("c", true, true); |
CheckTextFieldsState("c", false, std::string(), false); |
CheckUsernameSelection(1, 1); |
// Check that we complete other_possible_usernames as well. |
- SimulateUsernameChange("R", true); |
- CheckTextFieldsState(kCarolAlternateUsername, true, kCarolPassword, true); |
+ SimulateUsernameChange("R", true, true); |
+ CheckTextFieldsDOMState(kCarolAlternateUsername, true, kCarolPassword, true); |
CheckUsernameSelection(1, 17); |
} |
@@ -920,6 +906,8 @@ TEST_F(PasswordAutofillAgentTest, IframeNoFillTest) { |
// Simulate the user typing in the username in the iframe which should cause |
// an autofill. |
+ content::RenderFrame::FromWebFrame(iframe) |
+ ->OnMessageReceived(AutofillMsg_FirstUserGestureObservedInTab(0)); |
SimulateInputChangeForElement( |
kAliceUsername, true, iframe, username_input, true); |
@@ -1029,9 +1017,9 @@ TEST_F(PasswordAutofillAgentTest, |
// set directly. |
SimulateElementClick(kUsernameName); |
- // Simulate the user entering her username and selecting the matching autofill |
- // from the dropdown. |
- SimulateUsernameChange(kAliceUsername, true, true); |
+ // Simulate the user entering the first letter of her username and selecting |
+ // the matching autofill from the dropdown. |
+ SimulateUsernameChange("a", true, true); |
SimulateSuggestionChoice(username_element_); |
// The username and password should now have been autocompleted. |
@@ -1289,10 +1277,10 @@ TEST_F(PasswordAutofillAgentTest, ClearPreviewWithInlineAutocompletedUsername) { |
ClearUsernameAndPasswordFields(); |
// Simulate the user typing in the first letter of 'alice', a stored username. |
- SimulateUsernameChange("a", true); |
+ SimulateUsernameChange("a", true, true); |
// Both the username and password text fields should reflect selection of the |
// stored login. |
- CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
+ CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); |
// The selection should have been set to 'lice', the last 4 letters. |
CheckUsernameSelection(1, 5); |
@@ -1314,7 +1302,7 @@ TEST_F(PasswordAutofillAgentTest, ClearPreviewWithInlineAutocompletedUsername) { |
EXPECT_EQ(kAliceUsername, username_element_.value().utf8()); |
EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); |
EXPECT_TRUE(username_element_.isAutofilled()); |
- EXPECT_TRUE(password_element_.value().isEmpty()); |
+ EXPECT_EQ(kAlicePassword, password_element_.value().utf8()); |
EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); |
EXPECT_TRUE(password_element_.isAutofilled()); |
CheckUsernameSelection(1, 5); |
@@ -1419,12 +1407,13 @@ TEST_F(PasswordAutofillAgentTest, CredentialsOnClick) { |
static_cast<PageClickListener*>(autofill_agent_) |
->FormControlElementClicked(username_element_, true); |
CheckSuggestions("baz", true); |
+ ClearUsernameAndPasswordFields(); |
// Now simulate a user typing in the first letter of the username and then |
// clicking on the username element. While the typing of the first letter will |
// inline autocomplete, clicking on the element should still produce a full |
// suggestion list. |
- SimulateUsernameChange("a", true); |
+ SimulateUsernameChange("a", true, true); |
render_thread_->sink().ClearMessages(); |
static_cast<PageClickListener*>(autofill_agent_) |
->FormControlElementClicked(username_element_, true); |
@@ -1644,7 +1633,7 @@ TEST_F(PasswordAutofillAgentTest, |
/*is_user_input=*/true); |
// Simulate the user typing a stored username. |
- SimulateUsernameChange(kAliceUsername, true); |
+ SimulateUsernameChange(kAliceUsername, true, true); |
// The autofileld password should replace the typed one. |
CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); |
} |