| 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> |
| 11 #include <map> | 11 #include <map> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <utility> | 14 #include <utility> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/feature_list.h" | 18 #include "base/feature_list.h" |
| 19 #include "base/files/scoped_temp_dir.h" | 19 #include "base/files/scoped_temp_dir.h" |
| 20 #include "base/guid.h" | 20 #include "base/guid.h" |
| 21 #include "base/metrics/field_trial.h" | 21 #include "base/metrics/field_trial.h" |
| 22 #include "base/run_loop.h" | 22 #include "base/run_loop.h" |
| 23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 24 #include "base/synchronization/waitable_event.h" | 24 #include "base/synchronization/waitable_event.h" |
| 25 #include "base/test/histogram_tester.h" | 25 #include "base/test/histogram_tester.h" |
| 26 #include "base/test/scoped_feature_list.h" |
| 26 #include "base/threading/thread_task_runner_handle.h" | 27 #include "base/threading/thread_task_runner_handle.h" |
| 27 #include "base/time/time.h" | 28 #include "base/time/time.h" |
| 28 #include "build/build_config.h" | 29 #include "build/build_config.h" |
| 29 #include "components/autofill/core/browser/autofill_experiments.h" | 30 #include "components/autofill/core/browser/autofill_experiments.h" |
| 30 #include "components/autofill/core/browser/autofill_profile.h" | 31 #include "components/autofill/core/browser/autofill_profile.h" |
| 31 #include "components/autofill/core/browser/autofill_test_utils.h" | 32 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 32 #include "components/autofill/core/browser/field_types.h" | 33 #include "components/autofill/core/browser/field_types.h" |
| 33 #include "components/autofill/core/browser/form_structure.h" | 34 #include "components/autofill/core/browser/form_structure.h" |
| 34 #include "components/autofill/core/browser/personal_data_manager_observer.h" | 35 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
| 35 #include "components/autofill/core/browser/webdata/autofill_table.h" | 36 #include "components/autofill/core/browser/webdata/autofill_table.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 web_database_, base::ThreadTaskRunnerHandle::Get(), | 135 web_database_, base::ThreadTaskRunnerHandle::Get(), |
| 135 base::ThreadTaskRunnerHandle::Get(), | 136 base::ThreadTaskRunnerHandle::Get(), |
| 136 WebDataServiceBase::ProfileErrorCallback()); | 137 WebDataServiceBase::ProfileErrorCallback()); |
| 137 autofill_database_service_->Init(); | 138 autofill_database_service_->Init(); |
| 138 | 139 |
| 139 test::DisableSystemServices(prefs_.get()); | 140 test::DisableSystemServices(prefs_.get()); |
| 140 ResetPersonalDataManager(USER_MODE_NORMAL); | 141 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 141 | 142 |
| 142 // There are no field trials enabled by default. | 143 // There are no field trials enabled by default. |
| 143 field_trial_list_.reset(); | 144 field_trial_list_.reset(); |
| 144 | 145 scoped_feature_list_.reset(); |
| 145 // There are no features enabled by default. | |
| 146 base::FeatureList::ClearInstanceForTesting(); | |
| 147 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | |
| 148 base::FeatureList::SetInstance(std::move(feature_list)); | |
| 149 | 146 |
| 150 // Reset the deduping pref to its default value. | 147 // Reset the deduping pref to its default value. |
| 151 personal_data_->pref_service_->SetInteger( | 148 personal_data_->pref_service_->SetInteger( |
| 152 prefs::kAutofillLastVersionDeduped, 0); | 149 prefs::kAutofillLastVersionDeduped, 0); |
| 153 personal_data_->pref_service_->SetBoolean( | 150 personal_data_->pref_service_->SetBoolean( |
| 154 prefs::kAutofillProfileUseDatesFixed, false); | 151 prefs::kAutofillProfileUseDatesFixed, false); |
| 155 } | 152 } |
| 156 | 153 |
| 157 void TearDown() override { | 154 void TearDown() override { |
| 158 // Order of destruction is important as AutofillManager relies on | 155 // Order of destruction is important as AutofillManager relies on |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 189 } |
| 193 | 190 |
| 194 void EnableWalletCardImport() { | 191 void EnableWalletCardImport() { |
| 195 signin_manager_->SetAuthenticatedAccountInfo("12345", | 192 signin_manager_->SetAuthenticatedAccountInfo("12345", |
| 196 "syncuser@example.com"); | 193 "syncuser@example.com"); |
| 197 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 194 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 198 switches::kEnableOfferStoreUnmaskedWalletCards); | 195 switches::kEnableOfferStoreUnmaskedWalletCards); |
| 199 } | 196 } |
| 200 | 197 |
| 201 void EnableAutofillProfileCleanup() { | 198 void EnableAutofillProfileCleanup() { |
| 202 base::FeatureList::ClearInstanceForTesting(); | 199 scoped_feature_list_.reset(new base::test::ScopedFeatureList); |
| 203 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 200 scoped_feature_list_->InitAndEnableFeature(kAutofillProfileCleanup); |
| 204 feature_list->InitializeFromCommandLine(kAutofillProfileCleanup.name, | |
| 205 std::string()); | |
| 206 base::FeatureList::SetInstance(std::move(feature_list)); | |
| 207 personal_data_->is_autofill_profile_dedupe_pending_ = true; | 201 personal_data_->is_autofill_profile_dedupe_pending_ = true; |
| 208 } | 202 } |
| 209 | 203 |
| 210 void SetupReferenceProfile() { | 204 void SetupReferenceProfile() { |
| 211 ASSERT_EQ(0U, personal_data_->GetProfiles().size()); | 205 ASSERT_EQ(0U, personal_data_->GetProfiles().size()); |
| 212 | 206 |
| 213 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com"); | 207 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com"); |
| 214 test::SetProfileInfo(&profile, "Marion", "Mitchell", "Morrison", | 208 test::SetProfileInfo(&profile, "Marion", "Mitchell", "Morrison", |
| 215 "johnwayne@me.xyz", "Fox", "123 Zoo St", "unit 5", | 209 "johnwayne@me.xyz", "Fox", "123 Zoo St", "unit 5", |
| 216 "Hollywood", "CA", "91601", "US", "12345678910"); | 210 "Hollywood", "CA", "91601", "US", "12345678910"); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 std::unique_ptr<FakeSigninManagerBase> signin_manager_; | 355 std::unique_ptr<FakeSigninManagerBase> signin_manager_; |
| 362 std::unique_ptr<TestSigninClient> signin_client_; | 356 std::unique_ptr<TestSigninClient> signin_client_; |
| 363 scoped_refptr<AutofillWebDataService> autofill_database_service_; | 357 scoped_refptr<AutofillWebDataService> autofill_database_service_; |
| 364 scoped_refptr<WebDatabaseService> web_database_; | 358 scoped_refptr<WebDatabaseService> web_database_; |
| 365 AutofillTable* autofill_table_; // weak ref | 359 AutofillTable* autofill_table_; // weak ref |
| 366 PersonalDataLoadedObserverMock personal_data_observer_; | 360 PersonalDataLoadedObserverMock personal_data_observer_; |
| 367 std::unique_ptr<PersonalDataManager> personal_data_; | 361 std::unique_ptr<PersonalDataManager> personal_data_; |
| 368 | 362 |
| 369 std::unique_ptr<base::FieldTrialList> field_trial_list_; | 363 std::unique_ptr<base::FieldTrialList> field_trial_list_; |
| 370 scoped_refptr<base::FieldTrial> field_trial_; | 364 scoped_refptr<base::FieldTrial> field_trial_; |
| 365 std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list_; |
| 371 }; | 366 }; |
| 372 | 367 |
| 373 TEST_F(PersonalDataManagerTest, AddProfile) { | 368 TEST_F(PersonalDataManagerTest, AddProfile) { |
| 374 // Add profile0 to the database. | 369 // Add profile0 to the database. |
| 375 AutofillProfile profile0(test::GetFullProfile()); | 370 AutofillProfile profile0(test::GetFullProfile()); |
| 376 profile0.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); | 371 profile0.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); |
| 377 personal_data_->AddProfile(profile0); | 372 personal_data_->AddProfile(profile0); |
| 378 | 373 |
| 379 // Reload the database. | 374 // Reload the database. |
| 380 ResetPersonalDataManager(USER_MODE_NORMAL); | 375 ResetPersonalDataManager(USER_MODE_NORMAL); |
| (...skipping 4814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5195 // The profiles should have been deduped | 5190 // The profiles should have been deduped |
| 5196 EXPECT_EQ(1U, profiles.size()); | 5191 EXPECT_EQ(1U, profiles.size()); |
| 5197 | 5192 |
| 5198 // Add another duplicate profile. | 5193 // Add another duplicate profile. |
| 5199 AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com"); | 5194 AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com"); |
| 5200 test::SetProfileInfo(&profile3, "Homer", "J", "Simpson", | 5195 test::SetProfileInfo(&profile3, "Homer", "J", "Simpson", |
| 5201 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", | 5196 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| 5202 "", "Springfield", "IL", "91601", "", ""); | 5197 "", "Springfield", "IL", "91601", "", ""); |
| 5203 | 5198 |
| 5204 // Disable the profile cleanup before adding |profile3|. | 5199 // Disable the profile cleanup before adding |profile3|. |
| 5205 base::FeatureList::ClearInstanceForTesting(); | 5200 scoped_feature_list_.reset(); |
| 5206 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | |
| 5207 base::FeatureList::SetInstance(std::move(feature_list)); | |
| 5208 | 5201 |
| 5209 personal_data_->AddProfile(profile3); | 5202 personal_data_->AddProfile(profile3); |
| 5210 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5203 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5211 .WillOnce(QuitMainMessageLoop()); | 5204 .WillOnce(QuitMainMessageLoop()); |
| 5212 base::RunLoop().Run(); | 5205 base::RunLoop().Run(); |
| 5213 | 5206 |
| 5214 // Make sure |profile3| was saved. | 5207 // Make sure |profile3| was saved. |
| 5215 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); | 5208 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
| 5216 | 5209 |
| 5217 // Re-enable the profile cleanup now that the profile was added. | 5210 // Re-enable the profile cleanup now that the profile was added. |
| 5218 EnableAutofillProfileCleanup(); | 5211 EnableAutofillProfileCleanup(); |
| 5219 | 5212 |
| 5220 // The deduping routine should not be run. | 5213 // The deduping routine should not be run. |
| 5221 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); | 5214 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); |
| 5222 | 5215 |
| 5223 // The two duplicate profiles should still be present. | 5216 // The two duplicate profiles should still be present. |
| 5224 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); | 5217 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
| 5225 } | 5218 } |
| 5226 | 5219 |
| 5227 } // namespace autofill | 5220 } // namespace autofill |
| OLD | NEW |