Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Unified Diff: components/autofill/core/browser/personal_data_manager_unittest.cc

Issue 2077003002: [Autofill] Fix profiles with bad |use_date| values. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..35c8936d143dfc3242a89ae42e0ad2771bc445fb 100644
--- a/components/autofill/core/browser/personal_data_manager_unittest.cc
+++ b/components/autofill/core/browser/personal_data_manager_unittest.cc
@@ -4668,4 +4668,67 @@ TEST_F(PersonalDataManagerTest,
profiles[0]->use_date());
}
+// Tests that ApplyProfileUseDatesFix sets the use date of profiles from an
+// incorrect value of 0 to [two weeks from now]. Also tests that SetProfiles
+// does not modify any other profiles.
+TEST_F(PersonalDataManagerTest, ApplyProfileUseDatesFix) {
+ // Set the kAutofillProfileUseDatesFixed pref to true so that the fix is not
+ // applied just yet.
+ personal_data_->pref_service_->SetBoolean(
+ prefs::kAutofillProfileUseDatesFixed, true);
+
+ // Create a profile. The use date will be set to now automatically.
+ AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com");
+ test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson",
+ "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace",
+ "", "Springfield", "IL", "91601", "US", "12345678910");
+
+ // Create another profile and set its use date to the default value.
+ AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com");
+ test::SetProfileInfo(&profile2, "Marge", "", "Simpson",
+ "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace",
+ "", "Springfield", "IL", "91601", "US", "12345678910");
+ profile2.set_use_date(base::Time());
+
+ personal_data_->AddProfile(profile1);
+ personal_data_->AddProfile(profile2);
+
+ EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
+ .WillOnce(QuitMainMessageLoop());
+ base::MessageLoop::current()->Run();
+
+ // Get a sorted list of profiles. |profile1| will be first and |profile2| will
+ // be second.
+ std::vector<AutofillProfile*> saved_profiles =
+ personal_data_->GetProfilesToSuggest();
+
+ ASSERT_EQ(2U, saved_profiles.size());
+ // The use dates should not have been modified.
+ EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(1),
+ saved_profiles[0]->use_date());
+ EXPECT_EQ(base::Time(), saved_profiles[1]->use_date());
+
+ // Set the pref to false to indicate the fix has never been run.
+ personal_data_->pref_service_->SetBoolean(
+ prefs::kAutofillProfileUseDatesFixed, false);
+ personal_data_->ApplyProfileUseDatesFix();
+
+ EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
+ .WillOnce(QuitMainMessageLoop());
+ base::MessageLoop::current()->Run();
+
+ // Get a sorted list of profiles.
+ saved_profiles = personal_data_->GetProfilesToSuggest();
+
+ ASSERT_EQ(2U, saved_profiles.size());
+ // |profile1|'s use date should not have been modified.
+ EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(1),
+ saved_profiles[0]->use_date());
+ // |profile2|'s use date should have been set to two weeks before now.
+ EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(15),
+ saved_profiles[1]->use_date());
+ EXPECT_GE(base::Time::Now() - base::TimeDelta::FromDays(13),
+ saved_profiles[1]->use_date());
sebsg 2016/06/17 17:33:05 Could you also test that the fix is not applied a
Mathieu 2016/06/17 17:45:23 Done.
+}
+
} // namespace autofill
« no previous file with comments | « components/autofill/core/browser/personal_data_manager.cc ('k') | components/autofill/core/common/autofill_pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698