| 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 306d2474e07cad399c07fd9f077d9a2a449c958a..e656cb1a9ba0adec0edda82b9fb428b4113ee562 100644
|
| --- a/components/autofill/core/browser/autofill_metrics_unittest.cc
|
| +++ b/components/autofill/core/browser/autofill_metrics_unittest.cc
|
| @@ -7,6 +7,7 @@
|
| #include <stddef.h>
|
|
|
| #include <memory>
|
| +#include <utility>
|
| #include <vector>
|
|
|
| #include "base/feature_list.h"
|
| @@ -53,7 +54,8 @@ using base::Bucket;
|
| using base::TimeTicks;
|
| using rappor::TestRapporServiceImpl;
|
| using ::testing::ElementsAre;
|
| -using ::testing::UnorderedElementsAre;
|
| +using ::testing::Matcher;
|
| +using ::testing::Pointwise;
|
|
|
| namespace autofill {
|
| namespace {
|
| @@ -316,6 +318,53 @@ const ukm::Entry_Metric* FindMetric(
|
| return nullptr;
|
| }
|
|
|
| +void VerifyDeveloperEngagementUkm(
|
| + const FormData& form,
|
| + const ukm::TestUkmService* ukm_service,
|
| + AutofillMetrics::DeveloperEngagementMetric expected_value) {
|
| + const ukm::UkmEntry* entry = ukm_service->GetEntryForEntryName(
|
| + internal::kUKMDeveloperEngagementEntryName);
|
| + ASSERT_NE(nullptr, entry);
|
| + ukm::Entry entry_proto;
|
| + entry->PopulateProto(&entry_proto);
|
| +
|
| + const ukm::UkmSource* source =
|
| + ukm_service->GetSourceForSourceId(entry_proto.source_id());
|
| + ASSERT_NE(nullptr, source);
|
| + EXPECT_EQ(form.origin, source->url());
|
| +
|
| + const ukm::Entry_Metric* metric = FindMetric(
|
| + internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics());
|
| + ASSERT_NE(nullptr, metric);
|
| + EXPECT_EQ(expected_value, metric->value());
|
| +}
|
| +
|
| +MATCHER(CompareMetrics, "") {
|
| + const ukm::Entry_Metric& lhs = ::testing::get<0>(arg);
|
| + const std::pair<const char*, int64_t>& rhs = ::testing::get<1>(arg);
|
| + return lhs.metric_hash() == base::HashMetricName(rhs.first) &&
|
| + lhs.value() == rhs.second;
|
| +}
|
| +
|
| +void VerifyFormInteractionsUkm(
|
| + const FormData& form,
|
| + const ukm::TestUkmService* ukm_service,
|
| + const std::vector<std::pair<const char*, int64_t>>& expected_metrics) {
|
| + const ukm::UkmEntry* entry = ukm_service->GetEntryForEntryName(
|
| + internal::kUKMFormInteractionsEntryName);
|
| + ASSERT_NE(nullptr, entry);
|
| + ukm::Entry entry_proto;
|
| + entry->PopulateProto(&entry_proto);
|
| +
|
| + const ukm::UkmSource* source =
|
| + ukm_service->GetSourceForSourceId(entry_proto.source_id());
|
| + ASSERT_NE(nullptr, source);
|
| + EXPECT_EQ(form.origin, source->url());
|
| +
|
| + EXPECT_THAT(entry_proto.metrics(),
|
| + Pointwise(CompareMetrics(), expected_metrics));
|
| +}
|
| +
|
| } // namespace
|
|
|
| // This is defined in the autofill_metrics.cc implementation file.
|
| @@ -393,6 +442,7 @@ void AutofillMetricsTest::TearDown() {
|
| account_tracker_.reset();
|
| signin_client_.reset();
|
| test::ReenableSystemServices();
|
| + autofill_client_.GetTestUkmService()->Purge();
|
| }
|
|
|
| void AutofillMetricsTest::EnableWalletSync() {
|
| @@ -1380,6 +1430,11 @@ TEST_F(AutofillMetricsTest, NumberOfEditedAutofilledFields) {
|
| // fields is logged.
|
| histogram_tester.ExpectUniqueSample(
|
| "Autofill.NumberOfEditedAutofilledFieldsAtSubmission", 2, 1);
|
| +
|
| + // UKM must not be logged unless enabled.
|
| + ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
|
| + EXPECT_EQ(0U, ukm_service->sources_count());
|
| + EXPECT_EQ(0U, ukm_service->entries_count());
|
| }
|
|
|
| // Verify that when resetting the autofill manager (such as during a
|
| @@ -1567,30 +1622,23 @@ TEST_F(AutofillMetricsTest,
|
| test::CreateTestFormField("Phone", "phone", "", "text", &field);
|
| forms.back().fields.push_back(field);
|
|
|
| - // Expect the "form parsed without field type hints" metric to be logged.
|
| + // Expect the "form parsed without field type hints" metric and the
|
| + // "form loaded" form interaction event to be logged.
|
| {
|
| autofill_manager_->OnFormsSeen(forms, TimeTicks());
|
| autofill_manager_->Reset();
|
|
|
| - ASSERT_EQ(1U, ukm_service->sources_count());
|
| - const ukm::UkmSource* source =
|
| - ukm_service->GetSourceForUrl(form.origin.spec().c_str());
|
| - ASSERT_NE(nullptr, source);
|
| -
|
| - ASSERT_EQ(1U, ukm_service->entries_count());
|
| - const ukm::UkmEntry* entry = ukm_service->GetEntry(0);
|
| - EXPECT_EQ(source->id(), entry->source_id());
|
| -
|
| - ukm::Entry entry_proto;
|
| - entry->PopulateProto(&entry_proto);
|
| - EXPECT_EQ(source->id(), entry_proto.source_id());
|
| - EXPECT_EQ(base::HashMetricName(internal::kUKMDeveloperEngagementEntryName),
|
| - entry_proto.event_hash());
|
| - const ukm::Entry_Metric* metric = FindMetric(
|
| - internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics());
|
| - ASSERT_NE(nullptr, metric);
|
| - EXPECT_EQ(AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS,
|
| - metric->value());
|
| + // Expect an entry for |kUKMDeveloperEngagementEntryName| and another entry
|
| + // for |kUKMFormInteractionsEntryName|. Both entries are for the same URL.
|
| + ASSERT_EQ(2U, ukm_service->entries_count());
|
| + ASSERT_EQ(2U, ukm_service->sources_count());
|
| + VerifyDeveloperEngagementUkm(
|
| + form, ukm_service,
|
| + AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS);
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsUserHappinessMetricMetricName,
|
| + AutofillMetrics::FORMS_LOADED}});
|
| }
|
| }
|
|
|
| @@ -1633,30 +1681,23 @@ TEST_F(AutofillMetricsTest,
|
| field.autocomplete_attribute = "address-line1";
|
| forms.back().fields.push_back(field);
|
|
|
| - // Expect the "form parsed with field type hints" metric to be logged.
|
| + // Expect the "form parsed without field type hints" metric and the
|
| + // "form loaded" form interaction event to be logged.
|
| {
|
| autofill_manager_->OnFormsSeen(forms, TimeTicks());
|
| autofill_manager_->Reset();
|
|
|
| - ASSERT_EQ(1U, ukm_service->sources_count());
|
| - const ukm::UkmSource* source =
|
| - ukm_service->GetSourceForUrl(form.origin.spec().c_str());
|
| - ASSERT_NE(nullptr, source);
|
| -
|
| - ASSERT_EQ(1U, ukm_service->entries_count());
|
| - const ukm::UkmEntry* entry = ukm_service->GetEntry(0);
|
| - EXPECT_EQ(source->id(), entry->source_id());
|
| -
|
| - ukm::Entry entry_proto;
|
| - entry->PopulateProto(&entry_proto);
|
| - EXPECT_EQ(source->id(), entry_proto.source_id());
|
| - EXPECT_EQ(base::HashMetricName(internal::kUKMDeveloperEngagementEntryName),
|
| - entry_proto.event_hash());
|
| - const ukm::Entry_Metric* metric = FindMetric(
|
| - internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics());
|
| - ASSERT_NE(nullptr, metric);
|
| - EXPECT_EQ(AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS,
|
| - metric->value());
|
| + // Expect an entry for |kUKMDeveloperEngagementEntryName| and another entry
|
| + // for |kUKMFormInteractionsEntryName|. Both entries are for the same URL.
|
| + ASSERT_EQ(2U, ukm_service->entries_count());
|
| + ASSERT_EQ(2U, ukm_service->sources_count());
|
| + VerifyDeveloperEngagementUkm(
|
| + form, ukm_service,
|
| + AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS);
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsUserHappinessMetricMetricName,
|
| + AutofillMetrics::FORMS_LOADED}});
|
| }
|
| }
|
|
|
| @@ -1682,29 +1723,20 @@ TEST_F(AutofillMetricsTest, UkmDeveloperEngagement_LogUpiVpaTypeHint) {
|
|
|
| std::vector<FormData> forms(1, form);
|
|
|
| - // Expect the "upi-vpa hint" metric to be logged.
|
| + // Expect the "upi-vpa hint" metric to be logged and the "form loaded" form
|
| + // interaction event to be logged.
|
| {
|
| autofill_manager_->OnFormsSeen(forms, TimeTicks());
|
| autofill_manager_->Reset();
|
|
|
| - ASSERT_EQ(1U, ukm_service->sources_count());
|
| - const ukm::UkmSource* source =
|
| - ukm_service->GetSourceForUrl(form.origin.spec().c_str());
|
| - ASSERT_NE(nullptr, source);
|
| -
|
| - ASSERT_EQ(1U, ukm_service->entries_count());
|
| - const ukm::UkmEntry* entry = ukm_service->GetEntry(0);
|
| - EXPECT_EQ(source->id(), entry->source_id());
|
| -
|
| - ukm::Entry entry_proto;
|
| - entry->PopulateProto(&entry_proto);
|
| - EXPECT_EQ(source->id(), entry_proto.source_id());
|
| - EXPECT_EQ(base::HashMetricName(internal::kUKMDeveloperEngagementEntryName),
|
| - entry_proto.event_hash());
|
| - const ukm::Entry_Metric* metric = FindMetric(
|
| - internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics());
|
| - ASSERT_NE(nullptr, metric);
|
| - EXPECT_EQ(AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT, metric->value());
|
| + ASSERT_EQ(2U, ukm_service->entries_count());
|
| + ASSERT_EQ(2U, ukm_service->sources_count());
|
| + VerifyDeveloperEngagementUkm(form, ukm_service,
|
| + AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT);
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsUserHappinessMetricMetricName,
|
| + AutofillMetrics::FORMS_LOADED}});
|
| }
|
| }
|
|
|
| @@ -1887,6 +1919,9 @@ TEST_F(AutofillMetricsTest, AddressSuggestionsCount) {
|
|
|
| // Test that the credit card checkout flow user actions are correctly logged.
|
| TEST_F(AutofillMetricsTest, CreditCardCheckoutFlowUserActions) {
|
| + EnableUkmLogging();
|
| + ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
|
| +
|
| personal_data_->RecreateCreditCards(
|
| true /* include_local_credit_card */,
|
| false /* include_masked_server_credit_card */,
|
| @@ -1962,10 +1997,31 @@ TEST_F(AutofillMetricsTest, CreditCardCheckoutFlowUserActions) {
|
| EXPECT_EQ(1, user_action_tester.GetActionCount(
|
| "Autofill_FormSubmitted_NonFillable"));
|
| }
|
| +
|
| + ASSERT_EQ(1U, ukm_service->entries_count());
|
| + ASSERT_EQ(1U, ukm_service->sources_count());
|
| + // Expect 2 |FORM_EVENT_LOCAL_SUGGESTION_FILLED| events. First, from
|
| + // call to |external_delegate_->DidAcceptSuggestion|. Second, from call to
|
| + // |autofill_manager_->FillOrPreviewForm|.
|
| + // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState|
|
| + // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|.
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsCreditCardFormEventMetricName,
|
| + AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN},
|
| + {internal::kUKMFormInteractionsCreditCardFormEventMetricName,
|
| + AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED},
|
| + {internal::kUKMFormInteractionsCreditCardFormEventMetricName,
|
| + AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED},
|
| + {internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName,
|
| + AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
|
| }
|
|
|
| // Test that the profile checkout flow user actions are correctly logged.
|
| TEST_F(AutofillMetricsTest, ProfileCheckoutFlowUserActions) {
|
| + EnableUkmLogging();
|
| + ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
|
| +
|
| // Create a profile.
|
| personal_data_->RecreateProfile();
|
|
|
| @@ -2013,7 +2069,7 @@ TEST_F(AutofillMetricsTest, ProfileCheckoutFlowUserActions) {
|
| std::string guid("00000000-0000-0000-0000-000000000001"); // local profile.
|
| external_delegate_->DidAcceptSuggestion(
|
| ASCIIToUTF16("Test"),
|
| - autofill_manager_->MakeFrontendID(guid, std::string()), 0);
|
| + autofill_manager_->MakeFrontendID(std::string(), guid), 0);
|
| EXPECT_EQ(1,
|
| user_action_tester.GetActionCount("Autofill_SelectedSuggestion"));
|
| }
|
| @@ -2039,6 +2095,24 @@ TEST_F(AutofillMetricsTest, ProfileCheckoutFlowUserActions) {
|
| EXPECT_EQ(1, user_action_tester.GetActionCount(
|
| "Autofill_FormSubmitted_NonFillable"));
|
| }
|
| +
|
| + ASSERT_EQ(1U, ukm_service->entries_count());
|
| + ASSERT_EQ(1U, ukm_service->sources_count());
|
| + // Expect 2 |FORM_EVENT_LOCAL_SUGGESTION_FILLED| events. First, from
|
| + // call to |external_delegate_->DidAcceptSuggestion|. Second, from call to
|
| + // |autofill_manager_->FillOrPreviewForm|.
|
| + // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState|
|
| + // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|.
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsAddressFormEventMetricName,
|
| + AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN},
|
| + {internal::kUKMFormInteractionsAddressFormEventMetricName,
|
| + AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED},
|
| + {internal::kUKMFormInteractionsAddressFormEventMetricName,
|
| + AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED},
|
| + {internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName,
|
| + AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
|
| }
|
|
|
| // Tests that the Autofill_PolledCreditCardSuggestions user action is only
|
| @@ -2328,6 +2402,11 @@ TEST_F(AutofillMetricsTest, CreditCardShownFormEvents) {
|
| "Autofill.FormEvents.CreditCard",
|
| AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 0);
|
| }
|
| +
|
| + // UKM must not be logged unless enabled.
|
| + ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
|
| + EXPECT_EQ(0U, ukm_service->sources_count());
|
| + EXPECT_EQ(0U, ukm_service->entries_count());
|
| }
|
|
|
| // Test that we log selected form event for credit cards.
|
| @@ -2593,6 +2672,9 @@ TEST_F(AutofillMetricsTest, CreditCardGetRealPanDuration) {
|
|
|
| // Test that we log submitted form events for credit cards.
|
| TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) {
|
| + EnableUkmLogging();
|
| + ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
|
| +
|
| EnableWalletSync();
|
| // Creating all kinds of cards.
|
| personal_data_->RecreateCreditCards(
|
| @@ -2632,6 +2714,14 @@ TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) {
|
| histogram_tester.ExpectBucketCount(
|
| "Autofill.FormEvents.CreditCard",
|
| AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
|
| +
|
| + ASSERT_EQ(1U, ukm_service->entries_count());
|
| + ASSERT_EQ(1U, ukm_service->sources_count());
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName,
|
| + AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
|
| + ukm_service->Purge();
|
| }
|
|
|
| // Reset the autofill manager state.
|
| @@ -2650,6 +2740,16 @@ TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) {
|
| histogram_tester.ExpectBucketCount(
|
| "Autofill.FormEvents.CreditCard",
|
| AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 1);
|
| +
|
| + ASSERT_EQ(1U, ukm_service->entries_count());
|
| + ASSERT_EQ(1U, ukm_service->sources_count());
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsCreditCardFormEventMetricName,
|
| + AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN},
|
| + {internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName,
|
| + AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
|
| + ukm_service->Purge();
|
| }
|
|
|
| // Reset the autofill manager state.
|
| @@ -2671,6 +2771,16 @@ TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) {
|
| histogram_tester.ExpectBucketCount(
|
| "Autofill.FormEvents.CreditCard",
|
| AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 1);
|
| +
|
| + ASSERT_EQ(1U, ukm_service->entries_count());
|
| + ASSERT_EQ(1U, ukm_service->sources_count());
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsCreditCardFormEventMetricName,
|
| + AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED},
|
| + {internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName,
|
| + AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
|
| + ukm_service->Purge();
|
| }
|
|
|
| // Reset the autofill manager state.
|
| @@ -2693,6 +2803,16 @@ TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) {
|
| histogram_tester.ExpectBucketCount(
|
| "Autofill.FormEvents.CreditCard",
|
| AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 1);
|
| +
|
| + ASSERT_EQ(1U, ukm_service->entries_count());
|
| + ASSERT_EQ(1U, ukm_service->sources_count());
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsCreditCardFormEventMetricName,
|
| + AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED},
|
| + {internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName,
|
| + AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
|
| + ukm_service->Purge();
|
| }
|
|
|
| // Reset the autofill manager state.
|
| @@ -2709,6 +2829,7 @@ TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) {
|
| autofill_manager_->MakeFrontendID(guid, std::string()));
|
| autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS,
|
| "6011000990139424");
|
| + autofill_manager_->SubmitForm(form, TimeTicks::Now());
|
| histogram_tester.ExpectBucketCount(
|
| "Autofill.FormEvents.CreditCard",
|
| AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED, 1);
|
| @@ -2716,8 +2837,24 @@ TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) {
|
| "Autofill.FormEvents.CreditCard",
|
| AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE,
|
| 1);
|
| + ASSERT_EQ(1U, ukm_service->entries_count());
|
| + ASSERT_EQ(1U, ukm_service->sources_count());
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsUnmaskPromptEventMetricName,
|
| + AutofillMetrics::UNMASK_PROMPT_SHOWN},
|
| + {internal::kUKMFormInteractionsCreditCardFormEventMetricName,
|
| + AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED},
|
| + {internal::kUKMFormInteractionsCreditCardFormEventMetricName,
|
| + AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED},
|
| + {internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName,
|
| + AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
|
| + ukm_service->Purge();
|
| }
|
|
|
| + // Reset the autofill manager state.
|
| + autofill_manager_->Reset();
|
| +
|
| // Recreating cards as the previous test should have upgraded the masked
|
| // card to a full card.
|
| personal_data_->RecreateCreditCards(
|
| @@ -2725,8 +2862,6 @@ TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) {
|
| true /* include_masked_server_credit_card */,
|
| true /* include_full_server_credit_card */);
|
|
|
| - // Reset the autofill manager state.
|
| - autofill_manager_->Reset();
|
| autofill_manager_->AddSeenForm(form, field_types, field_types);
|
|
|
| {
|
| @@ -2734,7 +2869,25 @@ TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) {
|
| base::HistogramTester histogram_tester;
|
| autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
|
| autofill_manager_->SubmitForm(form, TimeTicks::Now());
|
| +
|
| + ASSERT_EQ(1U, ukm_service->entries_count());
|
| + ASSERT_EQ(1U, ukm_service->sources_count());
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName,
|
| + AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
|
| + ukm_service->Purge();
|
| +
|
| autofill_manager_->SubmitForm(form, TimeTicks::Now());
|
| +
|
| + ASSERT_EQ(1U, ukm_service->entries_count());
|
| + ASSERT_EQ(1U, ukm_service->sources_count());
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName,
|
| + AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
|
| + ukm_service->Purge();
|
| +
|
| histogram_tester.ExpectBucketCount(
|
| "Autofill.FormEvents.CreditCard",
|
| AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
|
| @@ -2815,6 +2968,16 @@ TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) {
|
| AutofillMetrics::
|
| FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE,
|
| 0);
|
| +
|
| + ASSERT_EQ(1U, ukm_service->entries_count());
|
| + ASSERT_EQ(1U, ukm_service->sources_count());
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsCreditCardFormEventMetricName,
|
| + AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN},
|
| + {internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName,
|
| + AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
|
| + ukm_service->Purge();
|
| }
|
| }
|
|
|
| @@ -3236,6 +3399,9 @@ TEST_F(AutofillMetricsTest, AddressFilledFormEvents) {
|
|
|
| // Test that we log submitted form events for address.
|
| TEST_F(AutofillMetricsTest, AddressSubmittedFormEvents) {
|
| + EnableUkmLogging();
|
| + ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
|
| +
|
| EnableWalletSync();
|
| // Create a profile.
|
| personal_data_->RecreateProfile();
|
| @@ -3272,6 +3438,14 @@ TEST_F(AutofillMetricsTest, AddressSubmittedFormEvents) {
|
| histogram_tester.ExpectBucketCount(
|
| "Autofill.FormEvents.Address",
|
| AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
|
| +
|
| + ASSERT_EQ(1U, ukm_service->entries_count());
|
| + ASSERT_EQ(1U, ukm_service->sources_count());
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName,
|
| + AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
|
| + ukm_service->Purge();
|
| }
|
|
|
| // Reset the autofill manager state.
|
| @@ -3729,7 +3903,6 @@ TEST_F(AutofillMetricsTest, AddressFormEventsAreSegmented) {
|
| }
|
| }
|
|
|
| -
|
| // Test that we log that Autofill is enabled when filling a form.
|
| TEST_F(AutofillMetricsTest, AutofillIsEnabledAtPageLoad) {
|
| base::HistogramTester histogram_tester;
|
| @@ -3768,6 +3941,9 @@ TEST_F(AutofillMetricsTest, DaysSinceLastUse_Profile) {
|
|
|
| // Verify that we correctly log the submitted form's state.
|
| TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) {
|
| + EnableUkmLogging();
|
| + ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
|
| +
|
| // Start with a form with insufficiently many fields.
|
| FormData form;
|
| form.name = ASCIIToUTF16("TestForm");
|
| @@ -3802,6 +3978,21 @@ TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) {
|
| AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1);
|
| EXPECT_EQ(1, user_action_tester.GetActionCount(
|
| "Autofill_FormSubmitted_NonFillable"));
|
| +
|
| + // Expect an entry for |kUKMDeveloperEngagementEntryName| and another entry
|
| + // for |kUKMFormInteractionsEntryName|. Both entries are for the same URL.
|
| + ASSERT_EQ(2U, ukm_service->entries_count());
|
| + ASSERT_EQ(2U, ukm_service->sources_count());
|
| + VerifyDeveloperEngagementUkm(
|
| + form, ukm_service,
|
| + AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS);
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsUserHappinessMetricMetricName,
|
| + AutofillMetrics::FORMS_LOADED},
|
| + {internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName,
|
| + AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
|
| + ukm_service->Purge();
|
| }
|
|
|
| // Non fillable form.
|
| @@ -3818,6 +4009,14 @@ TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) {
|
| AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1);
|
| EXPECT_EQ(1, user_action_tester.GetActionCount(
|
| "Autofill_FormSubmitted_NonFillable"));
|
| +
|
| + ASSERT_EQ(1U, ukm_service->entries_count());
|
| + ASSERT_EQ(1U, ukm_service->sources_count());
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName,
|
| + AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
|
| + ukm_service->Purge();
|
| }
|
|
|
| // Fill in the third field.
|
| @@ -3835,6 +4034,15 @@ TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) {
|
| 1);
|
| EXPECT_EQ(1, user_action_tester.GetActionCount(
|
| "Autofill_FormSubmitted_FilledNone_SuggestionsNotShown"));
|
| +
|
| + ASSERT_EQ(1U, ukm_service->entries_count());
|
| + ASSERT_EQ(1U, ukm_service->sources_count());
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName,
|
| + AutofillMetrics::
|
| + FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS}});
|
| + ukm_service->Purge();
|
| }
|
|
|
| // Autofilled none with suggestions shown.
|
| @@ -3848,6 +4056,17 @@ TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) {
|
| AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS, 1);
|
| EXPECT_EQ(1, user_action_tester.GetActionCount(
|
| "Autofill_FormSubmitted_FilledNone_SuggestionsShown"));
|
| +
|
| + ASSERT_EQ(1U, ukm_service->entries_count());
|
| + ASSERT_EQ(1U, ukm_service->sources_count());
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsAddressFormEventMetricName,
|
| + AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN},
|
| + {internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName,
|
| + AutofillMetrics::
|
| + FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS}});
|
| + ukm_service->Purge();
|
| }
|
|
|
| // Mark one of the fields as autofilled.
|
| @@ -3864,6 +4083,14 @@ TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) {
|
| AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME, 1);
|
| EXPECT_EQ(1, user_action_tester.GetActionCount(
|
| "Autofill_FormSubmitted_FilledSome"));
|
| +
|
| + ASSERT_EQ(1U, ukm_service->entries_count());
|
| + ASSERT_EQ(1U, ukm_service->sources_count());
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName,
|
| + AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME}});
|
| + ukm_service->Purge();
|
| }
|
|
|
| // Mark all of the fillable fields as autofilled.
|
| @@ -3881,6 +4108,14 @@ TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) {
|
| AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL, 1);
|
| EXPECT_EQ(1, user_action_tester.GetActionCount(
|
| "Autofill_FormSubmitted_FilledAll"));
|
| +
|
| + ASSERT_EQ(1U, ukm_service->entries_count());
|
| + ASSERT_EQ(1U, ukm_service->sources_count());
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName,
|
| + AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL}});
|
| + ukm_service->Purge();
|
| }
|
|
|
| // Clear out the third field's value.
|
| @@ -3897,12 +4132,23 @@ TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) {
|
| AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1);
|
| EXPECT_EQ(1, user_action_tester.GetActionCount(
|
| "Autofill_FormSubmitted_NonFillable"));
|
| +
|
| + ASSERT_EQ(1U, ukm_service->entries_count());
|
| + ASSERT_EQ(1U, ukm_service->sources_count());
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName,
|
| + AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
|
| + ukm_service->Purge();
|
| }
|
| }
|
|
|
| // Verify that we correctly log user happiness metrics dealing with form
|
| // interaction.
|
| TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) {
|
| + EnableUkmLogging();
|
| + ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
|
| +
|
| // Load a fillable form.
|
| FormData form;
|
| form.name = ASCIIToUTF16("TestForm");
|
| @@ -4002,6 +4248,30 @@ TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) {
|
| "Autofill.UserHappiness",
|
| AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD, 1);
|
| }
|
| +
|
| + autofill_manager_->Reset();
|
| +
|
| + // Verify UKM logs.
|
| + VerifyFormInteractionsUkm(
|
| + form, ukm_service,
|
| + {{internal::kUKMFormInteractionsUserHappinessMetricMetricName,
|
| + AutofillMetrics::FORMS_LOADED},
|
| + {internal::kUKMFormInteractionsUserHappinessMetricMetricName,
|
| + AutofillMetrics::USER_DID_TYPE},
|
| + {internal::kUKMFormInteractionsAddressFormEventMetricName,
|
| + AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN},
|
| + {internal::kUKMFormInteractionsAddressFormEventMetricName,
|
| + AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN},
|
| + {internal::kUKMFormInteractionsUserHappinessMetricMetricName,
|
| + AutofillMetrics::USER_DID_AUTOFILL},
|
| + {internal::kUKMFormInteractionsAddressFormEventMetricName,
|
| + AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED},
|
| + {internal::kUKMFormInteractionsUserHappinessMetricMetricName,
|
| + AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD},
|
| + {internal::kUKMFormInteractionsUserHappinessMetricMetricName,
|
| + AutofillMetrics::USER_DID_AUTOFILL},
|
| + {internal::kUKMFormInteractionsUserHappinessMetricMetricName,
|
| + AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD}});
|
| }
|
|
|
| // Verify that we correctly log metrics tracking the duration of form fill.
|
| @@ -4579,7 +4849,7 @@ TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric) {
|
| ukm::UkmServiceTestingHarness ukm_service_test_harness;
|
| GURL url("https://www.google.com");
|
| int upload_decision = 1;
|
| - std::map<std::string, int> metrics = {
|
| + std::vector<std::pair<const char*, int>> metrics = {
|
| {internal::kUKMCardUploadDecisionMetricName, upload_decision}};
|
|
|
| EXPECT_TRUE(AutofillMetrics::LogUkm(
|
| @@ -4620,7 +4890,7 @@ TEST_F(AutofillMetricsTest, RecordDeveloperEngagementMetric) {
|
| ukm::UkmServiceTestingHarness ukm_service_test_harness;
|
| GURL url("https://www.google.com");
|
| int form_structure_metric = 1;
|
| - std::map<std::string, int> metrics = {
|
| + std::vector<std::pair<const char*, int>> metrics = {
|
| {internal::kUKMDeveloperEngagementMetricName, form_structure_metric}};
|
|
|
| EXPECT_TRUE(AutofillMetrics::LogUkm(
|
| @@ -4660,7 +4930,7 @@ TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_InvalidUrl) {
|
| EnableUkmLogging();
|
| ukm::UkmServiceTestingHarness ukm_service_test_harness;
|
| GURL url("");
|
| - std::map<std::string, int> metrics = {{"metric", 1}};
|
| + std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}};
|
|
|
| EXPECT_FALSE(AutofillMetrics::LogUkm(
|
| ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics));
|
| @@ -4672,7 +4942,7 @@ TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoMetrics) {
|
| EnableUkmLogging();
|
| ukm::UkmServiceTestingHarness ukm_service_test_harness;
|
| GURL url("https://www.google.com");
|
| - std::map<std::string, int> metrics;
|
| + std::vector<std::pair<const char*, int>> metrics;
|
|
|
| EXPECT_FALSE(AutofillMetrics::LogUkm(
|
| ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics));
|
| @@ -4684,7 +4954,7 @@ TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmService) {
|
| EnableUkmLogging();
|
| ukm::UkmServiceTestingHarness ukm_service_test_harness;
|
| GURL url("https://www.google.com");
|
| - std::map<std::string, int> metrics = {{"metric", 1}};
|
| + std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}};
|
|
|
| EXPECT_FALSE(AutofillMetrics::LogUkm(nullptr, url, "test_ukm", metrics));
|
| ASSERT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count());
|
| @@ -4694,7 +4964,7 @@ TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmService) {
|
| TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_FeatureDisabled) {
|
| ukm::UkmServiceTestingHarness ukm_service_test_harness;
|
| GURL url("https://www.google.com");
|
| - std::map<std::string, int> metrics = {{"metric", 1}};
|
| + std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}};
|
|
|
| EXPECT_FALSE(AutofillMetrics::LogUkm(
|
| ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics));
|
|
|