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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 options[i] = ASCIIToUTF16(kCountries[i]); | 724 options[i] = ASCIIToUTF16(kCountries[i]); |
725 } | 725 } |
726 | 726 |
727 FormFieldData field; | 727 FormFieldData field; |
728 field.form_control_type = "select-one"; | 728 field.form_control_type = "select-one"; |
729 field.option_values = options; | 729 field.option_values = options; |
730 field.option_contents = options; | 730 field.option_contents = options; |
731 | 731 |
732 AutofillProfile profile; | 732 AutofillProfile profile; |
733 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CA")); | 733 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CA")); |
734 profile.FillSelectControl(ADDRESS_HOME_COUNTRY, &field); | 734 profile.FillSelectControl(ADDRESS_HOME_COUNTRY, "en-US", &field); |
735 EXPECT_EQ(ASCIIToUTF16("Canada"), field.value); | 735 EXPECT_EQ(ASCIIToUTF16("Canada"), field.value); |
736 } | 736 } |
737 | 737 |
738 TEST(AutofillProfileTest, AddressCountryAbbrev) { | 738 TEST(AutofillProfileTest, AddressCountryAbbrev) { |
739 const char* const kCountries[] = { | 739 const char* const kCountries[] = { |
740 "AL", "CA" | 740 "AL", "CA" |
741 }; | 741 }; |
742 std::vector<string16> options(arraysize(kCountries)); | 742 std::vector<string16> options(arraysize(kCountries)); |
743 for (size_t i = 0; i < arraysize(kCountries); ++i) { | 743 for (size_t i = 0; i < arraysize(kCountries); ++i) { |
744 options[i] = ASCIIToUTF16(kCountries[i]); | 744 options[i] = ASCIIToUTF16(kCountries[i]); |
745 } | 745 } |
746 | 746 |
747 FormFieldData field; | 747 FormFieldData field; |
748 field.form_control_type = "select-one"; | 748 field.form_control_type = "select-one"; |
749 field.option_values = options; | 749 field.option_values = options; |
750 field.option_contents = options; | 750 field.option_contents = options; |
751 | 751 |
752 AutofillProfile profile; | 752 AutofillProfile profile; |
753 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CA")); | 753 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CA")); |
754 profile.FillSelectControl(ADDRESS_HOME_COUNTRY, &field); | 754 profile.FillSelectControl(ADDRESS_HOME_COUNTRY, "en-US", &field); |
755 EXPECT_EQ(ASCIIToUTF16("CA"), field.value); | 755 EXPECT_EQ(ASCIIToUTF16("CA"), field.value); |
756 } | 756 } |
757 | 757 |
758 TEST(AutofillProfileTest, AddressStateFull) { | 758 TEST(AutofillProfileTest, AddressStateFull) { |
759 const char* const kStates[] = { | 759 const char* const kStates[] = { |
760 "Alabama", "California" | 760 "Alabama", "California" |
761 }; | 761 }; |
762 std::vector<string16> options(arraysize(kStates)); | 762 std::vector<string16> options(arraysize(kStates)); |
763 for (size_t i = 0; i < arraysize(kStates); ++i) { | 763 for (size_t i = 0; i < arraysize(kStates); ++i) { |
764 options[i] = ASCIIToUTF16(kStates[i]); | 764 options[i] = ASCIIToUTF16(kStates[i]); |
765 } | 765 } |
766 | 766 |
767 FormFieldData field; | 767 FormFieldData field; |
768 field.form_control_type = "select-one"; | 768 field.form_control_type = "select-one"; |
769 field.option_values = options; | 769 field.option_values = options; |
770 field.option_contents = options; | 770 field.option_contents = options; |
771 | 771 |
772 AutofillProfile profile; | 772 AutofillProfile profile; |
773 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); | 773 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); |
774 profile.FillSelectControl(ADDRESS_HOME_STATE, &field); | 774 profile.FillSelectControl(ADDRESS_HOME_STATE, "en-US", &field); |
775 EXPECT_EQ(ASCIIToUTF16("California"), field.value); | 775 EXPECT_EQ(ASCIIToUTF16("California"), field.value); |
776 } | 776 } |
777 | 777 |
778 TEST(AutofillProfileTest, AddressStateAbbrev) { | 778 TEST(AutofillProfileTest, AddressStateAbbrev) { |
779 const char* const kStates[] = { | 779 const char* const kStates[] = { |
780 "AL", "CA" | 780 "AL", "CA" |
781 }; | 781 }; |
782 std::vector<string16> options(arraysize(kStates)); | 782 std::vector<string16> options(arraysize(kStates)); |
783 for (size_t i = 0; i < arraysize(kStates); ++i) { | 783 for (size_t i = 0; i < arraysize(kStates); ++i) { |
784 options[i] = ASCIIToUTF16(kStates[i]); | 784 options[i] = ASCIIToUTF16(kStates[i]); |
785 } | 785 } |
786 | 786 |
787 FormFieldData field; | 787 FormFieldData field; |
788 field.form_control_type = "select-one"; | 788 field.form_control_type = "select-one"; |
789 field.option_values = options; | 789 field.option_values = options; |
790 field.option_contents = options; | 790 field.option_contents = options; |
791 | 791 |
792 AutofillProfile profile; | 792 AutofillProfile profile; |
793 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); | 793 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); |
794 profile.FillSelectControl(ADDRESS_HOME_STATE, &field); | 794 profile.FillSelectControl(ADDRESS_HOME_STATE, "en-US", &field); |
795 EXPECT_EQ(ASCIIToUTF16("CA"), field.value); | 795 EXPECT_EQ(ASCIIToUTF16("CA"), field.value); |
796 } | 796 } |
797 | 797 |
798 TEST(AutofillProfileTest, FillByValue) { | 798 TEST(AutofillProfileTest, FillByValue) { |
799 const char* const kStates[] = { | 799 const char* const kStates[] = { |
800 "Alabama", "California" | 800 "Alabama", "California" |
801 }; | 801 }; |
802 std::vector<string16> values(arraysize(kStates)); | 802 std::vector<string16> values(arraysize(kStates)); |
803 std::vector<string16> contents(arraysize(kStates)); | 803 std::vector<string16> contents(arraysize(kStates)); |
804 for (unsigned int i = 0; i < arraysize(kStates); ++i) { | 804 for (unsigned int i = 0; i < arraysize(kStates); ++i) { |
805 values[i] = ASCIIToUTF16(kStates[i]); | 805 values[i] = ASCIIToUTF16(kStates[i]); |
806 contents[i] = ASCIIToUTF16(base::StringPrintf("%u", i)); | 806 contents[i] = ASCIIToUTF16(base::StringPrintf("%u", i)); |
807 } | 807 } |
808 | 808 |
809 FormFieldData field; | 809 FormFieldData field; |
810 field.form_control_type = "select-one"; | 810 field.form_control_type = "select-one"; |
811 field.option_values = values; | 811 field.option_values = values; |
812 field.option_contents = contents; | 812 field.option_contents = contents; |
813 | 813 |
814 AutofillProfile profile; | 814 AutofillProfile profile; |
815 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); | 815 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); |
816 profile.FillSelectControl(ADDRESS_HOME_STATE, &field); | 816 profile.FillSelectControl(ADDRESS_HOME_STATE, "en-US", &field); |
817 EXPECT_EQ(ASCIIToUTF16("California"), field.value); | 817 EXPECT_EQ(ASCIIToUTF16("California"), field.value); |
818 } | 818 } |
819 | 819 |
820 TEST(AutofillProfileTest, FillByContents) { | 820 TEST(AutofillProfileTest, FillByContents) { |
821 const char* const kStates[] = { | 821 const char* const kStates[] = { |
822 "Alabama", "California" | 822 "Alabama", "California" |
823 }; | 823 }; |
824 std::vector<string16> values(arraysize(kStates)); | 824 std::vector<string16> values(arraysize(kStates)); |
825 std::vector<string16> contents(arraysize(kStates)); | 825 std::vector<string16> contents(arraysize(kStates)); |
826 for (unsigned int i = 0; i < arraysize(kStates); ++i) { | 826 for (unsigned int i = 0; i < arraysize(kStates); ++i) { |
827 values[i] = ASCIIToUTF16(base::StringPrintf("%u", i + 1)); | 827 values[i] = ASCIIToUTF16(base::StringPrintf("%u", i + 1)); |
828 contents[i] = ASCIIToUTF16(kStates[i]); | 828 contents[i] = ASCIIToUTF16(kStates[i]); |
829 } | 829 } |
830 | 830 |
831 FormFieldData field; | 831 FormFieldData field; |
832 field.form_control_type = "select-one"; | 832 field.form_control_type = "select-one"; |
833 field.option_values = values; | 833 field.option_values = values; |
834 field.option_contents = contents; | 834 field.option_contents = contents; |
835 | 835 |
836 AutofillProfile profile; | 836 AutofillProfile profile; |
837 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); | 837 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); |
838 profile.FillSelectControl(ADDRESS_HOME_STATE, &field); | 838 profile.FillSelectControl(ADDRESS_HOME_STATE, "en-US", &field); |
839 EXPECT_EQ(ASCIIToUTF16("2"), field.value); | 839 EXPECT_EQ(ASCIIToUTF16("2"), field.value); |
840 } | 840 } |
OLD | NEW |