OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/guid.h" | 6 #include "base/guid.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 | 505 |
506 // |a| is a subset of |b|. | 506 // |a| is a subset of |b|. |
507 a.reset(new AutofillProfile); | 507 a.reset(new AutofillProfile); |
508 b.reset(new AutofillProfile); | 508 b.reset(new AutofillProfile); |
509 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson", | 509 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson", |
510 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, | 510 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
511 NULL); | 511 NULL); |
512 autofill_test::SetProfileInfo(b.get(), "Thomas", NULL, "Jefferson", | 512 autofill_test::SetProfileInfo(b.get(), "Thomas", NULL, "Jefferson", |
513 "declaration_guy@gmail.com", "United States Government", "Monticello", | 513 "declaration_guy@gmail.com", "United States Government", "Monticello", |
514 NULL, "Charlottesville", "Virginia", "22902", NULL, NULL); | 514 NULL, "Charlottesville", "Virginia", "22902", NULL, NULL); |
515 EXPECT_TRUE(a->IsSubsetOf(*b)); | 515 EXPECT_TRUE(a->IsSubsetOf(*b, "en-US")); |
516 | 516 |
517 // |b| is not a subset of |a|. | 517 // |b| is not a subset of |a|. |
518 EXPECT_FALSE(b->IsSubsetOf(*a)); | 518 EXPECT_FALSE(b->IsSubsetOf(*a, "en-US")); |
519 | 519 |
520 // |a| is a subset of |a|. | 520 // |a| is a subset of |a|. |
521 EXPECT_TRUE(a->IsSubsetOf(*a)); | 521 EXPECT_TRUE(a->IsSubsetOf(*a, "en-US")); |
522 | 522 |
523 // One field in |b| is different. | 523 // One field in |b| is different. |
524 a.reset(new AutofillProfile); | 524 a.reset(new AutofillProfile); |
525 b.reset(new AutofillProfile); | 525 b.reset(new AutofillProfile); |
526 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson", | 526 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson", |
527 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, | 527 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
528 NULL); | 528 NULL); |
529 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Adams", | 529 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Adams", |
530 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, | 530 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
531 NULL); | 531 NULL); |
532 EXPECT_FALSE(a->IsSubsetOf(*b)); | 532 EXPECT_FALSE(a->IsSubsetOf(*b, "en-US")); |
533 } | 533 } |
534 | 534 |
535 TEST(AutofillProfileTest, AssignmentOperator) { | 535 TEST(AutofillProfileTest, AssignmentOperator) { |
536 AutofillProfile a, b; | 536 AutofillProfile a, b; |
537 | 537 |
538 // Result of assignment should be logically equal to the original profile. | 538 // Result of assignment should be logically equal to the original profile. |
539 autofill_test::SetProfileInfo(&a, "Marion", "Mitchell", "Morrison", | 539 autofill_test::SetProfileInfo(&a, "Marion", "Mitchell", "Morrison", |
540 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", | 540 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
541 "Hollywood", "CA", "91601", "US", | 541 "Hollywood", "CA", "91601", "US", |
542 "12345678910"); | 542 "12345678910"); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 options[i] = ASCIIToUTF16(kCountries[i]); | 732 options[i] = ASCIIToUTF16(kCountries[i]); |
733 } | 733 } |
734 | 734 |
735 FormFieldData field; | 735 FormFieldData field; |
736 field.form_control_type = "select-one"; | 736 field.form_control_type = "select-one"; |
737 field.option_values = options; | 737 field.option_values = options; |
738 field.option_contents = options; | 738 field.option_contents = options; |
739 | 739 |
740 AutofillProfile profile; | 740 AutofillProfile profile; |
741 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CA")); | 741 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CA")); |
742 profile.FillSelectControl(ADDRESS_HOME_COUNTRY, &field); | 742 profile.FillSelectControl(ADDRESS_HOME_COUNTRY, "en-US", &field); |
743 EXPECT_EQ(ASCIIToUTF16("Canada"), field.value); | 743 EXPECT_EQ(ASCIIToUTF16("Canada"), field.value); |
744 } | 744 } |
745 | 745 |
746 TEST(AutofillProfileTest, AddressCountryAbbrev) { | 746 TEST(AutofillProfileTest, AddressCountryAbbrev) { |
747 const char* const kCountries[] = { | 747 const char* const kCountries[] = { |
748 "AL", "CA" | 748 "AL", "CA" |
749 }; | 749 }; |
750 std::vector<string16> options(arraysize(kCountries)); | 750 std::vector<string16> options(arraysize(kCountries)); |
751 for (size_t i = 0; i < arraysize(kCountries); ++i) { | 751 for (size_t i = 0; i < arraysize(kCountries); ++i) { |
752 options[i] = ASCIIToUTF16(kCountries[i]); | 752 options[i] = ASCIIToUTF16(kCountries[i]); |
753 } | 753 } |
754 | 754 |
755 FormFieldData field; | 755 FormFieldData field; |
756 field.form_control_type = "select-one"; | 756 field.form_control_type = "select-one"; |
757 field.option_values = options; | 757 field.option_values = options; |
758 field.option_contents = options; | 758 field.option_contents = options; |
759 | 759 |
760 AutofillProfile profile; | 760 AutofillProfile profile; |
761 profile.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Canada"), "en-US"); | 761 profile.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Canada"), "en-US"); |
762 profile.FillSelectControl(ADDRESS_HOME_COUNTRY, &field); | 762 profile.FillSelectControl(ADDRESS_HOME_COUNTRY, "en-US", &field); |
763 EXPECT_EQ(ASCIIToUTF16("CA"), field.value); | 763 EXPECT_EQ(ASCIIToUTF16("CA"), field.value); |
764 } | 764 } |
765 | 765 |
766 TEST(AutofillProfileTest, AddressStateFull) { | 766 TEST(AutofillProfileTest, AddressStateFull) { |
767 const char* const kStates[] = { | 767 const char* const kStates[] = { |
768 "Alabama", "California" | 768 "Alabama", "California" |
769 }; | 769 }; |
770 std::vector<string16> options(arraysize(kStates)); | 770 std::vector<string16> options(arraysize(kStates)); |
771 for (size_t i = 0; i < arraysize(kStates); ++i) { | 771 for (size_t i = 0; i < arraysize(kStates); ++i) { |
772 options[i] = ASCIIToUTF16(kStates[i]); | 772 options[i] = ASCIIToUTF16(kStates[i]); |
773 } | 773 } |
774 | 774 |
775 FormFieldData field; | 775 FormFieldData field; |
776 field.form_control_type = "select-one"; | 776 field.form_control_type = "select-one"; |
777 field.option_values = options; | 777 field.option_values = options; |
778 field.option_contents = options; | 778 field.option_contents = options; |
779 | 779 |
780 AutofillProfile profile; | 780 AutofillProfile profile; |
781 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); | 781 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); |
782 profile.FillSelectControl(ADDRESS_HOME_STATE, &field); | 782 profile.FillSelectControl(ADDRESS_HOME_STATE, "en-US", &field); |
783 EXPECT_EQ(ASCIIToUTF16("California"), field.value); | 783 EXPECT_EQ(ASCIIToUTF16("California"), field.value); |
784 } | 784 } |
785 | 785 |
786 TEST(AutofillProfileTest, AddressStateAbbrev) { | 786 TEST(AutofillProfileTest, AddressStateAbbrev) { |
787 const char* const kStates[] = { | 787 const char* const kStates[] = { |
788 "AL", "CA" | 788 "AL", "CA" |
789 }; | 789 }; |
790 std::vector<string16> options(arraysize(kStates)); | 790 std::vector<string16> options(arraysize(kStates)); |
791 for (size_t i = 0; i < arraysize(kStates); ++i) { | 791 for (size_t i = 0; i < arraysize(kStates); ++i) { |
792 options[i] = ASCIIToUTF16(kStates[i]); | 792 options[i] = ASCIIToUTF16(kStates[i]); |
793 } | 793 } |
794 | 794 |
795 FormFieldData field; | 795 FormFieldData field; |
796 field.form_control_type = "select-one"; | 796 field.form_control_type = "select-one"; |
797 field.option_values = options; | 797 field.option_values = options; |
798 field.option_contents = options; | 798 field.option_contents = options; |
799 | 799 |
800 AutofillProfile profile; | 800 AutofillProfile profile; |
801 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); | 801 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); |
802 profile.FillSelectControl(ADDRESS_HOME_STATE, &field); | 802 profile.FillSelectControl(ADDRESS_HOME_STATE, "en-US", &field); |
803 EXPECT_EQ(ASCIIToUTF16("CA"), field.value); | 803 EXPECT_EQ(ASCIIToUTF16("CA"), field.value); |
804 } | 804 } |
805 | 805 |
806 TEST(AutofillProfileTest, FillByValue) { | 806 TEST(AutofillProfileTest, FillByValue) { |
807 const char* const kStates[] = { | 807 const char* const kStates[] = { |
808 "Alabama", "California" | 808 "Alabama", "California" |
809 }; | 809 }; |
810 std::vector<string16> values(arraysize(kStates)); | 810 std::vector<string16> values(arraysize(kStates)); |
811 std::vector<string16> contents(arraysize(kStates)); | 811 std::vector<string16> contents(arraysize(kStates)); |
812 for (unsigned int i = 0; i < arraysize(kStates); ++i) { | 812 for (unsigned int i = 0; i < arraysize(kStates); ++i) { |
813 values[i] = ASCIIToUTF16(kStates[i]); | 813 values[i] = ASCIIToUTF16(kStates[i]); |
814 contents[i] = ASCIIToUTF16(base::StringPrintf("%u", i)); | 814 contents[i] = ASCIIToUTF16(base::StringPrintf("%u", i)); |
815 } | 815 } |
816 | 816 |
817 FormFieldData field; | 817 FormFieldData field; |
818 field.form_control_type = "select-one"; | 818 field.form_control_type = "select-one"; |
819 field.option_values = values; | 819 field.option_values = values; |
820 field.option_contents = contents; | 820 field.option_contents = contents; |
821 | 821 |
822 AutofillProfile profile; | 822 AutofillProfile profile; |
823 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); | 823 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); |
824 profile.FillSelectControl(ADDRESS_HOME_STATE, &field); | 824 profile.FillSelectControl(ADDRESS_HOME_STATE, "en-US", &field); |
825 EXPECT_EQ(ASCIIToUTF16("California"), field.value); | 825 EXPECT_EQ(ASCIIToUTF16("California"), field.value); |
826 } | 826 } |
827 | 827 |
828 TEST(AutofillProfileTest, FillByContents) { | 828 TEST(AutofillProfileTest, FillByContents) { |
829 const char* const kStates[] = { | 829 const char* const kStates[] = { |
830 "Alabama", "California" | 830 "Alabama", "California" |
831 }; | 831 }; |
832 std::vector<string16> values(arraysize(kStates)); | 832 std::vector<string16> values(arraysize(kStates)); |
833 std::vector<string16> contents(arraysize(kStates)); | 833 std::vector<string16> contents(arraysize(kStates)); |
834 for (unsigned int i = 0; i < arraysize(kStates); ++i) { | 834 for (unsigned int i = 0; i < arraysize(kStates); ++i) { |
835 values[i] = ASCIIToUTF16(base::StringPrintf("%u", i + 1)); | 835 values[i] = ASCIIToUTF16(base::StringPrintf("%u", i + 1)); |
836 contents[i] = ASCIIToUTF16(kStates[i]); | 836 contents[i] = ASCIIToUTF16(kStates[i]); |
837 } | 837 } |
838 | 838 |
839 FormFieldData field; | 839 FormFieldData field; |
840 field.form_control_type = "select-one"; | 840 field.form_control_type = "select-one"; |
841 field.option_values = values; | 841 field.option_values = values; |
842 field.option_contents = contents; | 842 field.option_contents = contents; |
843 | 843 |
844 AutofillProfile profile; | 844 AutofillProfile profile; |
845 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); | 845 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); |
846 profile.FillSelectControl(ADDRESS_HOME_STATE, &field); | 846 profile.FillSelectControl(ADDRESS_HOME_STATE, "en-US", &field); |
847 EXPECT_EQ(ASCIIToUTF16("2"), field.value); | 847 EXPECT_EQ(ASCIIToUTF16("2"), field.value); |
848 } | 848 } |
OLD | NEW |