OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/autofill/core/browser/form_structure.h" | 5 #include "components/autofill/core/browser/form_structure.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "components/autofill/content/browser/autocheckout_page_meta_data.h" | 10 #include "components/autofill/content/browser/autocheckout_page_meta_data.h" |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 // |autocomplete| attribute. | 666 // |autocomplete| attribute. |
667 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSectionsRepeated) { | 667 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSectionsRepeated) { |
668 FormData form; | 668 FormData form; |
669 form.method = ASCIIToUTF16("post"); | 669 form.method = ASCIIToUTF16("post"); |
670 | 670 |
671 FormFieldData field; | 671 FormFieldData field; |
672 field.form_control_type = "text"; | 672 field.form_control_type = "text"; |
673 | 673 |
674 field.autocomplete_attribute = "section-foo email"; | 674 field.autocomplete_attribute = "section-foo email"; |
675 form.fields.push_back(field); | 675 form.fields.push_back(field); |
676 field.autocomplete_attribute = "section-foo street-address"; | 676 field.autocomplete_attribute = "section-foo address-line1"; |
677 form.fields.push_back(field); | 677 form.fields.push_back(field); |
678 | 678 |
679 FormStructure form_structure(form, std::string()); | 679 FormStructure form_structure(form, std::string()); |
680 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 680 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
681 | 681 |
682 // Expect the correct number of fields. | 682 // Expect the correct number of fields. |
683 ASSERT_EQ(2U, form_structure.field_count()); | 683 ASSERT_EQ(2U, form_structure.field_count()); |
684 EXPECT_EQ(2U, form_structure.autofill_count()); | 684 EXPECT_EQ(2U, form_structure.autofill_count()); |
685 | 685 |
686 // All of the fields in this form should be parsed as belonging to the same | 686 // All of the fields in this form should be parsed as belonging to the same |
687 // section. | 687 // section. |
688 std::set<std::string> section_names; | 688 std::set<std::string> section_names; |
689 for (size_t i = 0; i < 2; ++i) { | 689 for (size_t i = 0; i < 2; ++i) { |
690 section_names.insert(form_structure.field(i)->section()); | 690 section_names.insert(form_structure.field(i)->section()); |
691 } | 691 } |
692 EXPECT_EQ(1U, section_names.size()); | 692 EXPECT_EQ(1U, section_names.size()); |
693 } | 693 } |
694 | 694 |
695 // Verify that we do not override the author-specified sections from a form with | 695 // Verify that we do not override the author-specified sections from a form with |
696 // local heuristics. | 696 // local heuristics. |
697 TEST(FormStructureTest, HeuristicsDontOverrideAutocompleteAttributeSections) { | 697 TEST(FormStructureTest, HeuristicsDontOverrideAutocompleteAttributeSections) { |
698 FormData form; | 698 FormData form; |
699 form.method = ASCIIToUTF16("post"); | 699 form.method = ASCIIToUTF16("post"); |
700 | 700 |
701 FormFieldData field; | 701 FormFieldData field; |
702 field.form_control_type = "text"; | 702 field.form_control_type = "text"; |
703 | 703 |
704 field.name = ASCIIToUTF16("one"); | 704 field.name = ASCIIToUTF16("one"); |
705 field.autocomplete_attribute = "street-address"; | 705 field.autocomplete_attribute = "address-line1"; |
706 form.fields.push_back(field); | 706 form.fields.push_back(field); |
707 field.name = base::string16(); | 707 field.name = base::string16(); |
708 field.autocomplete_attribute = "section-foo email"; | 708 field.autocomplete_attribute = "section-foo email"; |
709 form.fields.push_back(field); | 709 form.fields.push_back(field); |
710 field.name = base::string16(); | 710 field.name = base::string16(); |
711 field.autocomplete_attribute = "name"; | 711 field.autocomplete_attribute = "name"; |
712 form.fields.push_back(field); | 712 form.fields.push_back(field); |
713 field.name = ASCIIToUTF16("two"); | 713 field.name = ASCIIToUTF16("two"); |
714 field.autocomplete_attribute = "street-address"; | 714 field.autocomplete_attribute = "address-line1"; |
715 form.fields.push_back(field); | 715 form.fields.push_back(field); |
716 | 716 |
717 FormStructure form_structure(form, std::string()); | 717 FormStructure form_structure(form, std::string()); |
718 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 718 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
719 | 719 |
720 // Expect the correct number of fields. | 720 // Expect the correct number of fields. |
721 ASSERT_EQ(4U, form_structure.field_count()); | 721 ASSERT_EQ(4U, form_structure.field_count()); |
722 EXPECT_EQ(4U, form_structure.autofill_count()); | 722 EXPECT_EQ(4U, form_structure.autofill_count()); |
723 | 723 |
724 // Normally, the two separate address fields would cause us to detect two | 724 // Normally, the two separate address fields would cause us to detect two |
(...skipping 1709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2434 "<autofillqueryresponse><field autofilltype=\"3\" />" | 2434 "<autofillqueryresponse><field autofilltype=\"3\" />" |
2435 "<field autofilltype=\"9\" /></autofillqueryresponse>"; | 2435 "<field autofilltype=\"9\" /></autofillqueryresponse>"; |
2436 FormStructure::ParseQueryResponse(kServerResponse, forms.get(), | 2436 FormStructure::ParseQueryResponse(kServerResponse, forms.get(), |
2437 &page_meta_data, TestAutofillMetrics()); | 2437 &page_meta_data, TestAutofillMetrics()); |
2438 ASSERT_EQ(NAME_FIRST, forms[0]->field(0)->server_type()); | 2438 ASSERT_EQ(NAME_FIRST, forms[0]->field(0)->server_type()); |
2439 ASSERT_EQ(NO_SERVER_DATA, forms[0]->field(1)->server_type()); | 2439 ASSERT_EQ(NO_SERVER_DATA, forms[0]->field(1)->server_type()); |
2440 ASSERT_EQ(EMAIL_ADDRESS, forms[0]->field(2)->server_type()); | 2440 ASSERT_EQ(EMAIL_ADDRESS, forms[0]->field(2)->server_type()); |
2441 } | 2441 } |
2442 | 2442 |
2443 } // namespace autofill | 2443 } // namespace autofill |
OLD | NEW |