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

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

Issue 2639403002: [Autofill] Remove direct use of base::Time::Now() in Autofill (Closed)
Patch Set: Rebase Created 3 years, 11 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 18bb0aebdd43692e5a59a927b3175659b6b0fd1f..a130961ecd6db02457e5b43896bba580f7399f26 100644
--- a/components/autofill/core/browser/personal_data_manager_unittest.cc
+++ b/components/autofill/core/browser/personal_data_manager_unittest.cc
@@ -23,9 +23,11 @@
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/waitable_event.h"
#include "base/test/histogram_tester.h"
+#include "base/test/simple_test_clock.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "build/build_config.h"
+#include "components/autofill/core/browser/autofill_clock.h"
#include "components/autofill/core/browser/autofill_experiments.h"
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
@@ -66,6 +68,10 @@ const std::string kUTF8MidlineEllipsis =
"\xE2\x80\xA2\xE2\x80\x86"
"\xE2\x80\xA2\xE2\x80\x86";
+const base::Time kFirstArbitraryTestTime = base::Time::FromDoubleT(25);
+const base::Time kSecondArbitraryTestTime = base::Time::FromDoubleT(1000);
+const base::Time kThirdArbitraryTestTime = base::Time::FromDoubleT(5000);
+
ACTION(QuitMainMessageLoop) {
base::MessageLoop::current()->QuitWhenIdle();
}
@@ -263,13 +269,14 @@ class PersonalDataManagerTest : public testing::Test {
"347666888555" /* American Express */, "04",
"2999");
credit_card0.set_use_count(3);
- credit_card0.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1));
+ credit_card0.set_use_date(AutofillClock::Now() -
+ base::TimeDelta::FromDays(1));
personal_data_->AddCreditCard(credit_card0);
CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B",
"https://www.example.com");
credit_card1.set_use_count(300);
- credit_card1.set_use_date(base::Time::Now() -
+ credit_card1.set_use_date(AutofillClock::Now() -
base::TimeDelta::FromDays(10));
test::SetCreditCardInfo(&credit_card1, "John Dillinger",
"423456789012" /* Visa */, "01", "2999");
@@ -278,7 +285,8 @@ class PersonalDataManagerTest : public testing::Test {
CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B",
"https://www.example.com");
credit_card2.set_use_count(1);
- credit_card2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1));
+ credit_card2.set_use_date(AutofillClock::Now() -
+ base::TimeDelta::FromDays(1));
test::SetCreditCardInfo(&credit_card2, "Bonnie Parker",
"518765432109" /* Mastercard */, "12", "2999");
personal_data_->AddCreditCard(credit_card2);
@@ -417,6 +425,11 @@ TEST_F(PersonalDataManagerTest, AddProfile) {
// Test that a new profile has its basic information set.
TEST_F(PersonalDataManagerTest, AddProfile_BasicInformation) {
+ // Create the test clock and set the time to a specific value.
+ base::SimpleTestClock* test_clock = new base::SimpleTestClock();
+ AutofillClock::SetClockForTests(test_clock);
+ test_clock->SetNow(kFirstArbitraryTestTime);
+
// Add a profile to the database.
AutofillProfile profile(test::GetFullProfile());
profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com"));
@@ -432,13 +445,17 @@ TEST_F(PersonalDataManagerTest, AddProfile_BasicInformation) {
// Make sure the use count and use date were set.
EXPECT_EQ(1U, results[0]->use_count());
- EXPECT_NE(base::Time(), results[0]->use_date());
- EXPECT_NE(base::Time(), results[0]->modification_date());
+ EXPECT_EQ(kFirstArbitraryTestTime, results[0]->use_date());
+ EXPECT_EQ(kFirstArbitraryTestTime, results[0]->modification_date());
}
TEST_F(PersonalDataManagerTest, DontDuplicateServerProfile) {
EnableWalletCardImport();
+ // Create the test clock.
+ base::SimpleTestClock* test_clock = new base::SimpleTestClock();
+ AutofillClock::SetClockForTests(test_clock);
+
std::vector<AutofillProfile> server_profiles;
server_profiles.push_back(
AutofillProfile(AutofillProfile::SERVER_PROFILE, "a123"));
@@ -462,6 +479,10 @@ TEST_F(PersonalDataManagerTest, DontDuplicateServerProfile) {
"500 Oak View", "Apt 8", "Houston", "TX", "77401", "US",
"");
EXPECT_TRUE(scraped_profile.IsSubsetOf(server_profiles.back(), "en-US"));
+
+ // Set the time to a specific value.
+ test_clock->SetNow(kFirstArbitraryTestTime);
+
std::string saved_guid = personal_data_->SaveImportedProfile(scraped_profile);
EXPECT_NE(scraped_profile.guid(), saved_guid);
@@ -474,10 +495,10 @@ TEST_F(PersonalDataManagerTest, DontDuplicateServerProfile) {
EXPECT_EQ(0U, personal_data_->web_profiles().size());
ASSERT_EQ(1U, personal_data_->GetProfiles().size());
- // Verify that the server profile's use date was updated.
+ // Verify that the server profile's use date was updated with the specified
+ // value.
const AutofillProfile* server_profile = personal_data_->GetProfiles()[0];
- EXPECT_GT(base::TimeDelta::FromMilliseconds(500),
- base::Time::Now() - server_profile->use_date());
+ EXPECT_EQ(kFirstArbitraryTestTime, server_profile->use_date());
}
// Tests that SaveImportedProfile sets the modification date on new profiles.
@@ -489,7 +510,7 @@ TEST_F(PersonalDataManagerTest, SaveImportedProfileSetModificationDate) {
const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles();
ASSERT_EQ(1U, profiles.size());
EXPECT_GT(base::TimeDelta::FromMilliseconds(500),
- base::Time::Now() - profiles[0]->modification_date());
+ AutofillClock::Now() - profiles[0]->modification_date());
}
TEST_F(PersonalDataManagerTest, AddUpdateRemoveProfiles) {
@@ -607,6 +628,11 @@ TEST_F(PersonalDataManagerTest, AddUpdateRemoveCreditCards) {
// Test that a new credit card has its basic information set.
TEST_F(PersonalDataManagerTest, AddCreditCard_BasicInformation) {
+ // Create the test clock and set the time to a specific value.
+ base::SimpleTestClock* test_clock = new base::SimpleTestClock();
+ AutofillClock::SetClockForTests(test_clock);
+ test_clock->SetNow(kFirstArbitraryTestTime);
+
// Add a credit to the database.
CreditCard credit_card(base::GenerateGUID(), "https://www.example.com");
test::SetCreditCardInfo(&credit_card, "John Dillinger",
@@ -623,8 +649,8 @@ TEST_F(PersonalDataManagerTest, AddCreditCard_BasicInformation) {
// Make sure the use count and use date were set.
EXPECT_EQ(1U, results[0]->use_count());
- EXPECT_NE(base::Time(), results[0]->use_date());
- EXPECT_NE(base::Time(), results[0]->modification_date());
+ EXPECT_EQ(kFirstArbitraryTestTime, results[0]->use_date());
+ EXPECT_EQ(kFirstArbitraryTestTime, results[0]->modification_date());
}
TEST_F(PersonalDataManagerTest, UpdateUnverifiedProfilesAndCreditCards) {
@@ -3416,7 +3442,7 @@ TEST_F(PersonalDataManagerTest, GetProfileSuggestions_Ranking) {
"johnwayne@me.xyz", "Fox",
"123 Zoo St.\nSecond Line\nThird line", "unit 5",
"Hollywood", "CA", "91601", "US", "12345678910");
- profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1));
+ profile3.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1));
profile3.set_use_count(5);
personal_data_->AddProfile(profile3);
@@ -3425,7 +3451,7 @@ TEST_F(PersonalDataManagerTest, GetProfileSuggestions_Ranking) {
"johnwayne@me.xyz", "Fox",
"123 Zoo St.\nSecond Line\nThird line", "unit 5",
"Hollywood", "CA", "91601", "US", "12345678910");
- profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1));
+ profile1.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1));
profile1.set_use_count(10);
personal_data_->AddProfile(profile1);
@@ -3434,7 +3460,7 @@ TEST_F(PersonalDataManagerTest, GetProfileSuggestions_Ranking) {
"johnwayne@me.xyz", "Fox",
"123 Zoo St.\nSecond Line\nThird line", "unit 5",
"Hollywood", "CA", "91601", "US", "12345678910");
- profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15));
+ profile2.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(15));
profile2.set_use_count(300);
personal_data_->AddProfile(profile2);
@@ -3583,7 +3609,7 @@ TEST_F(PersonalDataManagerTest,
test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12",
"2999");
server_cards.back().set_use_count(2);
- server_cards.back().set_use_date(base::Time::Now() -
+ server_cards.back().set_use_date(AutofillClock::Now() -
base::TimeDelta::FromDays(1));
server_cards.back().SetTypeForMaskedCard(kVisaCard);
@@ -3591,7 +3617,7 @@ TEST_F(PersonalDataManagerTest,
test::SetCreditCardInfo(&server_cards.back(), "Jesse James", "2109", "12",
"2999");
server_cards.back().set_use_count(6);
- server_cards.back().set_use_date(base::Time::Now() -
+ server_cards.back().set_use_date(AutofillClock::Now() -
base::TimeDelta::FromDays(1));
test::SetServerCreditCards(autofill_table_, server_cards);
@@ -3632,14 +3658,16 @@ TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ExpiredCards) {
test::SetCreditCardInfo(&credit_card1, "Clyde Barrow",
"347666888555" /* American Express */, "04", "1999");
credit_card1.set_use_count(300);
- credit_card1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(10));
+ credit_card1.set_use_date(AutofillClock::Now() -
+ base::TimeDelta::FromDays(10));
personal_data_->AddCreditCard(credit_card1);
// Add an expired card with a lower frecency score.
CreditCard credit_card2("1141084B-72D7-4B73-90CF-3D6AC154673B",
"https://www.example.com");
credit_card2.set_use_count(3);
- credit_card2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1));
+ credit_card2.set_use_date(AutofillClock::Now() -
+ base::TimeDelta::FromDays(1));
test::SetCreditCardInfo(&credit_card2, "John Dillinger",
"423456789012" /* Visa */, "01", "1998");
personal_data_->AddCreditCard(credit_card2);
@@ -3675,13 +3703,15 @@ TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_NumberMissing) {
test::SetCreditCardInfo(&credit_card0, "Clyde Barrow",
"347666888555" /* American Express */, "04", "2999");
credit_card0.set_use_count(3);
- credit_card0.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1));
+ credit_card0.set_use_date(AutofillClock::Now() -
+ base::TimeDelta::FromDays(1));
personal_data_->AddCreditCard(credit_card0);
CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B",
"https://www.example.com");
credit_card1.set_use_count(300);
- credit_card1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(10));
+ credit_card1.set_use_date(AutofillClock::Now() -
+ base::TimeDelta::FromDays(10));
test::SetCreditCardInfo(&credit_card1, "John Dillinger", "", "01", "2999");
personal_data_->AddCreditCard(credit_card1);
@@ -3718,7 +3748,7 @@ TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ServerDuplicates) {
test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
"9012" /* Visa */, "01", "2999");
server_cards.back().set_use_count(2);
- server_cards.back().set_use_date(base::Time::Now() -
+ server_cards.back().set_use_date(AutofillClock::Now() -
base::TimeDelta::FromDays(15));
server_cards.back().SetTypeForMaskedCard(kVisaCard);
@@ -3728,7 +3758,7 @@ TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ServerDuplicates) {
test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", "2109", "12",
"2999");
server_cards.back().set_use_count(3);
- server_cards.back().set_use_date(base::Time::Now() -
+ server_cards.back().set_use_date(AutofillClock::Now() -
base::TimeDelta::FromDays(15));
server_cards.back().SetTypeForMaskedCard(kVisaCard);
@@ -3739,7 +3769,7 @@ TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ServerDuplicates) {
test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
"347666888555" /* American Express */, "04", "2999");
server_cards.back().set_use_count(1);
- server_cards.back().set_use_date(base::Time::Now() -
+ server_cards.back().set_use_date(AutofillClock::Now() -
base::TimeDelta::FromDays(15));
test::SetServerCreditCards(autofill_table_, server_cards);
@@ -3826,7 +3856,7 @@ TEST_F(PersonalDataManagerTest,
test::SetCreditCardInfo(&local_card, "Homer Simpson",
"423456789012" /* Visa */, "01", "2999");
local_card.set_use_count(3);
- local_card.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1));
+ local_card.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1));
credit_cards.push_back(&local_card);
// Create a full server card that is a duplicate of one of the local cards.
@@ -3834,7 +3864,7 @@ TEST_F(PersonalDataManagerTest,
test::SetCreditCardInfo(&full_server_card, "Homer Simpson",
"423456789012" /* Visa */, "01", "2999");
full_server_card.set_use_count(1);
- full_server_card.set_use_date(base::Time::Now() -
+ full_server_card.set_use_date(AutofillClock::Now() -
base::TimeDelta::FromDays(15));
credit_cards.push_back(&full_server_card);
@@ -3853,7 +3883,7 @@ TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_LocalShadowsMasked) {
CreditCard local_card("1141084B-72D7-4B73-90CF-3D6AC154673B",
"https://www.example.com");
local_card.set_use_count(300);
- local_card.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(10));
+ local_card.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(10));
test::SetCreditCardInfo(&local_card, "Homer Simpson",
"423456789012" /* Visa */, "01", "2999");
credit_cards.push_back(&local_card);
@@ -3863,7 +3893,8 @@ TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_LocalShadowsMasked) {
test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */,
"01", "2999");
masked_card.set_use_count(2);
- masked_card.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15));
+ masked_card.set_use_date(AutofillClock::Now() -
+ base::TimeDelta::FromDays(15));
masked_card.SetTypeForMaskedCard(kVisaCard);
credit_cards.push_back(&masked_card);
@@ -3883,7 +3914,7 @@ TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_FullServerAndMasked) {
test::SetCreditCardInfo(&full_server_card, "Homer Simpson",
"423456789012" /* Visa */, "01", "2999");
full_server_card.set_use_count(1);
- full_server_card.set_use_date(base::Time::Now() -
+ full_server_card.set_use_date(AutofillClock::Now() -
base::TimeDelta::FromDays(15));
credit_cards.push_back(&full_server_card);
@@ -3892,7 +3923,8 @@ TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_FullServerAndMasked) {
test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */,
"01", "2999");
masked_card.set_use_count(2);
- masked_card.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15));
+ masked_card.set_use_date(AutofillClock::Now() -
+ base::TimeDelta::FromDays(15));
masked_card.SetTypeForMaskedCard(kVisaCard);
credit_cards.push_back(&masked_card);
@@ -3908,7 +3940,8 @@ TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_DifferentCards) {
CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B",
"https://www.example.com");
credit_card2.set_use_count(1);
- credit_card2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1));
+ credit_card2.set_use_date(AutofillClock::Now() -
+ base::TimeDelta::FromDays(1));
test::SetCreditCardInfo(&credit_card2, "Homer Simpson",
"518765432109" /* Mastercard */, "", "");
credit_cards.push_back(&credit_card2);
@@ -3917,7 +3950,8 @@ TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_DifferentCards) {
CreditCard credit_card4(CreditCard::MASKED_SERVER_CARD, "b456");
test::SetCreditCardInfo(&credit_card4, "Homer Simpson", "2109", "12", "2999");
credit_card4.set_use_count(3);
- credit_card4.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15));
+ credit_card4.set_use_date(AutofillClock::Now() -
+ base::TimeDelta::FromDays(15));
credit_card4.SetTypeForMaskedCard(kVisaCard);
credit_cards.push_back(&credit_card4);
@@ -3927,7 +3961,8 @@ TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_DifferentCards) {
test::SetCreditCardInfo(&credit_card5, "Homer Simpson",
"347666888555" /* American Express */, "04", "2999");
credit_card5.set_use_count(1);
- credit_card5.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15));
+ credit_card5.set_use_date(AutofillClock::Now() -
+ base::TimeDelta::FromDays(15));
credit_cards.push_back(&credit_card5);
PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards);
@@ -3935,38 +3970,40 @@ TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_DifferentCards) {
}
TEST_F(PersonalDataManagerTest, RecordUseOf) {
- base::Time creation_time = base::Time::FromTimeT(12345);
+ // Create the test clock and set the time to a specific value.
+ base::SimpleTestClock* test_clock = new base::SimpleTestClock();
+ AutofillClock::SetClockForTests(test_clock);
+ test_clock->SetNow(kFirstArbitraryTestTime);
AutofillProfile profile(test::GetFullProfile());
- profile.set_use_date(creation_time);
- profile.set_modification_date(creation_time);
EXPECT_EQ(1U, profile.use_count());
- EXPECT_EQ(creation_time, profile.use_date());
- EXPECT_EQ(creation_time, profile.modification_date());
+ EXPECT_EQ(kFirstArbitraryTestTime, profile.use_date());
+ EXPECT_EQ(kFirstArbitraryTestTime, profile.modification_date());
personal_data_->AddProfile(profile);
CreditCard credit_card(base::GenerateGUID(), "https://www.example.com");
test::SetCreditCardInfo(&credit_card, "John Dillinger",
"423456789012" /* Visa */, "01", "2999");
- credit_card.set_use_date(creation_time);
- credit_card.set_modification_date(creation_time);
EXPECT_EQ(1U, credit_card.use_count());
- EXPECT_EQ(creation_time, credit_card.use_date());
- EXPECT_EQ(creation_time, credit_card.modification_date());
+ EXPECT_EQ(kFirstArbitraryTestTime, credit_card.use_date());
+ EXPECT_EQ(kFirstArbitraryTestTime, credit_card.modification_date());
personal_data_->AddCreditCard(credit_card);
EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
.WillOnce(QuitMainMessageLoop());
base::RunLoop().Run();
+ // Set the current time to another value.
+ test_clock->SetNow(kSecondArbitraryTestTime);
+
// Notify the PDM that the profile and credit card were used.
AutofillProfile* added_profile =
personal_data_->GetProfileByGUID(profile.guid());
ASSERT_TRUE(added_profile);
EXPECT_EQ(*added_profile, profile);
EXPECT_EQ(1U, added_profile->use_count());
- EXPECT_EQ(creation_time, added_profile->use_date());
- EXPECT_NE(creation_time, added_profile->modification_date());
+ EXPECT_EQ(kFirstArbitraryTestTime, added_profile->use_date());
+ EXPECT_EQ(kFirstArbitraryTestTime, added_profile->modification_date());
personal_data_->RecordUseOf(profile);
CreditCard* added_card =
@@ -3974,8 +4011,8 @@ TEST_F(PersonalDataManagerTest, RecordUseOf) {
ASSERT_TRUE(added_card);
EXPECT_EQ(*added_card, credit_card);
EXPECT_EQ(1U, added_card->use_count());
- EXPECT_EQ(creation_time, added_card->use_date());
- EXPECT_NE(creation_time, added_card->modification_date());
+ EXPECT_EQ(kFirstArbitraryTestTime, added_card->use_date());
+ EXPECT_EQ(kFirstArbitraryTestTime, added_card->modification_date());
personal_data_->RecordUseOf(credit_card);
EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
@@ -3986,14 +4023,14 @@ TEST_F(PersonalDataManagerTest, RecordUseOf) {
added_profile = personal_data_->GetProfileByGUID(profile.guid());
ASSERT_TRUE(added_profile);
EXPECT_EQ(2U, added_profile->use_count());
- EXPECT_NE(creation_time, added_profile->use_date());
- EXPECT_NE(creation_time, added_profile->modification_date());
+ EXPECT_EQ(kSecondArbitraryTestTime, added_profile->use_date());
+ EXPECT_EQ(kFirstArbitraryTestTime, added_profile->modification_date());
added_card = personal_data_->GetCreditCardByGUID(credit_card.guid());
ASSERT_TRUE(added_card);
EXPECT_EQ(2U, added_card->use_count());
- EXPECT_NE(creation_time, added_card->use_date());
- EXPECT_NE(creation_time, added_card->modification_date());
+ EXPECT_EQ(kSecondArbitraryTestTime, added_card->use_date());
+ EXPECT_EQ(kFirstArbitraryTestTime, added_card->modification_date());
}
TEST_F(PersonalDataManagerTest, UpdateServerCreditCardUsageStats) {
@@ -4014,6 +4051,11 @@ TEST_F(PersonalDataManagerTest, UpdateServerCreditCardUsageStats) {
test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
"347666888555" /* American Express */, "04", "2999");
+ // Create the test clock and set the time to a specific value.
+ base::SimpleTestClock* test_clock = new base::SimpleTestClock();
+ AutofillClock::SetClockForTests(test_clock);
+ test_clock->SetNow(kFirstArbitraryTestTime);
+
test::SetServerCreditCards(autofill_table_, server_cards);
personal_data_->Refresh();
@@ -4052,17 +4094,24 @@ TEST_F(PersonalDataManagerTest, UpdateServerCreditCardUsageStats) {
EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i]));
// For an unmasked card, usage data starts out as 2 because of the unmasking
- // which is considered a use.
+ // which is considered a use. The use date should now be the specified Now()
+ // time kFirstArbitraryTestTime.
EXPECT_EQ(2U, personal_data_->GetCreditCards()[0]->use_count());
- EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[0]->use_date());
+ EXPECT_EQ(kFirstArbitraryTestTime,
+ personal_data_->GetCreditCards()[0]->use_date());
EXPECT_EQ(1U, personal_data_->GetCreditCards()[1]->use_count());
- EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date());
+ EXPECT_NE(kFirstArbitraryTestTime,
+ personal_data_->GetCreditCards()[1]->use_date());
- // Having unmasked this card, usage stats should be 2 and Now().
+ // Having unmasked this card, usage stats should be 2 and
+ // kFirstArbitraryTestTime.
EXPECT_EQ(2U, personal_data_->GetCreditCards()[2]->use_count());
- EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[2]->use_date());
- base::Time initial_use_date = personal_data_->GetCreditCards()[2]->use_date();
+ EXPECT_EQ(kFirstArbitraryTestTime,
+ personal_data_->GetCreditCards()[2]->use_date());
+
+ // Change the Now() value for a second time.
+ test_clock->SetNow(kSecondArbitraryTestTime);
server_cards.back().set_guid(personal_data_->GetCreditCards()[2]->guid());
personal_data_->RecordUseOf(server_cards.back());
@@ -4072,15 +4121,18 @@ TEST_F(PersonalDataManagerTest, UpdateServerCreditCardUsageStats) {
ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
EXPECT_EQ(2U, personal_data_->GetCreditCards()[0]->use_count());
- EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[0]->use_date());
+ EXPECT_EQ(kFirstArbitraryTestTime,
+ personal_data_->GetCreditCards()[0]->use_date());
EXPECT_EQ(1U, personal_data_->GetCreditCards()[1]->use_count());
- EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date());
+ EXPECT_NE(kFirstArbitraryTestTime,
+ personal_data_->GetCreditCards()[1]->use_date());
+ // The RecordUseOf call should have incremented the use_count to 3 and set the
+ // use_date to kSecondArbitraryTestTime.
EXPECT_EQ(3U, personal_data_->GetCreditCards()[2]->use_count());
- EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[2]->use_date());
- // Time may or may not have elapsed between unmasking and RecordUseOf.
- EXPECT_LE(initial_use_date, personal_data_->GetCreditCards()[2]->use_date());
+ EXPECT_EQ(kSecondArbitraryTestTime,
+ personal_data_->GetCreditCards()[2]->use_date());
// Can record usage stats on masked cards.
server_cards[1].set_guid(personal_data_->GetCreditCards()[1]->guid());
@@ -4090,7 +4142,11 @@ TEST_F(PersonalDataManagerTest, UpdateServerCreditCardUsageStats) {
base::RunLoop().Run();
ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
EXPECT_EQ(2U, personal_data_->GetCreditCards()[1]->use_count());
- EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date());
+ EXPECT_EQ(kSecondArbitraryTestTime,
+ personal_data_->GetCreditCards()[1]->use_date());
+
+ // Change Now()'s return value for a third time.
+ test_clock->SetNow(kThirdArbitraryTestTime);
// Upgrading to unmasked retains the usage stats (and increments them).
CreditCard* unmasked_card2 = &server_cards[1];
@@ -4105,7 +4161,8 @@ TEST_F(PersonalDataManagerTest, UpdateServerCreditCardUsageStats) {
base::RunLoop().Run();
ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
EXPECT_EQ(3U, personal_data_->GetCreditCards()[1]->use_count());
- EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date());
+ EXPECT_EQ(kThirdArbitraryTestTime,
+ personal_data_->GetCreditCards()[1]->use_date());
}
TEST_F(PersonalDataManagerTest, ClearAllServerData) {
@@ -4516,10 +4573,10 @@ TEST_F(PersonalDataManagerTest, SaveImportedProfile) {
// date were properly updated.
EXPECT_EQ(1U, saved_profiles.front()->use_count());
EXPECT_GT(base::TimeDelta::FromMilliseconds(500),
- base::Time::Now() - saved_profiles.front()->use_date());
+ AutofillClock::Now() - saved_profiles.front()->use_date());
EXPECT_GT(
base::TimeDelta::FromMilliseconds(500),
- base::Time::Now() - saved_profiles.front()->modification_date());
+ AutofillClock::Now() - saved_profiles.front()->modification_date());
}
// Erase the profiles for the next test.
@@ -4569,6 +4626,11 @@ TEST_F(PersonalDataManagerTest, MergeProfile_Frecency) {
// Tests that MergeProfile produces a merged profile with the expected usage
// statistics.
TEST_F(PersonalDataManagerTest, MergeProfile_UsageStats) {
+ // Create the test clock and set the time to a specific value.
+ base::SimpleTestClock* test_clock = new base::SimpleTestClock();
+ AutofillClock::SetClockForTests(test_clock);
+ test_clock->SetNow(kFirstArbitraryTestTime);
+
// 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 =
@@ -4577,14 +4639,16 @@ TEST_F(PersonalDataManagerTest, MergeProfile_UsageStats) {
"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));
+ EXPECT_EQ(kFirstArbitraryTestTime, profile->use_date());
+ EXPECT_EQ(kFirstArbitraryTestTime, profile->modification_date());
// Create the |existing_profiles| vector.
std::vector<std::unique_ptr<AutofillProfile>> existing_profiles;
existing_profiles.push_back(base::WrapUnique(profile));
+ // Change the current date.
+ test_clock->SetNow(kSecondArbitraryTestTime);
+
// Create a new imported profile that will get merged with the existing one.
AutofillProfile imported_profile(base::GenerateGUID(),
"https://www.example.com");
@@ -4592,6 +4656,9 @@ TEST_F(PersonalDataManagerTest, MergeProfile_UsageStats) {
"homer.simpson@abc.com", "", "742 Evergreen Terrace", "",
"Springfield", "IL", "91601", "US", "12345678910");
+ // Change the current date.
+ test_clock->SetNow(kThirdArbitraryTestTime);
+
// Merge the imported profile into the existing profiles.
std::vector<AutofillProfile> profiles;
std::string guid = personal_data_->MergeProfile(
@@ -4601,12 +4668,12 @@ TEST_F(PersonalDataManagerTest, MergeProfile_UsageStats) {
EXPECT_EQ(profile->guid(), guid);
// The use count should have be max(4, 1) => 4.
EXPECT_EQ(4U, 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());
+ // The use date should be the one of the most recent profile, which is
+ // kSecondArbitraryTime.
+ EXPECT_EQ(kSecondArbitraryTestTime, profile->use_date());
+ // Since the merge is considered a modification, the modification_date should
+ // be set to kThirdArbitraryTestTime.
+ EXPECT_EQ(kThirdArbitraryTestTime, profile->modification_date());
}
// Tests that DedupeProfiles sets the correct profile guids to
@@ -4838,7 +4905,7 @@ TEST_F(PersonalDataManagerTest,
"homer.simpson@abc.com", "", "742. Evergreen Terrace",
"", "Springfield", "IL", "91601", "US", "");
profile1.set_use_count(12);
- profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1));
+ profile1.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1));
// Create a profile with a medium frecency score.
AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com");
@@ -4846,7 +4913,7 @@ TEST_F(PersonalDataManagerTest,
"homer.simpson@abc.com", "", "742 Evergreen Terrace", "",
"Springfield", "IL", "91601", "", "12345678910");
profile2.set_use_count(5);
- profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3));
+ profile2.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(3));
// Create a profile with a lower frecency score.
AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com");
@@ -4854,7 +4921,7 @@ TEST_F(PersonalDataManagerTest,
"homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.",
"", "Springfield", "IL", "91601", "", "");
profile3.set_use_count(3);
- profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5));
+ profile3.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(5));
// Create a set of two profiles to be merged together.
// Create a profile with a higher frecency score.
@@ -4863,7 +4930,7 @@ TEST_F(PersonalDataManagerTest,
"marge.simpson@abc.com", "", "742. Evergreen Terrace",
"", "Springfield", "IL", "91601", "US", "");
profile4.set_use_count(11);
- profile4.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1));
+ profile4.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1));
// Create a profile with a lower frecency score.
AutofillProfile profile5(base::GenerateGUID(), "https://www.example.com");
@@ -4871,7 +4938,7 @@ TEST_F(PersonalDataManagerTest,
"marge.simpson@abc.com", "Fox", "742 Evergreen Terrace.",
"", "Springfield", "IL", "91601", "", "");
profile5.set_use_count(5);
- profile5.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3));
+ profile5.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(3));
// Create a unique profile.
AutofillProfile profile6(base::GenerateGUID(), "https://www.example.com");
@@ -4879,7 +4946,7 @@ TEST_F(PersonalDataManagerTest,
"bart.simpson@abc.com", "Fox", "742 Evergreen Terrace.",
"", "Springfield", "IL", "91601", "", "");
profile6.set_use_count(10);
- profile6.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1));
+ profile6.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1));
// Add three credit cards. Give them a frecency score so that they are
// suggested in order (1, 2, 3). This will ensure a deterministic order for
@@ -4970,7 +5037,7 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MergedProfileValues) {
"homer.simpson@abc.com", "", "742. Evergreen Terrace",
"", "Springfield", "IL", "91601", "US", "");
profile1.set_use_count(10);
- profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1));
+ profile1.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1));
// Create a profile with a medium frecency score.
AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com");
@@ -4978,7 +5045,7 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MergedProfileValues) {
"homer.simpson@abc.com", "", "742 Evergreen Terrace", "",
"Springfield", "IL", "91601", "", "12345678910");
profile2.set_use_count(5);
- profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3));
+ profile2.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(3));
// Create a profile with a lower frecency score.
AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com");
@@ -4986,7 +5053,7 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MergedProfileValues) {
"homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.",
"", "Springfield", "IL", "91601", "", "");
profile3.set_use_count(3);
- profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5));
+ profile3.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(5));
personal_data_->AddProfile(profile1);
personal_data_->AddProfile(profile2);
@@ -5062,7 +5129,7 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_VerifiedProfileFirst) {
"homer.simpson@abc.com", "", "742 Evergreen Terrace", "",
"Springfield", "IL", "91601", "", "12345678910");
profile1.set_use_count(7);
- profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1));
+ profile1.set_use_date(kThirdArbitraryTestTime);
// Create a similar non verified profile with a medium frecency score.
AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com");
@@ -5070,7 +5137,7 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_VerifiedProfileFirst) {
"homer.simpson@abc.com", "", "742. Evergreen Terrace",
"", "Springfield", "IL", "91601", "US", "");
profile2.set_use_count(5);
- profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3));
+ profile2.set_use_date(kSecondArbitraryTestTime);
// Create a similar non verified profile with a lower frecency score.
AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com");
@@ -5078,7 +5145,7 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_VerifiedProfileFirst) {
"homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.",
"", "Springfield", "IL", "91601", "", "");
profile3.set_use_count(3);
- profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5));
+ profile3.set_use_date(kFirstArbitraryTestTime);
personal_data_->AddProfile(profile1);
personal_data_->AddProfile(profile2);
@@ -5118,10 +5185,7 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_VerifiedProfileFirst) {
EXPECT_EQ(profile1.guid(), profiles[0]->guid());
EXPECT_TRUE(profile1 == *profiles[0]);
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());
+ EXPECT_EQ(profile1.use_date(), profiles[0]->use_date());
}
// Tests that ApplyDedupingRoutine only keeps the verified profile with its
@@ -5134,7 +5198,7 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_VerifiedProfileLast) {
"homer.simpson@abc.com", "", "742. Evergreen Terrace",
"", "Springfield", "IL", "91601", "US", "");
profile1.set_use_count(5);
- profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3));
+ profile1.set_use_date(kThirdArbitraryTestTime);
// Create a similar non verified profile with a medium frecency score.
AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com");
@@ -5142,7 +5206,7 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_VerifiedProfileLast) {
"homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.",
"", "Springfield", "IL", "91601", "", "");
profile2.set_use_count(5);
- profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3));
+ profile2.set_use_date(kSecondArbitraryTestTime);
// Create a similar verified profile with a lower frecency score.
AutofillProfile profile3(base::GenerateGUID(), kSettingsOrigin);
@@ -5150,7 +5214,7 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_VerifiedProfileLast) {
"homer.simpson@abc.com", "", "742 Evergreen Terrace", "",
"Springfield", "IL", "91601", "", "12345678910");
profile3.set_use_count(3);
- profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5));
+ profile3.set_use_date(kFirstArbitraryTestTime);
personal_data_->AddProfile(profile1);
personal_data_->AddProfile(profile2);
@@ -5186,14 +5250,11 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_VerifiedProfileLast) {
histogram_tester.ExpectUniqueSample(
"Autofill.NumberOfProfilesRemovedDuringDedupe", 2, 1);
- // Only the verified |profile2| with it's original data should have been kept.
+ // Only the verified |profile3| with it's original data should have been kept.
EXPECT_EQ(profile3.guid(), profiles[0]->guid());
EXPECT_TRUE(profile3 == *profiles[0]);
EXPECT_EQ(profile3.use_count(), profiles[0]->use_count());
- EXPECT_LT(profile3.use_date() - TimeDelta::FromSeconds(2),
- profiles[0]->use_date());
- EXPECT_GT(profile3.use_date() + TimeDelta::FromSeconds(2),
- profiles[0]->use_date());
+ EXPECT_EQ(profile3.use_date(), profiles[0]->use_date());
}
// Tests that ApplyDedupingRoutine does not merge unverified data into
@@ -5205,7 +5266,7 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MultipleVerifiedProfiles) {
"homer.simpson@abc.com", "", "742. Evergreen Terrace",
"", "Springfield", "IL", "91601", "US", "");
profile1.set_use_count(5);
- profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3));
+ profile1.set_use_date(kThirdArbitraryTestTime);
// Create a similar verified profile with a medium frecency score.
AutofillProfile profile2(base::GenerateGUID(), kSettingsOrigin);
@@ -5213,7 +5274,7 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MultipleVerifiedProfiles) {
"homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.",
"", "Springfield", "IL", "91601", "", "");
profile2.set_use_count(5);
- profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3));
+ profile2.set_use_date(kSecondArbitraryTestTime);
// Create a similar verified profile with a lower frecency score.
AutofillProfile profile3(base::GenerateGUID(), kSettingsOrigin);
@@ -5221,7 +5282,7 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MultipleVerifiedProfiles) {
"homer.simpson@abc.com", "", "742 Evergreen Terrace", "",
"Springfield", "IL", "91601", "", "12345678910");
profile3.set_use_count(3);
- profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5));
+ profile3.set_use_date(kFirstArbitraryTestTime);
personal_data_->AddProfile(profile1);
personal_data_->AddProfile(profile2);
@@ -5268,14 +5329,8 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MultipleVerifiedProfiles) {
EXPECT_TRUE(profile3 == *profiles[1]);
EXPECT_EQ(profile2.use_count(), profiles[0]->use_count());
EXPECT_EQ(profile3.use_count(), profiles[1]->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());
- EXPECT_LT(profile3.use_date() - TimeDelta::FromSeconds(2),
- profiles[1]->use_date());
- EXPECT_GT(profile3.use_date() + TimeDelta::FromSeconds(2),
- profiles[1]->use_date());
+ EXPECT_EQ(profile2.use_date(), profiles[0]->use_date());
+ EXPECT_EQ(profile3.use_date(), profiles[1]->use_date());
}
// Tests that ApplyProfileUseDatesFix sets the use date of profiles from an
@@ -5292,6 +5347,7 @@ TEST_F(PersonalDataManagerTest, ApplyProfileUseDatesFix) {
test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson",
"homer.simpson@abc.com", "SNP", "742 Evergreen Terrace",
"", "Springfield", "IL", "91601", "US", "12345678910");
+ profile1.set_use_date(kFirstArbitraryTestTime);
// Create another profile and set its use date to the default value.
AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com");
@@ -5314,14 +5370,18 @@ TEST_F(PersonalDataManagerTest, ApplyProfileUseDatesFix) {
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());
+ EXPECT_EQ(profile1.use_date(), saved_profiles[0]->use_date());
+ EXPECT_EQ(profile2.use_date(), 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);
+ // Create the test clock and set the time to a specific value.
+ base::SimpleTestClock* test_clock = new base::SimpleTestClock();
+ AutofillClock::SetClockForTests(test_clock);
+ test_clock->SetNow(kSecondArbitraryTestTime);
+
personal_data_->ApplyProfileUseDatesFix();
EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
.WillOnce(QuitMainMessageLoop());
@@ -5333,12 +5393,9 @@ TEST_F(PersonalDataManagerTest, ApplyProfileUseDatesFix) {
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());
+ EXPECT_LE(profile1.use_date(), 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),
+ EXPECT_EQ(kSecondArbitraryTestTime - base::TimeDelta::FromDays(14),
saved_profiles[1]->use_date());
}
@@ -5355,6 +5412,7 @@ TEST_F(PersonalDataManagerTest, ApplyProfileUseDatesFix_NotAppliedTwice) {
test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson",
"homer.simpson@abc.com", "SNP", "742 Evergreen Terrace",
"", "Springfield", "IL", "91601", "US", "12345678910");
+ profile1.set_use_date(kFirstArbitraryTestTime);
AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com");
test::SetProfileInfo(&profile2, "Marge", "", "Simpson",
"homer.simpson@abc.com", "SNP", "742 Evergreen Terrace",
@@ -5375,8 +5433,7 @@ TEST_F(PersonalDataManagerTest, ApplyProfileUseDatesFix_NotAppliedTwice) {
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(profile1.use_date(), saved_profiles[0]->use_date());
EXPECT_EQ(base::Time(), saved_profiles[1]->use_date());
}
@@ -5392,7 +5449,7 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MultipleDedupes) {
"homer.simpson@abc.com", "", "742. Evergreen Terrace",
"", "Springfield", "IL", "91601", "US", "");
Homer1.set_use_count(10);
- Homer1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1));
+ Homer1.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1));
// Create a Homer home profile with a medium frecency score compared to other
// Homer profiles.
@@ -5401,7 +5458,7 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MultipleDedupes) {
"homer.simpson@abc.com", "", "742 Evergreen Terrace", "",
"Springfield", "IL", "91601", "", "12345678910");
Homer2.set_use_count(5);
- Homer2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3));
+ Homer2.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(3));
// Create a Homer home profile with a lower frecency score than other Homer
// profiles.
@@ -5410,7 +5467,7 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MultipleDedupes) {
"homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.",
"", "Springfield", "IL", "91601", "", "");
Homer3.set_use_count(3);
- Homer3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5));
+ Homer3.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(5));
// Create a Homer work profile (different address).
AutofillProfile Homer4(base::GenerateGUID(), "https://www.example.com");
@@ -5418,7 +5475,7 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MultipleDedupes) {
"homer.simpson@abc.com", "Fox", "12 Nuclear Plant.", "",
"Springfield", "IL", "91601", "US", "9876543");
Homer4.set_use_count(3);
- Homer4.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5));
+ Homer4.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(5));
// Create a Marge profile with a lower frecency score that other Marge
// profiles.
@@ -5427,7 +5484,7 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MultipleDedupes) {
"marge.simpson@abc.com", "", "742 Evergreen Terrace", "",
"Springfield", "IL", "91601", "", "12345678910");
Marge1.set_use_count(4);
- Marge1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3));
+ Marge1.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(3));
// Create a verified Marge home profile with a lower frecency score that the
// other Marge profile.
@@ -5436,7 +5493,7 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MultipleDedupes) {
"marge.simpson@abc.com", "", "742 Evergreen Terrace", "",
"Springfield", "IL", "91601", "", "12345678910");
Marge2.set_use_count(2);
- Marge2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3));
+ Marge2.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(3));
// Create a Barney profile (guest user).
AutofillProfile Barney(base::GenerateGUID(), "https://www.example.com");
@@ -5444,7 +5501,7 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MultipleDedupes) {
"ABC", "123 Other Street", "", "Springfield", "IL",
"91601", "", "");
Barney.set_use_count(1);
- Barney.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(180));
+ Barney.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(180));
personal_data_->AddProfile(Homer1);
personal_data_->AddProfile(Homer2);

Powered by Google App Engine
This is Rietveld 408576698