Commit e5f069d5 authored by pritam.nikam's avatar pritam.nikam Committed by Commit bot

[Password Manager] Unfriend PasswordAutofillAgentTest from PasswordAutofillAgent (clean-up).

BUG=368160
TBR=phajdan.jr@chromium.org

Review URL: https://codereview.chromium.org/563313004

Cr-Commit-Position: refs/heads/master@{#296071}
parent 07528460
...@@ -54,6 +54,14 @@ class AutofillRendererTest : public ChromeRenderViewTest { ...@@ -54,6 +54,14 @@ class AutofillRendererTest : public ChromeRenderViewTest {
SendContentStateImmediately(); SendContentStateImmediately();
} }
void SimulateRequestAutocompleteResult(
const blink::WebFormElement::AutocompleteResult& result,
const base::string16& message) {
AutofillMsg_RequestAutocompleteResult msg(0, result, message, FormData());
static_cast<content::RenderViewObserver*>(autofill_agent_)
->OnMessageReceived(msg);
}
private: private:
DISALLOW_COPY_AND_ASSIGN(AutofillRendererTest); DISALLOW_COPY_AND_ASSIGN(AutofillRendererTest);
}; };
...@@ -199,7 +207,8 @@ TEST_F(AutofillRendererTest, ShowAutofillWarning) { ...@@ -199,7 +207,8 @@ TEST_F(AutofillRendererTest, ShowAutofillWarning) {
// Simulate attempting to Autofill the form from the first element, which // Simulate attempting to Autofill the form from the first element, which
// specifies autocomplete="off". This should still trigger an IPC which // specifies autocomplete="off". This should still trigger an IPC which
// shouldn't display warnings. // shouldn't display warnings.
autofill_agent_->FormControlElementClicked(firstname, true); static_cast<PageClickListener*>(autofill_agent_)
->FormControlElementClicked(firstname, true);
const IPC::Message* message1 = render_thread_->sink().GetFirstMessageMatching( const IPC::Message* message1 = render_thread_->sink().GetFirstMessageMatching(
AutofillHostMsg_QueryFormFieldAutofill::ID); AutofillHostMsg_QueryFormFieldAutofill::ID);
EXPECT_NE(static_cast<IPC::Message*>(NULL), message1); EXPECT_NE(static_cast<IPC::Message*>(NULL), message1);
...@@ -213,7 +222,8 @@ TEST_F(AutofillRendererTest, ShowAutofillWarning) { ...@@ -213,7 +222,8 @@ TEST_F(AutofillRendererTest, ShowAutofillWarning) {
// does not specify autocomplete="off". This should trigger an IPC that will // does not specify autocomplete="off". This should trigger an IPC that will
// show warnings, as we *do* show warnings for elements that don't themselves // show warnings, as we *do* show warnings for elements that don't themselves
// set autocomplete="off", but for which the form does. // set autocomplete="off", but for which the form does.
autofill_agent_->FormControlElementClicked(middlename, true); static_cast<PageClickListener*>(autofill_agent_)
->FormControlElementClicked(middlename, true);
const IPC::Message* message2 = render_thread_->sink().GetFirstMessageMatching( const IPC::Message* message2 = render_thread_->sink().GetFirstMessageMatching(
AutofillHostMsg_QueryFormFieldAutofill::ID); AutofillHostMsg_QueryFormFieldAutofill::ID);
ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); ASSERT_NE(static_cast<IPC::Message*>(NULL), message2);
...@@ -277,7 +287,8 @@ class RequestAutocompleteRendererTest : public AutofillRendererTest { ...@@ -277,7 +287,8 @@ class RequestAutocompleteRendererTest : public AutofillRendererTest {
render_thread_->sink().ClearMessages(); render_thread_->sink().ClearMessages();
// Invoke requestAutocomplete to show the dialog. // Invoke requestAutocomplete to show the dialog.
autofill_agent_->didRequestAutocomplete(invoking_form()); static_cast<blink::WebAutofillClient*>(autofill_agent_)
->didRequestAutocomplete(invoking_form());
ASSERT_TRUE(render_thread_->sink().GetFirstMessageMatching( ASSERT_TRUE(render_thread_->sink().GetFirstMessageMatching(
AutofillHostMsg_RequestAutocomplete::ID)); AutofillHostMsg_RequestAutocomplete::ID));
...@@ -329,10 +340,9 @@ TEST_F(RequestAutocompleteRendererTest, MainFrameNavigateCancels) { ...@@ -329,10 +340,9 @@ TEST_F(RequestAutocompleteRendererTest, MainFrameNavigateCancels) {
TEST_F(RequestAutocompleteRendererTest, NoCancelOnSubframeNavigateAfterDone) { TEST_F(RequestAutocompleteRendererTest, NoCancelOnSubframeNavigateAfterDone) {
// Pretend that the dialog was cancelled. // Pretend that the dialog was cancelled.
autofill_agent_->OnRequestAutocompleteResult( SimulateRequestAutocompleteResult(
WebFormElement::AutocompleteResultErrorCancel, WebFormElement::AutocompleteResultErrorCancel,
base::ASCIIToUTF16("Print me to the console"), base::ASCIIToUTF16("Print me to the console"));
FormData());
// Additional navigations should not crash nor send cancels. // Additional navigations should not crash nor send cancels.
NavigateFrame(invoking_frame()); NavigateFrame(invoking_frame());
...@@ -342,10 +352,9 @@ TEST_F(RequestAutocompleteRendererTest, NoCancelOnSubframeNavigateAfterDone) { ...@@ -342,10 +352,9 @@ TEST_F(RequestAutocompleteRendererTest, NoCancelOnSubframeNavigateAfterDone) {
TEST_F(RequestAutocompleteRendererTest, NoCancelOnMainFrameNavigateAfterDone) { TEST_F(RequestAutocompleteRendererTest, NoCancelOnMainFrameNavigateAfterDone) {
// Pretend that the dialog was cancelled. // Pretend that the dialog was cancelled.
autofill_agent_->OnRequestAutocompleteResult( SimulateRequestAutocompleteResult(
WebFormElement::AutocompleteResultErrorCancel, WebFormElement::AutocompleteResultErrorCancel,
base::ASCIIToUTF16("Print me to the console"), base::ASCIIToUTF16("Print me to the console"));
FormData());
// Additional navigations should not crash nor send cancels. // Additional navigations should not crash nor send cancels.
NavigateFrame(GetMainFrame()); NavigateFrame(GetMainFrame());
...@@ -355,7 +364,8 @@ TEST_F(RequestAutocompleteRendererTest, NoCancelOnMainFrameNavigateAfterDone) { ...@@ -355,7 +364,8 @@ TEST_F(RequestAutocompleteRendererTest, NoCancelOnMainFrameNavigateAfterDone) {
TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) { TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) {
// Attempting to show the requestAutocomplete dialog again should be ignored. // Attempting to show the requestAutocomplete dialog again should be ignored.
autofill_agent_->didRequestAutocomplete(invoking_form()); static_cast<blink::WebAutofillClient*>(autofill_agent_)
->didRequestAutocomplete(invoking_form());
EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
AutofillHostMsg_RequestAutocomplete::ID)); AutofillHostMsg_RequestAutocomplete::ID));
} }
......
...@@ -177,12 +177,13 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest { ...@@ -177,12 +177,13 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
void SimulateOnFillPasswordForm( void SimulateOnFillPasswordForm(
const PasswordFormFillData& fill_data) { const PasswordFormFillData& fill_data) {
AutofillMsg_FillPasswordForm msg(0, fill_data); AutofillMsg_FillPasswordForm msg(0, fill_data);
password_autofill_->OnMessageReceived(msg); static_cast<content::RenderViewObserver*>(password_autofill_agent_)
->OnMessageReceived(msg);
} }
void SendVisiblePasswordForms() { void SendVisiblePasswordForms() {
password_autofill_->SendPasswordForms(GetMainFrame(), static_cast<content::RenderViewObserver*>(password_autofill_agent_)
true /* only_visible */); ->DidFinishLoad(GetMainFrame());
} }
virtual void SetUp() { virtual void SetUp() {
...@@ -262,7 +263,8 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest { ...@@ -262,7 +263,8 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
} }
void SimulateDidEndEditing(WebFrame* input_frame, WebInputElement& input) { 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, void SimulateInputChangeForElement(const std::string& new_value,
...@@ -278,8 +280,9 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest { ...@@ -278,8 +280,9 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
if (move_caret_to_end) if (move_caret_to_end)
input.setSelectionRange(new_value.length(), new_value.length()); input.setSelectionRange(new_value.length(), new_value.length());
if (is_user_input) if (is_user_input)
password_autofill_agent()->FirstUserGestureObserved(); password_autofill_agent_->FirstUserGestureObserved();
autofill_agent_->textFieldDidChange(input); static_cast<blink::WebAutofillClient*>(autofill_agent_)
->textFieldDidChange(input);
// Processing is delayed because of a Blink bug: // Processing is delayed because of a Blink bug:
// https://bugs.webkit.org/show_bug.cgi?id=16976 // https://bugs.webkit.org/show_bug.cgi?id=16976
// See PasswordAutofillAgent::TextDidChangeInTextField() for details. // See PasswordAutofillAgent::TextDidChangeInTextField() for details.
...@@ -294,17 +297,18 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest { ...@@ -294,17 +297,18 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
} }
void SimulateSuggestionChoice(WebInputElement& username_input) { void SimulateSuggestionChoice(WebInputElement& username_input) {
blink::WebString blink_username = base::string16 username(base::ASCIIToUTF16(kAliceUsername));
blink::WebString::fromUTF8(kAliceUsername); base::string16 password(base::ASCIIToUTF16(kAlicePassword));
blink::WebString blink_password =
blink::WebString::fromUTF8(kAlicePassword);
// This call is necessary to setup the autofill agent appropriate for the // This call is necessary to setup the autofill agent appropriate for the
// user selection; simulates the menu actually popping up. // user selection; simulates the menu actually popping up.
render_thread_->sink().ClearMessages(); 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() { void LayoutMainFrame() {
...@@ -345,7 +349,7 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest { ...@@ -345,7 +349,7 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
// permanently ignored. // permanently ignored.
if (!ShouldIgnoreAutocompleteOffForPasswordFields()) { if (!ShouldIgnoreAutocompleteOffForPasswordFields()) {
EXPECT_TRUE( EXPECT_TRUE(
password_autofill_agent()->ShowSuggestions(username_element_, false)); password_autofill_agent_->ShowSuggestions(username_element_, false));
EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
AutofillHostMsg_ShowPasswordSuggestions::ID)); AutofillHostMsg_ShowPasswordSuggestions::ID));
...@@ -356,7 +360,8 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest { ...@@ -356,7 +360,8 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
ui::KeyboardCode key_code) { ui::KeyboardCode key_code) {
blink::WebKeyboardEvent key_event; blink::WebKeyboardEvent key_event;
key_event.windowsKeyCode = key_code; 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, void CheckTextFieldsStateForElements(const WebInputElement& username_element,
...@@ -457,10 +462,6 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest { ...@@ -457,10 +462,6 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
render_thread_->sink().ClearMessages(); render_thread_->sink().ClearMessages();
} }
PasswordAutofillAgent* password_autofill_agent() {
return autofill_agent_->password_autofill_agent_;
}
void ExpectFormSubmittedWithPasswords(const std::string& password_value, void ExpectFormSubmittedWithPasswords(const std::string& password_value,
const std::string& new_password_value) { const std::string& new_password_value) {
const IPC::Message* message = const IPC::Message* message =
...@@ -725,16 +726,20 @@ TEST_F(PasswordAutofillAgentTest, WaitUsername) { ...@@ -725,16 +726,20 @@ TEST_F(PasswordAutofillAgentTest, WaitUsername) {
// Autocomplete should happen only when the username textfield is blurred with // Autocomplete should happen only when the username textfield is blurred with
// a full match. // a full match.
username_element_.setValue("a"); username_element_.setValue("a");
autofill_agent_->textFieldDidEndEditing(username_element_); static_cast<blink::WebAutofillClient*>(autofill_agent_)
->textFieldDidEndEditing(username_element_);
CheckTextFieldsState("a", false, std::string(), false); CheckTextFieldsState("a", false, std::string(), false);
username_element_.setValue("al"); username_element_.setValue("al");
autofill_agent_->textFieldDidEndEditing(username_element_); static_cast<blink::WebAutofillClient*>(autofill_agent_)
->textFieldDidEndEditing(username_element_);
CheckTextFieldsState("al", false, std::string(), false); CheckTextFieldsState("al", false, std::string(), false);
username_element_.setValue("alices"); username_element_.setValue("alices");
autofill_agent_->textFieldDidEndEditing(username_element_); static_cast<blink::WebAutofillClient*>(autofill_agent_)
->textFieldDidEndEditing(username_element_);
CheckTextFieldsState("alices", false, std::string(), false); CheckTextFieldsState("alices", false, std::string(), false);
username_element_.setValue(ASCIIToUTF16(kAliceUsername)); username_element_.setValue(ASCIIToUTF16(kAliceUsername));
autofill_agent_->textFieldDidEndEditing(username_element_); static_cast<blink::WebAutofillClient*>(autofill_agent_)
->textFieldDidEndEditing(username_element_);
CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true);
} }
...@@ -1132,13 +1137,13 @@ TEST_F(PasswordAutofillAgentTest, FillSuggestion) { ...@@ -1132,13 +1137,13 @@ TEST_F(PasswordAutofillAgentTest, FillSuggestion) {
// If the password field is not autocompletable, it should not be affected. // If the password field is not autocompletable, it should not be affected.
SetElementReadOnly(password_element_, true); SetElementReadOnly(password_element_, true);
EXPECT_FALSE(password_autofill_->FillSuggestion( EXPECT_FALSE(password_autofill_agent_->FillSuggestion(
username_element_, kAliceUsername, kAlicePassword)); username_element_, kAliceUsername, kAlicePassword));
CheckTextFieldsDOMState(std::string(), false, std::string(), false); CheckTextFieldsDOMState(std::string(), false, std::string(), false);
SetElementReadOnly(password_element_, false); SetElementReadOnly(password_element_, false);
// After filling with the suggestion, both fields should be autocompleted. // 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)); username_element_, kAliceUsername, kAlicePassword));
CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
int username_length = strlen(kAliceUsername); int username_length = strlen(kAliceUsername);
...@@ -1146,7 +1151,7 @@ TEST_F(PasswordAutofillAgentTest, FillSuggestion) { ...@@ -1146,7 +1151,7 @@ TEST_F(PasswordAutofillAgentTest, FillSuggestion) {
// Try Filling with a suggestion with password different from the one that was // Try Filling with a suggestion with password different from the one that was
// initially sent to the renderer. // initially sent to the renderer.
EXPECT_TRUE(password_autofill_->FillSuggestion( EXPECT_TRUE(password_autofill_agent_->FillSuggestion(
username_element_, kBobUsername, kCarolPassword)); username_element_, kBobUsername, kCarolPassword));
CheckTextFieldsDOMState(kBobUsername, true, kCarolPassword, true); CheckTextFieldsDOMState(kBobUsername, true, kCarolPassword, true);
username_length = strlen(kBobUsername); username_length = strlen(kBobUsername);
...@@ -1165,7 +1170,7 @@ TEST_F(PasswordAutofillAgentTest, PreviewSuggestion) { ...@@ -1165,7 +1170,7 @@ TEST_F(PasswordAutofillAgentTest, PreviewSuggestion) {
// If the password field is not autocompletable, it should not be affected. // If the password field is not autocompletable, it should not be affected.
SetElementReadOnly(password_element_, true); SetElementReadOnly(password_element_, true);
EXPECT_FALSE(password_autofill_->PreviewSuggestion( EXPECT_FALSE(password_autofill_agent_->PreviewSuggestion(
username_element_, kAliceUsername, kAlicePassword)); username_element_, kAliceUsername, kAlicePassword));
EXPECT_EQ(std::string(), username_element_.suggestedValue().utf8()); EXPECT_EQ(std::string(), username_element_.suggestedValue().utf8());
EXPECT_FALSE(username_element_.isAutofilled()); EXPECT_FALSE(username_element_.isAutofilled());
...@@ -1175,7 +1180,7 @@ TEST_F(PasswordAutofillAgentTest, PreviewSuggestion) { ...@@ -1175,7 +1180,7 @@ TEST_F(PasswordAutofillAgentTest, PreviewSuggestion) {
// After selecting the suggestion, both fields should be previewed // After selecting the suggestion, both fields should be previewed
// with suggested values. // with suggested values.
EXPECT_TRUE(password_autofill_->PreviewSuggestion( EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
username_element_, kAliceUsername, kAlicePassword)); username_element_, kAliceUsername, kAlicePassword));
EXPECT_EQ( EXPECT_EQ(
kAliceUsername, kAliceUsername,
...@@ -1190,7 +1195,7 @@ TEST_F(PasswordAutofillAgentTest, PreviewSuggestion) { ...@@ -1190,7 +1195,7 @@ TEST_F(PasswordAutofillAgentTest, PreviewSuggestion) {
// Try previewing with a password different from the one that was initially // Try previewing with a password different from the one that was initially
// sent to the renderer. // sent to the renderer.
EXPECT_TRUE(password_autofill_->PreviewSuggestion( EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
username_element_, kBobUsername, kCarolPassword)); username_element_, kBobUsername, kCarolPassword));
EXPECT_EQ( EXPECT_EQ(
kBobUsername, kBobUsername,
...@@ -1217,7 +1222,7 @@ TEST_F(PasswordAutofillAgentTest, PreviewSuggestionSelectionRange) { ...@@ -1217,7 +1222,7 @@ TEST_F(PasswordAutofillAgentTest, PreviewSuggestionSelectionRange) {
fill_data_.wait_for_username = true; fill_data_.wait_for_username = true;
SimulateOnFillPasswordForm(fill_data_); SimulateOnFillPasswordForm(fill_data_);
EXPECT_TRUE(password_autofill_->PreviewSuggestion( EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
username_element_, kAliceUsername, kAlicePassword)); username_element_, kAliceUsername, kAlicePassword));
EXPECT_EQ( EXPECT_EQ(
kAliceUsername, kAliceUsername,
...@@ -1244,11 +1249,11 @@ TEST_F(PasswordAutofillAgentTest, ClearPreviewWithPasswordAutofilled) { ...@@ -1244,11 +1249,11 @@ TEST_F(PasswordAutofillAgentTest, ClearPreviewWithPasswordAutofilled) {
CheckTextFieldsDOMState(std::string(), false, "sec", true); CheckTextFieldsDOMState(std::string(), false, "sec", true);
EXPECT_TRUE(password_autofill_->PreviewSuggestion( EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
username_element_, kAliceUsername, kAlicePassword)); username_element_, kAliceUsername, kAlicePassword));
EXPECT_TRUE(password_autofill_->DidClearAutofillSelection( EXPECT_TRUE(
username_element_)); password_autofill_agent_->DidClearAutofillSelection(username_element_));
EXPECT_TRUE(username_element_.value().isEmpty()); EXPECT_TRUE(username_element_.value().isEmpty());
EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
...@@ -1273,11 +1278,11 @@ TEST_F(PasswordAutofillAgentTest, ClearPreviewWithUsernameAutofilled) { ...@@ -1273,11 +1278,11 @@ TEST_F(PasswordAutofillAgentTest, ClearPreviewWithUsernameAutofilled) {
CheckTextFieldsDOMState("ali", true, std::string(), false); CheckTextFieldsDOMState("ali", true, std::string(), false);
EXPECT_TRUE(password_autofill_->PreviewSuggestion( EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
username_element_, kAliceUsername, kAlicePassword)); username_element_, kAliceUsername, kAlicePassword));
EXPECT_TRUE(password_autofill_->DidClearAutofillSelection( EXPECT_TRUE(
username_element_)); password_autofill_agent_->DidClearAutofillSelection(username_element_));
EXPECT_EQ(ASCIIToUTF16("ali"), username_element_.value()); EXPECT_EQ(ASCIIToUTF16("ali"), username_element_.value());
EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
...@@ -1305,11 +1310,11 @@ TEST_F(PasswordAutofillAgentTest, ...@@ -1305,11 +1310,11 @@ TEST_F(PasswordAutofillAgentTest,
CheckTextFieldsDOMState("ali", true, "sec", true); CheckTextFieldsDOMState("ali", true, "sec", true);
EXPECT_TRUE(password_autofill_->PreviewSuggestion( EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
username_element_, kAliceUsername, kAlicePassword)); username_element_, kAliceUsername, kAlicePassword));
EXPECT_TRUE(password_autofill_->DidClearAutofillSelection( EXPECT_TRUE(
username_element_)); password_autofill_agent_->DidClearAutofillSelection(username_element_));
EXPECT_EQ(ASCIIToUTF16("ali"), username_element_.value()); EXPECT_EQ(ASCIIToUTF16("ali"), username_element_.value());
EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
...@@ -1331,11 +1336,11 @@ TEST_F(PasswordAutofillAgentTest, ...@@ -1331,11 +1336,11 @@ TEST_F(PasswordAutofillAgentTest,
CheckTextFieldsDOMState(std::string(), false, std::string(), false); CheckTextFieldsDOMState(std::string(), false, std::string(), false);
EXPECT_TRUE(password_autofill_->PreviewSuggestion( EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
username_element_, kAliceUsername, kAlicePassword)); username_element_, kAliceUsername, kAlicePassword));
EXPECT_TRUE(password_autofill_->DidClearAutofillSelection( EXPECT_TRUE(
username_element_)); password_autofill_agent_->DidClearAutofillSelection(username_element_));
EXPECT_TRUE(username_element_.value().isEmpty()); EXPECT_TRUE(username_element_.value().isEmpty());
EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
...@@ -1363,7 +1368,7 @@ TEST_F(PasswordAutofillAgentTest, ClearPreviewWithInlineAutocompletedUsername) { ...@@ -1363,7 +1368,7 @@ TEST_F(PasswordAutofillAgentTest, ClearPreviewWithInlineAutocompletedUsername) {
// The selection should have been set to 'lice', the last 4 letters. // The selection should have been set to 'lice', the last 4 letters.
CheckUsernameSelection(1, 5); CheckUsernameSelection(1, 5);
EXPECT_TRUE(password_autofill_->PreviewSuggestion( EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
username_element_, "alicia", "secret")); username_element_, "alicia", "secret"));
EXPECT_EQ( EXPECT_EQ(
"alicia", "alicia",
...@@ -1375,8 +1380,8 @@ TEST_F(PasswordAutofillAgentTest, ClearPreviewWithInlineAutocompletedUsername) { ...@@ -1375,8 +1380,8 @@ TEST_F(PasswordAutofillAgentTest, ClearPreviewWithInlineAutocompletedUsername) {
EXPECT_TRUE(password_element_.isAutofilled()); EXPECT_TRUE(password_element_.isAutofilled());
CheckUsernameSelection(1, 6); CheckUsernameSelection(1, 6);
EXPECT_TRUE(password_autofill_->DidClearAutofillSelection( EXPECT_TRUE(
username_element_)); password_autofill_agent_->DidClearAutofillSelection(username_element_));
EXPECT_EQ(kAliceUsername, username_element_.value().utf8()); EXPECT_EQ(kAliceUsername, username_element_.value().utf8());
EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
...@@ -1401,7 +1406,7 @@ TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Activated) { ...@@ -1401,7 +1406,7 @@ TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Activated) {
// Turn the logging on. // Turn the logging on.
AutofillMsg_SetLoggingState msg_activate(0, true); AutofillMsg_SetLoggingState msg_activate(0, true);
// Up-cast to access OnMessageReceived, which is private in the agent. // 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)); ->OnMessageReceived(msg_activate));
render_thread_->sink().ClearMessages(); render_thread_->sink().ClearMessages();
...@@ -1416,10 +1421,10 @@ TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Deactivated) { ...@@ -1416,10 +1421,10 @@ TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Deactivated) {
// Turn the logging on and then off. // Turn the logging on and then off.
AutofillMsg_SetLoggingState msg_activate(0, /*active=*/true); AutofillMsg_SetLoggingState msg_activate(0, /*active=*/true);
// Up-cast to access OnMessageReceived, which is private in the agent. // 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)); ->OnMessageReceived(msg_activate));
AutofillMsg_SetLoggingState msg_deactivate(0, /*active=*/false); 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)); ->OnMessageReceived(msg_deactivate));
render_thread_->sink().ClearMessages(); render_thread_->sink().ClearMessages();
...@@ -1474,7 +1479,8 @@ TEST_F(PasswordAutofillAgentTest, CredentialsOnClick) { ...@@ -1474,7 +1479,8 @@ TEST_F(PasswordAutofillAgentTest, CredentialsOnClick) {
// Simulate a user clicking on the username element. This should produce a // Simulate a user clicking on the username element. This should produce a
// message with all the usernames. // message with all the usernames.
render_thread_->sink().ClearMessages(); render_thread_->sink().ClearMessages();
autofill_agent_->FormControlElementClicked(username_element_, false); static_cast<PageClickListener*>(autofill_agent_)
->FormControlElementClicked(username_element_, false);
ExpectAllCredentials(); ExpectAllCredentials();
// Now simulate a user typing in an unrecognized username and then // Now simulate a user typing in an unrecognized username and then
...@@ -1482,7 +1488,8 @@ TEST_F(PasswordAutofillAgentTest, CredentialsOnClick) { ...@@ -1482,7 +1488,8 @@ TEST_F(PasswordAutofillAgentTest, CredentialsOnClick) {
// all the usernames. // all the usernames.
SimulateUsernameChange("baz", true); SimulateUsernameChange("baz", true);
render_thread_->sink().ClearMessages(); render_thread_->sink().ClearMessages();
autofill_agent_->FormControlElementClicked(username_element_, true); static_cast<PageClickListener*>(autofill_agent_)
->FormControlElementClicked(username_element_, true);
ExpectAllCredentials(); ExpectAllCredentials();
// Now simulate a user typing in the first letter of the username and then // Now simulate a user typing in the first letter of the username and then
...@@ -1491,7 +1498,8 @@ TEST_F(PasswordAutofillAgentTest, CredentialsOnClick) { ...@@ -1491,7 +1498,8 @@ TEST_F(PasswordAutofillAgentTest, CredentialsOnClick) {
// suggestion list. // suggestion list.
SimulateUsernameChange("a", true); SimulateUsernameChange("a", true);
render_thread_->sink().ClearMessages(); render_thread_->sink().ClearMessages();
autofill_agent_->FormControlElementClicked(username_element_, true); static_cast<PageClickListener*>(autofill_agent_)
->FormControlElementClicked(username_element_, true);
ExpectAllCredentials(); ExpectAllCredentials();
} }
...@@ -1508,7 +1516,7 @@ TEST_F(PasswordAutofillAgentTest, ...@@ -1508,7 +1516,7 @@ TEST_F(PasswordAutofillAgentTest,
// Simulate that the password value was cleared by the site's JavaScript // Simulate that the password value was cleared by the site's JavaScript
// before submit. // before submit.
password_element_.setValue(WebString()); password_element_.setValue(WebString());
static_cast<content::RenderViewObserver*>(password_autofill_agent()) static_cast<content::RenderViewObserver*>(password_autofill_agent_)
->WillSubmitForm(GetMainFrame(), username_element_.form()); ->WillSubmitForm(GetMainFrame(), username_element_.form());
// Observe that the PasswordAutofillAgent still remembered the last non-empty // Observe that the PasswordAutofillAgent still remembered the last non-empty
...@@ -1529,7 +1537,7 @@ TEST_F(PasswordAutofillAgentTest, ...@@ -1529,7 +1537,7 @@ TEST_F(PasswordAutofillAgentTest,
// Simulate that the user actually cleared the password again. // Simulate that the user actually cleared the password again.
SimulateInputChangeForElement( SimulateInputChangeForElement(
"", true, GetMainFrame(), password_element_, true); "", true, GetMainFrame(), password_element_, true);
static_cast<content::RenderViewObserver*>(password_autofill_agent()) static_cast<content::RenderViewObserver*>(password_autofill_agent_)
->WillSubmitForm(GetMainFrame(), username_element_.form()); ->WillSubmitForm(GetMainFrame(), username_element_.form());
// Observe that the PasswordAutofillAgent respects the user having cleared the // Observe that the PasswordAutofillAgent respects the user having cleared the
...@@ -1558,7 +1566,7 @@ TEST_F(PasswordAutofillAgentTest, ...@@ -1558,7 +1566,7 @@ TEST_F(PasswordAutofillAgentTest,
// Simulate that the password value was cleared by the site's JavaScript // Simulate that the password value was cleared by the site's JavaScript
// before submit. // before submit.
password_element_.setValue(WebString()); password_element_.setValue(WebString());
static_cast<content::RenderViewObserver*>(password_autofill_agent()) static_cast<content::RenderViewObserver*>(password_autofill_agent_)
->WillSubmitForm(GetMainFrame(), username_element_.form()); ->WillSubmitForm(GetMainFrame(), username_element_.form());
// Observe that the PasswordAutofillAgent still remembered the last non-empty // Observe that the PasswordAutofillAgent still remembered the last non-empty
......
...@@ -46,7 +46,7 @@ using blink::WebString; ...@@ -46,7 +46,7 @@ using blink::WebString;
using blink::WebURLRequest; using blink::WebURLRequest;
ChromeRenderViewTest::ChromeRenderViewTest() ChromeRenderViewTest::ChromeRenderViewTest()
: password_autofill_(NULL), : password_autofill_agent_(NULL),
password_generation_(NULL), password_generation_(NULL),
autofill_agent_(NULL), autofill_agent_(NULL),
chrome_render_thread_(NULL) { chrome_render_thread_(NULL) {
...@@ -67,10 +67,10 @@ void ChromeRenderViewTest::SetUp() { ...@@ -67,10 +67,10 @@ void ChromeRenderViewTest::SetUp() {
// RenderView doesn't expose its Agent objects, because it has no need to // RenderView doesn't expose its Agent objects, because it has no need to
// store them directly (they're stored as RenderViewObserver*). So just // store them directly (they're stored as RenderViewObserver*). So just
// create another set. // create another set.
password_autofill_ = new autofill::TestPasswordAutofillAgent(view_); password_autofill_agent_ = new autofill::TestPasswordAutofillAgent(view_);
password_generation_ = new autofill::TestPasswordGenerationAgent(view_); password_generation_ = new autofill::TestPasswordGenerationAgent(view_);
autofill_agent_ = autofill_agent_ =
new AutofillAgent(view_, password_autofill_, password_generation_); new AutofillAgent(view_, password_autofill_agent_, password_generation_);
} }
void ChromeRenderViewTest::TearDown() { void ChromeRenderViewTest::TearDown() {
......
...@@ -39,7 +39,7 @@ class ChromeRenderViewTest : public content::RenderViewTest { ...@@ -39,7 +39,7 @@ class ChromeRenderViewTest : public content::RenderViewTest {
scoped_ptr<extensions::DispatcherDelegate> extension_dispatcher_delegate_; scoped_ptr<extensions::DispatcherDelegate> extension_dispatcher_delegate_;
#endif #endif
autofill::TestPasswordAutofillAgent* password_autofill_; autofill::TestPasswordAutofillAgent* password_autofill_agent_;
autofill::TestPasswordGenerationAgent* password_generation_; autofill::TestPasswordGenerationAgent* password_generation_;
autofill::AutofillAgent* autofill_agent_; autofill::AutofillAgent* autofill_agent_;
......
...@@ -230,25 +230,6 @@ class AutofillAgent : public content::RenderViewObserver, ...@@ -230,25 +230,6 @@ class AutofillAgent : public content::RenderViewObserver,
base::WeakPtrFactory<AutofillAgent> weak_ptr_factory_; base::WeakPtrFactory<AutofillAgent> weak_ptr_factory_;
friend class PasswordAutofillAgentTest;
friend class RequestAutocompleteRendererTest;
FRIEND_TEST_ALL_PREFIXES(AutofillRendererTest, FillFormElement);
FRIEND_TEST_ALL_PREFIXES(AutofillRendererTest, SendDynamicForms);
FRIEND_TEST_ALL_PREFIXES(AutofillRendererTest, ShowAutofillWarning);
FRIEND_TEST_ALL_PREFIXES(PasswordAutofillAgentTest, WaitUsername);
FRIEND_TEST_ALL_PREFIXES(PasswordAutofillAgentTest, SuggestionAccept);
FRIEND_TEST_ALL_PREFIXES(PasswordAutofillAgentTest, SuggestionSelect);
FRIEND_TEST_ALL_PREFIXES(
PasswordAutofillAgentTest,
PasswordAutofillTriggersOnChangeEventsWaitForUsername);
FRIEND_TEST_ALL_PREFIXES(PasswordAutofillAgentTest, CredentialsOnClick);
FRIEND_TEST_ALL_PREFIXES(RequestAutocompleteRendererTest,
NoCancelOnMainFrameNavigateAfterDone);
FRIEND_TEST_ALL_PREFIXES(RequestAutocompleteRendererTest,
NoCancelOnSubframeNavigateAfterDone);
FRIEND_TEST_ALL_PREFIXES(RequestAutocompleteRendererTest,
InvokingTwiceOnlyShowsOnce);
DISALLOW_COPY_AND_ASSIGN(AutofillAgent); DISALLOW_COPY_AND_ASSIGN(AutofillAgent);
}; };
......
...@@ -73,8 +73,6 @@ class PasswordAutofillAgent : public content::RenderViewObserver { ...@@ -73,8 +73,6 @@ class PasswordAutofillAgent : public content::RenderViewObserver {
const blink::WebSecurityOrigin& origin); const blink::WebSecurityOrigin& origin);
private: private:
friend class PasswordAutofillAgentTest;
enum OtherPossibleUsernamesUsage { enum OtherPossibleUsernamesUsage {
NOTHING_TO_AUTOFILL, NOTHING_TO_AUTOFILL,
OTHER_POSSIBLE_USERNAMES_ABSENT, OTHER_POSSIBLE_USERNAMES_ABSENT,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment