OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/autofill/core/browser/autofill_metrics.h" | 5 #include "components/autofill/core/browser/autofill_metrics.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
(...skipping 1642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1653 EXPECT_EQ(base::HashMetricName(internal::kUKMDeveloperEngagementEntryName), | 1653 EXPECT_EQ(base::HashMetricName(internal::kUKMDeveloperEngagementEntryName), |
1654 entry_proto.event_hash()); | 1654 entry_proto.event_hash()); |
1655 const ukm::Entry_Metric* metric = FindMetric( | 1655 const ukm::Entry_Metric* metric = FindMetric( |
1656 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics()); | 1656 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics()); |
1657 ASSERT_NE(nullptr, metric); | 1657 ASSERT_NE(nullptr, metric); |
1658 EXPECT_EQ(AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS, | 1658 EXPECT_EQ(AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS, |
1659 metric->value()); | 1659 metric->value()); |
1660 } | 1660 } |
1661 } | 1661 } |
1662 | 1662 |
| 1663 // Verify that we correctly log UKM for form parsed with type hints regarding |
| 1664 // developer engagement. |
| 1665 TEST_F(AutofillMetricsTest, UkmDeveloperEngagement_LogUpiVpaTypeHint) { |
| 1666 EnableUkmLogging(); |
| 1667 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
| 1668 |
| 1669 FormData form; |
| 1670 form.name = ASCIIToUTF16("TestForm"); |
| 1671 form.origin = GURL("http://example.com/form.html"); |
| 1672 form.action = GURL("http://example.com/submit.html"); |
| 1673 |
| 1674 FormFieldData field; |
| 1675 test::CreateTestFormField("Name", "name", "", "text", &field); |
| 1676 form.fields.push_back(field); |
| 1677 test::CreateTestFormField("Email", "email", "", "text", &field); |
| 1678 form.fields.push_back(field); |
| 1679 test::CreateTestFormField("Payment", "payment", "", "text", &field); |
| 1680 field.autocomplete_attribute = "upi-vpa"; |
| 1681 form.fields.push_back(field); |
| 1682 |
| 1683 std::vector<FormData> forms(1, form); |
| 1684 |
| 1685 // Expect the "upi-vpa hint" metric to be logged. |
| 1686 { |
| 1687 autofill_manager_->OnFormsSeen(forms, TimeTicks()); |
| 1688 autofill_manager_->Reset(); |
| 1689 |
| 1690 ASSERT_EQ(1U, ukm_service->sources_count()); |
| 1691 const ukm::UkmSource* source = |
| 1692 ukm_service->GetSourceForUrl(form.origin.spec().c_str()); |
| 1693 ASSERT_NE(nullptr, source); |
| 1694 |
| 1695 ASSERT_EQ(1U, ukm_service->entries_count()); |
| 1696 const ukm::UkmEntry* entry = ukm_service->GetEntry(0); |
| 1697 EXPECT_EQ(source->id(), entry->source_id()); |
| 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 } |
| 1709 } |
| 1710 |
1663 // Test that the profile count is logged correctly. | 1711 // Test that the profile count is logged correctly. |
1664 TEST_F(AutofillMetricsTest, StoredProfileCount) { | 1712 TEST_F(AutofillMetricsTest, StoredProfileCount) { |
1665 // The metric should be logged when the profiles are first loaded. | 1713 // The metric should be logged when the profiles are first loaded. |
1666 { | 1714 { |
1667 base::HistogramTester histogram_tester; | 1715 base::HistogramTester histogram_tester; |
1668 personal_data_->LoadProfiles(); | 1716 personal_data_->LoadProfiles(); |
1669 histogram_tester.ExpectUniqueSample("Autofill.StoredProfileCount", 2, 1); | 1717 histogram_tester.ExpectUniqueSample("Autofill.StoredProfileCount", 2, 1); |
1670 } | 1718 } |
1671 | 1719 |
1672 // The metric should only be logged once. | 1720 // The metric should only be logged once. |
(...skipping 2974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4647 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 4695 ukm::UkmServiceTestingHarness ukm_service_test_harness; |
4648 GURL url("https://www.google.com"); | 4696 GURL url("https://www.google.com"); |
4649 std::map<std::string, int> metrics = {{"metric", 1}}; | 4697 std::map<std::string, int> metrics = {{"metric", 1}}; |
4650 | 4698 |
4651 EXPECT_FALSE(AutofillMetrics::LogUkm( | 4699 EXPECT_FALSE(AutofillMetrics::LogUkm( |
4652 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); | 4700 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); |
4653 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); | 4701 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); |
4654 } | 4702 } |
4655 | 4703 |
4656 } // namespace autofill | 4704 } // namespace autofill |
OLD | NEW |