| 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 f17aeb63127b985df577ec84794cf32e049e6e99..2168e4b08bfb2069bd0cd1e67c32383354a67d1c 100644
|
| --- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
|
| +++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
|
| @@ -177,12 +177,13 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
|
| void SimulateOnFillPasswordForm(
|
| const PasswordFormFillData& fill_data) {
|
| AutofillMsg_FillPasswordForm msg(0, fill_data);
|
| - password_autofill_->OnMessageReceived(msg);
|
| + static_cast<content::RenderViewObserver*>(password_autofill_agent_)
|
| + ->OnMessageReceived(msg);
|
| }
|
|
|
| void SendVisiblePasswordForms() {
|
| - password_autofill_->SendPasswordForms(GetMainFrame(),
|
| - true /* only_visible */);
|
| + static_cast<content::RenderViewObserver*>(password_autofill_agent_)
|
| + ->DidFinishLoad(GetMainFrame());
|
| }
|
|
|
| virtual void SetUp() {
|
| @@ -262,7 +263,8 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
|
| }
|
|
|
| void SimulateDidEndEditing(WebFrame* input_frame, WebInputElement& input) {
|
| - autofill_agent_->textFieldDidEndEditing(input);
|
| + static_cast<blink::WebAutofillClient*>(autofill_agent_)
|
| + ->textFieldDidEndEditing(input);
|
| }
|
|
|
| void SimulateInputChangeForElement(const std::string& new_value,
|
| @@ -278,8 +280,9 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
|
| if (move_caret_to_end)
|
| input.setSelectionRange(new_value.length(), new_value.length());
|
| if (is_user_input)
|
| - password_autofill_agent()->FirstUserGestureObserved();
|
| - autofill_agent_->textFieldDidChange(input);
|
| + password_autofill_agent_->FirstUserGestureObserved();
|
| + static_cast<blink::WebAutofillClient*>(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.
|
| @@ -294,17 +297,18 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
|
| }
|
|
|
| void SimulateSuggestionChoice(WebInputElement& username_input) {
|
| - blink::WebString blink_username =
|
| - blink::WebString::fromUTF8(kAliceUsername);
|
| - blink::WebString blink_password =
|
| - blink::WebString::fromUTF8(kAlicePassword);
|
| + base::string16 username(base::ASCIIToUTF16(kAliceUsername));
|
| + base::string16 password(base::ASCIIToUTF16(kAlicePassword));
|
|
|
| // This call is necessary to setup the autofill agent appropriate for the
|
| // user selection; simulates the menu actually popping up.
|
| render_thread_->sink().ClearMessages();
|
| - autofill_agent_->FormControlElementClicked(username_input, false);
|
| + static_cast<autofill::PageClickListener*>(autofill_agent_)
|
| + ->FormControlElementClicked(username_input, false);
|
|
|
| - autofill_agent_->OnFillPasswordSuggestion(blink_username, blink_password);
|
| + AutofillMsg_FillPasswordSuggestion msg(0, username, password);
|
| + static_cast<content::RenderViewObserver*>(autofill_agent_)
|
| + ->OnMessageReceived(msg);
|
| }
|
|
|
| void LayoutMainFrame() {
|
| @@ -345,7 +349,7 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
|
| // permanently ignored.
|
| if (!ShouldIgnoreAutocompleteOffForPasswordFields()) {
|
| EXPECT_TRUE(
|
| - password_autofill_agent()->ShowSuggestions(username_element_, false));
|
| + password_autofill_agent_->ShowSuggestions(username_element_, false));
|
|
|
| EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
|
| AutofillHostMsg_ShowPasswordSuggestions::ID));
|
| @@ -356,7 +360,8 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
|
| ui::KeyboardCode key_code) {
|
| blink::WebKeyboardEvent key_event;
|
| key_event.windowsKeyCode = key_code;
|
| - autofill_agent_->textFieldDidReceiveKeyDown(element, key_event);
|
| + static_cast<blink::WebAutofillClient*>(autofill_agent_)
|
| + ->textFieldDidReceiveKeyDown(element, key_event);
|
| }
|
|
|
| void CheckTextFieldsStateForElements(const WebInputElement& username_element,
|
| @@ -457,10 +462,6 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
|
| render_thread_->sink().ClearMessages();
|
| }
|
|
|
| - PasswordAutofillAgent* password_autofill_agent() {
|
| - return autofill_agent_->password_autofill_agent_;
|
| - }
|
| -
|
| void ExpectFormSubmittedWithPasswords(const std::string& password_value,
|
| const std::string& new_password_value) {
|
| const IPC::Message* message =
|
| @@ -725,16 +726,20 @@ TEST_F(PasswordAutofillAgentTest, WaitUsername) {
|
| // Autocomplete should happen only when the username textfield is blurred with
|
| // a full match.
|
| username_element_.setValue("a");
|
| - autofill_agent_->textFieldDidEndEditing(username_element_);
|
| + static_cast<blink::WebAutofillClient*>(autofill_agent_)
|
| + ->textFieldDidEndEditing(username_element_);
|
| CheckTextFieldsState("a", false, std::string(), false);
|
| username_element_.setValue("al");
|
| - autofill_agent_->textFieldDidEndEditing(username_element_);
|
| + static_cast<blink::WebAutofillClient*>(autofill_agent_)
|
| + ->textFieldDidEndEditing(username_element_);
|
| CheckTextFieldsState("al", false, std::string(), false);
|
| username_element_.setValue("alices");
|
| - autofill_agent_->textFieldDidEndEditing(username_element_);
|
| + static_cast<blink::WebAutofillClient*>(autofill_agent_)
|
| + ->textFieldDidEndEditing(username_element_);
|
| CheckTextFieldsState("alices", false, std::string(), false);
|
| username_element_.setValue(ASCIIToUTF16(kAliceUsername));
|
| - autofill_agent_->textFieldDidEndEditing(username_element_);
|
| + static_cast<blink::WebAutofillClient*>(autofill_agent_)
|
| + ->textFieldDidEndEditing(username_element_);
|
| CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true);
|
| }
|
|
|
| @@ -1005,7 +1010,7 @@ TEST_F(PasswordAutofillAgentTest, SelectUsernameWithPasswordAutofillOff) {
|
| password_element_.setAttribute(WebString::fromUTF8("autocomplete"),
|
| WebString::fromUTF8("off"));
|
|
|
| - // Simulate the user changing the username to some known username.
|
| + // Simulate the user changing the username to some known username.
|
| SimulateUsernameChange(kAliceUsername, true);
|
|
|
| ExpectNoSuggestionsPopup();
|
| @@ -1132,13 +1137,13 @@ TEST_F(PasswordAutofillAgentTest, FillSuggestion) {
|
|
|
| // If the password field is not autocompletable, it should not be affected.
|
| SetElementReadOnly(password_element_, true);
|
| - EXPECT_FALSE(password_autofill_->FillSuggestion(
|
| + EXPECT_FALSE(password_autofill_agent_->FillSuggestion(
|
| username_element_, kAliceUsername, kAlicePassword));
|
| CheckTextFieldsDOMState(std::string(), false, std::string(), false);
|
| SetElementReadOnly(password_element_, false);
|
|
|
| // After filling with the suggestion, both fields should be autocompleted.
|
| - EXPECT_TRUE(password_autofill_->FillSuggestion(
|
| + EXPECT_TRUE(password_autofill_agent_->FillSuggestion(
|
| username_element_, kAliceUsername, kAlicePassword));
|
| CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
|
| int username_length = strlen(kAliceUsername);
|
| @@ -1146,7 +1151,7 @@ TEST_F(PasswordAutofillAgentTest, FillSuggestion) {
|
|
|
| // Try Filling with a suggestion with password different from the one that was
|
| // initially sent to the renderer.
|
| - EXPECT_TRUE(password_autofill_->FillSuggestion(
|
| + EXPECT_TRUE(password_autofill_agent_->FillSuggestion(
|
| username_element_, kBobUsername, kCarolPassword));
|
| CheckTextFieldsDOMState(kBobUsername, true, kCarolPassword, true);
|
| username_length = strlen(kBobUsername);
|
| @@ -1165,7 +1170,7 @@ TEST_F(PasswordAutofillAgentTest, PreviewSuggestion) {
|
|
|
| // If the password field is not autocompletable, it should not be affected.
|
| SetElementReadOnly(password_element_, true);
|
| - EXPECT_FALSE(password_autofill_->PreviewSuggestion(
|
| + EXPECT_FALSE(password_autofill_agent_->PreviewSuggestion(
|
| username_element_, kAliceUsername, kAlicePassword));
|
| EXPECT_EQ(std::string(), username_element_.suggestedValue().utf8());
|
| EXPECT_FALSE(username_element_.isAutofilled());
|
| @@ -1175,7 +1180,7 @@ TEST_F(PasswordAutofillAgentTest, PreviewSuggestion) {
|
|
|
| // After selecting the suggestion, both fields should be previewed
|
| // with suggested values.
|
| - EXPECT_TRUE(password_autofill_->PreviewSuggestion(
|
| + EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
|
| username_element_, kAliceUsername, kAlicePassword));
|
| EXPECT_EQ(
|
| kAliceUsername,
|
| @@ -1190,7 +1195,7 @@ TEST_F(PasswordAutofillAgentTest, PreviewSuggestion) {
|
|
|
| // Try previewing with a password different from the one that was initially
|
| // sent to the renderer.
|
| - EXPECT_TRUE(password_autofill_->PreviewSuggestion(
|
| + EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
|
| username_element_, kBobUsername, kCarolPassword));
|
| EXPECT_EQ(
|
| kBobUsername,
|
| @@ -1217,7 +1222,7 @@ TEST_F(PasswordAutofillAgentTest, PreviewSuggestionSelectionRange) {
|
| fill_data_.wait_for_username = true;
|
| SimulateOnFillPasswordForm(fill_data_);
|
|
|
| - EXPECT_TRUE(password_autofill_->PreviewSuggestion(
|
| + EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
|
| username_element_, kAliceUsername, kAlicePassword));
|
| EXPECT_EQ(
|
| kAliceUsername,
|
| @@ -1244,11 +1249,11 @@ TEST_F(PasswordAutofillAgentTest, ClearPreviewWithPasswordAutofilled) {
|
|
|
| CheckTextFieldsDOMState(std::string(), false, "sec", true);
|
|
|
| - EXPECT_TRUE(password_autofill_->PreviewSuggestion(
|
| + EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
|
| username_element_, kAliceUsername, kAlicePassword));
|
|
|
| - EXPECT_TRUE(password_autofill_->DidClearAutofillSelection(
|
| - username_element_));
|
| + EXPECT_TRUE(
|
| + password_autofill_agent_->DidClearAutofillSelection(username_element_));
|
|
|
| EXPECT_TRUE(username_element_.value().isEmpty());
|
| EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
|
| @@ -1273,11 +1278,11 @@ TEST_F(PasswordAutofillAgentTest, ClearPreviewWithUsernameAutofilled) {
|
|
|
| CheckTextFieldsDOMState("ali", true, std::string(), false);
|
|
|
| - EXPECT_TRUE(password_autofill_->PreviewSuggestion(
|
| + EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
|
| username_element_, kAliceUsername, kAlicePassword));
|
|
|
| - EXPECT_TRUE(password_autofill_->DidClearAutofillSelection(
|
| - username_element_));
|
| + EXPECT_TRUE(
|
| + password_autofill_agent_->DidClearAutofillSelection(username_element_));
|
|
|
| EXPECT_EQ(ASCIIToUTF16("ali"), username_element_.value());
|
| EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
|
| @@ -1305,11 +1310,11 @@ TEST_F(PasswordAutofillAgentTest,
|
|
|
| CheckTextFieldsDOMState("ali", true, "sec", true);
|
|
|
| - EXPECT_TRUE(password_autofill_->PreviewSuggestion(
|
| + EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
|
| username_element_, kAliceUsername, kAlicePassword));
|
|
|
| - EXPECT_TRUE(password_autofill_->DidClearAutofillSelection(
|
| - username_element_));
|
| + EXPECT_TRUE(
|
| + password_autofill_agent_->DidClearAutofillSelection(username_element_));
|
|
|
| EXPECT_EQ(ASCIIToUTF16("ali"), username_element_.value());
|
| EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
|
| @@ -1331,11 +1336,11 @@ TEST_F(PasswordAutofillAgentTest,
|
|
|
| CheckTextFieldsDOMState(std::string(), false, std::string(), false);
|
|
|
| - EXPECT_TRUE(password_autofill_->PreviewSuggestion(
|
| + EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
|
| username_element_, kAliceUsername, kAlicePassword));
|
|
|
| - EXPECT_TRUE(password_autofill_->DidClearAutofillSelection(
|
| - username_element_));
|
| + EXPECT_TRUE(
|
| + password_autofill_agent_->DidClearAutofillSelection(username_element_));
|
|
|
| EXPECT_TRUE(username_element_.value().isEmpty());
|
| EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
|
| @@ -1363,7 +1368,7 @@ TEST_F(PasswordAutofillAgentTest, ClearPreviewWithInlineAutocompletedUsername) {
|
| // The selection should have been set to 'lice', the last 4 letters.
|
| CheckUsernameSelection(1, 5);
|
|
|
| - EXPECT_TRUE(password_autofill_->PreviewSuggestion(
|
| + EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
|
| username_element_, "alicia", "secret"));
|
| EXPECT_EQ(
|
| "alicia",
|
| @@ -1375,8 +1380,8 @@ TEST_F(PasswordAutofillAgentTest, ClearPreviewWithInlineAutocompletedUsername) {
|
| EXPECT_TRUE(password_element_.isAutofilled());
|
| CheckUsernameSelection(1, 6);
|
|
|
| - EXPECT_TRUE(password_autofill_->DidClearAutofillSelection(
|
| - username_element_));
|
| + EXPECT_TRUE(
|
| + password_autofill_agent_->DidClearAutofillSelection(username_element_));
|
|
|
| EXPECT_EQ(kAliceUsername, username_element_.value().utf8());
|
| EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
|
| @@ -1401,7 +1406,7 @@ TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Activated) {
|
| // Turn the logging on.
|
| AutofillMsg_SetLoggingState msg_activate(0, true);
|
| // Up-cast to access OnMessageReceived, which is private in the agent.
|
| - EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_)
|
| + EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_agent_)
|
| ->OnMessageReceived(msg_activate));
|
|
|
| render_thread_->sink().ClearMessages();
|
| @@ -1416,10 +1421,10 @@ TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Deactivated) {
|
| // Turn the logging on and then off.
|
| AutofillMsg_SetLoggingState msg_activate(0, /*active=*/true);
|
| // Up-cast to access OnMessageReceived, which is private in the agent.
|
| - EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_)
|
| + EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_agent_)
|
| ->OnMessageReceived(msg_activate));
|
| AutofillMsg_SetLoggingState msg_deactivate(0, /*active=*/false);
|
| - EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_)
|
| + EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_agent_)
|
| ->OnMessageReceived(msg_deactivate));
|
|
|
| render_thread_->sink().ClearMessages();
|
| @@ -1474,7 +1479,8 @@ TEST_F(PasswordAutofillAgentTest, CredentialsOnClick) {
|
| // Simulate a user clicking on the username element. This should produce a
|
| // message with all the usernames.
|
| render_thread_->sink().ClearMessages();
|
| - autofill_agent_->FormControlElementClicked(username_element_, false);
|
| + static_cast<PageClickListener*>(autofill_agent_)
|
| + ->FormControlElementClicked(username_element_, false);
|
| ExpectAllCredentials();
|
|
|
| // Now simulate a user typing in an unrecognized username and then
|
| @@ -1482,7 +1488,8 @@ TEST_F(PasswordAutofillAgentTest, CredentialsOnClick) {
|
| // all the usernames.
|
| SimulateUsernameChange("baz", true);
|
| render_thread_->sink().ClearMessages();
|
| - autofill_agent_->FormControlElementClicked(username_element_, true);
|
| + static_cast<PageClickListener*>(autofill_agent_)
|
| + ->FormControlElementClicked(username_element_, true);
|
| ExpectAllCredentials();
|
|
|
| // Now simulate a user typing in the first letter of the username and then
|
| @@ -1491,7 +1498,8 @@ TEST_F(PasswordAutofillAgentTest, CredentialsOnClick) {
|
| // suggestion list.
|
| SimulateUsernameChange("a", true);
|
| render_thread_->sink().ClearMessages();
|
| - autofill_agent_->FormControlElementClicked(username_element_, true);
|
| + static_cast<PageClickListener*>(autofill_agent_)
|
| + ->FormControlElementClicked(username_element_, true);
|
| ExpectAllCredentials();
|
| }
|
|
|
| @@ -1508,7 +1516,7 @@ TEST_F(PasswordAutofillAgentTest,
|
| // Simulate that the password value was cleared by the site's JavaScript
|
| // before submit.
|
| password_element_.setValue(WebString());
|
| - static_cast<content::RenderViewObserver*>(password_autofill_agent())
|
| + static_cast<content::RenderViewObserver*>(password_autofill_agent_)
|
| ->WillSubmitForm(GetMainFrame(), username_element_.form());
|
|
|
| // Observe that the PasswordAutofillAgent still remembered the last non-empty
|
| @@ -1529,7 +1537,7 @@ TEST_F(PasswordAutofillAgentTest,
|
| // Simulate that the user actually cleared the password again.
|
| SimulateInputChangeForElement(
|
| "", true, GetMainFrame(), password_element_, true);
|
| - static_cast<content::RenderViewObserver*>(password_autofill_agent())
|
| + static_cast<content::RenderViewObserver*>(password_autofill_agent_)
|
| ->WillSubmitForm(GetMainFrame(), username_element_.form());
|
|
|
| // Observe that the PasswordAutofillAgent respects the user having cleared the
|
| @@ -1558,7 +1566,7 @@ TEST_F(PasswordAutofillAgentTest,
|
| // Simulate that the password value was cleared by the site's JavaScript
|
| // before submit.
|
| password_element_.setValue(WebString());
|
| - static_cast<content::RenderViewObserver*>(password_autofill_agent())
|
| + static_cast<content::RenderViewObserver*>(password_autofill_agent_)
|
| ->WillSubmitForm(GetMainFrame(), username_element_.form());
|
|
|
| // Observe that the PasswordAutofillAgent still remembered the last non-empty
|
|
|