Chromium Code Reviews| Index: components/autofill/core/browser/personal_data_manager_unittest.cc |
| diff --git a/components/autofill/core/browser/personal_data_manager_unittest.cc b/components/autofill/core/browser/personal_data_manager_unittest.cc |
| index 6c2b79aced15ba2f692a05a6247a8c44bc48e60f..e35c4986d37abff2d1beea95f988bb3d7f0c28ea 100644 |
| --- a/components/autofill/core/browser/personal_data_manager_unittest.cc |
| +++ b/components/autofill/core/browser/personal_data_manager_unittest.cc |
| @@ -4668,4 +4668,230 @@ TEST_F(PersonalDataManagerTest, |
| profiles[0]->use_date()); |
| } |
| +// Tests that FindAndMergeDuplicateProfiles only keeps the verified profile with |
| +// it's original data when deduping with similar profiles, even if it has a |
|
Mathieu
2016/06/17 14:15:09
nit: its
sebsg
2016/06/17 17:09:01
Done.
|
| +// higher frecency score. |
| +TEST_F(PersonalDataManagerTest, |
| + FindAndMergeDuplicateProfiles_VerifiedProfileFirst) { |
| + EnableAutofillProfileCleanup(); |
| + |
| + // Create a verified profile with a higher frecency score. |
| + AutofillProfile profile1(base::GenerateGUID(), kSettingsOrigin); |
| + test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", |
| + "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| + "Springfield", "IL", "91601", "", "12345678910"); |
| + profile1.set_use_count(5); |
| + profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); |
| + |
| + // Create a similar non verified profile with a lower frecency score. |
| + AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| + test::SetProfileInfo(&profile2, "Homer", "J", "Simpson", |
| + "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| + "", "Springfield", "IL", "91601", "", ""); |
| + profile2.set_use_count(3); |
| + profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); |
| + |
| + personal_data_->AddProfile(profile1); |
| + personal_data_->AddProfile(profile2); |
| + |
| + EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| + .WillOnce(QuitMainMessageLoop()); |
| + base::MessageLoop::current()->Run(); |
| + |
| + EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
| + |
| + // Create a similar new non verified imported profile to be merged with the |
| + // saved profiles. |
| + AutofillProfile imported_profile(base::GenerateGUID(), |
| + "https://www.example.com"); |
| + test::SetProfileInfo(&imported_profile, "Homer", "J", "Simpson", |
| + "homer.simpson@abc.com", "", "742. Evergreen Terrace", |
| + "", "Springfield", "IL", "91601", "US", ""); |
| + |
| + base::HistogramTester histogram_tester; |
| + personal_data_->SaveImportedProfile(imported_profile); |
| + |
| + EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| + .WillOnce(QuitMainMessageLoop()); |
| + base::MessageLoop::current()->Run(); |
| + |
| + std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); |
| + |
| + // The |imported_profile| should have merged with |profile2|. |profile2| |
| + // should then have been discarded because it is similar to the verified |
| + // |profile1|. |
| + ASSERT_EQ(1U, profiles.size()); |
| + // 2 profiles were considered for dedupe (profiles 1 and 2). |
| + histogram_tester.ExpectUniqueSample( |
| + "Autofill.NumberOfProfilesConsideredForDedupe", 2, 1); |
| + // 1 profile was removed (|profile2|). |
| + histogram_tester.ExpectUniqueSample( |
| + "Autofill.NumberOfProfilesRemovedDuringDedupe", 1, 1); |
| + |
| + // Only the verified |profile2| with it's original data should have been kept. |
| + EXPECT_EQ(profile1.guid(), profiles[0]->guid()); |
| + EXPECT_EQ(UTF8ToUTF16("742 Evergreen Terrace"), |
| + profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1)); |
| + EXPECT_EQ(UTF8ToUTF16("Jay"), profiles[0]->GetRawInfo(NAME_MIDDLE)); |
| + EXPECT_EQ(UTF8ToUTF16("12345678910"), |
| + profiles[0]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); |
| + EXPECT_EQ(UTF8ToUTF16(""), profiles[0]->GetRawInfo(COMPANY_NAME)); |
| + EXPECT_EQ(UTF8ToUTF16(""), profiles[0]->GetRawInfo(ADDRESS_HOME_COUNTRY)); |
| + EXPECT_EQ(profile1.use_count(), profiles[0]->use_count()); |
| + EXPECT_LT(profile1.use_date() - TimeDelta::FromSeconds(2), |
| + profiles[0]->use_date()); |
| + EXPECT_GT(profile1.use_date() + TimeDelta::FromSeconds(2), |
| + profiles[0]->use_date()); |
| +} |
| + |
| +// Tests that FindAndMergeDuplicateProfiles only keeps the verified profile with |
| +// it's original data when deduping with similar profiles, even if it has a |
| +// lower frecency score. |
| +TEST_F(PersonalDataManagerTest, |
| + FindAndMergeDuplicateProfiles_VerifiedProfileLast) { |
| + EnableAutofillProfileCleanup(); |
| + |
| + // Create a non verified profile with a higher frecency score. |
| + AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| + test::SetProfileInfo(&profile1, "Homer", "J", "Simpson", |
| + "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| + "", "Springfield", "IL", "91601", "", ""); |
| + profile1.set_use_count(5); |
| + profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); |
| + |
| + // Create a similar verified profile with a lower frecency score. |
| + AutofillProfile profile2(base::GenerateGUID(), kSettingsOrigin); |
| + test::SetProfileInfo(&profile2, "Homer", "Jay", "Simpson", |
| + "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| + "Springfield", "IL", "91601", "", "12345678910"); |
| + profile2.set_use_count(3); |
| + profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); |
| + |
| + personal_data_->AddProfile(profile1); |
| + personal_data_->AddProfile(profile2); |
| + |
| + EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| + .WillOnce(QuitMainMessageLoop()); |
| + base::MessageLoop::current()->Run(); |
| + |
| + EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
| + |
| + // Create a similar non verified imported profile to be merged with the saved |
| + // profiles. |
| + AutofillProfile imported_profile(base::GenerateGUID(), |
| + "https://www.example.com"); |
| + test::SetProfileInfo(&imported_profile, "Homer", "J", "Simpson", |
| + "homer.simpson@abc.com", "", "742. Evergreen Terrace", |
| + "", "Springfield", "IL", "91601", "US", ""); |
| + |
| + base::HistogramTester histogram_tester; |
| + personal_data_->SaveImportedProfile(imported_profile); |
| + |
| + EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| + .WillOnce(QuitMainMessageLoop()); |
| + base::MessageLoop::current()->Run(); |
| + |
| + std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); |
| + |
| + // The |imported_profile| should have merged with |profile1|. |profile1| |
| + // should then have been discarded because it is similar to the verified |
| + // |profile2|. |
| + ASSERT_EQ(1U, profiles.size()); |
| + // 2 profiles were considered for dedupe (profiles 1 and 2). |
| + histogram_tester.ExpectUniqueSample( |
| + "Autofill.NumberOfProfilesConsideredForDedupe", 2, 1); |
| + // 1 profile was removed (|profile1|). |
| + histogram_tester.ExpectUniqueSample( |
| + "Autofill.NumberOfProfilesRemovedDuringDedupe", 1, 1); |
| + |
| + // Only the verified |profile2| with it's original data should have been kept. |
| + EXPECT_EQ(profile2.guid(), profiles[0]->guid()); |
| + EXPECT_EQ(UTF8ToUTF16("742 Evergreen Terrace"), |
| + profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1)); |
| + EXPECT_EQ(UTF8ToUTF16("Jay"), profiles[0]->GetRawInfo(NAME_MIDDLE)); |
| + EXPECT_EQ(UTF8ToUTF16("12345678910"), |
| + profiles[0]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); |
| + EXPECT_EQ(UTF8ToUTF16(""), profiles[0]->GetRawInfo(COMPANY_NAME)); |
| + EXPECT_EQ(UTF8ToUTF16(""), profiles[0]->GetRawInfo(ADDRESS_HOME_COUNTRY)); |
| + EXPECT_EQ(profile2.use_count(), profiles[0]->use_count()); |
| + EXPECT_LT(profile2.use_date() - TimeDelta::FromSeconds(2), |
| + profiles[0]->use_date()); |
| + EXPECT_GT(profile2.use_date() + TimeDelta::FromSeconds(2), |
| + profiles[0]->use_date()); |
| +} |
| + |
| +// Tests that FindAndMergeDuplicateProfiles does not merge unverfied data into a |
| +// verified profile. Also tests that two verified profiles get merged. |
| +TEST_F(PersonalDataManagerTest, |
| + FindAndMergeDuplicateProfiles_MultipleVerifiedProfiles) { |
| + EnableAutofillProfileCleanup(); |
| + |
| + // Create a verified profile with a higher frecency score. |
| + AutofillProfile profile1(base::GenerateGUID(), kSettingsOrigin); |
| + test::SetProfileInfo(&profile1, "Homer", "J", "Simpson", |
| + "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| + "", "Springfield", "IL", "91601", "", ""); |
| + profile1.set_use_count(5); |
| + profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); |
| + |
| + // Create a similar verified profile with a lower frecency score. |
| + AutofillProfile profile2(base::GenerateGUID(), kSettingsOrigin); |
| + test::SetProfileInfo(&profile2, "Homer", "Jay", "Simpson", |
| + "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| + "Springfield", "IL", "91601", "", "12345678910"); |
| + profile2.set_use_count(3); |
| + profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); |
| + |
| + personal_data_->AddProfile(profile1); |
| + personal_data_->AddProfile(profile2); |
| + |
| + EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| + .WillOnce(QuitMainMessageLoop()); |
| + base::MessageLoop::current()->Run(); |
| + |
| + EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
| + |
| + // Create a non verified imported profile to be merged with the saved |
| + // profiles. |
| + AutofillProfile imported_profile(base::GenerateGUID(), |
| + "https://www.example.com"); |
| + test::SetProfileInfo(&imported_profile, "Homer", "J", "Simpson", |
| + "homer.simpson@abc.com", "", "742. Evergreen Terrace", |
| + "", "Springfield", "IL", "91601", "US", ""); |
| + |
| + base::HistogramTester histogram_tester; |
| + personal_data_->SaveImportedProfile(imported_profile); |
| + |
| + EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| + .WillOnce(QuitMainMessageLoop()); |
| + base::MessageLoop::current()->Run(); |
| + |
| + std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); |
| + |
| + // The |imported_profile| should have been discarded because the saved profile |
| + // with the highest frecency score is verified (|profile1|). Therefore, the |
| + // |imported_profile|'s data should not have been merged with the |
| + // |imported_profile|'s data. However, |profile1| should then have been merged |
| + // with |profile2| since they are both verified. |
| + ASSERT_EQ(1U, profiles.size()); |
| + // 2 profiles were considered for dedupe (the 2 saved profiles). |
| + histogram_tester.ExpectUniqueSample( |
| + "Autofill.NumberOfProfilesConsideredForDedupe", 2, 1); |
| + // 1 profile was removed (|profile1|). |
| + histogram_tester.ExpectUniqueSample( |
| + "Autofill.NumberOfProfilesRemovedDuringDedupe", 1, 1); |
| + |
| + EXPECT_EQ(profile2.guid(), profiles[0]->guid()); |
| + // The address syntax from |profile1| should have been kept (higher frecency |
| + // score). |
| + EXPECT_EQ(UTF8ToUTF16("742 Evergreen Terrace."), |
| + profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1)); |
| + // The full middle name from |profile2| should have been kept (no loss of |
| + // information). |
| + EXPECT_EQ(UTF8ToUTF16("Jay"), profiles[0]->GetRawInfo(NAME_MIDDLE)); |
| + // Since the |imported_profile| matched a verified profile, it's data should |
| + // not have been merged. |
| + EXPECT_EQ(UTF8ToUTF16(""), profiles[0]->GetRawInfo(ADDRESS_HOME_COUNTRY)); |
| +} |
| + |
| } // namespace autofill |