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

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

Issue 2419853002: [Autofill] Do not offer autofill suggestions on insecure forms (Closed)
Patch Set: Scheme check for HTTPS Created 4 years, 2 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 1799 matching lines...) Expand 10 before | Expand all | Expand 10 after
1810 // logged once if the field is queried repeatedly. 1810 // logged once if the field is queried repeatedly.
1811 TEST_F(AutofillMetricsTest, PolledCreditCardSuggestions_DebounceLogs) { 1811 TEST_F(AutofillMetricsTest, PolledCreditCardSuggestions_DebounceLogs) {
1812 personal_data_->RecreateCreditCards( 1812 personal_data_->RecreateCreditCards(
1813 true /* include_local_credit_card */, 1813 true /* include_local_credit_card */,
1814 false /* include_masked_server_credit_card */, 1814 false /* include_masked_server_credit_card */,
1815 false /* include_full_server_credit_card */); 1815 false /* include_full_server_credit_card */);
1816 1816
1817 // Set up the form data. 1817 // Set up the form data.
1818 FormData form; 1818 FormData form;
1819 form.name = ASCIIToUTF16("TestForm"); 1819 form.name = ASCIIToUTF16("TestForm");
1820 form.origin = GURL("http://example.com/form.html");
1821 form.action = GURL("http://example.com/submit.html");
1822 1820
1823 FormFieldData field; 1821 FormFieldData field;
1824 std::vector<ServerFieldType> field_types; 1822 std::vector<ServerFieldType> field_types;
1825 test::CreateTestFormField("Name on card", "cc-name", "", "text", &field); 1823 test::CreateTestFormField("Name on card", "cc-name", "", "text", &field);
1826 form.fields.push_back(field); 1824 form.fields.push_back(field);
1827 field_types.push_back(CREDIT_CARD_NAME_FULL); 1825 field_types.push_back(CREDIT_CARD_NAME_FULL);
1828 test::CreateTestFormField("Credit card", "card", "", "text", &field); 1826 test::CreateTestFormField("Credit card", "card", "", "text", &field);
1829 form.fields.push_back(field); 1827 form.fields.push_back(field);
1830 field_types.push_back(CREDIT_CARD_NUMBER); 1828 field_types.push_back(CREDIT_CARD_NUMBER);
1831 test::CreateTestFormField("Month", "card_month", "", "text", &field); 1829 test::CreateTestFormField("Month", "card_month", "", "text", &field);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1883 test::CreateTestFormField("Month", "card_month", "", "text", &field); 1881 test::CreateTestFormField("Month", "card_month", "", "text", &field);
1884 form.fields.push_back(field); 1882 form.fields.push_back(field);
1885 field_types.push_back(CREDIT_CARD_EXP_MONTH); 1883 field_types.push_back(CREDIT_CARD_EXP_MONTH);
1886 test::CreateTestFormField("Year", "card_year", "", "text", &field); 1884 test::CreateTestFormField("Year", "card_year", "", "text", &field);
1887 form.fields.push_back(field); 1885 form.fields.push_back(field);
1888 field_types.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR); 1886 field_types.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR);
1889 test::CreateTestFormField("Credit card", "card", "", "text", &field); 1887 test::CreateTestFormField("Credit card", "card", "", "text", &field);
1890 form.fields.push_back(field); 1888 form.fields.push_back(field);
1891 field_types.push_back(CREDIT_CARD_NUMBER); 1889 field_types.push_back(CREDIT_CARD_NUMBER);
1892 1890
1893 // Simulate having seen this form on page load. 1891 {
1894 autofill_manager_->AddSeenForm(form, field_types, field_types); 1892 // Simulate having seen this insecure form on page load.
1893 form.origin = GURL("http://example.com/form.html");
1894 form.action = GURL("http://example.com/submit.html");
1895 autofill_manager_->AddSeenForm(form, field_types, field_types);
1896
1897 // Simulate an Autofill query on a credit card field (HTTP, non-secure
1898 // form).
1899 base::HistogramTester histogram_tester;
1900 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[1],
1901 gfx::RectF());
1902 histogram_tester.ExpectUniqueSample(
1903 "Autofill.QueriedCreditCardFormIsSecure", false, 1);
1904 }
1895 1905
1896 { 1906 {
1897 // Simulate an Autofill query on a credit card field. 1907 // Simulate having seen this secure form on page load.
1898 autofill_client_.set_is_context_secure(true); 1908 autofill_manager_->Reset();
1909 form.origin = GURL("https://example.com/form.html");
1910 form.action = GURL("https://example.com/submit.html");
1911 autofill_manager_->AddSeenForm(form, field_types, field_types);
1912
1913 // Simulate an Autofill query on a credit card field (HTTPS form).
1899 base::HistogramTester histogram_tester; 1914 base::HistogramTester histogram_tester;
1900 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[1], 1915 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[1],
1901 gfx::RectF()); 1916 gfx::RectF());
1902 histogram_tester.ExpectUniqueSample( 1917 histogram_tester.ExpectUniqueSample(
1903 "Autofill.QueriedCreditCardFormIsSecure", true, 1); 1918 "Autofill.QueriedCreditCardFormIsSecure", true, 1);
1904 } 1919 }
1905
1906 {
1907 // Simulate an Autofill query on a credit card field.
1908 autofill_client_.set_is_context_secure(false);
1909 base::HistogramTester histogram_tester;
1910 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[1],
1911 gfx::RectF());
1912 histogram_tester.ExpectUniqueSample(
1913 "Autofill.QueriedCreditCardFormIsSecure", false, 1);
1914 }
1915 } 1920 }
1916 1921
1917 // Tests that the Autofill_PolledProfileSuggestions user action is only logged 1922 // Tests that the Autofill_PolledProfileSuggestions user action is only logged
1918 // once if the field is queried repeatedly. 1923 // once if the field is queried repeatedly.
1919 TEST_F(AutofillMetricsTest, PolledProfileSuggestions_DebounceLogs) { 1924 TEST_F(AutofillMetricsTest, PolledProfileSuggestions_DebounceLogs) {
1920 personal_data_->RecreateProfiles(true /* include_local_profile */, 1925 personal_data_->RecreateProfiles(true /* include_local_profile */,
1921 false /* include_server_profile */); 1926 false /* include_server_profile */);
1922 1927
1923 // Set up the form data. 1928 // Set up the form data.
1924 FormData form; 1929 FormData form;
(...skipping 2194 matching lines...) Expand 10 before | Expand all | Expand 10 after
4119 EXPECT_THAT( 4124 EXPECT_THAT(
4120 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), 4125 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"),
4121 ElementsAre(Bucket(true, 2))); 4126 ElementsAre(Bucket(true, 2)));
4122 4127
4123 // No RAPPOR metrics are logged in the case there is at least some server data 4128 // No RAPPOR metrics are logged in the case there is at least some server data
4124 // available for all forms. 4129 // available for all forms.
4125 EXPECT_EQ(0, rappor_service_.GetReportsCount()); 4130 EXPECT_EQ(0, rappor_service_.GetReportsCount());
4126 } 4131 }
4127 4132
4128 } // namespace autofill 4133 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager_unittest.cc ('k') | components/autofill/core/browser/test_autofill_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698