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

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

Issue 2672623005: Record Autofill form events specially for nonsecure pages (Closed)
Patch Set: fix test added in rebase Created 3 years, 10 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/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 cdf459ea4194b2ff672e5423f1966e9ed8a940ce..b0928c076534b6967dbb3851fa0d20400c9c6814 100644
--- a/components/autofill/core/browser/autofill_metrics_unittest.cc
+++ b/components/autofill/core/browser/autofill_metrics_unittest.cc
@@ -1877,6 +1877,7 @@ TEST_F(AutofillMetricsTest, QueriedCreditCardFormIsSecure) {
form.name = ASCIIToUTF16("TestForm");
form.origin = GURL("http://example.com/form.html");
form.action = GURL("http://example.com/submit.html");
+ autofill_client_.set_form_origin(form.origin);
FormFieldData field;
std::vector<ServerFieldType> field_types;
@@ -1910,6 +1911,7 @@ TEST_F(AutofillMetricsTest, QueriedCreditCardFormIsSecure) {
autofill_manager_->Reset();
form.origin = GURL("https://example.com/form.html");
form.action = GURL("https://example.com/submit.html");
+ autofill_client_.set_form_origin(form.origin);
autofill_manager_->AddSeenForm(form, field_types, field_types);
// Simulate an Autofill query on a credit card field (HTTPS form).
@@ -4226,4 +4228,116 @@ TEST_F(AutofillMetricsTest, ShowHttpNotSecureExplanationUserAction) {
"Autofill_ShowedHttpNotSecureExplanation"));
}
+// Tests that credit card form submissions are logged specially when the form is
+// on a non-secure page.
+TEST_F(AutofillMetricsTest, NonsecureCreditCardForm) {
+ personal_data_->RecreateCreditCards(
+ true /* include_local_credit_card */,
+ false /* include_masked_server_credit_card */,
+ false /* include_full_server_credit_card */);
+
+ // 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");
+ autofill_client_.set_form_origin(form.origin);
+
+ FormFieldData field;
+ std::vector<ServerFieldType> field_types;
+ test::CreateTestFormField("Name on card", "cc-name", "", "text", &field);
+ form.fields.push_back(field);
+ field_types.push_back(CREDIT_CARD_NAME_FULL);
+ test::CreateTestFormField("Credit card", "card", "", "text", &field);
+ form.fields.push_back(field);
+ field_types.push_back(CREDIT_CARD_NUMBER);
+ test::CreateTestFormField("Month", "card_month", "", "text", &field);
+ form.fields.push_back(field);
+ field_types.push_back(CREDIT_CARD_EXP_MONTH);
+
+ // 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 an Autofill query on a credit card field.
+ {
+ base::UserActionTester user_action_tester;
+ autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
+ EXPECT_EQ(1, user_action_tester.GetActionCount(
+ "Autofill_PolledCreditCardSuggestions"));
+ }
+
+ // Simulate submitting the credit card form.
+ {
+ base::HistogramTester histograms;
+ autofill_manager_->SubmitForm(form, TimeTicks::Now());
+ histograms.ExpectBucketCount(
+ "Autofill.FormEvents.CreditCard.OnNonsecurePage",
+ AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
+ histograms.ExpectBucketCount(
+ "Autofill.FormEvents.CreditCard",
+ AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
+ histograms.ExpectBucketCount(
+ "Autofill.FormEvents.CreditCard.WithOnlyLocalData",
+ AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
+ }
+}
+
+// Tests that credit card form submissions are *not* logged specially when the
+// form is *not* on a non-secure page.
+TEST_F(AutofillMetricsTest,
+ NonsecureCreditCardFormMetricsNotRecordedOnSecurePage) {
+ personal_data_->RecreateCreditCards(
+ true /* include_local_credit_card */,
+ false /* include_masked_server_credit_card */,
+ false /* include_full_server_credit_card */);
+
+ // Set up our form data.
+ FormData form;
+ form.name = ASCIIToUTF16("TestForm");
+ form.origin = GURL("https://example.com/form.html");
+ form.action = GURL("http://example.com/submit.html");
+
+ FormFieldData field;
+ std::vector<ServerFieldType> field_types;
+ test::CreateTestFormField("Name on card", "cc-name", "", "text", &field);
+ form.fields.push_back(field);
+ field_types.push_back(CREDIT_CARD_NAME_FULL);
+ test::CreateTestFormField("Credit card", "card", "", "text", &field);
+ form.fields.push_back(field);
+ field_types.push_back(CREDIT_CARD_NUMBER);
+ test::CreateTestFormField("Month", "card_month", "", "text", &field);
+ form.fields.push_back(field);
+ field_types.push_back(CREDIT_CARD_EXP_MONTH);
+
+ // 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 an Autofill query on a credit card field.
+ {
+ base::UserActionTester user_action_tester;
+ autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
+ EXPECT_EQ(1, user_action_tester.GetActionCount(
+ "Autofill_PolledCreditCardSuggestions"));
+ }
+
+ // Simulate submitting the credit card form.
+ {
+ base::HistogramTester histograms;
+ autofill_manager_->SubmitForm(form, TimeTicks::Now());
+ histograms.ExpectBucketCount(
+ "Autofill.FormEvents.CreditCard",
+ AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
+ histograms.ExpectBucketCount(
+ "Autofill.FormEvents.CreditCard",
+ AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
+ // Check that the nonsecure histogram was not recorded. ExpectBucketCount()
+ // can't be used here because it expects the histogram to exist.
+ EXPECT_EQ(
+ 0, histograms.GetTotalCountsForPrefix("Autofill.FormEvents.CreditCard")
+ ["Autofill.FormEvents.CreditCard.OnNonsecurePage"]);
+ }
+}
+
} // namespace autofill
« no previous file with comments | « components/autofill/core/browser/autofill_metrics.cc ('k') | components/autofill/core/browser/test_autofill_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698