Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: components/autofill/core/browser/personal_data_manager_unittest.cc

Issue 2110563002: Use AutofillProfileComparator in place of ad-hoc merge logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@merge
Patch Set: Rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/personal_data_manager.h" 5 #include "components/autofill/core/browser/personal_data_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 1725 matching lines...) Expand 10 before | Expand all | Expand 10 after
1736 form_structure2.DetermineHeuristicTypes(); 1736 form_structure2.DetermineHeuristicTypes();
1737 EXPECT_TRUE(ImportAddressProfiles(form_structure2)); 1737 EXPECT_TRUE(ImportAddressProfiles(form_structure2));
1738 1738
1739 // Verify that the web database has been updated and the notification sent. 1739 // Verify that the web database has been updated and the notification sent.
1740 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1740 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1741 .WillOnce(QuitMainMessageLoop()); 1741 .WillOnce(QuitMainMessageLoop());
1742 base::RunLoop().Run(); 1742 base::RunLoop().Run();
1743 1743
1744 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); 1744 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
1745 1745
1746 // Phone formatting is updated. Also, country gets added. 1746 // Full name, phone formatting and country are updated.
1747 expected.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("650-555-6666")); 1747 expected.SetRawInfo(NAME_FULL, ASCIIToUTF16("George Washington"));
1748 expected.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("+1 650-555-6666"));
1748 expected.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); 1749 expected.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
1749 ASSERT_EQ(1U, results2.size()); 1750 ASSERT_EQ(1U, results2.size());
1750 EXPECT_EQ(0, expected.Compare(*results2[0])); 1751 EXPECT_EQ(0, expected.Compare(*results2[0]));
1751 } 1752 }
1752 1753
1753 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_MissingInfoInOld) { 1754 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_MissingInfoInOld) {
1754 FormData form1; 1755 FormData form1;
1755 FormFieldData field; 1756 FormFieldData field;
1756 test::CreateTestFormField( 1757 test::CreateTestFormField(
1757 "First name:", "first_name", "George", "text", &field); 1758 "First name:", "first_name", "George", "text", &field);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1815 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1816 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1816 .WillOnce(QuitMainMessageLoop()); 1817 .WillOnce(QuitMainMessageLoop());
1817 base::RunLoop().Run(); 1818 base::RunLoop().Run();
1818 1819
1819 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); 1820 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
1820 1821
1821 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com"); 1822 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com");
1822 test::SetProfileInfo(&expected2, "George", NULL, 1823 test::SetProfileInfo(&expected2, "George", NULL,
1823 "Washington", "theprez@gmail.com", NULL, "190 High Street", NULL, 1824 "Washington", "theprez@gmail.com", NULL, "190 High Street", NULL,
1824 "Philadelphia", "Pennsylvania", "19106", NULL, NULL); 1825 "Philadelphia", "Pennsylvania", "19106", NULL, NULL);
1826 expected2.SetRawInfo(NAME_FULL, ASCIIToUTF16("George Washington"));
1825 ASSERT_EQ(1U, results2.size()); 1827 ASSERT_EQ(1U, results2.size());
1826 EXPECT_EQ(0, expected2.Compare(*results2[0])); 1828 EXPECT_EQ(0, expected2.Compare(*results2[0]));
1827 } 1829 }
1828 1830
1829 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_MissingInfoInNew) { 1831 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_MissingInfoInNew) {
1830 FormData form1; 1832 FormData form1;
1831 FormFieldData field; 1833 FormFieldData field;
1832 test::CreateTestFormField( 1834 test::CreateTestFormField(
1833 "First name:", "first_name", "George", "text", &field); 1835 "First name:", "first_name", "George", "text", &field);
1834 form1.fields.push_back(field); 1836 form1.fields.push_back(field);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1894 form_structure2.DetermineHeuristicTypes(); 1896 form_structure2.DetermineHeuristicTypes();
1895 EXPECT_TRUE(ImportAddressProfiles(form_structure2)); 1897 EXPECT_TRUE(ImportAddressProfiles(form_structure2));
1896 1898
1897 // Verify that the web database has been updated and the notification sent. 1899 // Verify that the web database has been updated and the notification sent.
1898 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1900 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1899 .WillOnce(QuitMainMessageLoop()); 1901 .WillOnce(QuitMainMessageLoop());
1900 base::RunLoop().Run(); 1902 base::RunLoop().Run();
1901 1903
1902 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); 1904 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
1903 1905
1904 // Expect no change. 1906 // The merge operation will populate the full name if it's empty.
1907 expected.SetRawInfo(NAME_FULL, ASCIIToUTF16("George Washington"));
1905 ASSERT_EQ(1U, results2.size()); 1908 ASSERT_EQ(1U, results2.size());
1906 EXPECT_EQ(0, expected.Compare(*results2[0])); 1909 EXPECT_EQ(0, expected.Compare(*results2[0]));
1907 } 1910 }
1908 1911
1909 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_InsufficientAddress) { 1912 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_InsufficientAddress) {
1910 FormData form1; 1913 FormData form1;
1911 FormFieldData field; 1914 FormFieldData field;
1912 test::CreateTestFormField( 1915 test::CreateTestFormField(
1913 "First name:", "first_name", "George", "text", &field); 1916 "First name:", "first_name", "George", "text", &field);
1914 form1.fields.push_back(field); 1917 form1.fields.push_back(field);
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
2734 personal_data_->SaveImportedProfile(new_verified_profile); 2737 personal_data_->SaveImportedProfile(new_verified_profile);
2735 2738
2736 // Verify that the web database has been updated and the notification sent. 2739 // Verify that the web database has been updated and the notification sent.
2737 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2740 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2738 .WillOnce(QuitMainMessageLoop()); 2741 .WillOnce(QuitMainMessageLoop());
2739 base::RunLoop().Run(); 2742 base::RunLoop().Run();
2740 2743
2741 // The new profile should be merged into the existing one. 2744 // The new profile should be merged into the existing one.
2742 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); 2745 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
2743 ASSERT_EQ(1U, results.size()); 2746 ASSERT_EQ(1U, results.size());
2744 EXPECT_EQ(0, new_verified_profile.Compare(*results[0])); 2747 AutofillProfile expected(new_verified_profile);
2748 expected.SetRawInfo(NAME_FULL, ASCIIToUTF16("Marion Mitchell Morrison"));
2749 expected.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("+1 234-567-8910"));
2750 EXPECT_EQ(0, expected.Compare(*results[0]))
2751 << "result = {" << *results[0] << "} | expected = {" << expected << "}";
2745 } 2752 }
2746 2753
2747 // Ensure that verified credit cards can be saved via SaveImportedCreditCard. 2754 // Ensure that verified credit cards can be saved via SaveImportedCreditCard.
2748 TEST_F(PersonalDataManagerTest, SaveImportedCreditCardWithVerifiedData) { 2755 TEST_F(PersonalDataManagerTest, SaveImportedCreditCardWithVerifiedData) {
2749 // Start with a verified credit card. 2756 // Start with a verified credit card.
2750 CreditCard credit_card(base::GenerateGUID(), kSettingsOrigin); 2757 CreditCard credit_card(base::GenerateGUID(), kSettingsOrigin);
2751 test::SetCreditCardInfo(&credit_card, 2758 test::SetCreditCardInfo(&credit_card,
2752 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2999"); 2759 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2999");
2753 EXPECT_TRUE(credit_card.IsVerified()); 2760 EXPECT_TRUE(credit_card.IsVerified());
2754 2761
(...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after
3997 } TestCase; 4004 } TestCase;
3998 4005
3999 TestCase test_cases[] = { 4006 TestCase test_cases[] = {
4000 // Test that saving an identical profile except for the name results in 4007 // Test that saving an identical profile except for the name results in
4001 // two profiles being saved. 4008 // two profiles being saved.
4002 {ProfileFields(), {{NAME_FIRST, "Marionette"}}}, 4009 {ProfileFields(), {{NAME_FIRST, "Marionette"}}},
4003 4010
4004 // Test that saving an identical profile except with the middle name 4011 // Test that saving an identical profile except with the middle name
4005 // initial instead of the full middle name results in the profiles 4012 // initial instead of the full middle name results in the profiles
4006 // getting merged and the full middle name being kept. 4013 // getting merged and the full middle name being kept.
4007 {ProfileFields(), {{NAME_MIDDLE, "M"}}, {{NAME_MIDDLE, "Mitchell"}}}, 4014 {ProfileFields(),
4015 {{NAME_MIDDLE, "M"}},
4016 {{NAME_MIDDLE, "Mitchell"}, {NAME_FULL, "Marion Mitchell Morrison"}}},
4008 4017
4009 // Test that saving an identical profile except with the full middle name 4018 // Test that saving an identical profile except with the full middle name
4010 // instead of the middle name initial results in the profiles getting 4019 // instead of the middle name initial results in the profiles getting
4011 // merged and the full middle name replacing the initial. 4020 // merged and the full middle name replacing the initial.
4012 {{{NAME_MIDDLE, "M"}}, 4021 {{{NAME_MIDDLE, "M"}},
4013 {{NAME_MIDDLE, "Mitchell"}}, 4022 {{NAME_MIDDLE, "Mitchell"}},
4014 {{NAME_MIDDLE, "Mitchell"}}}, 4023 {{NAME_MIDDLE, "Mitchell"}}},
4015 4024
4016 // Test that saving an identical profile except with no middle name 4025 // Test that saving an identical profile except with no middle name
4017 // results in the profiles getting merged and the full middle name being 4026 // results in the profiles getting merged and the full middle name being
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
4160 4169
4161 // Tests that saving an identical except with more punctuation in the fist 4170 // Tests that saving an identical except with more punctuation in the fist
4162 // address line, while the second is empty, results in a merge and that 4171 // address line, while the second is empty, results in a merge and that
4163 // the original address gets overwritten. 4172 // the original address gets overwritten.
4164 {{{ADDRESS_HOME_LINE2, ""}}, 4173 {{{ADDRESS_HOME_LINE2, ""}},
4165 {{ADDRESS_HOME_LINE2, ""}, {ADDRESS_HOME_LINE1, "123, Zoo St."}}, 4174 {{ADDRESS_HOME_LINE2, ""}, {ADDRESS_HOME_LINE1, "123, Zoo St."}},
4166 {{ADDRESS_HOME_LINE1, "123, Zoo St."}}}, 4175 {{ADDRESS_HOME_LINE1, "123, Zoo St."}}},
4167 4176
4168 // Tests that saving an identical profile except with less punctuation in 4177 // Tests that saving an identical profile except with less punctuation in
4169 // the fist address line, while the second is empty, results in a merge 4178 // the fist address line, while the second is empty, results in a merge
4170 // and that the original address gets overwritten. 4179 // and that the longer address is retained.
4171 {{{ADDRESS_HOME_LINE2, ""}, {ADDRESS_HOME_LINE1, "123, Zoo St."}}, 4180 {{{ADDRESS_HOME_LINE2, ""}, {ADDRESS_HOME_LINE1, "123, Zoo St."}},
4172 {{ADDRESS_HOME_LINE2, ""}}, 4181 {{ADDRESS_HOME_LINE2, ""}},
4173 {{ADDRESS_HOME_LINE1, "123 Zoo St"}}}, 4182 {{ADDRESS_HOME_LINE1, "123 Zoo St"}}},
4174 4183
4175 // Tests that saving an identical profile except additional punctuation in 4184 // Tests that saving an identical profile except additional punctuation in
4176 // the two address lines results in a merge and that the original address 4185 // the two address lines results in a merge and that the newer address
4177 // gets overwritten. 4186 // is retained.
4178 {ProfileFields(), 4187 {ProfileFields(),
4179 {{ADDRESS_HOME_LINE1, "123, Zoo St."}, {ADDRESS_HOME_LINE2, "unit. 5"}}, 4188 {{ADDRESS_HOME_LINE1, "123, Zoo St."}, {ADDRESS_HOME_LINE2, "unit. 5"}},
4180 {{ADDRESS_HOME_LINE1, "123, Zoo St."}, {ADDRESS_HOME_LINE2, "unit. 5"}}}, 4189 {{ADDRESS_HOME_LINE1, "123, Zoo St."}, {ADDRESS_HOME_LINE2, "unit. 5"}}},
4181 4190
4182 // Tests that saving an identical profile except less punctuation in the 4191 // Tests that saving an identical profile except less punctuation in the
4183 // two address lines results in a merge and that the original address gets 4192 // two address lines results in a merge and that the newer address is
4184 // overwritten. 4193 // retained.
4185 {{{ADDRESS_HOME_LINE1, "123, Zoo St."}, {ADDRESS_HOME_LINE2, "unit. 5"}}, 4194 {{{ADDRESS_HOME_LINE1, "123, Zoo St."}, {ADDRESS_HOME_LINE2, "unit. 5"}},
4186 ProfileFields(), 4195 ProfileFields(),
4187 {{ADDRESS_HOME_LINE1, "123 Zoo St"}, {ADDRESS_HOME_LINE2, "unit 5"}}}, 4196 {{ADDRESS_HOME_LINE1, "123 Zoo St"}, {ADDRESS_HOME_LINE2, "unit 5"}}},
4188 4197
4189 // Tests that saving an identical profile with accented characters in 4198 // Tests that saving an identical profile with accented characters in
4190 // the two address lines results in a merge and that the original address 4199 // the two address lines results in a merge and that the newer address
4191 // gets overwritten. 4200 // is retained.
4192 {ProfileFields(), 4201 {ProfileFields(),
4193 {{ADDRESS_HOME_LINE1, "123 Zôö St"}, {ADDRESS_HOME_LINE2, "üñìt 5"}}, 4202 {{ADDRESS_HOME_LINE1, "123 Zôö St"}, {ADDRESS_HOME_LINE2, "üñìt 5"}},
4194 {{ADDRESS_HOME_LINE1, "123 Zôö St"}, {ADDRESS_HOME_LINE2, "üñìt 5"}}}, 4203 {{ADDRESS_HOME_LINE1, "123 Zôö St"}, {ADDRESS_HOME_LINE2, "üñìt 5"}}},
4195 4204
4196 // Tests that saving an identical profile without accented characters in 4205 // Tests that saving an identical profile without accented characters in
4197 // the two address lines results in a merge and that the original address 4206 // the two address lines results in a merge and that the newer address
4198 // gets overwritten. 4207 // is retained.
4199 {{{ADDRESS_HOME_LINE1, "123 Zôö St"}, {ADDRESS_HOME_LINE2, "üñìt 5"}}, 4208 {{{ADDRESS_HOME_LINE1, "123 Zôö St"}, {ADDRESS_HOME_LINE2, "üñìt 5"}},
4200 ProfileFields(), 4209 ProfileFields(),
4201 {{ADDRESS_HOME_LINE1, "123 Zoo St"}, {ADDRESS_HOME_LINE2, "unit 5"}}}, 4210 {{ADDRESS_HOME_LINE1, "123 Zoo St"}, {ADDRESS_HOME_LINE2, "unit 5"}}},
4202 4211
4203 // Tests that saving an identical profile except that the address line 1 4212 // Tests that saving an identical profile except that the address line 1
4204 // is in the address line 2 results in a merge and that the original 4213 // is in the address line 2 results in a merge and that the multi-lne
4205 // address lines do not get overwritten. 4214 // address is retained.
4206 {ProfileFields(), 4215 {ProfileFields(),
4207 {{ADDRESS_HOME_LINE1, "123 Zoo St, unit 5"}, {ADDRESS_HOME_LINE2, ""}}, 4216 {{ADDRESS_HOME_LINE1, "123 Zoo St, unit 5"}, {ADDRESS_HOME_LINE2, ""}},
4208 {{ADDRESS_HOME_LINE1, "123 Zoo St"}, {ADDRESS_HOME_LINE2, "unit 5"}}}, 4217 {{ADDRESS_HOME_LINE1, "123 Zoo St"}, {ADDRESS_HOME_LINE2, "unit 5"}}},
4209 4218
4210 // Tests that saving an identical profile except that the address line 2 4219 // Tests that saving an identical profile except that the address line 2
4211 // contains part of the old address line 1 results in a merge and that the 4220 // contains part of the old address line 1 results in a merge and that the
4212 // original address lines of the reference profile get overwritten. 4221 // original address lines of the reference profile get overwritten.
4213 {{{ADDRESS_HOME_LINE1, "123 Zoo St, unit 5"}, {ADDRESS_HOME_LINE2, ""}}, 4222 {{{ADDRESS_HOME_LINE1, "123 Zoo St, unit 5"}, {ADDRESS_HOME_LINE2, ""}},
4214 ProfileFields(), 4223 ProfileFields(),
4215 {{ADDRESS_HOME_LINE1, "123 Zoo St"}, {ADDRESS_HOME_LINE2, "unit 5"}}}, 4224 {{ADDRESS_HOME_LINE1, "123 Zoo St"}, {ADDRESS_HOME_LINE2, "unit 5"}}},
4216 4225
4217 // Tests that saving an identical profile except that the state is the 4226 // Tests that saving an identical profile except that the state is the
4218 // abbreviation instead of the full form results in a merge and that the 4227 // abbreviation instead of the full form results in a merge and that the
4219 // original state gets overwritten. 4228 // original state gets overwritten.
4220 {{{ADDRESS_HOME_STATE, "California"}}, 4229 {{{ADDRESS_HOME_STATE, "California"}},
4221 ProfileFields(), 4230 ProfileFields(),
4222 {{ADDRESS_HOME_STATE, "CA"}}}, 4231 {{ADDRESS_HOME_STATE, "CA"}}},
4223 4232
4224 // Tests that saving an identical profile except that the state is the 4233 // Tests that saving an identical profile except that the state is the
4225 // full form instead of the abbreviation results in a merge and that the 4234 // full form instead of the abbreviation results in a merge and that the
4226 // original state gets overwritten. 4235 // abbreviated state is retained.
4227 {ProfileFields(), 4236 {ProfileFields(),
4228 {{ADDRESS_HOME_STATE, "California"}}, 4237 {{ADDRESS_HOME_STATE, "California"}},
4229 {{ADDRESS_HOME_STATE, "California"}}}, 4238 {{ADDRESS_HOME_STATE, "CA"}}},
4230 4239
4231 // Tests that saving and identical profile except that the company name 4240 // Tests that saving and identical profile except that the company name
4232 // has different punctuation and case results in a merge and that the 4241 // has different punctuation and case results in a merge and that the
4233 // syntax of the new profile replaces the old one. 4242 // syntax of the new profile replaces the old one.
4234 {{{COMPANY_NAME, "Stark inc"}}, 4243 {{{COMPANY_NAME, "Stark inc"}},
4235 {{COMPANY_NAME, "Stark Inc."}}, 4244 {{COMPANY_NAME, "Stark Inc."}},
4236 {{COMPANY_NAME, "Stark Inc."}}}, 4245 {{COMPANY_NAME, "Stark Inc."}}},
4237 }; 4246 };
4238 4247
4239 for (TestCase test_case : test_cases) { 4248 for (TestCase test_case : test_cases) {
4240 SetupReferenceProfile(); 4249 SetupReferenceProfile();
4241
4242 const std::vector<AutofillProfile*>& initial_profiles = 4250 const std::vector<AutofillProfile*>& initial_profiles =
4243 personal_data_->GetProfiles(); 4251 personal_data_->GetProfiles();
4244 4252
4245 // Apply changes to the original profile (if applicable). 4253 // Apply changes to the original profile (if applicable).
4246 for (ProfileField change : test_case.changes_to_original) { 4254 for (ProfileField change : test_case.changes_to_original) {
4247 initial_profiles.front()->SetRawInfo( 4255 initial_profiles.front()->SetRawInfo(
4248 change.field_type, base::UTF8ToUTF16(change.field_value)); 4256 change.field_type, base::UTF8ToUTF16(change.field_value));
4249 } 4257 }
4250 4258
4251 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); 4259 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com");
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after
5107 EnableAutofillProfileCleanup(); 5115 EnableAutofillProfileCleanup();
5108 5116
5109 // The deduping routine should not be run. 5117 // The deduping routine should not be run.
5110 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); 5118 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine());
5111 5119
5112 // The two duplicate profiles should still be present. 5120 // The two duplicate profiles should still be present.
5113 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); 5121 EXPECT_EQ(2U, personal_data_->GetProfiles().size());
5114 } 5122 }
5115 5123
5116 } // namespace autofill 5124 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/personal_data_manager.cc ('k') | components/autofill/core/browser/phone_number.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698