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()); |
4605 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4607 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
4606 .WillOnce(QuitMainMessageLoop()); | 4608 .WillOnce(QuitMainMessageLoop()); |
4607 base::RunLoop().Run(); | 4609 base::RunLoop().Run(); |
4608 | 4610 |
4609 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); | 4611 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); |
4610 | 4612 |
4611 // |profile1| should have been merged into |profile2| which should then have | 4613 // |profile1| should have been merged into |profile2| which should then have |
4612 // been merged into |profile3|. Therefore there should only be 1 saved | 4614 // been merged into |profile3|. Therefore there should only be 1 saved |
4613 // profile. | 4615 // profile. |
4614 ASSERT_EQ(1U, profiles.size()); | 4616 ASSERT_EQ(1U, profiles.size()); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4687 | 4689 |
4688 // Make sure the 3 profiles were saved. | 4690 // Make sure the 3 profiles were saved. |
4689 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); | 4691 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); |
4690 | 4692 |
4691 // Enable the profile cleanup now. Otherwise it would be triggered by the | 4693 // Enable the profile cleanup now. Otherwise it would be triggered by the |
4692 // calls to AddProfile. | 4694 // calls to AddProfile. |
4693 EnableAutofillProfileCleanup(); | 4695 EnableAutofillProfileCleanup(); |
4694 | 4696 |
4695 base::HistogramTester histogram_tester; | 4697 base::HistogramTester histogram_tester; |
4696 | 4698 |
4697 personal_data_->ApplyDedupingRoutine(); | 4699 EXPECT_TRUE(personal_data_->ApplyDedupingRoutine()); |
4698 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4700 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
4699 .WillOnce(QuitMainMessageLoop()); | 4701 .WillOnce(QuitMainMessageLoop()); |
4700 base::RunLoop().Run(); | 4702 base::RunLoop().Run(); |
4701 | 4703 |
4702 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); | 4704 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); |
4703 | 4705 |
4704 // |profile2| should have merged with |profile3|. |profile3| | 4706 // |profile2| should have merged with |profile3|. |profile3| |
4705 // should then have been discarded because it is similar to the verified | 4707 // should then have been discarded because it is similar to the verified |
4706 // |profile1|. | 4708 // |profile1|. |
4707 ASSERT_EQ(1U, profiles.size()); | 4709 ASSERT_EQ(1U, profiles.size()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4759 | 4761 |
4760 // Make sure the 3 profiles were saved. | 4762 // Make sure the 3 profiles were saved. |
4761 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); | 4763 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); |
4762 | 4764 |
4763 // Enable the profile cleanup now. Otherwise it would be triggered by the | 4765 // Enable the profile cleanup now. Otherwise it would be triggered by the |
4764 // calls to AddProfile. | 4766 // calls to AddProfile. |
4765 EnableAutofillProfileCleanup(); | 4767 EnableAutofillProfileCleanup(); |
4766 | 4768 |
4767 base::HistogramTester histogram_tester; | 4769 base::HistogramTester histogram_tester; |
4768 | 4770 |
4769 personal_data_->ApplyDedupingRoutine(); | 4771 EXPECT_TRUE(personal_data_->ApplyDedupingRoutine()); |
4770 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4772 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
4771 .WillOnce(QuitMainMessageLoop()); | 4773 .WillOnce(QuitMainMessageLoop()); |
4772 base::RunLoop().Run(); | 4774 base::RunLoop().Run(); |
4773 | 4775 |
4774 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); | 4776 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); |
4775 | 4777 |
4776 // |profile1| should have merged with |profile2|. |profile2| | 4778 // |profile1| should have merged with |profile2|. |profile2| |
4777 // should then have been discarded because it is similar to the verified | 4779 // should then have been discarded because it is similar to the verified |
4778 // |profile3|. | 4780 // |profile3|. |
4779 ASSERT_EQ(1U, profiles.size()); | 4781 ASSERT_EQ(1U, profiles.size()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4830 | 4832 |
4831 // Make sure the 3 profiles were saved. | 4833 // Make sure the 3 profiles were saved. |
4832 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); | 4834 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); |
4833 | 4835 |
4834 // Enable the profile cleanup now. Otherwise it would be triggered by the | 4836 // Enable the profile cleanup now. Otherwise it would be triggered by the |
4835 // calls to AddProfile. | 4837 // calls to AddProfile. |
4836 EnableAutofillProfileCleanup(); | 4838 EnableAutofillProfileCleanup(); |
4837 | 4839 |
4838 base::HistogramTester histogram_tester; | 4840 base::HistogramTester histogram_tester; |
4839 | 4841 |
4840 personal_data_->ApplyDedupingRoutine(); | 4842 EXPECT_TRUE(personal_data_->ApplyDedupingRoutine()); |
4841 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4843 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
4842 .WillOnce(QuitMainMessageLoop()); | 4844 .WillOnce(QuitMainMessageLoop()); |
4843 base::RunLoop().Run(); | 4845 base::RunLoop().Run(); |
4844 | 4846 |
4845 // Get the profiles, sorted by frecency to have a deterministic order. | 4847 // Get the profiles, sorted by frecency to have a deterministic order. |
4846 std::vector<AutofillProfile*> profiles = | 4848 std::vector<AutofillProfile*> profiles = |
4847 personal_data_->GetProfilesToSuggest(); | 4849 personal_data_->GetProfilesToSuggest(); |
4848 | 4850 |
4849 // |profile1| should have been discarded because the saved profile with the | 4851 // |profile1| should have been discarded because the saved profile with the |
4850 // highest frecency score is verified (|profile2|). Therefore, |profile1|'s | 4852 // highest frecency score is verified (|profile2|). Therefore, |profile1|'s |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5060 | 5062 |
5061 // Enable the profile cleanup now. Otherwise it would be triggered by the | 5063 // Enable the profile cleanup now. Otherwise it would be triggered by the |
5062 // calls to AddProfile. | 5064 // calls to AddProfile. |
5063 EnableAutofillProfileCleanup(); | 5065 EnableAutofillProfileCleanup(); |
5064 | 5066 |
5065 base::HistogramTester histogram_tester; | 5067 base::HistogramTester histogram_tester; |
5066 | 5068 |
5067 // |Homer1| should get merged into |Homer2| which should then be merged into | 5069 // |Homer1| should get merged into |Homer2| which should then be merged into |
5068 // |Homer3|. |Marge2| should be discarded in favor of |Marge1| which is | 5070 // |Homer3|. |Marge2| should be discarded in favor of |Marge1| which is |
5069 // verified. |Homer4| and |Barney| should not be deduped at all. | 5071 // verified. |Homer4| and |Barney| should not be deduped at all. |
5070 personal_data_->ApplyDedupingRoutine(); | 5072 EXPECT_TRUE(personal_data_->ApplyDedupingRoutine()); |
5071 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5073 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
5072 .WillOnce(QuitMainMessageLoop()); | 5074 .WillOnce(QuitMainMessageLoop()); |
5073 base::RunLoop().Run(); | 5075 base::RunLoop().Run(); |
5074 | 5076 |
5075 // Get the profiles, sorted by frecency to have a deterministic order. | 5077 // Get the profiles, sorted by frecency to have a deterministic order. |
5076 std::vector<AutofillProfile*> profiles = | 5078 std::vector<AutofillProfile*> profiles = |
5077 personal_data_->GetProfilesToSuggest(); | 5079 personal_data_->GetProfilesToSuggest(); |
5078 | 5080 |
5079 // The 2 duplicates Homer home profiles with the higher frecency and the | 5081 // The 2 duplicates Homer home profiles with the higher frecency and the |
5080 // unverified Marge profile should have been deduped. | 5082 // unverified Marge profile should have been deduped. |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5216 EnableAutofillProfileCleanup(); | 5218 EnableAutofillProfileCleanup(); |
5217 | 5219 |
5218 // The deduping routine should not be run. | 5220 // The deduping routine should not be run. |
5219 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); | 5221 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); |
5220 | 5222 |
5221 // The two duplicate profiles should still be present. | 5223 // The two duplicate profiles should still be present. |
5222 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); | 5224 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
5223 } | 5225 } |
5224 | 5226 |
5225 } // namespace autofill | 5227 } // namespace autofill |
OLD | NEW |