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 1d5c5168f5475ad417889ec883020c51760dda2e..8c1a8801c5291ae243277c7458218ccde0c00cf3 100644 |
| --- a/components/autofill/core/browser/autofill_metrics_unittest.cc |
| +++ b/components/autofill/core/browser/autofill_metrics_unittest.cc |
| @@ -155,7 +155,8 @@ class TestPersonalDataManager : public PersonalDataManager { |
| local_credit_cards_.clear(); |
| server_credit_cards_.clear(); |
| if (include_local_credit_card) { |
| - CreditCard* credit_card = new CreditCard; |
| + CreditCard* credit_card = |
| + new CreditCard(base::ASCIIToUTF16("4111111111111111"), 12, 24); |
| credit_card->set_guid("10000000-0000-0000-0000-000000000001"); |
| local_credit_cards_.push_back(credit_card); |
| } |
| @@ -1812,6 +1813,57 @@ TEST_F(AutofillMetricsTest, PolledCreditCardSuggestions_DebounceLogs) { |
| "Autofill_PolledCreditCardSuggestions")); |
| } |
| +// Tests that the Autofill.QueriedCreditCardFormIsSecure histogram is logged |
| +// properly. |
| +TEST_F(AutofillMetricsTest, QueriedCreditCardFormIsSecure) { |
| + personal_data_->RecreateCreditCards( |
| + true /* include_local_credit_card */, |
| + false /* include_masked_server_credit_card */, |
| + false /* include_full_server_credit_card */); |
| + |
| + // Set up the form data. |
| + FormData form; |
| + form.name = ASCIIToUTF16("TestForm"); |
| + form.origin = GURL("http://example.com/form.html"); |
| + form.action = GURL("http://example.com/submit.html"); |
| + |
| + 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_|. |
|
Ilya Sherman
2016/07/12 21:33:04
nit: Please omit the ownership comment, since it d
Mathieu
2016/07/13 01:32:57
Done.
|
| + autofill_manager_->AddSeenForm(form, field_types, field_types); |
| + |
| + { |
| + // Simulate an Autofill query on a credit card field. |
| + base::HistogramTester histogram_tester; |
| + autofill_client_.set_is_context_secure(true); |
|
Ilya Sherman
2016/07/12 21:33:04
nit: I'd swap the order of the above two lines (an
Mathieu
2016/07/13 01:32:57
Done.
|
| + autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[1], |
| + gfx::RectF()); |
| + histogram_tester.ExpectUniqueSample( |
| + "Autofill.QueriedCreditCardFormIsSecure", true, 1); |
| + } |
| + |
| + { |
| + // Simulate an Autofill query on a credit card field. |
| + base::HistogramTester histogram_tester; |
| + autofill_client_.set_is_context_secure(false); |
| + autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[1], |
| + gfx::RectF()); |
| + histogram_tester.ExpectUniqueSample( |
| + "Autofill.QueriedCreditCardFormIsSecure", false, 1); |
| + } |
| +} |
| + |
| // Tests that the Autofill_PolledProfileSuggestions user action is only logged |
| // once if the field is queried repeatedly. |
| TEST_F(AutofillMetricsTest, PolledProfileSuggestions_DebounceLogs) { |