| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 web_database_, base::ThreadTaskRunnerHandle::Get(), | 133 web_database_, base::ThreadTaskRunnerHandle::Get(), |
| 134 base::ThreadTaskRunnerHandle::Get(), | 134 base::ThreadTaskRunnerHandle::Get(), |
| 135 WebDataServiceBase::ProfileErrorCallback()); | 135 WebDataServiceBase::ProfileErrorCallback()); |
| 136 autofill_database_service_->Init(); | 136 autofill_database_service_->Init(); |
| 137 | 137 |
| 138 test::DisableSystemServices(prefs_.get()); | 138 test::DisableSystemServices(prefs_.get()); |
| 139 ResetPersonalDataManager(USER_MODE_NORMAL); | 139 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 140 | 140 |
| 141 // There are no field trials enabled by default. | 141 // There are no field trials enabled by default. |
| 142 field_trial_list_.reset(); | 142 field_trial_list_.reset(); |
| 143 |
| 144 // There are no features enabled by default. |
| 145 base::FeatureList::ClearInstanceForTesting(); |
| 146 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 147 base::FeatureList::SetInstance(std::move(feature_list)); |
| 148 |
| 149 // Reset the deduping pref to its default value. |
| 150 personal_data_->pref_service_->SetInteger( |
| 151 prefs::kAutofillLastVersionDeduped, 0); |
| 143 } | 152 } |
| 144 | 153 |
| 145 void TearDown() override { | 154 void TearDown() override { |
| 146 // Order of destruction is important as AutofillManager relies on | 155 // Order of destruction is important as AutofillManager relies on |
| 147 // PersonalDataManager to be around when it gets destroyed. | 156 // PersonalDataManager to be around when it gets destroyed. |
| 148 signin_manager_->Shutdown(); | 157 signin_manager_->Shutdown(); |
| 149 signin_manager_.reset(); | 158 signin_manager_.reset(); |
| 150 | 159 |
| 151 account_tracker_->Shutdown(); | 160 account_tracker_->Shutdown(); |
| 152 account_tracker_.reset(); | 161 account_tracker_.reset(); |
| (...skipping 4200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4353 // The use count should have been incremented by one. | 4362 // The use count should have been incremented by one. |
| 4354 EXPECT_EQ(5U, profile.use_count()); | 4363 EXPECT_EQ(5U, profile.use_count()); |
| 4355 // The use date and modification dates should have been set to less than 500 | 4364 // The use date and modification dates should have been set to less than 500 |
| 4356 // milliseconds ago. | 4365 // milliseconds ago. |
| 4357 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), | 4366 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), |
| 4358 base::Time::Now() - profile.use_date()); | 4367 base::Time::Now() - profile.use_date()); |
| 4359 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), | 4368 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), |
| 4360 base::Time::Now() - profile.modification_date()); | 4369 base::Time::Now() - profile.modification_date()); |
| 4361 } | 4370 } |
| 4362 | 4371 |
| 4363 // Tests that using a profile results in a merge of with all similar profiles | 4372 // Tests that DedupeProfiles sets the correct profile guids to |
| 4364 // and that all but the resulting profile gets deleted. Also tests that | |
| 4365 // non-similar profiles are not affected by the merge or the delete. | |
| 4366 TEST_F(PersonalDataManagerTest, DedupeOnInsert) { | |
| 4367 EnableAutofillProfileCleanup(); | |
| 4368 // Create saved profiles. | |
| 4369 // Create two very similar profiles that should be deduped. The first one has | |
| 4370 // no company name, while the second has one. The second profile also has | |
| 4371 // punctuation at the end of its first address line and no middle name. | |
| 4372 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | |
| 4373 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", | |
| 4374 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", | |
| 4375 "Springfield", "IL", "91601", "US", "12345678910"); | |
| 4376 profile1.set_use_count(2); | |
| 4377 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | |
| 4378 test::SetProfileInfo(&profile2, "Homer", "", "Simpson", | |
| 4379 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", | |
| 4380 "", "Springfield", "IL", "91601", "US", "12345678910"); | |
| 4381 profile2.set_use_count(3); | |
| 4382 | |
| 4383 // Create a different profile that should not be deduped (different address). | |
| 4384 AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com"); | |
| 4385 test::SetProfileInfo(&profile3, "Homer", "Jay", "Simpson", | |
| 4386 "homer.simpson@abc.com", "Fox", "1234 Other Street", "", | |
| 4387 "Springfield", "IL", "91601", "US", "12345678910"); | |
| 4388 profile3.set_use_count(4); | |
| 4389 | |
| 4390 // Create another different profile that should not be deduped (different | |
| 4391 // name). | |
| 4392 AutofillProfile profile4(base::GenerateGUID(), "https://www.example.com"); | |
| 4393 test::SetProfileInfo(&profile4, "Marjorie", "Jacqueline", "Simpson", | |
| 4394 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace", | |
| 4395 "", "Springfield", "IL", "91601", "US", "12345678910"); | |
| 4396 profile4.set_use_count(1); | |
| 4397 | |
| 4398 personal_data_->AddProfile(profile1); | |
| 4399 personal_data_->AddProfile(profile2); | |
| 4400 personal_data_->AddProfile(profile3); | |
| 4401 personal_data_->AddProfile(profile4); | |
| 4402 | |
| 4403 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | |
| 4404 .WillOnce(QuitMainMessageLoop()); | |
| 4405 base::MessageLoop::current()->Run(); | |
| 4406 | |
| 4407 EXPECT_EQ(4U, personal_data_->GetProfiles().size()); | |
| 4408 | |
| 4409 // Create a new imported profile with no company name. It is similar to | |
| 4410 // profiles 1 and 2 and should be merged with them. | |
| 4411 AutofillProfile imported_profile(base::GenerateGUID(), | |
| 4412 "https://www.example.com"); | |
| 4413 test::SetProfileInfo(&imported_profile, "Homer", "Jay", "Simpson", | |
| 4414 "homer.simpson@abc.com", "", "742. Evergreen Terrace", | |
| 4415 "", "Springfield", "IL", "91601", "US", "12345678910"); | |
| 4416 | |
| 4417 base::HistogramTester histogram_tester; | |
| 4418 // Save the imported profile (use it). | |
| 4419 personal_data_->SaveImportedProfile(imported_profile); | |
| 4420 | |
| 4421 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | |
| 4422 .WillOnce(QuitMainMessageLoop()); | |
| 4423 base::MessageLoop::current()->Run(); | |
| 4424 | |
| 4425 // Create a similar new non verified imported profile to be merged with the | |
| 4426 // saved profiles. | |
| 4427 std::vector<AutofillProfile*> profiles = | |
| 4428 personal_data_->GetProfilesToSuggest(); | |
| 4429 | |
| 4430 // The imported profile and saved profiles 1 and 2 should be merged together. | |
| 4431 // Therefore there should only be 3 saved profiles. | |
| 4432 ASSERT_EQ(3U, profiles.size()); | |
| 4433 // 4 profiles were considered for dedupe. | |
| 4434 histogram_tester.ExpectUniqueSample( | |
| 4435 "Autofill.NumberOfProfilesConsideredForDedupe", 4, 1); | |
| 4436 // 1 profile was removed. | |
| 4437 histogram_tester.ExpectUniqueSample( | |
| 4438 "Autofill.NumberOfProfilesRemovedDuringDedupe", 1, 1); | |
| 4439 | |
| 4440 // Sort the profiles by frecency to have a deterministic order. | |
| 4441 base::Time comparison_time = base::Time::Now(); | |
| 4442 std::sort(profiles.begin(), profiles.end(), | |
| 4443 [comparison_time](const AutofillDataModel* a, | |
| 4444 const AutofillDataModel* b) { | |
| 4445 return a->CompareFrecency(b, comparison_time); | |
| 4446 }); | |
| 4447 | |
| 4448 // Since profiles with higher frecency scores are merged into profiles with | |
| 4449 // lower frecency scores, the result of the merge should be contained in | |
| 4450 // profile1 since it had a lower frecency score compared to profile2. | |
| 4451 EXPECT_EQ(profile1.guid(), profiles[0]->guid()); | |
| 4452 // Even though one of the merged profiles had no middle name (|profile2|), the | |
| 4453 // result of the merge should have kept the middle name from the other | |
| 4454 // profiles. | |
| 4455 EXPECT_EQ(UTF8ToUTF16("Jay"), profiles[0]->GetRawInfo(NAME_MIDDLE)); | |
| 4456 // The address syntax that results from the merge should be the one from the | |
| 4457 // imported profile (most recent). | |
| 4458 EXPECT_EQ(UTF8ToUTF16("742. Evergreen Terrace"), | |
| 4459 profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1)); | |
| 4460 // Even though the imported profile had no company name, a merge should not | |
| 4461 // result in a loss of information. Therefore the company name present in | |
| 4462 // |profile2| should be kept. | |
| 4463 EXPECT_EQ(UTF8ToUTF16("Fox"), profiles[0]->GetRawInfo(COMPANY_NAME)); | |
| 4464 | |
| 4465 // Make sure the two other remaining profiles are the expected ones. | |
| 4466 EXPECT_EQ(profile3.guid(), profiles[1]->guid()); | |
| 4467 EXPECT_EQ(UTF8ToUTF16("1234 Other Street"), | |
| 4468 profiles[1]->GetRawInfo(ADDRESS_HOME_LINE1)); | |
| 4469 EXPECT_EQ(profile4.guid(), profiles[2]->guid()); | |
| 4470 EXPECT_EQ(UTF8ToUTF16("Marjorie"), profiles[2]->GetRawInfo(NAME_FIRST)); | |
| 4471 } | |
| 4472 | |
| 4473 // Tests that FindAndMergeDuplicateProfiles sets the correct profile guids to | |
| 4474 // delete after merging similar profiles. | 4373 // delete after merging similar profiles. |
| 4475 TEST_F(PersonalDataManagerTest, | 4374 TEST_F(PersonalDataManagerTest, DedupeProfiles_ProfilesToDelete) { |
| 4476 FindAndMergeDuplicateProfiles_ProfilesToDelete) { | 4375 // Create the profile for which to find duplicates. It has the highest |
| 4477 EnableAutofillProfileCleanup(); | 4376 // frecency. |
| 4478 | |
| 4479 // Create the profile for which to find duplicates. | |
| 4480 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | 4377 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 4481 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", | 4378 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", |
| 4482 "homer.simpson@abc.com", "", "742. Evergreen Terrace", | 4379 "homer.simpson@abc.com", "", "742. Evergreen Terrace", |
| 4483 "", "Springfield", "IL", "91601", "US", "12345678910"); | 4380 "", "Springfield", "IL", "91601", "US", "12345678910"); |
| 4381 profile1.set_use_count(9); |
| 4484 | 4382 |
| 4485 // Create a different profile that should not be deduped (different address). | 4383 // Create a different profile that should not be deduped (different address). |
| 4486 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | 4384 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| 4487 test::SetProfileInfo(&profile2, "Homer", "Jay", "Simpson", | 4385 test::SetProfileInfo(&profile2, "Homer", "Jay", "Simpson", |
| 4488 "homer.simpson@abc.com", "Fox", "1234 Other Street", "", | 4386 "homer.simpson@abc.com", "Fox", "1234 Other Street", "", |
| 4489 "Springfield", "IL", "91601", "US", "12345678910"); | 4387 "Springfield", "IL", "91601", "US", "12345678910"); |
| 4388 profile2.set_use_count(7); |
| 4490 | 4389 |
| 4491 // Create a profile similar to profile1 which should be deduped. | 4390 // Create a profile similar to profile1 which should be deduped. |
| 4492 AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com"); | 4391 AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com"); |
| 4493 test::SetProfileInfo(&profile3, "Homer", "Jay", "Simpson", | 4392 test::SetProfileInfo(&profile3, "Homer", "Jay", "Simpson", |
| 4494 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", | 4393 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 4495 "Springfield", "IL", "91601", "US", "12345678910"); | 4394 "Springfield", "IL", "91601", "US", "12345678910"); |
| 4395 profile3.set_use_count(5); |
| 4496 | 4396 |
| 4497 // Create another different profile that should not be deduped (different | 4397 // Create another different profile that should not be deduped (different |
| 4498 // name). | 4398 // name). |
| 4499 AutofillProfile profile4(base::GenerateGUID(), "https://www.example.com"); | 4399 AutofillProfile profile4(base::GenerateGUID(), "https://www.example.com"); |
| 4500 test::SetProfileInfo(&profile4, "Marjorie", "Jacqueline", "Simpson", | 4400 test::SetProfileInfo(&profile4, "Marjorie", "Jacqueline", "Simpson", |
| 4501 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace", | 4401 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace", |
| 4502 "", "Springfield", "IL", "91601", "US", "12345678910"); | 4402 "", "Springfield", "IL", "91601", "US", "12345678910"); |
| 4403 profile4.set_use_count(3); |
| 4503 | 4404 |
| 4504 // Create another profile similar to profile1. Since that one is last, the | 4405 // Create another profile similar to profile1. Since that one has the lowest |
| 4505 // result of the merge should be in this profile at the end of the test. | 4406 // frecency, the result of the merge should be in this profile at the end of |
| 4407 // the test. |
| 4506 AutofillProfile profile5(base::GenerateGUID(), "https://www.example.com"); | 4408 AutofillProfile profile5(base::GenerateGUID(), "https://www.example.com"); |
| 4507 test::SetProfileInfo(&profile5, "Homer", "Jay", "Simpson", | 4409 test::SetProfileInfo(&profile5, "Homer", "Jay", "Simpson", |
| 4508 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", | 4410 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| 4509 "", "Springfield", "IL", "91601", "US", "12345678910"); | 4411 "", "Springfield", "IL", "91601", "US", "12345678910"); |
| 4412 profile5.set_use_count(1); |
| 4510 | 4413 |
| 4414 // Add the profiles. |
| 4511 std::vector<AutofillProfile*> existing_profiles; | 4415 std::vector<AutofillProfile*> existing_profiles; |
| 4512 existing_profiles.push_back(&profile1); | 4416 existing_profiles.push_back(&profile1); |
| 4513 existing_profiles.push_back(&profile2); | 4417 existing_profiles.push_back(&profile2); |
| 4514 existing_profiles.push_back(&profile3); | 4418 existing_profiles.push_back(&profile3); |
| 4515 existing_profiles.push_back(&profile4); | 4419 existing_profiles.push_back(&profile4); |
| 4516 existing_profiles.push_back(&profile5); | 4420 existing_profiles.push_back(&profile5); |
| 4517 | 4421 |
| 4422 // Enable the profile cleanup. |
| 4423 EnableAutofillProfileCleanup(); |
| 4424 |
| 4518 base::HistogramTester histogram_tester; | 4425 base::HistogramTester histogram_tester; |
| 4519 std::vector<std::string> guids_to_delete; | 4426 std::unordered_set<AutofillProfile*> profiles_to_delete; |
| 4520 personal_data_->FindAndMergeDuplicateProfiles(existing_profiles, &profile1, | 4427 personal_data_->DedupeProfiles(&existing_profiles, &profiles_to_delete); |
| 4521 &guids_to_delete); | |
| 4522 // 5 profiles were considered for dedupe. | 4428 // 5 profiles were considered for dedupe. |
| 4523 histogram_tester.ExpectUniqueSample( | 4429 histogram_tester.ExpectUniqueSample( |
| 4524 "Autofill.NumberOfProfilesConsideredForDedupe", 5, 1); | 4430 "Autofill.NumberOfProfilesConsideredForDedupe", 5, 1); |
| 4525 // 2 profiles were removed. | 4431 // 2 profiles were removed (profiles 1 and 3). |
| 4526 histogram_tester.ExpectUniqueSample( | 4432 histogram_tester.ExpectUniqueSample( |
| 4527 "Autofill.NumberOfProfilesRemovedDuringDedupe", 2, 1); | 4433 "Autofill.NumberOfProfilesRemovedDuringDedupe", 2, 1); |
| 4528 | 4434 |
| 4529 // Profile1 should be deleted because it was sent as the profile to merge and | 4435 // Profile1 should be deleted because it was sent as the profile to merge and |
| 4530 // thus was merged into profile3 and then into profile5. | 4436 // thus was merged into profile3 and then into profile5. |
| 4531 EXPECT_TRUE(std::find(guids_to_delete.begin(), guids_to_delete.end(), | 4437 EXPECT_TRUE(profiles_to_delete.count(&profile1)); |
| 4532 profile1.guid()) != guids_to_delete.end()); | |
| 4533 | 4438 |
| 4534 // Profile3 should be deleted because profile1 was merged into it and the | 4439 // Profile3 should be deleted because profile1 was merged into it and the |
| 4535 // resulting profile was then merged into profile5. | 4440 // resulting profile was then merged into profile5. |
| 4536 EXPECT_TRUE(std::find(guids_to_delete.begin(), guids_to_delete.end(), | 4441 EXPECT_TRUE(profiles_to_delete.count(&profile3)); |
| 4537 profile3.guid()) != guids_to_delete.end()); | |
| 4538 | 4442 |
| 4539 // Only these two profiles should be deleted. | 4443 // Only these two profiles should be deleted. |
| 4540 EXPECT_EQ(2U, guids_to_delete.size()); | 4444 EXPECT_EQ(2U, profiles_to_delete.size()); |
| 4541 | 4445 |
| 4542 // All profiles should still be present in |existing_profiles|. | 4446 // All profiles should still be present in |existing_profiles|. |
| 4543 EXPECT_EQ(5U, existing_profiles.size()); | 4447 EXPECT_EQ(5U, existing_profiles.size()); |
| 4544 } | 4448 } |
| 4545 | 4449 |
| 4546 // Tests that FindAndMergeDuplicateProfiles merges the profile values correctly, | 4450 // Tests that ApplyDedupingRoutine merges the profile values correctly, i.e. |
| 4547 // ie: never lose information and keep the syntax of the profile with the higher | 4451 // never lose information and keep the syntax of the profile with the higher |
| 4548 // frecency score. | 4452 // frecency score. |
| 4549 TEST_F(PersonalDataManagerTest, | 4453 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MergedProfileValues) { |
| 4550 FindAndMergeDuplicateProfiles_MergedProfileValues) { | 4454 // Create a profile with a higher frecency score. |
| 4551 EnableAutofillProfileCleanup(); | 4455 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 4456 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson", |
| 4457 "homer.simpson@abc.com", "", "742. Evergreen Terrace", |
| 4458 "", "Springfield", "IL", "91601", "US", ""); |
| 4459 profile1.set_use_count(10); |
| 4460 profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); |
| 4552 | 4461 |
| 4553 // Create a saved profile with a higher frecency score. | 4462 // Create a profile with a medium frecency score. |
| 4554 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | 4463 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| 4555 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", | 4464 test::SetProfileInfo(&profile2, "Homer", "Jay", "Simpson", |
| 4556 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", | 4465 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 4557 "Springfield", "IL", "91601", "", "12345678910"); | 4466 "Springfield", "IL", "91601", "", "12345678910"); |
| 4558 profile1.set_use_count(5); | 4467 profile2.set_use_count(5); |
| 4559 profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); | 4468 profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); |
| 4560 | 4469 |
| 4561 // Create a saved profile with a lower frecency score. | 4470 // Create a profile with a lower frecency score. |
| 4562 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | 4471 AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com"); |
| 4563 test::SetProfileInfo(&profile2, "Homer", "J", "Simpson", | 4472 test::SetProfileInfo(&profile3, "Homer", "J", "Simpson", |
| 4564 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", | 4473 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| 4565 "", "Springfield", "IL", "91601", "", ""); | 4474 "", "Springfield", "IL", "91601", "", ""); |
| 4566 profile2.set_use_count(3); | 4475 profile3.set_use_count(3); |
| 4567 profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); | 4476 profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); |
| 4568 | 4477 |
| 4569 personal_data_->AddProfile(profile1); | 4478 personal_data_->AddProfile(profile1); |
| 4570 personal_data_->AddProfile(profile2); | 4479 personal_data_->AddProfile(profile2); |
| 4571 | 4480 personal_data_->AddProfile(profile3); |
| 4572 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4481 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4573 .WillOnce(QuitMainMessageLoop()); | 4482 .WillOnce(QuitMainMessageLoop()); |
| 4574 base::MessageLoop::current()->Run(); | 4483 base::MessageLoop::current()->Run(); |
| 4575 | 4484 |
| 4576 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); | 4485 // Make sure the 3 profiles were saved; |
| 4486 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); |
| 4577 | 4487 |
| 4578 // Create a new imported profile to be merged with the saved profiles. | 4488 // Enable the profile cleanup now. Otherwise it would be triggered by the |
| 4579 AutofillProfile imported_profile(base::GenerateGUID(), | 4489 // calls to AddProfile. |
| 4580 "https://www.example.com"); | 4490 EnableAutofillProfileCleanup(); |
| 4581 test::SetProfileInfo(&imported_profile, "Homer", "J", "Simpson", | |
| 4582 "homer.simpson@abc.com", "", "742. Evergreen Terrace", | |
| 4583 "", "Springfield", "IL", "91601", "US", ""); | |
| 4584 | 4491 |
| 4585 base::HistogramTester histogram_tester; | 4492 base::HistogramTester histogram_tester; |
| 4586 personal_data_->SaveImportedProfile(imported_profile); | |
| 4587 | 4493 |
| 4494 personal_data_->ApplyDedupingRoutine(); |
| 4588 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4495 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4589 .WillOnce(QuitMainMessageLoop()); | 4496 .WillOnce(QuitMainMessageLoop()); |
| 4590 base::MessageLoop::current()->Run(); | 4497 base::MessageLoop::current()->Run(); |
| 4591 | 4498 |
| 4592 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); | 4499 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); |
| 4593 | 4500 |
| 4594 // The imported profile and saved profiles 1 and 2 should be merged together. | 4501 // |profile1| should have been merged into |profile2| which should then have |
| 4595 // Therefore there should only be 1 saved profile. | 4502 // been merged into |profile3|. Therefore there should only be 1 saved |
| 4503 // profile. |
| 4596 ASSERT_EQ(1U, profiles.size()); | 4504 ASSERT_EQ(1U, profiles.size()); |
| 4597 // 2 profiles were considered for dedupe. | 4505 // 3 profiles were considered for dedupe. |
| 4598 histogram_tester.ExpectUniqueSample( | 4506 histogram_tester.ExpectUniqueSample( |
| 4599 "Autofill.NumberOfProfilesConsideredForDedupe", 2, 1); | 4507 "Autofill.NumberOfProfilesConsideredForDedupe", 3, 1); |
| 4600 // 1 profile was removed. | 4508 // 2 profiles were removed (profiles 1 and 2). |
| 4601 histogram_tester.ExpectUniqueSample( | 4509 histogram_tester.ExpectUniqueSample( |
| 4602 "Autofill.NumberOfProfilesRemovedDuringDedupe", 1, 1); | 4510 "Autofill.NumberOfProfilesRemovedDuringDedupe", 2, 1); |
| 4603 | 4511 |
| 4604 // Since profiles with higher frecency scores are merged into profiles with | 4512 // Since profiles with higher frecency scores are merged into profiles with |
| 4605 // lower frecency scores, the result of the merge should be contained in | 4513 // lower frecency scores, the result of the merge should be contained in |
| 4606 // profile2 since it had a lower frecency score compared to profile1. | 4514 // profile3 since it had a lower frecency score compared to profile1. |
| 4607 EXPECT_EQ(profile2.guid(), profiles[0]->guid()); | 4515 EXPECT_EQ(profile3.guid(), profiles[0]->guid()); |
| 4608 // The address syntax that results from the merge should be the one from the | 4516 // The address syntax that results from the merge should be the one from the |
| 4609 // imported profile (highest frecency). | 4517 // imported profile (highest frecency). |
| 4610 EXPECT_EQ(UTF8ToUTF16("742. Evergreen Terrace"), | 4518 EXPECT_EQ(UTF8ToUTF16("742. Evergreen Terrace"), |
| 4611 profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1)); | 4519 profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1)); |
| 4612 // The middle name should be full, even if the profile with the higher | 4520 // The middle name should be full, even if the profile with the higher |
| 4613 // frecency only had an initial (no loss of information). | 4521 // frecency only had an initial (no loss of information). |
| 4614 EXPECT_EQ(UTF8ToUTF16("Jay"), profiles[0]->GetRawInfo(NAME_MIDDLE)); | 4522 EXPECT_EQ(UTF8ToUTF16("Jay"), profiles[0]->GetRawInfo(NAME_MIDDLE)); |
| 4615 // The specified phone number from profile1 should be kept (no loss of | 4523 // The specified phone number from profile1 should be kept (no loss of |
| 4616 // information). | 4524 // information). |
| 4617 EXPECT_EQ(UTF8ToUTF16("12345678910"), | 4525 EXPECT_EQ(UTF8ToUTF16("12345678910"), |
| 4618 profiles[0]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); | 4526 profiles[0]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); |
| 4619 // The specified company name from profile2 should be kept (no loss of | 4527 // The specified company name from profile2 should be kept (no loss of |
| 4620 // information). | 4528 // information). |
| 4621 EXPECT_EQ(UTF8ToUTF16("Fox"), profiles[0]->GetRawInfo(COMPANY_NAME)); | 4529 EXPECT_EQ(UTF8ToUTF16("Fox"), profiles[0]->GetRawInfo(COMPANY_NAME)); |
| 4622 // The specified country from the imported profile shoudl be kept (no loss of | 4530 // The specified country from the imported profile shoudl be kept (no loss of |
| 4623 // information). | 4531 // information). |
| 4624 EXPECT_EQ(UTF8ToUTF16("US"), profiles[0]->GetRawInfo(ADDRESS_HOME_COUNTRY)); | 4532 EXPECT_EQ(UTF8ToUTF16("US"), profiles[0]->GetRawInfo(ADDRESS_HOME_COUNTRY)); |
| 4625 // The use count that results from the merge should be the sum of the two | 4533 // The use count that results from the merge should be the sum of the two |
| 4626 // saved profiles plus 1 (imported profile count). | 4534 // saved profiles plus 1 (imported profile count). |
| 4627 EXPECT_EQ(profile1.use_count() + profile2.use_count() + | 4535 EXPECT_EQ(profile1.use_count() + profile2.use_count() + profile3.use_count(), |
| 4628 imported_profile.use_count(), | |
| 4629 profiles[0]->use_count()); | 4536 profiles[0]->use_count()); |
| 4630 // The use date that results from the merge should be the one from the | 4537 // The use date that results from the merge should be the one from the |
| 4631 // imported profile since it was used just now. | 4538 // profile1 since it was the most recently used profile. |
| 4632 EXPECT_LT(base::Time::Now() - base::TimeDelta::FromSeconds(10), | 4539 EXPECT_LT(profile1.use_date() - base::TimeDelta::FromSeconds(10), |
| 4633 profiles[0]->use_date()); | 4540 profiles[0]->use_date()); |
| 4634 } | 4541 } |
| 4635 | 4542 |
| 4636 // Tests that FindAndMergeDuplicateProfiles only keeps the verified profile with | 4543 // Tests that ApplyDedupingRoutine only keeps the verified profile with its |
| 4637 // its original data when deduping with similar profiles, even if it has a | 4544 // original data when deduping with similar profiles, even if it has a higher |
| 4638 // higher frecency score. | 4545 // frecency score. |
| 4639 TEST_F(PersonalDataManagerTest, | 4546 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_VerifiedProfileFirst) { |
| 4640 FindAndMergeDuplicateProfiles_VerifiedProfileFirst) { | |
| 4641 EnableAutofillProfileCleanup(); | |
| 4642 | |
| 4643 // Create a verified profile with a higher frecency score. | 4547 // Create a verified profile with a higher frecency score. |
| 4644 AutofillProfile profile1(base::GenerateGUID(), kSettingsOrigin); | 4548 AutofillProfile profile1(base::GenerateGUID(), kSettingsOrigin); |
| 4645 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", | 4549 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", |
| 4646 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", | 4550 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 4647 "Springfield", "IL", "91601", "", "12345678910"); | 4551 "Springfield", "IL", "91601", "", "12345678910"); |
| 4648 profile1.set_use_count(5); | 4552 profile1.set_use_count(7); |
| 4649 profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); | 4553 profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); |
| 4554 |
| 4555 // Create a similar non verified profile with a medium frecency score. |
| 4556 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| 4557 test::SetProfileInfo(&profile2, "Homer", "J", "Simpson", |
| 4558 "homer.simpson@abc.com", "", "742. Evergreen Terrace", |
| 4559 "", "Springfield", "IL", "91601", "US", ""); |
| 4560 profile2.set_use_count(5); |
| 4561 profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); |
| 4650 | 4562 |
| 4651 // Create a similar non verified profile with a lower frecency score. | 4563 // Create a similar non verified profile with a lower frecency score. |
| 4652 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | 4564 AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com"); |
| 4653 test::SetProfileInfo(&profile2, "Homer", "J", "Simpson", | 4565 test::SetProfileInfo(&profile3, "Homer", "J", "Simpson", |
| 4654 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", | 4566 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| 4655 "", "Springfield", "IL", "91601", "", ""); | 4567 "", "Springfield", "IL", "91601", "", ""); |
| 4656 profile2.set_use_count(3); | 4568 profile3.set_use_count(3); |
| 4657 profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); | 4569 profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); |
| 4658 | 4570 |
| 4659 personal_data_->AddProfile(profile1); | 4571 personal_data_->AddProfile(profile1); |
| 4660 personal_data_->AddProfile(profile2); | 4572 personal_data_->AddProfile(profile2); |
| 4661 | 4573 personal_data_->AddProfile(profile3); |
| 4662 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4574 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4663 .WillOnce(QuitMainMessageLoop()); | 4575 .WillOnce(QuitMainMessageLoop()); |
| 4664 base::MessageLoop::current()->Run(); | 4576 base::MessageLoop::current()->Run(); |
| 4665 | 4577 |
| 4666 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); | 4578 // Make sure the 3 profiles were saved. |
| 4579 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); |
| 4667 | 4580 |
| 4668 // Create a similar new non verified imported profile to be merged with the | 4581 // Enable the profile cleanup now. Otherwise it would be triggered by the |
| 4669 // saved profiles. | 4582 // calls to AddProfile. |
| 4670 AutofillProfile imported_profile(base::GenerateGUID(), | 4583 EnableAutofillProfileCleanup(); |
| 4671 "https://www.example.com"); | |
| 4672 test::SetProfileInfo(&imported_profile, "Homer", "J", "Simpson", | |
| 4673 "homer.simpson@abc.com", "", "742. Evergreen Terrace", | |
| 4674 "", "Springfield", "IL", "91601", "US", ""); | |
| 4675 | 4584 |
| 4676 base::HistogramTester histogram_tester; | 4585 base::HistogramTester histogram_tester; |
| 4677 personal_data_->SaveImportedProfile(imported_profile); | |
| 4678 | 4586 |
| 4587 personal_data_->ApplyDedupingRoutine(); |
| 4679 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4588 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4680 .WillOnce(QuitMainMessageLoop()); | 4589 .WillOnce(QuitMainMessageLoop()); |
| 4681 base::MessageLoop::current()->Run(); | 4590 base::MessageLoop::current()->Run(); |
| 4682 | 4591 |
| 4683 std::vector<AutofillProfile*> profiles = | 4592 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); |
| 4684 personal_data_->GetProfilesToSuggest(); | 4593 |
| 4685 // The |imported_profile| should have merged with |profile2|. |profile2| | 4594 // |profile2| should have merged with |profile3|. |profile3| |
| 4686 // should then have been discarded because it is similar to the verified | 4595 // should then have been discarded because it is similar to the verified |
| 4687 // |profile1|. | 4596 // |profile1|. |
| 4688 ASSERT_EQ(1U, profiles.size()); | 4597 ASSERT_EQ(1U, profiles.size()); |
| 4689 // 2 profiles were considered for dedupe (profiles 1 and 2). | 4598 // 3 profiles were considered for dedupe. |
| 4690 histogram_tester.ExpectUniqueSample( | 4599 histogram_tester.ExpectUniqueSample( |
| 4691 "Autofill.NumberOfProfilesConsideredForDedupe", 2, 1); | 4600 "Autofill.NumberOfProfilesConsideredForDedupe", 3, 1); |
| 4692 // 1 profile was removed (|profile2|). | 4601 // 2 profile were removed (profiles 2 and 3). |
| 4693 histogram_tester.ExpectUniqueSample( | 4602 histogram_tester.ExpectUniqueSample( |
| 4694 "Autofill.NumberOfProfilesRemovedDuringDedupe", 1, 1); | 4603 "Autofill.NumberOfProfilesRemovedDuringDedupe", 2, 1); |
| 4695 | 4604 |
| 4696 // Only the verified |profile2| with its original data should have been kept. | 4605 // Only the verified |profile1| with its original data should have been kept. |
| 4697 EXPECT_EQ(profile1.guid(), profiles[0]->guid()); | 4606 EXPECT_EQ(profile1.guid(), profiles[0]->guid()); |
| 4698 EXPECT_EQ(UTF8ToUTF16("742 Evergreen Terrace"), | 4607 EXPECT_TRUE(profile1 == *profiles[0]); |
| 4699 profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1)); | |
| 4700 EXPECT_EQ(UTF8ToUTF16("Jay"), profiles[0]->GetRawInfo(NAME_MIDDLE)); | |
| 4701 EXPECT_EQ(UTF8ToUTF16("12345678910"), | |
| 4702 profiles[0]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); | |
| 4703 EXPECT_EQ(UTF8ToUTF16(""), profiles[0]->GetRawInfo(COMPANY_NAME)); | |
| 4704 EXPECT_EQ(UTF8ToUTF16(""), profiles[0]->GetRawInfo(ADDRESS_HOME_COUNTRY)); | |
| 4705 EXPECT_EQ(profile1.use_count(), profiles[0]->use_count()); | 4608 EXPECT_EQ(profile1.use_count(), profiles[0]->use_count()); |
| 4706 EXPECT_LT(profile1.use_date() - TimeDelta::FromSeconds(2), | 4609 EXPECT_LT(profile1.use_date() - TimeDelta::FromSeconds(2), |
| 4707 profiles[0]->use_date()); | 4610 profiles[0]->use_date()); |
| 4708 EXPECT_GT(profile1.use_date() + TimeDelta::FromSeconds(2), | 4611 EXPECT_GT(profile1.use_date() + TimeDelta::FromSeconds(2), |
| 4709 profiles[0]->use_date()); | 4612 profiles[0]->use_date()); |
| 4710 } | 4613 } |
| 4711 | 4614 |
| 4712 // Tests that FindAndMergeDuplicateProfiles only keeps the verified profile with | 4615 // Tests that ApplyDedupingRoutine only keeps the verified profile with its |
| 4713 // it's original data when deduping with similar profiles, even if it has a | 4616 // original data when deduping with similar profiles, even if it has a lower |
| 4714 // lower frecency score. | 4617 // frecency score. |
| 4715 TEST_F(PersonalDataManagerTest, | 4618 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_VerifiedProfileLast) { |
| 4716 FindAndMergeDuplicateProfiles_VerifiedProfileLast) { | 4619 // Create a profile to dedupe with a higher frecency score. |
| 4717 EnableAutofillProfileCleanup(); | |
| 4718 | |
| 4719 // Create a non verified profile with a higher frecency score. | |
| 4720 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | 4620 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 4721 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson", | 4621 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson", |
| 4722 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", | 4622 "homer.simpson@abc.com", "", "742. Evergreen Terrace", |
| 4723 "", "Springfield", "IL", "91601", "", ""); | 4623 "", "Springfield", "IL", "91601", "US", ""); |
| 4724 profile1.set_use_count(5); | 4624 profile1.set_use_count(5); |
| 4725 profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); | 4625 profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); |
| 4726 | 4626 |
| 4627 // Create a similar non verified profile with a medium frecency score. |
| 4628 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| 4629 test::SetProfileInfo(&profile2, "Homer", "J", "Simpson", |
| 4630 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| 4631 "", "Springfield", "IL", "91601", "", ""); |
| 4632 profile2.set_use_count(5); |
| 4633 profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); |
| 4634 |
| 4727 // Create a similar verified profile with a lower frecency score. | 4635 // Create a similar verified profile with a lower frecency score. |
| 4728 AutofillProfile profile2(base::GenerateGUID(), kSettingsOrigin); | 4636 AutofillProfile profile3(base::GenerateGUID(), kSettingsOrigin); |
| 4729 test::SetProfileInfo(&profile2, "Homer", "Jay", "Simpson", | 4637 test::SetProfileInfo(&profile3, "Homer", "Jay", "Simpson", |
| 4730 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", | 4638 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 4731 "Springfield", "IL", "91601", "", "12345678910"); | 4639 "Springfield", "IL", "91601", "", "12345678910"); |
| 4732 profile2.set_use_count(3); | 4640 profile3.set_use_count(3); |
| 4733 profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); | 4641 profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); |
| 4734 | 4642 |
| 4735 personal_data_->AddProfile(profile1); | 4643 personal_data_->AddProfile(profile1); |
| 4736 personal_data_->AddProfile(profile2); | 4644 personal_data_->AddProfile(profile2); |
| 4737 | 4645 personal_data_->AddProfile(profile3); |
| 4738 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4646 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4739 .WillOnce(QuitMainMessageLoop()); | 4647 .WillOnce(QuitMainMessageLoop()); |
| 4740 base::MessageLoop::current()->Run(); | 4648 base::MessageLoop::current()->Run(); |
| 4741 | 4649 |
| 4742 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); | 4650 // Make sure the 3 profiles were saved. |
| 4651 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); |
| 4743 | 4652 |
| 4744 // Create a similar non verified imported profile to be merged with the saved | 4653 // Enable the profile cleanup now. Otherwise it would be triggered by the |
| 4745 // profiles. | 4654 // calls to AddProfile. |
| 4746 AutofillProfile imported_profile(base::GenerateGUID(), | 4655 EnableAutofillProfileCleanup(); |
| 4747 "https://www.example.com"); | |
| 4748 test::SetProfileInfo(&imported_profile, "Homer", "J", "Simpson", | |
| 4749 "homer.simpson@abc.com", "", "742. Evergreen Terrace", | |
| 4750 "", "Springfield", "IL", "91601", "US", ""); | |
| 4751 | 4656 |
| 4752 base::HistogramTester histogram_tester; | 4657 base::HistogramTester histogram_tester; |
| 4753 personal_data_->SaveImportedProfile(imported_profile); | |
| 4754 | 4658 |
| 4659 personal_data_->ApplyDedupingRoutine(); |
| 4755 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4660 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4756 .WillOnce(QuitMainMessageLoop()); | 4661 .WillOnce(QuitMainMessageLoop()); |
| 4757 base::MessageLoop::current()->Run(); | 4662 base::MessageLoop::current()->Run(); |
| 4758 | 4663 |
| 4759 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); | 4664 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); |
| 4760 // The |imported_profile| should have merged with |profile1|. |profile1| | 4665 |
| 4666 // |profile1| should have merged with |profile2|. |profile2| |
| 4761 // should then have been discarded because it is similar to the verified | 4667 // should then have been discarded because it is similar to the verified |
| 4762 // |profile2|. | 4668 // |profile3|. |
| 4763 ASSERT_EQ(1U, profiles.size()); | 4669 ASSERT_EQ(1U, profiles.size()); |
| 4764 // 2 profiles were considered for dedupe (profiles 1 and 2). | 4670 // 3 profiles were considered for dedupe. |
| 4765 histogram_tester.ExpectUniqueSample( | 4671 histogram_tester.ExpectUniqueSample( |
| 4766 "Autofill.NumberOfProfilesConsideredForDedupe", 2, 1); | 4672 "Autofill.NumberOfProfilesConsideredForDedupe", 3, 1); |
| 4767 // 1 profile was removed (|profile1|). | 4673 // 2 profile were removed (profiles 1 and 2). |
| 4768 histogram_tester.ExpectUniqueSample( | 4674 histogram_tester.ExpectUniqueSample( |
| 4769 "Autofill.NumberOfProfilesRemovedDuringDedupe", 1, 1); | 4675 "Autofill.NumberOfProfilesRemovedDuringDedupe", 2, 1); |
| 4770 | 4676 |
| 4771 // Only the verified |profile2| with it's original data should have been kept. | 4677 // Only the verified |profile2| with it's original data should have been kept. |
| 4772 EXPECT_EQ(profile2.guid(), profiles[0]->guid()); | 4678 EXPECT_EQ(profile3.guid(), profiles[0]->guid()); |
| 4773 EXPECT_EQ(UTF8ToUTF16("742 Evergreen Terrace"), | 4679 EXPECT_TRUE(profile3 == *profiles[0]); |
| 4774 profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1)); | 4680 EXPECT_EQ(profile3.use_count(), profiles[0]->use_count()); |
| 4775 EXPECT_EQ(UTF8ToUTF16("Jay"), profiles[0]->GetRawInfo(NAME_MIDDLE)); | 4681 EXPECT_LT(profile3.use_date() - TimeDelta::FromSeconds(2), |
| 4776 EXPECT_EQ(UTF8ToUTF16("12345678910"), | |
| 4777 profiles[0]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); | |
| 4778 EXPECT_EQ(UTF8ToUTF16(""), profiles[0]->GetRawInfo(COMPANY_NAME)); | |
| 4779 EXPECT_EQ(UTF8ToUTF16(""), profiles[0]->GetRawInfo(ADDRESS_HOME_COUNTRY)); | |
| 4780 EXPECT_EQ(profile2.use_count(), profiles[0]->use_count()); | |
| 4781 EXPECT_LT(profile2.use_date() - TimeDelta::FromSeconds(2), | |
| 4782 profiles[0]->use_date()); | 4682 profiles[0]->use_date()); |
| 4783 EXPECT_GT(profile2.use_date() + TimeDelta::FromSeconds(2), | 4683 EXPECT_GT(profile3.use_date() + TimeDelta::FromSeconds(2), |
| 4784 profiles[0]->use_date()); | 4684 profiles[0]->use_date()); |
| 4785 } | 4685 } |
| 4786 | 4686 |
| 4787 // Tests that FindAndMergeDuplicateProfiles does not merge unverified data into | 4687 // Tests that ApplyDedupingRoutine does not merge unverified data into |
| 4788 // a verified profile. Also tests that two verified profiles don't get merged. | 4688 // a verified profile. Also tests that two verified profiles don't get merged. |
| 4789 TEST_F(PersonalDataManagerTest, | 4689 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MultipleVerifiedProfiles) { |
| 4790 FindAndMergeDuplicateProfiles_MultipleVerifiedProfiles) { | 4690 // Create a profile to dedupe with a higher frecency score. |
| 4791 EnableAutofillProfileCleanup(); | 4691 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 4792 | |
| 4793 // Create a verified profile with a higher frecency score. | |
| 4794 AutofillProfile profile1(base::GenerateGUID(), kSettingsOrigin); | |
| 4795 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson", | 4692 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson", |
| 4796 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", | 4693 "homer.simpson@abc.com", "", "742. Evergreen Terrace", |
| 4797 "", "Springfield", "IL", "91601", "", ""); | 4694 "", "Springfield", "IL", "91601", "US", ""); |
| 4798 profile1.set_use_count(5); | 4695 profile1.set_use_count(5); |
| 4799 profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); | 4696 profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); |
| 4800 | 4697 |
| 4698 // Create a similar verified profile with a medium frecency score. |
| 4699 AutofillProfile profile2(base::GenerateGUID(), kSettingsOrigin); |
| 4700 test::SetProfileInfo(&profile2, "Homer", "J", "Simpson", |
| 4701 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| 4702 "", "Springfield", "IL", "91601", "", ""); |
| 4703 profile2.set_use_count(5); |
| 4704 profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); |
| 4705 |
| 4801 // Create a similar verified profile with a lower frecency score. | 4706 // Create a similar verified profile with a lower frecency score. |
| 4802 AutofillProfile profile2(base::GenerateGUID(), kSettingsOrigin); | 4707 AutofillProfile profile3(base::GenerateGUID(), kSettingsOrigin); |
| 4803 test::SetProfileInfo(&profile2, "Homer", "Jay", "Simpson", | 4708 test::SetProfileInfo(&profile3, "Homer", "Jay", "Simpson", |
| 4804 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", | 4709 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 4805 "Springfield", "IL", "91601", "", "12345678910"); | 4710 "Springfield", "IL", "91601", "", "12345678910"); |
| 4806 profile2.set_use_count(3); | 4711 profile3.set_use_count(3); |
| 4807 profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); | 4712 profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); |
| 4808 | 4713 |
| 4809 personal_data_->AddProfile(profile1); | 4714 personal_data_->AddProfile(profile1); |
| 4810 personal_data_->AddProfile(profile2); | 4715 personal_data_->AddProfile(profile2); |
| 4811 | 4716 personal_data_->AddProfile(profile3); |
| 4812 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4717 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4813 .WillOnce(QuitMainMessageLoop()); | 4718 .WillOnce(QuitMainMessageLoop()); |
| 4814 base::MessageLoop::current()->Run(); | 4719 base::MessageLoop::current()->Run(); |
| 4815 | 4720 |
| 4816 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); | 4721 // Make sure the 3 profiles were saved. |
| 4722 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); |
| 4817 | 4723 |
| 4818 // Create a non verified imported profile to be merged with the saved | 4724 // Enable the profile cleanup now. Otherwise it would be triggered by the |
| 4819 // profiles. | 4725 // calls to AddProfile. |
| 4820 AutofillProfile imported_profile(base::GenerateGUID(), | 4726 EnableAutofillProfileCleanup(); |
| 4821 "https://www.example.com"); | |
| 4822 test::SetProfileInfo(&imported_profile, "Homer", "J", "Simpson", | |
| 4823 "homer.simpson@abc.com", "", "742. Evergreen Terrace", | |
| 4824 "", "Springfield", "IL", "91601", "US", ""); | |
| 4825 | 4727 |
| 4826 base::HistogramTester histogram_tester; | 4728 base::HistogramTester histogram_tester; |
| 4827 personal_data_->SaveImportedProfile(imported_profile); | |
| 4828 | 4729 |
| 4730 personal_data_->ApplyDedupingRoutine(); |
| 4829 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4731 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4830 .WillOnce(QuitMainMessageLoop()); | 4732 .WillOnce(QuitMainMessageLoop()); |
| 4831 base::MessageLoop::current()->Run(); | 4733 base::MessageLoop::current()->Run(); |
| 4832 | 4734 |
| 4833 // Get the profiles, sorted by frecency to have a deterministic order. | 4735 // Get the profiles, sorted by frecency to have a deterministic order. |
| 4834 std::vector<AutofillProfile*> profiles = | 4736 std::vector<AutofillProfile*> profiles = |
| 4835 personal_data_->GetProfilesToSuggest(); | 4737 personal_data_->GetProfilesToSuggest(); |
| 4836 | 4738 |
| 4837 // The |imported_profile| should have been discarded because the saved profile | 4739 // |profile1| should have been discarded because the saved profile with the |
| 4838 // with the highest frecency score is verified (|profile1|). Therefore, the | 4740 // highest frecency score is verified (|profile2|). Therefore, |profile1|'s |
| 4839 // |imported_profile|'s data should not have been merged with |profile1|'s | 4741 // data should not have been merged with |profile2|'s data. Then |profile2| |
| 4840 // data. Then |profile1| should have been compared to |profile2| but they | 4742 // should have been compared to |profile3| but they should not have merged |
| 4841 // should not have merged because both profiles are verified. | 4743 // because both profiles are verified. |
| 4842 ASSERT_EQ(2U, profiles.size()); | 4744 ASSERT_EQ(2U, profiles.size()); |
| 4843 // 2 profiles were considered for dedupe (the 2 saved profiles). | 4745 // 3 profiles were considered for dedupe. |
| 4844 histogram_tester.ExpectUniqueSample( | 4746 histogram_tester.ExpectUniqueSample( |
| 4845 "Autofill.NumberOfProfilesConsideredForDedupe", 2, 1); | 4747 "Autofill.NumberOfProfilesConsideredForDedupe", 3, 1); |
| 4846 // No profile was removed. | 4748 // 1 profile was removed (|profile1|). |
| 4847 histogram_tester.ExpectUniqueSample( | 4749 histogram_tester.ExpectUniqueSample( |
| 4848 "Autofill.NumberOfProfilesRemovedDuringDedupe", 0, 1); | 4750 "Autofill.NumberOfProfilesRemovedDuringDedupe", 1, 1); |
| 4849 | 4751 |
| 4850 EXPECT_EQ(profile1.guid(), profiles[0]->guid()); | 4752 EXPECT_EQ(profile2.guid(), profiles[0]->guid()); |
| 4851 EXPECT_EQ(profile2.guid(), profiles[1]->guid()); | 4753 EXPECT_EQ(profile3.guid(), profiles[1]->guid()); |
| 4852 // The profiles should have kept their original data. | 4754 // The profiles should have kept their original data. |
| 4853 EXPECT_EQ(UTF8ToUTF16("742 Evergreen Terrace."), | 4755 EXPECT_TRUE(profile2 == *profiles[0]); |
| 4854 profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1)); | 4756 EXPECT_TRUE(profile3 == *profiles[1]); |
| 4855 EXPECT_EQ(UTF8ToUTF16("742 Evergreen Terrace"), | 4757 EXPECT_EQ(profile2.use_count(), profiles[0]->use_count()); |
| 4856 profiles[1]->GetRawInfo(ADDRESS_HOME_LINE1)); | 4758 EXPECT_EQ(profile3.use_count(), profiles[1]->use_count()); |
| 4857 EXPECT_EQ(UTF8ToUTF16("J"), profiles[0]->GetRawInfo(NAME_MIDDLE)); | 4759 EXPECT_LT(profile2.use_date() - TimeDelta::FromSeconds(2), |
| 4858 EXPECT_EQ(UTF8ToUTF16("Jay"), profiles[1]->GetRawInfo(NAME_MIDDLE)); | |
| 4859 EXPECT_EQ(UTF8ToUTF16(""), profiles[0]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); | |
| 4860 EXPECT_EQ(UTF8ToUTF16("12345678910"), | |
| 4861 profiles[1]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); | |
| 4862 EXPECT_EQ(profile1.use_count(), profiles[0]->use_count()); | |
| 4863 EXPECT_EQ(profile2.use_count(), profiles[1]->use_count()); | |
| 4864 EXPECT_LT(profile1.use_date() - TimeDelta::FromSeconds(2), | |
| 4865 profiles[0]->use_date()); | 4760 profiles[0]->use_date()); |
| 4866 EXPECT_GT(profile1.use_date() + TimeDelta::FromSeconds(2), | 4761 EXPECT_GT(profile2.use_date() + TimeDelta::FromSeconds(2), |
| 4867 profiles[0]->use_date()); | 4762 profiles[0]->use_date()); |
| 4868 EXPECT_LT(profile2.use_date() - TimeDelta::FromSeconds(2), | 4763 EXPECT_LT(profile3.use_date() - TimeDelta::FromSeconds(2), |
| 4869 profiles[1]->use_date()); | 4764 profiles[1]->use_date()); |
| 4870 EXPECT_GT(profile2.use_date() + TimeDelta::FromSeconds(2), | 4765 EXPECT_GT(profile3.use_date() + TimeDelta::FromSeconds(2), |
| 4871 profiles[1]->use_date()); | 4766 profiles[1]->use_date()); |
| 4872 } | 4767 } |
| 4873 | 4768 |
| 4874 // Tests that ApplyProfileUseDatesFix sets the use date of profiles from an | 4769 // 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 | 4770 // incorrect value of 0 to [two weeks from now]. Also tests that SetProfiles |
| 4876 // does not modify any other profiles. | 4771 // does not modify any other profiles. |
| 4877 TEST_F(PersonalDataManagerTest, ApplyProfileUseDatesFix) { | 4772 TEST_F(PersonalDataManagerTest, ApplyProfileUseDatesFix) { |
| 4878 // Set the kAutofillProfileUseDatesFixed pref to true so that the fix is not | 4773 // Set the kAutofillProfileUseDatesFixed pref to true so that the fix is not |
| 4879 // applied just yet. | 4774 // applied just yet. |
| 4880 personal_data_->pref_service_->SetBoolean( | 4775 personal_data_->pref_service_->SetBoolean( |
| 4881 prefs::kAutofillProfileUseDatesFixed, true); | 4776 prefs::kAutofillProfileUseDatesFixed, true); |
| 4882 | 4777 |
| 4883 // Create a profile. The use date will be set to now automatically. | 4778 // Create a profile. The use date will be set to now automatically. |
| 4884 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | 4779 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 4885 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", | 4780 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", |
| 4886 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", | 4781 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", |
| 4887 "", "Springfield", "IL", "91601", "US", "12345678910"); | 4782 "", "Springfield", "IL", "91601", "US", "12345678910"); |
| 4888 | 4783 |
| 4889 // Create another profile and set its use date to the default value. | 4784 // Create another profile and set its use date to the default value. |
| 4890 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | 4785 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| 4891 test::SetProfileInfo(&profile2, "Marge", "", "Simpson", | 4786 test::SetProfileInfo(&profile2, "Marge", "", "Simpson", |
| 4892 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", | 4787 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", |
| 4893 "", "Springfield", "IL", "91601", "US", "12345678910"); | 4788 "", "Springfield", "IL", "91601", "US", "12345678910"); |
| 4894 profile2.set_use_date(base::Time()); | 4789 profile2.set_use_date(base::Time()); |
| 4895 | 4790 |
| 4896 personal_data_->AddProfile(profile1); | 4791 personal_data_->AddProfile(profile1); |
| 4897 personal_data_->AddProfile(profile2); | 4792 personal_data_->AddProfile(profile2); |
| 4898 | |
| 4899 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4793 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4900 .WillOnce(QuitMainMessageLoop()); | 4794 .WillOnce(QuitMainMessageLoop()); |
| 4901 base::MessageLoop::current()->Run(); | 4795 base::MessageLoop::current()->Run(); |
| 4902 | 4796 |
| 4903 // Get a sorted list of profiles. |profile1| will be first and |profile2| will | 4797 // Get a sorted list of profiles. |profile1| will be first and |profile2| will |
| 4904 // be second. | 4798 // be second. |
| 4905 std::vector<AutofillProfile*> saved_profiles = | 4799 std::vector<AutofillProfile*> saved_profiles = |
| 4906 personal_data_->GetProfilesToSuggest(); | 4800 personal_data_->GetProfilesToSuggest(); |
| 4907 | 4801 |
| 4908 ASSERT_EQ(2U, saved_profiles.size()); | 4802 ASSERT_EQ(2U, saved_profiles.size()); |
| 4909 | 4803 |
| 4910 // The use dates should not have been modified. | 4804 // The use dates should not have been modified. |
| 4911 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(1), | 4805 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(1), |
| 4912 saved_profiles[0]->use_date()); | 4806 saved_profiles[0]->use_date()); |
| 4913 EXPECT_EQ(base::Time(), saved_profiles[1]->use_date()); | 4807 EXPECT_EQ(base::Time(), saved_profiles[1]->use_date()); |
| 4914 | 4808 |
| 4915 // Set the pref to false to indicate the fix has never been run. | 4809 // Set the pref to false to indicate the fix has never been run. |
| 4916 personal_data_->pref_service_->SetBoolean( | 4810 personal_data_->pref_service_->SetBoolean( |
| 4917 prefs::kAutofillProfileUseDatesFixed, false); | 4811 prefs::kAutofillProfileUseDatesFixed, false); |
| 4918 | 4812 |
| 4919 personal_data_->ApplyProfileUseDatesFix(); | 4813 personal_data_->ApplyProfileUseDatesFix(); |
| 4920 | |
| 4921 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4814 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4922 .WillOnce(QuitMainMessageLoop()); | 4815 .WillOnce(QuitMainMessageLoop()); |
| 4923 base::MessageLoop::current()->Run(); | 4816 base::MessageLoop::current()->Run(); |
| 4924 | 4817 |
| 4925 // Get a sorted list of profiles. | 4818 // Get a sorted list of profiles. |
| 4926 saved_profiles = personal_data_->GetProfilesToSuggest(); | 4819 saved_profiles = personal_data_->GetProfilesToSuggest(); |
| 4927 | 4820 |
| 4928 ASSERT_EQ(2U, saved_profiles.size()); | 4821 ASSERT_EQ(2U, saved_profiles.size()); |
| 4929 | 4822 |
| 4930 // |profile1|'s use date should not have been modified. | 4823 // |profile1|'s use date should not have been modified. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4968 std::vector<AutofillProfile*> saved_profiles = | 4861 std::vector<AutofillProfile*> saved_profiles = |
| 4969 personal_data_->GetProfilesToSuggest(); | 4862 personal_data_->GetProfilesToSuggest(); |
| 4970 | 4863 |
| 4971 ASSERT_EQ(2U, saved_profiles.size()); | 4864 ASSERT_EQ(2U, saved_profiles.size()); |
| 4972 // The use dates should not have been modified. | 4865 // The use dates should not have been modified. |
| 4973 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(1), | 4866 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(1), |
| 4974 saved_profiles[0]->use_date()); | 4867 saved_profiles[0]->use_date()); |
| 4975 EXPECT_EQ(base::Time(), saved_profiles[1]->use_date()); | 4868 EXPECT_EQ(base::Time(), saved_profiles[1]->use_date()); |
| 4976 } | 4869 } |
| 4977 | 4870 |
| 4871 // Tests that ApplyDedupingRoutine works as expected in a realistic scenario. |
| 4872 // Tests that it merges the diffent set of similar profiles independently and |
| 4873 // that the resulting profiles have the right values, has no effect on the other |
| 4874 // profiles and that the data of verified profiles is not modified. |
| 4875 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MultipleDedupes) { |
| 4876 // Create a Homer home profile with a higher frecency score than other Homer |
| 4877 // profiles. |
| 4878 AutofillProfile Homer1(base::GenerateGUID(), "https://www.example.com"); |
| 4879 test::SetProfileInfo(&Homer1, "Homer", "J", "Simpson", |
| 4880 "homer.simpson@abc.com", "", "742. Evergreen Terrace", |
| 4881 "", "Springfield", "IL", "91601", "US", ""); |
| 4882 Homer1.set_use_count(10); |
| 4883 Homer1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); |
| 4884 |
| 4885 // Create a Homer home profile with a medium frecency score compared to other |
| 4886 // Homer profiles. |
| 4887 AutofillProfile Homer2(base::GenerateGUID(), "https://www.example.com"); |
| 4888 test::SetProfileInfo(&Homer2, "Homer", "Jay", "Simpson", |
| 4889 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 4890 "Springfield", "IL", "91601", "", "12345678910"); |
| 4891 Homer2.set_use_count(5); |
| 4892 Homer2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); |
| 4893 |
| 4894 // Create a Homer home profile with a lower frecency score than other Homer |
| 4895 // profiles. |
| 4896 AutofillProfile Homer3(base::GenerateGUID(), "https://www.example.com"); |
| 4897 test::SetProfileInfo(&Homer3, "Homer", "J", "Simpson", |
| 4898 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| 4899 "", "Springfield", "IL", "91601", "", ""); |
| 4900 Homer3.set_use_count(3); |
| 4901 Homer3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); |
| 4902 |
| 4903 // Create a Homer work profile (different address). |
| 4904 AutofillProfile Homer4(base::GenerateGUID(), "https://www.example.com"); |
| 4905 test::SetProfileInfo(&Homer4, "Homer", "J", "Simpson", |
| 4906 "homer.simpson@abc.com", "Fox", "12 Nuclear Plant.", "", |
| 4907 "Springfield", "IL", "91601", "US", "9876543"); |
| 4908 Homer4.set_use_count(3); |
| 4909 Homer4.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); |
| 4910 |
| 4911 // Create a Marge profile with a lower frecency score that other Marge |
| 4912 // profiles. |
| 4913 AutofillProfile Marge1(base::GenerateGUID(), kSettingsOrigin); |
| 4914 test::SetProfileInfo(&Marge1, "Marjorie", "J", "Simpson", |
| 4915 "marge.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 4916 "Springfield", "IL", "91601", "", "12345678910"); |
| 4917 Marge1.set_use_count(4); |
| 4918 Marge1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); |
| 4919 |
| 4920 // Create a verified Marge home profile with a lower frecency score that the |
| 4921 // other Marge profile. |
| 4922 AutofillProfile Marge2(base::GenerateGUID(), "https://www.example.com"); |
| 4923 test::SetProfileInfo(&Marge2, "Marjorie", "Jacqueline", "Simpson", |
| 4924 "marge.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 4925 "Springfield", "IL", "91601", "", "12345678910"); |
| 4926 Marge2.set_use_count(2); |
| 4927 Marge2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); |
| 4928 |
| 4929 // Create a Barney profile (guest user). |
| 4930 AutofillProfile Barney(base::GenerateGUID(), "https://www.example.com"); |
| 4931 test::SetProfileInfo(&Barney, "Barney", "", "Gumble", "barney.gumble@abc.com", |
| 4932 "ABC", "123 Other Street", "", "Springfield", "IL", |
| 4933 "91601", "", ""); |
| 4934 Barney.set_use_count(1); |
| 4935 Barney.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(180)); |
| 4936 |
| 4937 personal_data_->AddProfile(Homer1); |
| 4938 personal_data_->AddProfile(Homer2); |
| 4939 personal_data_->AddProfile(Homer3); |
| 4940 personal_data_->AddProfile(Homer4); |
| 4941 personal_data_->AddProfile(Marge1); |
| 4942 personal_data_->AddProfile(Marge2); |
| 4943 personal_data_->AddProfile(Barney); |
| 4944 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4945 .WillOnce(QuitMainMessageLoop()); |
| 4946 base::MessageLoop::current()->Run(); |
| 4947 |
| 4948 // Make sure the 7 profiles were saved; |
| 4949 EXPECT_EQ(7U, personal_data_->GetProfiles().size()); |
| 4950 |
| 4951 // Enable the profile cleanup now. Otherwise it would be triggered by the |
| 4952 // calls to AddProfile. |
| 4953 EnableAutofillProfileCleanup(); |
| 4954 |
| 4955 base::HistogramTester histogram_tester; |
| 4956 |
| 4957 // |Homer1| should get merged into |Homer2| which should then be merged into |
| 4958 // |Homer3|. |Marge2| should be discarded in favor of |Marge1| which is |
| 4959 // verified. |Homer4| and |Barney| should not be deduped at all. |
| 4960 personal_data_->ApplyDedupingRoutine(); |
| 4961 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4962 .WillOnce(QuitMainMessageLoop()); |
| 4963 base::MessageLoop::current()->Run(); |
| 4964 |
| 4965 // Get the profiles, sorted by frecency to have a deterministic order. |
| 4966 std::vector<AutofillProfile*> profiles = |
| 4967 personal_data_->GetProfilesToSuggest(); |
| 4968 |
| 4969 // The 2 duplicates Homer home profiles with the higher frecency and the |
| 4970 // unverified Marge profile should have been deduped. |
| 4971 ASSERT_EQ(4U, profiles.size()); |
| 4972 // 7 profiles were considered for dedupe. |
| 4973 histogram_tester.ExpectUniqueSample( |
| 4974 "Autofill.NumberOfProfilesConsideredForDedupe", 7, 1); |
| 4975 // 3 profile were removed (|Homer1|, |Homer2| and |Marge2|). |
| 4976 histogram_tester.ExpectUniqueSample( |
| 4977 "Autofill.NumberOfProfilesRemovedDuringDedupe", 3, 1); |
| 4978 |
| 4979 // The remaining profiles should be |Homer3|, |Marge1|, |Homer4| and |Barney| |
| 4980 // in this order of frecency. |
| 4981 EXPECT_EQ(Homer3.guid(), profiles[0]->guid()); |
| 4982 EXPECT_EQ(Marge1.guid(), profiles[1]->guid()); |
| 4983 EXPECT_EQ(Homer4.guid(), profiles[2]->guid()); |
| 4984 EXPECT_EQ(Barney.guid(), profiles[3]->guid()); |
| 4985 |
| 4986 // |Homer3|'s data: |
| 4987 // The address should be saved with the syntax of |Homer1| since it has the |
| 4988 // highest frecency score. |
| 4989 EXPECT_EQ(UTF8ToUTF16("742. Evergreen Terrace"), |
| 4990 profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1)); |
| 4991 // The middle name should be the full version found in |Homer2|, |
| 4992 EXPECT_EQ(UTF8ToUTF16("Jay"), profiles[0]->GetRawInfo(NAME_MIDDLE)); |
| 4993 // The phone number from |Homer2| should be kept (no loss of information). |
| 4994 EXPECT_EQ(UTF8ToUTF16("12345678910"), |
| 4995 profiles[0]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); |
| 4996 // The company name from |Homer3| should be kept (no loss of information). |
| 4997 EXPECT_EQ(UTF8ToUTF16("Fox"), profiles[0]->GetRawInfo(COMPANY_NAME)); |
| 4998 // The country from |Homer1| profile should be kept (no loss of information). |
| 4999 EXPECT_EQ(UTF8ToUTF16("US"), profiles[0]->GetRawInfo(ADDRESS_HOME_COUNTRY)); |
| 5000 // The use count that results from the merge should be the sum of Homer 1, 2 |
| 5001 // and 3's respective use counts. |
| 5002 EXPECT_EQ(Homer1.use_count() + Homer2.use_count() + Homer3.use_count(), |
| 5003 profiles[0]->use_count()); |
| 5004 // The use date that results from the merge should be the one from the |
| 5005 // |Homer1| since it was the most recently used profile. |
| 5006 EXPECT_LT(Homer1.use_date() - base::TimeDelta::FromSeconds(5), |
| 5007 profiles[0]->use_date()); |
| 5008 EXPECT_GT(Homer1.use_date() + base::TimeDelta::FromSeconds(5), |
| 5009 profiles[0]->use_date()); |
| 5010 |
| 5011 // The other profiles should not have been modified. |
| 5012 EXPECT_TRUE(Marge1 == *profiles[1]); |
| 5013 EXPECT_TRUE(Homer4 == *profiles[2]); |
| 5014 EXPECT_TRUE(Barney == *profiles[3]); |
| 5015 } |
| 5016 |
| 5017 // Tests that ApplyDedupingRoutine is not run if the feature is disabled. |
| 5018 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_FeatureDisabled) { |
| 5019 // Create a profile to dedupe. |
| 5020 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 5021 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson", |
| 5022 "homer.simpson@abc.com", "", "742. Evergreen Terrace", |
| 5023 "", "Springfield", "IL", "91601", "US", ""); |
| 5024 |
| 5025 // Create a similar profile. |
| 5026 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| 5027 test::SetProfileInfo(&profile2, "Homer", "J", "Simpson", |
| 5028 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| 5029 "", "Springfield", "IL", "91601", "", ""); |
| 5030 |
| 5031 personal_data_->AddProfile(profile1); |
| 5032 personal_data_->AddProfile(profile2); |
| 5033 |
| 5034 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5035 .WillOnce(QuitMainMessageLoop()); |
| 5036 base::MessageLoop::current()->Run(); |
| 5037 |
| 5038 // Make sure both profiles were saved. |
| 5039 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
| 5040 |
| 5041 // The deduping routine should not be run. |
| 5042 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); |
| 5043 |
| 5044 // Both profiles should still be present. |
| 5045 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
| 5046 } |
| 5047 |
| 5048 // Tests that ApplyDedupingRoutine is not run a second time on the same major |
| 5049 // version. |
| 5050 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_OncePerVersion) { |
| 5051 // Create a profile to dedupe. |
| 5052 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 5053 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson", |
| 5054 "homer.simpson@abc.com", "", "742. Evergreen Terrace", |
| 5055 "", "Springfield", "IL", "91601", "US", ""); |
| 5056 |
| 5057 // Create a similar profile. |
| 5058 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| 5059 test::SetProfileInfo(&profile2, "Homer", "J", "Simpson", |
| 5060 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| 5061 "", "Springfield", "IL", "91601", "", ""); |
| 5062 |
| 5063 personal_data_->AddProfile(profile1); |
| 5064 personal_data_->AddProfile(profile2); |
| 5065 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5066 .WillOnce(QuitMainMessageLoop()); |
| 5067 base::MessageLoop::current()->Run(); |
| 5068 |
| 5069 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
| 5070 |
| 5071 // Enable the profile cleanup now. Otherwise it would be triggered by the |
| 5072 // calls to AddProfile. |
| 5073 EnableAutofillProfileCleanup(); |
| 5074 |
| 5075 // The deduping routine should be run a first time. |
| 5076 EXPECT_TRUE(personal_data_->ApplyDedupingRoutine()); |
| 5077 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5078 .WillOnce(QuitMainMessageLoop()); |
| 5079 base::MessageLoop::current()->Run(); |
| 5080 |
| 5081 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); |
| 5082 |
| 5083 // The profiles should have been deduped |
| 5084 EXPECT_EQ(1U, profiles.size()); |
| 5085 |
| 5086 // Add another duplicate profile. |
| 5087 AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com"); |
| 5088 test::SetProfileInfo(&profile3, "Homer", "J", "Simpson", |
| 5089 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| 5090 "", "Springfield", "IL", "91601", "", ""); |
| 5091 |
| 5092 // Disable the profile cleanup before adding |profile3|. |
| 5093 base::FeatureList::ClearInstanceForTesting(); |
| 5094 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 5095 base::FeatureList::SetInstance(std::move(feature_list)); |
| 5096 |
| 5097 personal_data_->AddProfile(profile3); |
| 5098 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5099 .WillOnce(QuitMainMessageLoop()); |
| 5100 base::MessageLoop::current()->Run(); |
| 5101 |
| 5102 // Make sure |profile3| was saved. |
| 5103 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
| 5104 |
| 5105 // Re-enable the profile cleanup now that the profile was added. |
| 5106 EnableAutofillProfileCleanup(); |
| 5107 |
| 5108 // The deduping routine should not be run. |
| 5109 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); |
| 5110 |
| 5111 // The two duplicate profiles should still be present. |
| 5112 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
| 5113 } |
| 5114 |
| 4978 } // namespace autofill | 5115 } // namespace autofill |
| OLD | NEW |