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

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

Issue 2144653002: [Autofill] Log whether queried credit card form context is secure (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: initial 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
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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 } 148 }
149 149
150 // Removes all existing credit cards and creates 0 or 1 local profiles and 150 // Removes all existing credit cards and creates 0 or 1 local profiles and
151 // 0 or 1 server profile according to the paramters. 151 // 0 or 1 server profile according to the paramters.
152 void RecreateCreditCards(bool include_local_credit_card, 152 void RecreateCreditCards(bool include_local_credit_card,
153 bool include_masked_server_credit_card, 153 bool include_masked_server_credit_card,
154 bool include_full_server_credit_card) { 154 bool include_full_server_credit_card) {
155 local_credit_cards_.clear(); 155 local_credit_cards_.clear();
156 server_credit_cards_.clear(); 156 server_credit_cards_.clear();
157 if (include_local_credit_card) { 157 if (include_local_credit_card) {
158 CreditCard* credit_card = new CreditCard; 158 CreditCard* credit_card =
159 new CreditCard(base::ASCIIToUTF16("4111111111111111"), 12, 24);
159 credit_card->set_guid("10000000-0000-0000-0000-000000000001"); 160 credit_card->set_guid("10000000-0000-0000-0000-000000000001");
160 local_credit_cards_.push_back(credit_card); 161 local_credit_cards_.push_back(credit_card);
161 } 162 }
162 if (include_masked_server_credit_card) { 163 if (include_masked_server_credit_card) {
163 CreditCard* credit_card = new CreditCard( 164 CreditCard* credit_card = new CreditCard(
164 CreditCard::MASKED_SERVER_CARD, "server_id"); 165 CreditCard::MASKED_SERVER_CARD, "server_id");
165 credit_card->set_guid("10000000-0000-0000-0000-000000000002"); 166 credit_card->set_guid("10000000-0000-0000-0000-000000000002");
166 credit_card->SetTypeForMaskedCard(kDiscoverCard); 167 credit_card->SetTypeForMaskedCard(kDiscoverCard);
167 server_credit_cards_.push_back(credit_card); 168 server_credit_cards_.push_back(credit_card);
168 } 169 }
(...skipping 1636 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 "Autofill_PolledCreditCardSuggestions")); 1806 "Autofill_PolledCreditCardSuggestions"));
1806 1807
1807 // Simulate a query back to the initial field. There should be a third poll 1808 // Simulate a query back to the initial field. There should be a third poll
1808 // logged. 1809 // logged.
1809 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[0], 1810 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[0],
1810 gfx::RectF()); 1811 gfx::RectF());
1811 EXPECT_EQ(3, user_action_tester.GetActionCount( 1812 EXPECT_EQ(3, user_action_tester.GetActionCount(
1812 "Autofill_PolledCreditCardSuggestions")); 1813 "Autofill_PolledCreditCardSuggestions"));
1813 } 1814 }
1814 1815
1816 // Tests that the Autofill.QueriedCreditCardFormIsSecure histogram is logged
1817 // properly.
1818 TEST_F(AutofillMetricsTest, QueriedCreditCardFormIsSecure) {
1819 personal_data_->RecreateCreditCards(
1820 true /* include_local_credit_card */,
1821 false /* include_masked_server_credit_card */,
1822 false /* include_full_server_credit_card */);
1823
1824 // Set up the form data.
1825 FormData form;
1826 form.name = ASCIIToUTF16("TestForm");
1827 form.origin = GURL("http://example.com/form.html");
1828 form.action = GURL("http://example.com/submit.html");
1829
1830 FormFieldData field;
1831 std::vector<ServerFieldType> field_types;
1832 test::CreateTestFormField("Month", "card_month", "", "text", &field);
1833 form.fields.push_back(field);
1834 field_types.push_back(CREDIT_CARD_EXP_MONTH);
1835 test::CreateTestFormField("Year", "card_year", "", "text", &field);
1836 form.fields.push_back(field);
1837 field_types.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR);
1838 test::CreateTestFormField("Credit card", "card", "", "text", &field);
1839 form.fields.push_back(field);
1840 field_types.push_back(CREDIT_CARD_NUMBER);
1841
1842 // Simulate having seen this form on page load.
1843 // |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.
1844 autofill_manager_->AddSeenForm(form, field_types, field_types);
1845
1846 {
1847 // Simulate an Autofill query on a credit card field.
1848 base::HistogramTester histogram_tester;
1849 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.
1850 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[1],
1851 gfx::RectF());
1852 histogram_tester.ExpectUniqueSample(
1853 "Autofill.QueriedCreditCardFormIsSecure", true, 1);
1854 }
1855
1856 {
1857 // Simulate an Autofill query on a credit card field.
1858 base::HistogramTester histogram_tester;
1859 autofill_client_.set_is_context_secure(false);
1860 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[1],
1861 gfx::RectF());
1862 histogram_tester.ExpectUniqueSample(
1863 "Autofill.QueriedCreditCardFormIsSecure", false, 1);
1864 }
1865 }
1866
1815 // Tests that the Autofill_PolledProfileSuggestions user action is only logged 1867 // Tests that the Autofill_PolledProfileSuggestions user action is only logged
1816 // once if the field is queried repeatedly. 1868 // once if the field is queried repeatedly.
1817 TEST_F(AutofillMetricsTest, PolledProfileSuggestions_DebounceLogs) { 1869 TEST_F(AutofillMetricsTest, PolledProfileSuggestions_DebounceLogs) {
1818 personal_data_->RecreateProfiles(true /* include_local_profile */, 1870 personal_data_->RecreateProfiles(true /* include_local_profile */,
1819 false /* include_server_profile */); 1871 false /* include_server_profile */);
1820 1872
1821 // Set up the form data. 1873 // Set up the form data.
1822 FormData form; 1874 FormData form;
1823 form.name = ASCIIToUTF16("TestForm"); 1875 form.name = ASCIIToUTF16("TestForm");
1824 form.origin = GURL("http://example.com/form.html"); 1876 form.origin = GURL("http://example.com/form.html");
(...skipping 2192 matching lines...) Expand 10 before | Expand all | Expand 10 after
4017 EXPECT_THAT( 4069 EXPECT_THAT(
4018 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), 4070 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"),
4019 ElementsAre(Bucket(true, 2))); 4071 ElementsAre(Bucket(true, 2)));
4020 4072
4021 // No RAPPOR metrics are logged in the case there is at least some server data 4073 // No RAPPOR metrics are logged in the case there is at least some server data
4022 // available for all forms. 4074 // available for all forms.
4023 EXPECT_EQ(0, rappor_service_.GetReportsCount()); 4075 EXPECT_EQ(0, rappor_service_.GetReportsCount());
4024 } 4076 }
4025 4077
4026 } // namespace autofill 4078 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_metrics.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698