| 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 <vector> | 15 #include <vector> |
| 15 | 16 |
| 16 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/feature_list.h" |
| 17 #include "base/files/scoped_temp_dir.h" | 19 #include "base/files/scoped_temp_dir.h" |
| 18 #include "base/guid.h" | 20 #include "base/guid.h" |
| 19 #include "base/metrics/field_trial.h" | 21 #include "base/metrics/field_trial.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/synchronization/waitable_event.h" | 23 #include "base/synchronization/waitable_event.h" |
| 22 #include "base/threading/thread_task_runner_handle.h" | 24 #include "base/threading/thread_task_runner_handle.h" |
| 23 #include "base/time/time.h" | 25 #include "base/time/time.h" |
| 24 #include "build/build_config.h" | 26 #include "build/build_config.h" |
| 25 #include "components/autofill/core/browser/autofill_experiments.h" | 27 #include "components/autofill/core/browser/autofill_experiments.h" |
| 26 #include "components/autofill/core/browser/autofill_profile.h" | 28 #include "components/autofill/core/browser/autofill_profile.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 personal_data_->SetProfiles(&empty_profiles); | 177 personal_data_->SetProfiles(&empty_profiles); |
| 176 } | 178 } |
| 177 | 179 |
| 178 void EnableWalletCardImport() { | 180 void EnableWalletCardImport() { |
| 179 signin_manager_->SetAuthenticatedAccountInfo("12345", | 181 signin_manager_->SetAuthenticatedAccountInfo("12345", |
| 180 "syncuser@example.com"); | 182 "syncuser@example.com"); |
| 181 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 183 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 182 switches::kEnableOfferStoreUnmaskedWalletCards); | 184 switches::kEnableOfferStoreUnmaskedWalletCards); |
| 183 } | 185 } |
| 184 | 186 |
| 187 void EnableAutofillProfileCleanup() { |
| 188 base::FeatureList::ClearInstanceForTesting(); |
| 189 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 190 feature_list->InitializeFromCommandLine(kAutofillProfileCleanup.name, |
| 191 std::string()); |
| 192 base::FeatureList::SetInstance(std::move(feature_list)); |
| 193 } |
| 194 |
| 185 void SetupReferenceProfile() { | 195 void SetupReferenceProfile() { |
| 186 ASSERT_EQ(0U, personal_data_->GetProfiles().size()); | 196 ASSERT_EQ(0U, personal_data_->GetProfiles().size()); |
| 187 | 197 |
| 188 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com"); | 198 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com"); |
| 189 test::SetProfileInfo(&profile, "Marion", "Mitchell", "Morrison", | 199 test::SetProfileInfo(&profile, "Marion", "Mitchell", "Morrison", |
| 190 "johnwayne@me.xyz", "Fox", "123 Zoo St", "unit 5", | 200 "johnwayne@me.xyz", "Fox", "123 Zoo St", "unit 5", |
| 191 "Hollywood", "CA", "91601", "US", "12345678910"); | 201 "Hollywood", "CA", "91601", "US", "12345678910"); |
| 192 personal_data_->AddProfile(profile); | 202 personal_data_->AddProfile(profile); |
| 193 | 203 |
| 194 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 204 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| (...skipping 4189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4384 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), | 4394 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), |
| 4385 base::Time::Now() - profile.use_date()); | 4395 base::Time::Now() - profile.use_date()); |
| 4386 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), | 4396 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), |
| 4387 base::Time::Now() - profile.modification_date()); | 4397 base::Time::Now() - profile.modification_date()); |
| 4388 } | 4398 } |
| 4389 | 4399 |
| 4390 // Tests that using a profile results in a merge of with all similar profiles | 4400 // Tests that using a profile results in a merge of with all similar profiles |
| 4391 // and that all but the resulting profile gets deleted. Also tests that | 4401 // and that all but the resulting profile gets deleted. Also tests that |
| 4392 // non-similar profiles are not affected by the merge or the delete. | 4402 // non-similar profiles are not affected by the merge or the delete. |
| 4393 TEST_F(PersonalDataManagerTest, DedupeOnInsert) { | 4403 TEST_F(PersonalDataManagerTest, DedupeOnInsert) { |
| 4404 EnableAutofillProfileCleanup(); |
| 4394 // Create saved profiles. | 4405 // Create saved profiles. |
| 4395 // Create two very similar profiles that should be deduped. The first one has | 4406 // Create two very similar profiles that should be deduped. The first one has |
| 4396 // no company name, while the second has one. The second profile also has | 4407 // no company name, while the second has one. The second profile also has |
| 4397 // punctuation at the end of its first address line and no middle name. | 4408 // punctuation at the end of its first address line and no middle name. |
| 4398 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | 4409 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 4399 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", | 4410 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", |
| 4400 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", | 4411 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 4401 "Springfield", "IL", "91601", "US", "12345678910"); | 4412 "Springfield", "IL", "91601", "US", "12345678910"); |
| 4402 profile1.set_use_count(2); | 4413 profile1.set_use_count(2); |
| 4403 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | 4414 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4483 EXPECT_EQ(UTF8ToUTF16("1234 Other Street"), | 4494 EXPECT_EQ(UTF8ToUTF16("1234 Other Street"), |
| 4484 profiles[1]->GetRawInfo(ADDRESS_HOME_LINE1)); | 4495 profiles[1]->GetRawInfo(ADDRESS_HOME_LINE1)); |
| 4485 EXPECT_EQ(profile4.guid(), profiles[2]->guid()); | 4496 EXPECT_EQ(profile4.guid(), profiles[2]->guid()); |
| 4486 EXPECT_EQ(UTF8ToUTF16("Marjorie"), profiles[2]->GetRawInfo(NAME_FIRST)); | 4497 EXPECT_EQ(UTF8ToUTF16("Marjorie"), profiles[2]->GetRawInfo(NAME_FIRST)); |
| 4487 } | 4498 } |
| 4488 | 4499 |
| 4489 // Tests that FindAndMergeDuplicateProfiles sets the correct profile guids to | 4500 // Tests that FindAndMergeDuplicateProfiles sets the correct profile guids to |
| 4490 // delete after merging similar profiles. | 4501 // delete after merging similar profiles. |
| 4491 TEST_F(PersonalDataManagerTest, | 4502 TEST_F(PersonalDataManagerTest, |
| 4492 FindAndMergeDuplicateProfiles_ProfilesToDelete) { | 4503 FindAndMergeDuplicateProfiles_ProfilesToDelete) { |
| 4504 EnableAutofillProfileCleanup(); |
| 4505 |
| 4493 // Create the profile for which to find duplicates. | 4506 // Create the profile for which to find duplicates. |
| 4494 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | 4507 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 4495 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", | 4508 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", |
| 4496 "homer.simpson@abc.com", "", "742. Evergreen Terrace", | 4509 "homer.simpson@abc.com", "", "742. Evergreen Terrace", |
| 4497 "", "Springfield", "IL", "91601", "US", "12345678910"); | 4510 "", "Springfield", "IL", "91601", "US", "12345678910"); |
| 4498 | 4511 |
| 4499 // Create a different profile that should not be deduped (different address). | 4512 // Create a different profile that should not be deduped (different address). |
| 4500 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | 4513 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| 4501 test::SetProfileInfo(&profile2, "Homer", "Jay", "Simpson", | 4514 test::SetProfileInfo(&profile2, "Homer", "Jay", "Simpson", |
| 4502 "homer.simpson@abc.com", "Fox", "1234 Other Street", "", | 4515 "homer.simpson@abc.com", "Fox", "1234 Other Street", "", |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4548 | 4561 |
| 4549 // All profiles should still be present in |existing_profiles|. | 4562 // All profiles should still be present in |existing_profiles|. |
| 4550 EXPECT_EQ(5U, existing_profiles.size()); | 4563 EXPECT_EQ(5U, existing_profiles.size()); |
| 4551 } | 4564 } |
| 4552 | 4565 |
| 4553 // Tests that FindAndMergeDuplicateProfiles merges the profile values correctly, | 4566 // Tests that FindAndMergeDuplicateProfiles merges the profile values correctly, |
| 4554 // ie: never lose information and keep the syntax of the profile with the higher | 4567 // ie: never lose information and keep the syntax of the profile with the higher |
| 4555 // frecency score. | 4568 // frecency score. |
| 4556 TEST_F(PersonalDataManagerTest, | 4569 TEST_F(PersonalDataManagerTest, |
| 4557 FindAndMergeDuplicateProfiles_MergedProfileValues) { | 4570 FindAndMergeDuplicateProfiles_MergedProfileValues) { |
| 4571 EnableAutofillProfileCleanup(); |
| 4572 |
| 4558 // Create a saved profile with a higher frecency score. | 4573 // Create a saved profile with a higher frecency score. |
| 4559 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | 4574 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 4560 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", | 4575 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", |
| 4561 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", | 4576 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 4562 "Springfield", "IL", "91601", "", "12345678910"); | 4577 "Springfield", "IL", "91601", "", "12345678910"); |
| 4563 profile1.set_use_count(5); | 4578 profile1.set_use_count(5); |
| 4564 profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); | 4579 profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); |
| 4565 | 4580 |
| 4566 // Create a saved profile with a lower frecency score. | 4581 // Create a saved profile with a lower frecency score. |
| 4567 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | 4582 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4625 EXPECT_EQ(profile1.use_count() + profile2.use_count() + | 4640 EXPECT_EQ(profile1.use_count() + profile2.use_count() + |
| 4626 imported_profile.use_count(), | 4641 imported_profile.use_count(), |
| 4627 profiles[0]->use_count()); | 4642 profiles[0]->use_count()); |
| 4628 // The use date that results from the merge should be the one from the | 4643 // The use date that results from the merge should be the one from the |
| 4629 // imported profile since it was used just now. | 4644 // imported profile since it was used just now. |
| 4630 EXPECT_LT(base::Time::Now() - base::TimeDelta::FromSeconds(10), | 4645 EXPECT_LT(base::Time::Now() - base::TimeDelta::FromSeconds(10), |
| 4631 profiles[0]->use_date()); | 4646 profiles[0]->use_date()); |
| 4632 } | 4647 } |
| 4633 | 4648 |
| 4634 } // namespace autofill | 4649 } // namespace autofill |
| OLD | NEW |