| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/format_macros.h" | 6 #include "base/format_macros.h" |
| 7 #include "base/guid.h" | 7 #include "base/guid.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 const std::vector<NameParts>& expected_result) | 59 const std::vector<NameParts>& expected_result) |
| 60 : starting_names(starting_names), | 60 : starting_names(starting_names), |
| 61 additional_names(additional_names), | 61 additional_names(additional_names), |
| 62 expected_result(expected_result) {} | 62 expected_result(expected_result) {} |
| 63 | 63 |
| 64 std::vector<NameParts> starting_names; | 64 std::vector<NameParts> starting_names; |
| 65 std::vector<NameParts> additional_names; | 65 std::vector<NameParts> additional_names; |
| 66 std::vector<NameParts> expected_result; | 66 std::vector<NameParts> expected_result; |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 void SetupTestProfile(AutofillProfile& profile) { |
| 70 profile.set_guid(base::GenerateGUID()); |
| 71 profile.set_origin("Chrome settings"); |
| 72 test::SetProfileInfo(&profile, "Marion", "Mitchell", "Morrison", |
| 73 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
| 74 "Hollywood", "CA", "91601", "US", "12345678910"); |
| 75 } |
| 76 |
| 69 } // namespace | 77 } // namespace |
| 70 | 78 |
| 71 // Tests different possibilities for summary string generation. | 79 // Tests different possibilities for summary string generation. |
| 72 // Based on existence of first name, last name, and address line 1. | 80 // Based on existence of first name, last name, and address line 1. |
| 73 TEST(AutofillProfileTest, PreviewSummaryString) { | 81 TEST(AutofillProfileTest, PreviewSummaryString) { |
| 74 // Case 0/null: "" | 82 // Case 0/null: "" |
| 75 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com/"); | 83 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com/"); |
| 76 // Empty profile - nothing to update. | 84 // Empty profile - nothing to update. |
| 77 base::string16 summary0 = GetLabel(&profile0); | 85 base::string16 summary0 = GetLabel(&profile0); |
| 78 EXPECT_EQ(base::string16(), summary0); | 86 EXPECT_EQ(base::string16(), summary0); |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); | 831 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); |
| 824 test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson", | 832 test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson", |
| 825 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, | 833 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 826 NULL); | 834 NULL); |
| 827 test::SetProfileInfo(a.get(), "Thomas", NULL, "Adams", | 835 test::SetProfileInfo(a.get(), "Thomas", NULL, "Adams", |
| 828 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, | 836 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 829 NULL); | 837 NULL); |
| 830 EXPECT_FALSE(a->IsSubsetOf(*b, "en-US")); | 838 EXPECT_FALSE(a->IsSubsetOf(*b, "en-US")); |
| 831 } | 839 } |
| 832 | 840 |
| 833 TEST(AutofillProfileTest, OverwriteWith) { | 841 TEST(AutofillProfileTest, OverwriteWith_DifferentProfile) { |
| 834 AutofillProfile a(base::GenerateGUID(), "https://www.example.com"); | 842 AutofillProfile a; |
| 835 test::SetProfileInfo(&a, "Marion", "Mitchell", "Morrison", | 843 SetupTestProfile(a); |
| 836 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", | |
| 837 "Hollywood", "CA", "91601", "US", | |
| 838 "12345678910"); | |
| 839 | 844 |
| 840 // Create an identical profile except that the new profile: | 845 // Create an identical profile except that the new profile: |
| 841 // (1) Has a different origin, | 846 // (1) Has a different origin, |
| 842 // (2) Has a different address line 2, | 847 // (2) Has a different address line 2, |
| 843 // (3) Lacks a company name, | 848 // (3) Lacks a company name, |
| 844 // (4) Has a different full name, and | 849 // (4) Has a different full name, and |
| 845 // (5) Has a language code. | 850 // (5) Has a language code. |
| 846 AutofillProfile b = a; | 851 AutofillProfile b = a; |
| 847 b.set_guid(base::GenerateGUID()); | 852 b.set_guid(base::GenerateGUID()); |
| 848 b.set_origin("Chrome settings"); | 853 b.set_origin("Chrome settings"); |
| 849 b.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("area 51")); | 854 b.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("area 51")); |
| 850 b.SetRawInfo(COMPANY_NAME, base::string16()); | 855 b.SetRawInfo(COMPANY_NAME, base::string16()); |
| 851 | 856 |
| 852 b.SetRawInfo(NAME_FULL, ASCIIToUTF16("Marion M. Morrison")); | 857 b.SetRawInfo(NAME_FULL, ASCIIToUTF16("Marion M. Morrison")); |
| 853 b.set_language_code("en"); | 858 b.set_language_code("en"); |
| 854 | 859 |
| 855 a.OverwriteWith(b, "en-US"); | 860 EXPECT_TRUE(a.OverwriteWith(b, "en-US")); |
| 856 EXPECT_EQ("Chrome settings", a.origin()); | 861 EXPECT_EQ("Chrome settings", a.origin()); |
| 857 EXPECT_EQ(ASCIIToUTF16("area 51"), a.GetRawInfo(ADDRESS_HOME_LINE2)); | 862 EXPECT_EQ(ASCIIToUTF16("area 51"), a.GetRawInfo(ADDRESS_HOME_LINE2)); |
| 858 EXPECT_EQ(ASCIIToUTF16("Fox"), a.GetRawInfo(COMPANY_NAME)); | 863 EXPECT_EQ(ASCIIToUTF16("Fox"), a.GetRawInfo(COMPANY_NAME)); |
| 859 base::string16 name = a.GetInfo(AutofillType(NAME_FULL), "en-US"); | 864 base::string16 name = a.GetInfo(AutofillType(NAME_FULL), "en-US"); |
| 860 EXPECT_EQ(ASCIIToUTF16("Marion M. Morrison"), name); | 865 EXPECT_EQ(ASCIIToUTF16("Marion M. Morrison"), name); |
| 861 EXPECT_EQ("en", a.language_code()); | 866 EXPECT_EQ("en", a.language_code()); |
| 862 } | 867 } |
| 863 | 868 |
| 869 TEST(AutofillProfileTest, OverwriteWith_SameProfile) { |
| 870 AutofillProfile a; |
| 871 SetupTestProfile(a); |
| 872 |
| 873 AutofillProfile b = a; |
| 874 b.set_guid(base::GenerateGUID()); |
| 875 EXPECT_FALSE(a.OverwriteWith(b, "en-US")); |
| 876 } |
| 877 |
| 878 TEST(AutofillProfileTest, OverwriteWith_DifferentName) { |
| 879 AutofillProfile a; |
| 880 SetupTestProfile(a); |
| 881 |
| 882 AutofillProfile b = a; |
| 883 b.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Mario")); |
| 884 EXPECT_TRUE(a.OverwriteWith(b, "en-US")); |
| 885 base::string16 name_full = a.GetInfo(AutofillType(NAME_FULL), "en-US"); |
| 886 EXPECT_EQ(ASCIIToUTF16("Mario Mitchell Morrison"), name_full); |
| 887 } |
| 888 |
| 889 TEST(AutofillProfileTest, OverwriteWith_DifferentAddress) { |
| 890 AutofillProfile a; |
| 891 SetupTestProfile(a); |
| 892 |
| 893 AutofillProfile b = a; |
| 894 b.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Aquarium St.")); |
| 895 EXPECT_TRUE(a.OverwriteWith(b, "en-US")); |
| 896 base::string16 address = a.GetRawInfo(ADDRESS_HOME_LINE1); |
| 897 EXPECT_EQ(ASCIIToUTF16("123 Aquarium St."), address); |
| 898 } |
| 899 |
| 864 TEST(AutofillProfileTest, AssignmentOperator) { | 900 TEST(AutofillProfileTest, AssignmentOperator) { |
| 865 AutofillProfile a(base::GenerateGUID(), "https://www.example.com/"); | 901 AutofillProfile a(base::GenerateGUID(), "https://www.example.com/"); |
| 866 test::SetProfileInfo(&a, "Marion", "Mitchell", "Morrison", | 902 test::SetProfileInfo(&a, "Marion", "Mitchell", "Morrison", |
| 867 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", | 903 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
| 868 "Hollywood", "CA", "91601", "US", | 904 "Hollywood", "CA", "91601", "US", |
| 869 "12345678910"); | 905 "12345678910"); |
| 870 | 906 |
| 871 // Result of assignment should be logically equal to the original profile. | 907 // Result of assignment should be logically equal to the original profile. |
| 872 AutofillProfile b(base::GenerateGUID(), "http://www.example.com/"); | 908 AutofillProfile b(base::GenerateGUID(), "http://www.example.com/"); |
| 873 b = a; | 909 b = a; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1070 AutofillProfile::CanonicalizeProfileString(base::WideToUTF16( | 1106 AutofillProfile::CanonicalizeProfileString(base::WideToUTF16( |
| 1071 L"Mid\x2013Island\x2003 Plaza"))); | 1107 L"Mid\x2013Island\x2003 Plaza"))); |
| 1072 | 1108 |
| 1073 // Newline character removed. | 1109 // Newline character removed. |
| 1074 EXPECT_EQ(ASCIIToUTF16("1600 amphitheatre pkwy app 2"), | 1110 EXPECT_EQ(ASCIIToUTF16("1600 amphitheatre pkwy app 2"), |
| 1075 AutofillProfile::CanonicalizeProfileString( | 1111 AutofillProfile::CanonicalizeProfileString( |
| 1076 ASCIIToUTF16("1600 amphitheatre pkwy \n App. 2"))); | 1112 ASCIIToUTF16("1600 amphitheatre pkwy \n App. 2"))); |
| 1077 } | 1113 } |
| 1078 | 1114 |
| 1079 } // namespace autofill | 1115 } // namespace autofill |
| OLD | NEW |