Chromium Code Reviews| Index: components/autofill/core/browser/autofill_metrics_unittest.cc |
| diff --git a/components/autofill/core/browser/autofill_metrics_unittest.cc b/components/autofill/core/browser/autofill_metrics_unittest.cc |
| index 65c3b283f598b13a961094c0b88b75744efdbd05..fd4a76ff1c556b160d9b272928757f6405780659 100644 |
| --- a/components/autofill/core/browser/autofill_metrics_unittest.cc |
| +++ b/components/autofill/core/browser/autofill_metrics_unittest.cc |
| @@ -187,6 +187,19 @@ class TestPersonalDataManager : public PersonalDataManager { |
| Refresh(); |
| } |
| + // Removes all existing credit cards and creates 1 server card with bank names |
|
Jared Saul
2017/06/14 16:49:15
s/with bank names/with a bank name
Shanfeng
2017/06/14 17:48:25
Done.
|
| + void RecreateServerCreditCardsWithBankNames() { |
|
Jared Saul
2017/06/14 16:49:16
s/CardsWithBankNames/CardWithBankName
Since it's o
Shanfeng
2017/06/14 17:48:25
Done.
|
| + server_credit_cards_.clear(); |
| + std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>( |
| + CreditCard::FULL_SERVER_CARD, "server_id"); |
| + test::SetCreditCardInfo(credit_card.get(), "name", "4111111111111111", |
| + "12", "24", "1"); |
| + credit_card->set_guid("10000000-0000-0000-0000-000000000003"); |
| + credit_card->set_bank_name("Chase"); |
| + server_credit_cards_.push_back(std::move(credit_card)); |
| + Refresh(); |
| + } |
| + |
| bool IsAutofillEnabled() const override { return autofill_enabled_; } |
| void CreateAmbiguousProfiles() { |
| @@ -2529,6 +2542,11 @@ TEST_F(AutofillMetricsTest, CreditCardShownFormEvents) { |
| histogram_tester.ExpectBucketCount( |
| "Autofill.FormEvents.CreditCard", |
| AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 1); |
| + // Check that the bank name histogram was not recorded. ExpectBucketCount() |
| + // can't be used here because it expects the histogram to exist. |
| + EXPECT_EQ(0, histogram_tester.GetTotalCountsForPrefix( |
| + "Autofill.FormEvents.CreditCard") |
| + ["Autofill.FormEvents.CreditCard.BankNameExperiment"]); |
| } |
| // Reset the autofill manager state. |
| @@ -2546,6 +2564,11 @@ TEST_F(AutofillMetricsTest, CreditCardShownFormEvents) { |
| histogram_tester.ExpectBucketCount( |
| "Autofill.FormEvents.CreditCard", |
| AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 1); |
| + // Check that the bank name histogram was not recorded. ExpectBucketCount() |
| + // can't be used here because it expects the histogram to exist. |
| + EXPECT_EQ(0, histogram_tester.GetTotalCountsForPrefix( |
| + "Autofill.FormEvents.CreditCard") |
| + ["Autofill.FormEvents.CreditCard.BankNameExperiment"]); |
| } |
| // Reset the autofill manager state. |
| @@ -2563,6 +2586,59 @@ TEST_F(AutofillMetricsTest, CreditCardShownFormEvents) { |
| histogram_tester.ExpectBucketCount( |
| "Autofill.FormEvents.CreditCard", |
| AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 0); |
| + // Check that the bank name histogram was not recorded. ExpectBucketCount() |
| + // can't be used here because it expects the histogram to exist. |
| + EXPECT_EQ(0, histogram_tester.GetTotalCountsForPrefix( |
| + "Autofill.FormEvents.CreditCard") |
| + ["Autofill.FormEvents.CreditCard.BankNameExperiment"]); |
| + } |
| + |
| + // Recreate server cards with bank names. |
| + personal_data_->RecreateServerCreditCardsWithBankNames(); |
| + |
| + // Reset the autofill manager state. |
| + autofill_manager_->Reset(); |
| + autofill_manager_->AddSeenForm(form, field_types, field_types); |
| + |
| + { |
| + // Simulating new popup being shown. |
| + base::HistogramTester histogram_tester; |
| + autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
| + autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); |
| + histogram_tester.ExpectBucketCount( |
| + "Autofill.FormEvents.CreditCard", |
| + AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN, 1); |
| + histogram_tester.ExpectBucketCount( |
| + "Autofill.FormEvents.CreditCard", |
| + AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 1); |
| + histogram_tester.ExpectBucketCount( |
| + "Autofill.FormEvents.CreditCard.BankNameExperiment", |
| + AutofillMetrics:: |
| + FORM_EVENT_SUGGESTIONS_SHOWN_WITH_BANK_NAME_AVAILABLE_ONCE, |
| + 1); |
| + } |
| + |
| + // Reset the autofill manager state. |
| + autofill_manager_->Reset(); |
| + autofill_manager_->AddSeenForm(form, field_types, field_types); |
| + |
| + { |
| + // Simulating two popups in the same page load. |
| + base::HistogramTester histogram_tester; |
| + autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
| + autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); |
| + autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); |
| + histogram_tester.ExpectBucketCount( |
| + "Autofill.FormEvents.CreditCard", |
| + AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN, 2); |
| + histogram_tester.ExpectBucketCount( |
| + "Autofill.FormEvents.CreditCard", |
| + AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 1); |
| + histogram_tester.ExpectBucketCount( |
| + "Autofill.FormEvents.CreditCard.BankNameExperiment", |
| + AutofillMetrics:: |
| + FORM_EVENT_SUGGESTIONS_SHOWN_WITH_BANK_NAME_AVAILABLE_ONCE, |
| + 1); |
| } |
| } |
| @@ -2731,6 +2807,11 @@ TEST_F(AutofillMetricsTest, CreditCardFilledFormEvents) { |
| histogram_tester.ExpectBucketCount( |
| "Autofill.FormEvents.CreditCard", |
| AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED_ONCE, 1); |
| + // Check that the bank name histogram was not recorded. ExpectBucketCount() |
| + // can't be used here because it expects the histogram to exist. |
| + EXPECT_EQ(0, histogram_tester.GetTotalCountsForPrefix( |
| + "Autofill.FormEvents.CreditCard") |
| + ["Autofill.FormEvents.CreditCard.BankNameExperiment"]); |
| } |
| // Reset the autofill manager state. |
| @@ -2754,6 +2835,52 @@ TEST_F(AutofillMetricsTest, CreditCardFilledFormEvents) { |
| "Autofill.FormEvents.CreditCard", |
| AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE, 1); |
| } |
| + |
| + // Recreate server cards with bank names. |
| + personal_data_->RecreateServerCreditCardsWithBankNames(); |
| + |
| + // Reset the autofill manager state. |
| + autofill_manager_->Reset(); |
| + autofill_manager_->AddSeenForm(form, field_types, field_types); |
| + |
| + { |
| + // Simulating filling a full card server suggestion. |
| + base::HistogramTester histogram_tester; |
| + std::string guid( |
| + "10000000-0000-0000-0000-000000000003"); // full server card |
| + autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
| + autofill_manager_->FillOrPreviewForm( |
| + AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, field, |
| + autofill_manager_->MakeFrontendID(guid, std::string())); |
| + histogram_tester.ExpectBucketCount( |
| + "Autofill.FormEvents.CreditCard.BankNameExperiment", |
| + AutofillMetrics:: |
| + FORM_EVENT_SERVER_SUGGESTION_FILLED_WITH_BANK_NAME_AVAILABLE_ONCE, |
| + 1); |
| + } |
| + |
| + // Reset the autofill manager state. |
| + autofill_manager_->Reset(); |
| + autofill_manager_->AddSeenForm(form, field_types, field_types); |
| + |
| + { |
| + // Simulating filling multiple times. |
| + base::HistogramTester histogram_tester; |
| + std::string guid( |
| + "10000000-0000-0000-0000-000000000003"); // full server card |
| + autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
| + autofill_manager_->FillOrPreviewForm( |
| + AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, field, |
| + autofill_manager_->MakeFrontendID(guid, std::string())); |
| + autofill_manager_->FillOrPreviewForm( |
| + AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, field, |
| + autofill_manager_->MakeFrontendID(guid, std::string())); |
| + histogram_tester.ExpectBucketCount( |
| + "Autofill.FormEvents.CreditCard.BankNameExperiment", |
| + AutofillMetrics:: |
| + FORM_EVENT_SERVER_SUGGESTION_FILLED_WITH_BANK_NAME_AVAILABLE_ONCE, |
| + 1); |
| + } |
| } |
| // Test that we log submitted form events for credit cards. |
| @@ -3447,6 +3574,11 @@ TEST_F(AutofillMetricsTest, AddressShownFormEvents) { |
| histogram_tester.ExpectBucketCount( |
| "Autofill.FormEvents.Address", |
| AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 1); |
| + // Check that the bank name histogram was not recorded. ExpectBucketCount() |
| + // can't be used here because it expects the histogram to exist. |
| + EXPECT_EQ(0, histogram_tester.GetTotalCountsForPrefix( |
| + "Autofill.FormEvents.CreditCard") |
| + ["Autofill.FormEvents.CreditCard.BankNameExperiment"]); |
| } |
| // Reset the autofill manager state. |
| @@ -3464,6 +3596,11 @@ TEST_F(AutofillMetricsTest, AddressShownFormEvents) { |
| histogram_tester.ExpectBucketCount( |
| "Autofill.FormEvents.Address", |
| AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 1); |
| + // Check that the bank name histogram was not recorded. ExpectBucketCount() |
| + // can't be used here because it expects the histogram to exist. |
| + EXPECT_EQ(0, histogram_tester.GetTotalCountsForPrefix( |
| + "Autofill.FormEvents.CreditCard") |
| + ["Autofill.FormEvents.CreditCard.BankNameExperiment"]); |
| } |
| // Reset the autofill manager state. |
| @@ -3481,6 +3618,11 @@ TEST_F(AutofillMetricsTest, AddressShownFormEvents) { |
| histogram_tester.ExpectBucketCount( |
| "Autofill.FormEvents.Address", |
| AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 0); |
| + // Check that the bank name histogram was not recorded. ExpectBucketCount() |
| + // can't be used here because it expects the histogram to exist. |
| + EXPECT_EQ(0, histogram_tester.GetTotalCountsForPrefix( |
| + "Autofill.FormEvents.CreditCard") |
| + ["Autofill.FormEvents.CreditCard.BankNameExperiment"]); |
| } |
| } |