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

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

Issue 2883563002: Refactor UKM interface for mojo-ification (Closed)
Patch Set: Fix uma_session_stats.cc Created 3 years, 7 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 16 matching lines...) Expand all
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
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 // PersonalDataManager to be around when it gets destroyed. 451 // PersonalDataManager to be around when it gets destroyed.
471 autofill_manager_.reset(); 452 autofill_manager_.reset();
472 autofill_driver_.reset(); 453 autofill_driver_.reset();
473 personal_data_.reset(); 454 personal_data_.reset();
474 signin_manager_->Shutdown(); 455 signin_manager_->Shutdown();
475 signin_manager_.reset(); 456 signin_manager_.reset();
476 account_tracker_->Shutdown(); 457 account_tracker_->Shutdown();
477 account_tracker_.reset(); 458 account_tracker_.reset();
478 signin_client_.reset(); 459 signin_client_.reset();
479 test::ReenableSystemServices(); 460 test::ReenableSystemServices();
480 autofill_client_.GetTestUkmService()->Purge(); 461 autofill_client_.GetTestUkmRecorder()->Purge();
481 } 462 }
482 463
483 void AutofillMetricsTest::EnableWalletSync() { 464 void AutofillMetricsTest::EnableWalletSync() {
484 signin_manager_->SetAuthenticatedAccountInfo("12345", "syncuser@example.com"); 465 signin_manager_->SetAuthenticatedAccountInfo("12345", "syncuser@example.com");
485 } 466 }
486 467
487 void AutofillMetricsTest::EnableUkmLogging() { 468 void AutofillMetricsTest::EnableUkmLogging() {
488 scoped_feature_list_.InitAndEnableFeature(kAutofillUkmLogging); 469 scoped_feature_list_.InitAndEnableFeature(kAutofillUkmLogging);
489 } 470 }
490 471
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 form.fields.push_back(field); 948 form.fields.push_back(field);
968 949
969 // No autocomplete attribute. No metric logged. 950 // No autocomplete attribute. No metric logged.
970 test::CreateTestFormField("Address", "address", "", "text", &field); 951 test::CreateTestFormField("Address", "address", "", "text", &field);
971 field.autocomplete_attribute = ""; 952 field.autocomplete_attribute = "";
972 form.fields.push_back(field); 953 form.fields.push_back(field);
973 954
974 std::unique_ptr<TestFormStructure> form_structure = 955 std::unique_ptr<TestFormStructure> form_structure =
975 base::MakeUnique<TestFormStructure>(form); 956 base::MakeUnique<TestFormStructure>(form);
976 TestFormStructure* form_structure_ptr = form_structure.get(); 957 TestFormStructure* form_structure_ptr = form_structure.get();
977 form_structure->DetermineHeuristicTypes(nullptr /* ukm_service */); 958 form_structure->DetermineHeuristicTypes(nullptr /* ukm_recorder */);
978 autofill_manager_->form_structures()->push_back(std::move(form_structure)); 959 autofill_manager_->form_structures()->push_back(std::move(form_structure));
979 960
980 AutofillQueryResponseContents response; 961 AutofillQueryResponseContents response;
981 // Server response will match with autocomplete. 962 // Server response will match with autocomplete.
982 response.add_field()->set_autofill_type(NAME_LAST); 963 response.add_field()->set_autofill_type(NAME_LAST);
983 // Server response will NOT match with autocomplete. 964 // Server response will NOT match with autocomplete.
984 response.add_field()->set_autofill_type(NAME_FIRST); 965 response.add_field()->set_autofill_type(NAME_FIRST);
985 // Server response will have no data. 966 // Server response will have no data.
986 response.add_field()->set_autofill_type(NO_SERVER_DATA); 967 response.add_field()->set_autofill_type(NO_SERVER_DATA);
987 // Not logged. 968 // Not logged.
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
1624 1605
1625 // Simulate form submission. 1606 // Simulate form submission.
1626 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 1607 autofill_manager_->SubmitForm(form, TimeTicks::Now());
1627 1608
1628 // An autofillable form was submitted, and the number of edited autofilled 1609 // An autofillable form was submitted, and the number of edited autofilled
1629 // fields is logged. 1610 // fields is logged.
1630 histogram_tester.ExpectUniqueSample( 1611 histogram_tester.ExpectUniqueSample(
1631 "Autofill.NumberOfEditedAutofilledFieldsAtSubmission", 2, 1); 1612 "Autofill.NumberOfEditedAutofilledFieldsAtSubmission", 2, 1);
1632 1613
1633 // UKM must not be logged unless enabled. 1614 // UKM must not be logged unless enabled.
1634 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 1615 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder();
1635 EXPECT_EQ(0U, ukm_service->sources_count()); 1616 EXPECT_EQ(0U, ukm_recorder->sources_count());
1636 EXPECT_EQ(0U, ukm_service->entries_count()); 1617 EXPECT_EQ(0U, ukm_recorder->entries_count());
1637 } 1618 }
1638 1619
1639 // Verify that when resetting the autofill manager (such as during a 1620 // Verify that when resetting the autofill manager (such as during a
1640 // navigation), the proper number of edited fields is logged. 1621 // navigation), the proper number of edited fields is logged.
1641 TEST_F(AutofillMetricsTest, NumberOfEditedAutofilledFields_NoSubmission) { 1622 TEST_F(AutofillMetricsTest, NumberOfEditedAutofilledFields_NoSubmission) {
1642 // Construct a fillable form. 1623 // Construct a fillable form.
1643 FormData form; 1624 FormData form;
1644 form.name = ASCIIToUTF16("TestForm"); 1625 form.name = ASCIIToUTF16("TestForm");
1645 form.origin = GURL("http://example.com/form.html"); 1626 form.origin = GURL("http://example.com/form.html");
1646 form.action = GURL("http://example.com/submit.html"); 1627 form.action = GURL("http://example.com/submit.html");
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1681 autofill_manager_->RunRunLoop(); 1662 autofill_manager_->RunRunLoop();
1682 1663
1683 // An autofillable form was uploaded, and the number of edited autofilled 1664 // An autofillable form was uploaded, and the number of edited autofilled
1684 // fields is logged. 1665 // fields is logged.
1685 histogram_tester.ExpectUniqueSample( 1666 histogram_tester.ExpectUniqueSample(
1686 "Autofill.NumberOfEditedAutofilledFieldsAtSubmission.NoSubmission", 1, 1); 1667 "Autofill.NumberOfEditedAutofilledFieldsAtSubmission.NoSubmission", 1, 1);
1687 } 1668 }
1688 1669
1689 // Verify that we correctly log metrics regarding developer engagement. 1670 // Verify that we correctly log metrics regarding developer engagement.
1690 TEST_F(AutofillMetricsTest, DeveloperEngagement) { 1671 TEST_F(AutofillMetricsTest, DeveloperEngagement) {
1691 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 1672 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder();
1692 1673
1693 // Start with a non-fillable form. 1674 // Start with a non-fillable form.
1694 FormData form; 1675 FormData form;
1695 form.name = ASCIIToUTF16("TestForm"); 1676 form.name = ASCIIToUTF16("TestForm");
1696 form.origin = GURL("http://example.com/form.html"); 1677 form.origin = GURL("http://example.com/form.html");
1697 form.action = GURL("http://example.com/submit.html"); 1678 form.action = GURL("http://example.com/submit.html");
1698 1679
1699 FormFieldData field; 1680 FormFieldData field;
1700 test::CreateTestFormField("Name", "name", "", "text", &field); 1681 test::CreateTestFormField("Name", "name", "", "text", &field);
1701 form.fields.push_back(field); 1682 form.fields.push_back(field);
1702 test::CreateTestFormField("Email", "email", "", "text", &field); 1683 test::CreateTestFormField("Email", "email", "", "text", &field);
1703 form.fields.push_back(field); 1684 form.fields.push_back(field);
1704 1685
1705 std::vector<FormData> forms(1, form); 1686 std::vector<FormData> forms(1, form);
1706 1687
1707 // Ensure no metrics are logged when loading a non-fillable form. 1688 // Ensure no metrics are logged when loading a non-fillable form.
1708 { 1689 {
1709 base::HistogramTester histogram_tester; 1690 base::HistogramTester histogram_tester;
1710 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 1691 autofill_manager_->OnFormsSeen(forms, TimeTicks());
1711 autofill_manager_->Reset(); 1692 autofill_manager_->Reset();
1712 histogram_tester.ExpectTotalCount("Autofill.DeveloperEngagement", 0); 1693 histogram_tester.ExpectTotalCount("Autofill.DeveloperEngagement", 0);
1713 1694
1714 // UKM must not be logged unless enabled. 1695 // UKM must not be logged unless enabled.
1715 EXPECT_EQ(0U, ukm_service->sources_count()); 1696 EXPECT_EQ(0U, ukm_recorder->sources_count());
1716 EXPECT_EQ(0U, ukm_service->entries_count()); 1697 EXPECT_EQ(0U, ukm_recorder->entries_count());
1717 } 1698 }
1718 1699
1719 // Add another field to the form, so that it becomes fillable. 1700 // Add another field to the form, so that it becomes fillable.
1720 test::CreateTestFormField("Phone", "phone", "", "text", &field); 1701 test::CreateTestFormField("Phone", "phone", "", "text", &field);
1721 forms.back().fields.push_back(field); 1702 forms.back().fields.push_back(field);
1722 1703
1723 // Expect the "form parsed without hints" metric to be logged. 1704 // Expect the "form parsed without hints" metric to be logged.
1724 { 1705 {
1725 base::HistogramTester histogram_tester; 1706 base::HistogramTester histogram_tester;
1726 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 1707 autofill_manager_->OnFormsSeen(forms, TimeTicks());
1727 autofill_manager_->Reset(); 1708 autofill_manager_->Reset();
1728 histogram_tester.ExpectUniqueSample( 1709 histogram_tester.ExpectUniqueSample(
1729 "Autofill.DeveloperEngagement", 1710 "Autofill.DeveloperEngagement",
1730 AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS, 1); 1711 AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS, 1);
1731 1712
1732 // UKM must not be logged unless enabled. 1713 // UKM must not be logged unless enabled.
1733 EXPECT_EQ(0U, ukm_service->sources_count()); 1714 EXPECT_EQ(0U, ukm_recorder->sources_count());
1734 EXPECT_EQ(0U, ukm_service->entries_count()); 1715 EXPECT_EQ(0U, ukm_recorder->entries_count());
1735 } 1716 }
1736 1717
1737 // Add some fields with an author-specified field type to the form. 1718 // Add some fields with an author-specified field type to the form.
1738 // We need to add at least three fields, because a form must have at least 1719 // We need to add at least three fields, because a form must have at least
1739 // three fillable fields to be considered to be autofillable; and if at least 1720 // three fillable fields to be considered to be autofillable; and if at least
1740 // one field specifies an explicit type hint, we don't apply any of our usual 1721 // one field specifies an explicit type hint, we don't apply any of our usual
1741 // local heuristics to detect field types in the rest of the form. 1722 // local heuristics to detect field types in the rest of the form.
1742 test::CreateTestFormField("", "", "", "text", &field); 1723 test::CreateTestFormField("", "", "", "text", &field);
1743 field.autocomplete_attribute = "given-name"; 1724 field.autocomplete_attribute = "given-name";
1744 forms.back().fields.push_back(field); 1725 forms.back().fields.push_back(field);
1745 test::CreateTestFormField("", "", "", "text", &field); 1726 test::CreateTestFormField("", "", "", "text", &field);
1746 field.autocomplete_attribute = "email"; 1727 field.autocomplete_attribute = "email";
1747 forms.back().fields.push_back(field); 1728 forms.back().fields.push_back(field);
1748 test::CreateTestFormField("", "", "", "text", &field); 1729 test::CreateTestFormField("", "", "", "text", &field);
1749 field.autocomplete_attribute = "address-line1"; 1730 field.autocomplete_attribute = "address-line1";
1750 forms.back().fields.push_back(field); 1731 forms.back().fields.push_back(field);
1751 1732
1752 // Expect the "form parsed with field type hints" metric to be logged. 1733 // Expect the "form parsed with field type hints" metric to be logged.
1753 { 1734 {
1754 base::HistogramTester histogram_tester; 1735 base::HistogramTester histogram_tester;
1755 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 1736 autofill_manager_->OnFormsSeen(forms, TimeTicks());
1756 autofill_manager_->Reset(); 1737 autofill_manager_->Reset();
1757 histogram_tester.ExpectBucketCount( 1738 histogram_tester.ExpectBucketCount(
1758 "Autofill.DeveloperEngagement", 1739 "Autofill.DeveloperEngagement",
1759 AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS, 1); 1740 AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS, 1);
1760 1741
1761 // UKM must not be logged unless enabled. 1742 // UKM must not be logged unless enabled.
1762 EXPECT_EQ(0U, ukm_service->sources_count()); 1743 EXPECT_EQ(0U, ukm_recorder->sources_count());
1763 EXPECT_EQ(0U, ukm_service->entries_count()); 1744 EXPECT_EQ(0U, ukm_recorder->entries_count());
1764 1745
1765 histogram_tester.ExpectBucketCount( 1746 histogram_tester.ExpectBucketCount(
1766 "Autofill.DeveloperEngagement", 1747 "Autofill.DeveloperEngagement",
1767 AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT, 0); 1748 AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT, 0);
1768 } 1749 }
1769 1750
1770 // Add a field with an author-specified UPI-VPA field type in the form. 1751 // Add a field with an author-specified UPI-VPA field type in the form.
1771 test::CreateTestFormField("", "", "", "text", &field); 1752 test::CreateTestFormField("", "", "", "text", &field);
1772 field.autocomplete_attribute = "upi-vpa"; 1753 field.autocomplete_attribute = "upi-vpa";
1773 forms.back().fields.push_back(field); 1754 forms.back().fields.push_back(field);
(...skipping 11 matching lines...) Expand all
1785 "Autofill.DeveloperEngagement", 1766 "Autofill.DeveloperEngagement",
1786 AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT, 1); 1767 AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT, 1);
1787 } 1768 }
1788 } 1769 }
1789 1770
1790 // Verify that we correctly log UKM for form parsed without type hints regarding 1771 // Verify that we correctly log UKM for form parsed without type hints regarding
1791 // developer engagement. 1772 // developer engagement.
1792 TEST_F(AutofillMetricsTest, 1773 TEST_F(AutofillMetricsTest,
1793 UkmDeveloperEngagement_LogFillableFormParsedWithoutTypeHints) { 1774 UkmDeveloperEngagement_LogFillableFormParsedWithoutTypeHints) {
1794 EnableUkmLogging(); 1775 EnableUkmLogging();
1795 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 1776 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder();
1796 1777
1797 // Start with a non-fillable form. 1778 // Start with a non-fillable form.
1798 FormData form; 1779 FormData form;
1799 form.name = ASCIIToUTF16("TestForm"); 1780 form.name = ASCIIToUTF16("TestForm");
1800 form.origin = GURL("http://example.com/form.html"); 1781 form.origin = GURL("http://example.com/form.html");
1801 form.action = GURL("http://example.com/submit.html"); 1782 form.action = GURL("http://example.com/submit.html");
1802 1783
1803 FormFieldData field; 1784 FormFieldData field;
1804 test::CreateTestFormField("Name", "name", "", "text", &field); 1785 test::CreateTestFormField("Name", "name", "", "text", &field);
1805 form.fields.push_back(field); 1786 form.fields.push_back(field);
1806 test::CreateTestFormField("Email", "email", "", "text", &field); 1787 test::CreateTestFormField("Email", "email", "", "text", &field);
1807 form.fields.push_back(field); 1788 form.fields.push_back(field);
1808 1789
1809 std::vector<FormData> forms(1, form); 1790 std::vector<FormData> forms(1, form);
1810 1791
1811 // Ensure no metrics are logged when loading a non-fillable form. 1792 // Ensure no metrics are logged when loading a non-fillable form.
1812 { 1793 {
1813 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); 1794 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now());
1814 autofill_manager_->Reset(); 1795 autofill_manager_->Reset();
1815 1796
1816 EXPECT_EQ(0U, ukm_service->sources_count()); 1797 EXPECT_EQ(0U, ukm_recorder->sources_count());
1817 EXPECT_EQ(0U, ukm_service->entries_count()); 1798 EXPECT_EQ(0U, ukm_recorder->entries_count());
1818 } 1799 }
1819 1800
1820 // Add another field to the form, so that it becomes fillable. 1801 // Add another field to the form, so that it becomes fillable.
1821 test::CreateTestFormField("Phone", "phone", "", "text", &field); 1802 test::CreateTestFormField("Phone", "phone", "", "text", &field);
1822 forms.back().fields.push_back(field); 1803 forms.back().fields.push_back(field);
1823 1804
1824 // Expect the "form parsed without field type hints" metric and the 1805 // Expect the "form parsed without field type hints" metric and the
1825 // "form loaded" form interaction event to be logged. 1806 // "form loaded" form interaction event to be logged.
1826 { 1807 {
1827 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); 1808 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now());
1828 autofill_manager_->Reset(); 1809 autofill_manager_->Reset();
1829 1810
1830 ASSERT_EQ(1U, ukm_service->entries_count()); 1811 ASSERT_EQ(1U, ukm_recorder->entries_count());
1831 ASSERT_EQ(1U, ukm_service->sources_count()); 1812 ASSERT_EQ(1U, ukm_recorder->sources_count());
1832 VerifyDeveloperEngagementUkm( 1813 VerifyDeveloperEngagementUkm(
1833 form, ukm_service, 1814 form, ukm_recorder,
1834 {AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS}); 1815 {AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS});
1835 } 1816 }
1836 } 1817 }
1837 1818
1838 // Verify that we correctly log UKM for form parsed with type hints regarding 1819 // Verify that we correctly log UKM for form parsed with type hints regarding
1839 // developer engagement. 1820 // developer engagement.
1840 TEST_F(AutofillMetricsTest, 1821 TEST_F(AutofillMetricsTest,
1841 UkmDeveloperEngagement_LogFillableFormParsedWithTypeHints) { 1822 UkmDeveloperEngagement_LogFillableFormParsedWithTypeHints) {
1842 EnableUkmLogging(); 1823 EnableUkmLogging();
1843 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 1824 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder();
1844 1825
1845 FormData form; 1826 FormData form;
1846 form.name = ASCIIToUTF16("TestForm"); 1827 form.name = ASCIIToUTF16("TestForm");
1847 form.origin = GURL("http://example.com/form.html"); 1828 form.origin = GURL("http://example.com/form.html");
1848 form.action = GURL("http://example.com/submit.html"); 1829 form.action = GURL("http://example.com/submit.html");
1849 1830
1850 FormFieldData field; 1831 FormFieldData field;
1851 test::CreateTestFormField("Name", "name", "", "text", &field); 1832 test::CreateTestFormField("Name", "name", "", "text", &field);
1852 form.fields.push_back(field); 1833 form.fields.push_back(field);
1853 test::CreateTestFormField("Email", "email", "", "text", &field); 1834 test::CreateTestFormField("Email", "email", "", "text", &field);
(...skipping 19 matching lines...) Expand all
1873 test::CreateTestFormField("", "", "", "text", &field); 1854 test::CreateTestFormField("", "", "", "text", &field);
1874 field.autocomplete_attribute = "address-line1"; 1855 field.autocomplete_attribute = "address-line1";
1875 forms.back().fields.push_back(field); 1856 forms.back().fields.push_back(field);
1876 1857
1877 // Expect the "form parsed without field type hints" metric and the 1858 // Expect the "form parsed without field type hints" metric and the
1878 // "form loaded" form interaction event to be logged. 1859 // "form loaded" form interaction event to be logged.
1879 { 1860 {
1880 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); 1861 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now());
1881 autofill_manager_->Reset(); 1862 autofill_manager_->Reset();
1882 1863
1883 ASSERT_EQ(1U, ukm_service->entries_count()); 1864 ASSERT_EQ(1U, ukm_recorder->entries_count());
1884 ASSERT_EQ(1U, ukm_service->sources_count()); 1865 ASSERT_EQ(1U, ukm_recorder->sources_count());
1885 VerifyDeveloperEngagementUkm( 1866 VerifyDeveloperEngagementUkm(
1886 form, ukm_service, 1867 form, ukm_recorder,
1887 {AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS}); 1868 {AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS});
1888 } 1869 }
1889 } 1870 }
1890 1871
1891 // Verify that we correctly log UKM for form parsed with type hints regarding 1872 // Verify that we correctly log UKM for form parsed with type hints regarding
1892 // developer engagement. 1873 // developer engagement.
1893 TEST_F(AutofillMetricsTest, UkmDeveloperEngagement_LogUpiVpaTypeHint) { 1874 TEST_F(AutofillMetricsTest, UkmDeveloperEngagement_LogUpiVpaTypeHint) {
1894 EnableUkmLogging(); 1875 EnableUkmLogging();
1895 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 1876 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder();
1896 1877
1897 FormData form; 1878 FormData form;
1898 form.name = ASCIIToUTF16("TestForm"); 1879 form.name = ASCIIToUTF16("TestForm");
1899 form.origin = GURL("http://example.com/form.html"); 1880 form.origin = GURL("http://example.com/form.html");
1900 form.action = GURL("http://example.com/submit.html"); 1881 form.action = GURL("http://example.com/submit.html");
1901 1882
1902 FormFieldData field; 1883 FormFieldData field;
1903 test::CreateTestFormField("Name", "name", "", "text", &field); 1884 test::CreateTestFormField("Name", "name", "", "text", &field);
1904 form.fields.push_back(field); 1885 form.fields.push_back(field);
1905 test::CreateTestFormField("Email", "email", "", "text", &field); 1886 test::CreateTestFormField("Email", "email", "", "text", &field);
1906 form.fields.push_back(field); 1887 form.fields.push_back(field);
1907 test::CreateTestFormField("Payment", "payment", "", "text", &field); 1888 test::CreateTestFormField("Payment", "payment", "", "text", &field);
1908 field.autocomplete_attribute = "upi-vpa"; 1889 field.autocomplete_attribute = "upi-vpa";
1909 form.fields.push_back(field); 1890 form.fields.push_back(field);
1910 1891
1911 std::vector<FormData> forms(1, form); 1892 std::vector<FormData> forms(1, form);
1912 1893
1913 // Expect the "upi-vpa hint" metric to be logged and the "form loaded" form 1894 // Expect the "upi-vpa hint" metric to be logged and the "form loaded" form
1914 // interaction event to be logged. 1895 // interaction event to be logged.
1915 { 1896 {
1916 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); 1897 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now());
1917 autofill_manager_->Reset(); 1898 autofill_manager_->Reset();
1918 1899
1919 ASSERT_EQ(1U, ukm_service->entries_count()); 1900 ASSERT_EQ(1U, ukm_recorder->entries_count());
1920 ASSERT_EQ(1U, ukm_service->sources_count()); 1901 ASSERT_EQ(1U, ukm_recorder->sources_count());
1921 VerifyDeveloperEngagementUkm(form, ukm_service, 1902 VerifyDeveloperEngagementUkm(form, ukm_recorder,
1922 {AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT}); 1903 {AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT});
1923 ukm_service->Purge(); 1904 ukm_recorder->Purge();
1924 } 1905 }
1925 1906
1926 // Add another field with an author-specified field type to the form. 1907 // Add another field with an author-specified field type to the form.
1927 test::CreateTestFormField("", "", "", "text", &field); 1908 test::CreateTestFormField("", "", "", "text", &field);
1928 field.autocomplete_attribute = "address-line1"; 1909 field.autocomplete_attribute = "address-line1";
1929 forms.back().fields.push_back(field); 1910 forms.back().fields.push_back(field);
1930 1911
1931 { 1912 {
1932 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); 1913 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now());
1933 autofill_manager_->Reset(); 1914 autofill_manager_->Reset();
1934 1915
1935 VerifyDeveloperEngagementUkm( 1916 VerifyDeveloperEngagementUkm(
1936 form, ukm_service, 1917 form, ukm_recorder,
1937 {AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS, 1918 {AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS,
1938 AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT}); 1919 AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT});
1939 } 1920 }
1940 } 1921 }
1941 1922
1942 // Test that the profile count is logged correctly. 1923 // Test that the profile count is logged correctly.
1943 TEST_F(AutofillMetricsTest, StoredProfileCount) { 1924 TEST_F(AutofillMetricsTest, StoredProfileCount) {
1944 // The metric should be logged when the profiles are first loaded. 1925 // The metric should be logged when the profiles are first loaded.
1945 { 1926 {
1946 base::HistogramTester histogram_tester; 1927 base::HistogramTester histogram_tester;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
2112 form.fields[0].is_autofilled = true; 2093 form.fields[0].is_autofilled = true;
2113 base::HistogramTester histogram_tester; 2094 base::HistogramTester histogram_tester;
2114 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 2095 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2115 histogram_tester.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0); 2096 histogram_tester.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0);
2116 } 2097 }
2117 } 2098 }
2118 2099
2119 // Test that the credit card checkout flow user actions are correctly logged. 2100 // Test that the credit card checkout flow user actions are correctly logged.
2120 TEST_F(AutofillMetricsTest, CreditCardCheckoutFlowUserActions) { 2101 TEST_F(AutofillMetricsTest, CreditCardCheckoutFlowUserActions) {
2121 EnableUkmLogging(); 2102 EnableUkmLogging();
2122 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 2103 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder();
2123 2104
2124 personal_data_->RecreateCreditCards( 2105 personal_data_->RecreateCreditCards(
2125 true /* include_local_credit_card */, 2106 true /* include_local_credit_card */,
2126 false /* include_masked_server_credit_card */, 2107 false /* include_masked_server_credit_card */,
2127 false /* include_full_server_credit_card */); 2108 false /* include_full_server_credit_card */);
2128 2109
2129 // Set up our form data. 2110 // Set up our form data.
2130 FormData form; 2111 FormData form;
2131 form.name = ASCIIToUTF16("TestForm"); 2112 form.name = ASCIIToUTF16("TestForm");
2132 form.origin = GURL("http://example.com/form.html"); 2113 form.origin = GURL("http://example.com/form.html");
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2191 base::UserActionTester user_action_tester; 2172 base::UserActionTester user_action_tester;
2192 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 2173 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2193 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 2174 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2194 EXPECT_EQ(1, 2175 EXPECT_EQ(1,
2195 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); 2176 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm"));
2196 EXPECT_EQ(1, user_action_tester.GetActionCount( 2177 EXPECT_EQ(1, user_action_tester.GetActionCount(
2197 "Autofill_FormSubmitted_NonFillable")); 2178 "Autofill_FormSubmitted_NonFillable"));
2198 } 2179 }
2199 2180
2200 VerifyFormInteractionUkm( 2181 VerifyFormInteractionUkm(
2201 form, ukm_service, internal::kUKMSuggestionsShownEntryName, 2182 form, ukm_recorder, internal::kUKMSuggestionsShownEntryName,
2202 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 2183 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
2203 // Expect 2 |FORM_EVENT_LOCAL_SUGGESTION_FILLED| events. First, from 2184 // Expect 2 |FORM_EVENT_LOCAL_SUGGESTION_FILLED| events. First, from
2204 // call to |external_delegate_->DidAcceptSuggestion|. Second, from call to 2185 // call to |external_delegate_->DidAcceptSuggestion|. Second, from call to
2205 // |autofill_manager_->FillOrPreviewForm|. 2186 // |autofill_manager_->FillOrPreviewForm|.
2206 VerifyFormInteractionUkm( 2187 VerifyFormInteractionUkm(
2207 form, ukm_service, internal::kUKMSuggestionFilledEntryName, 2188 form, ukm_recorder, internal::kUKMSuggestionFilledEntryName,
2208 {{{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD}, 2189 {{{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD},
2209 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, 2190 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}},
2210 {{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD}, 2191 {{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD},
2211 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 2192 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
2212 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState| 2193 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState|
2213 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|. 2194 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|.
2214 VerifySubmitFormUkm(form, ukm_service, 2195 VerifySubmitFormUkm(form, ukm_recorder,
2215 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); 2196 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA);
2216 } 2197 }
2217 2198
2218 // Test that the profile checkout flow user actions are correctly logged. 2199 // Test that the profile checkout flow user actions are correctly logged.
2219 TEST_F(AutofillMetricsTest, ProfileCheckoutFlowUserActions) { 2200 TEST_F(AutofillMetricsTest, ProfileCheckoutFlowUserActions) {
2220 EnableUkmLogging(); 2201 EnableUkmLogging();
2221 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 2202 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder();
2222 2203
2223 // Create a profile. 2204 // Create a profile.
2224 personal_data_->RecreateProfile(); 2205 personal_data_->RecreateProfile();
2225 2206
2226 // Set up our form data. 2207 // Set up our form data.
2227 FormData form; 2208 FormData form;
2228 form.name = ASCIIToUTF16("TestForm"); 2209 form.name = ASCIIToUTF16("TestForm");
2229 form.origin = GURL("http://example.com/form.html"); 2210 form.origin = GURL("http://example.com/form.html");
2230 form.action = GURL("http://example.com/submit.html"); 2211 form.action = GURL("http://example.com/submit.html");
2231 2212
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2288 base::UserActionTester user_action_tester; 2269 base::UserActionTester user_action_tester;
2289 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 2270 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2290 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 2271 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2291 EXPECT_EQ(1, 2272 EXPECT_EQ(1,
2292 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); 2273 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm"));
2293 EXPECT_EQ(1, user_action_tester.GetActionCount( 2274 EXPECT_EQ(1, user_action_tester.GetActionCount(
2294 "Autofill_FormSubmitted_NonFillable")); 2275 "Autofill_FormSubmitted_NonFillable"));
2295 } 2276 }
2296 2277
2297 VerifyFormInteractionUkm( 2278 VerifyFormInteractionUkm(
2298 form, ukm_service, internal::kUKMSuggestionsShownEntryName, 2279 form, ukm_recorder, internal::kUKMSuggestionsShownEntryName,
2299 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 2280 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
2300 // Expect 2 |FORM_EVENT_LOCAL_SUGGESTION_FILLED| events. First, from 2281 // Expect 2 |FORM_EVENT_LOCAL_SUGGESTION_FILLED| events. First, from
2301 // call to |external_delegate_->DidAcceptSuggestion|. Second, from call to 2282 // call to |external_delegate_->DidAcceptSuggestion|. Second, from call to
2302 // |autofill_manager_->FillOrPreviewForm|. 2283 // |autofill_manager_->FillOrPreviewForm|.
2303 VerifyFormInteractionUkm( 2284 VerifyFormInteractionUkm(
2304 form, ukm_service, internal::kUKMSuggestionFilledEntryName, 2285 form, ukm_recorder, internal::kUKMSuggestionFilledEntryName,
2305 {{{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE}, 2286 {{{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE},
2306 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, 2287 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}},
2307 {{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE}, 2288 {{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE},
2308 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 2289 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
2309 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState| 2290 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState|
2310 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|. 2291 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|.
2311 VerifySubmitFormUkm(form, ukm_service, 2292 VerifySubmitFormUkm(form, ukm_recorder,
2312 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); 2293 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA);
2313 } 2294 }
2314 2295
2315 // Tests that the Autofill_PolledCreditCardSuggestions user action is only 2296 // Tests that the Autofill_PolledCreditCardSuggestions user action is only
2316 // logged once if the field is queried repeatedly. 2297 // logged once if the field is queried repeatedly.
2317 TEST_F(AutofillMetricsTest, PolledCreditCardSuggestions_DebounceLogs) { 2298 TEST_F(AutofillMetricsTest, PolledCreditCardSuggestions_DebounceLogs) {
2318 personal_data_->RecreateCreditCards( 2299 personal_data_->RecreateCreditCards(
2319 true /* include_local_credit_card */, 2300 true /* include_local_credit_card */,
2320 false /* include_masked_server_credit_card */, 2301 false /* include_masked_server_credit_card */,
2321 false /* include_full_server_credit_card */); 2302 false /* include_full_server_credit_card */);
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
2594 field); 2575 field);
2595 histogram_tester.ExpectBucketCount( 2576 histogram_tester.ExpectBucketCount(
2596 "Autofill.FormEvents.CreditCard", 2577 "Autofill.FormEvents.CreditCard",
2597 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN, 0); 2578 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN, 0);
2598 histogram_tester.ExpectBucketCount( 2579 histogram_tester.ExpectBucketCount(
2599 "Autofill.FormEvents.CreditCard", 2580 "Autofill.FormEvents.CreditCard",
2600 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 0); 2581 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 0);
2601 } 2582 }
2602 2583
2603 // UKM must not be logged unless enabled. 2584 // UKM must not be logged unless enabled.
2604 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 2585 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder();
2605 EXPECT_EQ(0U, ukm_service->sources_count()); 2586 EXPECT_EQ(0U, ukm_recorder->sources_count());
2606 EXPECT_EQ(0U, ukm_service->entries_count()); 2587 EXPECT_EQ(0U, ukm_recorder->entries_count());
2607 } 2588 }
2608 2589
2609 // Test that we log selected form event for credit cards. 2590 // Test that we log selected form event for credit cards.
2610 TEST_F(AutofillMetricsTest, CreditCardSelectedFormEvents) { 2591 TEST_F(AutofillMetricsTest, CreditCardSelectedFormEvents) {
2611 EnableWalletSync(); 2592 EnableWalletSync();
2612 // Creating all kinds of cards. 2593 // Creating all kinds of cards.
2613 personal_data_->RecreateCreditCards( 2594 personal_data_->RecreateCreditCards(
2614 true /* include_local_credit_card */, 2595 true /* include_local_credit_card */,
2615 true /* include_masked_server_credit_card */, 2596 true /* include_masked_server_credit_card */,
2616 true /* include_full_server_credit_card */); 2597 true /* include_full_server_credit_card */);
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
2864 histogram_tester.ExpectTotalCount( 2845 histogram_tester.ExpectTotalCount(
2865 "Autofill.UnmaskPrompt.GetRealPanDuration", 1); 2846 "Autofill.UnmaskPrompt.GetRealPanDuration", 1);
2866 histogram_tester.ExpectTotalCount( 2847 histogram_tester.ExpectTotalCount(
2867 "Autofill.UnmaskPrompt.GetRealPanDuration.Failure", 1); 2848 "Autofill.UnmaskPrompt.GetRealPanDuration.Failure", 1);
2868 } 2849 }
2869 } 2850 }
2870 2851
2871 // Test that we log submitted form events for credit cards. 2852 // Test that we log submitted form events for credit cards.
2872 TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) { 2853 TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) {
2873 EnableUkmLogging(); 2854 EnableUkmLogging();
2874 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 2855 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder();
2875 2856
2876 EnableWalletSync(); 2857 EnableWalletSync();
2877 // Creating all kinds of cards. 2858 // Creating all kinds of cards.
2878 personal_data_->RecreateCreditCards( 2859 personal_data_->RecreateCreditCards(
2879 true /* include_local_credit_card */, 2860 true /* include_local_credit_card */,
2880 true /* include_masked_server_credit_card */, 2861 true /* include_masked_server_credit_card */,
2881 true /* include_full_server_credit_card */); 2862 true /* include_full_server_credit_card */);
2882 // Set up our form data. 2863 // Set up our form data.
2883 FormData form; 2864 FormData form;
2884 form.name = ASCIIToUTF16("TestForm"); 2865 form.name = ASCIIToUTF16("TestForm");
(...skipping 21 matching lines...) Expand all
2906 base::HistogramTester histogram_tester; 2887 base::HistogramTester histogram_tester;
2907 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 2888 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2908 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 2889 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2909 histogram_tester.ExpectBucketCount( 2890 histogram_tester.ExpectBucketCount(
2910 "Autofill.FormEvents.CreditCard", 2891 "Autofill.FormEvents.CreditCard",
2911 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); 2892 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2912 histogram_tester.ExpectBucketCount( 2893 histogram_tester.ExpectBucketCount(
2913 "Autofill.FormEvents.CreditCard", 2894 "Autofill.FormEvents.CreditCard",
2914 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); 2895 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
2915 2896
2916 VerifySubmitFormUkm(form, ukm_service, 2897 VerifySubmitFormUkm(form, ukm_recorder,
2917 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); 2898 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA);
2918 } 2899 }
2919 2900
2920 // Reset the autofill manager state and purge UKM logs. 2901 // Reset the autofill manager state and purge UKM logs.
2921 autofill_manager_->Reset(); 2902 autofill_manager_->Reset();
2922 ukm_service->Purge(); 2903 ukm_recorder->Purge();
2923 2904
2924 autofill_manager_->AddSeenForm(form, field_types, field_types); 2905 autofill_manager_->AddSeenForm(form, field_types, field_types);
2925 2906
2926 { 2907 {
2927 // Simulating submission with suggestion shown. 2908 // Simulating submission with suggestion shown.
2928 base::HistogramTester histogram_tester; 2909 base::HistogramTester histogram_tester;
2929 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); 2910 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field);
2930 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 2911 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2931 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 2912 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2932 histogram_tester.ExpectBucketCount( 2913 histogram_tester.ExpectBucketCount(
2933 "Autofill.FormEvents.CreditCard", 2914 "Autofill.FormEvents.CreditCard",
2934 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_SUBMITTED_ONCE, 1); 2915 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_SUBMITTED_ONCE, 1);
2935 histogram_tester.ExpectBucketCount( 2916 histogram_tester.ExpectBucketCount(
2936 "Autofill.FormEvents.CreditCard", 2917 "Autofill.FormEvents.CreditCard",
2937 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 1); 2918 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 1);
2938 2919
2939 VerifyFormInteractionUkm( 2920 VerifyFormInteractionUkm(
2940 form, ukm_service, internal::kUKMSuggestionsShownEntryName, 2921 form, ukm_recorder, internal::kUKMSuggestionsShownEntryName,
2941 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 2922 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
2942 VerifySubmitFormUkm(form, ukm_service, 2923 VerifySubmitFormUkm(form, ukm_recorder,
2943 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); 2924 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA);
2944 } 2925 }
2945 2926
2946 // Reset the autofill manager state and purge UKM logs. 2927 // Reset the autofill manager state and purge UKM logs.
2947 autofill_manager_->Reset(); 2928 autofill_manager_->Reset();
2948 ukm_service->Purge(); 2929 ukm_recorder->Purge();
2949 2930
2950 autofill_manager_->AddSeenForm(form, field_types, field_types); 2931 autofill_manager_->AddSeenForm(form, field_types, field_types);
2951 2932
2952 { 2933 {
2953 // Simulating submission with filled local data. 2934 // Simulating submission with filled local data.
2954 base::HistogramTester histogram_tester; 2935 base::HistogramTester histogram_tester;
2955 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 2936 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2956 std::string guid("10000000-0000-0000-0000-000000000001"); // local card 2937 std::string guid("10000000-0000-0000-0000-000000000001"); // local card
2957 autofill_manager_->FillOrPreviewForm( 2938 autofill_manager_->FillOrPreviewForm(
2958 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), 2939 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
2959 autofill_manager_->MakeFrontendID(guid, std::string())); 2940 autofill_manager_->MakeFrontendID(guid, std::string()));
2960 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 2941 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2961 histogram_tester.ExpectBucketCount( 2942 histogram_tester.ExpectBucketCount(
2962 "Autofill.FormEvents.CreditCard", 2943 "Autofill.FormEvents.CreditCard",
2963 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 1); 2944 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2964 histogram_tester.ExpectBucketCount( 2945 histogram_tester.ExpectBucketCount(
2965 "Autofill.FormEvents.CreditCard", 2946 "Autofill.FormEvents.CreditCard",
2966 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 1); 2947 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 1);
2967 2948
2968 VerifyFormInteractionUkm( 2949 VerifyFormInteractionUkm(
2969 form, ukm_service, internal::kUKMSuggestionFilledEntryName, 2950 form, ukm_recorder, internal::kUKMSuggestionFilledEntryName,
2970 {{{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD}, 2951 {{{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD},
2971 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 2952 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
2972 VerifySubmitFormUkm(form, ukm_service, 2953 VerifySubmitFormUkm(form, ukm_recorder,
2973 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); 2954 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA);
2974 } 2955 }
2975 2956
2976 // Reset the autofill manager state and purge UKM logs. 2957 // Reset the autofill manager state and purge UKM logs.
2977 autofill_manager_->Reset(); 2958 autofill_manager_->Reset();
2978 ukm_service->Purge(); 2959 ukm_recorder->Purge();
2979 2960
2980 autofill_manager_->AddSeenForm(form, field_types, field_types); 2961 autofill_manager_->AddSeenForm(form, field_types, field_types);
2981 2962
2982 { 2963 {
2983 // Simulating submission with filled server data. 2964 // Simulating submission with filled server data.
2984 base::HistogramTester histogram_tester; 2965 base::HistogramTester histogram_tester;
2985 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 2966 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2986 std::string guid( 2967 std::string guid(
2987 "10000000-0000-0000-0000-000000000003"); // full server card 2968 "10000000-0000-0000-0000-000000000003"); // full server card
2988 autofill_manager_->FillOrPreviewForm( 2969 autofill_manager_->FillOrPreviewForm(
2989 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), 2970 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
2990 autofill_manager_->MakeFrontendID(guid, std::string())); 2971 autofill_manager_->MakeFrontendID(guid, std::string()));
2991 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 2972 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2992 histogram_tester.ExpectBucketCount( 2973 histogram_tester.ExpectBucketCount(
2993 "Autofill.FormEvents.CreditCard", 2974 "Autofill.FormEvents.CreditCard",
2994 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 1); 2975 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2995 histogram_tester.ExpectBucketCount( 2976 histogram_tester.ExpectBucketCount(
2996 "Autofill.FormEvents.CreditCard", 2977 "Autofill.FormEvents.CreditCard",
2997 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 1); 2978 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 1);
2998 2979
2999 VerifyFormInteractionUkm( 2980 VerifyFormInteractionUkm(
3000 form, ukm_service, internal::kUKMSuggestionFilledEntryName, 2981 form, ukm_recorder, internal::kUKMSuggestionFilledEntryName,
3001 {{{internal::kUKMRecordTypeMetricName, CreditCard::FULL_SERVER_CARD}, 2982 {{{internal::kUKMRecordTypeMetricName, CreditCard::FULL_SERVER_CARD},
3002 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 2983 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
3003 VerifySubmitFormUkm(form, ukm_service, 2984 VerifySubmitFormUkm(form, ukm_recorder,
3004 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); 2985 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA);
3005 } 2986 }
3006 2987
3007 // Reset the autofill manager state and purge UKM logs. 2988 // Reset the autofill manager state and purge UKM logs.
3008 autofill_manager_->Reset(); 2989 autofill_manager_->Reset();
3009 ukm_service->Purge(); 2990 ukm_recorder->Purge();
3010 2991
3011 autofill_manager_->AddSeenForm(form, field_types, field_types); 2992 autofill_manager_->AddSeenForm(form, field_types, field_types);
3012 2993
3013 { 2994 {
3014 // Simulating submission with a masked card server suggestion. 2995 // Simulating submission with a masked card server suggestion.
3015 base::HistogramTester histogram_tester; 2996 base::HistogramTester histogram_tester;
3016 std::string guid( 2997 std::string guid(
3017 "10000000-0000-0000-0000-000000000002"); // masked server card 2998 "10000000-0000-0000-0000-000000000002"); // masked server card
3018 autofill_manager_->FillOrPreviewForm( 2999 autofill_manager_->FillOrPreviewForm(
3019 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.back(), 3000 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.back(),
3020 autofill_manager_->MakeFrontendID(guid, std::string())); 3001 autofill_manager_->MakeFrontendID(guid, std::string()));
3021 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS, 3002 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS,
3022 "6011000990139424"); 3003 "6011000990139424");
3023 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 3004 autofill_manager_->SubmitForm(form, TimeTicks::Now());
3024 histogram_tester.ExpectBucketCount( 3005 histogram_tester.ExpectBucketCount(
3025 "Autofill.FormEvents.CreditCard", 3006 "Autofill.FormEvents.CreditCard",
3026 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED, 1); 3007 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED, 1);
3027 histogram_tester.ExpectBucketCount( 3008 histogram_tester.ExpectBucketCount(
3028 "Autofill.FormEvents.CreditCard", 3009 "Autofill.FormEvents.CreditCard",
3029 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE, 3010 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE,
3030 1); 3011 1);
3031 3012
3032 VerifyFormInteractionUkm( 3013 VerifyFormInteractionUkm(
3033 form, ukm_service, internal::kUKMSuggestionFilledEntryName, 3014 form, ukm_recorder, internal::kUKMSuggestionFilledEntryName,
3034 {{{internal::kUKMRecordTypeMetricName, CreditCard::MASKED_SERVER_CARD}, 3015 {{{internal::kUKMRecordTypeMetricName, CreditCard::MASKED_SERVER_CARD},
3035 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 3016 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
3036 VerifyFormInteractionUkm( 3017 VerifyFormInteractionUkm(
3037 form, ukm_service, internal::kUKMSelectedMaskedServerCardEntryName, 3018 form, ukm_recorder, internal::kUKMSelectedMaskedServerCardEntryName,
3038 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 3019 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
3039 VerifySubmitFormUkm(form, ukm_service, 3020 VerifySubmitFormUkm(form, ukm_recorder,
3040 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); 3021 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA);
3041 } 3022 }
3042 3023
3043 // Reset the autofill manager state and purge UKM logs. 3024 // Reset the autofill manager state and purge UKM logs.
3044 autofill_manager_->Reset(); 3025 autofill_manager_->Reset();
3045 ukm_service->Purge(); 3026 ukm_recorder->Purge();
3046 3027
3047 // Recreating cards as the previous test should have upgraded the masked 3028 // Recreating cards as the previous test should have upgraded the masked
3048 // card to a full card. 3029 // card to a full card.
3049 personal_data_->RecreateCreditCards( 3030 personal_data_->RecreateCreditCards(
3050 true /* include_local_credit_card */, 3031 true /* include_local_credit_card */,
3051 true /* include_masked_server_credit_card */, 3032 true /* include_masked_server_credit_card */,
3052 true /* include_full_server_credit_card */); 3033 true /* include_full_server_credit_card */);
3053 3034
3054 // Reset the autofill manager state. 3035 // Reset the autofill manager state.
3055 autofill_manager_->Reset(); 3036 autofill_manager_->Reset();
3056 autofill_manager_->AddSeenForm(form, field_types, field_types); 3037 autofill_manager_->AddSeenForm(form, field_types, field_types);
3057 3038
3058 { 3039 {
3059 // Simulating multiple submissions. 3040 // Simulating multiple submissions.
3060 base::HistogramTester histogram_tester; 3041 base::HistogramTester histogram_tester;
3061 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 3042 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
3062 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 3043 autofill_manager_->SubmitForm(form, TimeTicks::Now());
3063 3044
3064 VerifyFormInteractionUkm( 3045 VerifyFormInteractionUkm(
3065 form, ukm_service, internal::kUKMFormSubmittedEntryName, 3046 form, ukm_recorder, internal::kUKMFormSubmittedEntryName,
3066 {{{internal::kUKMAutofillFormSubmittedStateMetricName, 3047 {{{internal::kUKMAutofillFormSubmittedStateMetricName,
3067 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, 3048 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA},
3068 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 3049 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
3069 3050
3070 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 3051 autofill_manager_->SubmitForm(form, TimeTicks::Now());
3071 3052
3072 VerifyFormInteractionUkm( 3053 VerifyFormInteractionUkm(
3073 form, ukm_service, internal::kUKMFormSubmittedEntryName, 3054 form, ukm_recorder, internal::kUKMFormSubmittedEntryName,
3074 {{{internal::kUKMAutofillFormSubmittedStateMetricName, 3055 {{{internal::kUKMAutofillFormSubmittedStateMetricName,
3075 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, 3056 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA},
3076 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, 3057 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}},
3077 {{internal::kUKMAutofillFormSubmittedStateMetricName, 3058 {{internal::kUKMAutofillFormSubmittedStateMetricName,
3078 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, 3059 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA},
3079 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 3060 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
3080 3061
3081 histogram_tester.ExpectBucketCount( 3062 histogram_tester.ExpectBucketCount(
3082 "Autofill.FormEvents.CreditCard", 3063 "Autofill.FormEvents.CreditCard",
3083 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); 3064 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
(...skipping 25 matching lines...) Expand all
3109 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0); 3090 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
3110 histogram_tester.ExpectBucketCount( 3091 histogram_tester.ExpectBucketCount(
3111 "Autofill.FormEvents.CreditCard", 3092 "Autofill.FormEvents.CreditCard",
3112 AutofillMetrics:: 3093 AutofillMetrics::
3113 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SUBMITTED_ONCE, 3094 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SUBMITTED_ONCE,
3114 0); 3095 0);
3115 } 3096 }
3116 3097
3117 // Reset the autofill manager state and purge UKM logs. 3098 // Reset the autofill manager state and purge UKM logs.
3118 autofill_manager_->Reset(); 3099 autofill_manager_->Reset();
3119 ukm_service->Purge(); 3100 ukm_recorder->Purge();
3120 3101
3121 autofill_manager_->AddSeenForm(form, field_types, field_types); 3102 autofill_manager_->AddSeenForm(form, field_types, field_types);
3122 3103
3123 { 3104 {
3124 // Simulating submission with suggestion shown but without previous 3105 // Simulating submission with suggestion shown but without previous
3125 // interaction. 3106 // interaction.
3126 base::HistogramTester histogram_tester; 3107 base::HistogramTester histogram_tester;
3127 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); 3108 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field);
3128 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 3109 autofill_manager_->SubmitForm(form, TimeTicks::Now());
3129 histogram_tester.ExpectBucketCount( 3110 histogram_tester.ExpectBucketCount(
(...skipping 25 matching lines...) Expand all
3155 histogram_tester.ExpectBucketCount( 3136 histogram_tester.ExpectBucketCount(
3156 "Autofill.FormEvents.CreditCard", 3137 "Autofill.FormEvents.CreditCard",
3157 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0); 3138 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
3158 histogram_tester.ExpectBucketCount( 3139 histogram_tester.ExpectBucketCount(
3159 "Autofill.FormEvents.CreditCard", 3140 "Autofill.FormEvents.CreditCard",
3160 AutofillMetrics:: 3141 AutofillMetrics::
3161 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE, 3142 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE,
3162 0); 3143 0);
3163 3144
3164 VerifyFormInteractionUkm( 3145 VerifyFormInteractionUkm(
3165 form, ukm_service, internal::kUKMSuggestionsShownEntryName, 3146 form, ukm_recorder, internal::kUKMSuggestionsShownEntryName,
3166 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 3147 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
3167 VerifySubmitFormUkm(form, ukm_service, 3148 VerifySubmitFormUkm(form, ukm_recorder,
3168 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); 3149 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA);
3169 } 3150 }
3170 } 3151 }
3171 3152
3172 // Test that we log "will submit" (but not submitted) form events for credit 3153 // Test that we log "will submit" (but not submitted) form events for credit
3173 // cards. Mirrors CreditCardSubmittedFormEvents test but does not expect any 3154 // cards. Mirrors CreditCardSubmittedFormEvents test but does not expect any
3174 // "submitted" metrics. 3155 // "submitted" metrics.
3175 TEST_F(AutofillMetricsTest, CreditCardWillSubmitFormEvents) { 3156 TEST_F(AutofillMetricsTest, CreditCardWillSubmitFormEvents) {
3176 EnableWalletSync(); 3157 EnableWalletSync();
3177 // Creating all kinds of cards. 3158 // Creating all kinds of cards.
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
3581 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED, 2); 3562 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED, 2);
3582 histogram_tester.ExpectBucketCount( 3563 histogram_tester.ExpectBucketCount(
3583 "Autofill.FormEvents.Address", 3564 "Autofill.FormEvents.Address",
3584 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE, 1); 3565 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE, 1);
3585 } 3566 }
3586 } 3567 }
3587 3568
3588 // Test that we log submitted form events for address. 3569 // Test that we log submitted form events for address.
3589 TEST_F(AutofillMetricsTest, AddressSubmittedFormEvents) { 3570 TEST_F(AutofillMetricsTest, AddressSubmittedFormEvents) {
3590 EnableUkmLogging(); 3571 EnableUkmLogging();
3591 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 3572 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder();
3592 3573
3593 EnableWalletSync(); 3574 EnableWalletSync();
3594 // Create a profile. 3575 // Create a profile.
3595 personal_data_->RecreateProfile(); 3576 personal_data_->RecreateProfile();
3596 // Set up our form data. 3577 // Set up our form data.
3597 FormData form; 3578 FormData form;
3598 form.name = ASCIIToUTF16("TestForm"); 3579 form.name = ASCIIToUTF16("TestForm");
3599 form.origin = GURL("http://example.com/form.html"); 3580 form.origin = GURL("http://example.com/form.html");
3600 form.action = GURL("http://example.com/submit.html"); 3581 form.action = GURL("http://example.com/submit.html");
3601 3582
(...skipping 18 matching lines...) Expand all
3620 base::HistogramTester histogram_tester; 3601 base::HistogramTester histogram_tester;
3621 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 3602 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
3622 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 3603 autofill_manager_->SubmitForm(form, TimeTicks::Now());
3623 histogram_tester.ExpectBucketCount( 3604 histogram_tester.ExpectBucketCount(
3624 "Autofill.FormEvents.Address", 3605 "Autofill.FormEvents.Address",
3625 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); 3606 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
3626 histogram_tester.ExpectBucketCount( 3607 histogram_tester.ExpectBucketCount(
3627 "Autofill.FormEvents.Address", 3608 "Autofill.FormEvents.Address",
3628 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); 3609 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
3629 3610
3630 VerifySubmitFormUkm(form, ukm_service, 3611 VerifySubmitFormUkm(form, ukm_recorder,
3631 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); 3612 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA);
3632 } 3613 }
3633 3614
3634 // Reset the autofill manager state and purge UKM logs. 3615 // Reset the autofill manager state and purge UKM logs.
3635 autofill_manager_->Reset(); 3616 autofill_manager_->Reset();
3636 ukm_service->Purge(); 3617 ukm_recorder->Purge();
3637 3618
3638 autofill_manager_->AddSeenForm(form, field_types, field_types); 3619 autofill_manager_->AddSeenForm(form, field_types, field_types);
3639 3620
3640 { 3621 {
3641 // Simulating submission with suggestion shown. 3622 // Simulating submission with suggestion shown.
3642 base::HistogramTester histogram_tester; 3623 base::HistogramTester histogram_tester;
3643 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); 3624 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field);
3644 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 3625 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
3645 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 3626 autofill_manager_->SubmitForm(form, TimeTicks::Now());
3646 histogram_tester.ExpectBucketCount( 3627 histogram_tester.ExpectBucketCount(
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
4122 AutofillProfile profile; 4103 AutofillProfile profile;
4123 profile.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(13)); 4104 profile.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(13));
4124 profile.RecordAndLogUse(); 4105 profile.RecordAndLogUse();
4125 histogram_tester.ExpectBucketCount("Autofill.DaysSinceLastUse.Profile", 13, 4106 histogram_tester.ExpectBucketCount("Autofill.DaysSinceLastUse.Profile", 13,
4126 1); 4107 1);
4127 } 4108 }
4128 4109
4129 // Verify that we correctly log the submitted form's state. 4110 // Verify that we correctly log the submitted form's state.
4130 TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) { 4111 TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) {
4131 EnableUkmLogging(); 4112 EnableUkmLogging();
4132 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 4113 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder();
4133 4114
4134 // Start with a form with insufficiently many fields. 4115 // Start with a form with insufficiently many fields.
4135 FormData form; 4116 FormData form;
4136 form.name = ASCIIToUTF16("TestForm"); 4117 form.name = ASCIIToUTF16("TestForm");
4137 form.origin = GURL("http://example.com/form.html"); 4118 form.origin = GURL("http://example.com/form.html");
4138 form.action = GURL("http://example.com/submit.html"); 4119 form.action = GURL("http://example.com/submit.html");
4139 4120
4140 FormFieldData field; 4121 FormFieldData field;
4141 test::CreateTestFormField("Name", "name", "", "text", &field); 4122 test::CreateTestFormField("Name", "name", "", "text", &field);
4142 form.fields.push_back(field); 4123 form.fields.push_back(field);
(...skipping 24 matching lines...) Expand all
4167 base::UserActionTester user_action_tester; 4148 base::UserActionTester user_action_tester;
4168 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4149 autofill_manager_->SubmitForm(form, TimeTicks::Now());
4169 histogram_tester.ExpectUniqueSample( 4150 histogram_tester.ExpectUniqueSample(
4170 "Autofill.FormSubmittedState", 4151 "Autofill.FormSubmittedState",
4171 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); 4152 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1);
4172 EXPECT_EQ(1, user_action_tester.GetActionCount( 4153 EXPECT_EQ(1, user_action_tester.GetActionCount(
4173 "Autofill_FormSubmitted_NonFillable")); 4154 "Autofill_FormSubmitted_NonFillable"));
4174 4155
4175 // Expect an entry for |DeveloperEngagement| and an entry for form 4156 // Expect an entry for |DeveloperEngagement| and an entry for form
4176 // interactions. Both entries are for the same URL. 4157 // interactions. Both entries are for the same URL.
4177 ASSERT_EQ(2U, ukm_service->entries_count()); 4158 ASSERT_EQ(2U, ukm_recorder->entries_count());
4178 ASSERT_EQ(2U, ukm_service->sources_count()); 4159 ASSERT_EQ(2U, ukm_recorder->sources_count());
4179 VerifyDeveloperEngagementUkm( 4160 VerifyDeveloperEngagementUkm(
4180 form, ukm_service, 4161 form, ukm_recorder,
4181 {AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS}); 4162 {AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS});
4182 VerifyFormInteractionUkm(form, ukm_service, 4163 VerifyFormInteractionUkm(form, ukm_recorder,
4183 internal::kUKMFormSubmittedEntryName, 4164 internal::kUKMFormSubmittedEntryName,
4184 expected_form_submission_ukm_metrics); 4165 expected_form_submission_ukm_metrics);
4185 } 4166 }
4186 4167
4187 // Non fillable form. 4168 // Non fillable form.
4188 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley"); 4169 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley");
4189 form.fields[1].value = ASCIIToUTF16("theking@gmail.com"); 4170 form.fields[1].value = ASCIIToUTF16("theking@gmail.com");
4190 forms.front() = form; 4171 forms.front() = form;
4191 4172
4192 { 4173 {
4193 base::HistogramTester histogram_tester; 4174 base::HistogramTester histogram_tester;
4194 base::UserActionTester user_action_tester; 4175 base::UserActionTester user_action_tester;
4195 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4176 autofill_manager_->SubmitForm(form, TimeTicks::Now());
4196 histogram_tester.ExpectUniqueSample( 4177 histogram_tester.ExpectUniqueSample(
4197 "Autofill.FormSubmittedState", 4178 "Autofill.FormSubmittedState",
4198 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); 4179 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1);
4199 EXPECT_EQ(1, user_action_tester.GetActionCount( 4180 EXPECT_EQ(1, user_action_tester.GetActionCount(
4200 "Autofill_FormSubmitted_NonFillable")); 4181 "Autofill_FormSubmitted_NonFillable"));
4201 4182
4202 expected_form_submission_ukm_metrics.push_back( 4183 expected_form_submission_ukm_metrics.push_back(
4203 {{internal::kUKMAutofillFormSubmittedStateMetricName, 4184 {{internal::kUKMAutofillFormSubmittedStateMetricName,
4204 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, 4185 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA},
4205 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); 4186 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}});
4206 VerifyFormInteractionUkm(form, ukm_service, 4187 VerifyFormInteractionUkm(form, ukm_recorder,
4207 internal::kUKMFormSubmittedEntryName, 4188 internal::kUKMFormSubmittedEntryName,
4208 expected_form_submission_ukm_metrics); 4189 expected_form_submission_ukm_metrics);
4209 } 4190 }
4210 4191
4211 // Fill in the third field. 4192 // Fill in the third field.
4212 form.fields[2].value = ASCIIToUTF16("12345678901"); 4193 form.fields[2].value = ASCIIToUTF16("12345678901");
4213 forms.front() = form; 4194 forms.front() = form;
4214 4195
4215 // Autofilled none with no suggestions shown. 4196 // Autofilled none with no suggestions shown.
4216 { 4197 {
4217 base::HistogramTester histogram_tester; 4198 base::HistogramTester histogram_tester;
4218 base::UserActionTester user_action_tester; 4199 base::UserActionTester user_action_tester;
4219 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4200 autofill_manager_->SubmitForm(form, TimeTicks::Now());
4220 histogram_tester.ExpectUniqueSample( 4201 histogram_tester.ExpectUniqueSample(
4221 "Autofill.FormSubmittedState", 4202 "Autofill.FormSubmittedState",
4222 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS, 4203 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS,
4223 1); 4204 1);
4224 EXPECT_EQ(1, user_action_tester.GetActionCount( 4205 EXPECT_EQ(1, user_action_tester.GetActionCount(
4225 "Autofill_FormSubmitted_FilledNone_SuggestionsNotShown")); 4206 "Autofill_FormSubmitted_FilledNone_SuggestionsNotShown"));
4226 4207
4227 expected_form_submission_ukm_metrics.push_back( 4208 expected_form_submission_ukm_metrics.push_back(
4228 {{internal::kUKMAutofillFormSubmittedStateMetricName, 4209 {{internal::kUKMAutofillFormSubmittedStateMetricName,
4229 AutofillMetrics:: 4210 AutofillMetrics::
4230 FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS}, 4211 FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS},
4231 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); 4212 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}});
4232 VerifyFormInteractionUkm(form, ukm_service, 4213 VerifyFormInteractionUkm(form, ukm_recorder,
4233 internal::kUKMFormSubmittedEntryName, 4214 internal::kUKMFormSubmittedEntryName,
4234 expected_form_submission_ukm_metrics); 4215 expected_form_submission_ukm_metrics);
4235 } 4216 }
4236 4217
4237 // Autofilled none with suggestions shown. 4218 // Autofilled none with suggestions shown.
4238 autofill_manager_->DidShowSuggestions(true, form, form.fields[2]); 4219 autofill_manager_->DidShowSuggestions(true, form, form.fields[2]);
4239 { 4220 {
4240 base::HistogramTester histogram_tester; 4221 base::HistogramTester histogram_tester;
4241 base::UserActionTester user_action_tester; 4222 base::UserActionTester user_action_tester;
4242 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4223 autofill_manager_->SubmitForm(form, TimeTicks::Now());
4243 histogram_tester.ExpectUniqueSample( 4224 histogram_tester.ExpectUniqueSample(
4244 "Autofill.FormSubmittedState", 4225 "Autofill.FormSubmittedState",
4245 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS, 1); 4226 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS, 1);
4246 EXPECT_EQ(1, user_action_tester.GetActionCount( 4227 EXPECT_EQ(1, user_action_tester.GetActionCount(
4247 "Autofill_FormSubmitted_FilledNone_SuggestionsShown")); 4228 "Autofill_FormSubmitted_FilledNone_SuggestionsShown"));
4248 4229
4249 VerifyFormInteractionUkm( 4230 VerifyFormInteractionUkm(
4250 form, ukm_service, internal::kUKMSuggestionsShownEntryName, 4231 form, ukm_recorder, internal::kUKMSuggestionsShownEntryName,
4251 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 4232 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
4252 expected_form_submission_ukm_metrics.push_back( 4233 expected_form_submission_ukm_metrics.push_back(
4253 {{internal::kUKMAutofillFormSubmittedStateMetricName, 4234 {{internal::kUKMAutofillFormSubmittedStateMetricName,
4254 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS}, 4235 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS},
4255 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); 4236 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}});
4256 VerifyFormInteractionUkm(form, ukm_service, 4237 VerifyFormInteractionUkm(form, ukm_recorder,
4257 internal::kUKMFormSubmittedEntryName, 4238 internal::kUKMFormSubmittedEntryName,
4258 expected_form_submission_ukm_metrics); 4239 expected_form_submission_ukm_metrics);
4259 } 4240 }
4260 4241
4261 // Mark one of the fields as autofilled. 4242 // Mark one of the fields as autofilled.
4262 form.fields[1].is_autofilled = true; 4243 form.fields[1].is_autofilled = true;
4263 forms.front() = form; 4244 forms.front() = form;
4264 4245
4265 // Autofilled some of the fields. 4246 // Autofilled some of the fields.
4266 { 4247 {
4267 base::HistogramTester histogram_tester; 4248 base::HistogramTester histogram_tester;
4268 base::UserActionTester user_action_tester; 4249 base::UserActionTester user_action_tester;
4269 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4250 autofill_manager_->SubmitForm(form, TimeTicks::Now());
4270 histogram_tester.ExpectUniqueSample( 4251 histogram_tester.ExpectUniqueSample(
4271 "Autofill.FormSubmittedState", 4252 "Autofill.FormSubmittedState",
4272 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME, 1); 4253 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME, 1);
4273 EXPECT_EQ(1, user_action_tester.GetActionCount( 4254 EXPECT_EQ(1, user_action_tester.GetActionCount(
4274 "Autofill_FormSubmitted_FilledSome")); 4255 "Autofill_FormSubmitted_FilledSome"));
4275 4256
4276 expected_form_submission_ukm_metrics.push_back( 4257 expected_form_submission_ukm_metrics.push_back(
4277 {{internal::kUKMAutofillFormSubmittedStateMetricName, 4258 {{internal::kUKMAutofillFormSubmittedStateMetricName,
4278 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME}, 4259 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME},
4279 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); 4260 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}});
4280 VerifyFormInteractionUkm(form, ukm_service, 4261 VerifyFormInteractionUkm(form, ukm_recorder,
4281 internal::kUKMFormSubmittedEntryName, 4262 internal::kUKMFormSubmittedEntryName,
4282 expected_form_submission_ukm_metrics); 4263 expected_form_submission_ukm_metrics);
4283 } 4264 }
4284 4265
4285 // Mark all of the fillable fields as autofilled. 4266 // Mark all of the fillable fields as autofilled.
4286 form.fields[0].is_autofilled = true; 4267 form.fields[0].is_autofilled = true;
4287 form.fields[2].is_autofilled = true; 4268 form.fields[2].is_autofilled = true;
4288 forms.front() = form; 4269 forms.front() = form;
4289 4270
4290 // Autofilled all the fields. 4271 // Autofilled all the fields.
4291 { 4272 {
4292 base::HistogramTester histogram_tester; 4273 base::HistogramTester histogram_tester;
4293 base::UserActionTester user_action_tester; 4274 base::UserActionTester user_action_tester;
4294 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4275 autofill_manager_->SubmitForm(form, TimeTicks::Now());
4295 histogram_tester.ExpectUniqueSample( 4276 histogram_tester.ExpectUniqueSample(
4296 "Autofill.FormSubmittedState", 4277 "Autofill.FormSubmittedState",
4297 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL, 1); 4278 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL, 1);
4298 EXPECT_EQ(1, user_action_tester.GetActionCount( 4279 EXPECT_EQ(1, user_action_tester.GetActionCount(
4299 "Autofill_FormSubmitted_FilledAll")); 4280 "Autofill_FormSubmitted_FilledAll"));
4300 4281
4301 expected_form_submission_ukm_metrics.push_back( 4282 expected_form_submission_ukm_metrics.push_back(
4302 {{internal::kUKMAutofillFormSubmittedStateMetricName, 4283 {{internal::kUKMAutofillFormSubmittedStateMetricName,
4303 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL}, 4284 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL},
4304 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); 4285 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}});
4305 VerifyFormInteractionUkm(form, ukm_service, 4286 VerifyFormInteractionUkm(form, ukm_recorder,
4306 internal::kUKMFormSubmittedEntryName, 4287 internal::kUKMFormSubmittedEntryName,
4307 expected_form_submission_ukm_metrics); 4288 expected_form_submission_ukm_metrics);
4308 } 4289 }
4309 4290
4310 // Clear out the third field's value. 4291 // Clear out the third field's value.
4311 form.fields[2].value = base::string16(); 4292 form.fields[2].value = base::string16();
4312 forms.front() = form; 4293 forms.front() = form;
4313 4294
4314 // Non fillable form. 4295 // Non fillable form.
4315 { 4296 {
4316 base::HistogramTester histogram_tester; 4297 base::HistogramTester histogram_tester;
4317 base::UserActionTester user_action_tester; 4298 base::UserActionTester user_action_tester;
4318 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4299 autofill_manager_->SubmitForm(form, TimeTicks::Now());
4319 histogram_tester.ExpectUniqueSample( 4300 histogram_tester.ExpectUniqueSample(
4320 "Autofill.FormSubmittedState", 4301 "Autofill.FormSubmittedState",
4321 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); 4302 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1);
4322 EXPECT_EQ(1, user_action_tester.GetActionCount( 4303 EXPECT_EQ(1, user_action_tester.GetActionCount(
4323 "Autofill_FormSubmitted_NonFillable")); 4304 "Autofill_FormSubmitted_NonFillable"));
4324 4305
4325 expected_form_submission_ukm_metrics.push_back( 4306 expected_form_submission_ukm_metrics.push_back(
4326 {{internal::kUKMAutofillFormSubmittedStateMetricName, 4307 {{internal::kUKMAutofillFormSubmittedStateMetricName,
4327 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, 4308 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA},
4328 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}); 4309 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}});
4329 VerifyFormInteractionUkm(form, ukm_service, 4310 VerifyFormInteractionUkm(form, ukm_recorder,
4330 internal::kUKMFormSubmittedEntryName, 4311 internal::kUKMFormSubmittedEntryName,
4331 expected_form_submission_ukm_metrics); 4312 expected_form_submission_ukm_metrics);
4332 } 4313 }
4333 } 4314 }
4334 4315
4335 // Verify that we correctly log user happiness metrics dealing with form 4316 // Verify that we correctly log user happiness metrics dealing with form
4336 // interaction. 4317 // interaction.
4337 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) { 4318 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) {
4338 EnableUkmLogging(); 4319 EnableUkmLogging();
4339 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 4320 ukm::TestUkmRecorder* ukm_recorder = autofill_client_.GetTestUkmRecorder();
4340 4321
4341 // Load a fillable form. 4322 // Load a fillable form.
4342 FormData form; 4323 FormData form;
4343 form.name = ASCIIToUTF16("TestForm"); 4324 form.name = ASCIIToUTF16("TestForm");
4344 form.origin = GURL("http://example.com/form.html"); 4325 form.origin = GURL("http://example.com/form.html");
4345 form.action = GURL("http://example.com/submit.html"); 4326 form.action = GURL("http://example.com/submit.html");
4346 4327
4347 FormFieldData field; 4328 FormFieldData field;
4348 test::CreateTestFormField("Name", "name", "", "text", &field); 4329 test::CreateTestFormField("Name", "name", "", "text", &field);
4349 form.fields.push_back(field); 4330 form.fields.push_back(field);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
4434 base::HistogramTester histogram_tester; 4415 base::HistogramTester histogram_tester;
4435 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks()); 4416 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks());
4436 histogram_tester.ExpectUniqueSample( 4417 histogram_tester.ExpectUniqueSample(
4437 "Autofill.UserHappiness", 4418 "Autofill.UserHappiness",
4438 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD, 1); 4419 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD, 1);
4439 } 4420 }
4440 4421
4441 autofill_manager_->Reset(); 4422 autofill_manager_->Reset();
4442 4423
4443 VerifyFormInteractionUkm( 4424 VerifyFormInteractionUkm(
4444 form, ukm_service, internal::kUKMInteractedWithFormEntryName, 4425 form, ukm_recorder, internal::kUKMInteractedWithFormEntryName,
4445 {{{internal::kUKMIsForCreditCardMetricName, false}, 4426 {{{internal::kUKMIsForCreditCardMetricName, false},
4446 {internal::kUKMLocalRecordTypeCountMetricName, 0}, 4427 {internal::kUKMLocalRecordTypeCountMetricName, 0},
4447 {internal::kUKMServerRecordTypeCountMetricName, 0}}}); 4428 {internal::kUKMServerRecordTypeCountMetricName, 0}}});
4448 VerifyFormInteractionUkm( 4429 VerifyFormInteractionUkm(
4449 form, ukm_service, internal::kUKMSuggestionsShownEntryName, 4430 form, ukm_recorder, internal::kUKMSuggestionsShownEntryName,
4450 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, 4431 {{{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}},
4451 {{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 4432 {{internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
4452 VerifyFormInteractionUkm( 4433 VerifyFormInteractionUkm(
4453 form, ukm_service, internal::kUKMSuggestionFilledEntryName, 4434 form, ukm_recorder, internal::kUKMSuggestionFilledEntryName,
4454 {{{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE}, 4435 {{{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE},
4455 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, 4436 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}},
4456 {{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE}, 4437 {{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE},
4457 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}}); 4438 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}});
4458 VerifyFormInteractionUkm( 4439 VerifyFormInteractionUkm(
4459 form, ukm_service, internal::kUKMTextFieldDidChangeEntryName, 4440 form, ukm_recorder, internal::kUKMTextFieldDidChangeEntryName,
4460 {{{internal::kUKMFieldTypeGroupMetricName, NAME}, 4441 {{{internal::kUKMFieldTypeGroupMetricName, NAME},
4461 {internal::kUKMHeuristicTypeMetricName, NAME_FULL}, 4442 {internal::kUKMHeuristicTypeMetricName, NAME_FULL},
4462 {internal::kUKMServerTypeMetricName, NO_SERVER_DATA}, 4443 {internal::kUKMServerTypeMetricName, NO_SERVER_DATA},
4463 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}, 4444 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED},
4464 {internal::kUKMHtmlFieldModeMetricName, HTML_MODE_NONE}, 4445 {internal::kUKMHtmlFieldModeMetricName, HTML_MODE_NONE},
4465 {internal::kUKMIsAutofilledMetricName, false}, 4446 {internal::kUKMIsAutofilledMetricName, false},
4466 {internal::kUKMIsEmptyMetricName, true}, 4447 {internal::kUKMIsEmptyMetricName, true},
4467 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}}, 4448 {internal::kUKMMillisecondsSinceFormParsedMetricName, 0}},
4468 {{internal::kUKMFieldTypeGroupMetricName, NAME}, 4449 {{internal::kUKMFieldTypeGroupMetricName, NAME},
4469 {internal::kUKMHeuristicTypeMetricName, NAME_FULL}, 4450 {internal::kUKMHeuristicTypeMetricName, NAME_FULL},
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
5048 // can't be used here because it expects the histogram to exist. 5029 // can't be used here because it expects the histogram to exist.
5049 EXPECT_EQ( 5030 EXPECT_EQ(
5050 0, histograms.GetTotalCountsForPrefix("Autofill.FormEvents.CreditCard") 5031 0, histograms.GetTotalCountsForPrefix("Autofill.FormEvents.CreditCard")
5051 ["Autofill.FormEvents.CreditCard.OnNonsecurePage"]); 5032 ["Autofill.FormEvents.CreditCard.OnNonsecurePage"]);
5052 } 5033 }
5053 } 5034 }
5054 5035
5055 // Tests that logging CardUploadDecision UKM works as expected. 5036 // Tests that logging CardUploadDecision UKM works as expected.
5056 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric) { 5037 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric) {
5057 EnableUkmLogging(); 5038 EnableUkmLogging();
5058 ukm::UkmServiceTestingHarness ukm_service_test_harness; 5039 ukm::TestUkmRecorder test_ukm_recorder;
5059 GURL url("https://www.google.com"); 5040 GURL url("https://www.google.com");
5060 int upload_decision = 1; 5041 int upload_decision = 1;
5061 std::vector<std::pair<const char*, int>> metrics = { 5042 std::vector<std::pair<const char*, int>> metrics = {
5062 {internal::kUKMCardUploadDecisionMetricName, upload_decision}}; 5043 {internal::kUKMCardUploadDecisionMetricName, upload_decision}};
5063 5044
5064 EXPECT_TRUE(AutofillMetrics::LogUkm( 5045 EXPECT_TRUE(AutofillMetrics::LogUkm(&test_ukm_recorder, url,
5065 ukm_service_test_harness.test_ukm_service(), url, 5046 internal::kUKMCardUploadDecisionEntryName,
5066 internal::kUKMCardUploadDecisionEntryName, metrics)); 5047 metrics));
5067 5048
5068 // Make sure that the UKM was logged correctly. 5049 // Make sure that the UKM was logged correctly.
5069 ukm::TestUkmService* ukm_service = 5050 ukm::TestUkmRecorder* ukm_recorder = &test_ukm_recorder;
5070 ukm_service_test_harness.test_ukm_service();
5071 5051
5072 ASSERT_EQ(1U, ukm_service->sources_count()); 5052 ASSERT_EQ(1U, ukm_recorder->sources_count());
5073 const ukm::UkmSource* source = 5053 const ukm::UkmSource* source =
5074 ukm_service->GetSourceForUrl(url.spec().c_str()); 5054 ukm_recorder->GetSourceForUrl(url.spec().c_str());
5075 EXPECT_EQ(url.spec(), source->url().spec()); 5055 EXPECT_EQ(url.spec(), source->url().spec());
5076 5056
5077 ASSERT_EQ(1U, ukm_service->entries_count()); 5057 ASSERT_EQ(1U, ukm_recorder->entries_count());
5078 const ukm::UkmEntry* entry = ukm_service->GetEntry(0); 5058 const ukm::mojom::UkmEntry* entry = ukm_recorder->GetEntry(0);
5079 EXPECT_EQ(source->id(), entry->source_id());
5080 5059
5081 // Make sure that a card upload decision entry was logged. 5060 // Make sure that a card upload decision entry was logged.
5082 ukm::Entry entry_proto; 5061 EXPECT_EQ(source->id(), entry->source_id);
5083 entry->PopulateProto(&entry_proto);
5084 EXPECT_EQ(source->id(), entry_proto.source_id());
5085 EXPECT_EQ(base::HashMetricName(internal::kUKMCardUploadDecisionEntryName), 5062 EXPECT_EQ(base::HashMetricName(internal::kUKMCardUploadDecisionEntryName),
5086 entry_proto.event_hash()); 5063 entry->event_hash);
5087 EXPECT_EQ(1, entry_proto.metrics_size()); 5064 EXPECT_EQ(1U, entry->metrics.size());
5088 5065
5089 // Make sure that the correct upload decision was logged. 5066 // Make sure that the correct upload decision was logged.
5090 const ukm::Entry_Metric* metric = FindMetric( 5067 const ukm::mojom::UkmMetric* metric = ukm::TestUkmRecorder::FindMetric(
5091 internal::kUKMCardUploadDecisionMetricName, entry_proto.metrics()); 5068 entry, internal::kUKMCardUploadDecisionMetricName);
5092 ASSERT_NE(nullptr, metric); 5069 ASSERT_NE(nullptr, metric);
5093 EXPECT_EQ(upload_decision, metric->value()); 5070 EXPECT_EQ(upload_decision, metric->value);
5094 } 5071 }
5095 5072
5096 // Tests that logging DeveloperEngagement UKM works as expected. 5073 // Tests that logging DeveloperEngagement UKM works as expected.
5097 TEST_F(AutofillMetricsTest, RecordDeveloperEngagementMetric) { 5074 TEST_F(AutofillMetricsTest, RecordDeveloperEngagementMetric) {
5098 EnableUkmLogging(); 5075 EnableUkmLogging();
5099 ukm::UkmServiceTestingHarness ukm_service_test_harness; 5076 ukm::TestUkmRecorder test_ukm_recorder;
5100 GURL url("https://www.google.com"); 5077 GURL url("https://www.google.com");
5101 int form_structure_metric = 1; 5078 int form_structure_metric = 1;
5102 std::vector<std::pair<const char*, int>> metrics = { 5079 std::vector<std::pair<const char*, int>> metrics = {
5103 {internal::kUKMDeveloperEngagementMetricName, form_structure_metric}}; 5080 {internal::kUKMDeveloperEngagementMetricName, form_structure_metric}};
5104 5081
5105 EXPECT_TRUE(AutofillMetrics::LogUkm( 5082 EXPECT_TRUE(AutofillMetrics::LogUkm(
5106 ukm_service_test_harness.test_ukm_service(), url, 5083 &test_ukm_recorder, url, internal::kUKMDeveloperEngagementEntryName,
5107 internal::kUKMDeveloperEngagementEntryName, metrics)); 5084 metrics));
5108 5085
5109 // Make sure that the UKM was logged correctly. 5086 // Make sure that the UKM was logged correctly.
5110 ukm::TestUkmService* ukm_service = 5087 ukm::TestUkmRecorder* ukm_recorder = &test_ukm_recorder;
5111 ukm_service_test_harness.test_ukm_service();
5112 5088
5113 ASSERT_EQ(1U, ukm_service->sources_count()); 5089 ASSERT_EQ(1U, ukm_recorder->sources_count());
5114 const ukm::UkmSource* source = 5090 const ukm::UkmSource* source =
5115 ukm_service->GetSourceForUrl(url.spec().c_str()); 5091 ukm_recorder->GetSourceForUrl(url.spec().c_str());
5116 EXPECT_EQ(url.spec(), source->url().spec()); 5092 EXPECT_EQ(url.spec(), source->url().spec());
5117 5093
5118 ASSERT_EQ(1U, ukm_service->entries_count()); 5094 ASSERT_EQ(1U, ukm_recorder->entries_count());
5119 const ukm::UkmEntry* entry = ukm_service->GetEntry(0); 5095 const ukm::mojom::UkmEntry* entry = ukm_recorder->GetEntry(0);
5120 EXPECT_EQ(source->id(), entry->source_id());
5121 5096
5122 // Make sure that a developer engagement entry was logged. 5097 // Make sure that a developer engagement entry was logged.
5123 ukm::Entry entry_proto; 5098 EXPECT_EQ(source->id(), entry->source_id);
5124 entry->PopulateProto(&entry_proto);
5125 EXPECT_EQ(source->id(), entry_proto.source_id());
5126 EXPECT_EQ(base::HashMetricName(internal::kUKMDeveloperEngagementEntryName), 5099 EXPECT_EQ(base::HashMetricName(internal::kUKMDeveloperEngagementEntryName),
5127 entry_proto.event_hash()); 5100 entry->event_hash);
5128 EXPECT_EQ(1, entry_proto.metrics_size()); 5101 EXPECT_EQ(1U, entry->metrics.size());
5129 5102
5130 // Make sure that the correct developer engagement metric was logged. 5103 // Make sure that the correct developer engagement metric was logged.
5131 const ukm::Entry_Metric* metric = FindMetric( 5104 const ukm::mojom::UkmMetric* metric = ukm::TestUkmRecorder::FindMetric(
5132 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics()); 5105 entry, internal::kUKMDeveloperEngagementMetricName);
5133 ASSERT_NE(nullptr, metric); 5106 ASSERT_NE(nullptr, metric);
5134 EXPECT_EQ(form_structure_metric, metric->value()); 5107 EXPECT_EQ(form_structure_metric, metric->value);
5135 } 5108 }
5136 5109
5137 // Tests that no UKM is logged when the URL is not valid. 5110 // Tests that no UKM is logged when the URL is not valid.
5138 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_InvalidUrl) { 5111 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_InvalidUrl) {
5139 EnableUkmLogging(); 5112 EnableUkmLogging();
5140 ukm::UkmServiceTestingHarness ukm_service_test_harness; 5113 ukm::TestUkmRecorder test_ukm_recorder;
5141 GURL url(""); 5114 GURL url("");
5142 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; 5115 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}};
5143 5116
5144 EXPECT_FALSE(AutofillMetrics::LogUkm( 5117 EXPECT_FALSE(
5145 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); 5118 AutofillMetrics::LogUkm(&test_ukm_recorder, url, "test_ukm", metrics));
5146 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); 5119 EXPECT_EQ(0U, test_ukm_recorder.sources_count());
5147 } 5120 }
5148 5121
5149 // Tests that no UKM is logged when the metrics map is empty. 5122 // Tests that no UKM is logged when the metrics map is empty.
5150 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoMetrics) { 5123 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoMetrics) {
5151 EnableUkmLogging(); 5124 EnableUkmLogging();
5152 ukm::UkmServiceTestingHarness ukm_service_test_harness; 5125 ukm::TestUkmRecorder test_ukm_recorder;
5153 GURL url("https://www.google.com"); 5126 GURL url("https://www.google.com");
5154 std::vector<std::pair<const char*, int>> metrics; 5127 std::vector<std::pair<const char*, int>> metrics;
5155 5128
5156 EXPECT_FALSE(AutofillMetrics::LogUkm( 5129 EXPECT_FALSE(
5157 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); 5130 AutofillMetrics::LogUkm(&test_ukm_recorder, url, "test_ukm", metrics));
5158 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); 5131 EXPECT_EQ(0U, test_ukm_recorder.sources_count());
5159 } 5132 }
5160 5133
5161 // Tests that no UKM is logged when the ukm service is null. 5134 // Tests that no UKM is logged when the ukm service is null.
5162 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmService) { 5135 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmRecorder) {
5163 EnableUkmLogging(); 5136 EnableUkmLogging();
5164 ukm::UkmServiceTestingHarness ukm_service_test_harness; 5137 ukm::TestUkmRecorder test_ukm_recorder;
5165 GURL url("https://www.google.com"); 5138 GURL url("https://www.google.com");
5166 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; 5139 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}};
5167 5140
5168 EXPECT_FALSE(AutofillMetrics::LogUkm(nullptr, url, "test_ukm", metrics)); 5141 EXPECT_FALSE(AutofillMetrics::LogUkm(nullptr, url, "test_ukm", metrics));
5169 ASSERT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); 5142 ASSERT_EQ(0U, test_ukm_recorder.sources_count());
5170 } 5143 }
5171 5144
5172 // Tests that no UKM is logged when the ukm logging feature is disabled. 5145 // Tests that no UKM is logged when the ukm logging feature is disabled.
5173 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_FeatureDisabled) { 5146 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_FeatureDisabled) {
5174 ukm::UkmServiceTestingHarness ukm_service_test_harness; 5147 ukm::TestUkmRecorder test_ukm_recorder;
5175 GURL url("https://www.google.com"); 5148 GURL url("https://www.google.com");
5176 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; 5149 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}};
5177 5150
5178 EXPECT_FALSE(AutofillMetrics::LogUkm( 5151 EXPECT_FALSE(
5179 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); 5152 AutofillMetrics::LogUkm(&test_ukm_recorder, url, "test_ukm", metrics));
5180 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); 5153 EXPECT_EQ(0U, test_ukm_recorder.sources_count());
5181 } 5154 }
5182 5155
5183 } // namespace autofill 5156 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698