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:
components/autofill/core/browser
@@ -902,8 +902,6 @@ std::string PersonalDataManager::MergeProfile(
|
|||||||
// the profile will have a very slightly newer time reflecting what's
|
// the profile will have a very slightly newer time reflecting what's
|
||||||
// actually stored in the database.
|
// actually stored in the database.
|
||||||
existing_profile->set_modification_date(base::Time::Now());
|
existing_profile->set_modification_date(base::Time::Now());
|
||||||
|
|
||||||
existing_profile->RecordAndLogUse();
|
|
||||||
}
|
}
|
||||||
merged_profiles->push_back(*existing_profile);
|
merged_profiles->push_back(*existing_profile);
|
||||||
}
|
}
|
||||||
|
@@ -4157,13 +4157,14 @@ TEST_F(PersonalDataManagerTest, SaveImportedProfile) {
|
|||||||
EXPECT_EQ(base::UTF8ToUTF16(changed_field.field_value),
|
EXPECT_EQ(base::UTF8ToUTF16(changed_field.field_value),
|
||||||
saved_profiles.front()->GetRawInfo(changed_field.field_type));
|
saved_profiles.front()->GetRawInfo(changed_field.field_type));
|
||||||
}
|
}
|
||||||
// Verify that the merged profile's modification and use dates were
|
// Verify that the merged profile's use count, use date and modification
|
||||||
// updated.
|
// 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(
|
EXPECT_GT(
|
||||||
base::TimeDelta::FromMilliseconds(500),
|
base::TimeDelta::FromMilliseconds(500),
|
||||||
base::Time::Now() - saved_profiles.front()->modification_date());
|
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.
|
// Erase the profiles for the next test.
|
||||||
@@ -4208,4 +4209,46 @@ TEST_F(PersonalDataManagerTest, MergeProfile_Frecency) {
|
|||||||
EXPECT_EQ(profile2.guid(), guid);
|
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
|
} // namespace autofill
|
||||||
|
Reference in New Issue
Block a user