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

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

Issue 2940983003: [autofill] Add UKM for field type prediction quality and autofill outcome. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/core/browser/autofill_metrics.h" 5 #include "components/autofill/core/browser/autofill_metrics.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 using base::Bucket; 52 using base::Bucket;
53 using base::TimeTicks; 53 using base::TimeTicks;
54 using rappor::TestRapporServiceImpl; 54 using rappor::TestRapporServiceImpl;
55 using ::testing::ElementsAre; 55 using ::testing::ElementsAre;
56 using ::testing::Matcher; 56 using ::testing::Matcher;
57 using ::testing::UnorderedPointwise; 57 using ::testing::UnorderedPointwise;
58 58
59 namespace autofill { 59 namespace autofill {
60 namespace { 60 namespace {
61 61
62 using ExpectedUkmMetrics =
63 std::vector<std::vector<std::pair<const char*, int64_t>>>;
64
62 class TestPersonalDataManager : public PersonalDataManager { 65 class TestPersonalDataManager : public PersonalDataManager {
63 public: 66 public:
64 TestPersonalDataManager() 67 TestPersonalDataManager()
65 : PersonalDataManager("en-US"), 68 : PersonalDataManager("en-US"),
66 autofill_enabled_(true) { 69 autofill_enabled_(true) {
67 CreateTestAutofillProfiles(&web_profiles_); 70 CreateTestAutofillProfiles(&web_profiles_);
68 } 71 }
69 72
70 using PersonalDataManager::set_account_tracker; 73 using PersonalDataManager::set_account_tracker;
71 using PersonalDataManager::set_signin_manager; 74 using PersonalDataManager::set_signin_manager;
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 }; 325 };
323 326
324 MATCHER(CompareMetrics, "") { 327 MATCHER(CompareMetrics, "") {
325 const ukm::mojom::UkmMetric* lhs = ::testing::get<0>(arg).get(); 328 const ukm::mojom::UkmMetric* lhs = ::testing::get<0>(arg).get();
326 const std::pair<const char*, int64_t>& rhs = ::testing::get<1>(arg); 329 const std::pair<const char*, int64_t>& rhs = ::testing::get<1>(arg);
327 return lhs->metric_hash == base::HashMetricName(rhs.first) && 330 return lhs->metric_hash == base::HashMetricName(rhs.first) &&
328 lhs->value == rhs.second; 331 lhs->value == rhs.second;
329 } 332 }
330 333
331 void VerifyDeveloperEngagementUkm( 334 void VerifyDeveloperEngagementUkm(
335 const ukm::TestUkmRecorder& ukm_recorder,
sebsg 2017/06/19 14:48:09 What's the advantage of putting it first?
Roger McFarlane (Chromium) 2017/06/21 21:01:54 nothing in particular. mostly just a preference to
sebsg 2017/06/21 21:08:03 SGTM
332 const FormData& form, 336 const FormData& form,
333 const ukm::TestUkmRecorder* ukm_recorder,
334 const std::vector<int64_t>& expected_metric_values) { 337 const std::vector<int64_t>& expected_metric_values) {
335 const ukm::mojom::UkmEntry* entry = ukm_recorder->GetEntryForEntryName( 338 const ukm::mojom::UkmEntry* entry = ukm_recorder.GetEntryForEntryName(
336 internal::kUKMDeveloperEngagementEntryName); 339 internal::kUKMDeveloperEngagementEntryName);
337 ASSERT_NE(nullptr, entry); 340 ASSERT_NE(nullptr, entry);
338 const ukm::UkmSource* source = 341 const ukm::UkmSource* source =
339 ukm_recorder->GetSourceForSourceId(entry->source_id); 342 ukm_recorder.GetSourceForSourceId(entry->source_id);
340 ASSERT_NE(nullptr, source); 343 ASSERT_NE(nullptr, source);
341 EXPECT_EQ(form.origin, source->url()); 344 EXPECT_EQ(form.origin, source->url());
342 345
343 int expected_metric_value = 0; 346 int expected_metric_value = 0;
344 for (const auto it : expected_metric_values) 347 for (const auto it : expected_metric_values)
345 expected_metric_value |= 1 << it; 348 expected_metric_value |= 1 << it;
346 349
347 const std::vector<std::pair<const char*, int64_t>> expected_metrics{ 350 const std::vector<std::pair<const char*, int64_t>> expected_metrics{
348 {internal::kUKMDeveloperEngagementMetricName, expected_metric_value}}; 351 {internal::kUKMDeveloperEngagementMetricName, expected_metric_value}};
349 352
350 EXPECT_THAT(entry->metrics, 353 EXPECT_THAT(entry->metrics,
351 UnorderedPointwise(CompareMetrics(), expected_metrics)); 354 UnorderedPointwise(CompareMetrics(), expected_metrics));
352 } 355 }
353 356
354 MATCHER(CompareMetricsIgnoringMillisecondsSinceFormParsed, "") { 357 MATCHER(CompareMetricsIgnoringMillisecondsSinceFormParsed, "") {
355 const ukm::mojom::UkmMetric* lhs = ::testing::get<0>(arg).get(); 358 const ukm::mojom::UkmMetric* lhs = ::testing::get<0>(arg).get();
356 const std::pair<const char*, int64_t>& rhs = ::testing::get<1>(arg); 359 const std::pair<const char*, int64_t>& rhs = ::testing::get<1>(arg);
357 return lhs->metric_hash == base::HashMetricName(rhs.first) && 360 return lhs->metric_hash == base::HashMetricName(rhs.first) &&
358 (lhs->value == rhs.second || 361 (lhs->value == rhs.second ||
359 (lhs->value > 0 && 362 (lhs->value > 0 &&
360 rhs.first == internal::kUKMMillisecondsSinceFormParsedMetricName)); 363 rhs.first == internal::kUKMMillisecondsSinceFormParsedMetricName));
361 } 364 }
362 365
363 void VerifyFormInteractionUkm( 366 void VerifyFormInteractionUkm(const ukm::TestUkmRecorder& ukm_recorder,
364 const FormData& form, 367 const FormData& form,
365 const ukm::TestUkmRecorder* ukm_recorder, 368 const char* event_name,
366 const char* event_name, 369 const ExpectedUkmMetrics& expected_metrics) {
367 const std::vector<std::vector<std::pair<const char*, int64_t>>>&
368 expected_metrics) {
369 size_t expected_metrics_index = 0; 370 size_t expected_metrics_index = 0;
370 for (size_t i = 0; i < ukm_recorder->entries_count(); ++i) { 371 for (size_t i = 0; i < ukm_recorder.entries_count(); ++i) {
371 const ukm::mojom::UkmEntry* entry = ukm_recorder->GetEntry(i); 372 const ukm::mojom::UkmEntry* entry = ukm_recorder.GetEntry(i);
372 if (entry->event_hash != base::HashMetricName(event_name)) 373 if (entry->event_hash != base::HashMetricName(event_name))
373 continue; 374 continue;
374 375
375 const ukm::UkmSource* source = 376 const ukm::UkmSource* source =
376 ukm_recorder->GetSourceForSourceId(entry->source_id); 377 ukm_recorder.GetSourceForSourceId(entry->source_id);
377 ASSERT_NE(nullptr, source); 378 ASSERT_NE(nullptr, source);
378 EXPECT_EQ(form.origin, source->url()); 379 EXPECT_EQ(form.origin, source->url());
379 380
380 ASSERT_LT(expected_metrics_index, expected_metrics.size()); 381 ASSERT_LT(expected_metrics_index, expected_metrics.size());
381 EXPECT_THAT( 382 EXPECT_THAT(
382 entry->metrics, 383 entry->metrics,
383 UnorderedPointwise(CompareMetricsIgnoringMillisecondsSinceFormParsed(), 384 UnorderedPointwise(CompareMetricsIgnoringMillisecondsSinceFormParsed(),
384 expected_metrics[expected_metrics_index++])); 385 expected_metrics[expected_metrics_index++]));
385 } 386 }
386 } 387 }
387 388
388 void VerifySubmitFormUkm(const FormData& form, 389 void VerifySubmitFormUkm(const ukm::TestUkmRecorder& ukm_recorder,
389 const ukm::TestUkmRecorder* ukm_recorder, 390 const FormData& form,
390 AutofillMetrics::AutofillFormSubmittedState state) { 391 AutofillMetrics::AutofillFormSubmittedState state) {
391 VerifyFormInteractionUkm( 392 VerifyFormInteractionUkm(
392 form, ukm_recorder, internal::kUKMFormSubmittedEntryName, 393 ukm_recorder, form, internal::kUKMFormSubmittedEntryName,
393 {{{internal::kUKMAutofillFormSubmittedStateMetricName, state}, 394 {{{internal::kUKMAutofillFormSubmittedStateMetricName, state},
394 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 395 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
395 } 396 }
396 397
398 void AppendFieldFillStatusUkm(const FormData& form,
399 ExpectedUkmMetrics* expected_metrics) {
400 int64_t form_signature = static_cast<int64_t>(CalculateFormSignature(form));
401 int64_t metric_type = static_cast<int64_t>(AutofillMetrics::TYPE_SUBMISSION);
402 for (const FormFieldData& field : form.fields) {
403 int64_t field_signature =
404 static_cast<int64_t>(CalculateFieldSignatureForField(field));
405 expected_metrics->push_back(
406 {{internal::kUKMMillisecondsSinceFormParsedMetricName, 0},
407 {internal::kUKMFormSignatureMetricName, form_signature},
408 {internal::kUKMFieldSignatureMetricName, field_signature},
409 {internal::kUKMValidationEventMetricName, metric_type},
410 {internal::kUKMIsAutofilledMetricName, field.is_autofilled ? 1 : 0},
411 {internal::kUKMWasPreviouslyAutofilledMetricName, 0}});
412 }
413 }
414
415 void AppendFieldTypeUkm(const FormData& form,
416 const std::vector<ServerFieldType>& heuristic_types,
417 const std::vector<ServerFieldType>& server_types,
418 const std::vector<ServerFieldType>& actual_types,
419 ExpectedUkmMetrics* expected_metrics) {
420 ASSERT_EQ(heuristic_types.size(), form.fields.size());
421 ASSERT_EQ(server_types.size(), form.fields.size());
422 ASSERT_EQ(actual_types.size(), form.fields.size());
423 int64_t form_signature = static_cast<int64_t>(CalculateFormSignature(form));
424 int64_t metric_type = static_cast<int64_t>(AutofillMetrics::TYPE_SUBMISSION);
425 std::vector<int64_t> prediction_sources{
426 AutofillMetrics::PREDICTION_SOURCE_HEURISTIC,
427 AutofillMetrics::PREDICTION_SOURCE_SERVER,
428 AutofillMetrics::PREDICTION_SOURCE_OVERALL};
429 for (size_t i = 0; i < form.fields.size(); ++i) {
430 const FormFieldData& field = form.fields[i];
431 int64_t field_signature =
432 static_cast<int64_t>(CalculateFieldSignatureForField(field));
433 for (int64_t source : prediction_sources) {
434 int64_t predicted_type = static_cast<int64_t>(
435 (source == AutofillMetrics::PREDICTION_SOURCE_SERVER
436 ? server_types
437 : heuristic_types)[i]);
438 int64_t actual_type = static_cast<int64_t>(actual_types[i]);
439 expected_metrics->push_back(
440 {{internal::kUKMMillisecondsSinceFormParsedMetricName, 0},
441 {internal::kUKMFormSignatureMetricName, form_signature},
442 {internal::kUKMFieldSignatureMetricName, field_signature},
443 {internal::kUKMValidationEventMetricName, metric_type},
444 {internal::kUKMPredictionSourceMetricName, source},
445 {internal::kUKMPredictedTypeMetricName, predicted_type},
446 {internal::kUKMActualTypeMetricName, actual_type}});
447 }
448 }
449 }
450
397 } // namespace 451 } // namespace
398 452
399 // This is defined in the autofill_metrics.cc implementation file. 453 // This is defined in the autofill_metrics.cc implementation file.
400 int GetFieldTypeGroupMetric(ServerFieldType field_type, 454 int GetFieldTypeGroupMetric(ServerFieldType field_type,
401 AutofillMetrics::FieldTypeQualityMetric metric); 455 AutofillMetrics::FieldTypeQualityMetric metric);
402 456
403 class AutofillMetricsTest : public testing::Test { 457 class AutofillMetricsTest : public testing::Test {
404 public: 458 public:
405 ~AutofillMetricsTest() override; 459 ~AutofillMetricsTest() override;
406 460
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 VLOG(2) << "Test Case = Predicted: " 842 VLOG(2) << "Test Case = Predicted: "
789 << AutofillType(predicted_type).ToString() << "; " 843 << AutofillType(predicted_type).ToString() << "; "
790 << "Actual: " << AutofillType(actual_field_type).ToString(); 844 << "Actual: " << AutofillType(actual_field_type).ToString();
791 845
792 // Set up our form data. 846 // Set up our form data.
793 FormData form; 847 FormData form;
794 form.name = ASCIIToUTF16("TestForm"); 848 form.name = ASCIIToUTF16("TestForm");
795 form.origin = GURL("http://example.com/form.html"); 849 form.origin = GURL("http://example.com/form.html");
796 form.action = GURL("http://example.com/submit.html"); 850 form.action = GURL("http://example.com/submit.html");
797 851
798 std::vector<ServerFieldType> heuristic_types, server_types; 852 std::vector<ServerFieldType> heuristic_types, server_types, actual_types;
799 AutofillField field; 853 AutofillField field;
800 854
801 // Add a first name field, that is predicted correctly. 855 // Add a first name field, that is predicted correctly.
802 test::CreateTestFormField("first", "first", ValueForType(NAME_FIRST), "text", 856 test::CreateTestFormField("first", "first", ValueForType(NAME_FIRST), "text",
803 &field); 857 &field);
804 form.fields.push_back(field); 858 form.fields.push_back(field);
805 heuristic_types.push_back(NAME_FIRST); 859 heuristic_types.push_back(NAME_FIRST);
806 server_types.push_back(NAME_FIRST); 860 server_types.push_back(NAME_FIRST);
861 actual_types.push_back(NAME_FIRST);
807 862
808 // Add a last name field, that is predicted correctly. 863 // Add a last name field, that is predicted correctly.
809 test::CreateTestFormField("last", "last", ValueForType(NAME_LAST), "test", 864 test::CreateTestFormField("last", "last", ValueForType(NAME_LAST), "test",
810 &field); 865 &field);
811 form.fields.push_back(field); 866 form.fields.push_back(field);
812 heuristic_types.push_back(NAME_LAST); 867 heuristic_types.push_back(NAME_LAST);
813 server_types.push_back(NAME_LAST); 868 server_types.push_back(NAME_LAST);
869 actual_types.push_back(NAME_LAST);
814 870
815 // Add an empty or unknown field, that is predicted as per the test params. 871 // Add an empty or unknown field, that is predicted as per the test params.
816 test::CreateTestFormField("Unknown", "Unknown", 872 test::CreateTestFormField("Unknown", "Unknown",
817 ValueForType(actual_field_type), "text", &field); 873 ValueForType(actual_field_type), "text", &field);
818 form.fields.push_back(field); 874 form.fields.push_back(field);
819 heuristic_types.push_back(predicted_type); 875 heuristic_types.push_back(predicted_type);
820 server_types.push_back(predicted_type == UNKNOWN_TYPE ? NO_SERVER_DATA 876 server_types.push_back(predicted_type == UNKNOWN_TYPE ? NO_SERVER_DATA
821 : predicted_type); 877 : predicted_type);
878 // Resolve any field type ambiguity.
879 if (actual_field_type == AMBIGUOUS_TYPE) {
880 if (predicted_type == COMPANY_NAME || predicted_type == NAME_MIDDLE)
881 actual_field_type = predicted_type;
882 }
883 actual_types.push_back(actual_field_type);
822 884
823 // Simulate having seen this form on page load. 885 // Simulate having seen this form on page load.
824 autofill_manager_->AddSeenForm(form, heuristic_types, server_types); 886 autofill_manager_->AddSeenForm(form, heuristic_types, server_types);
825 887
826 // Run the form submission code while tracking the histograms. 888 // Run the form submission code while tracking the histograms.
827 base::HistogramTester histogram_tester; 889 base::HistogramTester histogram_tester;
828 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 890 autofill_manager_->SubmitForm(form, TimeTicks::Now());
829 891
830 // Resolve any field type ambiguity. 892 ExpectedUkmMetrics expected_ukm_metrics;
831 if (actual_field_type == AMBIGUOUS_TYPE) { 893 AppendFieldTypeUkm(form, heuristic_types, server_types, actual_types,
832 if (predicted_type == COMPANY_NAME || predicted_type == NAME_MIDDLE) 894 &expected_ukm_metrics);
833 actual_field_type = predicted_type; 895 VerifyFormInteractionUkm(test_ukm_recorder_, form,
834 } 896 internal::kUKMFieldTypeEntryName,
897 expected_ukm_metrics);
835 898
836 // Validate the total samples and the crossed (predicted-to-actual) samples. 899 // Validate the total samples and the crossed (predicted-to-actual) samples.
837 for (const auto& source : prediction_sources) { 900 for (const auto& source : prediction_sources) {
838 const std::string crossed_histogram = "Autofill.FieldPrediction." + source; 901 const std::string crossed_histogram = "Autofill.FieldPrediction." + source;
839 const std::string aggregate_histogram = 902 const std::string aggregate_histogram =
840 "Autofill.FieldPredictionQuality.Aggregate." + source; 903 "Autofill.FieldPredictionQuality.Aggregate." + source;
841 const std::string by_field_type_histogram = 904 const std::string by_field_type_histogram =
842 "Autofill.FieldPredictionQuality.ByFieldType." + source; 905 "Autofill.FieldPredictionQuality.ByFieldType." + source;
843 906
844 // Sanity Check: 907 // Sanity Check:
(...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after
1765 1828
1766 // Expect the "form parsed without field type hints" metric and the 1829 // Expect the "form parsed without field type hints" metric and the
1767 // "form loaded" form interaction event to be logged. 1830 // "form loaded" form interaction event to be logged.
1768 { 1831 {
1769 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); 1832 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now());
1770 autofill_manager_->Reset(); 1833 autofill_manager_->Reset();
1771 1834
1772 ASSERT_EQ(1U, test_ukm_recorder_.entries_count()); 1835 ASSERT_EQ(1U, test_ukm_recorder_.entries_count());
1773 ASSERT_EQ(1U, test_ukm_recorder_.sources_count()); 1836 ASSERT_EQ(1U, test_ukm_recorder_.sources_count());
1774 VerifyDeveloperEngagementUkm( 1837 VerifyDeveloperEngagementUkm(
1775 form, &test_ukm_recorder_, 1838 test_ukm_recorder_, form,
1776 {AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS}); 1839 {AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS});
1777 } 1840 }
1778 } 1841 }
1779 1842
1780 // Verify that we correctly log UKM for form parsed with type hints regarding 1843 // Verify that we correctly log UKM for form parsed with type hints regarding
1781 // developer engagement. 1844 // developer engagement.
1782 TEST_F(AutofillMetricsTest, 1845 TEST_F(AutofillMetricsTest,
1783 UkmDeveloperEngagement_LogFillableFormParsedWithTypeHints) { 1846 UkmDeveloperEngagement_LogFillableFormParsedWithTypeHints) {
1784 FormData form; 1847 FormData form;
1785 form.name = ASCIIToUTF16("TestForm"); 1848 form.name = ASCIIToUTF16("TestForm");
(...skipping 29 matching lines...) Expand all
1815 1878
1816 // Expect the "form parsed without field type hints" metric and the 1879 // Expect the "form parsed without field type hints" metric and the
1817 // "form loaded" form interaction event to be logged. 1880 // "form loaded" form interaction event to be logged.
1818 { 1881 {
1819 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); 1882 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now());
1820 autofill_manager_->Reset(); 1883 autofill_manager_->Reset();
1821 1884
1822 ASSERT_EQ(1U, test_ukm_recorder_.entries_count()); 1885 ASSERT_EQ(1U, test_ukm_recorder_.entries_count());
1823 ASSERT_EQ(1U, test_ukm_recorder_.sources_count()); 1886 ASSERT_EQ(1U, test_ukm_recorder_.sources_count());
1824 VerifyDeveloperEngagementUkm( 1887 VerifyDeveloperEngagementUkm(
1825 form, &test_ukm_recorder_, 1888 test_ukm_recorder_, form,
1826 {AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS}); 1889 {AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS});
1827 } 1890 }
1828 } 1891 }
1829 1892
1830 // Verify that we correctly log UKM for form parsed with type hints regarding 1893 // Verify that we correctly log UKM for form parsed with type hints regarding
1831 // developer engagement. 1894 // developer engagement.
1832 TEST_F(AutofillMetricsTest, UkmDeveloperEngagement_LogUpiVpaTypeHint) { 1895 TEST_F(AutofillMetricsTest, UkmDeveloperEngagement_LogUpiVpaTypeHint) {
1833 FormData form; 1896 FormData form;
1834 form.name = ASCIIToUTF16("TestForm"); 1897 form.name = ASCIIToUTF16("TestForm");
1835 form.origin = GURL("http://example.com/form.html"); 1898 form.origin = GURL("http://example.com/form.html");
(...skipping 11 matching lines...) Expand all
1847 std::vector<FormData> forms(1, form); 1910 std::vector<FormData> forms(1, form);
1848 1911
1849 // Expect the "upi-vpa hint" metric to be logged and the "form loaded" form 1912 // Expect the "upi-vpa hint" metric to be logged and the "form loaded" form
1850 // interaction event to be logged. 1913 // interaction event to be logged.
1851 { 1914 {
1852 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); 1915 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now());
1853 autofill_manager_->Reset(); 1916 autofill_manager_->Reset();
1854 1917
1855 ASSERT_EQ(1U, test_ukm_recorder_.entries_count()); 1918 ASSERT_EQ(1U, test_ukm_recorder_.entries_count());
1856 ASSERT_EQ(1U, test_ukm_recorder_.sources_count()); 1919 ASSERT_EQ(1U, test_ukm_recorder_.sources_count());
1857 VerifyDeveloperEngagementUkm(form, &test_ukm_recorder_, 1920 VerifyDeveloperEngagementUkm(test_ukm_recorder_, form,
1858 {AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT}); 1921 {AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT});
1859 test_ukm_recorder_.Purge(); 1922 test_ukm_recorder_.Purge();
1860 } 1923 }
1861 1924
1862 // Add another field with an author-specified field type to the form. 1925 // Add another field with an author-specified field type to the form.
1863 test::CreateTestFormField("", "", "", "text", &field); 1926 test::CreateTestFormField("", "", "", "text", &field);
1864 field.autocomplete_attribute = "address-line1"; 1927 field.autocomplete_attribute = "address-line1";
1865 forms.back().fields.push_back(field); 1928 forms.back().fields.push_back(field);
1866 1929
1867 { 1930 {
1868 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); 1931 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now());
1869 autofill_manager_->Reset(); 1932 autofill_manager_->Reset();
1870 1933
1871 VerifyDeveloperEngagementUkm( 1934 VerifyDeveloperEngagementUkm(
1872 form, &test_ukm_recorder_, 1935 test_ukm_recorder_, form,
1873 {AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS, 1936 {AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS,
1874 AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT}); 1937 AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT});
1875 } 1938 }
1876 } 1939 }
1877 1940
1878 // Test that the profile count is logged correctly. 1941 // Test that the profile count is logged correctly.
1879 TEST_F(AutofillMetricsTest, StoredProfileCount) { 1942 TEST_F(AutofillMetricsTest, StoredProfileCount) {
1880 // The metric should be logged when the profiles are first loaded. 1943 // The metric should be logged when the profiles are first loaded.
1881 { 1944 {
1882 base::HistogramTester histogram_tester; 1945 base::HistogramTester histogram_tester;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
2135 base::UserActionTester user_action_tester; 2198 base::UserActionTester user_action_tester;
2136 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 2199 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2137 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 2200 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2138 EXPECT_EQ(1, 2201 EXPECT_EQ(1,
2139 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); 2202 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm"));
2140 EXPECT_EQ(1, user_action_tester.GetActionCount( 2203 EXPECT_EQ(1, user_action_tester.GetActionCount(
2141 "Autofill_FormSubmitted_NonFillable")); 2204 "Autofill_FormSubmitted_NonFillable"));
2142 } 2205 }
2143 2206
2144 VerifyFormInteractionUkm( 2207 VerifyFormInteractionUkm(
2145 form, &test_ukm_recorder_, internal::kUKMSuggestionsShownEntryName, 2208 test_ukm_recorder_, form, internal::kUKMSuggestionsShownEntryName,
2146 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}, 2209 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0},
2147 {internal::kUKMHeuristicTypeMetricName, CREDIT_CARD_NAME_FULL}, 2210 {internal::kUKMHeuristicTypeMetricName, CREDIT_CARD_NAME_FULL},
2148 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}, 2211 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED},
2149 {internal::kUKMServerTypeMetricName, CREDIT_CARD_NAME_FULL}}, 2212 {internal::kUKMServerTypeMetricName, CREDIT_CARD_NAME_FULL}},
2150 {{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}, 2213 {{internal::kUKMMillisecondsSinceFormParsedMetricName, 0},
2151 {internal::kUKMHeuristicTypeMetricName, CREDIT_CARD_NUMBER}, 2214 {internal::kUKMHeuristicTypeMetricName, CREDIT_CARD_NUMBER},
2152 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}, 2215 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED},
2153 {internal::kUKMServerTypeMetricName, CREDIT_CARD_NUMBER}}}); 2216 {internal::kUKMServerTypeMetricName, CREDIT_CARD_NUMBER}}});
2154 // Expect 2 |FORM_EVENT_LOCAL_SUGGESTION_FILLED| events. First, from 2217 // Expect 2 |FORM_EVENT_LOCAL_SUGGESTION_FILLED| events. First, from
2155 // call to |external_delegate_->DidAcceptSuggestion|. Second, from call to 2218 // call to |external_delegate_->DidAcceptSuggestion|. Second, from call to
2156 // |autofill_manager_->FillOrPreviewForm|. 2219 // |autofill_manager_->FillOrPreviewForm|.
2157 VerifyFormInteractionUkm( 2220 VerifyFormInteractionUkm(
2158 form, &test_ukm_recorder_, internal::kUKMSuggestionFilledEntryName, 2221 test_ukm_recorder_, form, internal::kUKMSuggestionFilledEntryName,
2159 {{{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD}, 2222 {{{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD},
2160 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, 2223 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}},
2161 {{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD}, 2224 {{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD},
2162 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 2225 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
2163 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState| 2226 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState|
2164 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|. 2227 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|.
2165 VerifySubmitFormUkm(form, &test_ukm_recorder_, 2228 VerifySubmitFormUkm(test_ukm_recorder_, form,
2166 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); 2229 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA);
2167 } 2230 }
2168 2231
2169 // Test that the profile checkout flow user actions are correctly logged. 2232 // Test that the profile checkout flow user actions are correctly logged.
2170 TEST_F(AutofillMetricsTest, ProfileCheckoutFlowUserActions) { 2233 TEST_F(AutofillMetricsTest, ProfileCheckoutFlowUserActions) {
2171 // Create a profile. 2234 // Create a profile.
2172 personal_data_->RecreateProfile(); 2235 personal_data_->RecreateProfile();
2173 2236
2174 // Set up our form data. 2237 // Set up our form data.
2175 FormData form; 2238 FormData form;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2246 base::UserActionTester user_action_tester; 2309 base::UserActionTester user_action_tester;
2247 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 2310 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2248 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 2311 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2249 EXPECT_EQ(1, 2312 EXPECT_EQ(1,
2250 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); 2313 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm"));
2251 EXPECT_EQ(1, user_action_tester.GetActionCount( 2314 EXPECT_EQ(1, user_action_tester.GetActionCount(
2252 "Autofill_FormSubmitted_NonFillable")); 2315 "Autofill_FormSubmitted_NonFillable"));
2253 } 2316 }
2254 2317
2255 VerifyFormInteractionUkm( 2318 VerifyFormInteractionUkm(
2256 form, &test_ukm_recorder_, internal::kUKMSuggestionsShownEntryName, 2319 test_ukm_recorder_, form, internal::kUKMSuggestionsShownEntryName,
2257 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}, 2320 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0},
2258 {internal::kUKMHeuristicTypeMetricName, ADDRESS_HOME_STATE}, 2321 {internal::kUKMHeuristicTypeMetricName, ADDRESS_HOME_STATE},
2259 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}, 2322 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED},
2260 {internal::kUKMServerTypeMetricName, ADDRESS_HOME_STATE}}, 2323 {internal::kUKMServerTypeMetricName, ADDRESS_HOME_STATE}},
2261 {{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}, 2324 {{internal::kUKMMillisecondsSinceFormParsedMetricName, 0},
2262 {internal::kUKMHeuristicTypeMetricName, ADDRESS_HOME_CITY}, 2325 {internal::kUKMHeuristicTypeMetricName, ADDRESS_HOME_CITY},
2263 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}, 2326 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED},
2264 {internal::kUKMServerTypeMetricName, ADDRESS_HOME_CITY}}}); 2327 {internal::kUKMServerTypeMetricName, ADDRESS_HOME_CITY}}});
2265 // Expect 2 |FORM_EVENT_LOCAL_SUGGESTION_FILLED| events. First, from 2328 // Expect 2 |FORM_EVENT_LOCAL_SUGGESTION_FILLED| events. First, from
2266 // call to |external_delegate_->DidAcceptSuggestion|. Second, from call to 2329 // call to |external_delegate_->DidAcceptSuggestion|. Second, from call to
2267 // |autofill_manager_->FillOrPreviewForm|. 2330 // |autofill_manager_->FillOrPreviewForm|.
2268 VerifyFormInteractionUkm( 2331 VerifyFormInteractionUkm(
2269 form, &test_ukm_recorder_, internal::kUKMSuggestionFilledEntryName, 2332 test_ukm_recorder_, form, internal::kUKMSuggestionFilledEntryName,
2270 {{{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE}, 2333 {{{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE},
2271 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, 2334 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}},
2272 {{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE}, 2335 {{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE},
2273 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 2336 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
2274 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState| 2337 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState|
2275 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|. 2338 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|.
2276 VerifySubmitFormUkm(form, &test_ukm_recorder_, 2339 VerifySubmitFormUkm(test_ukm_recorder_, form,
2277 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); 2340 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA);
2278 } 2341 }
2279 2342
2280 // Tests that the Autofill_PolledCreditCardSuggestions user action is only 2343 // Tests that the Autofill_PolledCreditCardSuggestions user action is only
2281 // logged once if the field is queried repeatedly. 2344 // logged once if the field is queried repeatedly.
2282 TEST_F(AutofillMetricsTest, PolledCreditCardSuggestions_DebounceLogs) { 2345 TEST_F(AutofillMetricsTest, PolledCreditCardSuggestions_DebounceLogs) {
2283 personal_data_->RecreateCreditCards( 2346 personal_data_->RecreateCreditCards(
2284 true /* include_local_credit_card */, 2347 true /* include_local_credit_card */,
2285 false /* include_masked_server_credit_card */, 2348 false /* include_masked_server_credit_card */,
2286 false /* include_full_server_credit_card */); 2349 false /* include_full_server_credit_card */);
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
2863 base::HistogramTester histogram_tester; 2926 base::HistogramTester histogram_tester;
2864 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 2927 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2865 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 2928 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2866 histogram_tester.ExpectBucketCount( 2929 histogram_tester.ExpectBucketCount(
2867 "Autofill.FormEvents.CreditCard", 2930 "Autofill.FormEvents.CreditCard",
2868 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); 2931 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2869 histogram_tester.ExpectBucketCount( 2932 histogram_tester.ExpectBucketCount(
2870 "Autofill.FormEvents.CreditCard", 2933 "Autofill.FormEvents.CreditCard",
2871 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); 2934 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
2872 2935
2873 VerifySubmitFormUkm(form, &test_ukm_recorder_, 2936 VerifySubmitFormUkm(test_ukm_recorder_, form,
2874 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); 2937 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA);
2875 } 2938 }
2876 2939
2877 // Reset the autofill manager state and purge UKM logs. 2940 // Reset the autofill manager state and purge UKM logs.
2878 autofill_manager_->Reset(); 2941 autofill_manager_->Reset();
2879 test_ukm_recorder_.Purge(); 2942 test_ukm_recorder_.Purge();
2880 2943
2881 autofill_manager_->AddSeenForm(form, field_types, field_types); 2944 autofill_manager_->AddSeenForm(form, field_types, field_types);
2882 2945
2883 { 2946 {
2884 // Simulating submission with suggestion shown. 2947 // Simulating submission with suggestion shown.
2885 base::HistogramTester histogram_tester; 2948 base::HistogramTester histogram_tester;
2886 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); 2949 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field);
2887 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 2950 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2888 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 2951 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2889 histogram_tester.ExpectBucketCount( 2952 histogram_tester.ExpectBucketCount(
2890 "Autofill.FormEvents.CreditCard", 2953 "Autofill.FormEvents.CreditCard",
2891 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_SUBMITTED_ONCE, 1); 2954 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_SUBMITTED_ONCE, 1);
2892 histogram_tester.ExpectBucketCount( 2955 histogram_tester.ExpectBucketCount(
2893 "Autofill.FormEvents.CreditCard", 2956 "Autofill.FormEvents.CreditCard",
2894 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 1); 2957 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 1);
2895 2958
2896 VerifyFormInteractionUkm( 2959 VerifyFormInteractionUkm(
2897 form, &test_ukm_recorder_, internal::kUKMSuggestionsShownEntryName, 2960 test_ukm_recorder_, form, internal::kUKMSuggestionsShownEntryName,
2898 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}, 2961 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0},
2899 {internal::kUKMHeuristicTypeMetricName, CREDIT_CARD_NUMBER}, 2962 {internal::kUKMHeuristicTypeMetricName, CREDIT_CARD_NUMBER},
2900 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}, 2963 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED},
2901 {internal::kUKMServerTypeMetricName, CREDIT_CARD_NUMBER}}}); 2964 {internal::kUKMServerTypeMetricName, CREDIT_CARD_NUMBER}}});
2902 VerifySubmitFormUkm(form, &test_ukm_recorder_, 2965 VerifySubmitFormUkm(test_ukm_recorder_, form,
2903 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); 2966 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA);
2904 } 2967 }
2905 2968
2906 // Reset the autofill manager state and purge UKM logs. 2969 // Reset the autofill manager state and purge UKM logs.
2907 autofill_manager_->Reset(); 2970 autofill_manager_->Reset();
2908 test_ukm_recorder_.Purge(); 2971 test_ukm_recorder_.Purge();
2909 2972
2910 autofill_manager_->AddSeenForm(form, field_types, field_types); 2973 autofill_manager_->AddSeenForm(form, field_types, field_types);
2911 2974
2912 { 2975 {
2913 // Simulating submission with filled local data. 2976 // Simulating submission with filled local data.
2914 base::HistogramTester histogram_tester; 2977 base::HistogramTester histogram_tester;
2915 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 2978 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2916 std::string guid("10000000-0000-0000-0000-000000000001"); // local card 2979 std::string guid("10000000-0000-0000-0000-000000000001"); // local card
2917 autofill_manager_->FillOrPreviewForm( 2980 autofill_manager_->FillOrPreviewForm(
2918 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), 2981 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
2919 autofill_manager_->MakeFrontendID(guid, std::string())); 2982 autofill_manager_->MakeFrontendID(guid, std::string()));
2920 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 2983 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2921 histogram_tester.ExpectBucketCount( 2984 histogram_tester.ExpectBucketCount(
2922 "Autofill.FormEvents.CreditCard", 2985 "Autofill.FormEvents.CreditCard",
2923 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 1); 2986 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2924 histogram_tester.ExpectBucketCount( 2987 histogram_tester.ExpectBucketCount(
2925 "Autofill.FormEvents.CreditCard", 2988 "Autofill.FormEvents.CreditCard",
2926 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 1); 2989 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 1);
2927 2990
2928 VerifyFormInteractionUkm( 2991 VerifyFormInteractionUkm(
2929 form, &test_ukm_recorder_, internal::kUKMSuggestionFilledEntryName, 2992 test_ukm_recorder_, form, internal::kUKMSuggestionFilledEntryName,
2930 {{{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD}, 2993 {{{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD},
2931 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 2994 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
2932 VerifySubmitFormUkm(form, &test_ukm_recorder_, 2995 VerifySubmitFormUkm(test_ukm_recorder_, form,
2933 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); 2996 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA);
2934 } 2997 }
2935 2998
2936 // Reset the autofill manager state and purge UKM logs. 2999 // Reset the autofill manager state and purge UKM logs.
2937 autofill_manager_->Reset(); 3000 autofill_manager_->Reset();
2938 test_ukm_recorder_.Purge(); 3001 test_ukm_recorder_.Purge();
2939 3002
2940 autofill_manager_->AddSeenForm(form, field_types, field_types); 3003 autofill_manager_->AddSeenForm(form, field_types, field_types);
2941 3004
2942 { 3005 {
2943 // Simulating submission with filled server data. 3006 // Simulating submission with filled server data.
2944 base::HistogramTester histogram_tester; 3007 base::HistogramTester histogram_tester;
2945 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 3008 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2946 std::string guid( 3009 std::string guid(
2947 "10000000-0000-0000-0000-000000000003"); // full server card 3010 "10000000-0000-0000-0000-000000000003"); // full server card
2948 autofill_manager_->FillOrPreviewForm( 3011 autofill_manager_->FillOrPreviewForm(
2949 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), 3012 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
2950 autofill_manager_->MakeFrontendID(guid, std::string())); 3013 autofill_manager_->MakeFrontendID(guid, std::string()));
2951 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 3014 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2952 histogram_tester.ExpectBucketCount( 3015 histogram_tester.ExpectBucketCount(
2953 "Autofill.FormEvents.CreditCard", 3016 "Autofill.FormEvents.CreditCard",
2954 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 1); 3017 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2955 histogram_tester.ExpectBucketCount( 3018 histogram_tester.ExpectBucketCount(
2956 "Autofill.FormEvents.CreditCard", 3019 "Autofill.FormEvents.CreditCard",
2957 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 1); 3020 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 1);
2958 3021
2959 VerifyFormInteractionUkm( 3022 VerifyFormInteractionUkm(
2960 form, &test_ukm_recorder_, internal::kUKMSuggestionFilledEntryName, 3023 test_ukm_recorder_, form, internal::kUKMSuggestionFilledEntryName,
2961 {{{internal::kUKMRecordTypeMetricName, CreditCard::FULL_SERVER_CARD}, 3024 {{{internal::kUKMRecordTypeMetricName, CreditCard::FULL_SERVER_CARD},
2962 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 3025 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
2963 VerifySubmitFormUkm(form, &test_ukm_recorder_, 3026 VerifySubmitFormUkm(test_ukm_recorder_, form,
2964 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); 3027 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA);
2965 } 3028 }
2966 3029
2967 // Reset the autofill manager state and purge UKM logs. 3030 // Reset the autofill manager state and purge UKM logs.
2968 autofill_manager_->Reset(); 3031 autofill_manager_->Reset();
2969 test_ukm_recorder_.Purge(); 3032 test_ukm_recorder_.Purge();
2970 3033
2971 autofill_manager_->AddSeenForm(form, field_types, field_types); 3034 autofill_manager_->AddSeenForm(form, field_types, field_types);
2972 3035
2973 { 3036 {
2974 // Simulating submission with a masked card server suggestion. 3037 // Simulating submission with a masked card server suggestion.
2975 base::HistogramTester histogram_tester; 3038 base::HistogramTester histogram_tester;
2976 std::string guid( 3039 std::string guid(
2977 "10000000-0000-0000-0000-000000000002"); // masked server card 3040 "10000000-0000-0000-0000-000000000002"); // masked server card
2978 autofill_manager_->FillOrPreviewForm( 3041 autofill_manager_->FillOrPreviewForm(
2979 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.back(), 3042 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.back(),
2980 autofill_manager_->MakeFrontendID(guid, std::string())); 3043 autofill_manager_->MakeFrontendID(guid, std::string()));
2981 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS, 3044 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS,
2982 "6011000990139424"); 3045 "6011000990139424");
2983 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 3046 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2984 histogram_tester.ExpectBucketCount( 3047 histogram_tester.ExpectBucketCount(
2985 "Autofill.FormEvents.CreditCard", 3048 "Autofill.FormEvents.CreditCard",
2986 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED, 1); 3049 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED, 1);
2987 histogram_tester.ExpectBucketCount( 3050 histogram_tester.ExpectBucketCount(
2988 "Autofill.FormEvents.CreditCard", 3051 "Autofill.FormEvents.CreditCard",
2989 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE, 3052 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE,
2990 1); 3053 1);
2991 3054
2992 VerifyFormInteractionUkm( 3055 VerifyFormInteractionUkm(
2993 form, &test_ukm_recorder_, internal::kUKMSuggestionFilledEntryName, 3056 test_ukm_recorder_, form, internal::kUKMSuggestionFilledEntryName,
2994 {{{internal::kUKMRecordTypeMetricName, CreditCard::MASKED_SERVER_CARD}, 3057 {{{internal::kUKMRecordTypeMetricName, CreditCard::MASKED_SERVER_CARD},
2995 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 3058 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
2996 VerifyFormInteractionUkm( 3059 VerifyFormInteractionUkm(
2997 form, &test_ukm_recorder_, 3060 test_ukm_recorder_, form,
2998 internal::kUKMSelectedMaskedServerCardEntryName, 3061 internal::kUKMSelectedMaskedServerCardEntryName,
2999 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 3062 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
3000 VerifySubmitFormUkm(form, &test_ukm_recorder_, 3063 VerifySubmitFormUkm(test_ukm_recorder_, form,
3001 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); 3064 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA);
3002 } 3065 }
3003 3066
3004 // Reset the autofill manager state and purge UKM logs. 3067 // Reset the autofill manager state and purge UKM logs.
3005 autofill_manager_->Reset(); 3068 autofill_manager_->Reset();
3006 test_ukm_recorder_.Purge(); 3069 test_ukm_recorder_.Purge();
3007 3070
3008 // Recreating cards as the previous test should have upgraded the masked 3071 // Recreating cards as the previous test should have upgraded the masked
3009 // card to a full card. 3072 // card to a full card.
3010 personal_data_->RecreateCreditCards( 3073 personal_data_->RecreateCreditCards(
3011 true /* include_local_credit_card */, 3074 true /* include_local_credit_card */,
3012 true /* include_masked_server_credit_card */, 3075 true /* include_masked_server_credit_card */,
3013 true /* include_full_server_credit_card */); 3076 true /* include_full_server_credit_card */);
3014 3077
3015 // Reset the autofill manager state. 3078 // Reset the autofill manager state.
3016 autofill_manager_->Reset(); 3079 autofill_manager_->Reset();
3017 autofill_manager_->AddSeenForm(form, field_types, field_types); 3080 autofill_manager_->AddSeenForm(form, field_types, field_types);
3018 3081
3019 { 3082 {
3020 // Simulating multiple submissions. 3083 // Simulating multiple submissions.
3021 base::HistogramTester histogram_tester; 3084 base::HistogramTester histogram_tester;
3022 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 3085 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
3023 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 3086 autofill_manager_->SubmitForm(form, TimeTicks::Now());
3024 3087
3025 VerifyFormInteractionUkm( 3088 VerifyFormInteractionUkm(
3026 form, &test_ukm_recorder_, internal::kUKMFormSubmittedEntryName, 3089 test_ukm_recorder_, form, internal::kUKMFormSubmittedEntryName,
3027 {{{internal::kUKMAutofillFormSubmittedStateMetricName, 3090 {{{internal::kUKMAutofillFormSubmittedStateMetricName,
3028 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, 3091 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA},
3029 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 3092 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
3030 3093
3031 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 3094 autofill_manager_->SubmitForm(form, TimeTicks::Now());
3032 3095
3033 VerifyFormInteractionUkm( 3096 VerifyFormInteractionUkm(
3034 form, &test_ukm_recorder_, internal::kUKMFormSubmittedEntryName, 3097 test_ukm_recorder_, form, internal::kUKMFormSubmittedEntryName,
3035 {{{internal::kUKMAutofillFormSubmittedStateMetricName, 3098 {{{internal::kUKMAutofillFormSubmittedStateMetricName,
3036 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, 3099 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA},
3037 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, 3100 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}},
3038 {{internal::kUKMAutofillFormSubmittedStateMetricName, 3101 {{internal::kUKMAutofillFormSubmittedStateMetricName,
3039 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, 3102 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA},
3040 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 3103 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
3041 3104
3042 histogram_tester.ExpectBucketCount( 3105 histogram_tester.ExpectBucketCount(
3043 "Autofill.FormEvents.CreditCard", 3106 "Autofill.FormEvents.CreditCard",
3044 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); 3107 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
3116 histogram_tester.ExpectBucketCount( 3179 histogram_tester.ExpectBucketCount(
3117 "Autofill.FormEvents.CreditCard", 3180 "Autofill.FormEvents.CreditCard",
3118 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0); 3181 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
3119 histogram_tester.ExpectBucketCount( 3182 histogram_tester.ExpectBucketCount(
3120 "Autofill.FormEvents.CreditCard", 3183 "Autofill.FormEvents.CreditCard",
3121 AutofillMetrics:: 3184 AutofillMetrics::
3122 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE, 3185 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE,
3123 0); 3186 0);
3124 3187
3125 VerifyFormInteractionUkm( 3188 VerifyFormInteractionUkm(
3126 form, &test_ukm_recorder_, internal::kUKMSuggestionsShownEntryName, 3189 test_ukm_recorder_, form, internal::kUKMSuggestionsShownEntryName,
3127 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}, 3190 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0},
3128 {internal::kUKMHeuristicTypeMetricName, CREDIT_CARD_NUMBER}, 3191 {internal::kUKMHeuristicTypeMetricName, CREDIT_CARD_NUMBER},
3129 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}, 3192 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED},
3130 {internal::kUKMServerTypeMetricName, CREDIT_CARD_NUMBER}}}); 3193 {internal::kUKMServerTypeMetricName, CREDIT_CARD_NUMBER}}});
3131 VerifySubmitFormUkm(form, &test_ukm_recorder_, 3194 VerifySubmitFormUkm(test_ukm_recorder_, form,
3132 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); 3195 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA);
3133 } 3196 }
3134 } 3197 }
3135 3198
3136 // Test that we log "will submit" (but not submitted) form events for credit 3199 // Test that we log "will submit" (but not submitted) form events for credit
3137 // cards. Mirrors CreditCardSubmittedFormEvents test but does not expect any 3200 // cards. Mirrors CreditCardSubmittedFormEvents test but does not expect any
3138 // "submitted" metrics. 3201 // "submitted" metrics.
3139 TEST_F(AutofillMetricsTest, CreditCardWillSubmitFormEvents) { 3202 TEST_F(AutofillMetricsTest, CreditCardWillSubmitFormEvents) {
3140 EnableWalletSync(); 3203 EnableWalletSync();
3141 // Creating all kinds of cards. 3204 // Creating all kinds of cards.
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
3581 base::HistogramTester histogram_tester; 3644 base::HistogramTester histogram_tester;
3582 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 3645 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
3583 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 3646 autofill_manager_->SubmitForm(form, TimeTicks::Now());
3584 histogram_tester.ExpectBucketCount( 3647 histogram_tester.ExpectBucketCount(
3585 "Autofill.FormEvents.Address", 3648 "Autofill.FormEvents.Address",
3586 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); 3649 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
3587 histogram_tester.ExpectBucketCount( 3650 histogram_tester.ExpectBucketCount(
3588 "Autofill.FormEvents.Address", 3651 "Autofill.FormEvents.Address",
3589 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); 3652 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
3590 3653
3591 VerifySubmitFormUkm(form, &test_ukm_recorder_, 3654 VerifySubmitFormUkm(test_ukm_recorder_, form,
3592 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); 3655 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA);
3593 } 3656 }
3594 3657
3595 // Reset the autofill manager state and purge UKM logs. 3658 // Reset the autofill manager state and purge UKM logs.
3596 autofill_manager_->Reset(); 3659 autofill_manager_->Reset();
3597 test_ukm_recorder_.Purge(); 3660 test_ukm_recorder_.Purge();
3598 3661
3599 autofill_manager_->AddSeenForm(form, field_types, field_types); 3662 autofill_manager_->AddSeenForm(form, field_types, field_types);
3600 3663
3601 { 3664 {
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
4104 form.fields.push_back(field); 4167 form.fields.push_back(field);
4105 test::CreateTestFormField("Unknown", "unknown", "", "text", &field); 4168 test::CreateTestFormField("Unknown", "unknown", "", "text", &field);
4106 form.fields.push_back(field); 4169 form.fields.push_back(field);
4107 std::vector<FormData> forms(1, form); 4170 std::vector<FormData> forms(1, form);
4108 4171
4109 // Expect no notifications when the form is first seen. 4172 // Expect no notifications when the form is first seen.
4110 { 4173 {
4111 base::HistogramTester histogram_tester; 4174 base::HistogramTester histogram_tester;
4112 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); 4175 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now());
4113 histogram_tester.ExpectTotalCount("Autofill.FormSubmittedState", 0); 4176 histogram_tester.ExpectTotalCount("Autofill.FormSubmittedState", 0);
4177
4178 EXPECT_EQ(1U, test_ukm_recorder_.entries_count());
4179 EXPECT_EQ(1U, test_ukm_recorder_.sources_count());
4180
4181 VerifyDeveloperEngagementUkm(
4182 test_ukm_recorder_, form,
4183 {AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS});
4114 } 4184 }
4115 4185
4116 std::vector<std::vector<std::pair<const char*, int64_t>>> 4186 ExpectedUkmMetrics expected_form_submission_ukm_metrics;
4117 expected_form_submission_ukm_metrics = { 4187 ExpectedUkmMetrics expected_field_fill_status_ukm_metrics;
4118 {{internal::kUKMAutofillFormSubmittedStateMetricName,
4119 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA},
4120 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}};
4121 4188
4122 // No data entered in the form. 4189 // No data entered in the form.
4123 { 4190 {
4124 base::HistogramTester histogram_tester; 4191 base::HistogramTester histogram_tester;
4125 base::UserActionTester user_action_tester; 4192 base::UserActionTester user_action_tester;
4126 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4193 autofill_manager_->SubmitForm(form, TimeTicks::Now());
4127 histogram_tester.ExpectUniqueSample( 4194 histogram_tester.ExpectUniqueSample(
4128 "Autofill.FormSubmittedState", 4195 "Autofill.FormSubmittedState",
4129 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); 4196 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1);
4130 EXPECT_EQ(1, user_action_tester.GetActionCount( 4197 EXPECT_EQ(1, user_action_tester.GetActionCount(
4131 "Autofill_FormSubmitted_NonFillable")); 4198 "Autofill_FormSubmitted_NonFillable"));
4132 4199
4133 // Expect an entry for |DeveloperEngagement| and an entry for form 4200 expected_form_submission_ukm_metrics.push_back(
4134 // interactions. Both entries are for the same URL. 4201 {{internal::kUKMAutofillFormSubmittedStateMetricName,
4135 ASSERT_EQ(2U, test_ukm_recorder_.entries_count()); 4202 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA},
4136 ASSERT_EQ(2U, test_ukm_recorder_.sources_count()); 4203 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}});
4137 VerifyDeveloperEngagementUkm( 4204 VerifyFormInteractionUkm(test_ukm_recorder_, form,
4138 form, &test_ukm_recorder_,
4139 {AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS});
4140 VerifyFormInteractionUkm(form, &test_ukm_recorder_,
4141 internal::kUKMFormSubmittedEntryName, 4205 internal::kUKMFormSubmittedEntryName,
4142 expected_form_submission_ukm_metrics); 4206 expected_form_submission_ukm_metrics);
4207
4208 AppendFieldFillStatusUkm(form, &expected_field_fill_status_ukm_metrics);
4209 VerifyFormInteractionUkm(test_ukm_recorder_, form,
4210 internal::kUKMFieldFillStatusEntryName,
4211 expected_field_fill_status_ukm_metrics);
4143 } 4212 }
4144 4213
4145 // Non fillable form. 4214 // Non fillable form.
4146 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley"); 4215 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley");
4147 form.fields[1].value = ASCIIToUTF16("theking@gmail.com"); 4216 form.fields[1].value = ASCIIToUTF16("theking@gmail.com");
4148 forms.front() = form; 4217 forms.front() = form;
4149 4218
4150 { 4219 {
4151 base::HistogramTester histogram_tester; 4220 base::HistogramTester histogram_tester;
4152 base::UserActionTester user_action_tester; 4221 base::UserActionTester user_action_tester;
4153 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4222 autofill_manager_->SubmitForm(form, TimeTicks::Now());
4154 histogram_tester.ExpectUniqueSample( 4223 histogram_tester.ExpectUniqueSample(
4155 "Autofill.FormSubmittedState", 4224 "Autofill.FormSubmittedState",
4156 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); 4225 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1);
4157 EXPECT_EQ(1, user_action_tester.GetActionCount( 4226 EXPECT_EQ(1, user_action_tester.GetActionCount(
4158 "Autofill_FormSubmitted_NonFillable")); 4227 "Autofill_FormSubmitted_NonFillable"));
4159 4228
4160 expected_form_submission_ukm_metrics.push_back( 4229 expected_form_submission_ukm_metrics.push_back(
4161 {{internal::kUKMAutofillFormSubmittedStateMetricName, 4230 {{internal::kUKMAutofillFormSubmittedStateMetricName,
4162 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, 4231 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA},
4163 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); 4232 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}});
4164 VerifyFormInteractionUkm(form, &test_ukm_recorder_, 4233 VerifyFormInteractionUkm(test_ukm_recorder_, form,
4165 internal::kUKMFormSubmittedEntryName, 4234 internal::kUKMFormSubmittedEntryName,
4166 expected_form_submission_ukm_metrics); 4235 expected_form_submission_ukm_metrics);
4236
4237 AppendFieldFillStatusUkm(form, &expected_field_fill_status_ukm_metrics);
4238 VerifyFormInteractionUkm(test_ukm_recorder_, form,
4239 internal::kUKMFieldFillStatusEntryName,
4240 expected_field_fill_status_ukm_metrics);
4167 } 4241 }
4168 4242
4169 // Fill in the third field. 4243 // Fill in the third field.
4170 form.fields[2].value = ASCIIToUTF16("12345678901"); 4244 form.fields[2].value = ASCIIToUTF16("12345678901");
4171 forms.front() = form; 4245 forms.front() = form;
4172 4246
4173 // Autofilled none with no suggestions shown. 4247 // Autofilled none with no suggestions shown.
4174 { 4248 {
4175 base::HistogramTester histogram_tester; 4249 base::HistogramTester histogram_tester;
4176 base::UserActionTester user_action_tester; 4250 base::UserActionTester user_action_tester;
4177 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4251 autofill_manager_->SubmitForm(form, TimeTicks::Now());
4178 histogram_tester.ExpectUniqueSample( 4252 histogram_tester.ExpectUniqueSample(
4179 "Autofill.FormSubmittedState", 4253 "Autofill.FormSubmittedState",
4180 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS, 4254 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS,
4181 1); 4255 1);
4182 EXPECT_EQ(1, user_action_tester.GetActionCount( 4256 EXPECT_EQ(1, user_action_tester.GetActionCount(
4183 "Autofill_FormSubmitted_FilledNone_SuggestionsNotShown")); 4257 "Autofill_FormSubmitted_FilledNone_SuggestionsNotShown"));
4184 4258
4185 expected_form_submission_ukm_metrics.push_back( 4259 expected_form_submission_ukm_metrics.push_back(
4186 {{internal::kUKMAutofillFormSubmittedStateMetricName, 4260 {{internal::kUKMAutofillFormSubmittedStateMetricName,
4187 AutofillMetrics:: 4261 AutofillMetrics::
4188 FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS}, 4262 FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS},
4189 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); 4263 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}});
4190 VerifyFormInteractionUkm(form, &test_ukm_recorder_, 4264
4265 VerifyFormInteractionUkm(test_ukm_recorder_, form,
4191 internal::kUKMFormSubmittedEntryName, 4266 internal::kUKMFormSubmittedEntryName,
4192 expected_form_submission_ukm_metrics); 4267 expected_form_submission_ukm_metrics);
4268
4269 AppendFieldFillStatusUkm(form, &expected_field_fill_status_ukm_metrics);
4270 VerifyFormInteractionUkm(test_ukm_recorder_, form,
4271 internal::kUKMFieldFillStatusEntryName,
4272 expected_field_fill_status_ukm_metrics);
4193 } 4273 }
4194 4274
4195 // Autofilled none with suggestions shown. 4275 // Autofilled none with suggestions shown.
4196 autofill_manager_->DidShowSuggestions(true, form, form.fields[2]); 4276 autofill_manager_->DidShowSuggestions(true, form, form.fields[2]);
4197 { 4277 {
4198 base::HistogramTester histogram_tester; 4278 base::HistogramTester histogram_tester;
4199 base::UserActionTester user_action_tester; 4279 base::UserActionTester user_action_tester;
4200 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4280 autofill_manager_->SubmitForm(form, TimeTicks::Now());
4201 histogram_tester.ExpectUniqueSample( 4281 histogram_tester.ExpectUniqueSample(
4202 "Autofill.FormSubmittedState", 4282 "Autofill.FormSubmittedState",
4203 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS, 1); 4283 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS, 1);
4204 EXPECT_EQ(1, user_action_tester.GetActionCount( 4284 EXPECT_EQ(1, user_action_tester.GetActionCount(
4205 "Autofill_FormSubmitted_FilledNone_SuggestionsShown")); 4285 "Autofill_FormSubmitted_FilledNone_SuggestionsShown"));
4206 4286
4207 VerifyFormInteractionUkm( 4287 VerifyFormInteractionUkm(
4208 form, &test_ukm_recorder_, internal::kUKMSuggestionsShownEntryName, 4288 test_ukm_recorder_, form, internal::kUKMSuggestionsShownEntryName,
4209 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}, 4289 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0},
4210 {internal::kUKMHeuristicTypeMetricName, PHONE_HOME_WHOLE_NUMBER}, 4290 {internal::kUKMHeuristicTypeMetricName, PHONE_HOME_WHOLE_NUMBER},
4211 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}, 4291 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED},
4212 {internal::kUKMServerTypeMetricName, NO_SERVER_DATA}}}); 4292 {internal::kUKMServerTypeMetricName, NO_SERVER_DATA}}});
4293
4213 expected_form_submission_ukm_metrics.push_back( 4294 expected_form_submission_ukm_metrics.push_back(
4214 {{internal::kUKMAutofillFormSubmittedStateMetricName, 4295 {{internal::kUKMAutofillFormSubmittedStateMetricName,
4215 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS}, 4296 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS},
4216 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); 4297 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}});
4217 VerifyFormInteractionUkm(form, &test_ukm_recorder_, 4298 VerifyFormInteractionUkm(test_ukm_recorder_, form,
4218 internal::kUKMFormSubmittedEntryName, 4299 internal::kUKMFormSubmittedEntryName,
4219 expected_form_submission_ukm_metrics); 4300 expected_form_submission_ukm_metrics);
4301
4302 AppendFieldFillStatusUkm(form, &expected_field_fill_status_ukm_metrics);
4303 VerifyFormInteractionUkm(test_ukm_recorder_, form,
4304 internal::kUKMFieldFillStatusEntryName,
4305 expected_field_fill_status_ukm_metrics);
4220 } 4306 }
4221 4307
4222 // Mark one of the fields as autofilled. 4308 // Mark one of the fields as autofilled.
4223 form.fields[1].is_autofilled = true; 4309 form.fields[1].is_autofilled = true;
4224 forms.front() = form; 4310 forms.front() = form;
4225 4311
4226 // Autofilled some of the fields. 4312 // Autofilled some of the fields.
4227 { 4313 {
4228 base::HistogramTester histogram_tester; 4314 base::HistogramTester histogram_tester;
4229 base::UserActionTester user_action_tester; 4315 base::UserActionTester user_action_tester;
4230 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4316 autofill_manager_->SubmitForm(form, TimeTicks::Now());
4231 histogram_tester.ExpectUniqueSample( 4317 histogram_tester.ExpectUniqueSample(
4232 "Autofill.FormSubmittedState", 4318 "Autofill.FormSubmittedState",
4233 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME, 1); 4319 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME, 1);
4234 EXPECT_EQ(1, user_action_tester.GetActionCount( 4320 EXPECT_EQ(1, user_action_tester.GetActionCount(
4235 "Autofill_FormSubmitted_FilledSome")); 4321 "Autofill_FormSubmitted_FilledSome"));
4236 4322
4237 expected_form_submission_ukm_metrics.push_back( 4323 expected_form_submission_ukm_metrics.push_back(
4238 {{internal::kUKMAutofillFormSubmittedStateMetricName, 4324 {{internal::kUKMAutofillFormSubmittedStateMetricName,
4239 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME}, 4325 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME},
4240 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); 4326 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}});
4241 VerifyFormInteractionUkm(form, &test_ukm_recorder_, 4327 VerifyFormInteractionUkm(test_ukm_recorder_, form,
4242 internal::kUKMFormSubmittedEntryName, 4328 internal::kUKMFormSubmittedEntryName,
4243 expected_form_submission_ukm_metrics); 4329 expected_form_submission_ukm_metrics);
4330
4331 AppendFieldFillStatusUkm(form, &expected_field_fill_status_ukm_metrics);
4332 VerifyFormInteractionUkm(test_ukm_recorder_, form,
4333 internal::kUKMFieldFillStatusEntryName,
4334 expected_field_fill_status_ukm_metrics);
4244 } 4335 }
4245 4336
4246 // Mark all of the fillable fields as autofilled. 4337 // Mark all of the fillable fields as autofilled.
4247 form.fields[0].is_autofilled = true; 4338 form.fields[0].is_autofilled = true;
4248 form.fields[2].is_autofilled = true; 4339 form.fields[2].is_autofilled = true;
4249 forms.front() = form; 4340 forms.front() = form;
4250 4341
4251 // Autofilled all the fields. 4342 // Autofilled all the fields.
4252 { 4343 {
4253 base::HistogramTester histogram_tester; 4344 base::HistogramTester histogram_tester;
4254 base::UserActionTester user_action_tester; 4345 base::UserActionTester user_action_tester;
4255 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4346 autofill_manager_->SubmitForm(form, TimeTicks::Now());
4256 histogram_tester.ExpectUniqueSample( 4347 histogram_tester.ExpectUniqueSample(
4257 "Autofill.FormSubmittedState", 4348 "Autofill.FormSubmittedState",
4258 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL, 1); 4349 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL, 1);
4259 EXPECT_EQ(1, user_action_tester.GetActionCount( 4350 EXPECT_EQ(1, user_action_tester.GetActionCount(
4260 "Autofill_FormSubmitted_FilledAll")); 4351 "Autofill_FormSubmitted_FilledAll"));
4261 4352
4262 expected_form_submission_ukm_metrics.push_back( 4353 expected_form_submission_ukm_metrics.push_back(
4263 {{internal::kUKMAutofillFormSubmittedStateMetricName, 4354 {{internal::kUKMAutofillFormSubmittedStateMetricName,
4264 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL}, 4355 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL},
4265 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); 4356 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}});
4266 VerifyFormInteractionUkm(form, &test_ukm_recorder_, 4357 VerifyFormInteractionUkm(test_ukm_recorder_, form,
4267 internal::kUKMFormSubmittedEntryName, 4358 internal::kUKMFormSubmittedEntryName,
4268 expected_form_submission_ukm_metrics); 4359 expected_form_submission_ukm_metrics);
4360
4361 AppendFieldFillStatusUkm(form, &expected_field_fill_status_ukm_metrics);
4362 VerifyFormInteractionUkm(test_ukm_recorder_, form,
4363 internal::kUKMFieldFillStatusEntryName,
4364 expected_field_fill_status_ukm_metrics);
4269 } 4365 }
4270 4366
4271 // Clear out the third field's value. 4367 // Clear out the third field's value.
4272 form.fields[2].value = base::string16(); 4368 form.fields[2].value = base::string16();
4273 forms.front() = form; 4369 forms.front() = form;
4274 4370
4275 // Non fillable form. 4371 // Non fillable form.
4276 { 4372 {
4277 base::HistogramTester histogram_tester; 4373 base::HistogramTester histogram_tester;
4278 base::UserActionTester user_action_tester; 4374 base::UserActionTester user_action_tester;
4279 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4375 autofill_manager_->SubmitForm(form, TimeTicks::Now());
4280 histogram_tester.ExpectUniqueSample( 4376 histogram_tester.ExpectUniqueSample(
4281 "Autofill.FormSubmittedState", 4377 "Autofill.FormSubmittedState",
4282 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); 4378 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1);
4283 EXPECT_EQ(1, user_action_tester.GetActionCount( 4379 EXPECT_EQ(1, user_action_tester.GetActionCount(
4284 "Autofill_FormSubmitted_NonFillable")); 4380 "Autofill_FormSubmitted_NonFillable"));
4285 4381
4286 expected_form_submission_ukm_metrics.push_back( 4382 expected_form_submission_ukm_metrics.push_back(
4287 {{internal::kUKMAutofillFormSubmittedStateMetricName, 4383 {{internal::kUKMAutofillFormSubmittedStateMetricName,
4288 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, 4384 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA},
4289 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); 4385 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}});
4290 VerifyFormInteractionUkm(form, &test_ukm_recorder_, 4386 VerifyFormInteractionUkm(test_ukm_recorder_, form,
4291 internal::kUKMFormSubmittedEntryName, 4387 internal::kUKMFormSubmittedEntryName,
4292 expected_form_submission_ukm_metrics); 4388 expected_form_submission_ukm_metrics);
4389
4390 AppendFieldFillStatusUkm(form, &expected_field_fill_status_ukm_metrics);
4391 VerifyFormInteractionUkm(test_ukm_recorder_, form,
4392 internal::kUKMFieldFillStatusEntryName,
4393 expected_field_fill_status_ukm_metrics);
4293 } 4394 }
4294 } 4395 }
4295 4396
4296 // Verify that we correctly log user happiness metrics dealing with form 4397 // Verify that we correctly log user happiness metrics dealing with form
4297 // interaction. 4398 // interaction.
4298 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) { 4399 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) {
4299 // Load a fillable form. 4400 // Load a fillable form.
4300 FormData form; 4401 FormData form;
4301 form.name = ASCIIToUTF16("TestForm"); 4402 form.name = ASCIIToUTF16("TestForm");
4302 form.origin = GURL("http://example.com/form.html"); 4403 form.origin = GURL("http://example.com/form.html");
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
4392 base::HistogramTester histogram_tester; 4493 base::HistogramTester histogram_tester;
4393 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks()); 4494 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks());
4394 histogram_tester.ExpectUniqueSample( 4495 histogram_tester.ExpectUniqueSample(
4395 "Autofill.UserHappiness", 4496 "Autofill.UserHappiness",
4396 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD, 1); 4497 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD, 1);
4397 } 4498 }
4398 4499
4399 autofill_manager_->Reset(); 4500 autofill_manager_->Reset();
4400 4501
4401 VerifyFormInteractionUkm( 4502 VerifyFormInteractionUkm(
4402 form, &test_ukm_recorder_, internal::kUKMInteractedWithFormEntryName, 4503 test_ukm_recorder_, form, internal::kUKMInteractedWithFormEntryName,
4403 {{{internal::kUKMIsForCreditCardMetricName, false}, 4504 {{{internal::kUKMIsForCreditCardMetricName, false},
4404 {internal::kUKMLocalRecordTypeCountMetricName, 0}, 4505 {internal::kUKMLocalRecordTypeCountMetricName, 0},
4405 {internal::kUKMServerRecordTypeCountMetricName, 0}}}); 4506 {internal::kUKMServerRecordTypeCountMetricName, 0}}});
4406 VerifyFormInteractionUkm( 4507 VerifyFormInteractionUkm(
4407 form, &test_ukm_recorder_, internal::kUKMSuggestionsShownEntryName, 4508 test_ukm_recorder_, form, internal::kUKMSuggestionsShownEntryName,
4408 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}, 4509 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0},
4409 {internal::kUKMHeuristicTypeMetricName, PHONE_HOME_WHOLE_NUMBER}, 4510 {internal::kUKMHeuristicTypeMetricName, PHONE_HOME_WHOLE_NUMBER},
4410 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}, 4511 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED},
4411 {internal::kUKMServerTypeMetricName, NO_SERVER_DATA}}, 4512 {internal::kUKMServerTypeMetricName, NO_SERVER_DATA}},
4412 {{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}, 4513 {{internal::kUKMMillisecondsSinceFormParsedMetricName, 0},
4413 {internal::kUKMHeuristicTypeMetricName, EMAIL_ADDRESS}, 4514 {internal::kUKMHeuristicTypeMetricName, EMAIL_ADDRESS},
4414 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}, 4515 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED},
4415 {internal::kUKMServerTypeMetricName, NO_SERVER_DATA}}}); 4516 {internal::kUKMServerTypeMetricName, NO_SERVER_DATA}}});
4416 VerifyFormInteractionUkm( 4517 VerifyFormInteractionUkm(
4417 form, &test_ukm_recorder_, internal::kUKMSuggestionFilledEntryName, 4518 test_ukm_recorder_, form, internal::kUKMSuggestionFilledEntryName,
4418 {{{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE}, 4519 {{{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE},
4419 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, 4520 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}},
4420 {{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE}, 4521 {{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE},
4421 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 4522 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
4422 VerifyFormInteractionUkm( 4523 VerifyFormInteractionUkm(
4423 form, &test_ukm_recorder_, internal::kUKMTextFieldDidChangeEntryName, 4524 test_ukm_recorder_, form, internal::kUKMTextFieldDidChangeEntryName,
4424 {{{internal::kUKMFieldTypeGroupMetricName, NAME}, 4525 {{{internal::kUKMFieldTypeGroupMetricName, NAME},
4425 {internal::kUKMHeuristicTypeMetricName, NAME_FULL}, 4526 {internal::kUKMHeuristicTypeMetricName, NAME_FULL},
4426 {internal::kUKMServerTypeMetricName, NO_SERVER_DATA}, 4527 {internal::kUKMServerTypeMetricName, NO_SERVER_DATA},
4427 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}, 4528 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED},
4428 {internal::kUKMHtmlFieldModeMetricName, HTML_MODE_NONE}, 4529 {internal::kUKMHtmlFieldModeMetricName, HTML_MODE_NONE},
4429 {internal::kUKMIsAutofilledMetricName, false}, 4530 {internal::kUKMIsAutofilledMetricName, false},
4430 {internal::kUKMIsEmptyMetricName, true}, 4531 {internal::kUKMIsEmptyMetricName, true},
4431 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, 4532 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}},
4432 {{internal::kUKMFieldTypeGroupMetricName, NAME}, 4533 {{internal::kUKMFieldTypeGroupMetricName, NAME},
4433 {internal::kUKMHeuristicTypeMetricName, NAME_FULL}, 4534 {internal::kUKMHeuristicTypeMetricName, NAME_FULL},
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
5103 // Tests that no UKM is logged when the ukm service is null. 5204 // Tests that no UKM is logged when the ukm service is null.
5104 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmService) { 5205 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmService) {
5105 GURL url("https://www.google.com"); 5206 GURL url("https://www.google.com");
5106 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; 5207 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}};
5107 5208
5108 EXPECT_FALSE(AutofillMetrics::LogUkm(nullptr, url, "test_ukm", metrics)); 5209 EXPECT_FALSE(AutofillMetrics::LogUkm(nullptr, url, "test_ukm", metrics));
5109 ASSERT_EQ(0U, test_ukm_recorder_.sources_count()); 5210 ASSERT_EQ(0U, test_ukm_recorder_.sources_count());
5110 } 5211 }
5111 5212
5112 } // namespace autofill 5213 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698