OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/autofill/core/browser/autofill_metrics.h" | 5 #include "components/autofill/core/browser/autofill_metrics.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/feature_list.h" | 13 #include "base/feature_list.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
15 #include "base/metrics/metrics_hashes.h" | 16 #include "base/metrics/metrics_hashes.h" |
16 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
17 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
19 #include "base/test/histogram_tester.h" | 20 #include "base/test/histogram_tester.h" |
(...skipping 26 matching lines...) Expand all Loading... |
46 #include "testing/gmock/include/gmock/gmock.h" | 47 #include "testing/gmock/include/gmock/gmock.h" |
47 #include "testing/gtest/include/gtest/gtest.h" | 48 #include "testing/gtest/include/gtest/gtest.h" |
48 #include "ui/gfx/geometry/rect.h" | 49 #include "ui/gfx/geometry/rect.h" |
49 #include "url/gurl.h" | 50 #include "url/gurl.h" |
50 | 51 |
51 using base::ASCIIToUTF16; | 52 using base::ASCIIToUTF16; |
52 using base::Bucket; | 53 using base::Bucket; |
53 using base::TimeTicks; | 54 using base::TimeTicks; |
54 using rappor::TestRapporServiceImpl; | 55 using rappor::TestRapporServiceImpl; |
55 using ::testing::ElementsAre; | 56 using ::testing::ElementsAre; |
56 using ::testing::UnorderedElementsAre; | 57 using ::testing::Matcher; |
| 58 using ::testing::Pointwise; |
57 | 59 |
58 namespace autofill { | 60 namespace autofill { |
59 namespace { | 61 namespace { |
60 | 62 |
61 class TestPersonalDataManager : public PersonalDataManager { | 63 class TestPersonalDataManager : public PersonalDataManager { |
62 public: | 64 public: |
63 TestPersonalDataManager() | 65 TestPersonalDataManager() |
64 : PersonalDataManager("en-US"), | 66 : PersonalDataManager("en-US"), |
65 autofill_enabled_(true) { | 67 autofill_enabled_(true) { |
66 CreateTestAutofillProfiles(&web_profiles_); | 68 CreateTestAutofillProfiles(&web_profiles_); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 const ukm::Entry_Metric* FindMetric( | 311 const ukm::Entry_Metric* FindMetric( |
310 const char* name, | 312 const char* name, |
311 const google::protobuf::RepeatedPtrField<ukm::Entry_Metric>& metrics) { | 313 const google::protobuf::RepeatedPtrField<ukm::Entry_Metric>& metrics) { |
312 for (const auto& metric : metrics) { | 314 for (const auto& metric : metrics) { |
313 if (metric.metric_hash() == base::HashMetricName(name)) | 315 if (metric.metric_hash() == base::HashMetricName(name)) |
314 return &metric; | 316 return &metric; |
315 } | 317 } |
316 return nullptr; | 318 return nullptr; |
317 } | 319 } |
318 | 320 |
| 321 void VerifyDeveloperEngagementUkm( |
| 322 const FormData& form, |
| 323 const ukm::TestUkmService* ukm_service, |
| 324 AutofillMetrics::DeveloperEngagementMetric expected_value) { |
| 325 const ukm::UkmEntry* entry = ukm_service->GetEntryForEntryName( |
| 326 internal::kUKMDeveloperEngagementEntryName); |
| 327 ASSERT_NE(nullptr, entry); |
| 328 ukm::Entry entry_proto; |
| 329 entry->PopulateProto(&entry_proto); |
| 330 |
| 331 const ukm::UkmSource* source = |
| 332 ukm_service->GetSourceForSourceId(entry_proto.source_id()); |
| 333 ASSERT_NE(nullptr, source); |
| 334 EXPECT_EQ(form.origin, source->url()); |
| 335 |
| 336 const ukm::Entry_Metric* metric = FindMetric( |
| 337 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics()); |
| 338 ASSERT_NE(nullptr, metric); |
| 339 EXPECT_EQ(expected_value, metric->value()); |
| 340 } |
| 341 |
| 342 MATCHER(CompareMetrics, "") { |
| 343 const ukm::Entry_Metric& lhs = ::testing::get<0>(arg); |
| 344 const std::pair<const char*, int64_t>& rhs = ::testing::get<1>(arg); |
| 345 return lhs.metric_hash() == base::HashMetricName(rhs.first) && |
| 346 lhs.value() == rhs.second; |
| 347 } |
| 348 |
| 349 void VerifyFormInteractionsUkm( |
| 350 const FormData& form, |
| 351 const ukm::TestUkmService* ukm_service, |
| 352 const std::vector<std::pair<const char*, int64_t>>& expected_metrics) { |
| 353 const ukm::UkmEntry* entry = ukm_service->GetEntryForEntryName( |
| 354 internal::kUKMFormInteractionsEntryName); |
| 355 ASSERT_NE(nullptr, entry); |
| 356 ukm::Entry entry_proto; |
| 357 entry->PopulateProto(&entry_proto); |
| 358 |
| 359 const ukm::UkmSource* source = |
| 360 ukm_service->GetSourceForSourceId(entry_proto.source_id()); |
| 361 ASSERT_NE(nullptr, source); |
| 362 EXPECT_EQ(form.origin, source->url()); |
| 363 |
| 364 EXPECT_THAT(entry_proto.metrics(), |
| 365 Pointwise(CompareMetrics(), expected_metrics)); |
| 366 } |
| 367 |
319 } // namespace | 368 } // namespace |
320 | 369 |
321 // This is defined in the autofill_metrics.cc implementation file. | 370 // This is defined in the autofill_metrics.cc implementation file. |
322 int GetFieldTypeGroupMetric(ServerFieldType field_type, | 371 int GetFieldTypeGroupMetric(ServerFieldType field_type, |
323 AutofillMetrics::FieldTypeQualityMetric metric); | 372 AutofillMetrics::FieldTypeQualityMetric metric); |
324 | 373 |
325 class AutofillMetricsTest : public testing::Test { | 374 class AutofillMetricsTest : public testing::Test { |
326 public: | 375 public: |
327 ~AutofillMetricsTest() override; | 376 ~AutofillMetricsTest() override; |
328 | 377 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 // PersonalDataManager to be around when it gets destroyed. | 435 // PersonalDataManager to be around when it gets destroyed. |
387 autofill_manager_.reset(); | 436 autofill_manager_.reset(); |
388 autofill_driver_.reset(); | 437 autofill_driver_.reset(); |
389 personal_data_.reset(); | 438 personal_data_.reset(); |
390 signin_manager_->Shutdown(); | 439 signin_manager_->Shutdown(); |
391 signin_manager_.reset(); | 440 signin_manager_.reset(); |
392 account_tracker_->Shutdown(); | 441 account_tracker_->Shutdown(); |
393 account_tracker_.reset(); | 442 account_tracker_.reset(); |
394 signin_client_.reset(); | 443 signin_client_.reset(); |
395 test::ReenableSystemServices(); | 444 test::ReenableSystemServices(); |
| 445 autofill_client_.GetTestUkmService()->Purge(); |
396 } | 446 } |
397 | 447 |
398 void AutofillMetricsTest::EnableWalletSync() { | 448 void AutofillMetricsTest::EnableWalletSync() { |
399 signin_manager_->SetAuthenticatedAccountInfo("12345", "syncuser@example.com"); | 449 signin_manager_->SetAuthenticatedAccountInfo("12345", "syncuser@example.com"); |
400 } | 450 } |
401 | 451 |
402 void AutofillMetricsTest::EnableUkmLogging() { | 452 void AutofillMetricsTest::EnableUkmLogging() { |
403 scoped_feature_list_.InitAndEnableFeature(kAutofillUkmLogging); | 453 scoped_feature_list_.InitAndEnableFeature(kAutofillUkmLogging); |
404 } | 454 } |
405 | 455 |
(...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1373 autofill_manager_->OnTextFieldDidChange(form, form.fields[0], TimeTicks()); | 1423 autofill_manager_->OnTextFieldDidChange(form, form.fields[0], TimeTicks()); |
1374 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks()); | 1424 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks()); |
1375 | 1425 |
1376 // Simulate form submission. | 1426 // Simulate form submission. |
1377 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 1427 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
1378 | 1428 |
1379 // An autofillable form was submitted, and the number of edited autofilled | 1429 // An autofillable form was submitted, and the number of edited autofilled |
1380 // fields is logged. | 1430 // fields is logged. |
1381 histogram_tester.ExpectUniqueSample( | 1431 histogram_tester.ExpectUniqueSample( |
1382 "Autofill.NumberOfEditedAutofilledFieldsAtSubmission", 2, 1); | 1432 "Autofill.NumberOfEditedAutofilledFieldsAtSubmission", 2, 1); |
| 1433 |
| 1434 // UKM must not be logged unless enabled. |
| 1435 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
| 1436 EXPECT_EQ(0U, ukm_service->sources_count()); |
| 1437 EXPECT_EQ(0U, ukm_service->entries_count()); |
1383 } | 1438 } |
1384 | 1439 |
1385 // Verify that when resetting the autofill manager (such as during a | 1440 // Verify that when resetting the autofill manager (such as during a |
1386 // navigation), the proper number of edited fields is logged. | 1441 // navigation), the proper number of edited fields is logged. |
1387 TEST_F(AutofillMetricsTest, NumberOfEditedAutofilledFields_NoSubmission) { | 1442 TEST_F(AutofillMetricsTest, NumberOfEditedAutofilledFields_NoSubmission) { |
1388 // Construct a fillable form. | 1443 // Construct a fillable form. |
1389 FormData form; | 1444 FormData form; |
1390 form.name = ASCIIToUTF16("TestForm"); | 1445 form.name = ASCIIToUTF16("TestForm"); |
1391 form.origin = GURL("http://example.com/form.html"); | 1446 form.origin = GURL("http://example.com/form.html"); |
1392 form.action = GURL("http://example.com/submit.html"); | 1447 form.action = GURL("http://example.com/submit.html"); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1560 autofill_manager_->Reset(); | 1615 autofill_manager_->Reset(); |
1561 | 1616 |
1562 EXPECT_EQ(0U, ukm_service->sources_count()); | 1617 EXPECT_EQ(0U, ukm_service->sources_count()); |
1563 EXPECT_EQ(0U, ukm_service->entries_count()); | 1618 EXPECT_EQ(0U, ukm_service->entries_count()); |
1564 } | 1619 } |
1565 | 1620 |
1566 // Add another field to the form, so that it becomes fillable. | 1621 // Add another field to the form, so that it becomes fillable. |
1567 test::CreateTestFormField("Phone", "phone", "", "text", &field); | 1622 test::CreateTestFormField("Phone", "phone", "", "text", &field); |
1568 forms.back().fields.push_back(field); | 1623 forms.back().fields.push_back(field); |
1569 | 1624 |
1570 // Expect the "form parsed without field type hints" metric to be logged. | 1625 // Expect the "form parsed without field type hints" metric and the |
| 1626 // "form loaded" form interaction event to be logged. |
1571 { | 1627 { |
1572 autofill_manager_->OnFormsSeen(forms, TimeTicks()); | 1628 autofill_manager_->OnFormsSeen(forms, TimeTicks()); |
1573 autofill_manager_->Reset(); | 1629 autofill_manager_->Reset(); |
1574 | 1630 |
1575 ASSERT_EQ(1U, ukm_service->sources_count()); | 1631 // Expect an entry for |kUKMDeveloperEngagementEntryName| and another entry |
1576 const ukm::UkmSource* source = | 1632 // for |kUKMFormInteractionsEntryName|. Both entries are for the same URL. |
1577 ukm_service->GetSourceForUrl(form.origin.spec().c_str()); | 1633 ASSERT_EQ(2U, ukm_service->entries_count()); |
1578 ASSERT_NE(nullptr, source); | 1634 ASSERT_EQ(2U, ukm_service->sources_count()); |
1579 | 1635 VerifyDeveloperEngagementUkm( |
1580 ASSERT_EQ(1U, ukm_service->entries_count()); | 1636 form, ukm_service, |
1581 const ukm::UkmEntry* entry = ukm_service->GetEntry(0); | 1637 AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS); |
1582 EXPECT_EQ(source->id(), entry->source_id()); | 1638 VerifyFormInteractionsUkm( |
1583 | 1639 form, ukm_service, |
1584 ukm::Entry entry_proto; | 1640 {{internal::kUKMFormInteractionsUserHappinessMetricMetricName, |
1585 entry->PopulateProto(&entry_proto); | 1641 AutofillMetrics::FORMS_LOADED}}); |
1586 EXPECT_EQ(source->id(), entry_proto.source_id()); | |
1587 EXPECT_EQ(base::HashMetricName(internal::kUKMDeveloperEngagementEntryName), | |
1588 entry_proto.event_hash()); | |
1589 const ukm::Entry_Metric* metric = FindMetric( | |
1590 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics()); | |
1591 ASSERT_NE(nullptr, metric); | |
1592 EXPECT_EQ(AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS, | |
1593 metric->value()); | |
1594 } | 1642 } |
1595 } | 1643 } |
1596 | 1644 |
1597 // Verify that we correctly log UKM for form parsed with type hints regarding | 1645 // Verify that we correctly log UKM for form parsed with type hints regarding |
1598 // developer engagement. | 1646 // developer engagement. |
1599 TEST_F(AutofillMetricsTest, | 1647 TEST_F(AutofillMetricsTest, |
1600 UkmDeveloperEngagement_LogFillableFormParsedWithTypeHints) { | 1648 UkmDeveloperEngagement_LogFillableFormParsedWithTypeHints) { |
1601 EnableUkmLogging(); | 1649 EnableUkmLogging(); |
1602 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); | 1650 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
1603 | 1651 |
(...skipping 22 matching lines...) Expand all Loading... |
1626 test::CreateTestFormField("", "", "", "text", &field); | 1674 test::CreateTestFormField("", "", "", "text", &field); |
1627 field.autocomplete_attribute = "given-name"; | 1675 field.autocomplete_attribute = "given-name"; |
1628 forms.back().fields.push_back(field); | 1676 forms.back().fields.push_back(field); |
1629 test::CreateTestFormField("", "", "", "text", &field); | 1677 test::CreateTestFormField("", "", "", "text", &field); |
1630 field.autocomplete_attribute = "email"; | 1678 field.autocomplete_attribute = "email"; |
1631 forms.back().fields.push_back(field); | 1679 forms.back().fields.push_back(field); |
1632 test::CreateTestFormField("", "", "", "text", &field); | 1680 test::CreateTestFormField("", "", "", "text", &field); |
1633 field.autocomplete_attribute = "address-line1"; | 1681 field.autocomplete_attribute = "address-line1"; |
1634 forms.back().fields.push_back(field); | 1682 forms.back().fields.push_back(field); |
1635 | 1683 |
1636 // Expect the "form parsed with field type hints" metric to be logged. | 1684 // Expect the "form parsed without field type hints" metric and the |
| 1685 // "form loaded" form interaction event to be logged. |
1637 { | 1686 { |
1638 autofill_manager_->OnFormsSeen(forms, TimeTicks()); | 1687 autofill_manager_->OnFormsSeen(forms, TimeTicks()); |
1639 autofill_manager_->Reset(); | 1688 autofill_manager_->Reset(); |
1640 | 1689 |
1641 ASSERT_EQ(1U, ukm_service->sources_count()); | 1690 // Expect an entry for |kUKMDeveloperEngagementEntryName| and another entry |
1642 const ukm::UkmSource* source = | 1691 // for |kUKMFormInteractionsEntryName|. Both entries are for the same URL. |
1643 ukm_service->GetSourceForUrl(form.origin.spec().c_str()); | 1692 ASSERT_EQ(2U, ukm_service->entries_count()); |
1644 ASSERT_NE(nullptr, source); | 1693 ASSERT_EQ(2U, ukm_service->sources_count()); |
1645 | 1694 VerifyDeveloperEngagementUkm( |
1646 ASSERT_EQ(1U, ukm_service->entries_count()); | 1695 form, ukm_service, |
1647 const ukm::UkmEntry* entry = ukm_service->GetEntry(0); | 1696 AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS); |
1648 EXPECT_EQ(source->id(), entry->source_id()); | 1697 VerifyFormInteractionsUkm( |
1649 | 1698 form, ukm_service, |
1650 ukm::Entry entry_proto; | 1699 {{internal::kUKMFormInteractionsUserHappinessMetricMetricName, |
1651 entry->PopulateProto(&entry_proto); | 1700 AutofillMetrics::FORMS_LOADED}}); |
1652 EXPECT_EQ(source->id(), entry_proto.source_id()); | |
1653 EXPECT_EQ(base::HashMetricName(internal::kUKMDeveloperEngagementEntryName), | |
1654 entry_proto.event_hash()); | |
1655 const ukm::Entry_Metric* metric = FindMetric( | |
1656 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics()); | |
1657 ASSERT_NE(nullptr, metric); | |
1658 EXPECT_EQ(AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS, | |
1659 metric->value()); | |
1660 } | 1701 } |
1661 } | 1702 } |
1662 | 1703 |
1663 // Verify that we correctly log UKM for form parsed with type hints regarding | 1704 // Verify that we correctly log UKM for form parsed with type hints regarding |
1664 // developer engagement. | 1705 // developer engagement. |
1665 TEST_F(AutofillMetricsTest, UkmDeveloperEngagement_LogUpiVpaTypeHint) { | 1706 TEST_F(AutofillMetricsTest, UkmDeveloperEngagement_LogUpiVpaTypeHint) { |
1666 EnableUkmLogging(); | 1707 EnableUkmLogging(); |
1667 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); | 1708 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
1668 | 1709 |
1669 FormData form; | 1710 FormData form; |
1670 form.name = ASCIIToUTF16("TestForm"); | 1711 form.name = ASCIIToUTF16("TestForm"); |
1671 form.origin = GURL("http://example.com/form.html"); | 1712 form.origin = GURL("http://example.com/form.html"); |
1672 form.action = GURL("http://example.com/submit.html"); | 1713 form.action = GURL("http://example.com/submit.html"); |
1673 | 1714 |
1674 FormFieldData field; | 1715 FormFieldData field; |
1675 test::CreateTestFormField("Name", "name", "", "text", &field); | 1716 test::CreateTestFormField("Name", "name", "", "text", &field); |
1676 form.fields.push_back(field); | 1717 form.fields.push_back(field); |
1677 test::CreateTestFormField("Email", "email", "", "text", &field); | 1718 test::CreateTestFormField("Email", "email", "", "text", &field); |
1678 form.fields.push_back(field); | 1719 form.fields.push_back(field); |
1679 test::CreateTestFormField("Payment", "payment", "", "text", &field); | 1720 test::CreateTestFormField("Payment", "payment", "", "text", &field); |
1680 field.autocomplete_attribute = "upi-vpa"; | 1721 field.autocomplete_attribute = "upi-vpa"; |
1681 form.fields.push_back(field); | 1722 form.fields.push_back(field); |
1682 | 1723 |
1683 std::vector<FormData> forms(1, form); | 1724 std::vector<FormData> forms(1, form); |
1684 | 1725 |
1685 // Expect the "upi-vpa hint" metric to be logged. | 1726 // Expect the "upi-vpa hint" metric to be logged and the "form loaded" form |
| 1727 // interaction event to be logged. |
1686 { | 1728 { |
1687 autofill_manager_->OnFormsSeen(forms, TimeTicks()); | 1729 autofill_manager_->OnFormsSeen(forms, TimeTicks()); |
1688 autofill_manager_->Reset(); | 1730 autofill_manager_->Reset(); |
1689 | 1731 |
1690 ASSERT_EQ(1U, ukm_service->sources_count()); | 1732 ASSERT_EQ(2U, ukm_service->entries_count()); |
1691 const ukm::UkmSource* source = | 1733 ASSERT_EQ(2U, ukm_service->sources_count()); |
1692 ukm_service->GetSourceForUrl(form.origin.spec().c_str()); | 1734 VerifyDeveloperEngagementUkm(form, ukm_service, |
1693 ASSERT_NE(nullptr, source); | 1735 AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT); |
1694 | 1736 VerifyFormInteractionsUkm( |
1695 ASSERT_EQ(1U, ukm_service->entries_count()); | 1737 form, ukm_service, |
1696 const ukm::UkmEntry* entry = ukm_service->GetEntry(0); | 1738 {{internal::kUKMFormInteractionsUserHappinessMetricMetricName, |
1697 EXPECT_EQ(source->id(), entry->source_id()); | 1739 AutofillMetrics::FORMS_LOADED}}); |
1698 | |
1699 ukm::Entry entry_proto; | |
1700 entry->PopulateProto(&entry_proto); | |
1701 EXPECT_EQ(source->id(), entry_proto.source_id()); | |
1702 EXPECT_EQ(base::HashMetricName(internal::kUKMDeveloperEngagementEntryName), | |
1703 entry_proto.event_hash()); | |
1704 const ukm::Entry_Metric* metric = FindMetric( | |
1705 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics()); | |
1706 ASSERT_NE(nullptr, metric); | |
1707 EXPECT_EQ(AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT, metric->value()); | |
1708 } | 1740 } |
1709 } | 1741 } |
1710 | 1742 |
1711 // Test that the profile count is logged correctly. | 1743 // Test that the profile count is logged correctly. |
1712 TEST_F(AutofillMetricsTest, StoredProfileCount) { | 1744 TEST_F(AutofillMetricsTest, StoredProfileCount) { |
1713 // The metric should be logged when the profiles are first loaded. | 1745 // The metric should be logged when the profiles are first loaded. |
1714 { | 1746 { |
1715 base::HistogramTester histogram_tester; | 1747 base::HistogramTester histogram_tester; |
1716 personal_data_->LoadProfiles(); | 1748 personal_data_->LoadProfiles(); |
1717 histogram_tester.ExpectUniqueSample("Autofill.StoredProfileCount", 2, 1); | 1749 histogram_tester.ExpectUniqueSample("Autofill.StoredProfileCount", 2, 1); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1880 // Simulate activating the autofill popup for the email field after typing. | 1912 // Simulate activating the autofill popup for the email field after typing. |
1881 form.fields[0].is_autofilled = true; | 1913 form.fields[0].is_autofilled = true; |
1882 base::HistogramTester histogram_tester; | 1914 base::HistogramTester histogram_tester; |
1883 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 1915 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
1884 histogram_tester.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0); | 1916 histogram_tester.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0); |
1885 } | 1917 } |
1886 } | 1918 } |
1887 | 1919 |
1888 // Test that the credit card checkout flow user actions are correctly logged. | 1920 // Test that the credit card checkout flow user actions are correctly logged. |
1889 TEST_F(AutofillMetricsTest, CreditCardCheckoutFlowUserActions) { | 1921 TEST_F(AutofillMetricsTest, CreditCardCheckoutFlowUserActions) { |
| 1922 EnableUkmLogging(); |
| 1923 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
| 1924 |
1890 personal_data_->RecreateCreditCards( | 1925 personal_data_->RecreateCreditCards( |
1891 true /* include_local_credit_card */, | 1926 true /* include_local_credit_card */, |
1892 false /* include_masked_server_credit_card */, | 1927 false /* include_masked_server_credit_card */, |
1893 false /* include_full_server_credit_card */); | 1928 false /* include_full_server_credit_card */); |
1894 | 1929 |
1895 // Set up our form data. | 1930 // Set up our form data. |
1896 FormData form; | 1931 FormData form; |
1897 form.name = ASCIIToUTF16("TestForm"); | 1932 form.name = ASCIIToUTF16("TestForm"); |
1898 form.origin = GURL("http://example.com/form.html"); | 1933 form.origin = GURL("http://example.com/form.html"); |
1899 form.action = GURL("http://example.com/submit.html"); | 1934 form.action = GURL("http://example.com/submit.html"); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1955 // Simulate submitting the credit card form. | 1990 // Simulate submitting the credit card form. |
1956 { | 1991 { |
1957 base::UserActionTester user_action_tester; | 1992 base::UserActionTester user_action_tester; |
1958 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 1993 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
1959 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 1994 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
1960 EXPECT_EQ(1, | 1995 EXPECT_EQ(1, |
1961 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); | 1996 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); |
1962 EXPECT_EQ(1, user_action_tester.GetActionCount( | 1997 EXPECT_EQ(1, user_action_tester.GetActionCount( |
1963 "Autofill_FormSubmitted_NonFillable")); | 1998 "Autofill_FormSubmitted_NonFillable")); |
1964 } | 1999 } |
| 2000 |
| 2001 ASSERT_EQ(1U, ukm_service->entries_count()); |
| 2002 ASSERT_EQ(1U, ukm_service->sources_count()); |
| 2003 // Expect 2 |FORM_EVENT_LOCAL_SUGGESTION_FILLED| events. First, from |
| 2004 // call to |external_delegate_->DidAcceptSuggestion|. Second, from call to |
| 2005 // |autofill_manager_->FillOrPreviewForm|. |
| 2006 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState| |
| 2007 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|. |
| 2008 VerifyFormInteractionsUkm( |
| 2009 form, ukm_service, |
| 2010 {{internal::kUKMFormInteractionsCreditCardFormEventMetricName, |
| 2011 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN}, |
| 2012 {internal::kUKMFormInteractionsCreditCardFormEventMetricName, |
| 2013 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED}, |
| 2014 {internal::kUKMFormInteractionsCreditCardFormEventMetricName, |
| 2015 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED}, |
| 2016 {internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName, |
| 2017 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}}); |
1965 } | 2018 } |
1966 | 2019 |
1967 // Test that the profile checkout flow user actions are correctly logged. | 2020 // Test that the profile checkout flow user actions are correctly logged. |
1968 TEST_F(AutofillMetricsTest, ProfileCheckoutFlowUserActions) { | 2021 TEST_F(AutofillMetricsTest, ProfileCheckoutFlowUserActions) { |
| 2022 EnableUkmLogging(); |
| 2023 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
| 2024 |
1969 // Create a profile. | 2025 // Create a profile. |
1970 personal_data_->RecreateProfile(); | 2026 personal_data_->RecreateProfile(); |
1971 | 2027 |
1972 // Set up our form data. | 2028 // Set up our form data. |
1973 FormData form; | 2029 FormData form; |
1974 form.name = ASCIIToUTF16("TestForm"); | 2030 form.name = ASCIIToUTF16("TestForm"); |
1975 form.origin = GURL("http://example.com/form.html"); | 2031 form.origin = GURL("http://example.com/form.html"); |
1976 form.action = GURL("http://example.com/submit.html"); | 2032 form.action = GURL("http://example.com/submit.html"); |
1977 | 2033 |
1978 FormFieldData field; | 2034 FormFieldData field; |
(...skipping 27 matching lines...) Expand all Loading... |
2006 EXPECT_EQ(1, user_action_tester.GetActionCount( | 2062 EXPECT_EQ(1, user_action_tester.GetActionCount( |
2007 "Autofill_ShowedProfileSuggestions")); | 2063 "Autofill_ShowedProfileSuggestions")); |
2008 } | 2064 } |
2009 | 2065 |
2010 // Simulate selecting a profile suggestions. | 2066 // Simulate selecting a profile suggestions. |
2011 { | 2067 { |
2012 base::UserActionTester user_action_tester; | 2068 base::UserActionTester user_action_tester; |
2013 std::string guid("00000000-0000-0000-0000-000000000001"); // local profile. | 2069 std::string guid("00000000-0000-0000-0000-000000000001"); // local profile. |
2014 external_delegate_->DidAcceptSuggestion( | 2070 external_delegate_->DidAcceptSuggestion( |
2015 ASCIIToUTF16("Test"), | 2071 ASCIIToUTF16("Test"), |
2016 autofill_manager_->MakeFrontendID(guid, std::string()), 0); | 2072 autofill_manager_->MakeFrontendID(std::string(), guid), 0); |
2017 EXPECT_EQ(1, | 2073 EXPECT_EQ(1, |
2018 user_action_tester.GetActionCount("Autofill_SelectedSuggestion")); | 2074 user_action_tester.GetActionCount("Autofill_SelectedSuggestion")); |
2019 } | 2075 } |
2020 | 2076 |
2021 // Simulate filling a profile suggestion. | 2077 // Simulate filling a profile suggestion. |
2022 { | 2078 { |
2023 base::UserActionTester user_action_tester; | 2079 base::UserActionTester user_action_tester; |
2024 std::string guid("00000000-0000-0000-0000-000000000001"); // local profile. | 2080 std::string guid("00000000-0000-0000-0000-000000000001"); // local profile. |
2025 autofill_manager_->FillOrPreviewForm( | 2081 autofill_manager_->FillOrPreviewForm( |
2026 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), | 2082 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), |
2027 autofill_manager_->MakeFrontendID(std::string(), guid)); | 2083 autofill_manager_->MakeFrontendID(std::string(), guid)); |
2028 EXPECT_EQ(1, user_action_tester.GetActionCount( | 2084 EXPECT_EQ(1, user_action_tester.GetActionCount( |
2029 "Autofill_FilledProfileSuggestion")); | 2085 "Autofill_FilledProfileSuggestion")); |
2030 } | 2086 } |
2031 | 2087 |
2032 // Simulate submitting the profile form. | 2088 // Simulate submitting the profile form. |
2033 { | 2089 { |
2034 base::UserActionTester user_action_tester; | 2090 base::UserActionTester user_action_tester; |
2035 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 2091 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2036 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 2092 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2037 EXPECT_EQ(1, | 2093 EXPECT_EQ(1, |
2038 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); | 2094 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); |
2039 EXPECT_EQ(1, user_action_tester.GetActionCount( | 2095 EXPECT_EQ(1, user_action_tester.GetActionCount( |
2040 "Autofill_FormSubmitted_NonFillable")); | 2096 "Autofill_FormSubmitted_NonFillable")); |
2041 } | 2097 } |
| 2098 |
| 2099 ASSERT_EQ(1U, ukm_service->entries_count()); |
| 2100 ASSERT_EQ(1U, ukm_service->sources_count()); |
| 2101 // Expect 2 |FORM_EVENT_LOCAL_SUGGESTION_FILLED| events. First, from |
| 2102 // call to |external_delegate_->DidAcceptSuggestion|. Second, from call to |
| 2103 // |autofill_manager_->FillOrPreviewForm|. |
| 2104 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState| |
| 2105 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|. |
| 2106 VerifyFormInteractionsUkm( |
| 2107 form, ukm_service, |
| 2108 {{internal::kUKMFormInteractionsAddressFormEventMetricName, |
| 2109 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN}, |
| 2110 {internal::kUKMFormInteractionsAddressFormEventMetricName, |
| 2111 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED}, |
| 2112 {internal::kUKMFormInteractionsAddressFormEventMetricName, |
| 2113 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED}, |
| 2114 {internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName, |
| 2115 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}}); |
2042 } | 2116 } |
2043 | 2117 |
2044 // Tests that the Autofill_PolledCreditCardSuggestions user action is only | 2118 // Tests that the Autofill_PolledCreditCardSuggestions user action is only |
2045 // logged once if the field is queried repeatedly. | 2119 // logged once if the field is queried repeatedly. |
2046 TEST_F(AutofillMetricsTest, PolledCreditCardSuggestions_DebounceLogs) { | 2120 TEST_F(AutofillMetricsTest, PolledCreditCardSuggestions_DebounceLogs) { |
2047 personal_data_->RecreateCreditCards( | 2121 personal_data_->RecreateCreditCards( |
2048 true /* include_local_credit_card */, | 2122 true /* include_local_credit_card */, |
2049 false /* include_masked_server_credit_card */, | 2123 false /* include_masked_server_credit_card */, |
2050 false /* include_full_server_credit_card */); | 2124 false /* include_full_server_credit_card */); |
2051 | 2125 |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2321 base::HistogramTester histogram_tester; | 2395 base::HistogramTester histogram_tester; |
2322 autofill_manager_->DidShowSuggestions(false /* is_new_popup */, form, | 2396 autofill_manager_->DidShowSuggestions(false /* is_new_popup */, form, |
2323 field); | 2397 field); |
2324 histogram_tester.ExpectBucketCount( | 2398 histogram_tester.ExpectBucketCount( |
2325 "Autofill.FormEvents.CreditCard", | 2399 "Autofill.FormEvents.CreditCard", |
2326 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN, 0); | 2400 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN, 0); |
2327 histogram_tester.ExpectBucketCount( | 2401 histogram_tester.ExpectBucketCount( |
2328 "Autofill.FormEvents.CreditCard", | 2402 "Autofill.FormEvents.CreditCard", |
2329 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 0); | 2403 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 0); |
2330 } | 2404 } |
| 2405 |
| 2406 // UKM must not be logged unless enabled. |
| 2407 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
| 2408 EXPECT_EQ(0U, ukm_service->sources_count()); |
| 2409 EXPECT_EQ(0U, ukm_service->entries_count()); |
2331 } | 2410 } |
2332 | 2411 |
2333 // Test that we log selected form event for credit cards. | 2412 // Test that we log selected form event for credit cards. |
2334 TEST_F(AutofillMetricsTest, CreditCardSelectedFormEvents) { | 2413 TEST_F(AutofillMetricsTest, CreditCardSelectedFormEvents) { |
2335 EnableWalletSync(); | 2414 EnableWalletSync(); |
2336 // Creating all kinds of cards. | 2415 // Creating all kinds of cards. |
2337 personal_data_->RecreateCreditCards( | 2416 personal_data_->RecreateCreditCards( |
2338 true /* include_local_credit_card */, | 2417 true /* include_local_credit_card */, |
2339 true /* include_masked_server_credit_card */, | 2418 true /* include_masked_server_credit_card */, |
2340 true /* include_full_server_credit_card */); | 2419 true /* include_full_server_credit_card */); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2586 std::string()); | 2665 std::string()); |
2587 histogram_tester.ExpectTotalCount( | 2666 histogram_tester.ExpectTotalCount( |
2588 "Autofill.UnmaskPrompt.GetRealPanDuration", 1); | 2667 "Autofill.UnmaskPrompt.GetRealPanDuration", 1); |
2589 histogram_tester.ExpectTotalCount( | 2668 histogram_tester.ExpectTotalCount( |
2590 "Autofill.UnmaskPrompt.GetRealPanDuration.Failure", 1); | 2669 "Autofill.UnmaskPrompt.GetRealPanDuration.Failure", 1); |
2591 } | 2670 } |
2592 } | 2671 } |
2593 | 2672 |
2594 // Test that we log submitted form events for credit cards. | 2673 // Test that we log submitted form events for credit cards. |
2595 TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) { | 2674 TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) { |
| 2675 EnableUkmLogging(); |
| 2676 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
| 2677 |
2596 EnableWalletSync(); | 2678 EnableWalletSync(); |
2597 // Creating all kinds of cards. | 2679 // Creating all kinds of cards. |
2598 personal_data_->RecreateCreditCards( | 2680 personal_data_->RecreateCreditCards( |
2599 true /* include_local_credit_card */, | 2681 true /* include_local_credit_card */, |
2600 true /* include_masked_server_credit_card */, | 2682 true /* include_masked_server_credit_card */, |
2601 true /* include_full_server_credit_card */); | 2683 true /* include_full_server_credit_card */); |
2602 // Set up our form data. | 2684 // Set up our form data. |
2603 FormData form; | 2685 FormData form; |
2604 form.name = ASCIIToUTF16("TestForm"); | 2686 form.name = ASCIIToUTF16("TestForm"); |
2605 form.origin = GURL("http://example.com/form.html"); | 2687 form.origin = GURL("http://example.com/form.html"); |
(...skipping 19 matching lines...) Expand all Loading... |
2625 // Simulating submission with no filled data. | 2707 // Simulating submission with no filled data. |
2626 base::HistogramTester histogram_tester; | 2708 base::HistogramTester histogram_tester; |
2627 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 2709 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2628 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 2710 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2629 histogram_tester.ExpectBucketCount( | 2711 histogram_tester.ExpectBucketCount( |
2630 "Autofill.FormEvents.CreditCard", | 2712 "Autofill.FormEvents.CreditCard", |
2631 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); | 2713 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); |
2632 histogram_tester.ExpectBucketCount( | 2714 histogram_tester.ExpectBucketCount( |
2633 "Autofill.FormEvents.CreditCard", | 2715 "Autofill.FormEvents.CreditCard", |
2634 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); | 2716 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); |
| 2717 |
| 2718 ASSERT_EQ(1U, ukm_service->entries_count()); |
| 2719 ASSERT_EQ(1U, ukm_service->sources_count()); |
| 2720 VerifyFormInteractionsUkm( |
| 2721 form, ukm_service, |
| 2722 {{internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName, |
| 2723 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}}); |
| 2724 ukm_service->Purge(); |
2635 } | 2725 } |
2636 | 2726 |
2637 // Reset the autofill manager state. | 2727 // Reset the autofill manager state. |
2638 autofill_manager_->Reset(); | 2728 autofill_manager_->Reset(); |
2639 autofill_manager_->AddSeenForm(form, field_types, field_types); | 2729 autofill_manager_->AddSeenForm(form, field_types, field_types); |
2640 | 2730 |
2641 { | 2731 { |
2642 // Simulating submission with suggestion shown. | 2732 // Simulating submission with suggestion shown. |
2643 base::HistogramTester histogram_tester; | 2733 base::HistogramTester histogram_tester; |
2644 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); | 2734 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); |
2645 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 2735 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2646 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 2736 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2647 histogram_tester.ExpectBucketCount( | 2737 histogram_tester.ExpectBucketCount( |
2648 "Autofill.FormEvents.CreditCard", | 2738 "Autofill.FormEvents.CreditCard", |
2649 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_SUBMITTED_ONCE, 1); | 2739 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_SUBMITTED_ONCE, 1); |
2650 histogram_tester.ExpectBucketCount( | 2740 histogram_tester.ExpectBucketCount( |
2651 "Autofill.FormEvents.CreditCard", | 2741 "Autofill.FormEvents.CreditCard", |
2652 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 1); | 2742 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 1); |
| 2743 |
| 2744 ASSERT_EQ(1U, ukm_service->entries_count()); |
| 2745 ASSERT_EQ(1U, ukm_service->sources_count()); |
| 2746 VerifyFormInteractionsUkm( |
| 2747 form, ukm_service, |
| 2748 {{internal::kUKMFormInteractionsCreditCardFormEventMetricName, |
| 2749 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN}, |
| 2750 {internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName, |
| 2751 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}}); |
| 2752 ukm_service->Purge(); |
2653 } | 2753 } |
2654 | 2754 |
2655 // Reset the autofill manager state. | 2755 // Reset the autofill manager state. |
2656 autofill_manager_->Reset(); | 2756 autofill_manager_->Reset(); |
2657 autofill_manager_->AddSeenForm(form, field_types, field_types); | 2757 autofill_manager_->AddSeenForm(form, field_types, field_types); |
2658 | 2758 |
2659 { | 2759 { |
2660 // Simulating submission with filled local data. | 2760 // Simulating submission with filled local data. |
2661 base::HistogramTester histogram_tester; | 2761 base::HistogramTester histogram_tester; |
2662 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 2762 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2663 std::string guid("10000000-0000-0000-0000-000000000001"); // local card | 2763 std::string guid("10000000-0000-0000-0000-000000000001"); // local card |
2664 autofill_manager_->FillOrPreviewForm( | 2764 autofill_manager_->FillOrPreviewForm( |
2665 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), | 2765 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), |
2666 autofill_manager_->MakeFrontendID(guid, std::string())); | 2766 autofill_manager_->MakeFrontendID(guid, std::string())); |
2667 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 2767 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2668 histogram_tester.ExpectBucketCount( | 2768 histogram_tester.ExpectBucketCount( |
2669 "Autofill.FormEvents.CreditCard", | 2769 "Autofill.FormEvents.CreditCard", |
2670 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 1); | 2770 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 1); |
2671 histogram_tester.ExpectBucketCount( | 2771 histogram_tester.ExpectBucketCount( |
2672 "Autofill.FormEvents.CreditCard", | 2772 "Autofill.FormEvents.CreditCard", |
2673 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 1); | 2773 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 1); |
| 2774 |
| 2775 ASSERT_EQ(1U, ukm_service->entries_count()); |
| 2776 ASSERT_EQ(1U, ukm_service->sources_count()); |
| 2777 VerifyFormInteractionsUkm( |
| 2778 form, ukm_service, |
| 2779 {{internal::kUKMFormInteractionsCreditCardFormEventMetricName, |
| 2780 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED}, |
| 2781 {internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName, |
| 2782 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}}); |
| 2783 ukm_service->Purge(); |
2674 } | 2784 } |
2675 | 2785 |
2676 // Reset the autofill manager state. | 2786 // Reset the autofill manager state. |
2677 autofill_manager_->Reset(); | 2787 autofill_manager_->Reset(); |
2678 autofill_manager_->AddSeenForm(form, field_types, field_types); | 2788 autofill_manager_->AddSeenForm(form, field_types, field_types); |
2679 | 2789 |
2680 { | 2790 { |
2681 // Simulating submission with filled server data. | 2791 // Simulating submission with filled server data. |
2682 base::HistogramTester histogram_tester; | 2792 base::HistogramTester histogram_tester; |
2683 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 2793 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2684 std::string guid( | 2794 std::string guid( |
2685 "10000000-0000-0000-0000-000000000003"); // full server card | 2795 "10000000-0000-0000-0000-000000000003"); // full server card |
2686 autofill_manager_->FillOrPreviewForm( | 2796 autofill_manager_->FillOrPreviewForm( |
2687 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), | 2797 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), |
2688 autofill_manager_->MakeFrontendID(guid, std::string())); | 2798 autofill_manager_->MakeFrontendID(guid, std::string())); |
2689 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 2799 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2690 histogram_tester.ExpectBucketCount( | 2800 histogram_tester.ExpectBucketCount( |
2691 "Autofill.FormEvents.CreditCard", | 2801 "Autofill.FormEvents.CreditCard", |
2692 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 1); | 2802 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 1); |
2693 histogram_tester.ExpectBucketCount( | 2803 histogram_tester.ExpectBucketCount( |
2694 "Autofill.FormEvents.CreditCard", | 2804 "Autofill.FormEvents.CreditCard", |
2695 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 1); | 2805 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 1); |
| 2806 |
| 2807 ASSERT_EQ(1U, ukm_service->entries_count()); |
| 2808 ASSERT_EQ(1U, ukm_service->sources_count()); |
| 2809 VerifyFormInteractionsUkm( |
| 2810 form, ukm_service, |
| 2811 {{internal::kUKMFormInteractionsCreditCardFormEventMetricName, |
| 2812 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED}, |
| 2813 {internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName, |
| 2814 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}}); |
| 2815 ukm_service->Purge(); |
2696 } | 2816 } |
2697 | 2817 |
2698 // Reset the autofill manager state. | 2818 // Reset the autofill manager state. |
2699 autofill_manager_->Reset(); | 2819 autofill_manager_->Reset(); |
2700 autofill_manager_->AddSeenForm(form, field_types, field_types); | 2820 autofill_manager_->AddSeenForm(form, field_types, field_types); |
2701 | 2821 |
2702 { | 2822 { |
2703 // Simulating submission with a masked card server suggestion. | 2823 // Simulating submission with a masked card server suggestion. |
2704 base::HistogramTester histogram_tester; | 2824 base::HistogramTester histogram_tester; |
2705 std::string guid( | 2825 std::string guid( |
2706 "10000000-0000-0000-0000-000000000002"); // masked server card | 2826 "10000000-0000-0000-0000-000000000002"); // masked server card |
2707 autofill_manager_->FillOrPreviewForm( | 2827 autofill_manager_->FillOrPreviewForm( |
2708 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.back(), | 2828 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.back(), |
2709 autofill_manager_->MakeFrontendID(guid, std::string())); | 2829 autofill_manager_->MakeFrontendID(guid, std::string())); |
2710 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS, | 2830 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS, |
2711 "6011000990139424"); | 2831 "6011000990139424"); |
| 2832 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2712 histogram_tester.ExpectBucketCount( | 2833 histogram_tester.ExpectBucketCount( |
2713 "Autofill.FormEvents.CreditCard", | 2834 "Autofill.FormEvents.CreditCard", |
2714 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED, 1); | 2835 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED, 1); |
2715 histogram_tester.ExpectBucketCount( | 2836 histogram_tester.ExpectBucketCount( |
2716 "Autofill.FormEvents.CreditCard", | 2837 "Autofill.FormEvents.CreditCard", |
2717 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE, | 2838 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE, |
2718 1); | 2839 1); |
| 2840 ASSERT_EQ(1U, ukm_service->entries_count()); |
| 2841 ASSERT_EQ(1U, ukm_service->sources_count()); |
| 2842 VerifyFormInteractionsUkm( |
| 2843 form, ukm_service, |
| 2844 {{internal::kUKMFormInteractionsUnmaskPromptEventMetricName, |
| 2845 AutofillMetrics::UNMASK_PROMPT_SHOWN}, |
| 2846 {internal::kUKMFormInteractionsCreditCardFormEventMetricName, |
| 2847 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED}, |
| 2848 {internal::kUKMFormInteractionsCreditCardFormEventMetricName, |
| 2849 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED}, |
| 2850 {internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName, |
| 2851 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}}); |
| 2852 ukm_service->Purge(); |
2719 } | 2853 } |
2720 | 2854 |
| 2855 // Reset the autofill manager state. |
| 2856 autofill_manager_->Reset(); |
| 2857 |
2721 // Recreating cards as the previous test should have upgraded the masked | 2858 // Recreating cards as the previous test should have upgraded the masked |
2722 // card to a full card. | 2859 // card to a full card. |
2723 personal_data_->RecreateCreditCards( | 2860 personal_data_->RecreateCreditCards( |
2724 true /* include_local_credit_card */, | 2861 true /* include_local_credit_card */, |
2725 true /* include_masked_server_credit_card */, | 2862 true /* include_masked_server_credit_card */, |
2726 true /* include_full_server_credit_card */); | 2863 true /* include_full_server_credit_card */); |
2727 | 2864 |
2728 // Reset the autofill manager state. | |
2729 autofill_manager_->Reset(); | |
2730 autofill_manager_->AddSeenForm(form, field_types, field_types); | 2865 autofill_manager_->AddSeenForm(form, field_types, field_types); |
2731 | 2866 |
2732 { | 2867 { |
2733 // Simulating multiple submissions. | 2868 // Simulating multiple submissions. |
2734 base::HistogramTester histogram_tester; | 2869 base::HistogramTester histogram_tester; |
2735 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 2870 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2736 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 2871 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
| 2872 |
| 2873 ASSERT_EQ(1U, ukm_service->entries_count()); |
| 2874 ASSERT_EQ(1U, ukm_service->sources_count()); |
| 2875 VerifyFormInteractionsUkm( |
| 2876 form, ukm_service, |
| 2877 {{internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName, |
| 2878 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}}); |
| 2879 ukm_service->Purge(); |
| 2880 |
2737 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 2881 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
| 2882 |
| 2883 ASSERT_EQ(1U, ukm_service->entries_count()); |
| 2884 ASSERT_EQ(1U, ukm_service->sources_count()); |
| 2885 VerifyFormInteractionsUkm( |
| 2886 form, ukm_service, |
| 2887 {{internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName, |
| 2888 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}}); |
| 2889 ukm_service->Purge(); |
| 2890 |
2738 histogram_tester.ExpectBucketCount( | 2891 histogram_tester.ExpectBucketCount( |
2739 "Autofill.FormEvents.CreditCard", | 2892 "Autofill.FormEvents.CreditCard", |
2740 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); | 2893 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); |
2741 histogram_tester.ExpectBucketCount( | 2894 histogram_tester.ExpectBucketCount( |
2742 "Autofill.FormEvents.CreditCard", | 2895 "Autofill.FormEvents.CreditCard", |
2743 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 0); | 2896 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 0); |
2744 histogram_tester.ExpectBucketCount( | 2897 histogram_tester.ExpectBucketCount( |
2745 "Autofill.FormEvents.CreditCard", | 2898 "Autofill.FormEvents.CreditCard", |
2746 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0); | 2899 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0); |
2747 histogram_tester.ExpectBucketCount( | 2900 histogram_tester.ExpectBucketCount( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2808 "Autofill.FormEvents.CreditCard", | 2961 "Autofill.FormEvents.CreditCard", |
2809 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0); | 2962 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0); |
2810 histogram_tester.ExpectBucketCount( | 2963 histogram_tester.ExpectBucketCount( |
2811 "Autofill.FormEvents.CreditCard", | 2964 "Autofill.FormEvents.CreditCard", |
2812 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0); | 2965 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0); |
2813 histogram_tester.ExpectBucketCount( | 2966 histogram_tester.ExpectBucketCount( |
2814 "Autofill.FormEvents.CreditCard", | 2967 "Autofill.FormEvents.CreditCard", |
2815 AutofillMetrics:: | 2968 AutofillMetrics:: |
2816 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE, | 2969 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE, |
2817 0); | 2970 0); |
| 2971 |
| 2972 ASSERT_EQ(1U, ukm_service->entries_count()); |
| 2973 ASSERT_EQ(1U, ukm_service->sources_count()); |
| 2974 VerifyFormInteractionsUkm( |
| 2975 form, ukm_service, |
| 2976 {{internal::kUKMFormInteractionsCreditCardFormEventMetricName, |
| 2977 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN}, |
| 2978 {internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName, |
| 2979 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}}); |
| 2980 ukm_service->Purge(); |
2818 } | 2981 } |
2819 } | 2982 } |
2820 | 2983 |
2821 // Test that we log "will submit" (but not submitted) form events for credit | 2984 // Test that we log "will submit" (but not submitted) form events for credit |
2822 // cards. Mirrors CreditCardSubmittedFormEvents test but does not expect any | 2985 // cards. Mirrors CreditCardSubmittedFormEvents test but does not expect any |
2823 // "submitted" metrics. | 2986 // "submitted" metrics. |
2824 TEST_F(AutofillMetricsTest, CreditCardWillSubmitFormEvents) { | 2987 TEST_F(AutofillMetricsTest, CreditCardWillSubmitFormEvents) { |
2825 EnableWalletSync(); | 2988 EnableWalletSync(); |
2826 // Creating all kinds of cards. | 2989 // Creating all kinds of cards. |
2827 personal_data_->RecreateCreditCards( | 2990 personal_data_->RecreateCreditCards( |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3229 "Autofill.FormEvents.Address", | 3392 "Autofill.FormEvents.Address", |
3230 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED, 2); | 3393 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED, 2); |
3231 histogram_tester.ExpectBucketCount( | 3394 histogram_tester.ExpectBucketCount( |
3232 "Autofill.FormEvents.Address", | 3395 "Autofill.FormEvents.Address", |
3233 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE, 1); | 3396 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE, 1); |
3234 } | 3397 } |
3235 } | 3398 } |
3236 | 3399 |
3237 // Test that we log submitted form events for address. | 3400 // Test that we log submitted form events for address. |
3238 TEST_F(AutofillMetricsTest, AddressSubmittedFormEvents) { | 3401 TEST_F(AutofillMetricsTest, AddressSubmittedFormEvents) { |
| 3402 EnableUkmLogging(); |
| 3403 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
| 3404 |
3239 EnableWalletSync(); | 3405 EnableWalletSync(); |
3240 // Create a profile. | 3406 // Create a profile. |
3241 personal_data_->RecreateProfile(); | 3407 personal_data_->RecreateProfile(); |
3242 // Set up our form data. | 3408 // Set up our form data. |
3243 FormData form; | 3409 FormData form; |
3244 form.name = ASCIIToUTF16("TestForm"); | 3410 form.name = ASCIIToUTF16("TestForm"); |
3245 form.origin = GURL("http://example.com/form.html"); | 3411 form.origin = GURL("http://example.com/form.html"); |
3246 form.action = GURL("http://example.com/submit.html"); | 3412 form.action = GURL("http://example.com/submit.html"); |
3247 | 3413 |
3248 FormFieldData field; | 3414 FormFieldData field; |
(...skipping 16 matching lines...) Expand all Loading... |
3265 // Simulating submission with no filled data. | 3431 // Simulating submission with no filled data. |
3266 base::HistogramTester histogram_tester; | 3432 base::HistogramTester histogram_tester; |
3267 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 3433 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
3268 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 3434 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
3269 histogram_tester.ExpectBucketCount( | 3435 histogram_tester.ExpectBucketCount( |
3270 "Autofill.FormEvents.Address", | 3436 "Autofill.FormEvents.Address", |
3271 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); | 3437 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); |
3272 histogram_tester.ExpectBucketCount( | 3438 histogram_tester.ExpectBucketCount( |
3273 "Autofill.FormEvents.Address", | 3439 "Autofill.FormEvents.Address", |
3274 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); | 3440 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); |
| 3441 |
| 3442 ASSERT_EQ(1U, ukm_service->entries_count()); |
| 3443 ASSERT_EQ(1U, ukm_service->sources_count()); |
| 3444 VerifyFormInteractionsUkm( |
| 3445 form, ukm_service, |
| 3446 {{internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName, |
| 3447 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}}); |
| 3448 ukm_service->Purge(); |
3275 } | 3449 } |
3276 | 3450 |
3277 // Reset the autofill manager state. | 3451 // Reset the autofill manager state. |
3278 autofill_manager_->Reset(); | 3452 autofill_manager_->Reset(); |
3279 autofill_manager_->AddSeenForm(form, field_types, field_types); | 3453 autofill_manager_->AddSeenForm(form, field_types, field_types); |
3280 | 3454 |
3281 { | 3455 { |
3282 // Simulating submission with suggestion shown. | 3456 // Simulating submission with suggestion shown. |
3283 base::HistogramTester histogram_tester; | 3457 base::HistogramTester histogram_tester; |
3284 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); | 3458 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3722 { | 3896 { |
3723 // Simulate activating the autofill popup for the street field. | 3897 // Simulate activating the autofill popup for the street field. |
3724 base::HistogramTester histogram_tester; | 3898 base::HistogramTester histogram_tester; |
3725 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 3899 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
3726 histogram_tester.ExpectUniqueSample( | 3900 histogram_tester.ExpectUniqueSample( |
3727 "Autofill.FormEvents.Address.WithOnlyLocalData", | 3901 "Autofill.FormEvents.Address.WithOnlyLocalData", |
3728 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE, 1); | 3902 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE, 1); |
3729 } | 3903 } |
3730 } | 3904 } |
3731 | 3905 |
3732 | |
3733 // Test that we log that Autofill is enabled when filling a form. | 3906 // Test that we log that Autofill is enabled when filling a form. |
3734 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtPageLoad) { | 3907 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtPageLoad) { |
3735 base::HistogramTester histogram_tester; | 3908 base::HistogramTester histogram_tester; |
3736 autofill_manager_->set_autofill_enabled(true); | 3909 autofill_manager_->set_autofill_enabled(true); |
3737 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks()); | 3910 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks()); |
3738 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.PageLoad", true, 1); | 3911 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.PageLoad", true, 1); |
3739 } | 3912 } |
3740 | 3913 |
3741 // Test that we log that Autofill is disabled when filling a form. | 3914 // Test that we log that Autofill is disabled when filling a form. |
3742 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtPageLoad) { | 3915 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtPageLoad) { |
(...skipping 18 matching lines...) Expand all Loading... |
3761 base::HistogramTester histogram_tester; | 3934 base::HistogramTester histogram_tester; |
3762 AutofillProfile profile; | 3935 AutofillProfile profile; |
3763 profile.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(13)); | 3936 profile.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(13)); |
3764 profile.RecordAndLogUse(); | 3937 profile.RecordAndLogUse(); |
3765 histogram_tester.ExpectBucketCount("Autofill.DaysSinceLastUse.Profile", 13, | 3938 histogram_tester.ExpectBucketCount("Autofill.DaysSinceLastUse.Profile", 13, |
3766 1); | 3939 1); |
3767 } | 3940 } |
3768 | 3941 |
3769 // Verify that we correctly log the submitted form's state. | 3942 // Verify that we correctly log the submitted form's state. |
3770 TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) { | 3943 TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) { |
| 3944 EnableUkmLogging(); |
| 3945 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
| 3946 |
3771 // Start with a form with insufficiently many fields. | 3947 // Start with a form with insufficiently many fields. |
3772 FormData form; | 3948 FormData form; |
3773 form.name = ASCIIToUTF16("TestForm"); | 3949 form.name = ASCIIToUTF16("TestForm"); |
3774 form.origin = GURL("http://example.com/form.html"); | 3950 form.origin = GURL("http://example.com/form.html"); |
3775 form.action = GURL("http://example.com/submit.html"); | 3951 form.action = GURL("http://example.com/submit.html"); |
3776 | 3952 |
3777 FormFieldData field; | 3953 FormFieldData field; |
3778 test::CreateTestFormField("Name", "name", "", "text", &field); | 3954 test::CreateTestFormField("Name", "name", "", "text", &field); |
3779 form.fields.push_back(field); | 3955 form.fields.push_back(field); |
3780 test::CreateTestFormField("Email", "email", "", "text", &field); | 3956 test::CreateTestFormField("Email", "email", "", "text", &field); |
(...skipping 14 matching lines...) Expand all Loading... |
3795 // No data entered in the form. | 3971 // No data entered in the form. |
3796 { | 3972 { |
3797 base::HistogramTester histogram_tester; | 3973 base::HistogramTester histogram_tester; |
3798 base::UserActionTester user_action_tester; | 3974 base::UserActionTester user_action_tester; |
3799 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 3975 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
3800 histogram_tester.ExpectUniqueSample( | 3976 histogram_tester.ExpectUniqueSample( |
3801 "Autofill.FormSubmittedState", | 3977 "Autofill.FormSubmittedState", |
3802 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); | 3978 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); |
3803 EXPECT_EQ(1, user_action_tester.GetActionCount( | 3979 EXPECT_EQ(1, user_action_tester.GetActionCount( |
3804 "Autofill_FormSubmitted_NonFillable")); | 3980 "Autofill_FormSubmitted_NonFillable")); |
| 3981 |
| 3982 // Expect an entry for |kUKMDeveloperEngagementEntryName| and another entry |
| 3983 // for |kUKMFormInteractionsEntryName|. Both entries are for the same URL. |
| 3984 ASSERT_EQ(2U, ukm_service->entries_count()); |
| 3985 ASSERT_EQ(2U, ukm_service->sources_count()); |
| 3986 VerifyDeveloperEngagementUkm( |
| 3987 form, ukm_service, |
| 3988 AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS); |
| 3989 VerifyFormInteractionsUkm( |
| 3990 form, ukm_service, |
| 3991 {{internal::kUKMFormInteractionsUserHappinessMetricMetricName, |
| 3992 AutofillMetrics::FORMS_LOADED}, |
| 3993 {internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName, |
| 3994 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}}); |
| 3995 ukm_service->Purge(); |
3805 } | 3996 } |
3806 | 3997 |
3807 // Non fillable form. | 3998 // Non fillable form. |
3808 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley"); | 3999 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley"); |
3809 form.fields[1].value = ASCIIToUTF16("theking@gmail.com"); | 4000 form.fields[1].value = ASCIIToUTF16("theking@gmail.com"); |
3810 forms.front() = form; | 4001 forms.front() = form; |
3811 | 4002 |
3812 { | 4003 { |
3813 base::HistogramTester histogram_tester; | 4004 base::HistogramTester histogram_tester; |
3814 base::UserActionTester user_action_tester; | 4005 base::UserActionTester user_action_tester; |
3815 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 4006 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
3816 histogram_tester.ExpectUniqueSample( | 4007 histogram_tester.ExpectUniqueSample( |
3817 "Autofill.FormSubmittedState", | 4008 "Autofill.FormSubmittedState", |
3818 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); | 4009 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); |
3819 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4010 EXPECT_EQ(1, user_action_tester.GetActionCount( |
3820 "Autofill_FormSubmitted_NonFillable")); | 4011 "Autofill_FormSubmitted_NonFillable")); |
| 4012 |
| 4013 ASSERT_EQ(1U, ukm_service->entries_count()); |
| 4014 ASSERT_EQ(1U, ukm_service->sources_count()); |
| 4015 VerifyFormInteractionsUkm( |
| 4016 form, ukm_service, |
| 4017 {{internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName, |
| 4018 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}}); |
| 4019 ukm_service->Purge(); |
3821 } | 4020 } |
3822 | 4021 |
3823 // Fill in the third field. | 4022 // Fill in the third field. |
3824 form.fields[2].value = ASCIIToUTF16("12345678901"); | 4023 form.fields[2].value = ASCIIToUTF16("12345678901"); |
3825 forms.front() = form; | 4024 forms.front() = form; |
3826 | 4025 |
3827 // Autofilled none with no suggestions shown. | 4026 // Autofilled none with no suggestions shown. |
3828 { | 4027 { |
3829 base::HistogramTester histogram_tester; | 4028 base::HistogramTester histogram_tester; |
3830 base::UserActionTester user_action_tester; | 4029 base::UserActionTester user_action_tester; |
3831 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 4030 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
3832 histogram_tester.ExpectUniqueSample( | 4031 histogram_tester.ExpectUniqueSample( |
3833 "Autofill.FormSubmittedState", | 4032 "Autofill.FormSubmittedState", |
3834 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS, | 4033 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS, |
3835 1); | 4034 1); |
3836 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4035 EXPECT_EQ(1, user_action_tester.GetActionCount( |
3837 "Autofill_FormSubmitted_FilledNone_SuggestionsNotShown")); | 4036 "Autofill_FormSubmitted_FilledNone_SuggestionsNotShown")); |
| 4037 |
| 4038 ASSERT_EQ(1U, ukm_service->entries_count()); |
| 4039 ASSERT_EQ(1U, ukm_service->sources_count()); |
| 4040 VerifyFormInteractionsUkm( |
| 4041 form, ukm_service, |
| 4042 {{internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName, |
| 4043 AutofillMetrics:: |
| 4044 FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS}}); |
| 4045 ukm_service->Purge(); |
3838 } | 4046 } |
3839 | 4047 |
3840 // Autofilled none with suggestions shown. | 4048 // Autofilled none with suggestions shown. |
3841 autofill_manager_->DidShowSuggestions(true, form, form.fields[2]); | 4049 autofill_manager_->DidShowSuggestions(true, form, form.fields[2]); |
3842 { | 4050 { |
3843 base::HistogramTester histogram_tester; | 4051 base::HistogramTester histogram_tester; |
3844 base::UserActionTester user_action_tester; | 4052 base::UserActionTester user_action_tester; |
3845 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 4053 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
3846 histogram_tester.ExpectUniqueSample( | 4054 histogram_tester.ExpectUniqueSample( |
3847 "Autofill.FormSubmittedState", | 4055 "Autofill.FormSubmittedState", |
3848 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS, 1); | 4056 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS, 1); |
3849 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4057 EXPECT_EQ(1, user_action_tester.GetActionCount( |
3850 "Autofill_FormSubmitted_FilledNone_SuggestionsShown")); | 4058 "Autofill_FormSubmitted_FilledNone_SuggestionsShown")); |
| 4059 |
| 4060 ASSERT_EQ(1U, ukm_service->entries_count()); |
| 4061 ASSERT_EQ(1U, ukm_service->sources_count()); |
| 4062 VerifyFormInteractionsUkm( |
| 4063 form, ukm_service, |
| 4064 {{internal::kUKMFormInteractionsAddressFormEventMetricName, |
| 4065 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN}, |
| 4066 {internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName, |
| 4067 AutofillMetrics:: |
| 4068 FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS}}); |
| 4069 ukm_service->Purge(); |
3851 } | 4070 } |
3852 | 4071 |
3853 // Mark one of the fields as autofilled. | 4072 // Mark one of the fields as autofilled. |
3854 form.fields[1].is_autofilled = true; | 4073 form.fields[1].is_autofilled = true; |
3855 forms.front() = form; | 4074 forms.front() = form; |
3856 | 4075 |
3857 // Autofilled some of the fields. | 4076 // Autofilled some of the fields. |
3858 { | 4077 { |
3859 base::HistogramTester histogram_tester; | 4078 base::HistogramTester histogram_tester; |
3860 base::UserActionTester user_action_tester; | 4079 base::UserActionTester user_action_tester; |
3861 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 4080 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
3862 histogram_tester.ExpectUniqueSample( | 4081 histogram_tester.ExpectUniqueSample( |
3863 "Autofill.FormSubmittedState", | 4082 "Autofill.FormSubmittedState", |
3864 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME, 1); | 4083 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME, 1); |
3865 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4084 EXPECT_EQ(1, user_action_tester.GetActionCount( |
3866 "Autofill_FormSubmitted_FilledSome")); | 4085 "Autofill_FormSubmitted_FilledSome")); |
| 4086 |
| 4087 ASSERT_EQ(1U, ukm_service->entries_count()); |
| 4088 ASSERT_EQ(1U, ukm_service->sources_count()); |
| 4089 VerifyFormInteractionsUkm( |
| 4090 form, ukm_service, |
| 4091 {{internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName, |
| 4092 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME}}); |
| 4093 ukm_service->Purge(); |
3867 } | 4094 } |
3868 | 4095 |
3869 // Mark all of the fillable fields as autofilled. | 4096 // Mark all of the fillable fields as autofilled. |
3870 form.fields[0].is_autofilled = true; | 4097 form.fields[0].is_autofilled = true; |
3871 form.fields[2].is_autofilled = true; | 4098 form.fields[2].is_autofilled = true; |
3872 forms.front() = form; | 4099 forms.front() = form; |
3873 | 4100 |
3874 // Autofilled all the fields. | 4101 // Autofilled all the fields. |
3875 { | 4102 { |
3876 base::HistogramTester histogram_tester; | 4103 base::HistogramTester histogram_tester; |
3877 base::UserActionTester user_action_tester; | 4104 base::UserActionTester user_action_tester; |
3878 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 4105 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
3879 histogram_tester.ExpectUniqueSample( | 4106 histogram_tester.ExpectUniqueSample( |
3880 "Autofill.FormSubmittedState", | 4107 "Autofill.FormSubmittedState", |
3881 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL, 1); | 4108 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL, 1); |
3882 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4109 EXPECT_EQ(1, user_action_tester.GetActionCount( |
3883 "Autofill_FormSubmitted_FilledAll")); | 4110 "Autofill_FormSubmitted_FilledAll")); |
| 4111 |
| 4112 ASSERT_EQ(1U, ukm_service->entries_count()); |
| 4113 ASSERT_EQ(1U, ukm_service->sources_count()); |
| 4114 VerifyFormInteractionsUkm( |
| 4115 form, ukm_service, |
| 4116 {{internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName, |
| 4117 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL}}); |
| 4118 ukm_service->Purge(); |
3884 } | 4119 } |
3885 | 4120 |
3886 // Clear out the third field's value. | 4121 // Clear out the third field's value. |
3887 form.fields[2].value = base::string16(); | 4122 form.fields[2].value = base::string16(); |
3888 forms.front() = form; | 4123 forms.front() = form; |
3889 | 4124 |
3890 // Non fillable form. | 4125 // Non fillable form. |
3891 { | 4126 { |
3892 base::HistogramTester histogram_tester; | 4127 base::HistogramTester histogram_tester; |
3893 base::UserActionTester user_action_tester; | 4128 base::UserActionTester user_action_tester; |
3894 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 4129 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
3895 histogram_tester.ExpectUniqueSample( | 4130 histogram_tester.ExpectUniqueSample( |
3896 "Autofill.FormSubmittedState", | 4131 "Autofill.FormSubmittedState", |
3897 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); | 4132 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); |
3898 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4133 EXPECT_EQ(1, user_action_tester.GetActionCount( |
3899 "Autofill_FormSubmitted_NonFillable")); | 4134 "Autofill_FormSubmitted_NonFillable")); |
| 4135 |
| 4136 ASSERT_EQ(1U, ukm_service->entries_count()); |
| 4137 ASSERT_EQ(1U, ukm_service->sources_count()); |
| 4138 VerifyFormInteractionsUkm( |
| 4139 form, ukm_service, |
| 4140 {{internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName, |
| 4141 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}}); |
| 4142 ukm_service->Purge(); |
3900 } | 4143 } |
3901 } | 4144 } |
3902 | 4145 |
3903 // Verify that we correctly log user happiness metrics dealing with form | 4146 // Verify that we correctly log user happiness metrics dealing with form |
3904 // interaction. | 4147 // interaction. |
3905 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) { | 4148 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) { |
| 4149 EnableUkmLogging(); |
| 4150 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
| 4151 |
3906 // Load a fillable form. | 4152 // Load a fillable form. |
3907 FormData form; | 4153 FormData form; |
3908 form.name = ASCIIToUTF16("TestForm"); | 4154 form.name = ASCIIToUTF16("TestForm"); |
3909 form.origin = GURL("http://example.com/form.html"); | 4155 form.origin = GURL("http://example.com/form.html"); |
3910 form.action = GURL("http://example.com/submit.html"); | 4156 form.action = GURL("http://example.com/submit.html"); |
3911 | 4157 |
3912 FormFieldData field; | 4158 FormFieldData field; |
3913 test::CreateTestFormField("Name", "name", "", "text", &field); | 4159 test::CreateTestFormField("Name", "name", "", "text", &field); |
3914 form.fields.push_back(field); | 4160 form.fields.push_back(field); |
3915 test::CreateTestFormField("Email", "email", "", "text", &field); | 4161 test::CreateTestFormField("Email", "email", "", "text", &field); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3995 } | 4241 } |
3996 | 4242 |
3997 // Simulate editing another autofilled field. | 4243 // Simulate editing another autofilled field. |
3998 { | 4244 { |
3999 base::HistogramTester histogram_tester; | 4245 base::HistogramTester histogram_tester; |
4000 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks()); | 4246 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks()); |
4001 histogram_tester.ExpectUniqueSample( | 4247 histogram_tester.ExpectUniqueSample( |
4002 "Autofill.UserHappiness", | 4248 "Autofill.UserHappiness", |
4003 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD, 1); | 4249 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD, 1); |
4004 } | 4250 } |
| 4251 |
| 4252 autofill_manager_->Reset(); |
| 4253 |
| 4254 // Verify UKM logs. |
| 4255 VerifyFormInteractionsUkm( |
| 4256 form, ukm_service, |
| 4257 {{internal::kUKMFormInteractionsUserHappinessMetricMetricName, |
| 4258 AutofillMetrics::FORMS_LOADED}, |
| 4259 {internal::kUKMFormInteractionsUserHappinessMetricMetricName, |
| 4260 AutofillMetrics::USER_DID_TYPE}, |
| 4261 {internal::kUKMFormInteractionsAddressFormEventMetricName, |
| 4262 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN}, |
| 4263 {internal::kUKMFormInteractionsAddressFormEventMetricName, |
| 4264 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN}, |
| 4265 {internal::kUKMFormInteractionsUserHappinessMetricMetricName, |
| 4266 AutofillMetrics::USER_DID_AUTOFILL}, |
| 4267 {internal::kUKMFormInteractionsAddressFormEventMetricName, |
| 4268 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED}, |
| 4269 {internal::kUKMFormInteractionsUserHappinessMetricMetricName, |
| 4270 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD}, |
| 4271 {internal::kUKMFormInteractionsUserHappinessMetricMetricName, |
| 4272 AutofillMetrics::USER_DID_AUTOFILL}, |
| 4273 {internal::kUKMFormInteractionsUserHappinessMetricMetricName, |
| 4274 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD}}); |
4005 } | 4275 } |
4006 | 4276 |
4007 // Verify that we correctly log metrics tracking the duration of form fill. | 4277 // Verify that we correctly log metrics tracking the duration of form fill. |
4008 TEST_F(AutofillMetricsTest, FormFillDuration) { | 4278 TEST_F(AutofillMetricsTest, FormFillDuration) { |
4009 // Load a fillable form. | 4279 // Load a fillable form. |
4010 FormData form; | 4280 FormData form; |
4011 form.name = ASCIIToUTF16("TestForm"); | 4281 form.name = ASCIIToUTF16("TestForm"); |
4012 form.origin = GURL("http://example.com/form.html"); | 4282 form.origin = GURL("http://example.com/form.html"); |
4013 form.action = GURL("http://example.com/submit.html"); | 4283 form.action = GURL("http://example.com/submit.html"); |
4014 | 4284 |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4572 ["Autofill.FormEvents.CreditCard.OnNonsecurePage"]); | 4842 ["Autofill.FormEvents.CreditCard.OnNonsecurePage"]); |
4573 } | 4843 } |
4574 } | 4844 } |
4575 | 4845 |
4576 // Tests that logging CardUploadDecision UKM works as expected. | 4846 // Tests that logging CardUploadDecision UKM works as expected. |
4577 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric) { | 4847 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric) { |
4578 EnableUkmLogging(); | 4848 EnableUkmLogging(); |
4579 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 4849 ukm::UkmServiceTestingHarness ukm_service_test_harness; |
4580 GURL url("https://www.google.com"); | 4850 GURL url("https://www.google.com"); |
4581 int upload_decision = 1; | 4851 int upload_decision = 1; |
4582 std::map<std::string, int> metrics = { | 4852 std::vector<std::pair<const char*, int>> metrics = { |
4583 {internal::kUKMCardUploadDecisionMetricName, upload_decision}}; | 4853 {internal::kUKMCardUploadDecisionMetricName, upload_decision}}; |
4584 | 4854 |
4585 EXPECT_TRUE(AutofillMetrics::LogUkm( | 4855 EXPECT_TRUE(AutofillMetrics::LogUkm( |
4586 ukm_service_test_harness.test_ukm_service(), url, | 4856 ukm_service_test_harness.test_ukm_service(), url, |
4587 internal::kUKMCardUploadDecisionEntryName, metrics)); | 4857 internal::kUKMCardUploadDecisionEntryName, metrics)); |
4588 | 4858 |
4589 // Make sure that the UKM was logged correctly. | 4859 // Make sure that the UKM was logged correctly. |
4590 ukm::TestUkmService* ukm_service = | 4860 ukm::TestUkmService* ukm_service = |
4591 ukm_service_test_harness.test_ukm_service(); | 4861 ukm_service_test_harness.test_ukm_service(); |
4592 | 4862 |
(...skipping 20 matching lines...) Expand all Loading... |
4613 ASSERT_NE(nullptr, metric); | 4883 ASSERT_NE(nullptr, metric); |
4614 EXPECT_EQ(upload_decision, metric->value()); | 4884 EXPECT_EQ(upload_decision, metric->value()); |
4615 } | 4885 } |
4616 | 4886 |
4617 // Tests that logging DeveloperEngagement UKM works as expected. | 4887 // Tests that logging DeveloperEngagement UKM works as expected. |
4618 TEST_F(AutofillMetricsTest, RecordDeveloperEngagementMetric) { | 4888 TEST_F(AutofillMetricsTest, RecordDeveloperEngagementMetric) { |
4619 EnableUkmLogging(); | 4889 EnableUkmLogging(); |
4620 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 4890 ukm::UkmServiceTestingHarness ukm_service_test_harness; |
4621 GURL url("https://www.google.com"); | 4891 GURL url("https://www.google.com"); |
4622 int form_structure_metric = 1; | 4892 int form_structure_metric = 1; |
4623 std::map<std::string, int> metrics = { | 4893 std::vector<std::pair<const char*, int>> metrics = { |
4624 {internal::kUKMDeveloperEngagementMetricName, form_structure_metric}}; | 4894 {internal::kUKMDeveloperEngagementMetricName, form_structure_metric}}; |
4625 | 4895 |
4626 EXPECT_TRUE(AutofillMetrics::LogUkm( | 4896 EXPECT_TRUE(AutofillMetrics::LogUkm( |
4627 ukm_service_test_harness.test_ukm_service(), url, | 4897 ukm_service_test_harness.test_ukm_service(), url, |
4628 internal::kUKMDeveloperEngagementEntryName, metrics)); | 4898 internal::kUKMDeveloperEngagementEntryName, metrics)); |
4629 | 4899 |
4630 // Make sure that the UKM was logged correctly. | 4900 // Make sure that the UKM was logged correctly. |
4631 ukm::TestUkmService* ukm_service = | 4901 ukm::TestUkmService* ukm_service = |
4632 ukm_service_test_harness.test_ukm_service(); | 4902 ukm_service_test_harness.test_ukm_service(); |
4633 | 4903 |
(...skipping 19 matching lines...) Expand all Loading... |
4653 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics()); | 4923 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics()); |
4654 ASSERT_NE(nullptr, metric); | 4924 ASSERT_NE(nullptr, metric); |
4655 EXPECT_EQ(form_structure_metric, metric->value()); | 4925 EXPECT_EQ(form_structure_metric, metric->value()); |
4656 } | 4926 } |
4657 | 4927 |
4658 // Tests that no UKM is logged when the URL is not valid. | 4928 // Tests that no UKM is logged when the URL is not valid. |
4659 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_InvalidUrl) { | 4929 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_InvalidUrl) { |
4660 EnableUkmLogging(); | 4930 EnableUkmLogging(); |
4661 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 4931 ukm::UkmServiceTestingHarness ukm_service_test_harness; |
4662 GURL url(""); | 4932 GURL url(""); |
4663 std::map<std::string, int> metrics = {{"metric", 1}}; | 4933 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; |
4664 | 4934 |
4665 EXPECT_FALSE(AutofillMetrics::LogUkm( | 4935 EXPECT_FALSE(AutofillMetrics::LogUkm( |
4666 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); | 4936 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); |
4667 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); | 4937 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); |
4668 } | 4938 } |
4669 | 4939 |
4670 // Tests that no UKM is logged when the metrics map is empty. | 4940 // Tests that no UKM is logged when the metrics map is empty. |
4671 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoMetrics) { | 4941 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoMetrics) { |
4672 EnableUkmLogging(); | 4942 EnableUkmLogging(); |
4673 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 4943 ukm::UkmServiceTestingHarness ukm_service_test_harness; |
4674 GURL url("https://www.google.com"); | 4944 GURL url("https://www.google.com"); |
4675 std::map<std::string, int> metrics; | 4945 std::vector<std::pair<const char*, int>> metrics; |
4676 | 4946 |
4677 EXPECT_FALSE(AutofillMetrics::LogUkm( | 4947 EXPECT_FALSE(AutofillMetrics::LogUkm( |
4678 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); | 4948 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); |
4679 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); | 4949 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); |
4680 } | 4950 } |
4681 | 4951 |
4682 // Tests that no UKM is logged when the ukm service is null. | 4952 // Tests that no UKM is logged when the ukm service is null. |
4683 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmService) { | 4953 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmService) { |
4684 EnableUkmLogging(); | 4954 EnableUkmLogging(); |
4685 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 4955 ukm::UkmServiceTestingHarness ukm_service_test_harness; |
4686 GURL url("https://www.google.com"); | 4956 GURL url("https://www.google.com"); |
4687 std::map<std::string, int> metrics = {{"metric", 1}}; | 4957 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; |
4688 | 4958 |
4689 EXPECT_FALSE(AutofillMetrics::LogUkm(nullptr, url, "test_ukm", metrics)); | 4959 EXPECT_FALSE(AutofillMetrics::LogUkm(nullptr, url, "test_ukm", metrics)); |
4690 ASSERT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); | 4960 ASSERT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); |
4691 } | 4961 } |
4692 | 4962 |
4693 // Tests that no UKM is logged when the ukm logging feature is disabled. | 4963 // Tests that no UKM is logged when the ukm logging feature is disabled. |
4694 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_FeatureDisabled) { | 4964 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_FeatureDisabled) { |
4695 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 4965 ukm::UkmServiceTestingHarness ukm_service_test_harness; |
4696 GURL url("https://www.google.com"); | 4966 GURL url("https://www.google.com"); |
4697 std::map<std::string, int> metrics = {{"metric", 1}}; | 4967 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; |
4698 | 4968 |
4699 EXPECT_FALSE(AutofillMetrics::LogUkm( | 4969 EXPECT_FALSE(AutofillMetrics::LogUkm( |
4700 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); | 4970 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); |
4701 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); | 4971 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); |
4702 } | 4972 } |
4703 | 4973 |
4704 } // namespace autofill | 4974 } // namespace autofill |
OLD | NEW |