| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 autofill_manager_->AddSeenForm(form, field_types, field_types); |
| 1844 |
| 1845 { |
| 1846 // Simulate an Autofill query on a credit card field. |
| 1847 autofill_client_.set_is_context_secure(true); |
| 1848 base::HistogramTester histogram_tester; |
| 1849 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[1], |
| 1850 gfx::RectF()); |
| 1851 histogram_tester.ExpectUniqueSample( |
| 1852 "Autofill.QueriedCreditCardFormIsSecure", true, 1); |
| 1853 } |
| 1854 |
| 1855 { |
| 1856 // Simulate an Autofill query on a credit card field. |
| 1857 autofill_client_.set_is_context_secure(false); |
| 1858 base::HistogramTester histogram_tester; |
| 1859 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[1], |
| 1860 gfx::RectF()); |
| 1861 histogram_tester.ExpectUniqueSample( |
| 1862 "Autofill.QueriedCreditCardFormIsSecure", false, 1); |
| 1863 } |
| 1864 } |
| 1865 |
| 1815 // Tests that the Autofill_PolledProfileSuggestions user action is only logged | 1866 // Tests that the Autofill_PolledProfileSuggestions user action is only logged |
| 1816 // once if the field is queried repeatedly. | 1867 // once if the field is queried repeatedly. |
| 1817 TEST_F(AutofillMetricsTest, PolledProfileSuggestions_DebounceLogs) { | 1868 TEST_F(AutofillMetricsTest, PolledProfileSuggestions_DebounceLogs) { |
| 1818 personal_data_->RecreateProfiles(true /* include_local_profile */, | 1869 personal_data_->RecreateProfiles(true /* include_local_profile */, |
| 1819 false /* include_server_profile */); | 1870 false /* include_server_profile */); |
| 1820 | 1871 |
| 1821 // Set up the form data. | 1872 // Set up the form data. |
| 1822 FormData form; | 1873 FormData form; |
| 1823 form.name = ASCIIToUTF16("TestForm"); | 1874 form.name = ASCIIToUTF16("TestForm"); |
| 1824 form.origin = GURL("http://example.com/form.html"); | 1875 form.origin = GURL("http://example.com/form.html"); |
| (...skipping 2192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4017 EXPECT_THAT( | 4068 EXPECT_THAT( |
| 4018 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), | 4069 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), |
| 4019 ElementsAre(Bucket(true, 2))); | 4070 ElementsAre(Bucket(true, 2))); |
| 4020 | 4071 |
| 4021 // No RAPPOR metrics are logged in the case there is at least some server data | 4072 // No RAPPOR metrics are logged in the case there is at least some server data |
| 4022 // available for all forms. | 4073 // available for all forms. |
| 4023 EXPECT_EQ(0, rappor_service_.GetReportsCount()); | 4074 EXPECT_EQ(0, rappor_service_.GetReportsCount()); |
| 4024 } | 4075 } |
| 4025 | 4076 |
| 4026 } // namespace autofill | 4077 } // namespace autofill |
| OLD | NEW |