| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/core/browser/autofill_metrics.h" | 5 #include "components/autofill/core/browser/autofill_metrics.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 1868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1879 personal_data_->RecreateCreditCards( | 1879 personal_data_->RecreateCreditCards( |
| 1880 true /* include_local_credit_card */, | 1880 true /* include_local_credit_card */, |
| 1881 false /* include_masked_server_credit_card */, | 1881 false /* include_masked_server_credit_card */, |
| 1882 false /* include_full_server_credit_card */); | 1882 false /* include_full_server_credit_card */); |
| 1883 | 1883 |
| 1884 // Set up the form data. | 1884 // Set up the form data. |
| 1885 FormData form; | 1885 FormData form; |
| 1886 form.name = ASCIIToUTF16("TestForm"); | 1886 form.name = ASCIIToUTF16("TestForm"); |
| 1887 form.origin = GURL("http://example.com/form.html"); | 1887 form.origin = GURL("http://example.com/form.html"); |
| 1888 form.action = GURL("http://example.com/submit.html"); | 1888 form.action = GURL("http://example.com/submit.html"); |
| 1889 autofill_client_.set_form_origin(form.origin); |
| 1889 | 1890 |
| 1890 FormFieldData field; | 1891 FormFieldData field; |
| 1891 std::vector<ServerFieldType> field_types; | 1892 std::vector<ServerFieldType> field_types; |
| 1892 test::CreateTestFormField("Month", "card_month", "", "text", &field); | 1893 test::CreateTestFormField("Month", "card_month", "", "text", &field); |
| 1893 form.fields.push_back(field); | 1894 form.fields.push_back(field); |
| 1894 field_types.push_back(CREDIT_CARD_EXP_MONTH); | 1895 field_types.push_back(CREDIT_CARD_EXP_MONTH); |
| 1895 test::CreateTestFormField("Year", "card_year", "", "text", &field); | 1896 test::CreateTestFormField("Year", "card_year", "", "text", &field); |
| 1896 form.fields.push_back(field); | 1897 form.fields.push_back(field); |
| 1897 field_types.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR); | 1898 field_types.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR); |
| 1898 test::CreateTestFormField("Credit card", "card", "", "text", &field); | 1899 test::CreateTestFormField("Credit card", "card", "", "text", &field); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1912 gfx::RectF()); | 1913 gfx::RectF()); |
| 1913 histogram_tester.ExpectUniqueSample( | 1914 histogram_tester.ExpectUniqueSample( |
| 1914 "Autofill.QueriedCreditCardFormIsSecure", false, 1); | 1915 "Autofill.QueriedCreditCardFormIsSecure", false, 1); |
| 1915 } | 1916 } |
| 1916 | 1917 |
| 1917 { | 1918 { |
| 1918 // Simulate having seen this secure form on page load. | 1919 // Simulate having seen this secure form on page load. |
| 1919 autofill_manager_->Reset(); | 1920 autofill_manager_->Reset(); |
| 1920 form.origin = GURL("https://example.com/form.html"); | 1921 form.origin = GURL("https://example.com/form.html"); |
| 1921 form.action = GURL("https://example.com/submit.html"); | 1922 form.action = GURL("https://example.com/submit.html"); |
| 1923 autofill_client_.set_form_origin(form.origin); |
| 1922 autofill_manager_->AddSeenForm(form, field_types, field_types); | 1924 autofill_manager_->AddSeenForm(form, field_types, field_types); |
| 1923 | 1925 |
| 1924 // Simulate an Autofill query on a credit card field (HTTPS form). | 1926 // Simulate an Autofill query on a credit card field (HTTPS form). |
| 1925 base::HistogramTester histogram_tester; | 1927 base::HistogramTester histogram_tester; |
| 1926 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[1], | 1928 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[1], |
| 1927 gfx::RectF()); | 1929 gfx::RectF()); |
| 1928 histogram_tester.ExpectUniqueSample( | 1930 histogram_tester.ExpectUniqueSample( |
| 1929 "Autofill.QueriedCreditCardFormIsSecure", true, 1); | 1931 "Autofill.QueriedCreditCardFormIsSecure", true, 1); |
| 1930 } | 1932 } |
| 1931 } | 1933 } |
| (...skipping 2394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4326 | 4328 |
| 4327 // Test that the Form-Not-Secure warning user action is recorded. | 4329 // Test that the Form-Not-Secure warning user action is recorded. |
| 4328 TEST_F(AutofillMetricsTest, ShowHttpNotSecureExplanationUserAction) { | 4330 TEST_F(AutofillMetricsTest, ShowHttpNotSecureExplanationUserAction) { |
| 4329 base::UserActionTester user_action_tester; | 4331 base::UserActionTester user_action_tester; |
| 4330 external_delegate_->DidAcceptSuggestion( | 4332 external_delegate_->DidAcceptSuggestion( |
| 4331 ASCIIToUTF16("Test"), POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE, 0); | 4333 ASCIIToUTF16("Test"), POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE, 0); |
| 4332 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4334 EXPECT_EQ(1, user_action_tester.GetActionCount( |
| 4333 "Autofill_ShowedHttpNotSecureExplanation")); | 4335 "Autofill_ShowedHttpNotSecureExplanation")); |
| 4334 } | 4336 } |
| 4335 | 4337 |
| 4338 // Tests that credit card form submissions are logged specially when the form is |
| 4339 // on a non-secure page. |
| 4340 TEST_F(AutofillMetricsTest, NonsecureCreditCardForm) { |
| 4341 personal_data_->RecreateCreditCards( |
| 4342 true /* include_local_credit_card */, |
| 4343 false /* include_masked_server_credit_card */, |
| 4344 false /* include_full_server_credit_card */); |
| 4345 |
| 4346 // Set up our form data. |
| 4347 FormData form; |
| 4348 form.name = ASCIIToUTF16("TestForm"); |
| 4349 form.origin = GURL("http://example.com/form.html"); |
| 4350 form.action = GURL("http://example.com/submit.html"); |
| 4351 autofill_client_.set_form_origin(form.origin); |
| 4352 |
| 4353 FormFieldData field; |
| 4354 std::vector<ServerFieldType> field_types; |
| 4355 test::CreateTestFormField("Name on card", "cc-name", "", "text", &field); |
| 4356 form.fields.push_back(field); |
| 4357 field_types.push_back(CREDIT_CARD_NAME_FULL); |
| 4358 test::CreateTestFormField("Credit card", "card", "", "text", &field); |
| 4359 form.fields.push_back(field); |
| 4360 field_types.push_back(CREDIT_CARD_NUMBER); |
| 4361 test::CreateTestFormField("Month", "card_month", "", "text", &field); |
| 4362 form.fields.push_back(field); |
| 4363 field_types.push_back(CREDIT_CARD_EXP_MONTH); |
| 4364 |
| 4365 // Simulate having seen this form on page load. |
| 4366 // |form_structure| will be owned by |autofill_manager_|. |
| 4367 autofill_manager_->AddSeenForm(form, field_types, field_types); |
| 4368 |
| 4369 // Simulate an Autofill query on a credit card field. |
| 4370 { |
| 4371 base::UserActionTester user_action_tester; |
| 4372 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
| 4373 EXPECT_EQ(1, user_action_tester.GetActionCount( |
| 4374 "Autofill_PolledCreditCardSuggestions")); |
| 4375 } |
| 4376 |
| 4377 // Simulate submitting the credit card form. |
| 4378 { |
| 4379 base::HistogramTester histograms; |
| 4380 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
| 4381 histograms.ExpectBucketCount( |
| 4382 "Autofill.FormEvents.CreditCard.OnNonsecurePage", |
| 4383 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); |
| 4384 histograms.ExpectBucketCount( |
| 4385 "Autofill.FormEvents.CreditCard", |
| 4386 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); |
| 4387 histograms.ExpectBucketCount( |
| 4388 "Autofill.FormEvents.CreditCard.WithOnlyLocalData", |
| 4389 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); |
| 4390 } |
| 4391 } |
| 4392 |
| 4393 // Tests that credit card form submissions are *not* logged specially when the |
| 4394 // form is *not* on a non-secure page. |
| 4395 TEST_F(AutofillMetricsTest, |
| 4396 NonsecureCreditCardFormMetricsNotRecordedOnSecurePage) { |
| 4397 personal_data_->RecreateCreditCards( |
| 4398 true /* include_local_credit_card */, |
| 4399 false /* include_masked_server_credit_card */, |
| 4400 false /* include_full_server_credit_card */); |
| 4401 |
| 4402 // Set up our form data. |
| 4403 FormData form; |
| 4404 form.name = ASCIIToUTF16("TestForm"); |
| 4405 form.origin = GURL("https://example.com/form.html"); |
| 4406 form.action = GURL("http://example.com/submit.html"); |
| 4407 |
| 4408 FormFieldData field; |
| 4409 std::vector<ServerFieldType> field_types; |
| 4410 test::CreateTestFormField("Name on card", "cc-name", "", "text", &field); |
| 4411 form.fields.push_back(field); |
| 4412 field_types.push_back(CREDIT_CARD_NAME_FULL); |
| 4413 test::CreateTestFormField("Credit card", "card", "", "text", &field); |
| 4414 form.fields.push_back(field); |
| 4415 field_types.push_back(CREDIT_CARD_NUMBER); |
| 4416 test::CreateTestFormField("Month", "card_month", "", "text", &field); |
| 4417 form.fields.push_back(field); |
| 4418 field_types.push_back(CREDIT_CARD_EXP_MONTH); |
| 4419 |
| 4420 // Simulate having seen this form on page load. |
| 4421 // |form_structure| will be owned by |autofill_manager_|. |
| 4422 autofill_manager_->AddSeenForm(form, field_types, field_types); |
| 4423 |
| 4424 // Simulate an Autofill query on a credit card field. |
| 4425 { |
| 4426 base::UserActionTester user_action_tester; |
| 4427 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
| 4428 EXPECT_EQ(1, user_action_tester.GetActionCount( |
| 4429 "Autofill_PolledCreditCardSuggestions")); |
| 4430 } |
| 4431 |
| 4432 // Simulate submitting the credit card form. |
| 4433 { |
| 4434 base::HistogramTester histograms; |
| 4435 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
| 4436 histograms.ExpectBucketCount( |
| 4437 "Autofill.FormEvents.CreditCard", |
| 4438 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); |
| 4439 histograms.ExpectBucketCount( |
| 4440 "Autofill.FormEvents.CreditCard", |
| 4441 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); |
| 4442 // Check that the nonsecure histogram was not recorded. ExpectBucketCount() |
| 4443 // can't be used here because it expects the histogram to exist. |
| 4444 EXPECT_EQ( |
| 4445 0, histograms.GetTotalCountsForPrefix("Autofill.FormEvents.CreditCard") |
| 4446 ["Autofill.FormEvents.CreditCard.OnNonsecurePage"]); |
| 4447 } |
| 4448 } |
| 4449 |
| 4336 } // namespace autofill | 4450 } // namespace autofill |
| OLD | NEW |