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 <utility> | 10 #include <utility> |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "components/autofill/core/browser/autofill_manager.h" | 27 #include "components/autofill/core/browser/autofill_manager.h" |
28 #include "components/autofill/core/browser/autofill_test_utils.h" | 28 #include "components/autofill/core/browser/autofill_test_utils.h" |
29 #include "components/autofill/core/browser/payments/payments_client.h" | 29 #include "components/autofill/core/browser/payments/payments_client.h" |
30 #include "components/autofill/core/browser/personal_data_manager.h" | 30 #include "components/autofill/core/browser/personal_data_manager.h" |
31 #include "components/autofill/core/browser/popup_item_ids.h" | 31 #include "components/autofill/core/browser/popup_item_ids.h" |
32 #include "components/autofill/core/browser/test_autofill_client.h" | 32 #include "components/autofill/core/browser/test_autofill_client.h" |
33 #include "components/autofill/core/browser/test_autofill_driver.h" | 33 #include "components/autofill/core/browser/test_autofill_driver.h" |
34 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 34 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
35 #include "components/autofill/core/common/form_data.h" | 35 #include "components/autofill/core/common/form_data.h" |
36 #include "components/autofill/core/common/form_field_data.h" | 36 #include "components/autofill/core/common/form_field_data.h" |
37 #include "components/metrics/proto/ukm/entry.pb.h" | |
38 #include "components/prefs/pref_service.h" | 37 #include "components/prefs/pref_service.h" |
39 #include "components/rappor/test_rappor_service.h" | 38 #include "components/rappor/test_rappor_service.h" |
40 #include "components/signin/core/browser/account_tracker_service.h" | 39 #include "components/signin/core/browser/account_tracker_service.h" |
41 #include "components/signin/core/browser/fake_signin_manager.h" | 40 #include "components/signin/core/browser/fake_signin_manager.h" |
42 #include "components/signin/core/browser/test_signin_client.h" | 41 #include "components/signin/core/browser/test_signin_client.h" |
43 #include "components/signin/core/common/signin_pref_names.h" | 42 #include "components/signin/core/common/signin_pref_names.h" |
44 #include "components/ukm/test_ukm_service.h" | 43 #include "components/ukm/test_ukm_recorder.h" |
45 #include "components/ukm/ukm_entry.h" | |
46 #include "components/ukm/ukm_source.h" | 44 #include "components/ukm/ukm_source.h" |
47 #include "components/webdata/common/web_data_results.h" | 45 #include "components/webdata/common/web_data_results.h" |
48 #include "testing/gmock/include/gmock/gmock.h" | 46 #include "testing/gmock/include/gmock/gmock.h" |
49 #include "testing/gtest/include/gtest/gtest.h" | 47 #include "testing/gtest/include/gtest/gtest.h" |
50 #include "ui/gfx/geometry/rect.h" | 48 #include "ui/gfx/geometry/rect.h" |
51 #include "url/gurl.h" | 49 #include "url/gurl.h" |
52 | 50 |
53 using base::ASCIIToUTF16; | 51 using base::ASCIIToUTF16; |
54 using base::Bucket; | 52 using base::Bucket; |
55 using base::TimeTicks; | 53 using base::TimeTicks; |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 observed_submission); | 301 observed_submission); |
304 } | 302 } |
305 | 303 |
306 private: | 304 private: |
307 bool autofill_enabled_; | 305 bool autofill_enabled_; |
308 std::unique_ptr<base::RunLoop> run_loop_; | 306 std::unique_ptr<base::RunLoop> run_loop_; |
309 | 307 |
310 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 308 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
311 }; | 309 }; |
312 | 310 |
313 // Finds the specified UKM metric by |name| in the specified UKM |metrics|. | |
314 const ukm::Entry_Metric* FindMetric( | |
315 const char* name, | |
316 const google::protobuf::RepeatedPtrField<ukm::Entry_Metric>& metrics) { | |
317 for (const auto& metric : metrics) { | |
318 if (metric.metric_hash() == base::HashMetricName(name)) | |
319 return &metric; | |
320 } | |
321 return nullptr; | |
322 } | |
323 | |
324 MATCHER(CompareMetrics, "") { | 311 MATCHER(CompareMetrics, "") { |
325 const ukm::Entry_Metric& lhs = ::testing::get<0>(arg); | 312 const ukm::mojom::UkmMetric* lhs = ::testing::get<0>(arg).get(); |
326 const std::pair<const char*, int64_t>& rhs = ::testing::get<1>(arg); | 313 const std::pair<const char*, int64_t>& rhs = ::testing::get<1>(arg); |
327 return lhs.metric_hash() == base::HashMetricName(rhs.first) && | 314 return lhs->metric_hash == base::HashMetricName(rhs.first) && |
328 lhs.value() == rhs.second; | 315 lhs->value == rhs.second; |
329 } | 316 } |
330 | 317 |
331 void VerifyDeveloperEngagementUkm( | 318 void VerifyDeveloperEngagementUkm( |
332 const FormData& form, | 319 const FormData& form, |
333 const ukm::TestUkmService* ukm_service, | 320 const ukm::TestUkmRecorder* ukm_recorder, |
334 const std::vector<int64_t>& expected_metric_values) { | 321 const std::vector<int64_t>& expected_metric_values) { |
335 const ukm::UkmEntry* entry = ukm_service->GetEntryForEntryName( | 322 const ukm::mojom::UkmEntry* entry = ukm_recorder->GetEntryForEntryName( |
336 internal::kUKMDeveloperEngagementEntryName); | 323 internal::kUKMDeveloperEngagementEntryName); |
337 ASSERT_NE(nullptr, entry); | 324 ASSERT_NE(nullptr, entry); |
338 ukm::Entry entry_proto; | |
339 entry->PopulateProto(&entry_proto); | |
340 | |
341 const ukm::UkmSource* source = | 325 const ukm::UkmSource* source = |
342 ukm_service->GetSourceForSourceId(entry_proto.source_id()); | 326 ukm_recorder->GetSourceForSourceId(entry->source_id); |
343 ASSERT_NE(nullptr, source); | 327 ASSERT_NE(nullptr, source); |
344 EXPECT_EQ(form.origin, source->url()); | 328 EXPECT_EQ(form.origin, source->url()); |
345 | 329 |
346 int expected_metric_value = 0; | 330 int expected_metric_value = 0; |
347 for (const auto it : expected_metric_values) | 331 for (const auto it : expected_metric_values) |
348 expected_metric_value |= 1 << it; | 332 expected_metric_value |= 1 << it; |
349 | 333 |
350 const std::vector<std::pair<const char*, int64_t>> expected_metrics{ | 334 const std::vector<std::pair<const char*, int64_t>> expected_metrics{ |
351 {internal::kUKMDeveloperEngagementMetricName, expected_metric_value}}; | 335 {internal::kUKMDeveloperEngagementMetricName, expected_metric_value}}; |
352 | 336 |
353 EXPECT_THAT(entry_proto.metrics(), | 337 EXPECT_THAT(entry->metrics, |
354 UnorderedPointwise(CompareMetrics(), expected_metrics)); | 338 UnorderedPointwise(CompareMetrics(), expected_metrics)); |
355 } | 339 } |
356 | 340 |
357 MATCHER(CompareMetricsIgnoringMillisecondsSinceFormParsed, "") { | 341 MATCHER(CompareMetricsIgnoringMillisecondsSinceFormParsed, "") { |
358 const ukm::Entry_Metric& lhs = ::testing::get<0>(arg); | 342 const ukm::mojom::UkmMetric* lhs = ::testing::get<0>(arg).get(); |
359 const std::pair<const char*, int64_t>& rhs = ::testing::get<1>(arg); | 343 const std::pair<const char*, int64_t>& rhs = ::testing::get<1>(arg); |
360 return lhs.metric_hash() == base::HashMetricName(rhs.first) && | 344 return lhs->metric_hash == base::HashMetricName(rhs.first) && |
361 (lhs.value() == rhs.second || | 345 (lhs->value == rhs.second || |
362 (lhs.value() > 0 && | 346 (lhs->value > 0 && |
363 rhs.first == internal::kUKMMillisecondsSinceFormParsedMetricName)); | 347 rhs.first == internal::kUKMMillisecondsSinceFormParsedMetricName)); |
364 } | 348 } |
365 | 349 |
366 void VerifyFormInteractionUkm( | 350 void VerifyFormInteractionUkm( |
367 const FormData& form, | 351 const FormData& form, |
368 const ukm::TestUkmService* ukm_service, | 352 const ukm::TestUkmRecorder* ukm_recorder, |
369 const char* event_name, | 353 const char* event_name, |
370 const std::vector<std::vector<std::pair<const char*, int64_t>>>& | 354 const std::vector<std::vector<std::pair<const char*, int64_t>>>& |
371 expected_metrics) { | 355 expected_metrics) { |
372 size_t expected_metrics_index = 0; | 356 size_t expected_metrics_index = 0; |
373 for (size_t i = 0; i < ukm_service->entries_count(); ++i) { | 357 for (size_t i = 0; i < ukm_recorder->entries_count(); ++i) { |
374 const ukm::UkmEntry* entry = ukm_service->GetEntry(i); | 358 const ukm::mojom::UkmEntry* entry = ukm_recorder->GetEntry(i); |
375 if (entry->event_hash() != base::HashMetricName(event_name)) | 359 if (entry->event_hash != base::HashMetricName(event_name)) |
376 continue; | 360 continue; |
377 | 361 |
378 ukm::Entry entry_proto; | |
379 entry->PopulateProto(&entry_proto); | |
380 | |
381 const ukm::UkmSource* source = | 362 const ukm::UkmSource* source = |
382 ukm_service->GetSourceForSourceId(entry_proto.source_id()); | 363 ukm_recorder->GetSourceForSourceId(entry->source_id); |
383 ASSERT_NE(nullptr, source); | 364 ASSERT_NE(nullptr, source); |
384 EXPECT_EQ(form.origin, source->url()); | 365 EXPECT_EQ(form.origin, source->url()); |
385 | 366 |
386 ASSERT_LT(expected_metrics_index, expected_metrics.size()); | 367 ASSERT_LT(expected_metrics_index, expected_metrics.size()); |
387 EXPECT_THAT( | 368 EXPECT_THAT( |
388 entry_proto.metrics(), | 369 entry->metrics, |
389 UnorderedPointwise(CompareMetricsIgnoringMillisecondsSinceFormParsed(), | 370 UnorderedPointwise(CompareMetricsIgnoringMillisecondsSinceFormParsed(), |
390 expected_metrics[expected_metrics_index++])); | 371 expected_metrics[expected_metrics_index++])); |
391 } | 372 } |
392 } | 373 } |
393 | 374 |
394 void VerifySubmitFormUkm(const FormData& form, | 375 void VerifySubmitFormUkm(const FormData& form, |
395 const ukm::TestUkmService* ukm_service, | 376 const ukm::TestUkmRecorder* ukm_recorder, |
396 AutofillMetrics::AutofillFormSubmittedState state) { | 377 AutofillMetrics::AutofillFormSubmittedState state) { |
397 VerifyFormInteractionUkm( | 378 VerifyFormInteractionUkm( |
398 form, ukm_service, internal::kUKMFormSubmittedEntryName, | 379 form, ukm_recorder, internal::kUKMFormSubmittedEntryName, |
399 {{{internal::kUKMAutofillFormSubmittedStateMetricName, state}, | 380 {{{internal::kUKMAutofillFormSubmittedStateMetricName, state}, |
400 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); | 381 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); |
401 } | 382 } |
402 | 383 |
403 } // namespace | 384 } // namespace |
404 | 385 |
405 // This is defined in the autofill_metrics.cc implementation file. | 386 // This is defined in the autofill_metrics.cc implementation file. |
406 int GetFieldTypeGroupMetric(ServerFieldType field_type, | 387 int GetFieldTypeGroupMetric(ServerFieldType field_type, |
407 AutofillMetrics::FieldTypeQualityMetric metric); | 388 AutofillMetrics::FieldTypeQualityMetric metric); |
408 | 389 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 // PersonalDataManager to be around when it gets destroyed. | 450 // PersonalDataManager to be around when it gets destroyed. |
470 autofill_manager_.reset(); | 451 autofill_manager_.reset(); |
471 autofill_driver_.reset(); | 452 autofill_driver_.reset(); |
472 personal_data_.reset(); | 453 personal_data_.reset(); |
473 signin_manager_->Shutdown(); | 454 signin_manager_->Shutdown(); |
474 signin_manager_.reset(); | 455 signin_manager_.reset(); |
475 account_tracker_->Shutdown(); | 456 account_tracker_->Shutdown(); |
476 account_tracker_.reset(); | 457 account_tracker_.reset(); |
477 signin_client_.reset(); | 458 signin_client_.reset(); |
478 test::ReenableSystemServices(); | 459 test::ReenableSystemServices(); |
479 autofill_client_.GetTestUkmService()->Purge(); | 460 autofill_client_.GetTestUkmRecorder()->Purge(); |
480 } | 461 } |
481 | 462 |
482 void AutofillMetricsTest::EnableWalletSync() { | 463 void AutofillMetricsTest::EnableWalletSync() { |
483 signin_manager_->SetAuthenticatedAccountInfo("12345", "syncuser@example.com"); | 464 signin_manager_->SetAuthenticatedAccountInfo("12345", "syncuser@example.com"); |
484 } | 465 } |
485 | 466 |
486 // Test that we log quality metrics appropriately. | 467 // Test that we log quality metrics appropriately. |
487 TEST_F(AutofillMetricsTest, QualityMetrics) { | 468 TEST_F(AutofillMetricsTest, QualityMetrics) { |
488 // Set up our form data. | 469 // Set up our form data. |
489 FormData form; | 470 FormData form; |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 form.fields.push_back(field); | 943 form.fields.push_back(field); |
963 | 944 |
964 // No autocomplete attribute. No metric logged. | 945 // No autocomplete attribute. No metric logged. |
965 test::CreateTestFormField("Address", "address", "", "text", &field); | 946 test::CreateTestFormField("Address", "address", "", "text", &field); |
966 field.autocomplete_attribute = ""; | 947 field.autocomplete_attribute = ""; |
967 form.fields.push_back(field); | 948 form.fields.push_back(field); |
968 | 949 |
969 std::unique_ptr<TestFormStructure> form_structure = | 950 std::unique_ptr<TestFormStructure> form_structure = |
970 base::MakeUnique<TestFormStructure>(form); | 951 base::MakeUnique<TestFormStructure>(form); |
971 TestFormStructure* form_structure_ptr = form_structure.get(); | 952 TestFormStructure* form_structure_ptr = form_structure.get(); |
972 form_structure->DetermineHeuristicTypes(nullptr /* ukm_service */); | 953 form_structure->DetermineHeuristicTypes(nullptr /* ukm_recorder */); |
973 autofill_manager_->form_structures()->push_back(std::move(form_structure)); | 954 autofill_manager_->form_structures()->push_back(std::move(form_structure)); |
974 | 955 |
975 AutofillQueryResponseContents response; | 956 AutofillQueryResponseContents response; |
976 // Server response will match with autocomplete. | 957 // Server response will match with autocomplete. |
977 response.add_field()->set_autofill_type(NAME_LAST); | 958 response.add_field()->set_autofill_type(NAME_LAST); |
978 // Server response will NOT match with autocomplete. | 959 // Server response will NOT match with autocomplete. |
979 response.add_field()->set_autofill_type(NAME_FIRST); | 960 response.add_field()->set_autofill_type(NAME_FIRST); |
980 // Server response will have no data. | 961 // Server response will have no data. |
981 response.add_field()->set_autofill_type(NO_SERVER_DATA); | 962 response.add_field()->set_autofill_type(NO_SERVER_DATA); |
982 // Not logged. | 963 // Not logged. |
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1760 histogram_tester.ExpectBucketCount( | 1741 histogram_tester.ExpectBucketCount( |
1761 "Autofill.DeveloperEngagement", | 1742 "Autofill.DeveloperEngagement", |
1762 AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT, 1); | 1743 AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT, 1); |
1763 } | 1744 } |
1764 } | 1745 } |
1765 | 1746 |
1766 // Verify that we correctly log UKM for form parsed without type hints regarding | 1747 // Verify that we correctly log UKM for form parsed without type hints regarding |
1767 // developer engagement. | 1748 // developer engagement. |
1768 TEST_F(AutofillMetricsTest, | 1749 TEST_F(AutofillMetricsTest, |
1769 UkmDeveloperEngagement_LogFillableFormParsedWithoutTypeHints) { | 1750 UkmDeveloperEngagement_LogFillableFormParsedWithoutTypeHints) { |
1770 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); | 1751 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder(); |
1771 | 1752 |
1772 // Start with a non-fillable form. | 1753 // Start with a non-fillable form. |
1773 FormData form; | 1754 FormData form; |
1774 form.name = ASCIIToUTF16("TestForm"); | 1755 form.name = ASCIIToUTF16("TestForm"); |
1775 form.origin = GURL("http://example.com/form.html"); | 1756 form.origin = GURL("http://example.com/form.html"); |
1776 form.action = GURL("http://example.com/submit.html"); | 1757 form.action = GURL("http://example.com/submit.html"); |
1777 | 1758 |
1778 FormFieldData field; | 1759 FormFieldData field; |
1779 test::CreateTestFormField("Name", "name", "", "text", &field); | 1760 test::CreateTestFormField("Name", "name", "", "text", &field); |
1780 form.fields.push_back(field); | 1761 form.fields.push_back(field); |
1781 test::CreateTestFormField("Email", "email", "", "text", &field); | 1762 test::CreateTestFormField("Email", "email", "", "text", &field); |
1782 form.fields.push_back(field); | 1763 form.fields.push_back(field); |
1783 | 1764 |
1784 std::vector<FormData> forms(1, form); | 1765 std::vector<FormData> forms(1, form); |
1785 | 1766 |
1786 // Ensure no metrics are logged when loading a non-fillable form. | 1767 // Ensure no metrics are logged when loading a non-fillable form. |
1787 { | 1768 { |
1788 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); | 1769 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); |
1789 autofill_manager_->Reset(); | 1770 autofill_manager_->Reset(); |
1790 | 1771 |
1791 EXPECT_EQ(0U, ukm_service->sources_count()); | 1772 EXPECT_EQ(0U, ukm_recorder->sources_count()); |
1792 EXPECT_EQ(0U, ukm_service->entries_count()); | 1773 EXPECT_EQ(0U, ukm_recorder->entries_count()); |
1793 } | 1774 } |
1794 | 1775 |
1795 // Add another field to the form, so that it becomes fillable. | 1776 // Add another field to the form, so that it becomes fillable. |
1796 test::CreateTestFormField("Phone", "phone", "", "text", &field); | 1777 test::CreateTestFormField("Phone", "phone", "", "text", &field); |
1797 forms.back().fields.push_back(field); | 1778 forms.back().fields.push_back(field); |
1798 | 1779 |
1799 // Expect the "form parsed without field type hints" metric and the | 1780 // Expect the "form parsed without field type hints" metric and the |
1800 // "form loaded" form interaction event to be logged. | 1781 // "form loaded" form interaction event to be logged. |
1801 { | 1782 { |
1802 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); | 1783 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); |
1803 autofill_manager_->Reset(); | 1784 autofill_manager_->Reset(); |
1804 | 1785 |
1805 ASSERT_EQ(1U, ukm_service->entries_count()); | 1786 ASSERT_EQ(1U, ukm_recorder->entries_count()); |
1806 ASSERT_EQ(1U, ukm_service->sources_count()); | 1787 ASSERT_EQ(1U, ukm_recorder->sources_count()); |
1807 VerifyDeveloperEngagementUkm( | 1788 VerifyDeveloperEngagementUkm( |
1808 form, ukm_service, | 1789 form, ukm_recorder, |
1809 {AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS}); | 1790 {AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS}); |
1810 } | 1791 } |
1811 } | 1792 } |
1812 | 1793 |
1813 // Verify that we correctly log UKM for form parsed with type hints regarding | 1794 // Verify that we correctly log UKM for form parsed with type hints regarding |
1814 // developer engagement. | 1795 // developer engagement. |
1815 TEST_F(AutofillMetricsTest, | 1796 TEST_F(AutofillMetricsTest, |
1816 UkmDeveloperEngagement_LogFillableFormParsedWithTypeHints) { | 1797 UkmDeveloperEngagement_LogFillableFormParsedWithTypeHints) { |
1817 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); | 1798 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder(); |
1818 | 1799 |
1819 FormData form; | 1800 FormData form; |
1820 form.name = ASCIIToUTF16("TestForm"); | 1801 form.name = ASCIIToUTF16("TestForm"); |
1821 form.origin = GURL("http://example.com/form.html"); | 1802 form.origin = GURL("http://example.com/form.html"); |
1822 form.action = GURL("http://example.com/submit.html"); | 1803 form.action = GURL("http://example.com/submit.html"); |
1823 | 1804 |
1824 FormFieldData field; | 1805 FormFieldData field; |
1825 test::CreateTestFormField("Name", "name", "", "text", &field); | 1806 test::CreateTestFormField("Name", "name", "", "text", &field); |
1826 form.fields.push_back(field); | 1807 form.fields.push_back(field); |
1827 test::CreateTestFormField("Email", "email", "", "text", &field); | 1808 test::CreateTestFormField("Email", "email", "", "text", &field); |
(...skipping 19 matching lines...) Expand all Loading... |
1847 test::CreateTestFormField("", "", "", "text", &field); | 1828 test::CreateTestFormField("", "", "", "text", &field); |
1848 field.autocomplete_attribute = "address-line1"; | 1829 field.autocomplete_attribute = "address-line1"; |
1849 forms.back().fields.push_back(field); | 1830 forms.back().fields.push_back(field); |
1850 | 1831 |
1851 // Expect the "form parsed without field type hints" metric and the | 1832 // Expect the "form parsed without field type hints" metric and the |
1852 // "form loaded" form interaction event to be logged. | 1833 // "form loaded" form interaction event to be logged. |
1853 { | 1834 { |
1854 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); | 1835 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); |
1855 autofill_manager_->Reset(); | 1836 autofill_manager_->Reset(); |
1856 | 1837 |
1857 ASSERT_EQ(1U, ukm_service->entries_count()); | 1838 ASSERT_EQ(1U, ukm_recorder->entries_count()); |
1858 ASSERT_EQ(1U, ukm_service->sources_count()); | 1839 ASSERT_EQ(1U, ukm_recorder->sources_count()); |
1859 VerifyDeveloperEngagementUkm( | 1840 VerifyDeveloperEngagementUkm( |
1860 form, ukm_service, | 1841 form, ukm_recorder, |
1861 {AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS}); | 1842 {AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS}); |
1862 } | 1843 } |
1863 } | 1844 } |
1864 | 1845 |
1865 // Verify that we correctly log UKM for form parsed with type hints regarding | 1846 // Verify that we correctly log UKM for form parsed with type hints regarding |
1866 // developer engagement. | 1847 // developer engagement. |
1867 TEST_F(AutofillMetricsTest, UkmDeveloperEngagement_LogUpiVpaTypeHint) { | 1848 TEST_F(AutofillMetricsTest, UkmDeveloperEngagement_LogUpiVpaTypeHint) { |
1868 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); | 1849 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder(); |
1869 | 1850 |
1870 FormData form; | 1851 FormData form; |
1871 form.name = ASCIIToUTF16("TestForm"); | 1852 form.name = ASCIIToUTF16("TestForm"); |
1872 form.origin = GURL("http://example.com/form.html"); | 1853 form.origin = GURL("http://example.com/form.html"); |
1873 form.action = GURL("http://example.com/submit.html"); | 1854 form.action = GURL("http://example.com/submit.html"); |
1874 | 1855 |
1875 FormFieldData field; | 1856 FormFieldData field; |
1876 test::CreateTestFormField("Name", "name", "", "text", &field); | 1857 test::CreateTestFormField("Name", "name", "", "text", &field); |
1877 form.fields.push_back(field); | 1858 form.fields.push_back(field); |
1878 test::CreateTestFormField("Email", "email", "", "text", &field); | 1859 test::CreateTestFormField("Email", "email", "", "text", &field); |
1879 form.fields.push_back(field); | 1860 form.fields.push_back(field); |
1880 test::CreateTestFormField("Payment", "payment", "", "text", &field); | 1861 test::CreateTestFormField("Payment", "payment", "", "text", &field); |
1881 field.autocomplete_attribute = "upi-vpa"; | 1862 field.autocomplete_attribute = "upi-vpa"; |
1882 form.fields.push_back(field); | 1863 form.fields.push_back(field); |
1883 | 1864 |
1884 std::vector<FormData> forms(1, form); | 1865 std::vector<FormData> forms(1, form); |
1885 | 1866 |
1886 // Expect the "upi-vpa hint" metric to be logged and the "form loaded" form | 1867 // Expect the "upi-vpa hint" metric to be logged and the "form loaded" form |
1887 // interaction event to be logged. | 1868 // interaction event to be logged. |
1888 { | 1869 { |
1889 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); | 1870 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); |
1890 autofill_manager_->Reset(); | 1871 autofill_manager_->Reset(); |
1891 | 1872 |
1892 ASSERT_EQ(1U, ukm_service->entries_count()); | 1873 ASSERT_EQ(1U, ukm_recorder->entries_count()); |
1893 ASSERT_EQ(1U, ukm_service->sources_count()); | 1874 ASSERT_EQ(1U, ukm_recorder->sources_count()); |
1894 VerifyDeveloperEngagementUkm(form, ukm_service, | 1875 VerifyDeveloperEngagementUkm(form, ukm_recorder, |
1895 {AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT}); | 1876 {AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT}); |
1896 ukm_service->Purge(); | 1877 ukm_recorder->Purge(); |
1897 } | 1878 } |
1898 | 1879 |
1899 // Add another field with an author-specified field type to the form. | 1880 // Add another field with an author-specified field type to the form. |
1900 test::CreateTestFormField("", "", "", "text", &field); | 1881 test::CreateTestFormField("", "", "", "text", &field); |
1901 field.autocomplete_attribute = "address-line1"; | 1882 field.autocomplete_attribute = "address-line1"; |
1902 forms.back().fields.push_back(field); | 1883 forms.back().fields.push_back(field); |
1903 | 1884 |
1904 { | 1885 { |
1905 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); | 1886 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); |
1906 autofill_manager_->Reset(); | 1887 autofill_manager_->Reset(); |
1907 | 1888 |
1908 VerifyDeveloperEngagementUkm( | 1889 VerifyDeveloperEngagementUkm( |
1909 form, ukm_service, | 1890 form, ukm_recorder, |
1910 {AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS, | 1891 {AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS, |
1911 AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT}); | 1892 AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT}); |
1912 } | 1893 } |
1913 } | 1894 } |
1914 | 1895 |
1915 // Test that the profile count is logged correctly. | 1896 // Test that the profile count is logged correctly. |
1916 TEST_F(AutofillMetricsTest, StoredProfileCount) { | 1897 TEST_F(AutofillMetricsTest, StoredProfileCount) { |
1917 // The metric should be logged when the profiles are first loaded. | 1898 // The metric should be logged when the profiles are first loaded. |
1918 { | 1899 { |
1919 base::HistogramTester histogram_tester; | 1900 base::HistogramTester histogram_tester; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2084 // Simulate activating the autofill popup for the email field after typing. | 2065 // Simulate activating the autofill popup for the email field after typing. |
2085 form.fields[0].is_autofilled = true; | 2066 form.fields[0].is_autofilled = true; |
2086 base::HistogramTester histogram_tester; | 2067 base::HistogramTester histogram_tester; |
2087 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 2068 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2088 histogram_tester.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0); | 2069 histogram_tester.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0); |
2089 } | 2070 } |
2090 } | 2071 } |
2091 | 2072 |
2092 // Test that the credit card checkout flow user actions are correctly logged. | 2073 // Test that the credit card checkout flow user actions are correctly logged. |
2093 TEST_F(AutofillMetricsTest, CreditCardCheckoutFlowUserActions) { | 2074 TEST_F(AutofillMetricsTest, CreditCardCheckoutFlowUserActions) { |
2094 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); | 2075 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder(); |
2095 | 2076 |
2096 personal_data_->RecreateCreditCards( | 2077 personal_data_->RecreateCreditCards( |
2097 true /* include_local_credit_card */, | 2078 true /* include_local_credit_card */, |
2098 false /* include_masked_server_credit_card */, | 2079 false /* include_masked_server_credit_card */, |
2099 false /* include_full_server_credit_card */); | 2080 false /* include_full_server_credit_card */); |
2100 | 2081 |
2101 // Set up our form data. | 2082 // Set up our form data. |
2102 FormData form; | 2083 FormData form; |
2103 form.name = ASCIIToUTF16("TestForm"); | 2084 form.name = ASCIIToUTF16("TestForm"); |
2104 form.origin = GURL("http://example.com/form.html"); | 2085 form.origin = GURL("http://example.com/form.html"); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2163 base::UserActionTester user_action_tester; | 2144 base::UserActionTester user_action_tester; |
2164 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 2145 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2165 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 2146 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2166 EXPECT_EQ(1, | 2147 EXPECT_EQ(1, |
2167 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); | 2148 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); |
2168 EXPECT_EQ(1, user_action_tester.GetActionCount( | 2149 EXPECT_EQ(1, user_action_tester.GetActionCount( |
2169 "Autofill_FormSubmitted_NonFillable")); | 2150 "Autofill_FormSubmitted_NonFillable")); |
2170 } | 2151 } |
2171 | 2152 |
2172 VerifyFormInteractionUkm( | 2153 VerifyFormInteractionUkm( |
2173 form, ukm_service, internal::kUKMSuggestionsShownEntryName, | 2154 form, ukm_recorder, internal::kUKMSuggestionsShownEntryName, |
2174 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); | 2155 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); |
2175 // Expect 2 |FORM_EVENT_LOCAL_SUGGESTION_FILLED| events. First, from | 2156 // Expect 2 |FORM_EVENT_LOCAL_SUGGESTION_FILLED| events. First, from |
2176 // call to |external_delegate_->DidAcceptSuggestion|. Second, from call to | 2157 // call to |external_delegate_->DidAcceptSuggestion|. Second, from call to |
2177 // |autofill_manager_->FillOrPreviewForm|. | 2158 // |autofill_manager_->FillOrPreviewForm|. |
2178 VerifyFormInteractionUkm( | 2159 VerifyFormInteractionUkm( |
2179 form, ukm_service, internal::kUKMSuggestionFilledEntryName, | 2160 form, ukm_recorder, internal::kUKMSuggestionFilledEntryName, |
2180 {{{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD}, | 2161 {{{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD}, |
2181 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, | 2162 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, |
2182 {{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD}, | 2163 {{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD}, |
2183 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); | 2164 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); |
2184 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState| | 2165 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState| |
2185 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|. | 2166 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|. |
2186 VerifySubmitFormUkm(form, ukm_service, | 2167 VerifySubmitFormUkm(form, ukm_recorder, |
2187 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); | 2168 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); |
2188 } | 2169 } |
2189 | 2170 |
2190 // Test that the profile checkout flow user actions are correctly logged. | 2171 // Test that the profile checkout flow user actions are correctly logged. |
2191 TEST_F(AutofillMetricsTest, ProfileCheckoutFlowUserActions) { | 2172 TEST_F(AutofillMetricsTest, ProfileCheckoutFlowUserActions) { |
2192 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); | 2173 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder(); |
2193 | 2174 |
2194 // Create a profile. | 2175 // Create a profile. |
2195 personal_data_->RecreateProfile(); | 2176 personal_data_->RecreateProfile(); |
2196 | 2177 |
2197 // Set up our form data. | 2178 // Set up our form data. |
2198 FormData form; | 2179 FormData form; |
2199 form.name = ASCIIToUTF16("TestForm"); | 2180 form.name = ASCIIToUTF16("TestForm"); |
2200 form.origin = GURL("http://example.com/form.html"); | 2181 form.origin = GURL("http://example.com/form.html"); |
2201 form.action = GURL("http://example.com/submit.html"); | 2182 form.action = GURL("http://example.com/submit.html"); |
2202 | 2183 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2259 base::UserActionTester user_action_tester; | 2240 base::UserActionTester user_action_tester; |
2260 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 2241 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2261 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 2242 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2262 EXPECT_EQ(1, | 2243 EXPECT_EQ(1, |
2263 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); | 2244 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); |
2264 EXPECT_EQ(1, user_action_tester.GetActionCount( | 2245 EXPECT_EQ(1, user_action_tester.GetActionCount( |
2265 "Autofill_FormSubmitted_NonFillable")); | 2246 "Autofill_FormSubmitted_NonFillable")); |
2266 } | 2247 } |
2267 | 2248 |
2268 VerifyFormInteractionUkm( | 2249 VerifyFormInteractionUkm( |
2269 form, ukm_service, internal::kUKMSuggestionsShownEntryName, | 2250 form, ukm_recorder, internal::kUKMSuggestionsShownEntryName, |
2270 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); | 2251 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); |
2271 // Expect 2 |FORM_EVENT_LOCAL_SUGGESTION_FILLED| events. First, from | 2252 // Expect 2 |FORM_EVENT_LOCAL_SUGGESTION_FILLED| events. First, from |
2272 // call to |external_delegate_->DidAcceptSuggestion|. Second, from call to | 2253 // call to |external_delegate_->DidAcceptSuggestion|. Second, from call to |
2273 // |autofill_manager_->FillOrPreviewForm|. | 2254 // |autofill_manager_->FillOrPreviewForm|. |
2274 VerifyFormInteractionUkm( | 2255 VerifyFormInteractionUkm( |
2275 form, ukm_service, internal::kUKMSuggestionFilledEntryName, | 2256 form, ukm_recorder, internal::kUKMSuggestionFilledEntryName, |
2276 {{{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE}, | 2257 {{{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE}, |
2277 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, | 2258 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, |
2278 {{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE}, | 2259 {{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE}, |
2279 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); | 2260 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); |
2280 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState| | 2261 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState| |
2281 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|. | 2262 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|. |
2282 VerifySubmitFormUkm(form, ukm_service, | 2263 VerifySubmitFormUkm(form, ukm_recorder, |
2283 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); | 2264 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); |
2284 } | 2265 } |
2285 | 2266 |
2286 // Tests that the Autofill_PolledCreditCardSuggestions user action is only | 2267 // Tests that the Autofill_PolledCreditCardSuggestions user action is only |
2287 // logged once if the field is queried repeatedly. | 2268 // logged once if the field is queried repeatedly. |
2288 TEST_F(AutofillMetricsTest, PolledCreditCardSuggestions_DebounceLogs) { | 2269 TEST_F(AutofillMetricsTest, PolledCreditCardSuggestions_DebounceLogs) { |
2289 personal_data_->RecreateCreditCards( | 2270 personal_data_->RecreateCreditCards( |
2290 true /* include_local_credit_card */, | 2271 true /* include_local_credit_card */, |
2291 false /* include_masked_server_credit_card */, | 2272 false /* include_masked_server_credit_card */, |
2292 false /* include_full_server_credit_card */); | 2273 false /* include_full_server_credit_card */); |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2829 std::string()); | 2810 std::string()); |
2830 histogram_tester.ExpectTotalCount( | 2811 histogram_tester.ExpectTotalCount( |
2831 "Autofill.UnmaskPrompt.GetRealPanDuration", 1); | 2812 "Autofill.UnmaskPrompt.GetRealPanDuration", 1); |
2832 histogram_tester.ExpectTotalCount( | 2813 histogram_tester.ExpectTotalCount( |
2833 "Autofill.UnmaskPrompt.GetRealPanDuration.Failure", 1); | 2814 "Autofill.UnmaskPrompt.GetRealPanDuration.Failure", 1); |
2834 } | 2815 } |
2835 } | 2816 } |
2836 | 2817 |
2837 // Test that we log submitted form events for credit cards. | 2818 // Test that we log submitted form events for credit cards. |
2838 TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) { | 2819 TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) { |
2839 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); | 2820 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder(); |
2840 | 2821 |
2841 EnableWalletSync(); | 2822 EnableWalletSync(); |
2842 // Creating all kinds of cards. | 2823 // Creating all kinds of cards. |
2843 personal_data_->RecreateCreditCards( | 2824 personal_data_->RecreateCreditCards( |
2844 true /* include_local_credit_card */, | 2825 true /* include_local_credit_card */, |
2845 true /* include_masked_server_credit_card */, | 2826 true /* include_masked_server_credit_card */, |
2846 true /* include_full_server_credit_card */); | 2827 true /* include_full_server_credit_card */); |
2847 // Set up our form data. | 2828 // Set up our form data. |
2848 FormData form; | 2829 FormData form; |
2849 form.name = ASCIIToUTF16("TestForm"); | 2830 form.name = ASCIIToUTF16("TestForm"); |
(...skipping 21 matching lines...) Expand all Loading... |
2871 base::HistogramTester histogram_tester; | 2852 base::HistogramTester histogram_tester; |
2872 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 2853 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2873 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 2854 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2874 histogram_tester.ExpectBucketCount( | 2855 histogram_tester.ExpectBucketCount( |
2875 "Autofill.FormEvents.CreditCard", | 2856 "Autofill.FormEvents.CreditCard", |
2876 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); | 2857 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); |
2877 histogram_tester.ExpectBucketCount( | 2858 histogram_tester.ExpectBucketCount( |
2878 "Autofill.FormEvents.CreditCard", | 2859 "Autofill.FormEvents.CreditCard", |
2879 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); | 2860 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); |
2880 | 2861 |
2881 VerifySubmitFormUkm(form, ukm_service, | 2862 VerifySubmitFormUkm(form, ukm_recorder, |
2882 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); | 2863 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); |
2883 } | 2864 } |
2884 | 2865 |
2885 // Reset the autofill manager state and purge UKM logs. | 2866 // Reset the autofill manager state and purge UKM logs. |
2886 autofill_manager_->Reset(); | 2867 autofill_manager_->Reset(); |
2887 ukm_service->Purge(); | 2868 ukm_recorder->Purge(); |
2888 | 2869 |
2889 autofill_manager_->AddSeenForm(form, field_types, field_types); | 2870 autofill_manager_->AddSeenForm(form, field_types, field_types); |
2890 | 2871 |
2891 { | 2872 { |
2892 // Simulating submission with suggestion shown. | 2873 // Simulating submission with suggestion shown. |
2893 base::HistogramTester histogram_tester; | 2874 base::HistogramTester histogram_tester; |
2894 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); | 2875 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); |
2895 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 2876 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2896 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 2877 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2897 histogram_tester.ExpectBucketCount( | 2878 histogram_tester.ExpectBucketCount( |
2898 "Autofill.FormEvents.CreditCard", | 2879 "Autofill.FormEvents.CreditCard", |
2899 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_SUBMITTED_ONCE, 1); | 2880 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_SUBMITTED_ONCE, 1); |
2900 histogram_tester.ExpectBucketCount( | 2881 histogram_tester.ExpectBucketCount( |
2901 "Autofill.FormEvents.CreditCard", | 2882 "Autofill.FormEvents.CreditCard", |
2902 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 1); | 2883 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 1); |
2903 | 2884 |
2904 VerifyFormInteractionUkm( | 2885 VerifyFormInteractionUkm( |
2905 form, ukm_service, internal::kUKMSuggestionsShownEntryName, | 2886 form, ukm_recorder, internal::kUKMSuggestionsShownEntryName, |
2906 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); | 2887 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); |
2907 VerifySubmitFormUkm(form, ukm_service, | 2888 VerifySubmitFormUkm(form, ukm_recorder, |
2908 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); | 2889 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); |
2909 } | 2890 } |
2910 | 2891 |
2911 // Reset the autofill manager state and purge UKM logs. | 2892 // Reset the autofill manager state and purge UKM logs. |
2912 autofill_manager_->Reset(); | 2893 autofill_manager_->Reset(); |
2913 ukm_service->Purge(); | 2894 ukm_recorder->Purge(); |
2914 | 2895 |
2915 autofill_manager_->AddSeenForm(form, field_types, field_types); | 2896 autofill_manager_->AddSeenForm(form, field_types, field_types); |
2916 | 2897 |
2917 { | 2898 { |
2918 // Simulating submission with filled local data. | 2899 // Simulating submission with filled local data. |
2919 base::HistogramTester histogram_tester; | 2900 base::HistogramTester histogram_tester; |
2920 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 2901 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2921 std::string guid("10000000-0000-0000-0000-000000000001"); // local card | 2902 std::string guid("10000000-0000-0000-0000-000000000001"); // local card |
2922 autofill_manager_->FillOrPreviewForm( | 2903 autofill_manager_->FillOrPreviewForm( |
2923 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), | 2904 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), |
2924 autofill_manager_->MakeFrontendID(guid, std::string())); | 2905 autofill_manager_->MakeFrontendID(guid, std::string())); |
2925 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 2906 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2926 histogram_tester.ExpectBucketCount( | 2907 histogram_tester.ExpectBucketCount( |
2927 "Autofill.FormEvents.CreditCard", | 2908 "Autofill.FormEvents.CreditCard", |
2928 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 1); | 2909 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 1); |
2929 histogram_tester.ExpectBucketCount( | 2910 histogram_tester.ExpectBucketCount( |
2930 "Autofill.FormEvents.CreditCard", | 2911 "Autofill.FormEvents.CreditCard", |
2931 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 1); | 2912 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 1); |
2932 | 2913 |
2933 VerifyFormInteractionUkm( | 2914 VerifyFormInteractionUkm( |
2934 form, ukm_service, internal::kUKMSuggestionFilledEntryName, | 2915 form, ukm_recorder, internal::kUKMSuggestionFilledEntryName, |
2935 {{{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD}, | 2916 {{{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD}, |
2936 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); | 2917 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); |
2937 VerifySubmitFormUkm(form, ukm_service, | 2918 VerifySubmitFormUkm(form, ukm_recorder, |
2938 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); | 2919 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); |
2939 } | 2920 } |
2940 | 2921 |
2941 // Reset the autofill manager state and purge UKM logs. | 2922 // Reset the autofill manager state and purge UKM logs. |
2942 autofill_manager_->Reset(); | 2923 autofill_manager_->Reset(); |
2943 ukm_service->Purge(); | 2924 ukm_recorder->Purge(); |
2944 | 2925 |
2945 autofill_manager_->AddSeenForm(form, field_types, field_types); | 2926 autofill_manager_->AddSeenForm(form, field_types, field_types); |
2946 | 2927 |
2947 { | 2928 { |
2948 // Simulating submission with filled server data. | 2929 // Simulating submission with filled server data. |
2949 base::HistogramTester histogram_tester; | 2930 base::HistogramTester histogram_tester; |
2950 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 2931 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2951 std::string guid( | 2932 std::string guid( |
2952 "10000000-0000-0000-0000-000000000003"); // full server card | 2933 "10000000-0000-0000-0000-000000000003"); // full server card |
2953 autofill_manager_->FillOrPreviewForm( | 2934 autofill_manager_->FillOrPreviewForm( |
2954 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), | 2935 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), |
2955 autofill_manager_->MakeFrontendID(guid, std::string())); | 2936 autofill_manager_->MakeFrontendID(guid, std::string())); |
2956 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 2937 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2957 histogram_tester.ExpectBucketCount( | 2938 histogram_tester.ExpectBucketCount( |
2958 "Autofill.FormEvents.CreditCard", | 2939 "Autofill.FormEvents.CreditCard", |
2959 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 1); | 2940 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 1); |
2960 histogram_tester.ExpectBucketCount( | 2941 histogram_tester.ExpectBucketCount( |
2961 "Autofill.FormEvents.CreditCard", | 2942 "Autofill.FormEvents.CreditCard", |
2962 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 1); | 2943 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 1); |
2963 | 2944 |
2964 VerifyFormInteractionUkm( | 2945 VerifyFormInteractionUkm( |
2965 form, ukm_service, internal::kUKMSuggestionFilledEntryName, | 2946 form, ukm_recorder, internal::kUKMSuggestionFilledEntryName, |
2966 {{{internal::kUKMRecordTypeMetricName, CreditCard::FULL_SERVER_CARD}, | 2947 {{{internal::kUKMRecordTypeMetricName, CreditCard::FULL_SERVER_CARD}, |
2967 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); | 2948 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); |
2968 VerifySubmitFormUkm(form, ukm_service, | 2949 VerifySubmitFormUkm(form, ukm_recorder, |
2969 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); | 2950 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); |
2970 } | 2951 } |
2971 | 2952 |
2972 // Reset the autofill manager state and purge UKM logs. | 2953 // Reset the autofill manager state and purge UKM logs. |
2973 autofill_manager_->Reset(); | 2954 autofill_manager_->Reset(); |
2974 ukm_service->Purge(); | 2955 ukm_recorder->Purge(); |
2975 | 2956 |
2976 autofill_manager_->AddSeenForm(form, field_types, field_types); | 2957 autofill_manager_->AddSeenForm(form, field_types, field_types); |
2977 | 2958 |
2978 { | 2959 { |
2979 // Simulating submission with a masked card server suggestion. | 2960 // Simulating submission with a masked card server suggestion. |
2980 base::HistogramTester histogram_tester; | 2961 base::HistogramTester histogram_tester; |
2981 std::string guid( | 2962 std::string guid( |
2982 "10000000-0000-0000-0000-000000000002"); // masked server card | 2963 "10000000-0000-0000-0000-000000000002"); // masked server card |
2983 autofill_manager_->FillOrPreviewForm( | 2964 autofill_manager_->FillOrPreviewForm( |
2984 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.back(), | 2965 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.back(), |
2985 autofill_manager_->MakeFrontendID(guid, std::string())); | 2966 autofill_manager_->MakeFrontendID(guid, std::string())); |
2986 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS, | 2967 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS, |
2987 "6011000990139424"); | 2968 "6011000990139424"); |
2988 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 2969 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2989 histogram_tester.ExpectBucketCount( | 2970 histogram_tester.ExpectBucketCount( |
2990 "Autofill.FormEvents.CreditCard", | 2971 "Autofill.FormEvents.CreditCard", |
2991 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED, 1); | 2972 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED, 1); |
2992 histogram_tester.ExpectBucketCount( | 2973 histogram_tester.ExpectBucketCount( |
2993 "Autofill.FormEvents.CreditCard", | 2974 "Autofill.FormEvents.CreditCard", |
2994 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE, | 2975 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE, |
2995 1); | 2976 1); |
2996 | 2977 |
2997 VerifyFormInteractionUkm( | 2978 VerifyFormInteractionUkm( |
2998 form, ukm_service, internal::kUKMSuggestionFilledEntryName, | 2979 form, ukm_recorder, internal::kUKMSuggestionFilledEntryName, |
2999 {{{internal::kUKMRecordTypeMetricName, CreditCard::MASKED_SERVER_CARD}, | 2980 {{{internal::kUKMRecordTypeMetricName, CreditCard::MASKED_SERVER_CARD}, |
3000 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); | 2981 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); |
3001 VerifyFormInteractionUkm( | 2982 VerifyFormInteractionUkm( |
3002 form, ukm_service, internal::kUKMSelectedMaskedServerCardEntryName, | 2983 form, ukm_recorder, internal::kUKMSelectedMaskedServerCardEntryName, |
3003 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); | 2984 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); |
3004 VerifySubmitFormUkm(form, ukm_service, | 2985 VerifySubmitFormUkm(form, ukm_recorder, |
3005 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); | 2986 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); |
3006 } | 2987 } |
3007 | 2988 |
3008 // Reset the autofill manager state and purge UKM logs. | 2989 // Reset the autofill manager state and purge UKM logs. |
3009 autofill_manager_->Reset(); | 2990 autofill_manager_->Reset(); |
3010 ukm_service->Purge(); | 2991 ukm_recorder->Purge(); |
3011 | 2992 |
3012 // Recreating cards as the previous test should have upgraded the masked | 2993 // Recreating cards as the previous test should have upgraded the masked |
3013 // card to a full card. | 2994 // card to a full card. |
3014 personal_data_->RecreateCreditCards( | 2995 personal_data_->RecreateCreditCards( |
3015 true /* include_local_credit_card */, | 2996 true /* include_local_credit_card */, |
3016 true /* include_masked_server_credit_card */, | 2997 true /* include_masked_server_credit_card */, |
3017 true /* include_full_server_credit_card */); | 2998 true /* include_full_server_credit_card */); |
3018 | 2999 |
3019 // Reset the autofill manager state. | 3000 // Reset the autofill manager state. |
3020 autofill_manager_->Reset(); | 3001 autofill_manager_->Reset(); |
3021 autofill_manager_->AddSeenForm(form, field_types, field_types); | 3002 autofill_manager_->AddSeenForm(form, field_types, field_types); |
3022 | 3003 |
3023 { | 3004 { |
3024 // Simulating multiple submissions. | 3005 // Simulating multiple submissions. |
3025 base::HistogramTester histogram_tester; | 3006 base::HistogramTester histogram_tester; |
3026 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 3007 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
3027 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 3008 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
3028 | 3009 |
3029 VerifyFormInteractionUkm( | 3010 VerifyFormInteractionUkm( |
3030 form, ukm_service, internal::kUKMFormSubmittedEntryName, | 3011 form, ukm_recorder, internal::kUKMFormSubmittedEntryName, |
3031 {{{internal::kUKMAutofillFormSubmittedStateMetricName, | 3012 {{{internal::kUKMAutofillFormSubmittedStateMetricName, |
3032 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, | 3013 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, |
3033 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); | 3014 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); |
3034 | 3015 |
3035 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 3016 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
3036 | 3017 |
3037 VerifyFormInteractionUkm( | 3018 VerifyFormInteractionUkm( |
3038 form, ukm_service, internal::kUKMFormSubmittedEntryName, | 3019 form, ukm_recorder, internal::kUKMFormSubmittedEntryName, |
3039 {{{internal::kUKMAutofillFormSubmittedStateMetricName, | 3020 {{{internal::kUKMAutofillFormSubmittedStateMetricName, |
3040 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, | 3021 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, |
3041 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, | 3022 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, |
3042 {{internal::kUKMAutofillFormSubmittedStateMetricName, | 3023 {{internal::kUKMAutofillFormSubmittedStateMetricName, |
3043 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, | 3024 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, |
3044 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); | 3025 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); |
3045 | 3026 |
3046 histogram_tester.ExpectBucketCount( | 3027 histogram_tester.ExpectBucketCount( |
3047 "Autofill.FormEvents.CreditCard", | 3028 "Autofill.FormEvents.CreditCard", |
3048 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); | 3029 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); |
(...skipping 25 matching lines...) Expand all Loading... |
3074 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0); | 3055 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0); |
3075 histogram_tester.ExpectBucketCount( | 3056 histogram_tester.ExpectBucketCount( |
3076 "Autofill.FormEvents.CreditCard", | 3057 "Autofill.FormEvents.CreditCard", |
3077 AutofillMetrics:: | 3058 AutofillMetrics:: |
3078 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SUBMITTED_ONCE, | 3059 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SUBMITTED_ONCE, |
3079 0); | 3060 0); |
3080 } | 3061 } |
3081 | 3062 |
3082 // Reset the autofill manager state and purge UKM logs. | 3063 // Reset the autofill manager state and purge UKM logs. |
3083 autofill_manager_->Reset(); | 3064 autofill_manager_->Reset(); |
3084 ukm_service->Purge(); | 3065 ukm_recorder->Purge(); |
3085 | 3066 |
3086 autofill_manager_->AddSeenForm(form, field_types, field_types); | 3067 autofill_manager_->AddSeenForm(form, field_types, field_types); |
3087 | 3068 |
3088 { | 3069 { |
3089 // Simulating submission with suggestion shown but without previous | 3070 // Simulating submission with suggestion shown but without previous |
3090 // interaction. | 3071 // interaction. |
3091 base::HistogramTester histogram_tester; | 3072 base::HistogramTester histogram_tester; |
3092 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); | 3073 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); |
3093 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 3074 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
3094 histogram_tester.ExpectBucketCount( | 3075 histogram_tester.ExpectBucketCount( |
(...skipping 25 matching lines...) Expand all Loading... |
3120 histogram_tester.ExpectBucketCount( | 3101 histogram_tester.ExpectBucketCount( |
3121 "Autofill.FormEvents.CreditCard", | 3102 "Autofill.FormEvents.CreditCard", |
3122 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0); | 3103 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0); |
3123 histogram_tester.ExpectBucketCount( | 3104 histogram_tester.ExpectBucketCount( |
3124 "Autofill.FormEvents.CreditCard", | 3105 "Autofill.FormEvents.CreditCard", |
3125 AutofillMetrics:: | 3106 AutofillMetrics:: |
3126 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE, | 3107 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE, |
3127 0); | 3108 0); |
3128 | 3109 |
3129 VerifyFormInteractionUkm( | 3110 VerifyFormInteractionUkm( |
3130 form, ukm_service, internal::kUKMSuggestionsShownEntryName, | 3111 form, ukm_recorder, internal::kUKMSuggestionsShownEntryName, |
3131 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); | 3112 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); |
3132 VerifySubmitFormUkm(form, ukm_service, | 3113 VerifySubmitFormUkm(form, ukm_recorder, |
3133 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); | 3114 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); |
3134 } | 3115 } |
3135 } | 3116 } |
3136 | 3117 |
3137 // Test that we log "will submit" (but not submitted) form events for credit | 3118 // Test that we log "will submit" (but not submitted) form events for credit |
3138 // cards. Mirrors CreditCardSubmittedFormEvents test but does not expect any | 3119 // cards. Mirrors CreditCardSubmittedFormEvents test but does not expect any |
3139 // "submitted" metrics. | 3120 // "submitted" metrics. |
3140 TEST_F(AutofillMetricsTest, CreditCardWillSubmitFormEvents) { | 3121 TEST_F(AutofillMetricsTest, CreditCardWillSubmitFormEvents) { |
3141 EnableWalletSync(); | 3122 EnableWalletSync(); |
3142 // Creating all kinds of cards. | 3123 // Creating all kinds of cards. |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3545 "Autofill.FormEvents.Address", | 3526 "Autofill.FormEvents.Address", |
3546 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED, 2); | 3527 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED, 2); |
3547 histogram_tester.ExpectBucketCount( | 3528 histogram_tester.ExpectBucketCount( |
3548 "Autofill.FormEvents.Address", | 3529 "Autofill.FormEvents.Address", |
3549 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE, 1); | 3530 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE, 1); |
3550 } | 3531 } |
3551 } | 3532 } |
3552 | 3533 |
3553 // Test that we log submitted form events for address. | 3534 // Test that we log submitted form events for address. |
3554 TEST_F(AutofillMetricsTest, AddressSubmittedFormEvents) { | 3535 TEST_F(AutofillMetricsTest, AddressSubmittedFormEvents) { |
3555 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); | 3536 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder(); |
3556 | 3537 |
3557 EnableWalletSync(); | 3538 EnableWalletSync(); |
3558 // Create a profile. | 3539 // Create a profile. |
3559 personal_data_->RecreateProfile(); | 3540 personal_data_->RecreateProfile(); |
3560 // Set up our form data. | 3541 // Set up our form data. |
3561 FormData form; | 3542 FormData form; |
3562 form.name = ASCIIToUTF16("TestForm"); | 3543 form.name = ASCIIToUTF16("TestForm"); |
3563 form.origin = GURL("http://example.com/form.html"); | 3544 form.origin = GURL("http://example.com/form.html"); |
3564 form.action = GURL("http://example.com/submit.html"); | 3545 form.action = GURL("http://example.com/submit.html"); |
3565 | 3546 |
(...skipping 18 matching lines...) Expand all Loading... |
3584 base::HistogramTester histogram_tester; | 3565 base::HistogramTester histogram_tester; |
3585 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 3566 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
3586 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 3567 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
3587 histogram_tester.ExpectBucketCount( | 3568 histogram_tester.ExpectBucketCount( |
3588 "Autofill.FormEvents.Address", | 3569 "Autofill.FormEvents.Address", |
3589 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); | 3570 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); |
3590 histogram_tester.ExpectBucketCount( | 3571 histogram_tester.ExpectBucketCount( |
3591 "Autofill.FormEvents.Address", | 3572 "Autofill.FormEvents.Address", |
3592 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); | 3573 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); |
3593 | 3574 |
3594 VerifySubmitFormUkm(form, ukm_service, | 3575 VerifySubmitFormUkm(form, ukm_recorder, |
3595 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); | 3576 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); |
3596 } | 3577 } |
3597 | 3578 |
3598 // Reset the autofill manager state and purge UKM logs. | 3579 // Reset the autofill manager state and purge UKM logs. |
3599 autofill_manager_->Reset(); | 3580 autofill_manager_->Reset(); |
3600 ukm_service->Purge(); | 3581 ukm_recorder->Purge(); |
3601 | 3582 |
3602 autofill_manager_->AddSeenForm(form, field_types, field_types); | 3583 autofill_manager_->AddSeenForm(form, field_types, field_types); |
3603 | 3584 |
3604 { | 3585 { |
3605 // Simulating submission with suggestion shown. | 3586 // Simulating submission with suggestion shown. |
3606 base::HistogramTester histogram_tester; | 3587 base::HistogramTester histogram_tester; |
3607 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); | 3588 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); |
3608 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 3589 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
3609 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 3590 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
3610 histogram_tester.ExpectBucketCount( | 3591 histogram_tester.ExpectBucketCount( |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4085 base::HistogramTester histogram_tester; | 4066 base::HistogramTester histogram_tester; |
4086 AutofillProfile profile; | 4067 AutofillProfile profile; |
4087 profile.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(13)); | 4068 profile.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(13)); |
4088 profile.RecordAndLogUse(); | 4069 profile.RecordAndLogUse(); |
4089 histogram_tester.ExpectBucketCount("Autofill.DaysSinceLastUse.Profile", 13, | 4070 histogram_tester.ExpectBucketCount("Autofill.DaysSinceLastUse.Profile", 13, |
4090 1); | 4071 1); |
4091 } | 4072 } |
4092 | 4073 |
4093 // Verify that we correctly log the submitted form's state. | 4074 // Verify that we correctly log the submitted form's state. |
4094 TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) { | 4075 TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) { |
4095 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); | 4076 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder(); |
4096 | 4077 |
4097 // Start with a form with insufficiently many fields. | 4078 // Start with a form with insufficiently many fields. |
4098 FormData form; | 4079 FormData form; |
4099 form.name = ASCIIToUTF16("TestForm"); | 4080 form.name = ASCIIToUTF16("TestForm"); |
4100 form.origin = GURL("http://example.com/form.html"); | 4081 form.origin = GURL("http://example.com/form.html"); |
4101 form.action = GURL("http://example.com/submit.html"); | 4082 form.action = GURL("http://example.com/submit.html"); |
4102 | 4083 |
4103 FormFieldData field; | 4084 FormFieldData field; |
4104 test::CreateTestFormField("Name", "name", "", "text", &field); | 4085 test::CreateTestFormField("Name", "name", "", "text", &field); |
4105 form.fields.push_back(field); | 4086 form.fields.push_back(field); |
(...skipping 24 matching lines...) Expand all Loading... |
4130 base::UserActionTester user_action_tester; | 4111 base::UserActionTester user_action_tester; |
4131 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 4112 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
4132 histogram_tester.ExpectUniqueSample( | 4113 histogram_tester.ExpectUniqueSample( |
4133 "Autofill.FormSubmittedState", | 4114 "Autofill.FormSubmittedState", |
4134 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); | 4115 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); |
4135 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4116 EXPECT_EQ(1, user_action_tester.GetActionCount( |
4136 "Autofill_FormSubmitted_NonFillable")); | 4117 "Autofill_FormSubmitted_NonFillable")); |
4137 | 4118 |
4138 // Expect an entry for |DeveloperEngagement| and an entry for form | 4119 // Expect an entry for |DeveloperEngagement| and an entry for form |
4139 // interactions. Both entries are for the same URL. | 4120 // interactions. Both entries are for the same URL. |
4140 ASSERT_EQ(2U, ukm_service->entries_count()); | 4121 ASSERT_EQ(2U, ukm_recorder->entries_count()); |
4141 ASSERT_EQ(2U, ukm_service->sources_count()); | 4122 ASSERT_EQ(2U, ukm_recorder->sources_count()); |
4142 VerifyDeveloperEngagementUkm( | 4123 VerifyDeveloperEngagementUkm( |
4143 form, ukm_service, | 4124 form, ukm_recorder, |
4144 {AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS}); | 4125 {AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS}); |
4145 VerifyFormInteractionUkm(form, ukm_service, | 4126 VerifyFormInteractionUkm(form, ukm_recorder, |
4146 internal::kUKMFormSubmittedEntryName, | 4127 internal::kUKMFormSubmittedEntryName, |
4147 expected_form_submission_ukm_metrics); | 4128 expected_form_submission_ukm_metrics); |
4148 } | 4129 } |
4149 | 4130 |
4150 // Non fillable form. | 4131 // Non fillable form. |
4151 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley"); | 4132 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley"); |
4152 form.fields[1].value = ASCIIToUTF16("theking@gmail.com"); | 4133 form.fields[1].value = ASCIIToUTF16("theking@gmail.com"); |
4153 forms.front() = form; | 4134 forms.front() = form; |
4154 | 4135 |
4155 { | 4136 { |
4156 base::HistogramTester histogram_tester; | 4137 base::HistogramTester histogram_tester; |
4157 base::UserActionTester user_action_tester; | 4138 base::UserActionTester user_action_tester; |
4158 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 4139 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
4159 histogram_tester.ExpectUniqueSample( | 4140 histogram_tester.ExpectUniqueSample( |
4160 "Autofill.FormSubmittedState", | 4141 "Autofill.FormSubmittedState", |
4161 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); | 4142 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); |
4162 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4143 EXPECT_EQ(1, user_action_tester.GetActionCount( |
4163 "Autofill_FormSubmitted_NonFillable")); | 4144 "Autofill_FormSubmitted_NonFillable")); |
4164 | 4145 |
4165 expected_form_submission_ukm_metrics.push_back( | 4146 expected_form_submission_ukm_metrics.push_back( |
4166 {{internal::kUKMAutofillFormSubmittedStateMetricName, | 4147 {{internal::kUKMAutofillFormSubmittedStateMetricName, |
4167 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, | 4148 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, |
4168 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); | 4149 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); |
4169 VerifyFormInteractionUkm(form, ukm_service, | 4150 VerifyFormInteractionUkm(form, ukm_recorder, |
4170 internal::kUKMFormSubmittedEntryName, | 4151 internal::kUKMFormSubmittedEntryName, |
4171 expected_form_submission_ukm_metrics); | 4152 expected_form_submission_ukm_metrics); |
4172 } | 4153 } |
4173 | 4154 |
4174 // Fill in the third field. | 4155 // Fill in the third field. |
4175 form.fields[2].value = ASCIIToUTF16("12345678901"); | 4156 form.fields[2].value = ASCIIToUTF16("12345678901"); |
4176 forms.front() = form; | 4157 forms.front() = form; |
4177 | 4158 |
4178 // Autofilled none with no suggestions shown. | 4159 // Autofilled none with no suggestions shown. |
4179 { | 4160 { |
4180 base::HistogramTester histogram_tester; | 4161 base::HistogramTester histogram_tester; |
4181 base::UserActionTester user_action_tester; | 4162 base::UserActionTester user_action_tester; |
4182 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 4163 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
4183 histogram_tester.ExpectUniqueSample( | 4164 histogram_tester.ExpectUniqueSample( |
4184 "Autofill.FormSubmittedState", | 4165 "Autofill.FormSubmittedState", |
4185 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS, | 4166 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS, |
4186 1); | 4167 1); |
4187 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4168 EXPECT_EQ(1, user_action_tester.GetActionCount( |
4188 "Autofill_FormSubmitted_FilledNone_SuggestionsNotShown")); | 4169 "Autofill_FormSubmitted_FilledNone_SuggestionsNotShown")); |
4189 | 4170 |
4190 expected_form_submission_ukm_metrics.push_back( | 4171 expected_form_submission_ukm_metrics.push_back( |
4191 {{internal::kUKMAutofillFormSubmittedStateMetricName, | 4172 {{internal::kUKMAutofillFormSubmittedStateMetricName, |
4192 AutofillMetrics:: | 4173 AutofillMetrics:: |
4193 FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS}, | 4174 FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS}, |
4194 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); | 4175 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); |
4195 VerifyFormInteractionUkm(form, ukm_service, | 4176 VerifyFormInteractionUkm(form, ukm_recorder, |
4196 internal::kUKMFormSubmittedEntryName, | 4177 internal::kUKMFormSubmittedEntryName, |
4197 expected_form_submission_ukm_metrics); | 4178 expected_form_submission_ukm_metrics); |
4198 } | 4179 } |
4199 | 4180 |
4200 // Autofilled none with suggestions shown. | 4181 // Autofilled none with suggestions shown. |
4201 autofill_manager_->DidShowSuggestions(true, form, form.fields[2]); | 4182 autofill_manager_->DidShowSuggestions(true, form, form.fields[2]); |
4202 { | 4183 { |
4203 base::HistogramTester histogram_tester; | 4184 base::HistogramTester histogram_tester; |
4204 base::UserActionTester user_action_tester; | 4185 base::UserActionTester user_action_tester; |
4205 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 4186 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
4206 histogram_tester.ExpectUniqueSample( | 4187 histogram_tester.ExpectUniqueSample( |
4207 "Autofill.FormSubmittedState", | 4188 "Autofill.FormSubmittedState", |
4208 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS, 1); | 4189 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS, 1); |
4209 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4190 EXPECT_EQ(1, user_action_tester.GetActionCount( |
4210 "Autofill_FormSubmitted_FilledNone_SuggestionsShown")); | 4191 "Autofill_FormSubmitted_FilledNone_SuggestionsShown")); |
4211 | 4192 |
4212 VerifyFormInteractionUkm( | 4193 VerifyFormInteractionUkm( |
4213 form, ukm_service, internal::kUKMSuggestionsShownEntryName, | 4194 form, ukm_recorder, internal::kUKMSuggestionsShownEntryName, |
4214 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); | 4195 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); |
4215 expected_form_submission_ukm_metrics.push_back( | 4196 expected_form_submission_ukm_metrics.push_back( |
4216 {{internal::kUKMAutofillFormSubmittedStateMetricName, | 4197 {{internal::kUKMAutofillFormSubmittedStateMetricName, |
4217 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS}, | 4198 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS}, |
4218 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); | 4199 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); |
4219 VerifyFormInteractionUkm(form, ukm_service, | 4200 VerifyFormInteractionUkm(form, ukm_recorder, |
4220 internal::kUKMFormSubmittedEntryName, | 4201 internal::kUKMFormSubmittedEntryName, |
4221 expected_form_submission_ukm_metrics); | 4202 expected_form_submission_ukm_metrics); |
4222 } | 4203 } |
4223 | 4204 |
4224 // Mark one of the fields as autofilled. | 4205 // Mark one of the fields as autofilled. |
4225 form.fields[1].is_autofilled = true; | 4206 form.fields[1].is_autofilled = true; |
4226 forms.front() = form; | 4207 forms.front() = form; |
4227 | 4208 |
4228 // Autofilled some of the fields. | 4209 // Autofilled some of the fields. |
4229 { | 4210 { |
4230 base::HistogramTester histogram_tester; | 4211 base::HistogramTester histogram_tester; |
4231 base::UserActionTester user_action_tester; | 4212 base::UserActionTester user_action_tester; |
4232 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 4213 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
4233 histogram_tester.ExpectUniqueSample( | 4214 histogram_tester.ExpectUniqueSample( |
4234 "Autofill.FormSubmittedState", | 4215 "Autofill.FormSubmittedState", |
4235 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME, 1); | 4216 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME, 1); |
4236 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4217 EXPECT_EQ(1, user_action_tester.GetActionCount( |
4237 "Autofill_FormSubmitted_FilledSome")); | 4218 "Autofill_FormSubmitted_FilledSome")); |
4238 | 4219 |
4239 expected_form_submission_ukm_metrics.push_back( | 4220 expected_form_submission_ukm_metrics.push_back( |
4240 {{internal::kUKMAutofillFormSubmittedStateMetricName, | 4221 {{internal::kUKMAutofillFormSubmittedStateMetricName, |
4241 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME}, | 4222 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME}, |
4242 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); | 4223 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); |
4243 VerifyFormInteractionUkm(form, ukm_service, | 4224 VerifyFormInteractionUkm(form, ukm_recorder, |
4244 internal::kUKMFormSubmittedEntryName, | 4225 internal::kUKMFormSubmittedEntryName, |
4245 expected_form_submission_ukm_metrics); | 4226 expected_form_submission_ukm_metrics); |
4246 } | 4227 } |
4247 | 4228 |
4248 // Mark all of the fillable fields as autofilled. | 4229 // Mark all of the fillable fields as autofilled. |
4249 form.fields[0].is_autofilled = true; | 4230 form.fields[0].is_autofilled = true; |
4250 form.fields[2].is_autofilled = true; | 4231 form.fields[2].is_autofilled = true; |
4251 forms.front() = form; | 4232 forms.front() = form; |
4252 | 4233 |
4253 // Autofilled all the fields. | 4234 // Autofilled all the fields. |
4254 { | 4235 { |
4255 base::HistogramTester histogram_tester; | 4236 base::HistogramTester histogram_tester; |
4256 base::UserActionTester user_action_tester; | 4237 base::UserActionTester user_action_tester; |
4257 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 4238 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
4258 histogram_tester.ExpectUniqueSample( | 4239 histogram_tester.ExpectUniqueSample( |
4259 "Autofill.FormSubmittedState", | 4240 "Autofill.FormSubmittedState", |
4260 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL, 1); | 4241 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL, 1); |
4261 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4242 EXPECT_EQ(1, user_action_tester.GetActionCount( |
4262 "Autofill_FormSubmitted_FilledAll")); | 4243 "Autofill_FormSubmitted_FilledAll")); |
4263 | 4244 |
4264 expected_form_submission_ukm_metrics.push_back( | 4245 expected_form_submission_ukm_metrics.push_back( |
4265 {{internal::kUKMAutofillFormSubmittedStateMetricName, | 4246 {{internal::kUKMAutofillFormSubmittedStateMetricName, |
4266 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL}, | 4247 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL}, |
4267 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); | 4248 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); |
4268 VerifyFormInteractionUkm(form, ukm_service, | 4249 VerifyFormInteractionUkm(form, ukm_recorder, |
4269 internal::kUKMFormSubmittedEntryName, | 4250 internal::kUKMFormSubmittedEntryName, |
4270 expected_form_submission_ukm_metrics); | 4251 expected_form_submission_ukm_metrics); |
4271 } | 4252 } |
4272 | 4253 |
4273 // Clear out the third field's value. | 4254 // Clear out the third field's value. |
4274 form.fields[2].value = base::string16(); | 4255 form.fields[2].value = base::string16(); |
4275 forms.front() = form; | 4256 forms.front() = form; |
4276 | 4257 |
4277 // Non fillable form. | 4258 // Non fillable form. |
4278 { | 4259 { |
4279 base::HistogramTester histogram_tester; | 4260 base::HistogramTester histogram_tester; |
4280 base::UserActionTester user_action_tester; | 4261 base::UserActionTester user_action_tester; |
4281 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 4262 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
4282 histogram_tester.ExpectUniqueSample( | 4263 histogram_tester.ExpectUniqueSample( |
4283 "Autofill.FormSubmittedState", | 4264 "Autofill.FormSubmittedState", |
4284 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); | 4265 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); |
4285 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4266 EXPECT_EQ(1, user_action_tester.GetActionCount( |
4286 "Autofill_FormSubmitted_NonFillable")); | 4267 "Autofill_FormSubmitted_NonFillable")); |
4287 | 4268 |
4288 expected_form_submission_ukm_metrics.push_back( | 4269 expected_form_submission_ukm_metrics.push_back( |
4289 {{internal::kUKMAutofillFormSubmittedStateMetricName, | 4270 {{internal::kUKMAutofillFormSubmittedStateMetricName, |
4290 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, | 4271 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, |
4291 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); | 4272 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); |
4292 VerifyFormInteractionUkm(form, ukm_service, | 4273 VerifyFormInteractionUkm(form, ukm_recorder, |
4293 internal::kUKMFormSubmittedEntryName, | 4274 internal::kUKMFormSubmittedEntryName, |
4294 expected_form_submission_ukm_metrics); | 4275 expected_form_submission_ukm_metrics); |
4295 } | 4276 } |
4296 } | 4277 } |
4297 | 4278 |
4298 // Verify that we correctly log user happiness metrics dealing with form | 4279 // Verify that we correctly log user happiness metrics dealing with form |
4299 // interaction. | 4280 // interaction. |
4300 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) { | 4281 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) { |
4301 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); | 4282 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder(); |
4302 | 4283 |
4303 // Load a fillable form. | 4284 // Load a fillable form. |
4304 FormData form; | 4285 FormData form; |
4305 form.name = ASCIIToUTF16("TestForm"); | 4286 form.name = ASCIIToUTF16("TestForm"); |
4306 form.origin = GURL("http://example.com/form.html"); | 4287 form.origin = GURL("http://example.com/form.html"); |
4307 form.action = GURL("http://example.com/submit.html"); | 4288 form.action = GURL("http://example.com/submit.html"); |
4308 | 4289 |
4309 FormFieldData field; | 4290 FormFieldData field; |
4310 test::CreateTestFormField("Name", "name", "", "text", &field); | 4291 test::CreateTestFormField("Name", "name", "", "text", &field); |
4311 form.fields.push_back(field); | 4292 form.fields.push_back(field); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4396 base::HistogramTester histogram_tester; | 4377 base::HistogramTester histogram_tester; |
4397 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks()); | 4378 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks()); |
4398 histogram_tester.ExpectUniqueSample( | 4379 histogram_tester.ExpectUniqueSample( |
4399 "Autofill.UserHappiness", | 4380 "Autofill.UserHappiness", |
4400 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD, 1); | 4381 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD, 1); |
4401 } | 4382 } |
4402 | 4383 |
4403 autofill_manager_->Reset(); | 4384 autofill_manager_->Reset(); |
4404 | 4385 |
4405 VerifyFormInteractionUkm( | 4386 VerifyFormInteractionUkm( |
4406 form, ukm_service, internal::kUKMInteractedWithFormEntryName, | 4387 form, ukm_recorder, internal::kUKMInteractedWithFormEntryName, |
4407 {{{internal::kUKMIsForCreditCardMetricName, false}, | 4388 {{{internal::kUKMIsForCreditCardMetricName, false}, |
4408 {internal::kUKMLocalRecordTypeCountMetricName, 0}, | 4389 {internal::kUKMLocalRecordTypeCountMetricName, 0}, |
4409 {internal::kUKMServerRecordTypeCountMetricName, 0}}}); | 4390 {internal::kUKMServerRecordTypeCountMetricName, 0}}}); |
4410 VerifyFormInteractionUkm( | 4391 VerifyFormInteractionUkm( |
4411 form, ukm_service, internal::kUKMSuggestionsShownEntryName, | 4392 form, ukm_recorder, internal::kUKMSuggestionsShownEntryName, |
4412 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, | 4393 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, |
4413 {{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); | 4394 {{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); |
4414 VerifyFormInteractionUkm( | 4395 VerifyFormInteractionUkm( |
4415 form, ukm_service, internal::kUKMSuggestionFilledEntryName, | 4396 form, ukm_recorder, internal::kUKMSuggestionFilledEntryName, |
4416 {{{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE}, | 4397 {{{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE}, |
4417 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, | 4398 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, |
4418 {{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE}, | 4399 {{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE}, |
4419 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); | 4400 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); |
4420 VerifyFormInteractionUkm( | 4401 VerifyFormInteractionUkm( |
4421 form, ukm_service, internal::kUKMTextFieldDidChangeEntryName, | 4402 form, ukm_recorder, internal::kUKMTextFieldDidChangeEntryName, |
4422 {{{internal::kUKMFieldTypeGroupMetricName, NAME}, | 4403 {{{internal::kUKMFieldTypeGroupMetricName, NAME}, |
4423 {internal::kUKMHeuristicTypeMetricName, NAME_FULL}, | 4404 {internal::kUKMHeuristicTypeMetricName, NAME_FULL}, |
4424 {internal::kUKMServerTypeMetricName, NO_SERVER_DATA}, | 4405 {internal::kUKMServerTypeMetricName, NO_SERVER_DATA}, |
4425 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}, | 4406 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}, |
4426 {internal::kUKMHtmlFieldModeMetricName, HTML_MODE_NONE}, | 4407 {internal::kUKMHtmlFieldModeMetricName, HTML_MODE_NONE}, |
4427 {internal::kUKMIsAutofilledMetricName, false}, | 4408 {internal::kUKMIsAutofilledMetricName, false}, |
4428 {internal::kUKMIsEmptyMetricName, true}, | 4409 {internal::kUKMIsEmptyMetricName, true}, |
4429 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, | 4410 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, |
4430 {{internal::kUKMFieldTypeGroupMetricName, NAME}, | 4411 {{internal::kUKMFieldTypeGroupMetricName, NAME}, |
4431 {internal::kUKMHeuristicTypeMetricName, NAME_FULL}, | 4412 {internal::kUKMHeuristicTypeMetricName, NAME_FULL}, |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5009 // Check that the nonsecure histogram was not recorded. ExpectBucketCount() | 4990 // Check that the nonsecure histogram was not recorded. ExpectBucketCount() |
5010 // can't be used here because it expects the histogram to exist. | 4991 // can't be used here because it expects the histogram to exist. |
5011 EXPECT_EQ( | 4992 EXPECT_EQ( |
5012 0, histograms.GetTotalCountsForPrefix("Autofill.FormEvents.CreditCard") | 4993 0, histograms.GetTotalCountsForPrefix("Autofill.FormEvents.CreditCard") |
5013 ["Autofill.FormEvents.CreditCard.OnNonsecurePage"]); | 4994 ["Autofill.FormEvents.CreditCard.OnNonsecurePage"]); |
5014 } | 4995 } |
5015 } | 4996 } |
5016 | 4997 |
5017 // Tests that logging CardUploadDecision UKM works as expected. | 4998 // Tests that logging CardUploadDecision UKM works as expected. |
5018 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric) { | 4999 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric) { |
5019 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 5000 ukm::TestUkmRecorder test_ukm_recorder; |
5020 GURL url("https://www.google.com"); | 5001 GURL url("https://www.google.com"); |
5021 int upload_decision = 1; | 5002 int upload_decision = 1; |
5022 std::vector<std::pair<const char*, int>> metrics = { | 5003 std::vector<std::pair<const char*, int>> metrics = { |
5023 {internal::kUKMCardUploadDecisionMetricName, upload_decision}}; | 5004 {internal::kUKMCardUploadDecisionMetricName, upload_decision}}; |
5024 | 5005 |
5025 EXPECT_TRUE(AutofillMetrics::LogUkm( | 5006 EXPECT_TRUE(AutofillMetrics::LogUkm(&test_ukm_recorder, url, |
5026 ukm_service_test_harness.test_ukm_service(), url, | 5007 internal::kUKMCardUploadDecisionEntryName, |
5027 internal::kUKMCardUploadDecisionEntryName, metrics)); | 5008 metrics)); |
5028 | 5009 |
5029 // Make sure that the UKM was logged correctly. | 5010 // Make sure that the UKM was logged correctly. |
5030 ukm::TestUkmService* ukm_service = | 5011 ukm::TestUkmRecorder* ukm_recorder = &test_ukm_recorder; |
5031 ukm_service_test_harness.test_ukm_service(); | |
5032 | 5012 |
5033 ASSERT_EQ(1U, ukm_service->sources_count()); | 5013 ASSERT_EQ(1U, ukm_recorder->sources_count()); |
5034 const ukm::UkmSource* source = | 5014 const ukm::UkmSource* source = |
5035 ukm_service->GetSourceForUrl(url.spec().c_str()); | 5015 ukm_recorder->GetSourceForUrl(url.spec().c_str()); |
5036 EXPECT_EQ(url.spec(), source->url().spec()); | 5016 EXPECT_EQ(url.spec(), source->url().spec()); |
5037 | 5017 |
5038 ASSERT_EQ(1U, ukm_service->entries_count()); | 5018 ASSERT_EQ(1U, ukm_recorder->entries_count()); |
5039 const ukm::UkmEntry* entry = ukm_service->GetEntry(0); | 5019 const ukm::mojom::UkmEntry* entry = ukm_recorder->GetEntry(0); |
5040 EXPECT_EQ(source->id(), entry->source_id()); | |
5041 | 5020 |
5042 // Make sure that a card upload decision entry was logged. | 5021 // Make sure that a card upload decision entry was logged. |
5043 ukm::Entry entry_proto; | 5022 EXPECT_EQ(source->id(), entry->source_id); |
5044 entry->PopulateProto(&entry_proto); | |
5045 EXPECT_EQ(source->id(), entry_proto.source_id()); | |
5046 EXPECT_EQ(base::HashMetricName(internal::kUKMCardUploadDecisionEntryName), | 5023 EXPECT_EQ(base::HashMetricName(internal::kUKMCardUploadDecisionEntryName), |
5047 entry_proto.event_hash()); | 5024 entry->event_hash); |
5048 EXPECT_EQ(1, entry_proto.metrics_size()); | 5025 EXPECT_EQ(1U, entry->metrics.size()); |
5049 | 5026 |
5050 // Make sure that the correct upload decision was logged. | 5027 // Make sure that the correct upload decision was logged. |
5051 const ukm::Entry_Metric* metric = FindMetric( | 5028 const ukm::mojom::UkmMetric* metric = ukm::TestUkmRecorder::FindMetric( |
5052 internal::kUKMCardUploadDecisionMetricName, entry_proto.metrics()); | 5029 entry, internal::kUKMCardUploadDecisionMetricName); |
5053 ASSERT_NE(nullptr, metric); | 5030 ASSERT_NE(nullptr, metric); |
5054 EXPECT_EQ(upload_decision, metric->value()); | 5031 EXPECT_EQ(upload_decision, metric->value); |
5055 } | 5032 } |
5056 | 5033 |
5057 // Tests that logging DeveloperEngagement UKM works as expected. | 5034 // Tests that logging DeveloperEngagement UKM works as expected. |
5058 TEST_F(AutofillMetricsTest, RecordDeveloperEngagementMetric) { | 5035 TEST_F(AutofillMetricsTest, RecordDeveloperEngagementMetric) { |
5059 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 5036 ukm::TestUkmRecorder test_ukm_recorder; |
5060 GURL url("https://www.google.com"); | 5037 GURL url("https://www.google.com"); |
5061 int form_structure_metric = 1; | 5038 int form_structure_metric = 1; |
5062 std::vector<std::pair<const char*, int>> metrics = { | 5039 std::vector<std::pair<const char*, int>> metrics = { |
5063 {internal::kUKMDeveloperEngagementMetricName, form_structure_metric}}; | 5040 {internal::kUKMDeveloperEngagementMetricName, form_structure_metric}}; |
5064 | 5041 |
5065 EXPECT_TRUE(AutofillMetrics::LogUkm( | 5042 EXPECT_TRUE(AutofillMetrics::LogUkm( |
5066 ukm_service_test_harness.test_ukm_service(), url, | 5043 &test_ukm_recorder, url, internal::kUKMDeveloperEngagementEntryName, |
5067 internal::kUKMDeveloperEngagementEntryName, metrics)); | 5044 metrics)); |
5068 | 5045 |
5069 // Make sure that the UKM was logged correctly. | 5046 // Make sure that the UKM was logged correctly. |
5070 ukm::TestUkmService* ukm_service = | 5047 ukm::TestUkmRecorder* ukm_recorder = &test_ukm_recorder; |
5071 ukm_service_test_harness.test_ukm_service(); | |
5072 | 5048 |
5073 ASSERT_EQ(1U, ukm_service->sources_count()); | 5049 ASSERT_EQ(1U, ukm_recorder->sources_count()); |
5074 const ukm::UkmSource* source = | 5050 const ukm::UkmSource* source = |
5075 ukm_service->GetSourceForUrl(url.spec().c_str()); | 5051 ukm_recorder->GetSourceForUrl(url.spec().c_str()); |
5076 EXPECT_EQ(url.spec(), source->url().spec()); | 5052 EXPECT_EQ(url.spec(), source->url().spec()); |
5077 | 5053 |
5078 ASSERT_EQ(1U, ukm_service->entries_count()); | 5054 ASSERT_EQ(1U, ukm_recorder->entries_count()); |
5079 const ukm::UkmEntry* entry = ukm_service->GetEntry(0); | 5055 const ukm::mojom::UkmEntry* entry = ukm_recorder->GetEntry(0); |
5080 EXPECT_EQ(source->id(), entry->source_id()); | |
5081 | 5056 |
5082 // Make sure that a developer engagement entry was logged. | 5057 // Make sure that a developer engagement entry was logged. |
5083 ukm::Entry entry_proto; | 5058 EXPECT_EQ(source->id(), entry->source_id); |
5084 entry->PopulateProto(&entry_proto); | |
5085 EXPECT_EQ(source->id(), entry_proto.source_id()); | |
5086 EXPECT_EQ(base::HashMetricName(internal::kUKMDeveloperEngagementEntryName), | 5059 EXPECT_EQ(base::HashMetricName(internal::kUKMDeveloperEngagementEntryName), |
5087 entry_proto.event_hash()); | 5060 entry->event_hash); |
5088 EXPECT_EQ(1, entry_proto.metrics_size()); | 5061 EXPECT_EQ(1U, entry->metrics.size()); |
5089 | 5062 |
5090 // Make sure that the correct developer engagement metric was logged. | 5063 // Make sure that the correct developer engagement metric was logged. |
5091 const ukm::Entry_Metric* metric = FindMetric( | 5064 const ukm::mojom::UkmMetric* metric = ukm::TestUkmRecorder::FindMetric( |
5092 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics()); | 5065 entry, internal::kUKMDeveloperEngagementMetricName); |
5093 ASSERT_NE(nullptr, metric); | 5066 ASSERT_NE(nullptr, metric); |
5094 EXPECT_EQ(form_structure_metric, metric->value()); | 5067 EXPECT_EQ(form_structure_metric, metric->value); |
5095 } | 5068 } |
5096 | 5069 |
5097 // Tests that no UKM is logged when the URL is not valid. | 5070 // Tests that no UKM is logged when the URL is not valid. |
5098 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_InvalidUrl) { | 5071 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_InvalidUrl) { |
5099 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 5072 ukm::TestUkmRecorder test_ukm_recorder; |
5100 GURL url(""); | 5073 GURL url(""); |
5101 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; | 5074 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; |
5102 | 5075 |
5103 EXPECT_FALSE(AutofillMetrics::LogUkm( | 5076 EXPECT_FALSE( |
5104 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); | 5077 AutofillMetrics::LogUkm(&test_ukm_recorder, url, "test_ukm", metrics)); |
5105 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); | 5078 EXPECT_EQ(0U, test_ukm_recorder.sources_count()); |
5106 } | 5079 } |
5107 | 5080 |
5108 // Tests that no UKM is logged when the metrics map is empty. | 5081 // Tests that no UKM is logged when the metrics map is empty. |
5109 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoMetrics) { | 5082 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoMetrics) { |
5110 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 5083 ukm::TestUkmRecorder test_ukm_recorder; |
5111 GURL url("https://www.google.com"); | 5084 GURL url("https://www.google.com"); |
5112 std::vector<std::pair<const char*, int>> metrics; | 5085 std::vector<std::pair<const char*, int>> metrics; |
5113 | 5086 |
5114 EXPECT_FALSE(AutofillMetrics::LogUkm( | 5087 EXPECT_FALSE( |
5115 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); | 5088 AutofillMetrics::LogUkm(&test_ukm_recorder, url, "test_ukm", metrics)); |
5116 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); | 5089 EXPECT_EQ(0U, test_ukm_recorder.sources_count()); |
5117 } | 5090 } |
5118 | 5091 |
5119 // Tests that no UKM is logged when the ukm service is null. | 5092 // Tests that no UKM is logged when the ukm service is null. |
5120 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmService) { | 5093 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmService) { |
5121 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 5094 ukm::TestUkmRecorder test_ukm_recorder; |
5122 GURL url("https://www.google.com"); | 5095 GURL url("https://www.google.com"); |
5123 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; | 5096 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; |
5124 | 5097 |
5125 EXPECT_FALSE(AutofillMetrics::LogUkm(nullptr, url, "test_ukm", metrics)); | 5098 EXPECT_FALSE(AutofillMetrics::LogUkm(nullptr, url, "test_ukm", metrics)); |
5126 ASSERT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); | 5099 ASSERT_EQ(0U, test_ukm_recorder.sources_count()); |
5127 } | 5100 } |
5128 | 5101 |
5129 } // namespace autofill | 5102 } // namespace autofill |
OLD | NEW |