Chromium Code Reviews| Index: components/autofill/core/browser/autofill_manager_unittest.cc |
| diff --git a/components/autofill/core/browser/autofill_manager_unittest.cc b/components/autofill/core/browser/autofill_manager_unittest.cc |
| index bd81eba76c94a436749bb53d28862bc7cc47b3b9..aea881a854c28e83036b1dc96eb188a41132867a 100644 |
| --- a/components/autofill/core/browser/autofill_manager_unittest.cc |
| +++ b/components/autofill/core/browser/autofill_manager_unittest.cc |
| @@ -183,7 +183,7 @@ class TestPersonalDataManager : public PersonalDataManager { |
| void AddCreditCard(const CreditCard& credit_card) override { |
| std::unique_ptr<CreditCard> local_credit_card = |
| base::MakeUnique<CreditCard>(credit_card); |
| - local_credit_card->set_modification_date(base::Time::Now()); |
| + local_credit_card->set_modification_date(AutofillClock::Now()); |
| local_credit_cards_.push_back(std::move(local_credit_card)); |
| } |
| @@ -231,7 +231,7 @@ class TestPersonalDataManager : public PersonalDataManager { |
| void AddServerCreditCard(const CreditCard& credit_card) { |
| std::unique_ptr<CreditCard> server_credit_card = |
| base::MakeUnique<CreditCard>(credit_card); |
| - server_credit_card->set_modification_date(base::Time::Now()); |
| + server_credit_card->set_modification_date(AutofillClock::Now()); |
| server_credit_cards_.push_back(std::move(server_credit_card)); |
| } |
| @@ -309,7 +309,8 @@ class TestPersonalDataManager : public PersonalDataManager { |
| "04", "2999"); |
| credit_card->set_guid("00000000-0000-0000-0000-000000000004"); |
| credit_card->set_use_count(10); |
| - credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); |
| + credit_card->set_use_date(AutofillClock::Now() - |
| + base::TimeDelta::FromDays(5)); |
| credit_cards->push_back(std::move(credit_card)); |
| credit_card = base::MakeUnique<CreditCard>(); |
| @@ -318,7 +319,8 @@ class TestPersonalDataManager : public PersonalDataManager { |
| "10", "2998"); |
| credit_card->set_guid("00000000-0000-0000-0000-000000000005"); |
| credit_card->set_use_count(5); |
| - credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(4)); |
| + credit_card->set_use_date(AutofillClock::Now() - |
| + base::TimeDelta::FromDays(4)); |
| credit_cards->push_back(std::move(credit_card)); |
| credit_card = base::MakeUnique<CreditCard>(); |
| @@ -1956,7 +1958,8 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { |
| "5231567890123456", // Mastercard |
| "05", "2999"); |
| credit_card.set_guid("00000000-0000-0000-0000-000000000007"); |
| - credit_card.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); |
| + credit_card.set_use_date(AutofillClock::Now() - |
| + base::TimeDelta::FromDays(15)); |
| autofill_manager_->AddCreditCard(credit_card); |
| // Set up our form data. |
| @@ -4672,12 +4675,15 @@ TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard) { |
| // Server did not send a server_id, expect copy of card is not stored. |
| EXPECT_TRUE(autofill_manager_->GetCreditCards().empty()); |
| - |
| // Verify that the correct histogram entry (and only that) was logged. |
| ExpectUniqueCardUploadDecision(histogram_tester, |
| AutofillMetrics::UPLOAD_OFFERED); |
| // Verify that the correct UKM was logged. |
| ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); |
| + // Verify that UMA for "DaysSincePreviousUse" was not logged because we |
| + // modified the profile. |
| + histogram_tester.ExpectTotalCount( |
| + "Autofill.DaysSincePreviousUseAtSubmission.Profile", 0); |
| } |
| // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| @@ -5872,6 +5878,54 @@ TEST_F(AutofillManagerTest, UploadCreditCard_IgnoreOldProfiles) { |
| AutofillMetrics::UPLOAD_OFFERED); |
| } |
| +TEST_F(AutofillManagerTest, UploadCreditCard_LogPreviousUseDate) { |
| + // Create the test clock and set the time to a specific value. |
| + TestAutofillClock test_clock; |
| + test_clock.SetNow(kArbitraryTime); |
| + |
| + personal_data_.ClearAutofillProfiles(); |
| + autofill_manager_->set_credit_card_upload_enabled(true); |
| + |
| + // Create, fill and submit an address form in order to establish a recent |
| + // profile which can be selected for the upload request. |
| + FormData address_form; |
| + test::CreateTestAddressFormData(&address_form); |
| + FormsSeen({address_form}); |
| + ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form); |
| + FormSubmitted(address_form); |
| + const std::vector<AutofillProfile*>& profiles = |
| + personal_data_.GetProfilesToSuggest(); |
| + ASSERT_EQ(1U, profiles.size()); |
| + |
| + // Advance the current time and simulate use of the address profile. |
| + test_clock.SetNow(kMuchLaterTime); |
| + profiles[0]->RecordAndLogUse(); |
| + |
| + // Set up our credit card form data. |
| + FormData credit_card_form; |
| + CreateTestCreditCardFormData(&credit_card_form, true, false); |
| + FormsSeen({credit_card_form}); |
| + |
| + // Edit the credit card form and submit. |
| + credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); |
| + credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); |
| + credit_card_form.fields[2].value = ASCIIToUTF16("11"); |
| + credit_card_form.fields[3].value = ASCIIToUTF16("2017"); |
| + credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
| + |
| + base::HistogramTester histogram_tester; |
| + |
| + EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
| + FormSubmitted(credit_card_form); |
| + EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
| + |
| + // Verify that UMA for "DaysSincePreviousUse" is logged. |
| + histogram_tester.ExpectUniqueSample( |
| + "Autofill.DaysSincePreviousUseAtSubmission.Profile", |
| + (kMuchLaterTime - kArbitraryTime).InDays(), |
| + /* expected_count= */ 1); |
|
sebsg
2017/05/08 21:43:29
nit: /*expected_count=*/1. That makes sure they wi
csashi
2017/05/08 21:51:41
Done.
|
| +} |
| + |
| // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| #if defined(OS_ANDROID) |
| #define MAYBE_UploadCreditCard_UploadDetailsFails \ |