| 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 4208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4219 | 4219 |
| 4220 // Test that the Form-Not-Secure warning user action is recorded. | 4220 // Test that the Form-Not-Secure warning user action is recorded. |
| 4221 TEST_F(AutofillMetricsTest, ShowHttpNotSecureExplanationUserAction) { | 4221 TEST_F(AutofillMetricsTest, ShowHttpNotSecureExplanationUserAction) { |
| 4222 base::UserActionTester user_action_tester; | 4222 base::UserActionTester user_action_tester; |
| 4223 external_delegate_->DidAcceptSuggestion( | 4223 external_delegate_->DidAcceptSuggestion( |
| 4224 ASCIIToUTF16("Test"), POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE, 0); | 4224 ASCIIToUTF16("Test"), POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE, 0); |
| 4225 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4225 EXPECT_EQ(1, user_action_tester.GetActionCount( |
| 4226 "Autofill_ShowedHttpNotSecureExplanation")); | 4226 "Autofill_ShowedHttpNotSecureExplanation")); |
| 4227 } | 4227 } |
| 4228 | 4228 |
| 4229 // Tests that credit card form submissions are logged specially when the form is |
| 4230 // on a non-secure page. |
| 4231 TEST_F(AutofillMetricsTest, NonsecureCreditCardForm) { |
| 4232 personal_data_->RecreateCreditCards( |
| 4233 true /* include_local_credit_card */, |
| 4234 false /* include_masked_server_credit_card */, |
| 4235 false /* include_full_server_credit_card */); |
| 4236 |
| 4237 // Set up our form data. |
| 4238 FormData form; |
| 4239 form.name = ASCIIToUTF16("TestForm"); |
| 4240 form.origin = GURL("http://example.com/form.html"); |
| 4241 form.action = GURL("http://example.com/submit.html"); |
| 4242 |
| 4243 FormFieldData field; |
| 4244 std::vector<ServerFieldType> field_types; |
| 4245 test::CreateTestFormField("Name on card", "cc-name", "", "text", &field); |
| 4246 form.fields.push_back(field); |
| 4247 field_types.push_back(CREDIT_CARD_NAME_FULL); |
| 4248 test::CreateTestFormField("Credit card", "card", "", "text", &field); |
| 4249 form.fields.push_back(field); |
| 4250 field_types.push_back(CREDIT_CARD_NUMBER); |
| 4251 test::CreateTestFormField("Month", "card_month", "", "text", &field); |
| 4252 form.fields.push_back(field); |
| 4253 field_types.push_back(CREDIT_CARD_EXP_MONTH); |
| 4254 |
| 4255 // Simulate having seen this form on page load. |
| 4256 // |form_structure| will be owned by |autofill_manager_|. |
| 4257 autofill_manager_->AddSeenForm(form, field_types, field_types); |
| 4258 |
| 4259 // Simulate an Autofill query on a credit card field. |
| 4260 { |
| 4261 base::UserActionTester user_action_tester; |
| 4262 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
| 4263 EXPECT_EQ(1, user_action_tester.GetActionCount( |
| 4264 "Autofill_PolledCreditCardSuggestions")); |
| 4265 } |
| 4266 |
| 4267 // Simulate submitting the credit card form. |
| 4268 { |
| 4269 base::HistogramTester histograms; |
| 4270 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
| 4271 histograms.ExpectBucketCount( |
| 4272 "Autofill.FormEvents.CreditCard.OnNonsecurePage", |
| 4273 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); |
| 4274 histograms.ExpectBucketCount( |
| 4275 "Autofill.FormEvents.CreditCard", |
| 4276 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); |
| 4277 histograms.ExpectBucketCount( |
| 4278 "Autofill.FormEvents.CreditCard.WithOnlyLocalData", |
| 4279 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); |
| 4280 } |
| 4281 } |
| 4282 |
| 4283 // Tests that credit card form submissions are *not* logged specially when the |
| 4284 // form is *not* on a non-secure page. |
| 4285 TEST_F(AutofillMetricsTest, |
| 4286 NonsecureCreditCardFormMetricsNotRecordedOnSecurePage) { |
| 4287 autofill_client_.set_main_url_secure(); |
| 4288 personal_data_->RecreateCreditCards( |
| 4289 true /* include_local_credit_card */, |
| 4290 false /* include_masked_server_credit_card */, |
| 4291 false /* include_full_server_credit_card */); |
| 4292 |
| 4293 // Set up our form data. |
| 4294 FormData form; |
| 4295 form.name = ASCIIToUTF16("TestForm"); |
| 4296 form.origin = GURL("https://example.com/form.html"); |
| 4297 form.action = GURL("http://example.com/submit.html"); |
| 4298 |
| 4299 FormFieldData field; |
| 4300 std::vector<ServerFieldType> field_types; |
| 4301 test::CreateTestFormField("Name on card", "cc-name", "", "text", &field); |
| 4302 form.fields.push_back(field); |
| 4303 field_types.push_back(CREDIT_CARD_NAME_FULL); |
| 4304 test::CreateTestFormField("Credit card", "card", "", "text", &field); |
| 4305 form.fields.push_back(field); |
| 4306 field_types.push_back(CREDIT_CARD_NUMBER); |
| 4307 test::CreateTestFormField("Month", "card_month", "", "text", &field); |
| 4308 form.fields.push_back(field); |
| 4309 field_types.push_back(CREDIT_CARD_EXP_MONTH); |
| 4310 |
| 4311 // Simulate having seen this form on page load. |
| 4312 // |form_structure| will be owned by |autofill_manager_|. |
| 4313 autofill_manager_->AddSeenForm(form, field_types, field_types); |
| 4314 |
| 4315 // Simulate an Autofill query on a credit card field. |
| 4316 { |
| 4317 base::UserActionTester user_action_tester; |
| 4318 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
| 4319 EXPECT_EQ(1, user_action_tester.GetActionCount( |
| 4320 "Autofill_PolledCreditCardSuggestions")); |
| 4321 } |
| 4322 |
| 4323 // Simulate submitting the credit card form. |
| 4324 { |
| 4325 base::HistogramTester histograms; |
| 4326 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
| 4327 histograms.ExpectBucketCount( |
| 4328 "Autofill.FormEvents.CreditCard", |
| 4329 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); |
| 4330 histograms.ExpectBucketCount( |
| 4331 "Autofill.FormEvents.CreditCard", |
| 4332 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); |
| 4333 // Check that the nonsecure histogram was not recorded. ExpectBucketCount() |
| 4334 // can't be used here because it expects the histogram to exist. |
| 4335 EXPECT_EQ( |
| 4336 0, histograms.GetTotalCountsForPrefix("Autofill.FormEvents.CreditCard") |
| 4337 ["Autofill.FormEvents.CreditCard.OnNonsecurePage"]); |
| 4338 } |
| 4339 } |
| 4340 |
| 4229 } // namespace autofill | 4341 } // namespace autofill |
| OLD | NEW |