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 d101f879395c0cfd9de4ca60d87252e3ed1a4b3f..7d18409a72c754f55c710b91de4525156b71dad8 100644 |
--- a/components/autofill/core/browser/autofill_metrics_unittest.cc |
+++ b/components/autofill/core/browser/autofill_metrics_unittest.cc |
@@ -680,6 +680,106 @@ TEST_F(AutofillMetricsTest, AddressSuggestionsCount) { |
} |
} |
+// Test that we log interacted form event for credit cards only once. |
+TEST_F(AutofillMetricsTest, CreditCardInteractedOnce) { |
+ // Set up our form data. |
+ FormData form; |
+ form.name = ASCIIToUTF16("TestForm"); |
+ form.origin = GURL("http://example.com/form.html"); |
+ form.action = GURL("http://example.com/submit.html"); |
+ form.user_submitted = true; |
+ |
+ FormFieldData field; |
+ std::vector<ServerFieldType> field_types; |
+ test::CreateTestFormField("Month", "card_month", "", "text", &field); |
+ form.fields.push_back(field); |
+ field_types.push_back(CREDIT_CARD_EXP_MONTH); |
+ test::CreateTestFormField("Year", "card_year", "", "text", &field); |
+ form.fields.push_back(field); |
+ field_types.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR); |
+ test::CreateTestFormField("Credit card", "card", "", "text", &field); |
+ form.fields.push_back(field); |
+ field_types.push_back(CREDIT_CARD_NUMBER); |
+ |
+ // Simulate having seen this form on page load. |
+ // |form_structure| will be owned by |autofill_manager_|. |
+ autofill_manager_->AddSeenForm(form, field_types, field_types); |
+ |
+ { |
+ // Simulate activating the autofill popup for the credit card field. |
+ base::HistogramTester histogram_tester; |
+ autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(), |
+ false); |
+ histogram_tester.ExpectUniqueSample( |
+ "Autofill.FormEvents.CreditCard", AutofillMetrics::INTERACTED_ONCE, 1); |
+ } |
+ |
+ // Reset the autofill manager state. |
+ autofill_manager_->Reset(); |
+ autofill_manager_->AddSeenForm(form, field_types, field_types); |
+ |
+ { |
+ // Simulate activating the autofill popup for the credit card field twice. |
+ base::HistogramTester histogram_tester; |
+ autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(), |
+ false); |
+ autofill_manager_->OnQueryFormFieldAutofill(1, form, field, gfx::Rect(), |
+ false); |
+ histogram_tester.ExpectUniqueSample( |
+ "Autofill.FormEvents.CreditCard", AutofillMetrics::INTERACTED_ONCE, 1); |
+ } |
+} |
+ |
+// Test that we log interacted form event for address only once. |
+TEST_F(AutofillMetricsTest, AddressInteractedOnce) { |
+ // Set up our form data. |
+ FormData form; |
+ form.name = ASCIIToUTF16("TestForm"); |
+ form.origin = GURL("http://example.com/form.html"); |
+ form.action = GURL("http://example.com/submit.html"); |
+ form.user_submitted = true; |
+ |
+ FormFieldData field; |
+ std::vector<ServerFieldType> field_types; |
+ test::CreateTestFormField("State", "state", "", "text", &field); |
+ form.fields.push_back(field); |
+ field_types.push_back(ADDRESS_HOME_STATE); |
+ test::CreateTestFormField("City", "city", "", "text", &field); |
+ form.fields.push_back(field); |
+ field_types.push_back(ADDRESS_HOME_CITY); |
+ test::CreateTestFormField("Street", "street", "", "text", &field); |
+ form.fields.push_back(field); |
+ field_types.push_back(ADDRESS_HOME_STREET_ADDRESS); |
+ |
+ // Simulate having seen this form on page load. |
+ // |form_structure| will be owned by |autofill_manager_|. |
+ autofill_manager_->AddSeenForm(form, field_types, field_types); |
+ |
+ { |
+ // Simulate activating the autofill popup for the street field. |
+ base::HistogramTester histogram_tester; |
+ autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(), |
+ false); |
+ histogram_tester.ExpectUniqueSample( |
+ "Autofill.FormEvents.Address", AutofillMetrics::INTERACTED_ONCE, 1); |
+ } |
+ |
+ // Reset the autofill manager state. |
+ autofill_manager_->Reset(); |
+ autofill_manager_->AddSeenForm(form, field_types, field_types); |
+ |
+ { |
+ // Simulate activating the autofill popup for the street field twice. |
+ base::HistogramTester histogram_tester; |
+ autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(), |
+ false); |
+ autofill_manager_->OnQueryFormFieldAutofill(1, form, field, gfx::Rect(), |
+ false); |
+ histogram_tester.ExpectUniqueSample( |
+ "Autofill.FormEvents.Address", AutofillMetrics::INTERACTED_ONCE, 1); |
+ } |
+} |
+ |
// Test that we log that Autofill is enabled when filling a form. |
TEST_F(AutofillMetricsTest, AutofillIsEnabledAtPageLoad) { |
base::HistogramTester histogram_tester; |