OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/scoped_ptr.h" | 5 #include "base/scoped_ptr.h" |
6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/autofill/form_structure.h" | 8 #include "chrome/browser/autofill/form_structure.h" |
9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 EXPECT_EQ(ADDRESS_BILLING_LINE1, form_structure->field(2)->heuristic_type()); | 414 EXPECT_EQ(ADDRESS_BILLING_LINE1, form_structure->field(2)->heuristic_type()); |
415 // Address. | 415 // Address. |
416 EXPECT_EQ(ADDRESS_BILLING_LINE2, form_structure->field(3)->heuristic_type()); | 416 EXPECT_EQ(ADDRESS_BILLING_LINE2, form_structure->field(3)->heuristic_type()); |
417 // City. | 417 // City. |
418 EXPECT_EQ(ADDRESS_BILLING_CITY, form_structure->field(4)->heuristic_type()); | 418 EXPECT_EQ(ADDRESS_BILLING_CITY, form_structure->field(4)->heuristic_type()); |
419 // State. | 419 // State. |
420 EXPECT_EQ(ADDRESS_BILLING_STATE, form_structure->field(5)->heuristic_type()); | 420 EXPECT_EQ(ADDRESS_BILLING_STATE, form_structure->field(5)->heuristic_type()); |
421 // Zip. | 421 // Zip. |
422 EXPECT_EQ(ADDRESS_BILLING_ZIP, form_structure->field(6)->heuristic_type()); | 422 EXPECT_EQ(ADDRESS_BILLING_ZIP, form_structure->field(6)->heuristic_type()); |
423 // Country. | 423 // Country. |
424 EXPECT_EQ(ADDRESS_BILLING_COUNTRY, form_structure->field(7)->heuristic_type())
; | 424 EXPECT_EQ(ADDRESS_BILLING_COUNTRY, |
| 425 form_structure->field(7)->heuristic_type()); |
425 // Phone. | 426 // Phone. |
426 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, | 427 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, |
427 form_structure->field(8)->heuristic_type()); | 428 form_structure->field(8)->heuristic_type()); |
428 // Submit. | 429 // Submit. |
429 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(9)->heuristic_type()); | 430 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(9)->heuristic_type()); |
430 } | 431 } |
431 | 432 |
432 TEST(FormStructureTest, HeuristicsSample6) { | 433 TEST(FormStructureTest, HeuristicsSample6) { |
433 scoped_ptr<FormStructure> form_structure; | 434 scoped_ptr<FormStructure> form_structure; |
434 FormData form; | 435 FormData form; |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 // Address Line 1. | 735 // Address Line 1. |
735 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 736 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
736 // Address Line 2. | 737 // Address Line 2. |
737 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 738 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
738 // Address Line 3. | 739 // Address Line 3. |
739 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); | 740 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); |
740 // City. | 741 // City. |
741 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(3)->heuristic_type()); | 742 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(3)->heuristic_type()); |
742 } | 743 } |
743 | 744 |
| 745 // This test verifies that "addressLine1" and "addressLine2" matches heuristics. |
| 746 // This occured in https://www.gorillaclothing.com/. http://crbug.com/52126. |
| 747 TEST(FormStructureTest, BillingAndShippingAddresses) { |
| 748 scoped_ptr<FormStructure> form_structure; |
| 749 FormData form; |
| 750 |
| 751 form.method = ASCIIToUTF16("post"); |
| 752 form.fields.push_back( |
| 753 webkit_glue::FormField(ASCIIToUTF16("Address Line1"), |
| 754 ASCIIToUTF16("shipping.address.addressLine1"), |
| 755 string16(), |
| 756 ASCIIToUTF16("text"), |
| 757 0)); |
| 758 form.fields.push_back( |
| 759 webkit_glue::FormField(ASCIIToUTF16("Address Line2"), |
| 760 ASCIIToUTF16("shipping.address.addressLine2"), |
| 761 string16(), |
| 762 ASCIIToUTF16("text"), |
| 763 0)); |
| 764 form.fields.push_back( |
| 765 webkit_glue::FormField(ASCIIToUTF16("Address Line1"), |
| 766 ASCIIToUTF16("billing.address.addressLine1"), |
| 767 string16(), |
| 768 ASCIIToUTF16("text"), |
| 769 0)); |
| 770 form.fields.push_back( |
| 771 webkit_glue::FormField(ASCIIToUTF16("Address Line2"), |
| 772 ASCIIToUTF16("billing.address.addressLine2"), |
| 773 string16(), |
| 774 ASCIIToUTF16("text"), |
| 775 0)); |
| 776 form_structure.reset(new FormStructure(form)); |
| 777 EXPECT_TRUE(form_structure->IsAutoFillable()); |
| 778 ASSERT_EQ(4U, form_structure->field_count()); |
| 779 ASSERT_EQ(4U, form_structure->autofill_count()); |
| 780 |
| 781 // Address Line 1. |
| 782 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
| 783 // Address Line 2. |
| 784 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
| 785 // Address Line 1. |
| 786 EXPECT_EQ(ADDRESS_BILLING_LINE1, form_structure->field(2)->heuristic_type()); |
| 787 // Address Line 2. |
| 788 EXPECT_EQ(ADDRESS_BILLING_LINE2, form_structure->field(3)->heuristic_type()); |
| 789 } |
| 790 |
| 791 |
744 // This example comes from expedia.com where they use a "Suite" label to | 792 // This example comes from expedia.com where they use a "Suite" label to |
745 // indicate a suite or apartment number. We interpret this as address line 2. | 793 // indicate a suite or apartment number. We interpret this as address line 2. |
746 // And the following "Street address second line" we interpret as address line | 794 // And the following "Street address second line" we interpret as address line |
747 // 3 and discard. | 795 // 3 and discard. |
748 // See http://crbug.com/48197 for details. | 796 // See http://crbug.com/48197 for details. |
749 TEST(FormStructureTest, ThreeAddressLinesExpedia) { | 797 TEST(FormStructureTest, ThreeAddressLinesExpedia) { |
750 scoped_ptr<FormStructure> form_structure; | 798 scoped_ptr<FormStructure> form_structure; |
751 FormData form; | 799 FormData form; |
752 | 800 |
753 form.method = ASCIIToUTF16("post"); | 801 form.method = ASCIIToUTF16("post"); |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1081 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type()); | 1129 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type()); |
1082 // City. Invalid input type. | 1130 // City. Invalid input type. |
1083 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(7)->heuristic_type()); | 1131 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(7)->heuristic_type()); |
1084 // State. Invalid input type. | 1132 // State. Invalid input type. |
1085 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(8)->heuristic_type()); | 1133 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(8)->heuristic_type()); |
1086 // Submit. Invalid input type. | 1134 // Submit. Invalid input type. |
1087 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(9)->heuristic_type()); | 1135 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(9)->heuristic_type()); |
1088 } | 1136 } |
1089 | 1137 |
1090 } // namespace | 1138 } // namespace |
OLD | NEW |