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

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: Don't merge verified profiles 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 2717 matching lines...) Expand 10 before | Expand all | Expand 10 after
2728 .WillOnce(QuitMainMessageLoop()); 2728 .WillOnce(QuitMainMessageLoop());
2729 base::MessageLoop::current()->Run(); 2729 base::MessageLoop::current()->Run();
2730 2730
2731 // The new profile should be merged into the existing one. 2731 // The new profile should be merged into the existing one.
2732 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); 2732 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
2733 ASSERT_EQ(1U, results.size()); 2733 ASSERT_EQ(1U, results.size());
2734 EXPECT_EQ(0, new_verified_profile.Compare(*results[0])); 2734 EXPECT_EQ(0, new_verified_profile.Compare(*results[0]));
2735 } 2735 }
2736 2736
2737 // Ensure that verified profiles can be saved via SaveImportedProfile, 2737 // Ensure that verified profiles can be saved via SaveImportedProfile,
2738 // overwriting existing verified profiles as well. 2738 // but do not merge with existing verified profiles.
2739 TEST_F(PersonalDataManagerTest, SaveImportedProfileWithExistingVerifiedData) { 2739 TEST_F(PersonalDataManagerTest, SaveImportedProfileWithExistingVerifiedData) {
2740 // Start with a verified profile. 2740 // Start with a verified profile.
2741 AutofillProfile profile(base::GenerateGUID(), kSettingsOrigin); 2741 AutofillProfile profile(base::GenerateGUID(), kSettingsOrigin);
2742 test::SetProfileInfo(&profile, 2742 test::SetProfileInfo(&profile,
2743 "Marion", "Mitchell", "Morrison", 2743 "Marion", "Mitchell", "Morrison",
2744 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", 2744 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
2745 "91601", "US", "12345678910"); 2745 "91601", "US", "12345678910");
2746 EXPECT_TRUE(profile.IsVerified()); 2746 EXPECT_TRUE(profile.IsVerified());
2747 2747
2748 // Add the profile to the database. 2748 // Add the profile to the database.
2749 personal_data_->AddProfile(profile); 2749 personal_data_->AddProfile(profile);
2750 2750
2751 // Verify that the web database has been updated and the notification sent. 2751 // Verify that the web database has been updated and the notification sent.
2752 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2752 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2753 .WillOnce(QuitMainMessageLoop()); 2753 .WillOnce(QuitMainMessageLoop());
2754 base::MessageLoop::current()->Run(); 2754 base::MessageLoop::current()->Run();
2755 2755
2756 AutofillProfile new_verified_profile = profile; 2756 AutofillProfile new_verified_profile = profile;
2757 new_verified_profile.set_guid(base::GenerateGUID()); 2757 new_verified_profile.set_guid(base::GenerateGUID());
2758 new_verified_profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, 2758 new_verified_profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER,
2759 ASCIIToUTF16("1 234 567-8910")); 2759 ASCIIToUTF16("1 234 567-8910"));
2760 EXPECT_TRUE(new_verified_profile.IsVerified()); 2760 EXPECT_TRUE(new_verified_profile.IsVerified());
2761 2761
2762 personal_data_->SaveImportedProfile(new_verified_profile); 2762 personal_data_->SaveImportedProfile(new_verified_profile);
Mathieu 2016/06/17 14:15:09 Is this even a possible codepath? The only way to
sebsg 2016/06/17 17:09:01 Done.
2763 2763
2764 // Verify that the web database has been updated and the notification sent. 2764 // Verify that the web database has been updated and the notification sent.
2765 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2765 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2766 .WillOnce(QuitMainMessageLoop()); 2766 .WillOnce(QuitMainMessageLoop());
2767 base::MessageLoop::current()->Run(); 2767 base::MessageLoop::current()->Run();
2768 2768
2769 // The new profile should be merged into the existing one. 2769 // The new profile should not be merged into the existing one. It should be
2770 // saved as a separate profile.
2770 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); 2771 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
2771 ASSERT_EQ(1U, results.size()); 2772 ASSERT_EQ(2U, results.size());
2772 EXPECT_EQ(0, new_verified_profile.Compare(*results[0]));
2773 } 2773 }
2774 2774
2775 // Ensure that verified credit cards can be saved via SaveImportedCreditCard. 2775 // Ensure that verified credit cards can be saved via SaveImportedCreditCard.
2776 TEST_F(PersonalDataManagerTest, SaveImportedCreditCardWithVerifiedData) { 2776 TEST_F(PersonalDataManagerTest, SaveImportedCreditCardWithVerifiedData) {
2777 // Start with a verified credit card. 2777 // Start with a verified credit card.
2778 CreditCard credit_card(base::GenerateGUID(), kSettingsOrigin); 2778 CreditCard credit_card(base::GenerateGUID(), kSettingsOrigin);
2779 test::SetCreditCardInfo(&credit_card, 2779 test::SetCreditCardInfo(&credit_card,
2780 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2999"); 2780 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2999");
2781 EXPECT_TRUE(credit_card.IsVerified()); 2781 EXPECT_TRUE(credit_card.IsVerified());
2782 2782
(...skipping 1878 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 *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.
Mathieu 2016/06/17 14:15:09 *its
sebsg 2016/06/17 17:09:01 Done.
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
Mathieu 2016/06/17 14:15:09 nit: unverified
sebsg 2016/06/17 17:09:02 Done.
4824 // verified profile. Also tests that two verified profiles don't 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 // Sort the profiles by frecency to have a deterministic order.
Mathieu 2016/06/17 14:15:09 not sure why this is here? I would rather have the
sebsg 2016/06/17 17:09:01 Otherwise the test fails half the time because the
4872 base::Time comparison_time = base::Time::Now();
4873 std::sort(profiles.begin(), profiles.end(),
4874 [comparison_time](const AutofillDataModel* a,
4875 const AutofillDataModel* b) {
4876 return a->CompareFrecency(b, comparison_time);
4877 });
4878
4879 // The |imported_profile| should have been discarded because the saved profile
4880 // with the highest frecency score is verified (|profile1|). Therefore, the
4881 // |imported_profile|'s data should not have been merged with the
4882 // |imported_profile|'s data. Then |profile1| should have been compared to
Mathieu 2016/06/17 14:15:09 fix comment?
sebsg 2016/06/17 17:09:01 Done.
4883 // |profile2| but they should not have merged because both profiles are
4884 // verified.
4885 ASSERT_EQ(2U, profiles.size());
4886 // 2 profiles were considered for dedupe (the 2 saved profiles).
4887 histogram_tester.ExpectUniqueSample(
4888 "Autofill.NumberOfProfilesConsideredForDedupe", 2, 1);
4889 // No profile was removed.
4890 histogram_tester.ExpectUniqueSample(
4891 "Autofill.NumberOfProfilesRemovedDuringDedupe", 0, 1);
4892
4893 EXPECT_EQ(profile1.guid(), profiles[0]->guid());
4894 EXPECT_EQ(profile2.guid(), profiles[1]->guid());
4895 // The profiles should have kept their original data.
4896 EXPECT_EQ(UTF8ToUTF16("742 Evergreen Terrace."),
4897 profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1));
4898 EXPECT_EQ(UTF8ToUTF16("742 Evergreen Terrace"),
4899 profiles[1]->GetRawInfo(ADDRESS_HOME_LINE1));
4900 EXPECT_EQ(UTF8ToUTF16("J"), profiles[0]->GetRawInfo(NAME_MIDDLE));
4901 EXPECT_EQ(UTF8ToUTF16("Jay"), profiles[1]->GetRawInfo(NAME_MIDDLE));
4902 EXPECT_EQ(UTF8ToUTF16(""),
4903 profiles[0]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
4904 EXPECT_EQ(UTF8ToUTF16("12345678910"),
4905 profiles[1]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
4906 EXPECT_EQ(profile1.use_count(), profiles[0]->use_count());
4907 EXPECT_EQ(profile2.use_count(), profiles[1]->use_count());
4908 EXPECT_LT(profile1.use_date() - TimeDelta::FromSeconds(2),
4909 profiles[0]->use_date());
4910 EXPECT_GT(profile1.use_date() + TimeDelta::FromSeconds(2),
4911 profiles[0]->use_date());
4912 EXPECT_LT(profile2.use_date() - TimeDelta::FromSeconds(2),
4913 profiles[1]->use_date());
4914 EXPECT_GT(profile2.use_date() + TimeDelta::FromSeconds(2),
4915 profiles[1]->use_date());
4916
4917 }
4918
4671 } // namespace autofill 4919 } // 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