0

Since the use_count and use_date of new profiles were changed to 1 and Now() respectively (were 0 and base::Time), there is no need to record the use of a newly merged profile. The merging logic will have set the usage statistics to the expected values.

BUG=611223
TEST=PersonalDataManagerTest

Review-Url: https://codereview.chromium.org/1974533003
Cr-Commit-Position: refs/heads/master@{#393344}
This commit is contained in:
sebsg
2016-05-12 13:40:39 -07:00
committed by Commit bot
parent 7f68ab4de6
commit f25a299b4a
2 changed files with 47 additions and 6 deletions

@ -902,8 +902,6 @@ std::string PersonalDataManager::MergeProfile(
// the profile will have a very slightly newer time reflecting what's
// actually stored in the database.
existing_profile->set_modification_date(base::Time::Now());
existing_profile->RecordAndLogUse();
}
merged_profiles->push_back(*existing_profile);
}

@ -4157,13 +4157,14 @@ TEST_F(PersonalDataManagerTest, SaveImportedProfile) {
EXPECT_EQ(base::UTF8ToUTF16(changed_field.field_value),
saved_profiles.front()->GetRawInfo(changed_field.field_type));
}
// Verify that the merged profile's modification and use dates were
// updated.
// Verify that the merged profile's use count, use date and modification
// date were updated.
EXPECT_EQ(2U, saved_profiles.front()->use_count());
EXPECT_GT(base::TimeDelta::FromMilliseconds(500),
base::Time::Now() - saved_profiles.front()->use_date());
EXPECT_GT(
base::TimeDelta::FromMilliseconds(500),
base::Time::Now() - saved_profiles.front()->modification_date());
EXPECT_GT(base::TimeDelta::FromMilliseconds(500),
base::Time::Now() - saved_profiles.front()->use_date());
}
// Erase the profiles for the next test.
@ -4208,4 +4209,46 @@ TEST_F(PersonalDataManagerTest, MergeProfile_Frecency) {
EXPECT_EQ(profile2.guid(), guid);
}
// Tests that MergeProfile produces a merged profile with the expected usage
// statistics.
TEST_F(PersonalDataManagerTest, MergeProfile_UsageStats) {
// Create an initial profile with a use count of 10, an old use date and an
// old modification date of 4 days ago.
AutofillProfile profile(base::GenerateGUID(), "https://www.example.com");
test::SetProfileInfo(&profile, "Homer", "Jay", "Simpson",
"homer.simpson@abc.com", "SNP", "742 Evergreen Terrace",
"", "Springfield", "IL", "91601", "US", "12345678910");
profile.set_use_count(4U);
profile.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(4));
profile.set_modification_date(base::Time::Now() -
base::TimeDelta::FromDays(4));
// Create the |existing_profiles| vector.
std::vector<AutofillProfile*> existing_profiles;
existing_profiles.push_back(&profile);
// Create a new imported profile that will get merged with the existing one.
AutofillProfile imported_profile(base::GenerateGUID(),
"https://www.example.com");
test::SetProfileInfo(&imported_profile, "Homer", "Jay", "Simpson",
"homer.simpson@abc.com", "", "742 Evergreen Terrace", "",
"Springfield", "IL", "91601", "US", "12345678910");
// Merge the imported profile into the existing profiles.
std::vector<AutofillProfile> profiles;
std::string guid = personal_data_->MergeProfile(
imported_profile, existing_profiles, "US-EN", &profiles);
// The new profile should be merged into the existing profile.
EXPECT_EQ(profile.guid(), guid);
// The use count should have been incremented by one.
EXPECT_EQ(5U, profile.use_count());
// The use date and modification dates should have been set to less than 500
// milliseconds ago.
EXPECT_GT(base::TimeDelta::FromMilliseconds(500),
base::Time::Now() - profile.use_date());
EXPECT_GT(base::TimeDelta::FromMilliseconds(500),
base::Time::Now() - profile.modification_date());
}
} // namespace autofill