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

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

Issue 2111863002: [Autofill] Debounce suggestions poll user actions for the same field. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « components/autofill/core/browser/autofill_metrics.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <vector> 10 #include <vector>
(...skipping 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 { 1745 {
1746 base::UserActionTester user_action_tester; 1746 base::UserActionTester user_action_tester;
1747 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 1747 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
1748 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 1748 autofill_manager_->SubmitForm(form, TimeTicks::Now());
1749 EXPECT_EQ(1, 1749 EXPECT_EQ(1,
1750 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); 1750 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm"));
1751 EXPECT_EQ(1, user_action_tester.GetActionCount("Autofill_FormSubmitted")); 1751 EXPECT_EQ(1, user_action_tester.GetActionCount("Autofill_FormSubmitted"));
1752 } 1752 }
1753 } 1753 }
1754 1754
1755 // Tests that the Autofill_PolledCreditCardSuggestions user action is only
1756 // logged once if the field is queried repeatedly.
1757 TEST_F(AutofillMetricsTest, PolledCreditCardSuggestions_DebounceLogs) {
1758 personal_data_->RecreateCreditCards(
1759 true /* include_local_credit_card */,
1760 false /* include_masked_server_credit_card */,
1761 false /* include_full_server_credit_card */);
1762
1763 // Set up the form data.
1764 FormData form;
1765 form.name = ASCIIToUTF16("TestForm");
1766 form.origin = GURL("http://example.com/form.html");
1767 form.action = GURL("http://example.com/submit.html");
1768
1769 FormFieldData field;
1770 std::vector<ServerFieldType> field_types;
1771 test::CreateTestFormField("Name on card", "cc-name", "", "text", &field);
1772 form.fields.push_back(field);
1773 field_types.push_back(CREDIT_CARD_NAME_FULL);
1774 test::CreateTestFormField("Credit card", "card", "", "text", &field);
1775 form.fields.push_back(field);
1776 field_types.push_back(CREDIT_CARD_NUMBER);
1777 test::CreateTestFormField("Month", "card_month", "", "text", &field);
1778 form.fields.push_back(field);
1779 field_types.push_back(CREDIT_CARD_EXP_MONTH);
1780
1781 // Simulate having seen this form on page load.
1782 // |form_structure| will be owned by |autofill_manager_|.
1783 autofill_manager_->AddSeenForm(form, field_types, field_types);
1784
1785 // Simulate an Autofill query on a credit card field. A poll should be logged.
1786 base::UserActionTester user_action_tester;
1787 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[0],
1788 gfx::RectF());
1789 EXPECT_EQ(1, user_action_tester.GetActionCount(
1790 "Autofill_PolledCreditCardSuggestions"));
1791
1792 // Simulate a second query on the same field. There should still only be one
1793 // logged poll.
1794 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[0],
1795 gfx::RectF());
1796 EXPECT_EQ(1, user_action_tester.GetActionCount(
1797 "Autofill_PolledCreditCardSuggestions"));
1798
1799 // Simulate a query to another field. There should be a second poll logged.
1800 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[1],
1801 gfx::RectF());
1802 EXPECT_EQ(2, user_action_tester.GetActionCount(
1803 "Autofill_PolledCreditCardSuggestions"));
1804
1805 // Simulate a query back to the initial field. There should be a third poll
1806 // logged.
1807 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[0],
1808 gfx::RectF());
1809 EXPECT_EQ(3, user_action_tester.GetActionCount(
1810 "Autofill_PolledCreditCardSuggestions"));
1811 }
1812
1813 // Tests that the Autofill_PolledProfileSuggestions user action is only logged
1814 // once if the field is queried repeatedly.
1815 TEST_F(AutofillMetricsTest, PolledProfileSuggestions_DebounceLogs) {
1816 personal_data_->RecreateProfiles(true /* include_local_profile */,
1817 false /* include_server_profile */);
1818
1819 // Set up the form data.
1820 FormData form;
1821 form.name = ASCIIToUTF16("TestForm");
1822 form.origin = GURL("http://example.com/form.html");
1823 form.action = GURL("http://example.com/submit.html");
1824
1825 FormFieldData field;
1826 std::vector<ServerFieldType> field_types;
1827 test::CreateTestFormField("State", "state", "", "text", &field);
1828 form.fields.push_back(field);
1829 field_types.push_back(ADDRESS_HOME_STATE);
1830 test::CreateTestFormField("City", "city", "", "text", &field);
1831 form.fields.push_back(field);
1832 field_types.push_back(ADDRESS_HOME_CITY);
1833 test::CreateTestFormField("Street", "street", "", "text", &field);
1834 form.fields.push_back(field);
1835 field_types.push_back(ADDRESS_HOME_STREET_ADDRESS);
1836
1837 // Simulate having seen this form on page load.
1838 // |form_structure| will be owned by |autofill_manager_|.
1839 autofill_manager_->AddSeenForm(form, field_types, field_types);
1840
1841 // Simulate an Autofill query on a profile field. A poll should be logged.
1842 base::UserActionTester user_action_tester;
1843 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[0],
1844 gfx::RectF());
1845 EXPECT_EQ(1, user_action_tester.GetActionCount(
1846 "Autofill_PolledProfileSuggestions"));
1847
1848 // Simulate a second query on the same field. There should still only be poll
1849 // logged.
1850 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[0],
1851 gfx::RectF());
1852 EXPECT_EQ(1, user_action_tester.GetActionCount(
1853 "Autofill_PolledProfileSuggestions"));
1854
1855 // Simulate a query to another field. There should be a second poll logged.
1856 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[1],
1857 gfx::RectF());
1858 EXPECT_EQ(2, user_action_tester.GetActionCount(
1859 "Autofill_PolledProfileSuggestions"));
1860
1861 // Simulate a query back to the initial field. There should be a third poll
1862 // logged.
1863 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[0],
1864 gfx::RectF());
1865 EXPECT_EQ(3, user_action_tester.GetActionCount(
1866 "Autofill_PolledProfileSuggestions"));
1867 }
1868
1755 // Test that we log interacted form event for credit cards related. 1869 // Test that we log interacted form event for credit cards related.
1756 TEST_F(AutofillMetricsTest, CreditCardInteractedFormEvents) { 1870 TEST_F(AutofillMetricsTest, CreditCardInteractedFormEvents) {
1757 // Set up our form data. 1871 // Set up our form data.
1758 FormData form; 1872 FormData form;
1759 form.name = ASCIIToUTF16("TestForm"); 1873 form.name = ASCIIToUTF16("TestForm");
1760 form.origin = GURL("http://example.com/form.html"); 1874 form.origin = GURL("http://example.com/form.html");
1761 form.action = GURL("http://example.com/submit.html"); 1875 form.action = GURL("http://example.com/submit.html");
1762 1876
1763 FormFieldData field; 1877 FormFieldData field;
1764 std::vector<ServerFieldType> field_types; 1878 std::vector<ServerFieldType> field_types;
(...skipping 2115 matching lines...) Expand 10 before | Expand all | Expand 10 after
3880 EXPECT_THAT( 3994 EXPECT_THAT(
3881 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), 3995 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"),
3882 ElementsAre(Bucket(true, 2))); 3996 ElementsAre(Bucket(true, 2)));
3883 3997
3884 // No RAPPOR metrics are logged in the case there is at least some server data 3998 // No RAPPOR metrics are logged in the case there is at least some server data
3885 // available for all forms. 3999 // available for all forms.
3886 EXPECT_EQ(0, rappor_service_.GetReportsCount()); 4000 EXPECT_EQ(0, rappor_service_.GetReportsCount());
3887 } 4001 }
3888 4002
3889 } // namespace autofill 4003 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_metrics.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698