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

Unified Diff: components/autofill/core/browser/autofill_manager_unittest.cc

Issue 17572015: Begin abstracting sending of IPC from autofill core code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Response to review, add tests Created 7 years, 6 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: components/autofill/core/browser/autofill_manager_unittest.cc
diff --git a/components/autofill/core/browser/autofill_manager_unittest.cc b/components/autofill/core/browser/autofill_manager_unittest.cc
index 57ae9150a1ba54a6754edcdfb2c6f93db43e45d2..1f8caa97317a163154346a8c6b4ee67440b37420 100644
--- a/components/autofill/core/browser/autofill_manager_unittest.cc
+++ b/components/autofill/core/browser/autofill_manager_unittest.cc
@@ -244,41 +244,6 @@ void CreateTestShippingOptionsFormData(FormData* form) {
form->fields.push_back(field);
}
-// Populates |form| with data corresponding to a simple address form.
-// Note that this actually appends fields to the form data, which can be useful
-// for building up more complex test forms.
-void CreateTestAddressFormData(FormData* form) {
- form->name = ASCIIToUTF16("MyForm");
- form->method = ASCIIToUTF16("POST");
- form->origin = GURL("http://myform.com/form.html");
- form->action = GURL("http://myform.com/submit.html");
- form->user_submitted = true;
-
- FormFieldData field;
- test::CreateTestFormField("First Name", "firstname", "", "text", &field);
- form->fields.push_back(field);
- test::CreateTestFormField("Middle Name", "middlename", "", "text", &field);
- form->fields.push_back(field);
- test::CreateTestFormField("Last Name", "lastname", "", "text", &field);
- form->fields.push_back(field);
- test::CreateTestFormField("Address Line 1", "addr1", "", "text", &field);
- form->fields.push_back(field);
- test::CreateTestFormField("Address Line 2", "addr2", "", "text", &field);
- form->fields.push_back(field);
- test::CreateTestFormField("City", "city", "", "text", &field);
- form->fields.push_back(field);
- test::CreateTestFormField("State", "state", "", "text", &field);
- form->fields.push_back(field);
- test::CreateTestFormField("Postal Code", "zipcode", "", "text", &field);
- form->fields.push_back(field);
- test::CreateTestFormField("Country", "country", "", "text", &field);
- form->fields.push_back(field);
- test::CreateTestFormField("Phone Number", "phonenumber", "", "tel", &field);
- form->fields.push_back(field);
- test::CreateTestFormField("Email", "email", "", "email", &field);
- form->fields.push_back(field);
-}
-
// Populates |form| with data corresponding to a simple credit card form.
// Note that this actually appends fields to the form data, which can be useful
// for building up more complex test forms.
@@ -761,6 +726,18 @@ class AutofillManagerTest : public ChromeRenderViewHostTestHarness {
autofill_manager_->OnFillAutofillFormData(query_id, form, field, unique_id);
}
+ void FillAutofillFormDataAndSaveResults(int input_query_id,
blundell 2013/06/25 16:11:04 This was the cleanest approach I found to the test
Ilya Sherman 2013/06/26 22:54:58 nit: Docs, please.
Ilya Sherman 2013/06/26 22:54:58 The approach you're using now seems pretty good to
blundell 2013/06/27 21:58:27 Done.
+ const FormData& input_form,
+ const FormFieldData& input_field,
+ int unique_id,
+ int* response_query_id,
+ FormData* response_data) {
+ EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _)).
+ WillOnce((DoAll(testing::SaveArg<0>(response_query_id),
+ testing::SaveArg<1>(response_data))));
+ FillAutofillFormData(input_query_id, input_form, input_field, unique_id);
+ }
+
int PackGUIDs(const GUIDPair& cc_guid, const GUIDPair& profile_guid) const {
return autofill_manager_->PackGUIDs(cc_guid, profile_guid);
}
@@ -856,7 +833,7 @@ class TestFormStructure : public FormStructure {
// Test that browser asks for all forms when Autocheckout is enabled.
TEST_F(AutofillManagerTest, GetAllForms) {
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
// Enable autocheckout.
autofill_manager_->set_autocheckout_url_prefix("test-prefix");
@@ -871,7 +848,7 @@ TEST_F(AutofillManagerTest, GetAllForms) {
TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
@@ -915,7 +892,7 @@ TEST_F(AutofillManagerTest, AutocheckoutFormsSeen) {
FormData user_supplied;
CreateTestFormWithAutocompleteAttribute(&user_supplied);
FormData address;
- CreateTestAddressFormData(&address);
+ test::CreateTestAddressFormData(&address);
// Push user_supplied before address and observe order changing when
// Autocheckout is not enabled..
@@ -952,7 +929,7 @@ TEST_F(AutofillManagerTest, DynamicFormsSeen) {
FormData user_supplied;
CreateTestFormWithAutocompleteAttribute(&user_supplied);
FormData address;
- CreateTestAddressFormData(&address);
+ test::CreateTestAddressFormData(&address);
autofill_manager_->set_autocheckout_url_prefix("test-prefix");
// Push user_supplied only
@@ -986,7 +963,7 @@ TEST_F(AutofillManagerTest, DynamicFormsSeen) {
TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
@@ -1047,7 +1024,7 @@ TEST_F(AutofillManagerTest, GetProfileSuggestionsUnknownFields) {
TEST_F(AutofillManagerTest, GetProfileSuggestionsWithDuplicates) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
@@ -1093,7 +1070,7 @@ TEST_F(AutofillManagerTest, GetProfileSuggestionsWithDuplicates) {
TEST_F(AutofillManagerTest, GetProfileSuggestionsAutofillDisabledByUser) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
@@ -1110,7 +1087,7 @@ TEST_F(AutofillManagerTest, GetProfileSuggestionsAutofillDisabledByUser) {
TEST_F(AutofillManagerTest, GetProfileSuggestionsMethodGet) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
form.method = ASCIIToUTF16("GET");
std::vector<FormData> forms(1, form);
FormsSeen(forms);
@@ -1428,7 +1405,7 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestionsRepeatedObfuscatedNumber) {
TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
CreateTestCreditCardFormData(&form, true, false);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
@@ -1502,7 +1479,7 @@ TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) {
TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
CreateTestCreditCardFormData(&form, false, false);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
@@ -1569,7 +1546,7 @@ TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) {
TEST_F(AutofillManagerTest, GetCombinedAutofillAndAutocompleteSuggestions) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
@@ -1619,7 +1596,7 @@ TEST_F(AutofillManagerTest, GetCombinedAutofillAndAutocompleteSuggestions) {
TEST_F(AutofillManagerTest, GetFieldSuggestionsWhenFormIsAutofilled) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
@@ -1657,7 +1634,7 @@ TEST_F(AutofillManagerTest, GetFieldSuggestionsWhenFormIsAutofilled) {
TEST_F(AutofillManagerTest, GetFieldSuggestionsForAutocompleteOnly) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
FormFieldData field;
test::CreateTestFormField("Some Field", "somefield", "", "text", &field);
form.fields.push_back(field);
@@ -1699,7 +1676,7 @@ TEST_F(AutofillManagerTest, GetFieldSuggestionsForAutocompleteOnly) {
TEST_F(AutofillManagerTest, GetFieldSuggestionsWithDuplicateValues) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
@@ -1742,7 +1719,7 @@ TEST_F(AutofillManagerTest, GetFieldSuggestionsWithDuplicateValues) {
TEST_F(AutofillManagerTest, GetFieldSuggestionsForMultiValuedProfileUnfilled) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
@@ -1829,7 +1806,7 @@ TEST_F(AutofillManagerTest, GetFieldSuggestionsForMultiValuedProfileUnfilled) {
TEST_F(AutofillManagerTest, GetFieldSuggestionsForMultiValuedProfileFilled) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
@@ -1880,7 +1857,7 @@ TEST_F(AutofillManagerTest, GetFieldSuggestionsForMultiValuedProfileFilled) {
TEST_F(AutofillManagerTest, GetProfileSuggestionsFancyPhone) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
@@ -1933,19 +1910,18 @@ TEST_F(AutofillManagerTest, GetProfileSuggestionsFancyPhone) {
TEST_F(AutofillManagerTest, FillAddressForm) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
GUIDPair guid("00000000-0000-0000-0000-000000000001", 0);
GUIDPair empty(std::string(), 0);
- FillAutofillFormData(kDefaultPageID, form, form.fields[0],
- PackGUIDs(empty, guid));
-
- int page_id = 0;
- FormData results;
- EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results));
- ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false);
+ int response_page_id = 0;
+ FormData response_data;
+ FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0],
+ PackGUIDs(empty, guid), &response_page_id, &response_data);
+ ExpectFilledAddressFormElvis(
+ response_page_id, response_data, kDefaultPageID, false);
}
// Test that we correctly fill an address form from an auxiliary profile.
@@ -1957,7 +1933,7 @@ TEST_F(AutofillManagerTest, FillAddressFormFromAuxiliaryProfile) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
@@ -2093,7 +2069,7 @@ TEST_F(AutofillManagerTest, FillCreditCardFormYearMonth) {
TEST_F(AutofillManagerTest, FillAddressAndCreditCardForm) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
CreateTestCreditCardFormData(&form, true, false);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
@@ -2131,9 +2107,9 @@ TEST_F(AutofillManagerTest, FillAddressAndCreditCardForm) {
TEST_F(AutofillManagerTest, FillFormWithMultipleSections) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
const size_t kAddressFormSize = form.fields.size();
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
for (size_t i = kAddressFormSize; i < form.fields.size(); ++i) {
// Make sure the fields have distinct names.
form.fields[i].name = form.fields[i].name + ASCIIToUTF16("_");
@@ -2363,7 +2339,7 @@ TEST_F(AutofillManagerTest, FillFormWithAuthorSpecifiedSections) {
TEST_F(AutofillManagerTest, FillFormWithMultipleEmails) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
FormFieldData field;
test::CreateTestFormField("Confirm email", "email2", "", "text", &field);
form.fields.push_back(field);
@@ -2393,7 +2369,7 @@ TEST_F(AutofillManagerTest, FillFormWithMultipleEmails) {
TEST_F(AutofillManagerTest, FillAutofilledForm) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
// Mark one of the address fields as autofilled.
form.fields[4].is_autofilled = true;
CreateTestCreditCardFormData(&form, true, false);
@@ -2456,7 +2432,7 @@ TEST_F(AutofillManagerTest, FillAutofilledForm) {
TEST_F(AutofillManagerTest, FillAddressFormWithVariantType) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
@@ -2655,7 +2631,7 @@ TEST_F(AutofillManagerTest, FillPhoneNumber) {
TEST_F(AutofillManagerTest, FormChangesRemoveField) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
// Add a field -- we'll remove it again later.
FormFieldData field;
@@ -2686,7 +2662,7 @@ TEST_F(AutofillManagerTest, FormChangesAddField) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
// Remove the phone field -- we'll add it back later.
std::vector<FormFieldData>::iterator pos =
@@ -2715,7 +2691,7 @@ TEST_F(AutofillManagerTest, FormChangesAddField) {
TEST_F(AutofillManagerTest, FormSubmitted) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
@@ -2753,7 +2729,7 @@ TEST_F(AutofillManagerTest, FormSubmittedAutocompleteEnabled) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
form.method = ASCIIToUTF16("GET");
MockAutocompleteHistoryManager* m = static_cast<
MockAutocompleteHistoryManager*>(
@@ -2775,7 +2751,7 @@ TEST_F(AutofillManagerTest, AutocompleteSuggestionsWhenAutofillDisabled) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
form.method = ASCIIToUTF16("GET");
std::vector<FormData> forms(1, form);
FormsSeen(forms);
@@ -2814,7 +2790,7 @@ TEST_F(AutofillManagerTest, AutocompleteSuggestionsWhenAutofillDisabled) {
TEST_F(AutofillManagerTest, FormSubmittedServerTypes) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
// Simulate having seen this form on page load.
// |form_structure| will be owned by |autofill_manager_|.
@@ -2853,7 +2829,7 @@ TEST_F(AutofillManagerTest, FormSubmittedServerTypes) {
TEST_F(AutofillManagerTest, FormSubmittedWithDifferentFields) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
@@ -2878,7 +2854,7 @@ TEST_F(AutofillManagerTest, FormSubmittedWithDifferentFields) {
TEST_F(AutofillManagerTest, FormSubmittedWithDefaultValues) {
// Set up our form data.
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
form.fields[3].value = ASCIIToUTF16("Enter your address");
// Convert the state field to a <select> popup, to make sure that we only
@@ -3350,7 +3326,7 @@ TEST_F(AutofillManagerTest, TestBubbleShown) {
autofill_manager_->MarkAsFirstPageInAutocheckoutFlow();
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
TestFormStructure* form_structure = new TestFormStructure(form);
AutofillMetrics metrics_logger; // ignored
@@ -3380,7 +3356,7 @@ TEST_F(AutofillManagerTest, TestAutocheckoutBubbleNotShown) {
autofill_manager_->MarkAsFirstPageInAutocheckoutFlow();
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
TestFormStructure* form_structure = new TestFormStructure(form);
AutofillMetrics metrics_logger; // ignored
@@ -3408,7 +3384,7 @@ TEST_F(AutofillManagerTest, TestExternalDelegate) {
autofill_manager_->SetExternalDelegate(&external_delegate);
FormData form;
- CreateTestAddressFormData(&form);
+ test::CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
const FormFieldData& field = form.fields[0];
@@ -3427,7 +3403,7 @@ TEST_F(AutofillManagerTest, DynamicFormsSeenAndIgnored) {
FormData user_supplied;
CreateTestFormWithAutocompleteAttribute(&user_supplied);
FormData address;
- CreateTestAddressFormData(&address);
+ test::CreateTestAddressFormData(&address);
autofill_manager_->set_autocheckout_url_prefix("test-prefix");
// Push address only

Powered by Google App Engine
This is Rietveld 408576698