| 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 void ResetPersonalDataManager(UserMode user_mode) { | 169 void ResetPersonalDataManager(UserMode user_mode) { |
| 170 bool is_incognito = (user_mode == USER_MODE_INCOGNITO); | 170 bool is_incognito = (user_mode == USER_MODE_INCOGNITO); |
| 171 personal_data_.reset(new PersonalDataManager("en")); | 171 personal_data_.reset(new PersonalDataManager("en")); |
| 172 personal_data_->Init( | 172 personal_data_->Init( |
| 173 scoped_refptr<AutofillWebDataService>(autofill_database_service_), | 173 scoped_refptr<AutofillWebDataService>(autofill_database_service_), |
| 174 prefs_.get(), | 174 prefs_.get(), |
| 175 account_tracker_.get(), | 175 account_tracker_.get(), |
| 176 signin_manager_.get(), | 176 signin_manager_.get(), |
| 177 is_incognito); | 177 is_incognito); |
| 178 personal_data_->AddObserver(&personal_data_observer_); | 178 personal_data_->AddObserver(&personal_data_observer_); |
| 179 personal_data_->OnSyncServiceConfigured(nullptr); |
| 179 | 180 |
| 180 // Verify that the web database has been updated and the notification sent. | 181 // Verify that the web database has been updated and the notification sent. |
| 181 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 182 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 182 .WillOnce(QuitMainMessageLoop()); | 183 .WillOnce(QuitMainMessageLoop()); |
| 183 base::RunLoop().Run(); | 184 base::RunLoop().Run(); |
| 184 } | 185 } |
| 185 | 186 |
| 186 void ResetProfiles() { | 187 void ResetProfiles() { |
| 187 std::vector<AutofillProfile> empty_profiles; | 188 std::vector<AutofillProfile> empty_profiles; |
| 188 personal_data_->SetProfiles(&empty_profiles); | 189 personal_data_->SetProfiles(&empty_profiles); |
| 189 } | 190 } |
| 190 | 191 |
| 191 void EnableWalletCardImport() { | 192 void EnableWalletCardImport() { |
| 192 signin_manager_->SetAuthenticatedAccountInfo("12345", | 193 signin_manager_->SetAuthenticatedAccountInfo("12345", |
| 193 "syncuser@example.com"); | 194 "syncuser@example.com"); |
| 194 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 195 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 195 switches::kEnableOfferStoreUnmaskedWalletCards); | 196 switches::kEnableOfferStoreUnmaskedWalletCards); |
| 196 } | 197 } |
| 197 | 198 |
| 198 void EnableAutofillProfileCleanup() { | 199 void EnableAutofillProfileCleanup() { |
| 199 base::FeatureList::ClearInstanceForTesting(); | 200 base::FeatureList::ClearInstanceForTesting(); |
| 200 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 201 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 201 feature_list->InitializeFromCommandLine(kAutofillProfileCleanup.name, | 202 feature_list->InitializeFromCommandLine(kAutofillProfileCleanup.name, |
| 202 std::string()); | 203 std::string()); |
| 203 base::FeatureList::SetInstance(std::move(feature_list)); | 204 base::FeatureList::SetInstance(std::move(feature_list)); |
| 205 personal_data_->is_autofill_profile_dedupe_pending_ = true; |
| 204 } | 206 } |
| 205 | 207 |
| 206 void SetupReferenceProfile() { | 208 void SetupReferenceProfile() { |
| 207 ASSERT_EQ(0U, personal_data_->GetProfiles().size()); | 209 ASSERT_EQ(0U, personal_data_->GetProfiles().size()); |
| 208 | 210 |
| 209 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com"); | 211 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com"); |
| 210 test::SetProfileInfo(&profile, "Marion", "Mitchell", "Morrison", | 212 test::SetProfileInfo(&profile, "Marion", "Mitchell", "Morrison", |
| 211 "johnwayne@me.xyz", "Fox", "123 Zoo St", "unit 5", | 213 "johnwayne@me.xyz", "Fox", "123 Zoo St", "unit 5", |
| 212 "Hollywood", "CA", "91601", "US", "12345678910"); | 214 "Hollywood", "CA", "91601", "US", "12345678910"); |
| 213 personal_data_->AddProfile(profile); | 215 personal_data_->AddProfile(profile); |
| (...skipping 4380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4594 | 4596 |
| 4595 // Make sure the 3 profiles were saved; | 4597 // Make sure the 3 profiles were saved; |
| 4596 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); | 4598 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); |
| 4597 | 4599 |
| 4598 // Enable the profile cleanup now. Otherwise it would be triggered by the | 4600 // Enable the profile cleanup now. Otherwise it would be triggered by the |
| 4599 // calls to AddProfile. | 4601 // calls to AddProfile. |
| 4600 EnableAutofillProfileCleanup(); | 4602 EnableAutofillProfileCleanup(); |
| 4601 | 4603 |
| 4602 base::HistogramTester histogram_tester; | 4604 base::HistogramTester histogram_tester; |
| 4603 | 4605 |
| 4604 personal_data_->ApplyDedupingRoutine(); | 4606 EXPECT_TRUE(personal_data_->ApplyDedupingRoutine()); |
| 4607 personal_data_->Refresh(); |
| 4605 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4608 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4606 .WillOnce(QuitMainMessageLoop()); | 4609 .WillOnce(QuitMainMessageLoop()); |
| 4607 base::RunLoop().Run(); | 4610 base::RunLoop().Run(); |
| 4608 | 4611 |
| 4609 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); | 4612 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); |
| 4610 | 4613 |
| 4611 // |profile1| should have been merged into |profile2| which should then have | 4614 // |profile1| should have been merged into |profile2| which should then have |
| 4612 // been merged into |profile3|. Therefore there should only be 1 saved | 4615 // been merged into |profile3|. Therefore there should only be 1 saved |
| 4613 // profile. | 4616 // profile. |
| 4614 ASSERT_EQ(1U, profiles.size()); | 4617 ASSERT_EQ(1U, profiles.size()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4687 | 4690 |
| 4688 // Make sure the 3 profiles were saved. | 4691 // Make sure the 3 profiles were saved. |
| 4689 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); | 4692 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); |
| 4690 | 4693 |
| 4691 // Enable the profile cleanup now. Otherwise it would be triggered by the | 4694 // Enable the profile cleanup now. Otherwise it would be triggered by the |
| 4692 // calls to AddProfile. | 4695 // calls to AddProfile. |
| 4693 EnableAutofillProfileCleanup(); | 4696 EnableAutofillProfileCleanup(); |
| 4694 | 4697 |
| 4695 base::HistogramTester histogram_tester; | 4698 base::HistogramTester histogram_tester; |
| 4696 | 4699 |
| 4697 personal_data_->ApplyDedupingRoutine(); | 4700 EXPECT_TRUE(personal_data_->ApplyDedupingRoutine()); |
| 4701 personal_data_->Refresh(); |
| 4698 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4702 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4699 .WillOnce(QuitMainMessageLoop()); | 4703 .WillOnce(QuitMainMessageLoop()); |
| 4700 base::RunLoop().Run(); | 4704 base::RunLoop().Run(); |
| 4701 | 4705 |
| 4702 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); | 4706 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); |
| 4703 | 4707 |
| 4704 // |profile2| should have merged with |profile3|. |profile3| | 4708 // |profile2| should have merged with |profile3|. |profile3| |
| 4705 // should then have been discarded because it is similar to the verified | 4709 // should then have been discarded because it is similar to the verified |
| 4706 // |profile1|. | 4710 // |profile1|. |
| 4707 ASSERT_EQ(1U, profiles.size()); | 4711 ASSERT_EQ(1U, profiles.size()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4759 | 4763 |
| 4760 // Make sure the 3 profiles were saved. | 4764 // Make sure the 3 profiles were saved. |
| 4761 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); | 4765 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); |
| 4762 | 4766 |
| 4763 // Enable the profile cleanup now. Otherwise it would be triggered by the | 4767 // Enable the profile cleanup now. Otherwise it would be triggered by the |
| 4764 // calls to AddProfile. | 4768 // calls to AddProfile. |
| 4765 EnableAutofillProfileCleanup(); | 4769 EnableAutofillProfileCleanup(); |
| 4766 | 4770 |
| 4767 base::HistogramTester histogram_tester; | 4771 base::HistogramTester histogram_tester; |
| 4768 | 4772 |
| 4769 personal_data_->ApplyDedupingRoutine(); | 4773 EXPECT_TRUE(personal_data_->ApplyDedupingRoutine()); |
| 4774 personal_data_->Refresh(); |
| 4770 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4775 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4771 .WillOnce(QuitMainMessageLoop()); | 4776 .WillOnce(QuitMainMessageLoop()); |
| 4772 base::RunLoop().Run(); | 4777 base::RunLoop().Run(); |
| 4773 | 4778 |
| 4774 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); | 4779 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); |
| 4775 | 4780 |
| 4776 // |profile1| should have merged with |profile2|. |profile2| | 4781 // |profile1| should have merged with |profile2|. |profile2| |
| 4777 // should then have been discarded because it is similar to the verified | 4782 // should then have been discarded because it is similar to the verified |
| 4778 // |profile3|. | 4783 // |profile3|. |
| 4779 ASSERT_EQ(1U, profiles.size()); | 4784 ASSERT_EQ(1U, profiles.size()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4830 | 4835 |
| 4831 // Make sure the 3 profiles were saved. | 4836 // Make sure the 3 profiles were saved. |
| 4832 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); | 4837 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); |
| 4833 | 4838 |
| 4834 // Enable the profile cleanup now. Otherwise it would be triggered by the | 4839 // Enable the profile cleanup now. Otherwise it would be triggered by the |
| 4835 // calls to AddProfile. | 4840 // calls to AddProfile. |
| 4836 EnableAutofillProfileCleanup(); | 4841 EnableAutofillProfileCleanup(); |
| 4837 | 4842 |
| 4838 base::HistogramTester histogram_tester; | 4843 base::HistogramTester histogram_tester; |
| 4839 | 4844 |
| 4840 personal_data_->ApplyDedupingRoutine(); | 4845 EXPECT_TRUE(personal_data_->ApplyDedupingRoutine()); |
| 4846 personal_data_->Refresh(); |
| 4841 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4847 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4842 .WillOnce(QuitMainMessageLoop()); | 4848 .WillOnce(QuitMainMessageLoop()); |
| 4843 base::RunLoop().Run(); | 4849 base::RunLoop().Run(); |
| 4844 | 4850 |
| 4845 // Get the profiles, sorted by frecency to have a deterministic order. | 4851 // Get the profiles, sorted by frecency to have a deterministic order. |
| 4846 std::vector<AutofillProfile*> profiles = | 4852 std::vector<AutofillProfile*> profiles = |
| 4847 personal_data_->GetProfilesToSuggest(); | 4853 personal_data_->GetProfilesToSuggest(); |
| 4848 | 4854 |
| 4849 // |profile1| should have been discarded because the saved profile with the | 4855 // |profile1| should have been discarded because the saved profile with the |
| 4850 // highest frecency score is verified (|profile2|). Therefore, |profile1|'s | 4856 // highest frecency score is verified (|profile2|). Therefore, |profile1|'s |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5060 | 5066 |
| 5061 // Enable the profile cleanup now. Otherwise it would be triggered by the | 5067 // Enable the profile cleanup now. Otherwise it would be triggered by the |
| 5062 // calls to AddProfile. | 5068 // calls to AddProfile. |
| 5063 EnableAutofillProfileCleanup(); | 5069 EnableAutofillProfileCleanup(); |
| 5064 | 5070 |
| 5065 base::HistogramTester histogram_tester; | 5071 base::HistogramTester histogram_tester; |
| 5066 | 5072 |
| 5067 // |Homer1| should get merged into |Homer2| which should then be merged into | 5073 // |Homer1| should get merged into |Homer2| which should then be merged into |
| 5068 // |Homer3|. |Marge2| should be discarded in favor of |Marge1| which is | 5074 // |Homer3|. |Marge2| should be discarded in favor of |Marge1| which is |
| 5069 // verified. |Homer4| and |Barney| should not be deduped at all. | 5075 // verified. |Homer4| and |Barney| should not be deduped at all. |
| 5070 personal_data_->ApplyDedupingRoutine(); | 5076 EXPECT_TRUE(personal_data_->ApplyDedupingRoutine()); |
| 5077 personal_data_->Refresh(); |
| 5071 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5078 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5072 .WillOnce(QuitMainMessageLoop()); | 5079 .WillOnce(QuitMainMessageLoop()); |
| 5073 base::RunLoop().Run(); | 5080 base::RunLoop().Run(); |
| 5074 | 5081 |
| 5075 // Get the profiles, sorted by frecency to have a deterministic order. | 5082 // Get the profiles, sorted by frecency to have a deterministic order. |
| 5076 std::vector<AutofillProfile*> profiles = | 5083 std::vector<AutofillProfile*> profiles = |
| 5077 personal_data_->GetProfilesToSuggest(); | 5084 personal_data_->GetProfilesToSuggest(); |
| 5078 | 5085 |
| 5079 // The 2 duplicates Homer home profiles with the higher frecency and the | 5086 // The 2 duplicates Homer home profiles with the higher frecency and the |
| 5080 // unverified Marge profile should have been deduped. | 5087 // unverified Marge profile should have been deduped. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5177 base::RunLoop().Run(); | 5184 base::RunLoop().Run(); |
| 5178 | 5185 |
| 5179 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); | 5186 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
| 5180 | 5187 |
| 5181 // Enable the profile cleanup now. Otherwise it would be triggered by the | 5188 // Enable the profile cleanup now. Otherwise it would be triggered by the |
| 5182 // calls to AddProfile. | 5189 // calls to AddProfile. |
| 5183 EnableAutofillProfileCleanup(); | 5190 EnableAutofillProfileCleanup(); |
| 5184 | 5191 |
| 5185 // The deduping routine should be run a first time. | 5192 // The deduping routine should be run a first time. |
| 5186 EXPECT_TRUE(personal_data_->ApplyDedupingRoutine()); | 5193 EXPECT_TRUE(personal_data_->ApplyDedupingRoutine()); |
| 5194 personal_data_->Refresh(); |
| 5187 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5195 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5188 .WillOnce(QuitMainMessageLoop()); | 5196 .WillOnce(QuitMainMessageLoop()); |
| 5189 base::RunLoop().Run(); | 5197 base::RunLoop().Run(); |
| 5190 | 5198 |
| 5191 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); | 5199 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); |
| 5192 | 5200 |
| 5193 // The profiles should have been deduped | 5201 // The profiles should have been deduped |
| 5194 EXPECT_EQ(1U, profiles.size()); | 5202 EXPECT_EQ(1U, profiles.size()); |
| 5195 | 5203 |
| 5196 // Add another duplicate profile. | 5204 // Add another duplicate profile. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 5210 base::RunLoop().Run(); | 5218 base::RunLoop().Run(); |
| 5211 | 5219 |
| 5212 // Make sure |profile3| was saved. | 5220 // Make sure |profile3| was saved. |
| 5213 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); | 5221 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
| 5214 | 5222 |
| 5215 // Re-enable the profile cleanup now that the profile was added. | 5223 // Re-enable the profile cleanup now that the profile was added. |
| 5216 EnableAutofillProfileCleanup(); | 5224 EnableAutofillProfileCleanup(); |
| 5217 | 5225 |
| 5218 // The deduping routine should not be run. | 5226 // The deduping routine should not be run. |
| 5219 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); | 5227 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); |
| 5228 personal_data_->Refresh(); |
| 5220 | 5229 |
| 5221 // The two duplicate profiles should still be present. | 5230 // The two duplicate profiles should still be present. |
| 5222 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); | 5231 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
| 5223 } | 5232 } |
| 5224 | 5233 |
| 5225 } // namespace autofill | 5234 } // namespace autofill |
| OLD | NEW |