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

Side by Side Diff: components/autofill/core/browser/autofill_metrics_unittest.cc

Issue 2888633002: Revert of [Autofill] Enable Autofill UKM by default. (Closed)
Patch Set: Created 3 years, 7 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 unified diff | Download patch
OLDNEW
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 <utility> 10 #include <utility>
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 408
409 class AutofillMetricsTest : public testing::Test { 409 class AutofillMetricsTest : public testing::Test {
410 public: 410 public:
411 ~AutofillMetricsTest() override; 411 ~AutofillMetricsTest() override;
412 412
413 void SetUp() override; 413 void SetUp() override;
414 void TearDown() override; 414 void TearDown() override;
415 415
416 protected: 416 protected:
417 void EnableWalletSync(); 417 void EnableWalletSync();
418 void EnableUkmLogging();
418 419
419 base::test::ScopedTaskEnvironment scoped_task_environment_; 420 base::test::ScopedTaskEnvironment scoped_task_environment_;
420 TestAutofillClient autofill_client_; 421 TestAutofillClient autofill_client_;
421 std::unique_ptr<AccountTrackerService> account_tracker_; 422 std::unique_ptr<AccountTrackerService> account_tracker_;
422 std::unique_ptr<FakeSigninManagerBase> signin_manager_; 423 std::unique_ptr<FakeSigninManagerBase> signin_manager_;
423 std::unique_ptr<TestSigninClient> signin_client_; 424 std::unique_ptr<TestSigninClient> signin_client_;
424 std::unique_ptr<TestAutofillDriver> autofill_driver_; 425 std::unique_ptr<TestAutofillDriver> autofill_driver_;
425 std::unique_ptr<TestAutofillManager> autofill_manager_; 426 std::unique_ptr<TestAutofillManager> autofill_manager_;
426 std::unique_ptr<TestPersonalDataManager> personal_data_; 427 std::unique_ptr<TestPersonalDataManager> personal_data_;
427 std::unique_ptr<AutofillExternalDelegate> external_delegate_; 428 std::unique_ptr<AutofillExternalDelegate> external_delegate_;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 account_tracker_.reset(); 477 account_tracker_.reset();
477 signin_client_.reset(); 478 signin_client_.reset();
478 test::ReenableSystemServices(); 479 test::ReenableSystemServices();
479 autofill_client_.GetTestUkmService()->Purge(); 480 autofill_client_.GetTestUkmService()->Purge();
480 } 481 }
481 482
482 void AutofillMetricsTest::EnableWalletSync() { 483 void AutofillMetricsTest::EnableWalletSync() {
483 signin_manager_->SetAuthenticatedAccountInfo("12345", "syncuser@example.com"); 484 signin_manager_->SetAuthenticatedAccountInfo("12345", "syncuser@example.com");
484 } 485 }
485 486
487 void AutofillMetricsTest::EnableUkmLogging() {
488 scoped_feature_list_.InitAndEnableFeature(kAutofillUkmLogging);
489 }
490
486 // Test that we log quality metrics appropriately. 491 // Test that we log quality metrics appropriately.
487 TEST_F(AutofillMetricsTest, QualityMetrics) { 492 TEST_F(AutofillMetricsTest, QualityMetrics) {
488 // Set up our form data. 493 // Set up our form data.
489 FormData form; 494 FormData form;
490 form.name = ASCIIToUTF16("TestForm"); 495 form.name = ASCIIToUTF16("TestForm");
491 form.origin = GURL("http://example.com/form.html"); 496 form.origin = GURL("http://example.com/form.html");
492 form.action = GURL("http://example.com/submit.html"); 497 form.action = GURL("http://example.com/submit.html");
493 498
494 std::vector<ServerFieldType> heuristic_types, server_types; 499 std::vector<ServerFieldType> heuristic_types, server_types;
495 FormFieldData field; 500 FormFieldData field;
(...skipping 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 autofill_manager_->OnTextFieldDidChange(form, form.fields[0], TimeTicks()); 1622 autofill_manager_->OnTextFieldDidChange(form, form.fields[0], TimeTicks());
1618 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks()); 1623 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks());
1619 1624
1620 // Simulate form submission. 1625 // Simulate form submission.
1621 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 1626 autofill_manager_->SubmitForm(form, TimeTicks::Now());
1622 1627
1623 // An autofillable form was submitted, and the number of edited autofilled 1628 // An autofillable form was submitted, and the number of edited autofilled
1624 // fields is logged. 1629 // fields is logged.
1625 histogram_tester.ExpectUniqueSample( 1630 histogram_tester.ExpectUniqueSample(
1626 "Autofill.NumberOfEditedAutofilledFieldsAtSubmission", 2, 1); 1631 "Autofill.NumberOfEditedAutofilledFieldsAtSubmission", 2, 1);
1632
1633 // UKM must not be logged unless enabled.
1634 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
1635 EXPECT_EQ(0U, ukm_service->sources_count());
1636 EXPECT_EQ(0U, ukm_service->entries_count());
1627 } 1637 }
1628 1638
1629 // Verify that when resetting the autofill manager (such as during a 1639 // Verify that when resetting the autofill manager (such as during a
1630 // navigation), the proper number of edited fields is logged. 1640 // navigation), the proper number of edited fields is logged.
1631 TEST_F(AutofillMetricsTest, NumberOfEditedAutofilledFields_NoSubmission) { 1641 TEST_F(AutofillMetricsTest, NumberOfEditedAutofilledFields_NoSubmission) {
1632 // Construct a fillable form. 1642 // Construct a fillable form.
1633 FormData form; 1643 FormData form;
1634 form.name = ASCIIToUTF16("TestForm"); 1644 form.name = ASCIIToUTF16("TestForm");
1635 form.origin = GURL("http://example.com/form.html"); 1645 form.origin = GURL("http://example.com/form.html");
1636 form.action = GURL("http://example.com/submit.html"); 1646 form.action = GURL("http://example.com/submit.html");
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1671 autofill_manager_->RunRunLoop(); 1681 autofill_manager_->RunRunLoop();
1672 1682
1673 // An autofillable form was uploaded, and the number of edited autofilled 1683 // An autofillable form was uploaded, and the number of edited autofilled
1674 // fields is logged. 1684 // fields is logged.
1675 histogram_tester.ExpectUniqueSample( 1685 histogram_tester.ExpectUniqueSample(
1676 "Autofill.NumberOfEditedAutofilledFieldsAtSubmission.NoSubmission", 1, 1); 1686 "Autofill.NumberOfEditedAutofilledFieldsAtSubmission.NoSubmission", 1, 1);
1677 } 1687 }
1678 1688
1679 // Verify that we correctly log metrics regarding developer engagement. 1689 // Verify that we correctly log metrics regarding developer engagement.
1680 TEST_F(AutofillMetricsTest, DeveloperEngagement) { 1690 TEST_F(AutofillMetricsTest, DeveloperEngagement) {
1691 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
1692
1681 // Start with a non-fillable form. 1693 // Start with a non-fillable form.
1682 FormData form; 1694 FormData form;
1683 form.name = ASCIIToUTF16("TestForm"); 1695 form.name = ASCIIToUTF16("TestForm");
1684 form.origin = GURL("http://example.com/form.html"); 1696 form.origin = GURL("http://example.com/form.html");
1685 form.action = GURL("http://example.com/submit.html"); 1697 form.action = GURL("http://example.com/submit.html");
1686 1698
1687 FormFieldData field; 1699 FormFieldData field;
1688 test::CreateTestFormField("Name", "name", "", "text", &field); 1700 test::CreateTestFormField("Name", "name", "", "text", &field);
1689 form.fields.push_back(field); 1701 form.fields.push_back(field);
1690 test::CreateTestFormField("Email", "email", "", "text", &field); 1702 test::CreateTestFormField("Email", "email", "", "text", &field);
1691 form.fields.push_back(field); 1703 form.fields.push_back(field);
1692 1704
1693 std::vector<FormData> forms(1, form); 1705 std::vector<FormData> forms(1, form);
1694 1706
1695 // Ensure no metrics are logged when loading a non-fillable form. 1707 // Ensure no metrics are logged when loading a non-fillable form.
1696 { 1708 {
1697 base::HistogramTester histogram_tester; 1709 base::HistogramTester histogram_tester;
1698 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 1710 autofill_manager_->OnFormsSeen(forms, TimeTicks());
1699 autofill_manager_->Reset(); 1711 autofill_manager_->Reset();
1700 histogram_tester.ExpectTotalCount("Autofill.DeveloperEngagement", 0); 1712 histogram_tester.ExpectTotalCount("Autofill.DeveloperEngagement", 0);
1713
1714 // UKM must not be logged unless enabled.
1715 EXPECT_EQ(0U, ukm_service->sources_count());
1716 EXPECT_EQ(0U, ukm_service->entries_count());
1701 } 1717 }
1702 1718
1703 // Add another field to the form, so that it becomes fillable. 1719 // Add another field to the form, so that it becomes fillable.
1704 test::CreateTestFormField("Phone", "phone", "", "text", &field); 1720 test::CreateTestFormField("Phone", "phone", "", "text", &field);
1705 forms.back().fields.push_back(field); 1721 forms.back().fields.push_back(field);
1706 1722
1707 // Expect the "form parsed without hints" metric to be logged. 1723 // Expect the "form parsed without hints" metric to be logged.
1708 { 1724 {
1709 base::HistogramTester histogram_tester; 1725 base::HistogramTester histogram_tester;
1710 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 1726 autofill_manager_->OnFormsSeen(forms, TimeTicks());
1711 autofill_manager_->Reset(); 1727 autofill_manager_->Reset();
1712 histogram_tester.ExpectUniqueSample( 1728 histogram_tester.ExpectUniqueSample(
1713 "Autofill.DeveloperEngagement", 1729 "Autofill.DeveloperEngagement",
1714 AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS, 1); 1730 AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS, 1);
1731
1732 // UKM must not be logged unless enabled.
1733 EXPECT_EQ(0U, ukm_service->sources_count());
1734 EXPECT_EQ(0U, ukm_service->entries_count());
1715 } 1735 }
1716 1736
1717 // Add some fields with an author-specified field type to the form. 1737 // Add some fields with an author-specified field type to the form.
1718 // We need to add at least three fields, because a form must have at least 1738 // We need to add at least three fields, because a form must have at least
1719 // three fillable fields to be considered to be autofillable; and if at least 1739 // three fillable fields to be considered to be autofillable; and if at least
1720 // one field specifies an explicit type hint, we don't apply any of our usual 1740 // one field specifies an explicit type hint, we don't apply any of our usual
1721 // local heuristics to detect field types in the rest of the form. 1741 // local heuristics to detect field types in the rest of the form.
1722 test::CreateTestFormField("", "", "", "text", &field); 1742 test::CreateTestFormField("", "", "", "text", &field);
1723 field.autocomplete_attribute = "given-name"; 1743 field.autocomplete_attribute = "given-name";
1724 forms.back().fields.push_back(field); 1744 forms.back().fields.push_back(field);
1725 test::CreateTestFormField("", "", "", "text", &field); 1745 test::CreateTestFormField("", "", "", "text", &field);
1726 field.autocomplete_attribute = "email"; 1746 field.autocomplete_attribute = "email";
1727 forms.back().fields.push_back(field); 1747 forms.back().fields.push_back(field);
1728 test::CreateTestFormField("", "", "", "text", &field); 1748 test::CreateTestFormField("", "", "", "text", &field);
1729 field.autocomplete_attribute = "address-line1"; 1749 field.autocomplete_attribute = "address-line1";
1730 forms.back().fields.push_back(field); 1750 forms.back().fields.push_back(field);
1731 1751
1732 // Expect the "form parsed with field type hints" metric to be logged. 1752 // Expect the "form parsed with field type hints" metric to be logged.
1733 { 1753 {
1734 base::HistogramTester histogram_tester; 1754 base::HistogramTester histogram_tester;
1735 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 1755 autofill_manager_->OnFormsSeen(forms, TimeTicks());
1736 autofill_manager_->Reset(); 1756 autofill_manager_->Reset();
1737 histogram_tester.ExpectBucketCount( 1757 histogram_tester.ExpectBucketCount(
1738 "Autofill.DeveloperEngagement", 1758 "Autofill.DeveloperEngagement",
1739 AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS, 1); 1759 AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS, 1);
1740 1760
1761 // UKM must not be logged unless enabled.
1762 EXPECT_EQ(0U, ukm_service->sources_count());
1763 EXPECT_EQ(0U, ukm_service->entries_count());
1764
1741 histogram_tester.ExpectBucketCount( 1765 histogram_tester.ExpectBucketCount(
1742 "Autofill.DeveloperEngagement", 1766 "Autofill.DeveloperEngagement",
1743 AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT, 0); 1767 AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT, 0);
1744 } 1768 }
1745 1769
1746 // Add a field with an author-specified UPI-VPA field type in the form. 1770 // Add a field with an author-specified UPI-VPA field type in the form.
1747 test::CreateTestFormField("", "", "", "text", &field); 1771 test::CreateTestFormField("", "", "", "text", &field);
1748 field.autocomplete_attribute = "upi-vpa"; 1772 field.autocomplete_attribute = "upi-vpa";
1749 forms.back().fields.push_back(field); 1773 forms.back().fields.push_back(field);
1750 1774
1751 // Expect the "form parsed with type hints" metric, and the 1775 // Expect the "form parsed with type hints" metric, and the
1752 // "author-specified upi-vpa type" metric to be logged. 1776 // "author-specified upi-vpa type" metric to be logged.
1753 { 1777 {
1754 base::HistogramTester histogram_tester; 1778 base::HistogramTester histogram_tester;
1755 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 1779 autofill_manager_->OnFormsSeen(forms, TimeTicks());
1756 autofill_manager_->Reset(); 1780 autofill_manager_->Reset();
1757 histogram_tester.ExpectBucketCount( 1781 histogram_tester.ExpectBucketCount(
1758 "Autofill.DeveloperEngagement", 1782 "Autofill.DeveloperEngagement",
1759 AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS, 1); 1783 AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS, 1);
1760 histogram_tester.ExpectBucketCount( 1784 histogram_tester.ExpectBucketCount(
1761 "Autofill.DeveloperEngagement", 1785 "Autofill.DeveloperEngagement",
1762 AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT, 1); 1786 AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT, 1);
1763 } 1787 }
1764 } 1788 }
1765 1789
1766 // Verify that we correctly log UKM for form parsed without type hints regarding 1790 // Verify that we correctly log UKM for form parsed without type hints regarding
1767 // developer engagement. 1791 // developer engagement.
1768 TEST_F(AutofillMetricsTest, 1792 TEST_F(AutofillMetricsTest,
1769 UkmDeveloperEngagement_LogFillableFormParsedWithoutTypeHints) { 1793 UkmDeveloperEngagement_LogFillableFormParsedWithoutTypeHints) {
1794 EnableUkmLogging();
1770 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 1795 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
1771 1796
1772 // Start with a non-fillable form. 1797 // Start with a non-fillable form.
1773 FormData form; 1798 FormData form;
1774 form.name = ASCIIToUTF16("TestForm"); 1799 form.name = ASCIIToUTF16("TestForm");
1775 form.origin = GURL("http://example.com/form.html"); 1800 form.origin = GURL("http://example.com/form.html");
1776 form.action = GURL("http://example.com/submit.html"); 1801 form.action = GURL("http://example.com/submit.html");
1777 1802
1778 FormFieldData field; 1803 FormFieldData field;
1779 test::CreateTestFormField("Name", "name", "", "text", &field); 1804 test::CreateTestFormField("Name", "name", "", "text", &field);
(...skipping 27 matching lines...) Expand all
1807 VerifyDeveloperEngagementUkm( 1832 VerifyDeveloperEngagementUkm(
1808 form, ukm_service, 1833 form, ukm_service,
1809 {AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS}); 1834 {AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS});
1810 } 1835 }
1811 } 1836 }
1812 1837
1813 // Verify that we correctly log UKM for form parsed with type hints regarding 1838 // Verify that we correctly log UKM for form parsed with type hints regarding
1814 // developer engagement. 1839 // developer engagement.
1815 TEST_F(AutofillMetricsTest, 1840 TEST_F(AutofillMetricsTest,
1816 UkmDeveloperEngagement_LogFillableFormParsedWithTypeHints) { 1841 UkmDeveloperEngagement_LogFillableFormParsedWithTypeHints) {
1842 EnableUkmLogging();
1817 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 1843 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
1818 1844
1819 FormData form; 1845 FormData form;
1820 form.name = ASCIIToUTF16("TestForm"); 1846 form.name = ASCIIToUTF16("TestForm");
1821 form.origin = GURL("http://example.com/form.html"); 1847 form.origin = GURL("http://example.com/form.html");
1822 form.action = GURL("http://example.com/submit.html"); 1848 form.action = GURL("http://example.com/submit.html");
1823 1849
1824 FormFieldData field; 1850 FormFieldData field;
1825 test::CreateTestFormField("Name", "name", "", "text", &field); 1851 test::CreateTestFormField("Name", "name", "", "text", &field);
1826 form.fields.push_back(field); 1852 form.fields.push_back(field);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 ASSERT_EQ(1U, ukm_service->sources_count()); 1884 ASSERT_EQ(1U, ukm_service->sources_count());
1859 VerifyDeveloperEngagementUkm( 1885 VerifyDeveloperEngagementUkm(
1860 form, ukm_service, 1886 form, ukm_service,
1861 {AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS}); 1887 {AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS});
1862 } 1888 }
1863 } 1889 }
1864 1890
1865 // Verify that we correctly log UKM for form parsed with type hints regarding 1891 // Verify that we correctly log UKM for form parsed with type hints regarding
1866 // developer engagement. 1892 // developer engagement.
1867 TEST_F(AutofillMetricsTest, UkmDeveloperEngagement_LogUpiVpaTypeHint) { 1893 TEST_F(AutofillMetricsTest, UkmDeveloperEngagement_LogUpiVpaTypeHint) {
1894 EnableUkmLogging();
1868 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 1895 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
1869 1896
1870 FormData form; 1897 FormData form;
1871 form.name = ASCIIToUTF16("TestForm"); 1898 form.name = ASCIIToUTF16("TestForm");
1872 form.origin = GURL("http://example.com/form.html"); 1899 form.origin = GURL("http://example.com/form.html");
1873 form.action = GURL("http://example.com/submit.html"); 1900 form.action = GURL("http://example.com/submit.html");
1874 1901
1875 FormFieldData field; 1902 FormFieldData field;
1876 test::CreateTestFormField("Name", "name", "", "text", &field); 1903 test::CreateTestFormField("Name", "name", "", "text", &field);
1877 form.fields.push_back(field); 1904 form.fields.push_back(field);
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
2084 // Simulate activating the autofill popup for the email field after typing. 2111 // Simulate activating the autofill popup for the email field after typing.
2085 form.fields[0].is_autofilled = true; 2112 form.fields[0].is_autofilled = true;
2086 base::HistogramTester histogram_tester; 2113 base::HistogramTester histogram_tester;
2087 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 2114 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2088 histogram_tester.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0); 2115 histogram_tester.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0);
2089 } 2116 }
2090 } 2117 }
2091 2118
2092 // Test that the credit card checkout flow user actions are correctly logged. 2119 // Test that the credit card checkout flow user actions are correctly logged.
2093 TEST_F(AutofillMetricsTest, CreditCardCheckoutFlowUserActions) { 2120 TEST_F(AutofillMetricsTest, CreditCardCheckoutFlowUserActions) {
2121 EnableUkmLogging();
2094 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 2122 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
2095 2123
2096 personal_data_->RecreateCreditCards( 2124 personal_data_->RecreateCreditCards(
2097 true /* include_local_credit_card */, 2125 true /* include_local_credit_card */,
2098 false /* include_masked_server_credit_card */, 2126 false /* include_masked_server_credit_card */,
2099 false /* include_full_server_credit_card */); 2127 false /* include_full_server_credit_card */);
2100 2128
2101 // Set up our form data. 2129 // Set up our form data.
2102 FormData form; 2130 FormData form;
2103 form.name = ASCIIToUTF16("TestForm"); 2131 form.name = ASCIIToUTF16("TestForm");
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2182 {{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD}, 2210 {{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD},
2183 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 2211 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
2184 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState| 2212 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState|
2185 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|. 2213 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|.
2186 VerifySubmitFormUkm(form, ukm_service, 2214 VerifySubmitFormUkm(form, ukm_service,
2187 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); 2215 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA);
2188 } 2216 }
2189 2217
2190 // Test that the profile checkout flow user actions are correctly logged. 2218 // Test that the profile checkout flow user actions are correctly logged.
2191 TEST_F(AutofillMetricsTest, ProfileCheckoutFlowUserActions) { 2219 TEST_F(AutofillMetricsTest, ProfileCheckoutFlowUserActions) {
2220 EnableUkmLogging();
2192 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 2221 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
2193 2222
2194 // Create a profile. 2223 // Create a profile.
2195 personal_data_->RecreateProfile(); 2224 personal_data_->RecreateProfile();
2196 2225
2197 // Set up our form data. 2226 // Set up our form data.
2198 FormData form; 2227 FormData form;
2199 form.name = ASCIIToUTF16("TestForm"); 2228 form.name = ASCIIToUTF16("TestForm");
2200 form.origin = GURL("http://example.com/form.html"); 2229 form.origin = GURL("http://example.com/form.html");
2201 form.action = GURL("http://example.com/submit.html"); 2230 form.action = GURL("http://example.com/submit.html");
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
2563 base::HistogramTester histogram_tester; 2592 base::HistogramTester histogram_tester;
2564 autofill_manager_->DidShowSuggestions(false /* is_new_popup */, form, 2593 autofill_manager_->DidShowSuggestions(false /* is_new_popup */, form,
2565 field); 2594 field);
2566 histogram_tester.ExpectBucketCount( 2595 histogram_tester.ExpectBucketCount(
2567 "Autofill.FormEvents.CreditCard", 2596 "Autofill.FormEvents.CreditCard",
2568 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN, 0); 2597 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN, 0);
2569 histogram_tester.ExpectBucketCount( 2598 histogram_tester.ExpectBucketCount(
2570 "Autofill.FormEvents.CreditCard", 2599 "Autofill.FormEvents.CreditCard",
2571 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 0); 2600 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 0);
2572 } 2601 }
2602
2603 // UKM must not be logged unless enabled.
2604 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
2605 EXPECT_EQ(0U, ukm_service->sources_count());
2606 EXPECT_EQ(0U, ukm_service->entries_count());
2573 } 2607 }
2574 2608
2575 // Test that we log selected form event for credit cards. 2609 // Test that we log selected form event for credit cards.
2576 TEST_F(AutofillMetricsTest, CreditCardSelectedFormEvents) { 2610 TEST_F(AutofillMetricsTest, CreditCardSelectedFormEvents) {
2577 EnableWalletSync(); 2611 EnableWalletSync();
2578 // Creating all kinds of cards. 2612 // Creating all kinds of cards.
2579 personal_data_->RecreateCreditCards( 2613 personal_data_->RecreateCreditCards(
2580 true /* include_local_credit_card */, 2614 true /* include_local_credit_card */,
2581 true /* include_masked_server_credit_card */, 2615 true /* include_masked_server_credit_card */,
2582 true /* include_full_server_credit_card */); 2616 true /* include_full_server_credit_card */);
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
2829 std::string()); 2863 std::string());
2830 histogram_tester.ExpectTotalCount( 2864 histogram_tester.ExpectTotalCount(
2831 "Autofill.UnmaskPrompt.GetRealPanDuration", 1); 2865 "Autofill.UnmaskPrompt.GetRealPanDuration", 1);
2832 histogram_tester.ExpectTotalCount( 2866 histogram_tester.ExpectTotalCount(
2833 "Autofill.UnmaskPrompt.GetRealPanDuration.Failure", 1); 2867 "Autofill.UnmaskPrompt.GetRealPanDuration.Failure", 1);
2834 } 2868 }
2835 } 2869 }
2836 2870
2837 // Test that we log submitted form events for credit cards. 2871 // Test that we log submitted form events for credit cards.
2838 TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) { 2872 TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) {
2873 EnableUkmLogging();
2839 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 2874 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
2840 2875
2841 EnableWalletSync(); 2876 EnableWalletSync();
2842 // Creating all kinds of cards. 2877 // Creating all kinds of cards.
2843 personal_data_->RecreateCreditCards( 2878 personal_data_->RecreateCreditCards(
2844 true /* include_local_credit_card */, 2879 true /* include_local_credit_card */,
2845 true /* include_masked_server_credit_card */, 2880 true /* include_masked_server_credit_card */,
2846 true /* include_full_server_credit_card */); 2881 true /* include_full_server_credit_card */);
2847 // Set up our form data. 2882 // Set up our form data.
2848 FormData form; 2883 FormData form;
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
3545 "Autofill.FormEvents.Address", 3580 "Autofill.FormEvents.Address",
3546 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED, 2); 3581 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED, 2);
3547 histogram_tester.ExpectBucketCount( 3582 histogram_tester.ExpectBucketCount(
3548 "Autofill.FormEvents.Address", 3583 "Autofill.FormEvents.Address",
3549 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE, 1); 3584 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE, 1);
3550 } 3585 }
3551 } 3586 }
3552 3587
3553 // Test that we log submitted form events for address. 3588 // Test that we log submitted form events for address.
3554 TEST_F(AutofillMetricsTest, AddressSubmittedFormEvents) { 3589 TEST_F(AutofillMetricsTest, AddressSubmittedFormEvents) {
3590 EnableUkmLogging();
3555 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 3591 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
3556 3592
3557 EnableWalletSync(); 3593 EnableWalletSync();
3558 // Create a profile. 3594 // Create a profile.
3559 personal_data_->RecreateProfile(); 3595 personal_data_->RecreateProfile();
3560 // Set up our form data. 3596 // Set up our form data.
3561 FormData form; 3597 FormData form;
3562 form.name = ASCIIToUTF16("TestForm"); 3598 form.name = ASCIIToUTF16("TestForm");
3563 form.origin = GURL("http://example.com/form.html"); 3599 form.origin = GURL("http://example.com/form.html");
3564 form.action = GURL("http://example.com/submit.html"); 3600 form.action = GURL("http://example.com/submit.html");
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
4085 base::HistogramTester histogram_tester; 4121 base::HistogramTester histogram_tester;
4086 AutofillProfile profile; 4122 AutofillProfile profile;
4087 profile.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(13)); 4123 profile.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(13));
4088 profile.RecordAndLogUse(); 4124 profile.RecordAndLogUse();
4089 histogram_tester.ExpectBucketCount("Autofill.DaysSinceLastUse.Profile", 13, 4125 histogram_tester.ExpectBucketCount("Autofill.DaysSinceLastUse.Profile", 13,
4090 1); 4126 1);
4091 } 4127 }
4092 4128
4093 // Verify that we correctly log the submitted form's state. 4129 // Verify that we correctly log the submitted form's state.
4094 TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) { 4130 TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) {
4131 EnableUkmLogging();
4095 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 4132 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
4096 4133
4097 // Start with a form with insufficiently many fields. 4134 // Start with a form with insufficiently many fields.
4098 FormData form; 4135 FormData form;
4099 form.name = ASCIIToUTF16("TestForm"); 4136 form.name = ASCIIToUTF16("TestForm");
4100 form.origin = GURL("http://example.com/form.html"); 4137 form.origin = GURL("http://example.com/form.html");
4101 form.action = GURL("http://example.com/submit.html"); 4138 form.action = GURL("http://example.com/submit.html");
4102 4139
4103 FormFieldData field; 4140 FormFieldData field;
4104 test::CreateTestFormField("Name", "name", "", "text", &field); 4141 test::CreateTestFormField("Name", "name", "", "text", &field);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
4291 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); 4328 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}});
4292 VerifyFormInteractionUkm(form, ukm_service, 4329 VerifyFormInteractionUkm(form, ukm_service,
4293 internal::kUKMFormSubmittedEntryName, 4330 internal::kUKMFormSubmittedEntryName,
4294 expected_form_submission_ukm_metrics); 4331 expected_form_submission_ukm_metrics);
4295 } 4332 }
4296 } 4333 }
4297 4334
4298 // Verify that we correctly log user happiness metrics dealing with form 4335 // Verify that we correctly log user happiness metrics dealing with form
4299 // interaction. 4336 // interaction.
4300 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) { 4337 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) {
4338 EnableUkmLogging();
4301 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 4339 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
4302 4340
4303 // Load a fillable form. 4341 // Load a fillable form.
4304 FormData form; 4342 FormData form;
4305 form.name = ASCIIToUTF16("TestForm"); 4343 form.name = ASCIIToUTF16("TestForm");
4306 form.origin = GURL("http://example.com/form.html"); 4344 form.origin = GURL("http://example.com/form.html");
4307 form.action = GURL("http://example.com/submit.html"); 4345 form.action = GURL("http://example.com/submit.html");
4308 4346
4309 FormFieldData field; 4347 FormFieldData field;
4310 test::CreateTestFormField("Name", "name", "", "text", &field); 4348 test::CreateTestFormField("Name", "name", "", "text", &field);
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
5009 // Check that the nonsecure histogram was not recorded. ExpectBucketCount() 5047 // Check that the nonsecure histogram was not recorded. ExpectBucketCount()
5010 // can't be used here because it expects the histogram to exist. 5048 // can't be used here because it expects the histogram to exist.
5011 EXPECT_EQ( 5049 EXPECT_EQ(
5012 0, histograms.GetTotalCountsForPrefix("Autofill.FormEvents.CreditCard") 5050 0, histograms.GetTotalCountsForPrefix("Autofill.FormEvents.CreditCard")
5013 ["Autofill.FormEvents.CreditCard.OnNonsecurePage"]); 5051 ["Autofill.FormEvents.CreditCard.OnNonsecurePage"]);
5014 } 5052 }
5015 } 5053 }
5016 5054
5017 // Tests that logging CardUploadDecision UKM works as expected. 5055 // Tests that logging CardUploadDecision UKM works as expected.
5018 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric) { 5056 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric) {
5057 EnableUkmLogging();
5019 ukm::UkmServiceTestingHarness ukm_service_test_harness; 5058 ukm::UkmServiceTestingHarness ukm_service_test_harness;
5020 GURL url("https://www.google.com"); 5059 GURL url("https://www.google.com");
5021 int upload_decision = 1; 5060 int upload_decision = 1;
5022 std::vector<std::pair<const char*, int>> metrics = { 5061 std::vector<std::pair<const char*, int>> metrics = {
5023 {internal::kUKMCardUploadDecisionMetricName, upload_decision}}; 5062 {internal::kUKMCardUploadDecisionMetricName, upload_decision}};
5024 5063
5025 EXPECT_TRUE(AutofillMetrics::LogUkm( 5064 EXPECT_TRUE(AutofillMetrics::LogUkm(
5026 ukm_service_test_harness.test_ukm_service(), url, 5065 ukm_service_test_harness.test_ukm_service(), url,
5027 internal::kUKMCardUploadDecisionEntryName, metrics)); 5066 internal::kUKMCardUploadDecisionEntryName, metrics));
5028 5067
(...skipping 20 matching lines...) Expand all
5049 5088
5050 // Make sure that the correct upload decision was logged. 5089 // Make sure that the correct upload decision was logged.
5051 const ukm::Entry_Metric* metric = FindMetric( 5090 const ukm::Entry_Metric* metric = FindMetric(
5052 internal::kUKMCardUploadDecisionMetricName, entry_proto.metrics()); 5091 internal::kUKMCardUploadDecisionMetricName, entry_proto.metrics());
5053 ASSERT_NE(nullptr, metric); 5092 ASSERT_NE(nullptr, metric);
5054 EXPECT_EQ(upload_decision, metric->value()); 5093 EXPECT_EQ(upload_decision, metric->value());
5055 } 5094 }
5056 5095
5057 // Tests that logging DeveloperEngagement UKM works as expected. 5096 // Tests that logging DeveloperEngagement UKM works as expected.
5058 TEST_F(AutofillMetricsTest, RecordDeveloperEngagementMetric) { 5097 TEST_F(AutofillMetricsTest, RecordDeveloperEngagementMetric) {
5098 EnableUkmLogging();
5059 ukm::UkmServiceTestingHarness ukm_service_test_harness; 5099 ukm::UkmServiceTestingHarness ukm_service_test_harness;
5060 GURL url("https://www.google.com"); 5100 GURL url("https://www.google.com");
5061 int form_structure_metric = 1; 5101 int form_structure_metric = 1;
5062 std::vector<std::pair<const char*, int>> metrics = { 5102 std::vector<std::pair<const char*, int>> metrics = {
5063 {internal::kUKMDeveloperEngagementMetricName, form_structure_metric}}; 5103 {internal::kUKMDeveloperEngagementMetricName, form_structure_metric}};
5064 5104
5065 EXPECT_TRUE(AutofillMetrics::LogUkm( 5105 EXPECT_TRUE(AutofillMetrics::LogUkm(
5066 ukm_service_test_harness.test_ukm_service(), url, 5106 ukm_service_test_harness.test_ukm_service(), url,
5067 internal::kUKMDeveloperEngagementEntryName, metrics)); 5107 internal::kUKMDeveloperEngagementEntryName, metrics));
5068 5108
(...skipping 20 matching lines...) Expand all
5089 5129
5090 // Make sure that the correct developer engagement metric was logged. 5130 // Make sure that the correct developer engagement metric was logged.
5091 const ukm::Entry_Metric* metric = FindMetric( 5131 const ukm::Entry_Metric* metric = FindMetric(
5092 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics()); 5132 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics());
5093 ASSERT_NE(nullptr, metric); 5133 ASSERT_NE(nullptr, metric);
5094 EXPECT_EQ(form_structure_metric, metric->value()); 5134 EXPECT_EQ(form_structure_metric, metric->value());
5095 } 5135 }
5096 5136
5097 // Tests that no UKM is logged when the URL is not valid. 5137 // Tests that no UKM is logged when the URL is not valid.
5098 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_InvalidUrl) { 5138 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_InvalidUrl) {
5139 EnableUkmLogging();
5099 ukm::UkmServiceTestingHarness ukm_service_test_harness; 5140 ukm::UkmServiceTestingHarness ukm_service_test_harness;
5100 GURL url(""); 5141 GURL url("");
5101 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; 5142 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}};
5102 5143
5103 EXPECT_FALSE(AutofillMetrics::LogUkm( 5144 EXPECT_FALSE(AutofillMetrics::LogUkm(
5104 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); 5145 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics));
5105 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); 5146 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count());
5106 } 5147 }
5107 5148
5108 // Tests that no UKM is logged when the metrics map is empty. 5149 // Tests that no UKM is logged when the metrics map is empty.
5109 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoMetrics) { 5150 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoMetrics) {
5151 EnableUkmLogging();
5110 ukm::UkmServiceTestingHarness ukm_service_test_harness; 5152 ukm::UkmServiceTestingHarness ukm_service_test_harness;
5111 GURL url("https://www.google.com"); 5153 GURL url("https://www.google.com");
5112 std::vector<std::pair<const char*, int>> metrics; 5154 std::vector<std::pair<const char*, int>> metrics;
5113 5155
5114 EXPECT_FALSE(AutofillMetrics::LogUkm( 5156 EXPECT_FALSE(AutofillMetrics::LogUkm(
5115 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); 5157 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics));
5116 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); 5158 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count());
5117 } 5159 }
5118 5160
5119 // Tests that no UKM is logged when the ukm service is null. 5161 // Tests that no UKM is logged when the ukm service is null.
5120 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmService) { 5162 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmService) {
5163 EnableUkmLogging();
5121 ukm::UkmServiceTestingHarness ukm_service_test_harness; 5164 ukm::UkmServiceTestingHarness ukm_service_test_harness;
5122 GURL url("https://www.google.com"); 5165 GURL url("https://www.google.com");
5123 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; 5166 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}};
5124 5167
5125 EXPECT_FALSE(AutofillMetrics::LogUkm(nullptr, url, "test_ukm", metrics)); 5168 EXPECT_FALSE(AutofillMetrics::LogUkm(nullptr, url, "test_ukm", metrics));
5126 ASSERT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); 5169 ASSERT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count());
5127 } 5170 }
5128 5171
5172 // Tests that no UKM is logged when the ukm logging feature is disabled.
5173 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_FeatureDisabled) {
5174 ukm::UkmServiceTestingHarness ukm_service_test_harness;
5175 GURL url("https://www.google.com");
5176 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}};
5177
5178 EXPECT_FALSE(AutofillMetrics::LogUkm(
5179 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics));
5180 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count());
5181 }
5182
5129 } // namespace autofill 5183 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_metrics.cc ('k') | components/payments/core/journey_logger.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698