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 27 matching lines...) Expand all Loading... |
47 #include "testing/gmock/include/gmock/gmock.h" | 48 #include "testing/gmock/include/gmock/gmock.h" |
48 #include "testing/gtest/include/gtest/gtest.h" | 49 #include "testing/gtest/include/gtest/gtest.h" |
49 #include "ui/gfx/geometry/rect.h" | 50 #include "ui/gfx/geometry/rect.h" |
50 #include "url/gurl.h" | 51 #include "url/gurl.h" |
51 | 52 |
52 using base::ASCIIToUTF16; | 53 using base::ASCIIToUTF16; |
53 using base::Bucket; | 54 using base::Bucket; |
54 using base::TimeTicks; | 55 using base::TimeTicks; |
55 using rappor::TestRapporServiceImpl; | 56 using rappor::TestRapporServiceImpl; |
56 using ::testing::ElementsAre; | 57 using ::testing::ElementsAre; |
57 using ::testing::UnorderedElementsAre; | 58 using ::testing::Matcher; |
| 59 using ::testing::UnorderedPointwise; |
58 | 60 |
59 namespace autofill { | 61 namespace autofill { |
60 namespace { | 62 namespace { |
61 | 63 |
62 class TestPersonalDataManager : public PersonalDataManager { | 64 class TestPersonalDataManager : public PersonalDataManager { |
63 public: | 65 public: |
64 TestPersonalDataManager() | 66 TestPersonalDataManager() |
65 : PersonalDataManager("en-US"), | 67 : PersonalDataManager("en-US"), |
66 autofill_enabled_(true) { | 68 autofill_enabled_(true) { |
67 CreateTestAutofillProfiles(&web_profiles_); | 69 CreateTestAutofillProfiles(&web_profiles_); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 const std::vector<ServerFieldType>& server_types) { | 259 const std::vector<ServerFieldType>& server_types) { |
258 FormData empty_form = form; | 260 FormData empty_form = form; |
259 for (size_t i = 0; i < empty_form.fields.size(); ++i) { | 261 for (size_t i = 0; i < empty_form.fields.size(); ++i) { |
260 empty_form.fields[i].value = base::string16(); | 262 empty_form.fields[i].value = base::string16(); |
261 } | 263 } |
262 | 264 |
263 std::unique_ptr<TestFormStructure> form_structure = | 265 std::unique_ptr<TestFormStructure> form_structure = |
264 base::MakeUnique<TestFormStructure>(empty_form); | 266 base::MakeUnique<TestFormStructure>(empty_form); |
265 form_structure->SetFieldTypes(heuristic_types, server_types); | 267 form_structure->SetFieldTypes(heuristic_types, server_types); |
266 form_structures()->push_back(std::move(form_structure)); | 268 form_structures()->push_back(std::move(form_structure)); |
| 269 |
| 270 form_interactions_ukm_logger()->OnFormsLoaded(form.origin); |
267 } | 271 } |
268 | 272 |
269 // Calls AutofillManager::OnWillSubmitForm and waits for it to complete. | 273 // Calls AutofillManager::OnWillSubmitForm and waits for it to complete. |
270 void WillSubmitForm(const FormData& form, const TimeTicks& timestamp) { | 274 void WillSubmitForm(const FormData& form, const TimeTicks& timestamp) { |
271 ResetRunLoop(); | 275 ResetRunLoop(); |
272 if (!OnWillSubmitForm(form, timestamp)) | 276 if (!OnWillSubmitForm(form, timestamp)) |
273 return; | 277 return; |
274 | 278 |
275 // Wait for the asynchronous OnWillSubmitForm() call to complete. | 279 // Wait for the asynchronous OnWillSubmitForm() call to complete. |
276 RunRunLoop(); | 280 RunRunLoop(); |
277 } | 281 } |
278 | 282 |
279 // Calls both AutofillManager::OnWillSubmitForm and | 283 // Calls both AutofillManager::OnWillSubmitForm and |
280 // AutofillManager::OnFormSubmitted. | 284 // AutofillManager::OnFormSubmitted. |
281 void SubmitForm(const FormData& form, const TimeTicks& timestamp) { | 285 void SubmitForm(const FormData& form, const TimeTicks& timestamp) { |
282 WillSubmitForm(form, timestamp); | 286 WillSubmitForm(form, timestamp); |
283 OnFormSubmitted(form); | 287 OnFormSubmitted(form); |
284 } | 288 } |
285 | 289 |
286 // Control the run loop from within tests. | 290 // Control the run loop from within tests. |
287 void ResetRunLoop() { run_loop_.reset(new base::RunLoop()); } | 291 void ResetRunLoop() { run_loop_.reset(new base::RunLoop()); } |
288 void RunRunLoop() { run_loop_->Run(); } | 292 void RunRunLoop() { run_loop_->Run(); } |
289 | 293 |
290 void UploadFormDataAsyncCallback(const FormStructure* submitted_form, | 294 void UploadFormDataAsyncCallback(const FormStructure* submitted_form, |
291 const base::TimeTicks& load_time, | 295 const TimeTicks& load_time, |
292 const base::TimeTicks& interaction_time, | 296 const TimeTicks& interaction_time, |
293 const base::TimeTicks& submission_time, | 297 const TimeTicks& submission_time, |
294 bool observed_submission) override { | 298 bool observed_submission) override { |
295 run_loop_->Quit(); | 299 run_loop_->Quit(); |
296 | 300 |
297 AutofillManager::UploadFormDataAsyncCallback( | 301 AutofillManager::UploadFormDataAsyncCallback( |
298 submitted_form, load_time, interaction_time, submission_time, | 302 submitted_form, load_time, interaction_time, submission_time, |
299 observed_submission); | 303 observed_submission); |
300 } | 304 } |
301 | 305 |
302 private: | 306 private: |
303 bool autofill_enabled_; | 307 bool autofill_enabled_; |
304 std::unique_ptr<base::RunLoop> run_loop_; | 308 std::unique_ptr<base::RunLoop> run_loop_; |
305 | 309 |
306 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 310 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
307 }; | 311 }; |
308 | 312 |
309 // Finds the specified UKM metric by |name| in the specified UKM |metrics|. | 313 // Finds the specified UKM metric by |name| in the specified UKM |metrics|. |
310 const ukm::Entry_Metric* FindMetric( | 314 const ukm::Entry_Metric* FindMetric( |
311 const char* name, | 315 const char* name, |
312 const google::protobuf::RepeatedPtrField<ukm::Entry_Metric>& metrics) { | 316 const google::protobuf::RepeatedPtrField<ukm::Entry_Metric>& metrics) { |
313 for (const auto& metric : metrics) { | 317 for (const auto& metric : metrics) { |
314 if (metric.metric_hash() == base::HashMetricName(name)) | 318 if (metric.metric_hash() == base::HashMetricName(name)) |
315 return &metric; | 319 return &metric; |
316 } | 320 } |
317 return nullptr; | 321 return nullptr; |
318 } | 322 } |
319 | 323 |
| 324 MATCHER(CompareMetrics, "") { |
| 325 const ukm::Entry_Metric& lhs = ::testing::get<0>(arg); |
| 326 const std::pair<const char*, int64_t>& rhs = ::testing::get<1>(arg); |
| 327 return lhs.metric_hash() == base::HashMetricName(rhs.first) && |
| 328 lhs.value() == rhs.second; |
| 329 } |
| 330 |
| 331 void VerifyDeveloperEngagementUkm( |
| 332 const FormData& form, |
| 333 const ukm::TestUkmService* ukm_service, |
| 334 const std::vector<int64_t>& expected_metric_values) { |
| 335 const ukm::UkmEntry* entry = ukm_service->GetEntryForEntryName( |
| 336 internal::kUKMDeveloperEngagementEntryName); |
| 337 ASSERT_NE(nullptr, entry); |
| 338 ukm::Entry entry_proto; |
| 339 entry->PopulateProto(&entry_proto); |
| 340 |
| 341 const ukm::UkmSource* source = |
| 342 ukm_service->GetSourceForSourceId(entry_proto.source_id()); |
| 343 ASSERT_NE(nullptr, source); |
| 344 EXPECT_EQ(form.origin, source->url()); |
| 345 |
| 346 std::vector<std::pair<const char*, int64_t>> expected_metrics; |
| 347 for (const auto it : expected_metric_values) |
| 348 expected_metrics.push_back( |
| 349 {internal::kUKMDeveloperEngagementMetricName, it}); |
| 350 |
| 351 EXPECT_THAT(entry_proto.metrics(), |
| 352 UnorderedPointwise(CompareMetrics(), expected_metrics)); |
| 353 } |
| 354 |
| 355 MATCHER(CompareMetricsIgnoringMillisecondsSinceFormLoaded, "") { |
| 356 const ukm::Entry_Metric& lhs = ::testing::get<0>(arg); |
| 357 const std::pair<const char*, int64_t>& rhs = ::testing::get<1>(arg); |
| 358 return lhs.metric_hash() == base::HashMetricName(rhs.first) && |
| 359 (lhs.value() == rhs.second || |
| 360 (lhs.value() > 0 && |
| 361 rhs.first == internal::kUKMMillisecondsSinceFormLoadedMetricName)); |
| 362 } |
| 363 |
| 364 void VerifyFormInteractionUkm( |
| 365 const FormData& form, |
| 366 const ukm::TestUkmService* ukm_service, |
| 367 const char* event_name, |
| 368 const std::vector<std::vector<std::pair<const char*, int64_t>>>& |
| 369 expected_metrics) { |
| 370 size_t expected_metrics_index = 0; |
| 371 for (size_t i = 0; i < ukm_service->entries_count(); ++i) { |
| 372 const ukm::UkmEntry* entry = ukm_service->GetEntry(i); |
| 373 if (entry->event_hash() != base::HashMetricName(event_name)) |
| 374 continue; |
| 375 |
| 376 ukm::Entry entry_proto; |
| 377 entry->PopulateProto(&entry_proto); |
| 378 |
| 379 const ukm::UkmSource* source = |
| 380 ukm_service->GetSourceForSourceId(entry_proto.source_id()); |
| 381 ASSERT_NE(nullptr, source); |
| 382 EXPECT_EQ(form.origin, source->url()); |
| 383 |
| 384 ASSERT_LT(expected_metrics_index, expected_metrics.size()); |
| 385 EXPECT_THAT( |
| 386 entry_proto.metrics(), |
| 387 UnorderedPointwise(CompareMetricsIgnoringMillisecondsSinceFormLoaded(), |
| 388 expected_metrics[expected_metrics_index++])); |
| 389 } |
| 390 } |
| 391 |
| 392 void VerifySubmitFormUkm(const FormData& form, |
| 393 const ukm::TestUkmService* ukm_service, |
| 394 AutofillMetrics::AutofillFormSubmittedState state) { |
| 395 VerifyFormInteractionUkm( |
| 396 form, ukm_service, internal::kUKMFormSubmittedEntryName, |
| 397 {{{internal::kUKMAutofillFormSubmittedStateMetricName, state}, |
| 398 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}}); |
| 399 } |
| 400 |
320 } // namespace | 401 } // namespace |
321 | 402 |
322 // This is defined in the autofill_metrics.cc implementation file. | 403 // This is defined in the autofill_metrics.cc implementation file. |
323 int GetFieldTypeGroupMetric(ServerFieldType field_type, | 404 int GetFieldTypeGroupMetric(ServerFieldType field_type, |
324 AutofillMetrics::FieldTypeQualityMetric metric); | 405 AutofillMetrics::FieldTypeQualityMetric metric); |
325 | 406 |
326 class AutofillMetricsTest : public testing::Test { | 407 class AutofillMetricsTest : public testing::Test { |
327 public: | 408 public: |
328 ~AutofillMetricsTest() override; | 409 ~AutofillMetricsTest() override; |
329 | 410 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 // PersonalDataManager to be around when it gets destroyed. | 468 // PersonalDataManager to be around when it gets destroyed. |
388 autofill_manager_.reset(); | 469 autofill_manager_.reset(); |
389 autofill_driver_.reset(); | 470 autofill_driver_.reset(); |
390 personal_data_.reset(); | 471 personal_data_.reset(); |
391 signin_manager_->Shutdown(); | 472 signin_manager_->Shutdown(); |
392 signin_manager_.reset(); | 473 signin_manager_.reset(); |
393 account_tracker_->Shutdown(); | 474 account_tracker_->Shutdown(); |
394 account_tracker_.reset(); | 475 account_tracker_.reset(); |
395 signin_client_.reset(); | 476 signin_client_.reset(); |
396 test::ReenableSystemServices(); | 477 test::ReenableSystemServices(); |
| 478 autofill_client_.GetTestUkmService()->Purge(); |
397 } | 479 } |
398 | 480 |
399 void AutofillMetricsTest::EnableWalletSync() { | 481 void AutofillMetricsTest::EnableWalletSync() { |
400 signin_manager_->SetAuthenticatedAccountInfo("12345", "syncuser@example.com"); | 482 signin_manager_->SetAuthenticatedAccountInfo("12345", "syncuser@example.com"); |
401 } | 483 } |
402 | 484 |
403 void AutofillMetricsTest::EnableUkmLogging() { | 485 void AutofillMetricsTest::EnableUkmLogging() { |
404 scoped_feature_list_.InitAndEnableFeature(kAutofillUkmLogging); | 486 scoped_feature_list_.InitAndEnableFeature(kAutofillUkmLogging); |
405 } | 487 } |
406 | 488 |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 field.is_autofilled = false; | 769 field.is_autofilled = false; |
688 form.fields.push_back(field); | 770 form.fields.push_back(field); |
689 | 771 |
690 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field); | 772 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field); |
691 field.is_autofilled = false; | 773 field.is_autofilled = false; |
692 form.fields.push_back(field); | 774 form.fields.push_back(field); |
693 | 775 |
694 // Simulate a OnFormsSeen() call that should trigger the recording. | 776 // Simulate a OnFormsSeen() call that should trigger the recording. |
695 std::vector<FormData> forms; | 777 std::vector<FormData> forms; |
696 forms.push_back(form); | 778 forms.push_back(form); |
697 autofill_manager_->OnFormsSeen(forms, base::TimeTicks::Now()); | 779 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); |
698 | 780 |
699 // Because these metrics are related to timing, it is not possible to know in | 781 // Because these metrics are related to timing, it is not possible to know in |
700 // advance which bucket the sample will fall into, so we just need to make | 782 // advance which bucket the sample will fall into, so we just need to make |
701 // sure we have valid samples. | 783 // sure we have valid samples. |
702 EXPECT_FALSE( | 784 EXPECT_FALSE( |
703 histogram_tester.GetAllSamples("Autofill.Timing.DetermineHeuristicTypes") | 785 histogram_tester.GetAllSamples("Autofill.Timing.DetermineHeuristicTypes") |
704 .empty()); | 786 .empty()); |
705 EXPECT_FALSE( | 787 EXPECT_FALSE( |
706 histogram_tester.GetAllSamples("Autofill.Timing.ParseForm").empty()); | 788 histogram_tester.GetAllSamples("Autofill.Timing.ParseForm").empty()); |
707 } | 789 } |
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1538 autofill_manager_->OnTextFieldDidChange(form, form.fields[0], TimeTicks()); | 1620 autofill_manager_->OnTextFieldDidChange(form, form.fields[0], TimeTicks()); |
1539 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks()); | 1621 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks()); |
1540 | 1622 |
1541 // Simulate form submission. | 1623 // Simulate form submission. |
1542 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 1624 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
1543 | 1625 |
1544 // An autofillable form was submitted, and the number of edited autofilled | 1626 // An autofillable form was submitted, and the number of edited autofilled |
1545 // fields is logged. | 1627 // fields is logged. |
1546 histogram_tester.ExpectUniqueSample( | 1628 histogram_tester.ExpectUniqueSample( |
1547 "Autofill.NumberOfEditedAutofilledFieldsAtSubmission", 2, 1); | 1629 "Autofill.NumberOfEditedAutofilledFieldsAtSubmission", 2, 1); |
| 1630 |
| 1631 // UKM must not be logged unless enabled. |
| 1632 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
| 1633 EXPECT_EQ(0U, ukm_service->sources_count()); |
| 1634 EXPECT_EQ(0U, ukm_service->entries_count()); |
1548 } | 1635 } |
1549 | 1636 |
1550 // Verify that when resetting the autofill manager (such as during a | 1637 // Verify that when resetting the autofill manager (such as during a |
1551 // navigation), the proper number of edited fields is logged. | 1638 // navigation), the proper number of edited fields is logged. |
1552 TEST_F(AutofillMetricsTest, NumberOfEditedAutofilledFields_NoSubmission) { | 1639 TEST_F(AutofillMetricsTest, NumberOfEditedAutofilledFields_NoSubmission) { |
1553 // Construct a fillable form. | 1640 // Construct a fillable form. |
1554 FormData form; | 1641 FormData form; |
1555 form.name = ASCIIToUTF16("TestForm"); | 1642 form.name = ASCIIToUTF16("TestForm"); |
1556 form.origin = GURL("http://example.com/form.html"); | 1643 form.origin = GURL("http://example.com/form.html"); |
1557 form.action = GURL("http://example.com/submit.html"); | 1644 form.action = GURL("http://example.com/submit.html"); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1714 FormFieldData field; | 1801 FormFieldData field; |
1715 test::CreateTestFormField("Name", "name", "", "text", &field); | 1802 test::CreateTestFormField("Name", "name", "", "text", &field); |
1716 form.fields.push_back(field); | 1803 form.fields.push_back(field); |
1717 test::CreateTestFormField("Email", "email", "", "text", &field); | 1804 test::CreateTestFormField("Email", "email", "", "text", &field); |
1718 form.fields.push_back(field); | 1805 form.fields.push_back(field); |
1719 | 1806 |
1720 std::vector<FormData> forms(1, form); | 1807 std::vector<FormData> forms(1, form); |
1721 | 1808 |
1722 // Ensure no metrics are logged when loading a non-fillable form. | 1809 // Ensure no metrics are logged when loading a non-fillable form. |
1723 { | 1810 { |
1724 autofill_manager_->OnFormsSeen(forms, TimeTicks()); | 1811 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); |
1725 autofill_manager_->Reset(); | 1812 autofill_manager_->Reset(); |
1726 | 1813 |
1727 EXPECT_EQ(0U, ukm_service->sources_count()); | 1814 EXPECT_EQ(0U, ukm_service->sources_count()); |
1728 EXPECT_EQ(0U, ukm_service->entries_count()); | 1815 EXPECT_EQ(0U, ukm_service->entries_count()); |
1729 } | 1816 } |
1730 | 1817 |
1731 // Add another field to the form, so that it becomes fillable. | 1818 // Add another field to the form, so that it becomes fillable. |
1732 test::CreateTestFormField("Phone", "phone", "", "text", &field); | 1819 test::CreateTestFormField("Phone", "phone", "", "text", &field); |
1733 forms.back().fields.push_back(field); | 1820 forms.back().fields.push_back(field); |
1734 | 1821 |
1735 // Expect the "form parsed without field type hints" metric to be logged. | 1822 // Expect the "form parsed without field type hints" metric and the |
| 1823 // "form loaded" form interaction event to be logged. |
1736 { | 1824 { |
1737 autofill_manager_->OnFormsSeen(forms, TimeTicks()); | 1825 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); |
1738 autofill_manager_->Reset(); | 1826 autofill_manager_->Reset(); |
1739 | 1827 |
| 1828 ASSERT_EQ(1U, ukm_service->entries_count()); |
1740 ASSERT_EQ(1U, ukm_service->sources_count()); | 1829 ASSERT_EQ(1U, ukm_service->sources_count()); |
1741 const ukm::UkmSource* source = | 1830 VerifyDeveloperEngagementUkm( |
1742 ukm_service->GetSourceForUrl(form.origin.spec().c_str()); | 1831 form, ukm_service, |
1743 ASSERT_NE(nullptr, source); | 1832 {AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS}); |
1744 | |
1745 ASSERT_EQ(1U, ukm_service->entries_count()); | |
1746 const ukm::UkmEntry* entry = ukm_service->GetEntry(0); | |
1747 EXPECT_EQ(source->id(), entry->source_id()); | |
1748 | |
1749 ukm::Entry entry_proto; | |
1750 entry->PopulateProto(&entry_proto); | |
1751 EXPECT_EQ(source->id(), entry_proto.source_id()); | |
1752 EXPECT_EQ(base::HashMetricName(internal::kUKMDeveloperEngagementEntryName), | |
1753 entry_proto.event_hash()); | |
1754 const ukm::Entry_Metric* metric = FindMetric( | |
1755 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics()); | |
1756 ASSERT_NE(nullptr, metric); | |
1757 EXPECT_EQ(AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS, | |
1758 metric->value()); | |
1759 } | 1833 } |
1760 } | 1834 } |
1761 | 1835 |
1762 // Verify that we correctly log UKM for form parsed with type hints regarding | 1836 // Verify that we correctly log UKM for form parsed with type hints regarding |
1763 // developer engagement. | 1837 // developer engagement. |
1764 TEST_F(AutofillMetricsTest, | 1838 TEST_F(AutofillMetricsTest, |
1765 UkmDeveloperEngagement_LogFillableFormParsedWithTypeHints) { | 1839 UkmDeveloperEngagement_LogFillableFormParsedWithTypeHints) { |
1766 EnableUkmLogging(); | 1840 EnableUkmLogging(); |
1767 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); | 1841 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
1768 | 1842 |
(...skipping 22 matching lines...) Expand all Loading... |
1791 test::CreateTestFormField("", "", "", "text", &field); | 1865 test::CreateTestFormField("", "", "", "text", &field); |
1792 field.autocomplete_attribute = "given-name"; | 1866 field.autocomplete_attribute = "given-name"; |
1793 forms.back().fields.push_back(field); | 1867 forms.back().fields.push_back(field); |
1794 test::CreateTestFormField("", "", "", "text", &field); | 1868 test::CreateTestFormField("", "", "", "text", &field); |
1795 field.autocomplete_attribute = "email"; | 1869 field.autocomplete_attribute = "email"; |
1796 forms.back().fields.push_back(field); | 1870 forms.back().fields.push_back(field); |
1797 test::CreateTestFormField("", "", "", "text", &field); | 1871 test::CreateTestFormField("", "", "", "text", &field); |
1798 field.autocomplete_attribute = "address-line1"; | 1872 field.autocomplete_attribute = "address-line1"; |
1799 forms.back().fields.push_back(field); | 1873 forms.back().fields.push_back(field); |
1800 | 1874 |
1801 // Expect the "form parsed with field type hints" metric to be logged. | 1875 // Expect the "form parsed without field type hints" metric and the |
| 1876 // "form loaded" form interaction event to be logged. |
1802 { | 1877 { |
1803 autofill_manager_->OnFormsSeen(forms, TimeTicks()); | 1878 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); |
1804 autofill_manager_->Reset(); | 1879 autofill_manager_->Reset(); |
1805 | 1880 |
| 1881 ASSERT_EQ(1U, ukm_service->entries_count()); |
1806 ASSERT_EQ(1U, ukm_service->sources_count()); | 1882 ASSERT_EQ(1U, ukm_service->sources_count()); |
1807 const ukm::UkmSource* source = | 1883 VerifyDeveloperEngagementUkm( |
1808 ukm_service->GetSourceForUrl(form.origin.spec().c_str()); | 1884 form, ukm_service, |
1809 ASSERT_NE(nullptr, source); | 1885 {AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS}); |
1810 | |
1811 ASSERT_EQ(1U, ukm_service->entries_count()); | |
1812 const ukm::UkmEntry* entry = ukm_service->GetEntry(0); | |
1813 EXPECT_EQ(source->id(), entry->source_id()); | |
1814 | |
1815 ukm::Entry entry_proto; | |
1816 entry->PopulateProto(&entry_proto); | |
1817 EXPECT_EQ(source->id(), entry_proto.source_id()); | |
1818 EXPECT_EQ(base::HashMetricName(internal::kUKMDeveloperEngagementEntryName), | |
1819 entry_proto.event_hash()); | |
1820 const ukm::Entry_Metric* metric = FindMetric( | |
1821 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics()); | |
1822 ASSERT_NE(nullptr, metric); | |
1823 EXPECT_EQ(AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS, | |
1824 metric->value()); | |
1825 } | 1886 } |
1826 } | 1887 } |
1827 | 1888 |
1828 // Verify that we correctly log UKM for form parsed with type hints regarding | 1889 // Verify that we correctly log UKM for form parsed with type hints regarding |
1829 // developer engagement. | 1890 // developer engagement. |
1830 TEST_F(AutofillMetricsTest, UkmDeveloperEngagement_LogUpiVpaTypeHint) { | 1891 TEST_F(AutofillMetricsTest, UkmDeveloperEngagement_LogUpiVpaTypeHint) { |
1831 EnableUkmLogging(); | 1892 EnableUkmLogging(); |
1832 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); | 1893 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
1833 | 1894 |
1834 FormData form; | 1895 FormData form; |
1835 form.name = ASCIIToUTF16("TestForm"); | 1896 form.name = ASCIIToUTF16("TestForm"); |
1836 form.origin = GURL("http://example.com/form.html"); | 1897 form.origin = GURL("http://example.com/form.html"); |
1837 form.action = GURL("http://example.com/submit.html"); | 1898 form.action = GURL("http://example.com/submit.html"); |
1838 | 1899 |
1839 FormFieldData field; | 1900 FormFieldData field; |
1840 test::CreateTestFormField("Name", "name", "", "text", &field); | 1901 test::CreateTestFormField("Name", "name", "", "text", &field); |
1841 form.fields.push_back(field); | 1902 form.fields.push_back(field); |
1842 test::CreateTestFormField("Email", "email", "", "text", &field); | 1903 test::CreateTestFormField("Email", "email", "", "text", &field); |
1843 form.fields.push_back(field); | 1904 form.fields.push_back(field); |
1844 test::CreateTestFormField("Payment", "payment", "", "text", &field); | 1905 test::CreateTestFormField("Payment", "payment", "", "text", &field); |
1845 field.autocomplete_attribute = "upi-vpa"; | 1906 field.autocomplete_attribute = "upi-vpa"; |
1846 form.fields.push_back(field); | 1907 form.fields.push_back(field); |
1847 | 1908 |
1848 std::vector<FormData> forms(1, form); | 1909 std::vector<FormData> forms(1, form); |
1849 | 1910 |
1850 // Expect the "upi-vpa hint" metric to be logged. | 1911 // Expect the "upi-vpa hint" metric to be logged and the "form loaded" form |
| 1912 // interaction event to be logged. |
1851 { | 1913 { |
1852 autofill_manager_->OnFormsSeen(forms, TimeTicks()); | 1914 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); |
1853 autofill_manager_->Reset(); | 1915 autofill_manager_->Reset(); |
1854 | 1916 |
| 1917 ASSERT_EQ(1U, ukm_service->entries_count()); |
1855 ASSERT_EQ(1U, ukm_service->sources_count()); | 1918 ASSERT_EQ(1U, ukm_service->sources_count()); |
1856 const ukm::UkmSource* source = | 1919 VerifyDeveloperEngagementUkm(form, ukm_service, |
1857 ukm_service->GetSourceForUrl(form.origin.spec().c_str()); | 1920 {AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT}); |
1858 ASSERT_NE(nullptr, source); | 1921 ukm_service->Purge(); |
| 1922 } |
1859 | 1923 |
1860 ASSERT_EQ(1U, ukm_service->entries_count()); | 1924 // Add another field with an author-specified field type to the form. |
1861 const ukm::UkmEntry* entry = ukm_service->GetEntry(0); | 1925 test::CreateTestFormField("", "", "", "text", &field); |
1862 EXPECT_EQ(source->id(), entry->source_id()); | 1926 field.autocomplete_attribute = "address-line1"; |
| 1927 forms.back().fields.push_back(field); |
1863 | 1928 |
1864 ukm::Entry entry_proto; | 1929 { |
1865 entry->PopulateProto(&entry_proto); | 1930 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); |
1866 EXPECT_EQ(source->id(), entry_proto.source_id()); | 1931 autofill_manager_->Reset(); |
1867 EXPECT_EQ(base::HashMetricName(internal::kUKMDeveloperEngagementEntryName), | 1932 |
1868 entry_proto.event_hash()); | 1933 VerifyDeveloperEngagementUkm( |
1869 const ukm::Entry_Metric* metric = FindMetric( | 1934 form, ukm_service, |
1870 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics()); | 1935 {AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS, |
1871 ASSERT_NE(nullptr, metric); | 1936 AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT}); |
1872 EXPECT_EQ(AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT, metric->value()); | |
1873 } | 1937 } |
1874 } | 1938 } |
1875 | 1939 |
1876 // Test that the profile count is logged correctly. | 1940 // Test that the profile count is logged correctly. |
1877 TEST_F(AutofillMetricsTest, StoredProfileCount) { | 1941 TEST_F(AutofillMetricsTest, StoredProfileCount) { |
1878 // The metric should be logged when the profiles are first loaded. | 1942 // The metric should be logged when the profiles are first loaded. |
1879 { | 1943 { |
1880 base::HistogramTester histogram_tester; | 1944 base::HistogramTester histogram_tester; |
1881 personal_data_->LoadProfiles(); | 1945 personal_data_->LoadProfiles(); |
1882 histogram_tester.ExpectUniqueSample("Autofill.StoredProfileCount", 2, 1); | 1946 histogram_tester.ExpectUniqueSample("Autofill.StoredProfileCount", 2, 1); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2045 // Simulate activating the autofill popup for the email field after typing. | 2109 // Simulate activating the autofill popup for the email field after typing. |
2046 form.fields[0].is_autofilled = true; | 2110 form.fields[0].is_autofilled = true; |
2047 base::HistogramTester histogram_tester; | 2111 base::HistogramTester histogram_tester; |
2048 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 2112 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2049 histogram_tester.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0); | 2113 histogram_tester.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0); |
2050 } | 2114 } |
2051 } | 2115 } |
2052 | 2116 |
2053 // Test that the credit card checkout flow user actions are correctly logged. | 2117 // Test that the credit card checkout flow user actions are correctly logged. |
2054 TEST_F(AutofillMetricsTest, CreditCardCheckoutFlowUserActions) { | 2118 TEST_F(AutofillMetricsTest, CreditCardCheckoutFlowUserActions) { |
| 2119 EnableUkmLogging(); |
| 2120 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
| 2121 |
2055 personal_data_->RecreateCreditCards( | 2122 personal_data_->RecreateCreditCards( |
2056 true /* include_local_credit_card */, | 2123 true /* include_local_credit_card */, |
2057 false /* include_masked_server_credit_card */, | 2124 false /* include_masked_server_credit_card */, |
2058 false /* include_full_server_credit_card */); | 2125 false /* include_full_server_credit_card */); |
2059 | 2126 |
2060 // Set up our form data. | 2127 // Set up our form data. |
2061 FormData form; | 2128 FormData form; |
2062 form.name = ASCIIToUTF16("TestForm"); | 2129 form.name = ASCIIToUTF16("TestForm"); |
2063 form.origin = GURL("http://example.com/form.html"); | 2130 form.origin = GURL("http://example.com/form.html"); |
2064 form.action = GURL("http://example.com/submit.html"); | 2131 form.action = GURL("http://example.com/submit.html"); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2120 // Simulate submitting the credit card form. | 2187 // Simulate submitting the credit card form. |
2121 { | 2188 { |
2122 base::UserActionTester user_action_tester; | 2189 base::UserActionTester user_action_tester; |
2123 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 2190 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2124 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 2191 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2125 EXPECT_EQ(1, | 2192 EXPECT_EQ(1, |
2126 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); | 2193 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); |
2127 EXPECT_EQ(1, user_action_tester.GetActionCount( | 2194 EXPECT_EQ(1, user_action_tester.GetActionCount( |
2128 "Autofill_FormSubmitted_NonFillable")); | 2195 "Autofill_FormSubmitted_NonFillable")); |
2129 } | 2196 } |
| 2197 |
| 2198 VerifyFormInteractionUkm( |
| 2199 form, ukm_service, internal::kUKMSuggestionsShownEntryName, |
| 2200 {{{internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}}); |
| 2201 // Expect 2 |FORM_EVENT_LOCAL_SUGGESTION_FILLED| events. First, from |
| 2202 // call to |external_delegate_->DidAcceptSuggestion|. Second, from call to |
| 2203 // |autofill_manager_->FillOrPreviewForm|. |
| 2204 VerifyFormInteractionUkm( |
| 2205 form, ukm_service, internal::kUKMSuggestionFilledEntryName, |
| 2206 {{{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD}, |
| 2207 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}, |
| 2208 {{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD}, |
| 2209 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}}); |
| 2210 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState| |
| 2211 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|. |
| 2212 VerifySubmitFormUkm(form, ukm_service, |
| 2213 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); |
2130 } | 2214 } |
2131 | 2215 |
2132 // Test that the profile checkout flow user actions are correctly logged. | 2216 // Test that the profile checkout flow user actions are correctly logged. |
2133 TEST_F(AutofillMetricsTest, ProfileCheckoutFlowUserActions) { | 2217 TEST_F(AutofillMetricsTest, ProfileCheckoutFlowUserActions) { |
| 2218 EnableUkmLogging(); |
| 2219 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
| 2220 |
2134 // Create a profile. | 2221 // Create a profile. |
2135 personal_data_->RecreateProfile(); | 2222 personal_data_->RecreateProfile(); |
2136 | 2223 |
2137 // Set up our form data. | 2224 // Set up our form data. |
2138 FormData form; | 2225 FormData form; |
2139 form.name = ASCIIToUTF16("TestForm"); | 2226 form.name = ASCIIToUTF16("TestForm"); |
2140 form.origin = GURL("http://example.com/form.html"); | 2227 form.origin = GURL("http://example.com/form.html"); |
2141 form.action = GURL("http://example.com/submit.html"); | 2228 form.action = GURL("http://example.com/submit.html"); |
2142 | 2229 |
2143 FormFieldData field; | 2230 FormFieldData field; |
(...skipping 27 matching lines...) Expand all Loading... |
2171 EXPECT_EQ(1, user_action_tester.GetActionCount( | 2258 EXPECT_EQ(1, user_action_tester.GetActionCount( |
2172 "Autofill_ShowedProfileSuggestions")); | 2259 "Autofill_ShowedProfileSuggestions")); |
2173 } | 2260 } |
2174 | 2261 |
2175 // Simulate selecting a profile suggestions. | 2262 // Simulate selecting a profile suggestions. |
2176 { | 2263 { |
2177 base::UserActionTester user_action_tester; | 2264 base::UserActionTester user_action_tester; |
2178 std::string guid("00000000-0000-0000-0000-000000000001"); // local profile. | 2265 std::string guid("00000000-0000-0000-0000-000000000001"); // local profile. |
2179 external_delegate_->DidAcceptSuggestion( | 2266 external_delegate_->DidAcceptSuggestion( |
2180 ASCIIToUTF16("Test"), | 2267 ASCIIToUTF16("Test"), |
2181 autofill_manager_->MakeFrontendID(guid, std::string()), 0); | 2268 autofill_manager_->MakeFrontendID(std::string(), guid), 0); |
2182 EXPECT_EQ(1, | 2269 EXPECT_EQ(1, |
2183 user_action_tester.GetActionCount("Autofill_SelectedSuggestion")); | 2270 user_action_tester.GetActionCount("Autofill_SelectedSuggestion")); |
2184 } | 2271 } |
2185 | 2272 |
2186 // Simulate filling a profile suggestion. | 2273 // Simulate filling a profile suggestion. |
2187 { | 2274 { |
2188 base::UserActionTester user_action_tester; | 2275 base::UserActionTester user_action_tester; |
2189 std::string guid("00000000-0000-0000-0000-000000000001"); // local profile. | 2276 std::string guid("00000000-0000-0000-0000-000000000001"); // local profile. |
2190 autofill_manager_->FillOrPreviewForm( | 2277 autofill_manager_->FillOrPreviewForm( |
2191 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), | 2278 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), |
2192 autofill_manager_->MakeFrontendID(std::string(), guid)); | 2279 autofill_manager_->MakeFrontendID(std::string(), guid)); |
2193 EXPECT_EQ(1, user_action_tester.GetActionCount( | 2280 EXPECT_EQ(1, user_action_tester.GetActionCount( |
2194 "Autofill_FilledProfileSuggestion")); | 2281 "Autofill_FilledProfileSuggestion")); |
2195 } | 2282 } |
2196 | 2283 |
2197 // Simulate submitting the profile form. | 2284 // Simulate submitting the profile form. |
2198 { | 2285 { |
2199 base::UserActionTester user_action_tester; | 2286 base::UserActionTester user_action_tester; |
2200 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 2287 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2201 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 2288 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2202 EXPECT_EQ(1, | 2289 EXPECT_EQ(1, |
2203 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); | 2290 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); |
2204 EXPECT_EQ(1, user_action_tester.GetActionCount( | 2291 EXPECT_EQ(1, user_action_tester.GetActionCount( |
2205 "Autofill_FormSubmitted_NonFillable")); | 2292 "Autofill_FormSubmitted_NonFillable")); |
2206 } | 2293 } |
| 2294 |
| 2295 VerifyFormInteractionUkm( |
| 2296 form, ukm_service, internal::kUKMSuggestionsShownEntryName, |
| 2297 {{{internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}}); |
| 2298 // Expect 2 |FORM_EVENT_LOCAL_SUGGESTION_FILLED| events. First, from |
| 2299 // call to |external_delegate_->DidAcceptSuggestion|. Second, from call to |
| 2300 // |autofill_manager_->FillOrPreviewForm|. |
| 2301 VerifyFormInteractionUkm( |
| 2302 form, ukm_service, internal::kUKMSuggestionFilledEntryName, |
| 2303 {{{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE}, |
| 2304 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}, |
| 2305 {{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE}, |
| 2306 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}}); |
| 2307 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState| |
| 2308 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|. |
| 2309 VerifySubmitFormUkm(form, ukm_service, |
| 2310 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); |
2207 } | 2311 } |
2208 | 2312 |
2209 // Tests that the Autofill_PolledCreditCardSuggestions user action is only | 2313 // Tests that the Autofill_PolledCreditCardSuggestions user action is only |
2210 // logged once if the field is queried repeatedly. | 2314 // logged once if the field is queried repeatedly. |
2211 TEST_F(AutofillMetricsTest, PolledCreditCardSuggestions_DebounceLogs) { | 2315 TEST_F(AutofillMetricsTest, PolledCreditCardSuggestions_DebounceLogs) { |
2212 personal_data_->RecreateCreditCards( | 2316 personal_data_->RecreateCreditCards( |
2213 true /* include_local_credit_card */, | 2317 true /* include_local_credit_card */, |
2214 false /* include_masked_server_credit_card */, | 2318 false /* include_masked_server_credit_card */, |
2215 false /* include_full_server_credit_card */); | 2319 false /* include_full_server_credit_card */); |
2216 | 2320 |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2486 base::HistogramTester histogram_tester; | 2590 base::HistogramTester histogram_tester; |
2487 autofill_manager_->DidShowSuggestions(false /* is_new_popup */, form, | 2591 autofill_manager_->DidShowSuggestions(false /* is_new_popup */, form, |
2488 field); | 2592 field); |
2489 histogram_tester.ExpectBucketCount( | 2593 histogram_tester.ExpectBucketCount( |
2490 "Autofill.FormEvents.CreditCard", | 2594 "Autofill.FormEvents.CreditCard", |
2491 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN, 0); | 2595 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN, 0); |
2492 histogram_tester.ExpectBucketCount( | 2596 histogram_tester.ExpectBucketCount( |
2493 "Autofill.FormEvents.CreditCard", | 2597 "Autofill.FormEvents.CreditCard", |
2494 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 0); | 2598 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 0); |
2495 } | 2599 } |
| 2600 |
| 2601 // UKM must not be logged unless enabled. |
| 2602 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
| 2603 EXPECT_EQ(0U, ukm_service->sources_count()); |
| 2604 EXPECT_EQ(0U, ukm_service->entries_count()); |
2496 } | 2605 } |
2497 | 2606 |
2498 // Test that we log selected form event for credit cards. | 2607 // Test that we log selected form event for credit cards. |
2499 TEST_F(AutofillMetricsTest, CreditCardSelectedFormEvents) { | 2608 TEST_F(AutofillMetricsTest, CreditCardSelectedFormEvents) { |
2500 EnableWalletSync(); | 2609 EnableWalletSync(); |
2501 // Creating all kinds of cards. | 2610 // Creating all kinds of cards. |
2502 personal_data_->RecreateCreditCards( | 2611 personal_data_->RecreateCreditCards( |
2503 true /* include_local_credit_card */, | 2612 true /* include_local_credit_card */, |
2504 true /* include_masked_server_credit_card */, | 2613 true /* include_masked_server_credit_card */, |
2505 true /* include_full_server_credit_card */); | 2614 true /* include_full_server_credit_card */); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2618 { | 2727 { |
2619 // Simulating filling a masked card server suggestion. | 2728 // Simulating filling a masked card server suggestion. |
2620 base::HistogramTester histogram_tester; | 2729 base::HistogramTester histogram_tester; |
2621 std::string guid( | 2730 std::string guid( |
2622 "10000000-0000-0000-0000-000000000002"); // masked server card | 2731 "10000000-0000-0000-0000-000000000002"); // masked server card |
2623 autofill_manager_->FillOrPreviewForm( | 2732 autofill_manager_->FillOrPreviewForm( |
2624 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.back(), | 2733 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.back(), |
2625 autofill_manager_->MakeFrontendID(guid, std::string())); | 2734 autofill_manager_->MakeFrontendID(guid, std::string())); |
2626 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS, | 2735 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS, |
2627 "6011000990139424"); | 2736 "6011000990139424"); |
| 2737 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2628 histogram_tester.ExpectBucketCount( | 2738 histogram_tester.ExpectBucketCount( |
2629 "Autofill.FormEvents.CreditCard", | 2739 "Autofill.FormEvents.CreditCard", |
2630 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED, 1); | 2740 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED, 1); |
2631 histogram_tester.ExpectBucketCount( | 2741 histogram_tester.ExpectBucketCount( |
2632 "Autofill.FormEvents.CreditCard", | 2742 "Autofill.FormEvents.CreditCard", |
2633 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE, | 2743 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE, |
2634 1); | 2744 1); |
2635 } | 2745 } |
2636 | 2746 |
2637 // Recreating cards as the previous test should have upgraded the masked | 2747 // Recreating cards as the previous test should have upgraded the masked |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2751 std::string()); | 2861 std::string()); |
2752 histogram_tester.ExpectTotalCount( | 2862 histogram_tester.ExpectTotalCount( |
2753 "Autofill.UnmaskPrompt.GetRealPanDuration", 1); | 2863 "Autofill.UnmaskPrompt.GetRealPanDuration", 1); |
2754 histogram_tester.ExpectTotalCount( | 2864 histogram_tester.ExpectTotalCount( |
2755 "Autofill.UnmaskPrompt.GetRealPanDuration.Failure", 1); | 2865 "Autofill.UnmaskPrompt.GetRealPanDuration.Failure", 1); |
2756 } | 2866 } |
2757 } | 2867 } |
2758 | 2868 |
2759 // Test that we log submitted form events for credit cards. | 2869 // Test that we log submitted form events for credit cards. |
2760 TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) { | 2870 TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) { |
| 2871 EnableUkmLogging(); |
| 2872 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
| 2873 |
2761 EnableWalletSync(); | 2874 EnableWalletSync(); |
2762 // Creating all kinds of cards. | 2875 // Creating all kinds of cards. |
2763 personal_data_->RecreateCreditCards( | 2876 personal_data_->RecreateCreditCards( |
2764 true /* include_local_credit_card */, | 2877 true /* include_local_credit_card */, |
2765 true /* include_masked_server_credit_card */, | 2878 true /* include_masked_server_credit_card */, |
2766 true /* include_full_server_credit_card */); | 2879 true /* include_full_server_credit_card */); |
2767 // Set up our form data. | 2880 // Set up our form data. |
2768 FormData form; | 2881 FormData form; |
2769 form.name = ASCIIToUTF16("TestForm"); | 2882 form.name = ASCIIToUTF16("TestForm"); |
2770 form.origin = GURL("http://example.com/form.html"); | 2883 form.origin = GURL("http://example.com/form.html"); |
(...skipping 19 matching lines...) Expand all Loading... |
2790 // Simulating submission with no filled data. | 2903 // Simulating submission with no filled data. |
2791 base::HistogramTester histogram_tester; | 2904 base::HistogramTester histogram_tester; |
2792 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 2905 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2793 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 2906 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2794 histogram_tester.ExpectBucketCount( | 2907 histogram_tester.ExpectBucketCount( |
2795 "Autofill.FormEvents.CreditCard", | 2908 "Autofill.FormEvents.CreditCard", |
2796 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); | 2909 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); |
2797 histogram_tester.ExpectBucketCount( | 2910 histogram_tester.ExpectBucketCount( |
2798 "Autofill.FormEvents.CreditCard", | 2911 "Autofill.FormEvents.CreditCard", |
2799 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); | 2912 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); |
| 2913 |
| 2914 VerifySubmitFormUkm(form, ukm_service, |
| 2915 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); |
2800 } | 2916 } |
2801 | 2917 |
2802 // Reset the autofill manager state. | 2918 // Reset the autofill manager state and purge UKM logs. |
2803 autofill_manager_->Reset(); | 2919 autofill_manager_->Reset(); |
| 2920 ukm_service->Purge(); |
| 2921 |
2804 autofill_manager_->AddSeenForm(form, field_types, field_types); | 2922 autofill_manager_->AddSeenForm(form, field_types, field_types); |
2805 | 2923 |
2806 { | 2924 { |
2807 // Simulating submission with suggestion shown. | 2925 // Simulating submission with suggestion shown. |
2808 base::HistogramTester histogram_tester; | 2926 base::HistogramTester histogram_tester; |
2809 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); | 2927 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); |
2810 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 2928 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2811 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 2929 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2812 histogram_tester.ExpectBucketCount( | 2930 histogram_tester.ExpectBucketCount( |
2813 "Autofill.FormEvents.CreditCard", | 2931 "Autofill.FormEvents.CreditCard", |
2814 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_SUBMITTED_ONCE, 1); | 2932 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_SUBMITTED_ONCE, 1); |
2815 histogram_tester.ExpectBucketCount( | 2933 histogram_tester.ExpectBucketCount( |
2816 "Autofill.FormEvents.CreditCard", | 2934 "Autofill.FormEvents.CreditCard", |
2817 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 1); | 2935 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 1); |
| 2936 |
| 2937 VerifyFormInteractionUkm( |
| 2938 form, ukm_service, internal::kUKMSuggestionsShownEntryName, |
| 2939 {{{internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}}); |
| 2940 VerifySubmitFormUkm(form, ukm_service, |
| 2941 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); |
2818 } | 2942 } |
2819 | 2943 |
2820 // Reset the autofill manager state. | 2944 // Reset the autofill manager state and purge UKM logs. |
2821 autofill_manager_->Reset(); | 2945 autofill_manager_->Reset(); |
| 2946 ukm_service->Purge(); |
| 2947 |
2822 autofill_manager_->AddSeenForm(form, field_types, field_types); | 2948 autofill_manager_->AddSeenForm(form, field_types, field_types); |
2823 | 2949 |
2824 { | 2950 { |
2825 // Simulating submission with filled local data. | 2951 // Simulating submission with filled local data. |
2826 base::HistogramTester histogram_tester; | 2952 base::HistogramTester histogram_tester; |
2827 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 2953 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2828 std::string guid("10000000-0000-0000-0000-000000000001"); // local card | 2954 std::string guid("10000000-0000-0000-0000-000000000001"); // local card |
2829 autofill_manager_->FillOrPreviewForm( | 2955 autofill_manager_->FillOrPreviewForm( |
2830 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), | 2956 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), |
2831 autofill_manager_->MakeFrontendID(guid, std::string())); | 2957 autofill_manager_->MakeFrontendID(guid, std::string())); |
2832 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 2958 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2833 histogram_tester.ExpectBucketCount( | 2959 histogram_tester.ExpectBucketCount( |
2834 "Autofill.FormEvents.CreditCard", | 2960 "Autofill.FormEvents.CreditCard", |
2835 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 1); | 2961 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 1); |
2836 histogram_tester.ExpectBucketCount( | 2962 histogram_tester.ExpectBucketCount( |
2837 "Autofill.FormEvents.CreditCard", | 2963 "Autofill.FormEvents.CreditCard", |
2838 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 1); | 2964 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 1); |
| 2965 |
| 2966 VerifyFormInteractionUkm( |
| 2967 form, ukm_service, internal::kUKMSuggestionFilledEntryName, |
| 2968 {{{internal::kUKMRecordTypeMetricName, CreditCard::LOCAL_CARD}, |
| 2969 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}}); |
| 2970 VerifySubmitFormUkm(form, ukm_service, |
| 2971 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); |
2839 } | 2972 } |
2840 | 2973 |
2841 // Reset the autofill manager state. | 2974 // Reset the autofill manager state and purge UKM logs. |
2842 autofill_manager_->Reset(); | 2975 autofill_manager_->Reset(); |
| 2976 ukm_service->Purge(); |
| 2977 |
2843 autofill_manager_->AddSeenForm(form, field_types, field_types); | 2978 autofill_manager_->AddSeenForm(form, field_types, field_types); |
2844 | 2979 |
2845 { | 2980 { |
2846 // Simulating submission with filled server data. | 2981 // Simulating submission with filled server data. |
2847 base::HistogramTester histogram_tester; | 2982 base::HistogramTester histogram_tester; |
2848 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 2983 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2849 std::string guid( | 2984 std::string guid( |
2850 "10000000-0000-0000-0000-000000000003"); // full server card | 2985 "10000000-0000-0000-0000-000000000003"); // full server card |
2851 autofill_manager_->FillOrPreviewForm( | 2986 autofill_manager_->FillOrPreviewForm( |
2852 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), | 2987 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), |
2853 autofill_manager_->MakeFrontendID(guid, std::string())); | 2988 autofill_manager_->MakeFrontendID(guid, std::string())); |
2854 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 2989 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2855 histogram_tester.ExpectBucketCount( | 2990 histogram_tester.ExpectBucketCount( |
2856 "Autofill.FormEvents.CreditCard", | 2991 "Autofill.FormEvents.CreditCard", |
2857 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 1); | 2992 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 1); |
2858 histogram_tester.ExpectBucketCount( | 2993 histogram_tester.ExpectBucketCount( |
2859 "Autofill.FormEvents.CreditCard", | 2994 "Autofill.FormEvents.CreditCard", |
2860 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 1); | 2995 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 1); |
| 2996 |
| 2997 VerifyFormInteractionUkm( |
| 2998 form, ukm_service, internal::kUKMSuggestionFilledEntryName, |
| 2999 {{{internal::kUKMRecordTypeMetricName, CreditCard::FULL_SERVER_CARD}, |
| 3000 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}}); |
| 3001 VerifySubmitFormUkm(form, ukm_service, |
| 3002 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); |
2861 } | 3003 } |
2862 | 3004 |
2863 // Reset the autofill manager state. | 3005 // Reset the autofill manager state and purge UKM logs. |
2864 autofill_manager_->Reset(); | 3006 autofill_manager_->Reset(); |
| 3007 ukm_service->Purge(); |
| 3008 |
2865 autofill_manager_->AddSeenForm(form, field_types, field_types); | 3009 autofill_manager_->AddSeenForm(form, field_types, field_types); |
2866 | 3010 |
2867 { | 3011 { |
2868 // Simulating submission with a masked card server suggestion. | 3012 // Simulating submission with a masked card server suggestion. |
2869 base::HistogramTester histogram_tester; | 3013 base::HistogramTester histogram_tester; |
2870 std::string guid( | 3014 std::string guid( |
2871 "10000000-0000-0000-0000-000000000002"); // masked server card | 3015 "10000000-0000-0000-0000-000000000002"); // masked server card |
2872 autofill_manager_->FillOrPreviewForm( | 3016 autofill_manager_->FillOrPreviewForm( |
2873 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.back(), | 3017 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.back(), |
2874 autofill_manager_->MakeFrontendID(guid, std::string())); | 3018 autofill_manager_->MakeFrontendID(guid, std::string())); |
2875 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS, | 3019 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS, |
2876 "6011000990139424"); | 3020 "6011000990139424"); |
| 3021 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2877 histogram_tester.ExpectBucketCount( | 3022 histogram_tester.ExpectBucketCount( |
2878 "Autofill.FormEvents.CreditCard", | 3023 "Autofill.FormEvents.CreditCard", |
2879 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED, 1); | 3024 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED, 1); |
2880 histogram_tester.ExpectBucketCount( | 3025 histogram_tester.ExpectBucketCount( |
2881 "Autofill.FormEvents.CreditCard", | 3026 "Autofill.FormEvents.CreditCard", |
2882 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE, | 3027 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE, |
2883 1); | 3028 1); |
| 3029 |
| 3030 VerifyFormInteractionUkm( |
| 3031 form, ukm_service, internal::kUKMSuggestionFilledEntryName, |
| 3032 {{{internal::kUKMRecordTypeMetricName, CreditCard::MASKED_SERVER_CARD}, |
| 3033 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}}); |
| 3034 VerifyFormInteractionUkm( |
| 3035 form, ukm_service, internal::kUKMSelectedMaskedServerCardEntryName, |
| 3036 {{{internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}}); |
| 3037 VerifySubmitFormUkm(form, ukm_service, |
| 3038 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); |
2884 } | 3039 } |
2885 | 3040 |
| 3041 // Reset the autofill manager state and purge UKM logs. |
| 3042 autofill_manager_->Reset(); |
| 3043 ukm_service->Purge(); |
| 3044 |
2886 // Recreating cards as the previous test should have upgraded the masked | 3045 // Recreating cards as the previous test should have upgraded the masked |
2887 // card to a full card. | 3046 // card to a full card. |
2888 personal_data_->RecreateCreditCards( | 3047 personal_data_->RecreateCreditCards( |
2889 true /* include_local_credit_card */, | 3048 true /* include_local_credit_card */, |
2890 true /* include_masked_server_credit_card */, | 3049 true /* include_masked_server_credit_card */, |
2891 true /* include_full_server_credit_card */); | 3050 true /* include_full_server_credit_card */); |
2892 | 3051 |
2893 // Reset the autofill manager state. | 3052 // Reset the autofill manager state. |
2894 autofill_manager_->Reset(); | 3053 autofill_manager_->Reset(); |
2895 autofill_manager_->AddSeenForm(form, field_types, field_types); | 3054 autofill_manager_->AddSeenForm(form, field_types, field_types); |
2896 | 3055 |
2897 { | 3056 { |
2898 // Simulating multiple submissions. | 3057 // Simulating multiple submissions. |
2899 base::HistogramTester histogram_tester; | 3058 base::HistogramTester histogram_tester; |
2900 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 3059 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
2901 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 3060 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
| 3061 |
| 3062 VerifyFormInteractionUkm( |
| 3063 form, ukm_service, internal::kUKMFormSubmittedEntryName, |
| 3064 {{{internal::kUKMAutofillFormSubmittedStateMetricName, |
| 3065 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, |
| 3066 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}}); |
| 3067 |
2902 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 3068 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
| 3069 |
| 3070 VerifyFormInteractionUkm( |
| 3071 form, ukm_service, internal::kUKMFormSubmittedEntryName, |
| 3072 {{{internal::kUKMAutofillFormSubmittedStateMetricName, |
| 3073 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, |
| 3074 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}, |
| 3075 {{internal::kUKMAutofillFormSubmittedStateMetricName, |
| 3076 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, |
| 3077 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}}); |
| 3078 |
2903 histogram_tester.ExpectBucketCount( | 3079 histogram_tester.ExpectBucketCount( |
2904 "Autofill.FormEvents.CreditCard", | 3080 "Autofill.FormEvents.CreditCard", |
2905 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); | 3081 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); |
2906 histogram_tester.ExpectBucketCount( | 3082 histogram_tester.ExpectBucketCount( |
2907 "Autofill.FormEvents.CreditCard", | 3083 "Autofill.FormEvents.CreditCard", |
2908 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 0); | 3084 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 0); |
2909 histogram_tester.ExpectBucketCount( | 3085 histogram_tester.ExpectBucketCount( |
2910 "Autofill.FormEvents.CreditCard", | 3086 "Autofill.FormEvents.CreditCard", |
2911 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0); | 3087 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0); |
2912 histogram_tester.ExpectBucketCount( | 3088 histogram_tester.ExpectBucketCount( |
(...skipping 16 matching lines...) Expand all Loading... |
2929 histogram_tester.ExpectBucketCount( | 3105 histogram_tester.ExpectBucketCount( |
2930 "Autofill.FormEvents.CreditCard", | 3106 "Autofill.FormEvents.CreditCard", |
2931 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0); | 3107 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0); |
2932 histogram_tester.ExpectBucketCount( | 3108 histogram_tester.ExpectBucketCount( |
2933 "Autofill.FormEvents.CreditCard", | 3109 "Autofill.FormEvents.CreditCard", |
2934 AutofillMetrics:: | 3110 AutofillMetrics:: |
2935 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SUBMITTED_ONCE, | 3111 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SUBMITTED_ONCE, |
2936 0); | 3112 0); |
2937 } | 3113 } |
2938 | 3114 |
2939 // Reset the autofill manager state. | 3115 // Reset the autofill manager state and purge UKM logs. |
2940 autofill_manager_->Reset(); | 3116 autofill_manager_->Reset(); |
| 3117 ukm_service->Purge(); |
| 3118 |
2941 autofill_manager_->AddSeenForm(form, field_types, field_types); | 3119 autofill_manager_->AddSeenForm(form, field_types, field_types); |
2942 | 3120 |
2943 { | 3121 { |
2944 // Simulating submission with suggestion shown but without previous | 3122 // Simulating submission with suggestion shown but without previous |
2945 // interaction. | 3123 // interaction. |
2946 base::HistogramTester histogram_tester; | 3124 base::HistogramTester histogram_tester; |
2947 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); | 3125 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); |
2948 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 3126 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
2949 histogram_tester.ExpectBucketCount( | 3127 histogram_tester.ExpectBucketCount( |
2950 "Autofill.FormEvents.CreditCard", | 3128 "Autofill.FormEvents.CreditCard", |
(...skipping 22 matching lines...) Expand all Loading... |
2973 "Autofill.FormEvents.CreditCard", | 3151 "Autofill.FormEvents.CreditCard", |
2974 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0); | 3152 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0); |
2975 histogram_tester.ExpectBucketCount( | 3153 histogram_tester.ExpectBucketCount( |
2976 "Autofill.FormEvents.CreditCard", | 3154 "Autofill.FormEvents.CreditCard", |
2977 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0); | 3155 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0); |
2978 histogram_tester.ExpectBucketCount( | 3156 histogram_tester.ExpectBucketCount( |
2979 "Autofill.FormEvents.CreditCard", | 3157 "Autofill.FormEvents.CreditCard", |
2980 AutofillMetrics:: | 3158 AutofillMetrics:: |
2981 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE, | 3159 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE, |
2982 0); | 3160 0); |
| 3161 |
| 3162 VerifyFormInteractionUkm( |
| 3163 form, ukm_service, internal::kUKMSuggestionsShownEntryName, |
| 3164 {{{internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}}); |
| 3165 VerifySubmitFormUkm(form, ukm_service, |
| 3166 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); |
2983 } | 3167 } |
2984 } | 3168 } |
2985 | 3169 |
2986 // Test that we log "will submit" (but not submitted) form events for credit | 3170 // Test that we log "will submit" (but not submitted) form events for credit |
2987 // cards. Mirrors CreditCardSubmittedFormEvents test but does not expect any | 3171 // cards. Mirrors CreditCardSubmittedFormEvents test but does not expect any |
2988 // "submitted" metrics. | 3172 // "submitted" metrics. |
2989 TEST_F(AutofillMetricsTest, CreditCardWillSubmitFormEvents) { | 3173 TEST_F(AutofillMetricsTest, CreditCardWillSubmitFormEvents) { |
2990 EnableWalletSync(); | 3174 EnableWalletSync(); |
2991 // Creating all kinds of cards. | 3175 // Creating all kinds of cards. |
2992 personal_data_->RecreateCreditCards( | 3176 personal_data_->RecreateCreditCards( |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3394 "Autofill.FormEvents.Address", | 3578 "Autofill.FormEvents.Address", |
3395 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED, 2); | 3579 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED, 2); |
3396 histogram_tester.ExpectBucketCount( | 3580 histogram_tester.ExpectBucketCount( |
3397 "Autofill.FormEvents.Address", | 3581 "Autofill.FormEvents.Address", |
3398 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE, 1); | 3582 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE, 1); |
3399 } | 3583 } |
3400 } | 3584 } |
3401 | 3585 |
3402 // Test that we log submitted form events for address. | 3586 // Test that we log submitted form events for address. |
3403 TEST_F(AutofillMetricsTest, AddressSubmittedFormEvents) { | 3587 TEST_F(AutofillMetricsTest, AddressSubmittedFormEvents) { |
| 3588 EnableUkmLogging(); |
| 3589 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
| 3590 |
3404 EnableWalletSync(); | 3591 EnableWalletSync(); |
3405 // Create a profile. | 3592 // Create a profile. |
3406 personal_data_->RecreateProfile(); | 3593 personal_data_->RecreateProfile(); |
3407 // Set up our form data. | 3594 // Set up our form data. |
3408 FormData form; | 3595 FormData form; |
3409 form.name = ASCIIToUTF16("TestForm"); | 3596 form.name = ASCIIToUTF16("TestForm"); |
3410 form.origin = GURL("http://example.com/form.html"); | 3597 form.origin = GURL("http://example.com/form.html"); |
3411 form.action = GURL("http://example.com/submit.html"); | 3598 form.action = GURL("http://example.com/submit.html"); |
3412 | 3599 |
3413 FormFieldData field; | 3600 FormFieldData field; |
(...skipping 16 matching lines...) Expand all Loading... |
3430 // Simulating submission with no filled data. | 3617 // Simulating submission with no filled data. |
3431 base::HistogramTester histogram_tester; | 3618 base::HistogramTester histogram_tester; |
3432 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 3619 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
3433 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 3620 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
3434 histogram_tester.ExpectBucketCount( | 3621 histogram_tester.ExpectBucketCount( |
3435 "Autofill.FormEvents.Address", | 3622 "Autofill.FormEvents.Address", |
3436 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); | 3623 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); |
3437 histogram_tester.ExpectBucketCount( | 3624 histogram_tester.ExpectBucketCount( |
3438 "Autofill.FormEvents.Address", | 3625 "Autofill.FormEvents.Address", |
3439 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); | 3626 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); |
| 3627 |
| 3628 VerifySubmitFormUkm(form, ukm_service, |
| 3629 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); |
3440 } | 3630 } |
3441 | 3631 |
3442 // Reset the autofill manager state. | 3632 // Reset the autofill manager state and purge UKM logs. |
3443 autofill_manager_->Reset(); | 3633 autofill_manager_->Reset(); |
| 3634 ukm_service->Purge(); |
| 3635 |
3444 autofill_manager_->AddSeenForm(form, field_types, field_types); | 3636 autofill_manager_->AddSeenForm(form, field_types, field_types); |
3445 | 3637 |
3446 { | 3638 { |
3447 // Simulating submission with suggestion shown. | 3639 // Simulating submission with suggestion shown. |
3448 base::HistogramTester histogram_tester; | 3640 base::HistogramTester histogram_tester; |
3449 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); | 3641 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); |
3450 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 3642 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
3451 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 3643 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
3452 histogram_tester.ExpectBucketCount( | 3644 histogram_tester.ExpectBucketCount( |
3453 "Autofill.FormEvents.Address", | 3645 "Autofill.FormEvents.Address", |
(...skipping 27 matching lines...) Expand all Loading... |
3481 // Reset the autofill manager state. | 3673 // Reset the autofill manager state. |
3482 autofill_manager_->Reset(); | 3674 autofill_manager_->Reset(); |
3483 autofill_manager_->AddSeenForm(form, field_types, field_types); | 3675 autofill_manager_->AddSeenForm(form, field_types, field_types); |
3484 | 3676 |
3485 { | 3677 { |
3486 // Simulating multiple submissions. | 3678 // Simulating multiple submissions. |
3487 base::HistogramTester histogram_tester; | 3679 base::HistogramTester histogram_tester; |
3488 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 3680 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
3489 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 3681 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
3490 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 3682 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
| 3683 |
3491 histogram_tester.ExpectBucketCount( | 3684 histogram_tester.ExpectBucketCount( |
3492 "Autofill.FormEvents.Address", | 3685 "Autofill.FormEvents.Address", |
3493 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); | 3686 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); |
3494 histogram_tester.ExpectBucketCount( | 3687 histogram_tester.ExpectBucketCount( |
3495 "Autofill.FormEvents.Address", | 3688 "Autofill.FormEvents.Address", |
3496 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 0); | 3689 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 0); |
3497 histogram_tester.ExpectBucketCount( | 3690 histogram_tester.ExpectBucketCount( |
3498 "Autofill.FormEvents.Address", | 3691 "Autofill.FormEvents.Address", |
3499 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0); | 3692 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0); |
3500 histogram_tester.ExpectBucketCount( | 3693 histogram_tester.ExpectBucketCount( |
(...skipping 16 matching lines...) Expand all Loading... |
3517 // Reset the autofill manager state. | 3710 // Reset the autofill manager state. |
3518 autofill_manager_->Reset(); | 3711 autofill_manager_->Reset(); |
3519 autofill_manager_->AddSeenForm(form, field_types, field_types); | 3712 autofill_manager_->AddSeenForm(form, field_types, field_types); |
3520 | 3713 |
3521 { | 3714 { |
3522 // Simulating submission with suggestion show but without previous | 3715 // Simulating submission with suggestion show but without previous |
3523 // interaction. | 3716 // interaction. |
3524 base::HistogramTester histogram_tester; | 3717 base::HistogramTester histogram_tester; |
3525 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); | 3718 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); |
3526 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 3719 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
| 3720 |
3527 histogram_tester.ExpectBucketCount( | 3721 histogram_tester.ExpectBucketCount( |
3528 "Autofill.FormEvents.Address", | 3722 "Autofill.FormEvents.Address", |
3529 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 0); | 3723 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 0); |
3530 histogram_tester.ExpectBucketCount( | 3724 histogram_tester.ExpectBucketCount( |
3531 "Autofill.FormEvents.Address", | 3725 "Autofill.FormEvents.Address", |
3532 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 0); | 3726 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 0); |
3533 histogram_tester.ExpectBucketCount( | 3727 histogram_tester.ExpectBucketCount( |
3534 "Autofill.FormEvents.Address", | 3728 "Autofill.FormEvents.Address", |
3535 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0); | 3729 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0); |
3536 histogram_tester.ExpectBucketCount( | 3730 histogram_tester.ExpectBucketCount( |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3887 { | 4081 { |
3888 // Simulate activating the autofill popup for the street field. | 4082 // Simulate activating the autofill popup for the street field. |
3889 base::HistogramTester histogram_tester; | 4083 base::HistogramTester histogram_tester; |
3890 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 4084 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
3891 histogram_tester.ExpectUniqueSample( | 4085 histogram_tester.ExpectUniqueSample( |
3892 "Autofill.FormEvents.Address.WithOnlyLocalData", | 4086 "Autofill.FormEvents.Address.WithOnlyLocalData", |
3893 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE, 1); | 4087 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE, 1); |
3894 } | 4088 } |
3895 } | 4089 } |
3896 | 4090 |
3897 | |
3898 // Test that we log that Autofill is enabled when filling a form. | 4091 // Test that we log that Autofill is enabled when filling a form. |
3899 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtPageLoad) { | 4092 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtPageLoad) { |
3900 base::HistogramTester histogram_tester; | 4093 base::HistogramTester histogram_tester; |
3901 autofill_manager_->set_autofill_enabled(true); | 4094 autofill_manager_->set_autofill_enabled(true); |
3902 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks()); | 4095 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks()); |
3903 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.PageLoad", true, 1); | 4096 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.PageLoad", true, 1); |
3904 } | 4097 } |
3905 | 4098 |
3906 // Test that we log that Autofill is disabled when filling a form. | 4099 // Test that we log that Autofill is disabled when filling a form. |
3907 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtPageLoad) { | 4100 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtPageLoad) { |
(...skipping 18 matching lines...) Expand all Loading... |
3926 base::HistogramTester histogram_tester; | 4119 base::HistogramTester histogram_tester; |
3927 AutofillProfile profile; | 4120 AutofillProfile profile; |
3928 profile.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(13)); | 4121 profile.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(13)); |
3929 profile.RecordAndLogUse(); | 4122 profile.RecordAndLogUse(); |
3930 histogram_tester.ExpectBucketCount("Autofill.DaysSinceLastUse.Profile", 13, | 4123 histogram_tester.ExpectBucketCount("Autofill.DaysSinceLastUse.Profile", 13, |
3931 1); | 4124 1); |
3932 } | 4125 } |
3933 | 4126 |
3934 // Verify that we correctly log the submitted form's state. | 4127 // Verify that we correctly log the submitted form's state. |
3935 TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) { | 4128 TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) { |
| 4129 EnableUkmLogging(); |
| 4130 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
| 4131 |
3936 // Start with a form with insufficiently many fields. | 4132 // Start with a form with insufficiently many fields. |
3937 FormData form; | 4133 FormData form; |
3938 form.name = ASCIIToUTF16("TestForm"); | 4134 form.name = ASCIIToUTF16("TestForm"); |
3939 form.origin = GURL("http://example.com/form.html"); | 4135 form.origin = GURL("http://example.com/form.html"); |
3940 form.action = GURL("http://example.com/submit.html"); | 4136 form.action = GURL("http://example.com/submit.html"); |
3941 | 4137 |
3942 FormFieldData field; | 4138 FormFieldData field; |
3943 test::CreateTestFormField("Name", "name", "", "text", &field); | 4139 test::CreateTestFormField("Name", "name", "", "text", &field); |
3944 form.fields.push_back(field); | 4140 form.fields.push_back(field); |
3945 test::CreateTestFormField("Email", "email", "", "text", &field); | 4141 test::CreateTestFormField("Email", "email", "", "text", &field); |
3946 form.fields.push_back(field); | 4142 form.fields.push_back(field); |
3947 test::CreateTestFormField("Phone", "phone", "", "text", &field); | 4143 test::CreateTestFormField("Phone", "phone", "", "text", &field); |
3948 form.fields.push_back(field); | 4144 form.fields.push_back(field); |
3949 test::CreateTestFormField("Unknown", "unknown", "", "text", &field); | 4145 test::CreateTestFormField("Unknown", "unknown", "", "text", &field); |
3950 form.fields.push_back(field); | 4146 form.fields.push_back(field); |
3951 std::vector<FormData> forms(1, form); | 4147 std::vector<FormData> forms(1, form); |
3952 | 4148 |
3953 // Expect no notifications when the form is first seen. | 4149 // Expect no notifications when the form is first seen. |
3954 { | 4150 { |
3955 base::HistogramTester histogram_tester; | 4151 base::HistogramTester histogram_tester; |
3956 autofill_manager_->OnFormsSeen(forms, TimeTicks()); | 4152 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now()); |
3957 histogram_tester.ExpectTotalCount("Autofill.FormSubmittedState", 0); | 4153 histogram_tester.ExpectTotalCount("Autofill.FormSubmittedState", 0); |
3958 } | 4154 } |
3959 | 4155 |
| 4156 std::vector<std::vector<std::pair<const char*, int64_t>>> |
| 4157 expected_form_submission_ukm_metrics = { |
| 4158 {{internal::kUKMAutofillFormSubmittedStateMetricName, |
| 4159 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, |
| 4160 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}}; |
| 4161 |
3960 // No data entered in the form. | 4162 // No data entered in the form. |
3961 { | 4163 { |
3962 base::HistogramTester histogram_tester; | 4164 base::HistogramTester histogram_tester; |
3963 base::UserActionTester user_action_tester; | 4165 base::UserActionTester user_action_tester; |
3964 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 4166 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
3965 histogram_tester.ExpectUniqueSample( | 4167 histogram_tester.ExpectUniqueSample( |
3966 "Autofill.FormSubmittedState", | 4168 "Autofill.FormSubmittedState", |
3967 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); | 4169 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); |
3968 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4170 EXPECT_EQ(1, user_action_tester.GetActionCount( |
3969 "Autofill_FormSubmitted_NonFillable")); | 4171 "Autofill_FormSubmitted_NonFillable")); |
| 4172 |
| 4173 // Expect an entry for |DeveloperEngagement| and an entry for form |
| 4174 // interactions. Both entries are for the same URL. |
| 4175 ASSERT_EQ(2U, ukm_service->entries_count()); |
| 4176 ASSERT_EQ(2U, ukm_service->sources_count()); |
| 4177 VerifyDeveloperEngagementUkm( |
| 4178 form, ukm_service, |
| 4179 {AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS}); |
| 4180 VerifyFormInteractionUkm(form, ukm_service, |
| 4181 internal::kUKMFormSubmittedEntryName, |
| 4182 expected_form_submission_ukm_metrics); |
3970 } | 4183 } |
3971 | 4184 |
3972 // Non fillable form. | 4185 // Non fillable form. |
3973 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley"); | 4186 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley"); |
3974 form.fields[1].value = ASCIIToUTF16("theking@gmail.com"); | 4187 form.fields[1].value = ASCIIToUTF16("theking@gmail.com"); |
3975 forms.front() = form; | 4188 forms.front() = form; |
3976 | 4189 |
3977 { | 4190 { |
3978 base::HistogramTester histogram_tester; | 4191 base::HistogramTester histogram_tester; |
3979 base::UserActionTester user_action_tester; | 4192 base::UserActionTester user_action_tester; |
3980 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 4193 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
3981 histogram_tester.ExpectUniqueSample( | 4194 histogram_tester.ExpectUniqueSample( |
3982 "Autofill.FormSubmittedState", | 4195 "Autofill.FormSubmittedState", |
3983 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); | 4196 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); |
3984 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4197 EXPECT_EQ(1, user_action_tester.GetActionCount( |
3985 "Autofill_FormSubmitted_NonFillable")); | 4198 "Autofill_FormSubmitted_NonFillable")); |
| 4199 |
| 4200 expected_form_submission_ukm_metrics.push_back( |
| 4201 {{internal::kUKMAutofillFormSubmittedStateMetricName, |
| 4202 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, |
| 4203 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}); |
| 4204 VerifyFormInteractionUkm(form, ukm_service, |
| 4205 internal::kUKMFormSubmittedEntryName, |
| 4206 expected_form_submission_ukm_metrics); |
3986 } | 4207 } |
3987 | 4208 |
3988 // Fill in the third field. | 4209 // Fill in the third field. |
3989 form.fields[2].value = ASCIIToUTF16("12345678901"); | 4210 form.fields[2].value = ASCIIToUTF16("12345678901"); |
3990 forms.front() = form; | 4211 forms.front() = form; |
3991 | 4212 |
3992 // Autofilled none with no suggestions shown. | 4213 // Autofilled none with no suggestions shown. |
3993 { | 4214 { |
3994 base::HistogramTester histogram_tester; | 4215 base::HistogramTester histogram_tester; |
3995 base::UserActionTester user_action_tester; | 4216 base::UserActionTester user_action_tester; |
3996 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 4217 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
3997 histogram_tester.ExpectUniqueSample( | 4218 histogram_tester.ExpectUniqueSample( |
3998 "Autofill.FormSubmittedState", | 4219 "Autofill.FormSubmittedState", |
3999 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS, | 4220 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS, |
4000 1); | 4221 1); |
4001 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4222 EXPECT_EQ(1, user_action_tester.GetActionCount( |
4002 "Autofill_FormSubmitted_FilledNone_SuggestionsNotShown")); | 4223 "Autofill_FormSubmitted_FilledNone_SuggestionsNotShown")); |
| 4224 |
| 4225 expected_form_submission_ukm_metrics.push_back( |
| 4226 {{internal::kUKMAutofillFormSubmittedStateMetricName, |
| 4227 AutofillMetrics:: |
| 4228 FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS}, |
| 4229 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}); |
| 4230 VerifyFormInteractionUkm(form, ukm_service, |
| 4231 internal::kUKMFormSubmittedEntryName, |
| 4232 expected_form_submission_ukm_metrics); |
4003 } | 4233 } |
4004 | 4234 |
4005 // Autofilled none with suggestions shown. | 4235 // Autofilled none with suggestions shown. |
4006 autofill_manager_->DidShowSuggestions(true, form, form.fields[2]); | 4236 autofill_manager_->DidShowSuggestions(true, form, form.fields[2]); |
4007 { | 4237 { |
4008 base::HistogramTester histogram_tester; | 4238 base::HistogramTester histogram_tester; |
4009 base::UserActionTester user_action_tester; | 4239 base::UserActionTester user_action_tester; |
4010 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 4240 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
4011 histogram_tester.ExpectUniqueSample( | 4241 histogram_tester.ExpectUniqueSample( |
4012 "Autofill.FormSubmittedState", | 4242 "Autofill.FormSubmittedState", |
4013 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS, 1); | 4243 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS, 1); |
4014 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4244 EXPECT_EQ(1, user_action_tester.GetActionCount( |
4015 "Autofill_FormSubmitted_FilledNone_SuggestionsShown")); | 4245 "Autofill_FormSubmitted_FilledNone_SuggestionsShown")); |
| 4246 |
| 4247 VerifyFormInteractionUkm( |
| 4248 form, ukm_service, internal::kUKMSuggestionsShownEntryName, |
| 4249 {{{internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}}); |
| 4250 expected_form_submission_ukm_metrics.push_back( |
| 4251 {{internal::kUKMAutofillFormSubmittedStateMetricName, |
| 4252 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS}, |
| 4253 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}); |
| 4254 VerifyFormInteractionUkm(form, ukm_service, |
| 4255 internal::kUKMFormSubmittedEntryName, |
| 4256 expected_form_submission_ukm_metrics); |
4016 } | 4257 } |
4017 | 4258 |
4018 // Mark one of the fields as autofilled. | 4259 // Mark one of the fields as autofilled. |
4019 form.fields[1].is_autofilled = true; | 4260 form.fields[1].is_autofilled = true; |
4020 forms.front() = form; | 4261 forms.front() = form; |
4021 | 4262 |
4022 // Autofilled some of the fields. | 4263 // Autofilled some of the fields. |
4023 { | 4264 { |
4024 base::HistogramTester histogram_tester; | 4265 base::HistogramTester histogram_tester; |
4025 base::UserActionTester user_action_tester; | 4266 base::UserActionTester user_action_tester; |
4026 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 4267 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
4027 histogram_tester.ExpectUniqueSample( | 4268 histogram_tester.ExpectUniqueSample( |
4028 "Autofill.FormSubmittedState", | 4269 "Autofill.FormSubmittedState", |
4029 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME, 1); | 4270 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME, 1); |
4030 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4271 EXPECT_EQ(1, user_action_tester.GetActionCount( |
4031 "Autofill_FormSubmitted_FilledSome")); | 4272 "Autofill_FormSubmitted_FilledSome")); |
| 4273 |
| 4274 expected_form_submission_ukm_metrics.push_back( |
| 4275 {{internal::kUKMAutofillFormSubmittedStateMetricName, |
| 4276 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME}, |
| 4277 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}); |
| 4278 VerifyFormInteractionUkm(form, ukm_service, |
| 4279 internal::kUKMFormSubmittedEntryName, |
| 4280 expected_form_submission_ukm_metrics); |
4032 } | 4281 } |
4033 | 4282 |
4034 // Mark all of the fillable fields as autofilled. | 4283 // Mark all of the fillable fields as autofilled. |
4035 form.fields[0].is_autofilled = true; | 4284 form.fields[0].is_autofilled = true; |
4036 form.fields[2].is_autofilled = true; | 4285 form.fields[2].is_autofilled = true; |
4037 forms.front() = form; | 4286 forms.front() = form; |
4038 | 4287 |
4039 // Autofilled all the fields. | 4288 // Autofilled all the fields. |
4040 { | 4289 { |
4041 base::HistogramTester histogram_tester; | 4290 base::HistogramTester histogram_tester; |
4042 base::UserActionTester user_action_tester; | 4291 base::UserActionTester user_action_tester; |
4043 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 4292 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
4044 histogram_tester.ExpectUniqueSample( | 4293 histogram_tester.ExpectUniqueSample( |
4045 "Autofill.FormSubmittedState", | 4294 "Autofill.FormSubmittedState", |
4046 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL, 1); | 4295 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL, 1); |
4047 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4296 EXPECT_EQ(1, user_action_tester.GetActionCount( |
4048 "Autofill_FormSubmitted_FilledAll")); | 4297 "Autofill_FormSubmitted_FilledAll")); |
| 4298 |
| 4299 expected_form_submission_ukm_metrics.push_back( |
| 4300 {{internal::kUKMAutofillFormSubmittedStateMetricName, |
| 4301 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL}, |
| 4302 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}); |
| 4303 VerifyFormInteractionUkm(form, ukm_service, |
| 4304 internal::kUKMFormSubmittedEntryName, |
| 4305 expected_form_submission_ukm_metrics); |
4049 } | 4306 } |
4050 | 4307 |
4051 // Clear out the third field's value. | 4308 // Clear out the third field's value. |
4052 form.fields[2].value = base::string16(); | 4309 form.fields[2].value = base::string16(); |
4053 forms.front() = form; | 4310 forms.front() = form; |
4054 | 4311 |
4055 // Non fillable form. | 4312 // Non fillable form. |
4056 { | 4313 { |
4057 base::HistogramTester histogram_tester; | 4314 base::HistogramTester histogram_tester; |
4058 base::UserActionTester user_action_tester; | 4315 base::UserActionTester user_action_tester; |
4059 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 4316 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
4060 histogram_tester.ExpectUniqueSample( | 4317 histogram_tester.ExpectUniqueSample( |
4061 "Autofill.FormSubmittedState", | 4318 "Autofill.FormSubmittedState", |
4062 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); | 4319 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); |
4063 EXPECT_EQ(1, user_action_tester.GetActionCount( | 4320 EXPECT_EQ(1, user_action_tester.GetActionCount( |
4064 "Autofill_FormSubmitted_NonFillable")); | 4321 "Autofill_FormSubmitted_NonFillable")); |
| 4322 |
| 4323 expected_form_submission_ukm_metrics.push_back( |
| 4324 {{internal::kUKMAutofillFormSubmittedStateMetricName, |
| 4325 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}, |
| 4326 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}); |
| 4327 VerifyFormInteractionUkm(form, ukm_service, |
| 4328 internal::kUKMFormSubmittedEntryName, |
| 4329 expected_form_submission_ukm_metrics); |
4065 } | 4330 } |
4066 } | 4331 } |
4067 | 4332 |
4068 // Verify that we correctly log user happiness metrics dealing with form | 4333 // Verify that we correctly log user happiness metrics dealing with form |
4069 // interaction. | 4334 // interaction. |
4070 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) { | 4335 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) { |
| 4336 EnableUkmLogging(); |
| 4337 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
| 4338 |
4071 // Load a fillable form. | 4339 // Load a fillable form. |
4072 FormData form; | 4340 FormData form; |
4073 form.name = ASCIIToUTF16("TestForm"); | 4341 form.name = ASCIIToUTF16("TestForm"); |
4074 form.origin = GURL("http://example.com/form.html"); | 4342 form.origin = GURL("http://example.com/form.html"); |
4075 form.action = GURL("http://example.com/submit.html"); | 4343 form.action = GURL("http://example.com/submit.html"); |
4076 | 4344 |
4077 FormFieldData field; | 4345 FormFieldData field; |
4078 test::CreateTestFormField("Name", "name", "", "text", &field); | 4346 test::CreateTestFormField("Name", "name", "", "text", &field); |
4079 form.fields.push_back(field); | 4347 form.fields.push_back(field); |
4080 test::CreateTestFormField("Email", "email", "", "text", &field); | 4348 test::CreateTestFormField("Email", "email", "", "text", &field); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4160 } | 4428 } |
4161 | 4429 |
4162 // Simulate editing another autofilled field. | 4430 // Simulate editing another autofilled field. |
4163 { | 4431 { |
4164 base::HistogramTester histogram_tester; | 4432 base::HistogramTester histogram_tester; |
4165 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks()); | 4433 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks()); |
4166 histogram_tester.ExpectUniqueSample( | 4434 histogram_tester.ExpectUniqueSample( |
4167 "Autofill.UserHappiness", | 4435 "Autofill.UserHappiness", |
4168 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD, 1); | 4436 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD, 1); |
4169 } | 4437 } |
| 4438 |
| 4439 autofill_manager_->Reset(); |
| 4440 |
| 4441 VerifyFormInteractionUkm( |
| 4442 form, ukm_service, internal::kUKMInteractedWithFormEntryName, |
| 4443 {{{internal::kUKMIsForCreditCardMetricName, false}, |
| 4444 {internal::kUKMLocalRecordTypeCountMetricName, 0}, |
| 4445 {internal::kUKMServerRecordTypeCountMetricName, 0}}}); |
| 4446 VerifyFormInteractionUkm( |
| 4447 form, ukm_service, internal::kUKMSuggestionsShownEntryName, |
| 4448 {{{internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}, |
| 4449 {{internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}}); |
| 4450 VerifyFormInteractionUkm( |
| 4451 form, ukm_service, internal::kUKMSuggestionFilledEntryName, |
| 4452 {{{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE}, |
| 4453 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}, |
| 4454 {{internal::kUKMRecordTypeMetricName, AutofillProfile::LOCAL_PROFILE}, |
| 4455 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}}); |
| 4456 VerifyFormInteractionUkm( |
| 4457 form, ukm_service, internal::kUKMTextFieldDidChangeEntryName, |
| 4458 {{{internal::kUKMFieldTypeGroupMetricName, NAME}, |
| 4459 {internal::kUKMHeuristicTypeMetricName, NAME_FULL}, |
| 4460 {internal::kUKMServerTypeMetricName, NO_SERVER_DATA}, |
| 4461 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}, |
| 4462 {internal::kUKMHtmlFieldModeMetricName, HTML_MODE_NONE}, |
| 4463 {internal::kUKMIsAutofilledMetricName, false}, |
| 4464 {internal::kUKMIsEmptyMetricName, true}, |
| 4465 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}, |
| 4466 {{internal::kUKMFieldTypeGroupMetricName, NAME}, |
| 4467 {internal::kUKMHeuristicTypeMetricName, NAME_FULL}, |
| 4468 {internal::kUKMServerTypeMetricName, NO_SERVER_DATA}, |
| 4469 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}, |
| 4470 {internal::kUKMHtmlFieldModeMetricName, HTML_MODE_NONE}, |
| 4471 {internal::kUKMIsAutofilledMetricName, true}, |
| 4472 {internal::kUKMIsEmptyMetricName, true}, |
| 4473 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}, |
| 4474 {{internal::kUKMFieldTypeGroupMetricName, EMAIL}, |
| 4475 {internal::kUKMHeuristicTypeMetricName, EMAIL_ADDRESS}, |
| 4476 {internal::kUKMServerTypeMetricName, NO_SERVER_DATA}, |
| 4477 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}, |
| 4478 {internal::kUKMHtmlFieldModeMetricName, HTML_MODE_NONE}, |
| 4479 {internal::kUKMIsAutofilledMetricName, true}, |
| 4480 {internal::kUKMIsEmptyMetricName, true}, |
| 4481 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}}); |
4170 } | 4482 } |
4171 | 4483 |
4172 // Verify that we correctly log metrics tracking the duration of form fill. | 4484 // Verify that we correctly log metrics tracking the duration of form fill. |
4173 TEST_F(AutofillMetricsTest, FormFillDuration) { | 4485 TEST_F(AutofillMetricsTest, FormFillDuration) { |
4174 // Load a fillable form. | 4486 // Load a fillable form. |
4175 FormData form; | 4487 FormData form; |
4176 form.name = ASCIIToUTF16("TestForm"); | 4488 form.name = ASCIIToUTF16("TestForm"); |
4177 form.origin = GURL("http://example.com/form.html"); | 4489 form.origin = GURL("http://example.com/form.html"); |
4178 form.action = GURL("http://example.com/submit.html"); | 4490 form.action = GURL("http://example.com/submit.html"); |
4179 | 4491 |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4737 ["Autofill.FormEvents.CreditCard.OnNonsecurePage"]); | 5049 ["Autofill.FormEvents.CreditCard.OnNonsecurePage"]); |
4738 } | 5050 } |
4739 } | 5051 } |
4740 | 5052 |
4741 // Tests that logging CardUploadDecision UKM works as expected. | 5053 // Tests that logging CardUploadDecision UKM works as expected. |
4742 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric) { | 5054 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric) { |
4743 EnableUkmLogging(); | 5055 EnableUkmLogging(); |
4744 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 5056 ukm::UkmServiceTestingHarness ukm_service_test_harness; |
4745 GURL url("https://www.google.com"); | 5057 GURL url("https://www.google.com"); |
4746 int upload_decision = 1; | 5058 int upload_decision = 1; |
4747 std::map<std::string, int> metrics = { | 5059 std::vector<std::pair<const char*, int>> metrics = { |
4748 {internal::kUKMCardUploadDecisionMetricName, upload_decision}}; | 5060 {internal::kUKMCardUploadDecisionMetricName, upload_decision}}; |
4749 | 5061 |
4750 EXPECT_TRUE(AutofillMetrics::LogUkm( | 5062 EXPECT_TRUE(AutofillMetrics::LogUkm( |
4751 ukm_service_test_harness.test_ukm_service(), url, | 5063 ukm_service_test_harness.test_ukm_service(), url, |
4752 internal::kUKMCardUploadDecisionEntryName, metrics)); | 5064 internal::kUKMCardUploadDecisionEntryName, metrics)); |
4753 | 5065 |
4754 // Make sure that the UKM was logged correctly. | 5066 // Make sure that the UKM was logged correctly. |
4755 ukm::TestUkmService* ukm_service = | 5067 ukm::TestUkmService* ukm_service = |
4756 ukm_service_test_harness.test_ukm_service(); | 5068 ukm_service_test_harness.test_ukm_service(); |
4757 | 5069 |
(...skipping 20 matching lines...) Expand all Loading... |
4778 ASSERT_NE(nullptr, metric); | 5090 ASSERT_NE(nullptr, metric); |
4779 EXPECT_EQ(upload_decision, metric->value()); | 5091 EXPECT_EQ(upload_decision, metric->value()); |
4780 } | 5092 } |
4781 | 5093 |
4782 // Tests that logging DeveloperEngagement UKM works as expected. | 5094 // Tests that logging DeveloperEngagement UKM works as expected. |
4783 TEST_F(AutofillMetricsTest, RecordDeveloperEngagementMetric) { | 5095 TEST_F(AutofillMetricsTest, RecordDeveloperEngagementMetric) { |
4784 EnableUkmLogging(); | 5096 EnableUkmLogging(); |
4785 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 5097 ukm::UkmServiceTestingHarness ukm_service_test_harness; |
4786 GURL url("https://www.google.com"); | 5098 GURL url("https://www.google.com"); |
4787 int form_structure_metric = 1; | 5099 int form_structure_metric = 1; |
4788 std::map<std::string, int> metrics = { | 5100 std::vector<std::pair<const char*, int>> metrics = { |
4789 {internal::kUKMDeveloperEngagementMetricName, form_structure_metric}}; | 5101 {internal::kUKMDeveloperEngagementMetricName, form_structure_metric}}; |
4790 | 5102 |
4791 EXPECT_TRUE(AutofillMetrics::LogUkm( | 5103 EXPECT_TRUE(AutofillMetrics::LogUkm( |
4792 ukm_service_test_harness.test_ukm_service(), url, | 5104 ukm_service_test_harness.test_ukm_service(), url, |
4793 internal::kUKMDeveloperEngagementEntryName, metrics)); | 5105 internal::kUKMDeveloperEngagementEntryName, metrics)); |
4794 | 5106 |
4795 // Make sure that the UKM was logged correctly. | 5107 // Make sure that the UKM was logged correctly. |
4796 ukm::TestUkmService* ukm_service = | 5108 ukm::TestUkmService* ukm_service = |
4797 ukm_service_test_harness.test_ukm_service(); | 5109 ukm_service_test_harness.test_ukm_service(); |
4798 | 5110 |
(...skipping 19 matching lines...) Expand all Loading... |
4818 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics()); | 5130 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics()); |
4819 ASSERT_NE(nullptr, metric); | 5131 ASSERT_NE(nullptr, metric); |
4820 EXPECT_EQ(form_structure_metric, metric->value()); | 5132 EXPECT_EQ(form_structure_metric, metric->value()); |
4821 } | 5133 } |
4822 | 5134 |
4823 // Tests that no UKM is logged when the URL is not valid. | 5135 // Tests that no UKM is logged when the URL is not valid. |
4824 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_InvalidUrl) { | 5136 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_InvalidUrl) { |
4825 EnableUkmLogging(); | 5137 EnableUkmLogging(); |
4826 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 5138 ukm::UkmServiceTestingHarness ukm_service_test_harness; |
4827 GURL url(""); | 5139 GURL url(""); |
4828 std::map<std::string, int> metrics = {{"metric", 1}}; | 5140 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; |
4829 | 5141 |
4830 EXPECT_FALSE(AutofillMetrics::LogUkm( | 5142 EXPECT_FALSE(AutofillMetrics::LogUkm( |
4831 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); | 5143 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); |
4832 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); | 5144 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); |
4833 } | 5145 } |
4834 | 5146 |
4835 // Tests that no UKM is logged when the metrics map is empty. | 5147 // Tests that no UKM is logged when the metrics map is empty. |
4836 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoMetrics) { | 5148 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoMetrics) { |
4837 EnableUkmLogging(); | 5149 EnableUkmLogging(); |
4838 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 5150 ukm::UkmServiceTestingHarness ukm_service_test_harness; |
4839 GURL url("https://www.google.com"); | 5151 GURL url("https://www.google.com"); |
4840 std::map<std::string, int> metrics; | 5152 std::vector<std::pair<const char*, int>> metrics; |
4841 | 5153 |
4842 EXPECT_FALSE(AutofillMetrics::LogUkm( | 5154 EXPECT_FALSE(AutofillMetrics::LogUkm( |
4843 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); | 5155 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); |
4844 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); | 5156 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); |
4845 } | 5157 } |
4846 | 5158 |
4847 // Tests that no UKM is logged when the ukm service is null. | 5159 // Tests that no UKM is logged when the ukm service is null. |
4848 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmService) { | 5160 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmService) { |
4849 EnableUkmLogging(); | 5161 EnableUkmLogging(); |
4850 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 5162 ukm::UkmServiceTestingHarness ukm_service_test_harness; |
4851 GURL url("https://www.google.com"); | 5163 GURL url("https://www.google.com"); |
4852 std::map<std::string, int> metrics = {{"metric", 1}}; | 5164 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; |
4853 | 5165 |
4854 EXPECT_FALSE(AutofillMetrics::LogUkm(nullptr, url, "test_ukm", metrics)); | 5166 EXPECT_FALSE(AutofillMetrics::LogUkm(nullptr, url, "test_ukm", metrics)); |
4855 ASSERT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); | 5167 ASSERT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); |
4856 } | 5168 } |
4857 | 5169 |
4858 // Tests that no UKM is logged when the ukm logging feature is disabled. | 5170 // Tests that no UKM is logged when the ukm logging feature is disabled. |
4859 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_FeatureDisabled) { | 5171 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_FeatureDisabled) { |
4860 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 5172 ukm::UkmServiceTestingHarness ukm_service_test_harness; |
4861 GURL url("https://www.google.com"); | 5173 GURL url("https://www.google.com"); |
4862 std::map<std::string, int> metrics = {{"metric", 1}}; | 5174 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; |
4863 | 5175 |
4864 EXPECT_FALSE(AutofillMetrics::LogUkm( | 5176 EXPECT_FALSE(AutofillMetrics::LogUkm( |
4865 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); | 5177 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); |
4866 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); | 5178 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); |
4867 } | 5179 } |
4868 | 5180 |
4869 } // namespace autofill | 5181 } // namespace autofill |
OLD | NEW |