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

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

Issue 2672623005: Record Autofill form events specially for nonsecure pages (Closed)
Patch Set: fix test added in rebase Created 3 years, 10 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 1859 matching lines...) Expand 10 before | Expand all | Expand 10 after
1870 personal_data_->RecreateCreditCards( 1870 personal_data_->RecreateCreditCards(
1871 true /* include_local_credit_card */, 1871 true /* include_local_credit_card */,
1872 false /* include_masked_server_credit_card */, 1872 false /* include_masked_server_credit_card */,
1873 false /* include_full_server_credit_card */); 1873 false /* include_full_server_credit_card */);
1874 1874
1875 // Set up the form data. 1875 // Set up the form data.
1876 FormData form; 1876 FormData form;
1877 form.name = ASCIIToUTF16("TestForm"); 1877 form.name = ASCIIToUTF16("TestForm");
1878 form.origin = GURL("http://example.com/form.html"); 1878 form.origin = GURL("http://example.com/form.html");
1879 form.action = GURL("http://example.com/submit.html"); 1879 form.action = GURL("http://example.com/submit.html");
1880 autofill_client_.set_form_origin(form.origin);
1880 1881
1881 FormFieldData field; 1882 FormFieldData field;
1882 std::vector<ServerFieldType> field_types; 1883 std::vector<ServerFieldType> field_types;
1883 test::CreateTestFormField("Month", "card_month", "", "text", &field); 1884 test::CreateTestFormField("Month", "card_month", "", "text", &field);
1884 form.fields.push_back(field); 1885 form.fields.push_back(field);
1885 field_types.push_back(CREDIT_CARD_EXP_MONTH); 1886 field_types.push_back(CREDIT_CARD_EXP_MONTH);
1886 test::CreateTestFormField("Year", "card_year", "", "text", &field); 1887 test::CreateTestFormField("Year", "card_year", "", "text", &field);
1887 form.fields.push_back(field); 1888 form.fields.push_back(field);
1888 field_types.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR); 1889 field_types.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR);
1889 test::CreateTestFormField("Credit card", "card", "", "text", &field); 1890 test::CreateTestFormField("Credit card", "card", "", "text", &field);
(...skipping 13 matching lines...) Expand all
1903 gfx::RectF()); 1904 gfx::RectF());
1904 histogram_tester.ExpectUniqueSample( 1905 histogram_tester.ExpectUniqueSample(
1905 "Autofill.QueriedCreditCardFormIsSecure", false, 1); 1906 "Autofill.QueriedCreditCardFormIsSecure", false, 1);
1906 } 1907 }
1907 1908
1908 { 1909 {
1909 // Simulate having seen this secure form on page load. 1910 // Simulate having seen this secure form on page load.
1910 autofill_manager_->Reset(); 1911 autofill_manager_->Reset();
1911 form.origin = GURL("https://example.com/form.html"); 1912 form.origin = GURL("https://example.com/form.html");
1912 form.action = GURL("https://example.com/submit.html"); 1913 form.action = GURL("https://example.com/submit.html");
1914 autofill_client_.set_form_origin(form.origin);
1913 autofill_manager_->AddSeenForm(form, field_types, field_types); 1915 autofill_manager_->AddSeenForm(form, field_types, field_types);
1914 1916
1915 // Simulate an Autofill query on a credit card field (HTTPS form). 1917 // Simulate an Autofill query on a credit card field (HTTPS form).
1916 base::HistogramTester histogram_tester; 1918 base::HistogramTester histogram_tester;
1917 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[1], 1919 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[1],
1918 gfx::RectF()); 1920 gfx::RectF());
1919 histogram_tester.ExpectUniqueSample( 1921 histogram_tester.ExpectUniqueSample(
1920 "Autofill.QueriedCreditCardFormIsSecure", true, 1); 1922 "Autofill.QueriedCreditCardFormIsSecure", true, 1);
1921 } 1923 }
1922 } 1924 }
(...skipping 2296 matching lines...) Expand 10 before | Expand all | Expand 10 after
4219 4221
4220 // Test that the Form-Not-Secure warning user action is recorded. 4222 // Test that the Form-Not-Secure warning user action is recorded.
4221 TEST_F(AutofillMetricsTest, ShowHttpNotSecureExplanationUserAction) { 4223 TEST_F(AutofillMetricsTest, ShowHttpNotSecureExplanationUserAction) {
4222 base::UserActionTester user_action_tester; 4224 base::UserActionTester user_action_tester;
4223 external_delegate_->DidAcceptSuggestion( 4225 external_delegate_->DidAcceptSuggestion(
4224 ASCIIToUTF16("Test"), POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE, 0); 4226 ASCIIToUTF16("Test"), POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE, 0);
4225 EXPECT_EQ(1, user_action_tester.GetActionCount( 4227 EXPECT_EQ(1, user_action_tester.GetActionCount(
4226 "Autofill_ShowedHttpNotSecureExplanation")); 4228 "Autofill_ShowedHttpNotSecureExplanation"));
4227 } 4229 }
4228 4230
4231 // Tests that credit card form submissions are logged specially when the form is
4232 // on a non-secure page.
4233 TEST_F(AutofillMetricsTest, NonsecureCreditCardForm) {
4234 personal_data_->RecreateCreditCards(
4235 true /* include_local_credit_card */,
4236 false /* include_masked_server_credit_card */,
4237 false /* include_full_server_credit_card */);
4238
4239 // Set up our form data.
4240 FormData form;
4241 form.name = ASCIIToUTF16("TestForm");
4242 form.origin = GURL("http://example.com/form.html");
4243 form.action = GURL("http://example.com/submit.html");
4244 autofill_client_.set_form_origin(form.origin);
4245
4246 FormFieldData field;
4247 std::vector<ServerFieldType> field_types;
4248 test::CreateTestFormField("Name on card", "cc-name", "", "text", &field);
4249 form.fields.push_back(field);
4250 field_types.push_back(CREDIT_CARD_NAME_FULL);
4251 test::CreateTestFormField("Credit card", "card", "", "text", &field);
4252 form.fields.push_back(field);
4253 field_types.push_back(CREDIT_CARD_NUMBER);
4254 test::CreateTestFormField("Month", "card_month", "", "text", &field);
4255 form.fields.push_back(field);
4256 field_types.push_back(CREDIT_CARD_EXP_MONTH);
4257
4258 // Simulate having seen this form on page load.
4259 // |form_structure| will be owned by |autofill_manager_|.
4260 autofill_manager_->AddSeenForm(form, field_types, field_types);
4261
4262 // Simulate an Autofill query on a credit card field.
4263 {
4264 base::UserActionTester user_action_tester;
4265 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
4266 EXPECT_EQ(1, user_action_tester.GetActionCount(
4267 "Autofill_PolledCreditCardSuggestions"));
4268 }
4269
4270 // Simulate submitting the credit card form.
4271 {
4272 base::HistogramTester histograms;
4273 autofill_manager_->SubmitForm(form, TimeTicks::Now());
4274 histograms.ExpectBucketCount(
4275 "Autofill.FormEvents.CreditCard.OnNonsecurePage",
4276 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
4277 histograms.ExpectBucketCount(
4278 "Autofill.FormEvents.CreditCard",
4279 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
4280 histograms.ExpectBucketCount(
4281 "Autofill.FormEvents.CreditCard.WithOnlyLocalData",
4282 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
4283 }
4284 }
4285
4286 // Tests that credit card form submissions are *not* logged specially when the
4287 // form is *not* on a non-secure page.
4288 TEST_F(AutofillMetricsTest,
4289 NonsecureCreditCardFormMetricsNotRecordedOnSecurePage) {
4290 personal_data_->RecreateCreditCards(
4291 true /* include_local_credit_card */,
4292 false /* include_masked_server_credit_card */,
4293 false /* include_full_server_credit_card */);
4294
4295 // Set up our form data.
4296 FormData form;
4297 form.name = ASCIIToUTF16("TestForm");
4298 form.origin = GURL("https://example.com/form.html");
4299 form.action = GURL("http://example.com/submit.html");
4300
4301 FormFieldData field;
4302 std::vector<ServerFieldType> field_types;
4303 test::CreateTestFormField("Name on card", "cc-name", "", "text", &field);
4304 form.fields.push_back(field);
4305 field_types.push_back(CREDIT_CARD_NAME_FULL);
4306 test::CreateTestFormField("Credit card", "card", "", "text", &field);
4307 form.fields.push_back(field);
4308 field_types.push_back(CREDIT_CARD_NUMBER);
4309 test::CreateTestFormField("Month", "card_month", "", "text", &field);
4310 form.fields.push_back(field);
4311 field_types.push_back(CREDIT_CARD_EXP_MONTH);
4312
4313 // Simulate having seen this form on page load.
4314 // |form_structure| will be owned by |autofill_manager_|.
4315 autofill_manager_->AddSeenForm(form, field_types, field_types);
4316
4317 // Simulate an Autofill query on a credit card field.
4318 {
4319 base::UserActionTester user_action_tester;
4320 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
4321 EXPECT_EQ(1, user_action_tester.GetActionCount(
4322 "Autofill_PolledCreditCardSuggestions"));
4323 }
4324
4325 // Simulate submitting the credit card form.
4326 {
4327 base::HistogramTester histograms;
4328 autofill_manager_->SubmitForm(form, TimeTicks::Now());
4329 histograms.ExpectBucketCount(
4330 "Autofill.FormEvents.CreditCard",
4331 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
4332 histograms.ExpectBucketCount(
4333 "Autofill.FormEvents.CreditCard",
4334 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
4335 // Check that the nonsecure histogram was not recorded. ExpectBucketCount()
4336 // can't be used here because it expects the histogram to exist.
4337 EXPECT_EQ(
4338 0, histograms.GetTotalCountsForPrefix("Autofill.FormEvents.CreditCard")
4339 ["Autofill.FormEvents.CreditCard.OnNonsecurePage"]);
4340 }
4341 }
4342
4229 } // namespace autofill 4343 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_metrics.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