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

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

Issue 2075503002: [Autofill] Fix the dedupe of verified profiles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « components/autofill/core/browser/personal_data_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4650 matching lines...) Expand 10 before | Expand all | Expand 10 after
4661 // saved profiles plus 1 (imported profile count). 4661 // saved profiles plus 1 (imported profile count).
4662 EXPECT_EQ(profile1.use_count() + profile2.use_count() + 4662 EXPECT_EQ(profile1.use_count() + profile2.use_count() +
4663 imported_profile.use_count(), 4663 imported_profile.use_count(),
4664 profiles[0]->use_count()); 4664 profiles[0]->use_count());
4665 // The use date that results from the merge should be the one from the 4665 // The use date that results from the merge should be the one from the
4666 // imported profile since it was used just now. 4666 // imported profile since it was used just now.
4667 EXPECT_LT(base::Time::Now() - base::TimeDelta::FromSeconds(10), 4667 EXPECT_LT(base::Time::Now() - base::TimeDelta::FromSeconds(10),
4668 profiles[0]->use_date()); 4668 profiles[0]->use_date());
4669 } 4669 }
4670 4670
4671 // Tests that FindAndMergeDuplicateProfiles only keeps the verified profile with
4672 // it's original data when deduping with similar profiles, even if it has a
Mathieu 2016/06/17 14:15:09 nit: its
sebsg 2016/06/17 17:09:01 Done.
4673 // higher frecency score.
4674 TEST_F(PersonalDataManagerTest,
4675 FindAndMergeDuplicateProfiles_VerifiedProfileFirst) {
4676 EnableAutofillProfileCleanup();
4677
4678 // Create a verified profile with a higher frecency score.
4679 AutofillProfile profile1(base::GenerateGUID(), kSettingsOrigin);
4680 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson",
4681 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "",
4682 "Springfield", "IL", "91601", "", "12345678910");
4683 profile1.set_use_count(5);
4684 profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3));
4685
4686 // Create a similar non verified profile with a lower frecency score.
4687 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com");
4688 test::SetProfileInfo(&profile2, "Homer", "J", "Simpson",
4689 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.",
4690 "", "Springfield", "IL", "91601", "", "");
4691 profile2.set_use_count(3);
4692 profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5));
4693
4694 personal_data_->AddProfile(profile1);
4695 personal_data_->AddProfile(profile2);
4696
4697 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4698 .WillOnce(QuitMainMessageLoop());
4699 base::MessageLoop::current()->Run();
4700
4701 EXPECT_EQ(2U, personal_data_->GetProfiles().size());
4702
4703 // Create a similar new non verified imported profile to be merged with the
4704 // saved profiles.
4705 AutofillProfile imported_profile(base::GenerateGUID(),
4706 "https://www.example.com");
4707 test::SetProfileInfo(&imported_profile, "Homer", "J", "Simpson",
4708 "homer.simpson@abc.com", "", "742. Evergreen Terrace",
4709 "", "Springfield", "IL", "91601", "US", "");
4710
4711 base::HistogramTester histogram_tester;
4712 personal_data_->SaveImportedProfile(imported_profile);
4713
4714 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4715 .WillOnce(QuitMainMessageLoop());
4716 base::MessageLoop::current()->Run();
4717
4718 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles();
4719
4720 // The |imported_profile| should have merged with |profile2|. |profile2|
4721 // should then have been discarded because it is similar to the verified
4722 // |profile1|.
4723 ASSERT_EQ(1U, profiles.size());
4724 // 2 profiles were considered for dedupe (profiles 1 and 2).
4725 histogram_tester.ExpectUniqueSample(
4726 "Autofill.NumberOfProfilesConsideredForDedupe", 2, 1);
4727 // 1 profile was removed (|profile2|).
4728 histogram_tester.ExpectUniqueSample(
4729 "Autofill.NumberOfProfilesRemovedDuringDedupe", 1, 1);
4730
4731 // Only the verified |profile2| with it's original data should have been kept.
4732 EXPECT_EQ(profile1.guid(), profiles[0]->guid());
4733 EXPECT_EQ(UTF8ToUTF16("742 Evergreen Terrace"),
4734 profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1));
4735 EXPECT_EQ(UTF8ToUTF16("Jay"), profiles[0]->GetRawInfo(NAME_MIDDLE));
4736 EXPECT_EQ(UTF8ToUTF16("12345678910"),
4737 profiles[0]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
4738 EXPECT_EQ(UTF8ToUTF16(""), profiles[0]->GetRawInfo(COMPANY_NAME));
4739 EXPECT_EQ(UTF8ToUTF16(""), profiles[0]->GetRawInfo(ADDRESS_HOME_COUNTRY));
4740 EXPECT_EQ(profile1.use_count(), profiles[0]->use_count());
4741 EXPECT_LT(profile1.use_date() - TimeDelta::FromSeconds(2),
4742 profiles[0]->use_date());
4743 EXPECT_GT(profile1.use_date() + TimeDelta::FromSeconds(2),
4744 profiles[0]->use_date());
4745 }
4746
4747 // Tests that FindAndMergeDuplicateProfiles only keeps the verified profile with
4748 // it's original data when deduping with similar profiles, even if it has a
4749 // lower frecency score.
4750 TEST_F(PersonalDataManagerTest,
4751 FindAndMergeDuplicateProfiles_VerifiedProfileLast) {
4752 EnableAutofillProfileCleanup();
4753
4754 // Create a non verified profile with a higher frecency score.
4755 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com");
4756 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson",
4757 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.",
4758 "", "Springfield", "IL", "91601", "", "");
4759 profile1.set_use_count(5);
4760 profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3));
4761
4762 // Create a similar verified profile with a lower frecency score.
4763 AutofillProfile profile2(base::GenerateGUID(), kSettingsOrigin);
4764 test::SetProfileInfo(&profile2, "Homer", "Jay", "Simpson",
4765 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "",
4766 "Springfield", "IL", "91601", "", "12345678910");
4767 profile2.set_use_count(3);
4768 profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5));
4769
4770 personal_data_->AddProfile(profile1);
4771 personal_data_->AddProfile(profile2);
4772
4773 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4774 .WillOnce(QuitMainMessageLoop());
4775 base::MessageLoop::current()->Run();
4776
4777 EXPECT_EQ(2U, personal_data_->GetProfiles().size());
4778
4779 // Create a similar non verified imported profile to be merged with the saved
4780 // profiles.
4781 AutofillProfile imported_profile(base::GenerateGUID(),
4782 "https://www.example.com");
4783 test::SetProfileInfo(&imported_profile, "Homer", "J", "Simpson",
4784 "homer.simpson@abc.com", "", "742. Evergreen Terrace",
4785 "", "Springfield", "IL", "91601", "US", "");
4786
4787 base::HistogramTester histogram_tester;
4788 personal_data_->SaveImportedProfile(imported_profile);
4789
4790 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4791 .WillOnce(QuitMainMessageLoop());
4792 base::MessageLoop::current()->Run();
4793
4794 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles();
4795
4796 // The |imported_profile| should have merged with |profile1|. |profile1|
4797 // should then have been discarded because it is similar to the verified
4798 // |profile2|.
4799 ASSERT_EQ(1U, profiles.size());
4800 // 2 profiles were considered for dedupe (profiles 1 and 2).
4801 histogram_tester.ExpectUniqueSample(
4802 "Autofill.NumberOfProfilesConsideredForDedupe", 2, 1);
4803 // 1 profile was removed (|profile1|).
4804 histogram_tester.ExpectUniqueSample(
4805 "Autofill.NumberOfProfilesRemovedDuringDedupe", 1, 1);
4806
4807 // Only the verified |profile2| with it's original data should have been kept.
4808 EXPECT_EQ(profile2.guid(), profiles[0]->guid());
4809 EXPECT_EQ(UTF8ToUTF16("742 Evergreen Terrace"),
4810 profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1));
4811 EXPECT_EQ(UTF8ToUTF16("Jay"), profiles[0]->GetRawInfo(NAME_MIDDLE));
4812 EXPECT_EQ(UTF8ToUTF16("12345678910"),
4813 profiles[0]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
4814 EXPECT_EQ(UTF8ToUTF16(""), profiles[0]->GetRawInfo(COMPANY_NAME));
4815 EXPECT_EQ(UTF8ToUTF16(""), profiles[0]->GetRawInfo(ADDRESS_HOME_COUNTRY));
4816 EXPECT_EQ(profile2.use_count(), profiles[0]->use_count());
4817 EXPECT_LT(profile2.use_date() - TimeDelta::FromSeconds(2),
4818 profiles[0]->use_date());
4819 EXPECT_GT(profile2.use_date() + TimeDelta::FromSeconds(2),
4820 profiles[0]->use_date());
4821 }
4822
4823 // Tests that FindAndMergeDuplicateProfiles does not merge unverfied data into a
4824 // verified profile. Also tests that two verified profiles get merged.
4825 TEST_F(PersonalDataManagerTest,
4826 FindAndMergeDuplicateProfiles_MultipleVerifiedProfiles) {
4827 EnableAutofillProfileCleanup();
4828
4829 // Create a verified profile with a higher frecency score.
4830 AutofillProfile profile1(base::GenerateGUID(), kSettingsOrigin);
4831 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson",
4832 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.",
4833 "", "Springfield", "IL", "91601", "", "");
4834 profile1.set_use_count(5);
4835 profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3));
4836
4837 // Create a similar verified profile with a lower frecency score.
4838 AutofillProfile profile2(base::GenerateGUID(), kSettingsOrigin);
4839 test::SetProfileInfo(&profile2, "Homer", "Jay", "Simpson",
4840 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "",
4841 "Springfield", "IL", "91601", "", "12345678910");
4842 profile2.set_use_count(3);
4843 profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5));
4844
4845 personal_data_->AddProfile(profile1);
4846 personal_data_->AddProfile(profile2);
4847
4848 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4849 .WillOnce(QuitMainMessageLoop());
4850 base::MessageLoop::current()->Run();
4851
4852 EXPECT_EQ(2U, personal_data_->GetProfiles().size());
4853
4854 // Create a non verified imported profile to be merged with the saved
4855 // profiles.
4856 AutofillProfile imported_profile(base::GenerateGUID(),
4857 "https://www.example.com");
4858 test::SetProfileInfo(&imported_profile, "Homer", "J", "Simpson",
4859 "homer.simpson@abc.com", "", "742. Evergreen Terrace",
4860 "", "Springfield", "IL", "91601", "US", "");
4861
4862 base::HistogramTester histogram_tester;
4863 personal_data_->SaveImportedProfile(imported_profile);
4864
4865 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4866 .WillOnce(QuitMainMessageLoop());
4867 base::MessageLoop::current()->Run();
4868
4869 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles();
4870
4871 // The |imported_profile| should have been discarded because the saved profile
4872 // with the highest frecency score is verified (|profile1|). Therefore, the
4873 // |imported_profile|'s data should not have been merged with the
4874 // |imported_profile|'s data. However, |profile1| should then have been merged
4875 // with |profile2| since they are both verified.
4876 ASSERT_EQ(1U, profiles.size());
4877 // 2 profiles were considered for dedupe (the 2 saved profiles).
4878 histogram_tester.ExpectUniqueSample(
4879 "Autofill.NumberOfProfilesConsideredForDedupe", 2, 1);
4880 // 1 profile was removed (|profile1|).
4881 histogram_tester.ExpectUniqueSample(
4882 "Autofill.NumberOfProfilesRemovedDuringDedupe", 1, 1);
4883
4884 EXPECT_EQ(profile2.guid(), profiles[0]->guid());
4885 // The address syntax from |profile1| should have been kept (higher frecency
4886 // score).
4887 EXPECT_EQ(UTF8ToUTF16("742 Evergreen Terrace."),
4888 profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1));
4889 // The full middle name from |profile2| should have been kept (no loss of
4890 // information).
4891 EXPECT_EQ(UTF8ToUTF16("Jay"), profiles[0]->GetRawInfo(NAME_MIDDLE));
4892 // Since the |imported_profile| matched a verified profile, it's data should
4893 // not have been merged.
4894 EXPECT_EQ(UTF8ToUTF16(""), profiles[0]->GetRawInfo(ADDRESS_HOME_COUNTRY));
4895 }
4896
4671 } // namespace autofill 4897 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/personal_data_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698