| 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 "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 4662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4673 "homer.simpson@abc.com", "", "742. Evergreen Terrace", | 4673 "homer.simpson@abc.com", "", "742. Evergreen Terrace", |
| 4674 "", "Springfield", "IL", "91601", "US", ""); | 4674 "", "Springfield", "IL", "91601", "US", ""); |
| 4675 | 4675 |
| 4676 base::HistogramTester histogram_tester; | 4676 base::HistogramTester histogram_tester; |
| 4677 personal_data_->SaveImportedProfile(imported_profile); | 4677 personal_data_->SaveImportedProfile(imported_profile); |
| 4678 | 4678 |
| 4679 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4679 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4680 .WillOnce(QuitMainMessageLoop()); | 4680 .WillOnce(QuitMainMessageLoop()); |
| 4681 base::MessageLoop::current()->Run(); | 4681 base::MessageLoop::current()->Run(); |
| 4682 | 4682 |
| 4683 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); | 4683 std::vector<AutofillProfile*> profiles = |
| 4684 | 4684 personal_data_->GetProfilesToSuggest(); |
| 4685 // The |imported_profile| should have merged with |profile2|. |profile2| | 4685 // The |imported_profile| should have merged with |profile2|. |profile2| |
| 4686 // should then have been discarded because it is similar to the verified | 4686 // should then have been discarded because it is similar to the verified |
| 4687 // |profile1|. | 4687 // |profile1|. |
| 4688 ASSERT_EQ(1U, profiles.size()); | 4688 ASSERT_EQ(1U, profiles.size()); |
| 4689 // 2 profiles were considered for dedupe (profiles 1 and 2). | 4689 // 2 profiles were considered for dedupe (profiles 1 and 2). |
| 4690 histogram_tester.ExpectUniqueSample( | 4690 histogram_tester.ExpectUniqueSample( |
| 4691 "Autofill.NumberOfProfilesConsideredForDedupe", 2, 1); | 4691 "Autofill.NumberOfProfilesConsideredForDedupe", 2, 1); |
| 4692 // 1 profile was removed (|profile2|). | 4692 // 1 profile was removed (|profile2|). |
| 4693 histogram_tester.ExpectUniqueSample( | 4693 histogram_tester.ExpectUniqueSample( |
| 4694 "Autofill.NumberOfProfilesRemovedDuringDedupe", 1, 1); | 4694 "Autofill.NumberOfProfilesRemovedDuringDedupe", 1, 1); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4750 "", "Springfield", "IL", "91601", "US", ""); | 4750 "", "Springfield", "IL", "91601", "US", ""); |
| 4751 | 4751 |
| 4752 base::HistogramTester histogram_tester; | 4752 base::HistogramTester histogram_tester; |
| 4753 personal_data_->SaveImportedProfile(imported_profile); | 4753 personal_data_->SaveImportedProfile(imported_profile); |
| 4754 | 4754 |
| 4755 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4755 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4756 .WillOnce(QuitMainMessageLoop()); | 4756 .WillOnce(QuitMainMessageLoop()); |
| 4757 base::MessageLoop::current()->Run(); | 4757 base::MessageLoop::current()->Run(); |
| 4758 | 4758 |
| 4759 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); | 4759 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); |
| 4760 | |
| 4761 // The |imported_profile| should have merged with |profile1|. |profile1| | 4760 // The |imported_profile| should have merged with |profile1|. |profile1| |
| 4762 // should then have been discarded because it is similar to the verified | 4761 // should then have been discarded because it is similar to the verified |
| 4763 // |profile2|. | 4762 // |profile2|. |
| 4764 ASSERT_EQ(1U, profiles.size()); | 4763 ASSERT_EQ(1U, profiles.size()); |
| 4765 // 2 profiles were considered for dedupe (profiles 1 and 2). | 4764 // 2 profiles were considered for dedupe (profiles 1 and 2). |
| 4766 histogram_tester.ExpectUniqueSample( | 4765 histogram_tester.ExpectUniqueSample( |
| 4767 "Autofill.NumberOfProfilesConsideredForDedupe", 2, 1); | 4766 "Autofill.NumberOfProfilesConsideredForDedupe", 2, 1); |
| 4768 // 1 profile was removed (|profile1|). | 4767 // 1 profile was removed (|profile1|). |
| 4769 histogram_tester.ExpectUniqueSample( | 4768 histogram_tester.ExpectUniqueSample( |
| 4770 "Autofill.NumberOfProfilesRemovedDuringDedupe", 1, 1); | 4769 "Autofill.NumberOfProfilesRemovedDuringDedupe", 1, 1); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4865 EXPECT_LT(profile1.use_date() - TimeDelta::FromSeconds(2), | 4864 EXPECT_LT(profile1.use_date() - TimeDelta::FromSeconds(2), |
| 4866 profiles[0]->use_date()); | 4865 profiles[0]->use_date()); |
| 4867 EXPECT_GT(profile1.use_date() + TimeDelta::FromSeconds(2), | 4866 EXPECT_GT(profile1.use_date() + TimeDelta::FromSeconds(2), |
| 4868 profiles[0]->use_date()); | 4867 profiles[0]->use_date()); |
| 4869 EXPECT_LT(profile2.use_date() - TimeDelta::FromSeconds(2), | 4868 EXPECT_LT(profile2.use_date() - TimeDelta::FromSeconds(2), |
| 4870 profiles[1]->use_date()); | 4869 profiles[1]->use_date()); |
| 4871 EXPECT_GT(profile2.use_date() + TimeDelta::FromSeconds(2), | 4870 EXPECT_GT(profile2.use_date() + TimeDelta::FromSeconds(2), |
| 4872 profiles[1]->use_date()); | 4871 profiles[1]->use_date()); |
| 4873 } | 4872 } |
| 4874 | 4873 |
| 4874 // Tests that ApplyProfileUseDatesFix sets the use date of profiles from an |
| 4875 // incorrect value of 0 to [two weeks from now]. Also tests that SetProfiles |
| 4876 // does not modify any other profiles. |
| 4877 TEST_F(PersonalDataManagerTest, ApplyProfileUseDatesFix) { |
| 4878 // Set the kAutofillProfileUseDatesFixed pref to true so that the fix is not |
| 4879 // applied just yet. |
| 4880 personal_data_->pref_service_->SetBoolean( |
| 4881 prefs::kAutofillProfileUseDatesFixed, true); |
| 4882 |
| 4883 // Create a profile. The use date will be set to now automatically. |
| 4884 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 4885 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", |
| 4886 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", |
| 4887 "", "Springfield", "IL", "91601", "US", "12345678910"); |
| 4888 |
| 4889 // Create another profile and set its use date to the default value. |
| 4890 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| 4891 test::SetProfileInfo(&profile2, "Marge", "", "Simpson", |
| 4892 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", |
| 4893 "", "Springfield", "IL", "91601", "US", "12345678910"); |
| 4894 profile2.set_use_date(base::Time()); |
| 4895 |
| 4896 personal_data_->AddProfile(profile1); |
| 4897 personal_data_->AddProfile(profile2); |
| 4898 |
| 4899 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4900 .WillOnce(QuitMainMessageLoop()); |
| 4901 base::MessageLoop::current()->Run(); |
| 4902 |
| 4903 // Get a sorted list of profiles. |profile1| will be first and |profile2| will |
| 4904 // be second. |
| 4905 std::vector<AutofillProfile*> saved_profiles = |
| 4906 personal_data_->GetProfilesToSuggest(); |
| 4907 |
| 4908 ASSERT_EQ(2U, saved_profiles.size()); |
| 4909 |
| 4910 // The use dates should not have been modified. |
| 4911 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(1), |
| 4912 saved_profiles[0]->use_date()); |
| 4913 EXPECT_EQ(base::Time(), saved_profiles[1]->use_date()); |
| 4914 |
| 4915 // Set the pref to false to indicate the fix has never been run. |
| 4916 personal_data_->pref_service_->SetBoolean( |
| 4917 prefs::kAutofillProfileUseDatesFixed, false); |
| 4918 |
| 4919 personal_data_->ApplyProfileUseDatesFix(); |
| 4920 |
| 4921 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4922 .WillOnce(QuitMainMessageLoop()); |
| 4923 base::MessageLoop::current()->Run(); |
| 4924 |
| 4925 // Get a sorted list of profiles. |
| 4926 saved_profiles = personal_data_->GetProfilesToSuggest(); |
| 4927 |
| 4928 ASSERT_EQ(2U, saved_profiles.size()); |
| 4929 |
| 4930 // |profile1|'s use date should not have been modified. |
| 4931 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(1), |
| 4932 saved_profiles[0]->use_date()); |
| 4933 // |profile2|'s use date should have been set to two weeks before now. |
| 4934 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(15), |
| 4935 saved_profiles[1]->use_date()); |
| 4936 EXPECT_GE(base::Time::Now() - base::TimeDelta::FromDays(13), |
| 4937 saved_profiles[1]->use_date()); |
| 4938 } |
| 4939 |
| 4940 // Tests that ApplyProfileUseDatesFix does apply the fix if it's already been |
| 4941 // applied. |
| 4942 TEST_F(PersonalDataManagerTest, ApplyProfileUseDatesFix_NotAppliedTwice) { |
| 4943 // Set the kAutofillProfileUseDatesFixed pref which means the fix has already |
| 4944 // been applied. |
| 4945 personal_data_->pref_service_->SetBoolean( |
| 4946 prefs::kAutofillProfileUseDatesFixed, true); |
| 4947 |
| 4948 // Create two profiles. |
| 4949 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 4950 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", |
| 4951 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", |
| 4952 "", "Springfield", "IL", "91601", "US", "12345678910"); |
| 4953 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| 4954 test::SetProfileInfo(&profile2, "Marge", "", "Simpson", |
| 4955 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", |
| 4956 "", "Springfield", "IL", "91601", "US", "12345678910"); |
| 4957 profile2.set_use_date(base::Time()); |
| 4958 |
| 4959 personal_data_->AddProfile(profile1); |
| 4960 personal_data_->AddProfile(profile2); |
| 4961 |
| 4962 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4963 .WillOnce(QuitMainMessageLoop()); |
| 4964 base::MessageLoop::current()->Run(); |
| 4965 |
| 4966 // Get a sorted list of profiles. |profile1| will be first and |profile2| will |
| 4967 // be second. |
| 4968 std::vector<AutofillProfile*> saved_profiles = |
| 4969 personal_data_->GetProfilesToSuggest(); |
| 4970 |
| 4971 ASSERT_EQ(2U, saved_profiles.size()); |
| 4972 // The use dates should not have been modified. |
| 4973 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(1), |
| 4974 saved_profiles[0]->use_date()); |
| 4975 EXPECT_EQ(base::Time(), saved_profiles[1]->use_date()); |
| 4976 } |
| 4977 |
| 4875 } // namespace autofill | 4978 } // namespace autofill |
| OLD | NEW |