Chromium Code Reviews| Index: chrome/browser/autofill/form_structure_unittest.cc |
| diff --git a/chrome/browser/autofill/form_structure_unittest.cc b/chrome/browser/autofill/form_structure_unittest.cc |
| index 64c8e17c46d07a8480dd903258ae42d320bdc42f..66101bdb8aef745555e69c7b6ebaefc8944f8dae 100644 |
| --- a/chrome/browser/autofill/form_structure_unittest.cc |
| +++ b/chrome/browser/autofill/form_structure_unittest.cc |
| @@ -329,8 +329,8 @@ TEST(FormStructureTest, HeuristicsContactInfo) { |
| EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(7)->heuristic_type()); |
| } |
| -// Verify that we can correctly process the |autocompletetype| attribute. |
| -TEST(FormStructureTest, HeuristicsAutocompletetype) { |
| +// Verify that we can correctly process the |autocomplete| attribute. |
| +TEST(FormStructureTest, HeuristicsAutocompleteAttribute) { |
| scoped_ptr<FormStructure> form_structure; |
| FormData form; |
| form.method = ASCIIToUTF16("post"); |
| @@ -340,17 +340,17 @@ TEST(FormStructureTest, HeuristicsAutocompletetype) { |
| field.label = string16(); |
| field.name = ASCIIToUTF16("field1"); |
| - field.autocomplete_type = ASCIIToUTF16("given-name"); |
| + field.autocomplete_attribute = ASCIIToUTF16("given-name"); |
| form.fields.push_back(field); |
| field.label = string16(); |
| field.name = ASCIIToUTF16("field2"); |
| - field.autocomplete_type = ASCIIToUTF16("surname"); |
| + field.autocomplete_attribute = ASCIIToUTF16("family-name"); |
| form.fields.push_back(field); |
| field.label = string16(); |
| field.name = ASCIIToUTF16("field3"); |
| - field.autocomplete_type = ASCIIToUTF16("email"); |
| + field.autocomplete_attribute = ASCIIToUTF16("email"); |
| form.fields.push_back(field); |
| form_structure.reset(new FormStructure(form)); |
| @@ -368,7 +368,7 @@ TEST(FormStructureTest, HeuristicsAutocompletetype) { |
| // Verify that we can correctly process the |autocompletetype| attribute for |
| // phone number types (especially phone prefixes and suffixes). |
| -TEST(FormStructureTest, HeuristicsAutocompletetypePhones) { |
| +TEST(FormStructureTest, HeuristicsAutocompleteAttributePhoneTypes) { |
| scoped_ptr<FormStructure> form_structure; |
| FormData form; |
| form.method = ASCIIToUTF16("post"); |
| @@ -378,17 +378,17 @@ TEST(FormStructureTest, HeuristicsAutocompletetypePhones) { |
| field.label = string16(); |
| field.name = ASCIIToUTF16("field1"); |
| - field.autocomplete_type = ASCIIToUTF16("phone-local"); |
| + field.autocomplete_attribute = ASCIIToUTF16("tel-local"); |
| form.fields.push_back(field); |
| field.label = string16(); |
| field.name = ASCIIToUTF16("field2"); |
| - field.autocomplete_type = ASCIIToUTF16("phone-local-prefix"); |
| + field.autocomplete_attribute = ASCIIToUTF16("tel-local-prefix"); |
| form.fields.push_back(field); |
| field.label = string16(); |
| field.name = ASCIIToUTF16("field3"); |
| - field.autocomplete_type = ASCIIToUTF16("phone-local-suffix"); |
| + field.autocomplete_attribute = ASCIIToUTF16("tel-local-suffix"); |
| form.fields.push_back(field); |
| form_structure.reset(new FormStructure(form)); |
| @@ -411,7 +411,7 @@ TEST(FormStructureTest, HeuristicsAutocompletetypePhones) { |
| // If at least one field includes the |autocompletetype| attribute, we should |
|
Dan Beam
2012/10/19 00:12:44
|autocompletetype| -> |autocomplete| probably, rig
Ilya Sherman
2012/10/19 04:19:32
Done.
|
| // not try to apply any other heuristics. |
| -TEST(FormStructureTest, AutocompletetypeOverridesOtherHeuristics) { |
| +TEST(FormStructureTest, AutocompleteAttributeOverridesOtherHeuristics) { |
| scoped_ptr<FormStructure> form_structure; |
| FormData form; |
| form.method = ASCIIToUTF16("post"); |
| @@ -445,7 +445,7 @@ TEST(FormStructureTest, AutocompletetypeOverridesOtherHeuristics) { |
| EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); |
| // Now update the first form field to include an 'autocompletetype' attribute. |
| - form.fields.front().autocomplete_type = ASCIIToUTF16("x-other"); |
| + form.fields.front().autocomplete_attribute = ASCIIToUTF16("x-other"); |
| form_structure.reset(new FormStructure(form)); |
| form_structure->DetermineHeuristicTypes(); |
| EXPECT_FALSE(form_structure->IsAutofillable(true)); |
| @@ -461,7 +461,7 @@ TEST(FormStructureTest, AutocompletetypeOverridesOtherHeuristics) { |
| // Verify that we can correctly process sections listed in the |autocomplete| |
| // attribute. |
| -TEST(FormStructureTest, HeuristicsAutocompletetypeWithSections) { |
| +TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSections) { |
| scoped_ptr<FormStructure> form_structure; |
| FormData form; |
| form.method = ASCIIToUTF16("post"); |
| @@ -469,96 +469,50 @@ TEST(FormStructureTest, HeuristicsAutocompletetypeWithSections) { |
| FormFieldData field; |
| field.form_control_type = ASCIIToUTF16("text"); |
| - // We expect "shipping" and "billing" to be the most common sections. |
| + // Some fields will have no section specified. These fall into the default |
| + // section, with an empty name. |
| field.label = string16(); |
| field.name = ASCIIToUTF16("field1"); |
| - field.autocomplete_type = ASCIIToUTF16("section-shipping given-name"); |
| + field.autocomplete_attribute = ASCIIToUTF16("given-name"); |
| form.fields.push_back(field); |
| - // Some field will have no section specified. These fall into the default |
| - // section, with an empty name. |
| + // We allow arbitrary section names. |
| field.label = string16(); |
| field.name = ASCIIToUTF16("field2"); |
| - field.autocomplete_type = ASCIIToUTF16("surname"); |
| + field.autocomplete_attribute = ASCIIToUTF16("section-foo family-name"); |
| form.fields.push_back(field); |
| - // We allow arbitrary section names. |
| + // "shipping" and "billing" are special section tokens that don't require the |
| + // "section-" prefix. |
| field.label = string16(); |
| field.name = ASCIIToUTF16("field3"); |
| - field.autocomplete_type = ASCIIToUTF16("section-foo address-line1"); |
| + field.autocomplete_attribute = ASCIIToUTF16("shipping address-line1"); |
| form.fields.push_back(field); |
| - // Specifying "section-" is equivalent to not specifying a section. |
| + // "shipping" and "billing" can be combined with other section names. |
| field.label = string16(); |
| field.name = ASCIIToUTF16("field4"); |
| - field.autocomplete_type = ASCIIToUTF16("section- address-line2"); |
| + field.autocomplete_attribute = |
| + ASCIIToUTF16("section-foo billing address-line2"); |
| form.fields.push_back(field); |
| - // We don't do anything clever to try to coalesce sections; it's up to site |
| - // authors to avoid typos. |
| + // Specifying "section-" is equivalent to not specifying a section. |
| field.label = string16(); |
| field.name = ASCIIToUTF16("field5"); |
| - field.autocomplete_type = ASCIIToUTF16("section--shipping locality"); |
| + field.autocomplete_attribute = ASCIIToUTF16("section- locality"); |
| form.fields.push_back(field); |
| - // Credit card fields are implicitly in a separate section from other fields. |
| + // We don't do anything clever to try to coalesce sections; it's up to site |
| + // authors to avoid typos. |
| field.label = string16(); |
| field.name = ASCIIToUTF16("field6"); |
| - field.autocomplete_type = ASCIIToUTF16("section-shipping cc-number"); |
| - form.fields.push_back(field); |
| - |
| - form_structure.reset(new FormStructure(form)); |
| - form_structure->DetermineHeuristicTypes(); |
| - EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| - |
| - // Expect the correct number of fields. |
| - ASSERT_EQ(6U, form_structure->field_count()); |
| - ASSERT_EQ(6U, form_structure->autofill_count()); |
| - |
| - EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
| - EXPECT_EQ(ASCIIToUTF16("shipping-default"), |
| - form_structure->field(0)->section()); |
| - EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); |
| - EXPECT_EQ(ASCIIToUTF16("-default"), form_structure->field(1)->section()); |
| - EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(2)->heuristic_type()); |
| - EXPECT_EQ(ASCIIToUTF16("foo-default"), form_structure->field(2)->section()); |
| - EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(3)->heuristic_type()); |
| - EXPECT_EQ(ASCIIToUTF16("-default"), form_structure->field(3)->section()); |
| - EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(4)->heuristic_type()); |
| - EXPECT_EQ(ASCIIToUTF16("-shipping-default"), |
| - form_structure->field(4)->section()); |
| - EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(5)->heuristic_type()); |
| - EXPECT_EQ(ASCIIToUTF16("shipping-cc"), form_structure->field(5)->section()); |
| -} |
| - |
| -// Verify that we can correctly process fallback types listed in the |
| -// |autocompletetype| attribute. |
| -TEST(FormStructureTest, HeuristicsAutocompletetypeWithFallbacks) { |
| - scoped_ptr<FormStructure> form_structure; |
| - FormData form; |
| - form.method = ASCIIToUTF16("post"); |
| - |
| - FormFieldData field; |
| - field.form_control_type = ASCIIToUTF16("text"); |
| - |
| - // Skip over any sections and "x"-prefixed types. |
| - field.label = string16(); |
| - field.name = ASCIIToUTF16("field1"); |
| - field.autocomplete_type = |
| - ASCIIToUTF16("section-full-name x-given-name-initial given-name"); |
| - form.fields.push_back(field); |
| - |
| - // Stop processing once we see a known type. |
| - field.label = string16(); |
| - field.name = ASCIIToUTF16("field2"); |
| - field.autocomplete_type = ASCIIToUTF16("section-full-name surname full-name"); |
| + field.autocomplete_attribute = ASCIIToUTF16("section--foo region"); |
| form.fields.push_back(field); |
| - // Skip over unknown types even if they are not prefixed with "x-". |
| + // Credit card fields are implicitly in a separate section from other fields. |
| field.label = string16(); |
| - field.name = ASCIIToUTF16("field3"); |
| - field.autocomplete_type = |
| - ASCIIToUTF16("section-shipping mobile-phone-full phone-full"); |
| + field.name = ASCIIToUTF16("field7"); |
| + field.autocomplete_attribute = ASCIIToUTF16("section-foo cc-number"); |
| form.fields.push_back(field); |
| form_structure.reset(new FormStructure(form)); |
| @@ -566,19 +520,30 @@ TEST(FormStructureTest, HeuristicsAutocompletetypeWithFallbacks) { |
| EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| // Expect the correct number of fields. |
| - ASSERT_EQ(3U, form_structure->field_count()); |
| - ASSERT_EQ(3U, form_structure->autofill_count()); |
| + ASSERT_EQ(7U, form_structure->field_count()); |
| + EXPECT_EQ(7U, form_structure->autofill_count()); |
| EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
| - EXPECT_EQ(ASCIIToUTF16("full-name-default"), |
| + EXPECT_EQ(ASCIIToUTF16("-default-default"), |
| form_structure->field(0)->section()); |
| EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); |
| - EXPECT_EQ(ASCIIToUTF16("full-name-default"), |
| + EXPECT_EQ(ASCIIToUTF16("foo-default-default"), |
| form_structure->field(1)->section()); |
| - EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, |
| - form_structure->field(2)->heuristic_type()); |
| - EXPECT_EQ(ASCIIToUTF16("shipping-default"), |
| + EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(2)->heuristic_type()); |
| + EXPECT_EQ(ASCIIToUTF16("-shipping-default"), |
| form_structure->field(2)->section()); |
| + EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(3)->heuristic_type()); |
| + EXPECT_EQ(ASCIIToUTF16("foo-billing-default"), |
| + form_structure->field(3)->section()); |
| + EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(4)->heuristic_type()); |
| + EXPECT_EQ(ASCIIToUTF16("-default-default"), |
| + form_structure->field(4)->section()); |
| + EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(5)->heuristic_type()); |
| + EXPECT_EQ(ASCIIToUTF16("-foo-default-default"), |
| + form_structure->field(5)->section()); |
| + EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(6)->heuristic_type()); |
| + EXPECT_EQ(ASCIIToUTF16("foo-default-cc"), |
| + form_structure->field(6)->section()); |
| } |
| TEST(FormStructureTest, HeuristicsSample8) { |