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

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

Issue 2800853004: UKM that threads together multiple form interaction events. (Closed)
Patch Set: Logs each form interaction event in a separate UkmEntry, includes time_delta as a metric. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/core/browser/autofill_metrics.h" 5 #include "components/autofill/core/browser/autofill_metrics.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility>
10 #include <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
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::Pointwise;
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
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()->set_url(form.origin);
271 form_interactions_ukm_logger()->set_form_loaded_timestamp(TimeTicks::Now());
267 } 272 }
268 273
269 // Calls AutofillManager::OnWillSubmitForm and waits for it to complete. 274 // Calls AutofillManager::OnWillSubmitForm and waits for it to complete.
270 void WillSubmitForm(const FormData& form, const TimeTicks& timestamp) { 275 void WillSubmitForm(const FormData& form, const TimeTicks& timestamp) {
271 ResetRunLoop(); 276 ResetRunLoop();
272 if (!OnWillSubmitForm(form, timestamp)) 277 if (!OnWillSubmitForm(form, timestamp))
273 return; 278 return;
274 279
275 // Wait for the asynchronous OnWillSubmitForm() call to complete. 280 // Wait for the asynchronous OnWillSubmitForm() call to complete.
276 RunRunLoop(); 281 RunRunLoop();
277 } 282 }
278 283
279 // Calls both AutofillManager::OnWillSubmitForm and 284 // Calls both AutofillManager::OnWillSubmitForm and
280 // AutofillManager::OnFormSubmitted. 285 // AutofillManager::OnFormSubmitted.
281 void SubmitForm(const FormData& form, const TimeTicks& timestamp) { 286 void SubmitForm(const FormData& form, const TimeTicks& timestamp) {
282 WillSubmitForm(form, timestamp); 287 WillSubmitForm(form, timestamp);
283 OnFormSubmitted(form); 288 OnFormSubmitted(form);
284 } 289 }
285 290
286 // Control the run loop from within tests. 291 // Control the run loop from within tests.
287 void ResetRunLoop() { run_loop_.reset(new base::RunLoop()); } 292 void ResetRunLoop() { run_loop_.reset(new base::RunLoop()); }
288 void RunRunLoop() { run_loop_->Run(); } 293 void RunRunLoop() { run_loop_->Run(); }
289 294
290 void UploadFormDataAsyncCallback(const FormStructure* submitted_form, 295 void UploadFormDataAsyncCallback(const FormStructure* submitted_form,
291 const base::TimeTicks& load_time, 296 const TimeTicks& load_time,
292 const base::TimeTicks& interaction_time, 297 const TimeTicks& interaction_time,
293 const base::TimeTicks& submission_time, 298 const TimeTicks& submission_time,
294 bool observed_submission) override { 299 bool observed_submission) override {
295 run_loop_->Quit(); 300 run_loop_->Quit();
296 301
297 AutofillManager::UploadFormDataAsyncCallback( 302 AutofillManager::UploadFormDataAsyncCallback(
298 submitted_form, load_time, interaction_time, submission_time, 303 submitted_form, load_time, interaction_time, submission_time,
299 observed_submission); 304 observed_submission);
300 } 305 }
301 306
302 private: 307 private:
303 bool autofill_enabled_; 308 bool autofill_enabled_;
304 std::unique_ptr<base::RunLoop> run_loop_; 309 std::unique_ptr<base::RunLoop> run_loop_;
305 310
306 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); 311 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager);
307 }; 312 };
308 313
309 // Finds the specified UKM metric by |name| in the specified UKM |metrics|. 314 // Finds the specified UKM metric by |name| in the specified UKM |metrics|.
310 const ukm::Entry_Metric* FindMetric( 315 const ukm::Entry_Metric* FindMetric(
311 const char* name, 316 const char* name,
312 const google::protobuf::RepeatedPtrField<ukm::Entry_Metric>& metrics) { 317 const google::protobuf::RepeatedPtrField<ukm::Entry_Metric>& metrics) {
313 for (const auto& metric : metrics) { 318 for (const auto& metric : metrics) {
314 if (metric.metric_hash() == base::HashMetricName(name)) 319 if (metric.metric_hash() == base::HashMetricName(name))
315 return &metric; 320 return &metric;
316 } 321 }
317 return nullptr; 322 return nullptr;
318 } 323 }
319 324
325 MATCHER(CompareMetrics, "") {
326 const ukm::Entry_Metric& lhs = ::testing::get<0>(arg);
327 const std::pair<const char*, int64_t>& rhs = ::testing::get<1>(arg);
328 return lhs.metric_hash() == base::HashMetricName(rhs.first) &&
329 lhs.value() == rhs.second;
330 }
331
332 void VerifyDeveloperEngagementUkm(
333 const FormData& form,
334 const ukm::TestUkmService* ukm_service,
335 const std::vector<int64_t>& expected_metric_values) {
336 const ukm::UkmEntry* entry = ukm_service->GetEntryForEntryName(
337 internal::kUKMDeveloperEngagementEntryName);
338 ASSERT_NE(nullptr, entry);
339 ukm::Entry entry_proto;
340 entry->PopulateProto(&entry_proto);
341
342 const ukm::UkmSource* source =
343 ukm_service->GetSourceForSourceId(entry_proto.source_id());
344 ASSERT_NE(nullptr, source);
345 EXPECT_EQ(form.origin, source->url());
346
347 std::vector<std::pair<const char*, int64_t>> expected_metrics;
348 for (const auto it : expected_metric_values)
349 expected_metrics.push_back(
350 {internal::kUKMDeveloperEngagementMetricName, it});
351
352 EXPECT_THAT(entry_proto.metrics(),
353 Pointwise(CompareMetrics(), expected_metrics));
354 }
355
356 void VerifyFormInteractionsUkm(
357 const FormData& form,
358 const ukm::TestUkmService* ukm_service,
359 const std::vector<std::pair<const char*, int64_t>>& expected_events) {
360 int entry_num = 0;
361 // Skip |DeveloperEngagement| entries.
362 ASSERT_GT(ukm_service->entries_count(), static_cast<size_t>(0));
363 while (ukm_service->GetEntry(entry_num)->event_hash() ==
364 base::HashMetricName(internal::kUKMDeveloperEngagementEntryName))
365 entry_num++;
366
367 for (const auto& it : expected_events) {
368 const ukm::UkmEntry* entry = ukm_service->GetEntry(entry_num++);
369 ASSERT_NE(nullptr, entry);
370 ukm::Entry entry_proto;
371 entry->PopulateProto(&entry_proto);
372
373 const ukm::UkmSource* source =
374 ukm_service->GetSourceForSourceId(entry_proto.source_id());
375 ASSERT_NE(nullptr, source);
376 EXPECT_EQ(form.origin, source->url());
377
378 ASSERT_EQ(2, entry_proto.metrics().size());
379 EXPECT_EQ(base::HashMetricName(it.first),
380 entry_proto.metrics().Get(0).metric_hash());
381 EXPECT_EQ(it.second, entry_proto.metrics().Get(0).value());
382
383 EXPECT_EQ(base::HashMetricName(
384 internal::kUKMMillisecondsSinceFormLoadedMetricName),
385 entry_proto.metrics().Get(1).metric_hash());
386 }
387 }
388
389 void VerifyUniqueFormInteractionEventUkm(const FormData& form,
390 const ukm::TestUkmService* ukm_service,
391 const char* event_name,
392 int expected_metric_value) {
393 const ukm::UkmEntry* entry = ukm_service->GetEntryForEntryName(event_name);
394 ASSERT_NE(nullptr, entry);
395 ukm::Entry entry_proto;
396 entry->PopulateProto(&entry_proto);
397
398 const ukm::UkmSource* source =
399 ukm_service->GetSourceForSourceId(entry_proto.source_id());
400 ASSERT_NE(nullptr, source);
401 EXPECT_EQ(form.origin, source->url());
402
403 ASSERT_EQ(2, entry_proto.metrics().size());
404 EXPECT_EQ(base::HashMetricName(event_name),
405 entry_proto.metrics().Get(0).metric_hash());
406 EXPECT_EQ(expected_metric_value, entry_proto.metrics().Get(0).value());
407
408 EXPECT_EQ(
409 base::HashMetricName(internal::kUKMMillisecondsSinceFormLoadedMetricName),
410 entry_proto.metrics().Get(1).metric_hash());
411 }
412
320 } // namespace 413 } // namespace
321 414
322 // This is defined in the autofill_metrics.cc implementation file. 415 // This is defined in the autofill_metrics.cc implementation file.
323 int GetFieldTypeGroupMetric(ServerFieldType field_type, 416 int GetFieldTypeGroupMetric(ServerFieldType field_type,
324 AutofillMetrics::FieldTypeQualityMetric metric); 417 AutofillMetrics::FieldTypeQualityMetric metric);
325 418
326 class AutofillMetricsTest : public testing::Test { 419 class AutofillMetricsTest : public testing::Test {
327 public: 420 public:
328 ~AutofillMetricsTest() override; 421 ~AutofillMetricsTest() override;
329 422
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 // PersonalDataManager to be around when it gets destroyed. 480 // PersonalDataManager to be around when it gets destroyed.
388 autofill_manager_.reset(); 481 autofill_manager_.reset();
389 autofill_driver_.reset(); 482 autofill_driver_.reset();
390 personal_data_.reset(); 483 personal_data_.reset();
391 signin_manager_->Shutdown(); 484 signin_manager_->Shutdown();
392 signin_manager_.reset(); 485 signin_manager_.reset();
393 account_tracker_->Shutdown(); 486 account_tracker_->Shutdown();
394 account_tracker_.reset(); 487 account_tracker_.reset();
395 signin_client_.reset(); 488 signin_client_.reset();
396 test::ReenableSystemServices(); 489 test::ReenableSystemServices();
490 autofill_client_.GetTestUkmService()->Purge();
397 } 491 }
398 492
399 void AutofillMetricsTest::EnableWalletSync() { 493 void AutofillMetricsTest::EnableWalletSync() {
400 signin_manager_->SetAuthenticatedAccountInfo("12345", "syncuser@example.com"); 494 signin_manager_->SetAuthenticatedAccountInfo("12345", "syncuser@example.com");
401 } 495 }
402 496
403 void AutofillMetricsTest::EnableUkmLogging() { 497 void AutofillMetricsTest::EnableUkmLogging() {
404 scoped_feature_list_.InitAndEnableFeature(kAutofillUkmLogging); 498 scoped_feature_list_.InitAndEnableFeature(kAutofillUkmLogging);
405 } 499 }
406 500
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 field.is_autofilled = false; 658 field.is_autofilled = false;
565 form.fields.push_back(field); 659 form.fields.push_back(field);
566 660
567 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field); 661 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field);
568 field.is_autofilled = false; 662 field.is_autofilled = false;
569 form.fields.push_back(field); 663 form.fields.push_back(field);
570 664
571 // Simulate a OnFormsSeen() call that should trigger the recording. 665 // Simulate a OnFormsSeen() call that should trigger the recording.
572 std::vector<FormData> forms; 666 std::vector<FormData> forms;
573 forms.push_back(form); 667 forms.push_back(form);
574 autofill_manager_->OnFormsSeen(forms, base::TimeTicks::Now()); 668 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now());
575 669
576 // Because these metrics are related to timing, it is not possible to know in 670 // Because these metrics are related to timing, it is not possible to know in
577 // advance which bucket the sample will fall into, so we just need to make 671 // advance which bucket the sample will fall into, so we just need to make
578 // sure we have valid samples. 672 // sure we have valid samples.
579 EXPECT_FALSE( 673 EXPECT_FALSE(
580 histogram_tester.GetAllSamples("Autofill.Timing.DetermineHeuristicTypes") 674 histogram_tester.GetAllSamples("Autofill.Timing.DetermineHeuristicTypes")
581 .empty()); 675 .empty());
582 EXPECT_FALSE( 676 EXPECT_FALSE(
583 histogram_tester.GetAllSamples("Autofill.Timing.ParseForm").empty()); 677 histogram_tester.GetAllSamples("Autofill.Timing.ParseForm").empty());
584 } 678 }
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 autofill_manager_->OnTextFieldDidChange(form, form.fields[0], TimeTicks()); 1468 autofill_manager_->OnTextFieldDidChange(form, form.fields[0], TimeTicks());
1375 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks()); 1469 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks());
1376 1470
1377 // Simulate form submission. 1471 // Simulate form submission.
1378 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 1472 autofill_manager_->SubmitForm(form, TimeTicks::Now());
1379 1473
1380 // An autofillable form was submitted, and the number of edited autofilled 1474 // An autofillable form was submitted, and the number of edited autofilled
1381 // fields is logged. 1475 // fields is logged.
1382 histogram_tester.ExpectUniqueSample( 1476 histogram_tester.ExpectUniqueSample(
1383 "Autofill.NumberOfEditedAutofilledFieldsAtSubmission", 2, 1); 1477 "Autofill.NumberOfEditedAutofilledFieldsAtSubmission", 2, 1);
1478
1479 // UKM must not be logged unless enabled.
1480 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
1481 EXPECT_EQ(0U, ukm_service->sources_count());
1482 EXPECT_EQ(0U, ukm_service->entries_count());
1384 } 1483 }
1385 1484
1386 // Verify that when resetting the autofill manager (such as during a 1485 // Verify that when resetting the autofill manager (such as during a
1387 // navigation), the proper number of edited fields is logged. 1486 // navigation), the proper number of edited fields is logged.
1388 TEST_F(AutofillMetricsTest, NumberOfEditedAutofilledFields_NoSubmission) { 1487 TEST_F(AutofillMetricsTest, NumberOfEditedAutofilledFields_NoSubmission) {
1389 // Construct a fillable form. 1488 // Construct a fillable form.
1390 FormData form; 1489 FormData form;
1391 form.name = ASCIIToUTF16("TestForm"); 1490 form.name = ASCIIToUTF16("TestForm");
1392 form.origin = GURL("http://example.com/form.html"); 1491 form.origin = GURL("http://example.com/form.html");
1393 form.action = GURL("http://example.com/submit.html"); 1492 form.action = GURL("http://example.com/submit.html");
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 FormFieldData field; 1649 FormFieldData field;
1551 test::CreateTestFormField("Name", "name", "", "text", &field); 1650 test::CreateTestFormField("Name", "name", "", "text", &field);
1552 form.fields.push_back(field); 1651 form.fields.push_back(field);
1553 test::CreateTestFormField("Email", "email", "", "text", &field); 1652 test::CreateTestFormField("Email", "email", "", "text", &field);
1554 form.fields.push_back(field); 1653 form.fields.push_back(field);
1555 1654
1556 std::vector<FormData> forms(1, form); 1655 std::vector<FormData> forms(1, form);
1557 1656
1558 // Ensure no metrics are logged when loading a non-fillable form. 1657 // Ensure no metrics are logged when loading a non-fillable form.
1559 { 1658 {
1560 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 1659 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now());
1561 autofill_manager_->Reset(); 1660 autofill_manager_->Reset();
1562 1661
1563 EXPECT_EQ(0U, ukm_service->sources_count()); 1662 EXPECT_EQ(0U, ukm_service->sources_count());
1564 EXPECT_EQ(0U, ukm_service->entries_count()); 1663 EXPECT_EQ(0U, ukm_service->entries_count());
1565 } 1664 }
1566 1665
1567 // Add another field to the form, so that it becomes fillable. 1666 // Add another field to the form, so that it becomes fillable.
1568 test::CreateTestFormField("Phone", "phone", "", "text", &field); 1667 test::CreateTestFormField("Phone", "phone", "", "text", &field);
1569 forms.back().fields.push_back(field); 1668 forms.back().fields.push_back(field);
1570 1669
1571 // Expect the "form parsed without field type hints" metric to be logged. 1670 // Expect the "form parsed without field type hints" metric and the
1671 // "form loaded" form interaction event to be logged.
1572 { 1672 {
1573 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 1673 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now());
1574 autofill_manager_->Reset(); 1674 autofill_manager_->Reset();
1575 1675
1576 ASSERT_EQ(1U, ukm_service->sources_count()); 1676 // Expect an entry for |kUKMDeveloperEngagementEntryName| and another entry
1577 const ukm::UkmSource* source = 1677 // for |kUKMUserHappinessMetricName|. Both entries are for the same URL.
1578 ukm_service->GetSourceForUrl(form.origin.spec().c_str()); 1678 ASSERT_EQ(2U, ukm_service->entries_count());
1579 ASSERT_NE(nullptr, source); 1679 ASSERT_EQ(2U, ukm_service->sources_count());
1580 1680 VerifyDeveloperEngagementUkm(
1581 ASSERT_EQ(1U, ukm_service->entries_count()); 1681 form, ukm_service,
1582 const ukm::UkmEntry* entry = ukm_service->GetEntry(0); 1682 {AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS});
1583 EXPECT_EQ(source->id(), entry->source_id()); 1683 VerifyUniqueFormInteractionEventUkm(form, ukm_service,
1584 1684 internal::kUKMUserHappinessMetricName,
1585 ukm::Entry entry_proto; 1685 AutofillMetrics::FORMS_LOADED);
1586 entry->PopulateProto(&entry_proto);
1587 EXPECT_EQ(source->id(), entry_proto.source_id());
1588 EXPECT_EQ(base::HashMetricName(internal::kUKMDeveloperEngagementEntryName),
1589 entry_proto.event_hash());
1590 const ukm::Entry_Metric* metric = FindMetric(
1591 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics());
1592 ASSERT_NE(nullptr, metric);
1593 EXPECT_EQ(AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS,
1594 metric->value());
1595 } 1686 }
1596 } 1687 }
1597 1688
1598 // Verify that we correctly log UKM for form parsed with type hints regarding 1689 // Verify that we correctly log UKM for form parsed with type hints regarding
1599 // developer engagement. 1690 // developer engagement.
1600 TEST_F(AutofillMetricsTest, 1691 TEST_F(AutofillMetricsTest,
1601 UkmDeveloperEngagement_LogFillableFormParsedWithTypeHints) { 1692 UkmDeveloperEngagement_LogFillableFormParsedWithTypeHints) {
1602 EnableUkmLogging(); 1693 EnableUkmLogging();
1603 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 1694 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
1604 1695
(...skipping 22 matching lines...) Expand all
1627 test::CreateTestFormField("", "", "", "text", &field); 1718 test::CreateTestFormField("", "", "", "text", &field);
1628 field.autocomplete_attribute = "given-name"; 1719 field.autocomplete_attribute = "given-name";
1629 forms.back().fields.push_back(field); 1720 forms.back().fields.push_back(field);
1630 test::CreateTestFormField("", "", "", "text", &field); 1721 test::CreateTestFormField("", "", "", "text", &field);
1631 field.autocomplete_attribute = "email"; 1722 field.autocomplete_attribute = "email";
1632 forms.back().fields.push_back(field); 1723 forms.back().fields.push_back(field);
1633 test::CreateTestFormField("", "", "", "text", &field); 1724 test::CreateTestFormField("", "", "", "text", &field);
1634 field.autocomplete_attribute = "address-line1"; 1725 field.autocomplete_attribute = "address-line1";
1635 forms.back().fields.push_back(field); 1726 forms.back().fields.push_back(field);
1636 1727
1637 // Expect the "form parsed with field type hints" metric to be logged. 1728 // Expect the "form parsed without field type hints" metric and the
1729 // "form loaded" form interaction event to be logged.
1638 { 1730 {
1639 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 1731 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now());
1640 autofill_manager_->Reset(); 1732 autofill_manager_->Reset();
1641 1733
1642 ASSERT_EQ(1U, ukm_service->sources_count()); 1734 // Expect an entry for |kUKMDeveloperEngagementEntryName| and another entry
1643 const ukm::UkmSource* source = 1735 // for |kUKMUserHappinessMetricName|. Both entries are for the same URL.
1644 ukm_service->GetSourceForUrl(form.origin.spec().c_str()); 1736 ASSERT_EQ(2U, ukm_service->entries_count());
1645 ASSERT_NE(nullptr, source); 1737 ASSERT_EQ(2U, ukm_service->sources_count());
1646 1738 VerifyDeveloperEngagementUkm(
1647 ASSERT_EQ(1U, ukm_service->entries_count()); 1739 form, ukm_service,
1648 const ukm::UkmEntry* entry = ukm_service->GetEntry(0); 1740 {AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS});
1649 EXPECT_EQ(source->id(), entry->source_id()); 1741 VerifyUniqueFormInteractionEventUkm(form, ukm_service,
1650 1742 internal::kUKMUserHappinessMetricName,
1651 ukm::Entry entry_proto; 1743 AutofillMetrics::FORMS_LOADED);
1652 entry->PopulateProto(&entry_proto);
1653 EXPECT_EQ(source->id(), entry_proto.source_id());
1654 EXPECT_EQ(base::HashMetricName(internal::kUKMDeveloperEngagementEntryName),
1655 entry_proto.event_hash());
1656 const ukm::Entry_Metric* metric = FindMetric(
1657 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics());
1658 ASSERT_NE(nullptr, metric);
1659 EXPECT_EQ(AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS,
1660 metric->value());
1661 } 1744 }
1662 } 1745 }
1663 1746
1664 // Verify that we correctly log UKM for form parsed with type hints regarding 1747 // Verify that we correctly log UKM for form parsed with type hints regarding
1665 // developer engagement. 1748 // developer engagement.
1666 TEST_F(AutofillMetricsTest, UkmDeveloperEngagement_LogUpiVpaTypeHint) { 1749 TEST_F(AutofillMetricsTest, UkmDeveloperEngagement_LogUpiVpaTypeHint) {
1667 EnableUkmLogging(); 1750 EnableUkmLogging();
1668 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 1751 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
1669 1752
1670 FormData form; 1753 FormData form;
1671 form.name = ASCIIToUTF16("TestForm"); 1754 form.name = ASCIIToUTF16("TestForm");
1672 form.origin = GURL("http://example.com/form.html"); 1755 form.origin = GURL("http://example.com/form.html");
1673 form.action = GURL("http://example.com/submit.html"); 1756 form.action = GURL("http://example.com/submit.html");
1674 1757
1675 FormFieldData field; 1758 FormFieldData field;
1676 test::CreateTestFormField("Name", "name", "", "text", &field); 1759 test::CreateTestFormField("Name", "name", "", "text", &field);
1677 form.fields.push_back(field); 1760 form.fields.push_back(field);
1678 test::CreateTestFormField("Email", "email", "", "text", &field); 1761 test::CreateTestFormField("Email", "email", "", "text", &field);
1679 form.fields.push_back(field); 1762 form.fields.push_back(field);
1680 test::CreateTestFormField("Payment", "payment", "", "text", &field); 1763 test::CreateTestFormField("Payment", "payment", "", "text", &field);
1681 field.autocomplete_attribute = "upi-vpa"; 1764 field.autocomplete_attribute = "upi-vpa";
1682 form.fields.push_back(field); 1765 form.fields.push_back(field);
1683 1766
1684 std::vector<FormData> forms(1, form); 1767 std::vector<FormData> forms(1, form);
1685 1768
1686 // Expect the "upi-vpa hint" metric to be logged. 1769 // Expect the "upi-vpa hint" metric to be logged and the "form loaded" form
1770 // interaction event to be logged.
1687 { 1771 {
1688 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 1772 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now());
1689 autofill_manager_->Reset(); 1773 autofill_manager_->Reset();
1690 1774
1691 ASSERT_EQ(1U, ukm_service->sources_count()); 1775 ASSERT_EQ(2U, ukm_service->entries_count());
1692 const ukm::UkmSource* source = 1776 ASSERT_EQ(2U, ukm_service->sources_count());
1693 ukm_service->GetSourceForUrl(form.origin.spec().c_str()); 1777 VerifyDeveloperEngagementUkm(form, ukm_service,
1694 ASSERT_NE(nullptr, source); 1778 {AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT});
1779 VerifyUniqueFormInteractionEventUkm(form, ukm_service,
1780 internal::kUKMUserHappinessMetricName,
1781 AutofillMetrics::FORMS_LOADED);
1695 1782
1696 ASSERT_EQ(1U, ukm_service->entries_count()); 1783 ukm_service->Purge();
1697 const ukm::UkmEntry* entry = ukm_service->GetEntry(0); 1784 }
1698 EXPECT_EQ(source->id(), entry->source_id());
1699 1785
1700 ukm::Entry entry_proto; 1786 // Add another field with an author-specified field type to the form.
1701 entry->PopulateProto(&entry_proto); 1787 test::CreateTestFormField("", "", "", "text", &field);
1702 EXPECT_EQ(source->id(), entry_proto.source_id()); 1788 field.autocomplete_attribute = "address-line1";
1703 EXPECT_EQ(base::HashMetricName(internal::kUKMDeveloperEngagementEntryName), 1789 forms.back().fields.push_back(field);
1704 entry_proto.event_hash()); 1790
1705 const ukm::Entry_Metric* metric = FindMetric( 1791 {
1706 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics()); 1792 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now());
1707 ASSERT_NE(nullptr, metric); 1793 autofill_manager_->Reset();
1708 EXPECT_EQ(AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT, metric->value()); 1794
1795 VerifyDeveloperEngagementUkm(
1796 form, ukm_service,
1797 {AutofillMetrics::FILLABLE_FORM_PARSED_WITH_TYPE_HINTS,
1798 AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT});
1709 } 1799 }
1710 } 1800 }
1711 1801
1712 // Test that the profile count is logged correctly. 1802 // Test that the profile count is logged correctly.
1713 TEST_F(AutofillMetricsTest, StoredProfileCount) { 1803 TEST_F(AutofillMetricsTest, StoredProfileCount) {
1714 // The metric should be logged when the profiles are first loaded. 1804 // The metric should be logged when the profiles are first loaded.
1715 { 1805 {
1716 base::HistogramTester histogram_tester; 1806 base::HistogramTester histogram_tester;
1717 personal_data_->LoadProfiles(); 1807 personal_data_->LoadProfiles();
1718 histogram_tester.ExpectUniqueSample("Autofill.StoredProfileCount", 2, 1); 1808 histogram_tester.ExpectUniqueSample("Autofill.StoredProfileCount", 2, 1);
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 // Simulate activating the autofill popup for the email field after typing. 1971 // Simulate activating the autofill popup for the email field after typing.
1882 form.fields[0].is_autofilled = true; 1972 form.fields[0].is_autofilled = true;
1883 base::HistogramTester histogram_tester; 1973 base::HistogramTester histogram_tester;
1884 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 1974 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
1885 histogram_tester.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0); 1975 histogram_tester.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0);
1886 } 1976 }
1887 } 1977 }
1888 1978
1889 // Test that the credit card checkout flow user actions are correctly logged. 1979 // Test that the credit card checkout flow user actions are correctly logged.
1890 TEST_F(AutofillMetricsTest, CreditCardCheckoutFlowUserActions) { 1980 TEST_F(AutofillMetricsTest, CreditCardCheckoutFlowUserActions) {
1981 EnableUkmLogging();
1982 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
1983
1891 personal_data_->RecreateCreditCards( 1984 personal_data_->RecreateCreditCards(
1892 true /* include_local_credit_card */, 1985 true /* include_local_credit_card */,
1893 false /* include_masked_server_credit_card */, 1986 false /* include_masked_server_credit_card */,
1894 false /* include_full_server_credit_card */); 1987 false /* include_full_server_credit_card */);
1895 1988
1896 // Set up our form data. 1989 // Set up our form data.
1897 FormData form; 1990 FormData form;
1898 form.name = ASCIIToUTF16("TestForm"); 1991 form.name = ASCIIToUTF16("TestForm");
1899 form.origin = GURL("http://example.com/form.html"); 1992 form.origin = GURL("http://example.com/form.html");
1900 form.action = GURL("http://example.com/submit.html"); 1993 form.action = GURL("http://example.com/submit.html");
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1956 // Simulate submitting the credit card form. 2049 // Simulate submitting the credit card form.
1957 { 2050 {
1958 base::UserActionTester user_action_tester; 2051 base::UserActionTester user_action_tester;
1959 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 2052 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
1960 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 2053 autofill_manager_->SubmitForm(form, TimeTicks::Now());
1961 EXPECT_EQ(1, 2054 EXPECT_EQ(1,
1962 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); 2055 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm"));
1963 EXPECT_EQ(1, user_action_tester.GetActionCount( 2056 EXPECT_EQ(1, user_action_tester.GetActionCount(
1964 "Autofill_FormSubmitted_NonFillable")); 2057 "Autofill_FormSubmitted_NonFillable"));
1965 } 2058 }
2059
2060 // Expect 2 |FORM_EVENT_LOCAL_SUGGESTION_FILLED| events. First, from
2061 // call to |external_delegate_->DidAcceptSuggestion|. Second, from call to
2062 // |autofill_manager_->FillOrPreviewForm|.
2063 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState|
2064 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|.
2065 ASSERT_EQ(4U, ukm_service->entries_count());
2066 ASSERT_EQ(1U, ukm_service->sources_count());
2067 VerifyFormInteractionsUkm(
2068 form, ukm_service,
2069 {{internal::kUKMCreditCardFormEventName,
2070 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN},
2071 {internal::kUKMCreditCardFormEventName,
2072 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED},
2073 {internal::kUKMCreditCardFormEventName,
2074 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED},
2075 {internal::kUKMAutofillFormSubmittedStateName,
2076 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
1966 } 2077 }
1967 2078
1968 // Test that the profile checkout flow user actions are correctly logged. 2079 // Test that the profile checkout flow user actions are correctly logged.
1969 TEST_F(AutofillMetricsTest, ProfileCheckoutFlowUserActions) { 2080 TEST_F(AutofillMetricsTest, ProfileCheckoutFlowUserActions) {
2081 EnableUkmLogging();
2082 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
2083
1970 // Create a profile. 2084 // Create a profile.
1971 personal_data_->RecreateProfile(); 2085 personal_data_->RecreateProfile();
1972 2086
1973 // Set up our form data. 2087 // Set up our form data.
1974 FormData form; 2088 FormData form;
1975 form.name = ASCIIToUTF16("TestForm"); 2089 form.name = ASCIIToUTF16("TestForm");
1976 form.origin = GURL("http://example.com/form.html"); 2090 form.origin = GURL("http://example.com/form.html");
1977 form.action = GURL("http://example.com/submit.html"); 2091 form.action = GURL("http://example.com/submit.html");
1978 2092
1979 FormFieldData field; 2093 FormFieldData field;
(...skipping 27 matching lines...) Expand all
2007 EXPECT_EQ(1, user_action_tester.GetActionCount( 2121 EXPECT_EQ(1, user_action_tester.GetActionCount(
2008 "Autofill_ShowedProfileSuggestions")); 2122 "Autofill_ShowedProfileSuggestions"));
2009 } 2123 }
2010 2124
2011 // Simulate selecting a profile suggestions. 2125 // Simulate selecting a profile suggestions.
2012 { 2126 {
2013 base::UserActionTester user_action_tester; 2127 base::UserActionTester user_action_tester;
2014 std::string guid("00000000-0000-0000-0000-000000000001"); // local profile. 2128 std::string guid("00000000-0000-0000-0000-000000000001"); // local profile.
2015 external_delegate_->DidAcceptSuggestion( 2129 external_delegate_->DidAcceptSuggestion(
2016 ASCIIToUTF16("Test"), 2130 ASCIIToUTF16("Test"),
2017 autofill_manager_->MakeFrontendID(guid, std::string()), 0); 2131 autofill_manager_->MakeFrontendID(std::string(), guid), 0);
2018 EXPECT_EQ(1, 2132 EXPECT_EQ(1,
2019 user_action_tester.GetActionCount("Autofill_SelectedSuggestion")); 2133 user_action_tester.GetActionCount("Autofill_SelectedSuggestion"));
2020 } 2134 }
2021 2135
2022 // Simulate filling a profile suggestion. 2136 // Simulate filling a profile suggestion.
2023 { 2137 {
2024 base::UserActionTester user_action_tester; 2138 base::UserActionTester user_action_tester;
2025 std::string guid("00000000-0000-0000-0000-000000000001"); // local profile. 2139 std::string guid("00000000-0000-0000-0000-000000000001"); // local profile.
2026 autofill_manager_->FillOrPreviewForm( 2140 autofill_manager_->FillOrPreviewForm(
2027 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), 2141 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
2028 autofill_manager_->MakeFrontendID(std::string(), guid)); 2142 autofill_manager_->MakeFrontendID(std::string(), guid));
2029 EXPECT_EQ(1, user_action_tester.GetActionCount( 2143 EXPECT_EQ(1, user_action_tester.GetActionCount(
2030 "Autofill_FilledProfileSuggestion")); 2144 "Autofill_FilledProfileSuggestion"));
2031 } 2145 }
2032 2146
2033 // Simulate submitting the profile form. 2147 // Simulate submitting the profile form.
2034 { 2148 {
2035 base::UserActionTester user_action_tester; 2149 base::UserActionTester user_action_tester;
2036 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 2150 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2037 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 2151 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2038 EXPECT_EQ(1, 2152 EXPECT_EQ(1,
2039 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); 2153 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm"));
2040 EXPECT_EQ(1, user_action_tester.GetActionCount( 2154 EXPECT_EQ(1, user_action_tester.GetActionCount(
2041 "Autofill_FormSubmitted_NonFillable")); 2155 "Autofill_FormSubmitted_NonFillable"));
2042 } 2156 }
2157
2158 // Expect 2 |FORM_EVENT_LOCAL_SUGGESTION_FILLED| events. First, from
2159 // call to |external_delegate_->DidAcceptSuggestion|. Second, from call to
2160 // |autofill_manager_->FillOrPreviewForm|.
2161 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState|
2162 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|.
2163 VerifyFormInteractionsUkm(
2164 form, ukm_service,
2165 {{internal::kUKMAddressFormEventName,
2166 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN},
2167 {internal::kUKMAddressFormEventName,
2168 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED},
2169 {internal::kUKMAddressFormEventName,
2170 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED},
2171 {internal::kUKMAutofillFormSubmittedStateName,
2172 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
2173 ASSERT_EQ(4U, ukm_service->entries_count());
2174 ASSERT_EQ(1U, ukm_service->sources_count());
2043 } 2175 }
2044 2176
2045 // Tests that the Autofill_PolledCreditCardSuggestions user action is only 2177 // Tests that the Autofill_PolledCreditCardSuggestions user action is only
2046 // logged once if the field is queried repeatedly. 2178 // logged once if the field is queried repeatedly.
2047 TEST_F(AutofillMetricsTest, PolledCreditCardSuggestions_DebounceLogs) { 2179 TEST_F(AutofillMetricsTest, PolledCreditCardSuggestions_DebounceLogs) {
2048 personal_data_->RecreateCreditCards( 2180 personal_data_->RecreateCreditCards(
2049 true /* include_local_credit_card */, 2181 true /* include_local_credit_card */,
2050 false /* include_masked_server_credit_card */, 2182 false /* include_masked_server_credit_card */,
2051 false /* include_full_server_credit_card */); 2183 false /* include_full_server_credit_card */);
2052 2184
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
2322 base::HistogramTester histogram_tester; 2454 base::HistogramTester histogram_tester;
2323 autofill_manager_->DidShowSuggestions(false /* is_new_popup */, form, 2455 autofill_manager_->DidShowSuggestions(false /* is_new_popup */, form,
2324 field); 2456 field);
2325 histogram_tester.ExpectBucketCount( 2457 histogram_tester.ExpectBucketCount(
2326 "Autofill.FormEvents.CreditCard", 2458 "Autofill.FormEvents.CreditCard",
2327 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN, 0); 2459 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN, 0);
2328 histogram_tester.ExpectBucketCount( 2460 histogram_tester.ExpectBucketCount(
2329 "Autofill.FormEvents.CreditCard", 2461 "Autofill.FormEvents.CreditCard",
2330 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 0); 2462 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 0);
2331 } 2463 }
2464
2465 // UKM must not be logged unless enabled.
2466 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
2467 EXPECT_EQ(0U, ukm_service->sources_count());
2468 EXPECT_EQ(0U, ukm_service->entries_count());
2332 } 2469 }
2333 2470
2334 // Test that we log selected form event for credit cards. 2471 // Test that we log selected form event for credit cards.
2335 TEST_F(AutofillMetricsTest, CreditCardSelectedFormEvents) { 2472 TEST_F(AutofillMetricsTest, CreditCardSelectedFormEvents) {
2336 EnableWalletSync(); 2473 EnableWalletSync();
2337 // Creating all kinds of cards. 2474 // Creating all kinds of cards.
2338 personal_data_->RecreateCreditCards( 2475 personal_data_->RecreateCreditCards(
2339 true /* include_local_credit_card */, 2476 true /* include_local_credit_card */,
2340 true /* include_masked_server_credit_card */, 2477 true /* include_masked_server_credit_card */,
2341 true /* include_full_server_credit_card */); 2478 true /* include_full_server_credit_card */);
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
2587 std::string()); 2724 std::string());
2588 histogram_tester.ExpectTotalCount( 2725 histogram_tester.ExpectTotalCount(
2589 "Autofill.UnmaskPrompt.GetRealPanDuration", 1); 2726 "Autofill.UnmaskPrompt.GetRealPanDuration", 1);
2590 histogram_tester.ExpectTotalCount( 2727 histogram_tester.ExpectTotalCount(
2591 "Autofill.UnmaskPrompt.GetRealPanDuration.Failure", 1); 2728 "Autofill.UnmaskPrompt.GetRealPanDuration.Failure", 1);
2592 } 2729 }
2593 } 2730 }
2594 2731
2595 // Test that we log submitted form events for credit cards. 2732 // Test that we log submitted form events for credit cards.
2596 TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) { 2733 TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) {
2734 EnableUkmLogging();
2735 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
2736
2597 EnableWalletSync(); 2737 EnableWalletSync();
2598 // Creating all kinds of cards. 2738 // Creating all kinds of cards.
2599 personal_data_->RecreateCreditCards( 2739 personal_data_->RecreateCreditCards(
2600 true /* include_local_credit_card */, 2740 true /* include_local_credit_card */,
2601 true /* include_masked_server_credit_card */, 2741 true /* include_masked_server_credit_card */,
2602 true /* include_full_server_credit_card */); 2742 true /* include_full_server_credit_card */);
2603 // Set up our form data. 2743 // Set up our form data.
2604 FormData form; 2744 FormData form;
2605 form.name = ASCIIToUTF16("TestForm"); 2745 form.name = ASCIIToUTF16("TestForm");
2606 form.origin = GURL("http://example.com/form.html"); 2746 form.origin = GURL("http://example.com/form.html");
(...skipping 19 matching lines...) Expand all
2626 // Simulating submission with no filled data. 2766 // Simulating submission with no filled data.
2627 base::HistogramTester histogram_tester; 2767 base::HistogramTester histogram_tester;
2628 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 2768 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2629 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 2769 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2630 histogram_tester.ExpectBucketCount( 2770 histogram_tester.ExpectBucketCount(
2631 "Autofill.FormEvents.CreditCard", 2771 "Autofill.FormEvents.CreditCard",
2632 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); 2772 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2633 histogram_tester.ExpectBucketCount( 2773 histogram_tester.ExpectBucketCount(
2634 "Autofill.FormEvents.CreditCard", 2774 "Autofill.FormEvents.CreditCard",
2635 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); 2775 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
2776
2777 ASSERT_EQ(1U, ukm_service->entries_count());
2778 ASSERT_EQ(1U, ukm_service->sources_count());
2779 VerifyFormInteractionsUkm(
2780 form, ukm_service,
2781 {{internal::kUKMAutofillFormSubmittedStateName,
2782 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
2783 ukm_service->Purge();
2636 } 2784 }
2637 2785
2638 // Reset the autofill manager state. 2786 // Reset the autofill manager state.
2639 autofill_manager_->Reset(); 2787 autofill_manager_->Reset();
2640 autofill_manager_->AddSeenForm(form, field_types, field_types); 2788 autofill_manager_->AddSeenForm(form, field_types, field_types);
2641 2789
2642 { 2790 {
2643 // Simulating submission with suggestion shown. 2791 // Simulating submission with suggestion shown.
2644 base::HistogramTester histogram_tester; 2792 base::HistogramTester histogram_tester;
2645 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); 2793 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field);
2646 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 2794 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2647 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 2795 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2648 histogram_tester.ExpectBucketCount( 2796 histogram_tester.ExpectBucketCount(
2649 "Autofill.FormEvents.CreditCard", 2797 "Autofill.FormEvents.CreditCard",
2650 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_SUBMITTED_ONCE, 1); 2798 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_SUBMITTED_ONCE, 1);
2651 histogram_tester.ExpectBucketCount( 2799 histogram_tester.ExpectBucketCount(
2652 "Autofill.FormEvents.CreditCard", 2800 "Autofill.FormEvents.CreditCard",
2653 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 1); 2801 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 1);
2802
2803 ASSERT_EQ(2U, ukm_service->entries_count());
2804 ASSERT_EQ(1U, ukm_service->sources_count());
2805 VerifyFormInteractionsUkm(
2806 form, ukm_service,
2807 {{internal::kUKMCreditCardFormEventName,
2808 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN},
2809 {internal::kUKMAutofillFormSubmittedStateName,
2810 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
2811 ukm_service->Purge();
2654 } 2812 }
2655 2813
2656 // Reset the autofill manager state. 2814 // Reset the autofill manager state.
2657 autofill_manager_->Reset(); 2815 autofill_manager_->Reset();
2658 autofill_manager_->AddSeenForm(form, field_types, field_types); 2816 autofill_manager_->AddSeenForm(form, field_types, field_types);
2659 2817
2660 { 2818 {
2661 // Simulating submission with filled local data. 2819 // Simulating submission with filled local data.
2662 base::HistogramTester histogram_tester; 2820 base::HistogramTester histogram_tester;
2663 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 2821 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2664 std::string guid("10000000-0000-0000-0000-000000000001"); // local card 2822 std::string guid("10000000-0000-0000-0000-000000000001"); // local card
2665 autofill_manager_->FillOrPreviewForm( 2823 autofill_manager_->FillOrPreviewForm(
2666 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), 2824 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
2667 autofill_manager_->MakeFrontendID(guid, std::string())); 2825 autofill_manager_->MakeFrontendID(guid, std::string()));
2668 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 2826 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2669 histogram_tester.ExpectBucketCount( 2827 histogram_tester.ExpectBucketCount(
2670 "Autofill.FormEvents.CreditCard", 2828 "Autofill.FormEvents.CreditCard",
2671 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 1); 2829 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2672 histogram_tester.ExpectBucketCount( 2830 histogram_tester.ExpectBucketCount(
2673 "Autofill.FormEvents.CreditCard", 2831 "Autofill.FormEvents.CreditCard",
2674 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 1); 2832 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 1);
2833
2834 ASSERT_EQ(2U, ukm_service->entries_count());
2835 ASSERT_EQ(1U, ukm_service->sources_count());
2836 VerifyFormInteractionsUkm(
2837 form, ukm_service,
2838 {{internal::kUKMCreditCardFormEventName,
2839 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED},
2840 {internal::kUKMAutofillFormSubmittedStateName,
2841 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
2842 ukm_service->Purge();
2675 } 2843 }
2676 2844
2677 // Reset the autofill manager state. 2845 // Reset the autofill manager state.
2678 autofill_manager_->Reset(); 2846 autofill_manager_->Reset();
2679 autofill_manager_->AddSeenForm(form, field_types, field_types); 2847 autofill_manager_->AddSeenForm(form, field_types, field_types);
2680 2848
2681 { 2849 {
2682 // Simulating submission with filled server data. 2850 // Simulating submission with filled server data.
2683 base::HistogramTester histogram_tester; 2851 base::HistogramTester histogram_tester;
2684 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 2852 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2685 std::string guid( 2853 std::string guid(
2686 "10000000-0000-0000-0000-000000000003"); // full server card 2854 "10000000-0000-0000-0000-000000000003"); // full server card
2687 autofill_manager_->FillOrPreviewForm( 2855 autofill_manager_->FillOrPreviewForm(
2688 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), 2856 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
2689 autofill_manager_->MakeFrontendID(guid, std::string())); 2857 autofill_manager_->MakeFrontendID(guid, std::string()));
2690 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 2858 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2691 histogram_tester.ExpectBucketCount( 2859 histogram_tester.ExpectBucketCount(
2692 "Autofill.FormEvents.CreditCard", 2860 "Autofill.FormEvents.CreditCard",
2693 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 1); 2861 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2694 histogram_tester.ExpectBucketCount( 2862 histogram_tester.ExpectBucketCount(
2695 "Autofill.FormEvents.CreditCard", 2863 "Autofill.FormEvents.CreditCard",
2696 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 1); 2864 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 1);
2865
2866 ASSERT_EQ(2U, ukm_service->entries_count());
2867 ASSERT_EQ(1U, ukm_service->sources_count());
2868 VerifyFormInteractionsUkm(
2869 form, ukm_service,
2870 {{internal::kUKMCreditCardFormEventName,
2871 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED},
2872 {internal::kUKMAutofillFormSubmittedStateName,
2873 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
2874 ukm_service->Purge();
2697 } 2875 }
2698 2876
2699 // Reset the autofill manager state. 2877 // Reset the autofill manager state.
2700 autofill_manager_->Reset(); 2878 autofill_manager_->Reset();
2701 autofill_manager_->AddSeenForm(form, field_types, field_types); 2879 autofill_manager_->AddSeenForm(form, field_types, field_types);
2702 2880
2703 { 2881 {
2704 // Simulating submission with a masked card server suggestion. 2882 // Simulating submission with a masked card server suggestion.
2705 base::HistogramTester histogram_tester; 2883 base::HistogramTester histogram_tester;
2706 std::string guid( 2884 std::string guid(
2707 "10000000-0000-0000-0000-000000000002"); // masked server card 2885 "10000000-0000-0000-0000-000000000002"); // masked server card
2708 autofill_manager_->FillOrPreviewForm( 2886 autofill_manager_->FillOrPreviewForm(
2709 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.back(), 2887 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.back(),
2710 autofill_manager_->MakeFrontendID(guid, std::string())); 2888 autofill_manager_->MakeFrontendID(guid, std::string()));
2711 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS, 2889 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS,
2712 "6011000990139424"); 2890 "6011000990139424");
2891 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2713 histogram_tester.ExpectBucketCount( 2892 histogram_tester.ExpectBucketCount(
2714 "Autofill.FormEvents.CreditCard", 2893 "Autofill.FormEvents.CreditCard",
2715 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED, 1); 2894 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED, 1);
2716 histogram_tester.ExpectBucketCount( 2895 histogram_tester.ExpectBucketCount(
2717 "Autofill.FormEvents.CreditCard", 2896 "Autofill.FormEvents.CreditCard",
2718 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE, 2897 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE,
2719 1); 2898 1);
2899
2900 ASSERT_EQ(4U, ukm_service->entries_count());
2901 ASSERT_EQ(1U, ukm_service->sources_count());
2902 VerifyFormInteractionsUkm(
2903 form, ukm_service,
2904 {{internal::kUKMUnmaskPromptEventName,
2905 AutofillMetrics::UNMASK_PROMPT_SHOWN},
2906 {internal::kUKMCreditCardFormEventName,
2907 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED},
2908 {internal::kUKMCreditCardFormEventName,
2909 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED},
2910 {internal::kUKMAutofillFormSubmittedStateName,
2911 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
2912 ukm_service->Purge();
2720 } 2913 }
2721 2914
2915 // Reset the autofill manager state.
2916 autofill_manager_->Reset();
2917
2722 // Recreating cards as the previous test should have upgraded the masked 2918 // Recreating cards as the previous test should have upgraded the masked
2723 // card to a full card. 2919 // card to a full card.
2724 personal_data_->RecreateCreditCards( 2920 personal_data_->RecreateCreditCards(
2725 true /* include_local_credit_card */, 2921 true /* include_local_credit_card */,
2726 true /* include_masked_server_credit_card */, 2922 true /* include_masked_server_credit_card */,
2727 true /* include_full_server_credit_card */); 2923 true /* include_full_server_credit_card */);
2728 2924
2729 // Reset the autofill manager state.
2730 autofill_manager_->Reset();
2731 autofill_manager_->AddSeenForm(form, field_types, field_types); 2925 autofill_manager_->AddSeenForm(form, field_types, field_types);
2732 2926
2733 { 2927 {
2734 // Simulating multiple submissions. 2928 // Simulating multiple submissions.
2735 base::HistogramTester histogram_tester; 2929 base::HistogramTester histogram_tester;
2736 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 2930 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2737 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 2931 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2932
2933 ASSERT_EQ(1U, ukm_service->entries_count());
2934 ASSERT_EQ(1U, ukm_service->sources_count());
2935 VerifyFormInteractionsUkm(
2936 form, ukm_service,
2937 {{internal::kUKMAutofillFormSubmittedStateName,
2938 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
2939 ukm_service->Purge();
2940
2941 autofill_manager_->form_interactions_ukm_logger()
2942 ->set_form_loaded_timestamp(TimeTicks::Now());
2738 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 2943 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2944
2945 ASSERT_EQ(1U, ukm_service->entries_count());
2946 ASSERT_EQ(1U, ukm_service->sources_count());
2947 VerifyFormInteractionsUkm(
2948 form, ukm_service,
2949 {{internal::kUKMAutofillFormSubmittedStateName,
2950 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
2951 ukm_service->Purge();
2952
2739 histogram_tester.ExpectBucketCount( 2953 histogram_tester.ExpectBucketCount(
2740 "Autofill.FormEvents.CreditCard", 2954 "Autofill.FormEvents.CreditCard",
2741 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); 2955 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2742 histogram_tester.ExpectBucketCount( 2956 histogram_tester.ExpectBucketCount(
2743 "Autofill.FormEvents.CreditCard", 2957 "Autofill.FormEvents.CreditCard",
2744 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 0); 2958 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 0);
2745 histogram_tester.ExpectBucketCount( 2959 histogram_tester.ExpectBucketCount(
2746 "Autofill.FormEvents.CreditCard", 2960 "Autofill.FormEvents.CreditCard",
2747 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0); 2961 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0);
2748 histogram_tester.ExpectBucketCount( 2962 histogram_tester.ExpectBucketCount(
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2809 "Autofill.FormEvents.CreditCard", 3023 "Autofill.FormEvents.CreditCard",
2810 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0); 3024 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0);
2811 histogram_tester.ExpectBucketCount( 3025 histogram_tester.ExpectBucketCount(
2812 "Autofill.FormEvents.CreditCard", 3026 "Autofill.FormEvents.CreditCard",
2813 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0); 3027 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
2814 histogram_tester.ExpectBucketCount( 3028 histogram_tester.ExpectBucketCount(
2815 "Autofill.FormEvents.CreditCard", 3029 "Autofill.FormEvents.CreditCard",
2816 AutofillMetrics:: 3030 AutofillMetrics::
2817 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE, 3031 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE,
2818 0); 3032 0);
3033
3034 ASSERT_EQ(2U, ukm_service->entries_count());
3035 ASSERT_EQ(1U, ukm_service->sources_count());
3036 VerifyFormInteractionsUkm(
3037 form, ukm_service,
3038 {{internal::kUKMCreditCardFormEventName,
3039 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN},
3040 {internal::kUKMAutofillFormSubmittedStateName,
3041 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
3042 ukm_service->Purge();
2819 } 3043 }
2820 } 3044 }
2821 3045
2822 // Test that we log "will submit" (but not submitted) form events for credit 3046 // Test that we log "will submit" (but not submitted) form events for credit
2823 // cards. Mirrors CreditCardSubmittedFormEvents test but does not expect any 3047 // cards. Mirrors CreditCardSubmittedFormEvents test but does not expect any
2824 // "submitted" metrics. 3048 // "submitted" metrics.
2825 TEST_F(AutofillMetricsTest, CreditCardWillSubmitFormEvents) { 3049 TEST_F(AutofillMetricsTest, CreditCardWillSubmitFormEvents) {
2826 EnableWalletSync(); 3050 EnableWalletSync();
2827 // Creating all kinds of cards. 3051 // Creating all kinds of cards.
2828 personal_data_->RecreateCreditCards( 3052 personal_data_->RecreateCreditCards(
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
3230 "Autofill.FormEvents.Address", 3454 "Autofill.FormEvents.Address",
3231 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED, 2); 3455 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED, 2);
3232 histogram_tester.ExpectBucketCount( 3456 histogram_tester.ExpectBucketCount(
3233 "Autofill.FormEvents.Address", 3457 "Autofill.FormEvents.Address",
3234 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE, 1); 3458 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE, 1);
3235 } 3459 }
3236 } 3460 }
3237 3461
3238 // Test that we log submitted form events for address. 3462 // Test that we log submitted form events for address.
3239 TEST_F(AutofillMetricsTest, AddressSubmittedFormEvents) { 3463 TEST_F(AutofillMetricsTest, AddressSubmittedFormEvents) {
3464 EnableUkmLogging();
3465 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
3466
3240 EnableWalletSync(); 3467 EnableWalletSync();
3241 // Create a profile. 3468 // Create a profile.
3242 personal_data_->RecreateProfile(); 3469 personal_data_->RecreateProfile();
3243 // Set up our form data. 3470 // Set up our form data.
3244 FormData form; 3471 FormData form;
3245 form.name = ASCIIToUTF16("TestForm"); 3472 form.name = ASCIIToUTF16("TestForm");
3246 form.origin = GURL("http://example.com/form.html"); 3473 form.origin = GURL("http://example.com/form.html");
3247 form.action = GURL("http://example.com/submit.html"); 3474 form.action = GURL("http://example.com/submit.html");
3248 3475
3249 FormFieldData field; 3476 FormFieldData field;
(...skipping 16 matching lines...) Expand all
3266 // Simulating submission with no filled data. 3493 // Simulating submission with no filled data.
3267 base::HistogramTester histogram_tester; 3494 base::HistogramTester histogram_tester;
3268 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 3495 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
3269 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 3496 autofill_manager_->SubmitForm(form, TimeTicks::Now());
3270 histogram_tester.ExpectBucketCount( 3497 histogram_tester.ExpectBucketCount(
3271 "Autofill.FormEvents.Address", 3498 "Autofill.FormEvents.Address",
3272 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); 3499 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
3273 histogram_tester.ExpectBucketCount( 3500 histogram_tester.ExpectBucketCount(
3274 "Autofill.FormEvents.Address", 3501 "Autofill.FormEvents.Address",
3275 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); 3502 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
3503
3504 ASSERT_EQ(1U, ukm_service->entries_count());
3505 ASSERT_EQ(1U, ukm_service->sources_count());
3506 VerifyFormInteractionsUkm(
3507 form, ukm_service,
3508 {{internal::kUKMAutofillFormSubmittedStateName,
3509 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
3510 ukm_service->Purge();
3276 } 3511 }
3277 3512
3278 // Reset the autofill manager state. 3513 // Reset the autofill manager state.
3279 autofill_manager_->Reset(); 3514 autofill_manager_->Reset();
3280 autofill_manager_->AddSeenForm(form, field_types, field_types); 3515 autofill_manager_->AddSeenForm(form, field_types, field_types);
3281 3516
3282 { 3517 {
3283 // Simulating submission with suggestion shown. 3518 // Simulating submission with suggestion shown.
3284 base::HistogramTester histogram_tester; 3519 base::HistogramTester histogram_tester;
3285 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); 3520 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field);
(...skipping 30 matching lines...) Expand all
3316 3551
3317 // Reset the autofill manager state. 3552 // Reset the autofill manager state.
3318 autofill_manager_->Reset(); 3553 autofill_manager_->Reset();
3319 autofill_manager_->AddSeenForm(form, field_types, field_types); 3554 autofill_manager_->AddSeenForm(form, field_types, field_types);
3320 3555
3321 { 3556 {
3322 // Simulating multiple submissions. 3557 // Simulating multiple submissions.
3323 base::HistogramTester histogram_tester; 3558 base::HistogramTester histogram_tester;
3324 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 3559 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
3325 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 3560 autofill_manager_->SubmitForm(form, TimeTicks::Now());
3561
3562 autofill_manager_->form_interactions_ukm_logger()
3563 ->set_form_loaded_timestamp(TimeTicks::Now());
3326 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 3564 autofill_manager_->SubmitForm(form, TimeTicks::Now());
3565
3327 histogram_tester.ExpectBucketCount( 3566 histogram_tester.ExpectBucketCount(
3328 "Autofill.FormEvents.Address", 3567 "Autofill.FormEvents.Address",
3329 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1); 3568 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
3330 histogram_tester.ExpectBucketCount( 3569 histogram_tester.ExpectBucketCount(
3331 "Autofill.FormEvents.Address", 3570 "Autofill.FormEvents.Address",
3332 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 0); 3571 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 0);
3333 histogram_tester.ExpectBucketCount( 3572 histogram_tester.ExpectBucketCount(
3334 "Autofill.FormEvents.Address", 3573 "Autofill.FormEvents.Address",
3335 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0); 3574 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0);
3336 histogram_tester.ExpectBucketCount( 3575 histogram_tester.ExpectBucketCount(
(...skipping 16 matching lines...) Expand all
3353 // Reset the autofill manager state. 3592 // Reset the autofill manager state.
3354 autofill_manager_->Reset(); 3593 autofill_manager_->Reset();
3355 autofill_manager_->AddSeenForm(form, field_types, field_types); 3594 autofill_manager_->AddSeenForm(form, field_types, field_types);
3356 3595
3357 { 3596 {
3358 // Simulating submission with suggestion show but without previous 3597 // Simulating submission with suggestion show but without previous
3359 // interaction. 3598 // interaction.
3360 base::HistogramTester histogram_tester; 3599 base::HistogramTester histogram_tester;
3361 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); 3600 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field);
3362 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 3601 autofill_manager_->SubmitForm(form, TimeTicks::Now());
3602
3363 histogram_tester.ExpectBucketCount( 3603 histogram_tester.ExpectBucketCount(
3364 "Autofill.FormEvents.Address", 3604 "Autofill.FormEvents.Address",
3365 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 0); 3605 AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, 0);
3366 histogram_tester.ExpectBucketCount( 3606 histogram_tester.ExpectBucketCount(
3367 "Autofill.FormEvents.Address", 3607 "Autofill.FormEvents.Address",
3368 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 0); 3608 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 0);
3369 histogram_tester.ExpectBucketCount( 3609 histogram_tester.ExpectBucketCount(
3370 "Autofill.FormEvents.Address", 3610 "Autofill.FormEvents.Address",
3371 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0); 3611 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0);
3372 histogram_tester.ExpectBucketCount( 3612 histogram_tester.ExpectBucketCount(
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
3723 { 3963 {
3724 // Simulate activating the autofill popup for the street field. 3964 // Simulate activating the autofill popup for the street field.
3725 base::HistogramTester histogram_tester; 3965 base::HistogramTester histogram_tester;
3726 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); 3966 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
3727 histogram_tester.ExpectUniqueSample( 3967 histogram_tester.ExpectUniqueSample(
3728 "Autofill.FormEvents.Address.WithOnlyLocalData", 3968 "Autofill.FormEvents.Address.WithOnlyLocalData",
3729 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE, 1); 3969 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE, 1);
3730 } 3970 }
3731 } 3971 }
3732 3972
3733
3734 // Test that we log that Autofill is enabled when filling a form. 3973 // Test that we log that Autofill is enabled when filling a form.
3735 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtPageLoad) { 3974 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtPageLoad) {
3736 base::HistogramTester histogram_tester; 3975 base::HistogramTester histogram_tester;
3737 autofill_manager_->set_autofill_enabled(true); 3976 autofill_manager_->set_autofill_enabled(true);
3738 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks()); 3977 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks());
3739 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.PageLoad", true, 1); 3978 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.PageLoad", true, 1);
3740 } 3979 }
3741 3980
3742 // Test that we log that Autofill is disabled when filling a form. 3981 // Test that we log that Autofill is disabled when filling a form.
3743 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtPageLoad) { 3982 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtPageLoad) {
(...skipping 18 matching lines...) Expand all
3762 base::HistogramTester histogram_tester; 4001 base::HistogramTester histogram_tester;
3763 AutofillProfile profile; 4002 AutofillProfile profile;
3764 profile.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(13)); 4003 profile.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(13));
3765 profile.RecordAndLogUse(); 4004 profile.RecordAndLogUse();
3766 histogram_tester.ExpectBucketCount("Autofill.DaysSinceLastUse.Profile", 13, 4005 histogram_tester.ExpectBucketCount("Autofill.DaysSinceLastUse.Profile", 13,
3767 1); 4006 1);
3768 } 4007 }
3769 4008
3770 // Verify that we correctly log the submitted form's state. 4009 // Verify that we correctly log the submitted form's state.
3771 TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) { 4010 TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) {
4011 EnableUkmLogging();
4012 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
4013
3772 // Start with a form with insufficiently many fields. 4014 // Start with a form with insufficiently many fields.
3773 FormData form; 4015 FormData form;
3774 form.name = ASCIIToUTF16("TestForm"); 4016 form.name = ASCIIToUTF16("TestForm");
3775 form.origin = GURL("http://example.com/form.html"); 4017 form.origin = GURL("http://example.com/form.html");
3776 form.action = GURL("http://example.com/submit.html"); 4018 form.action = GURL("http://example.com/submit.html");
3777 4019
3778 FormFieldData field; 4020 FormFieldData field;
3779 test::CreateTestFormField("Name", "name", "", "text", &field); 4021 test::CreateTestFormField("Name", "name", "", "text", &field);
3780 form.fields.push_back(field); 4022 form.fields.push_back(field);
3781 test::CreateTestFormField("Email", "email", "", "text", &field); 4023 test::CreateTestFormField("Email", "email", "", "text", &field);
3782 form.fields.push_back(field); 4024 form.fields.push_back(field);
3783 test::CreateTestFormField("Phone", "phone", "", "text", &field); 4025 test::CreateTestFormField("Phone", "phone", "", "text", &field);
3784 form.fields.push_back(field); 4026 form.fields.push_back(field);
3785 test::CreateTestFormField("Unknown", "unknown", "", "text", &field); 4027 test::CreateTestFormField("Unknown", "unknown", "", "text", &field);
3786 form.fields.push_back(field); 4028 form.fields.push_back(field);
3787 std::vector<FormData> forms(1, form); 4029 std::vector<FormData> forms(1, form);
3788 4030
3789 // Expect no notifications when the form is first seen. 4031 // Expect no notifications when the form is first seen.
3790 { 4032 {
3791 base::HistogramTester histogram_tester; 4033 base::HistogramTester histogram_tester;
3792 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 4034 autofill_manager_->OnFormsSeen(forms, TimeTicks::Now());
3793 histogram_tester.ExpectTotalCount("Autofill.FormSubmittedState", 0); 4035 histogram_tester.ExpectTotalCount("Autofill.FormSubmittedState", 0);
3794 } 4036 }
3795 4037
3796 // No data entered in the form. 4038 // No data entered in the form.
3797 { 4039 {
3798 base::HistogramTester histogram_tester; 4040 base::HistogramTester histogram_tester;
3799 base::UserActionTester user_action_tester; 4041 base::UserActionTester user_action_tester;
3800 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4042 autofill_manager_->SubmitForm(form, TimeTicks::Now());
3801 histogram_tester.ExpectUniqueSample( 4043 histogram_tester.ExpectUniqueSample(
3802 "Autofill.FormSubmittedState", 4044 "Autofill.FormSubmittedState",
3803 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); 4045 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1);
3804 EXPECT_EQ(1, user_action_tester.GetActionCount( 4046 EXPECT_EQ(1, user_action_tester.GetActionCount(
3805 "Autofill_FormSubmitted_NonFillable")); 4047 "Autofill_FormSubmitted_NonFillable"));
4048
4049 // Expect an entry for |DeveloperEngagement| and 2 entries for form
4050 // interactions. All 3 entries are for the same URL.
4051 ASSERT_EQ(3U, ukm_service->entries_count());
4052 ASSERT_EQ(2U, ukm_service->sources_count());
4053 VerifyDeveloperEngagementUkm(
4054 form, ukm_service,
4055 {AutofillMetrics::FILLABLE_FORM_PARSED_WITHOUT_TYPE_HINTS});
4056 VerifyUniqueFormInteractionEventUkm(form, ukm_service,
4057 internal::kUKMUserHappinessMetricName,
4058 AutofillMetrics::FORMS_LOADED);
4059 VerifyUniqueFormInteractionEventUkm(
4060 form, ukm_service, internal::kUKMAutofillFormSubmittedStateName,
4061 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA);
4062 ukm_service->Purge();
3806 } 4063 }
3807 4064
3808 // Non fillable form. 4065 // Non fillable form.
3809 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley"); 4066 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley");
3810 form.fields[1].value = ASCIIToUTF16("theking@gmail.com"); 4067 form.fields[1].value = ASCIIToUTF16("theking@gmail.com");
3811 forms.front() = form; 4068 forms.front() = form;
3812 4069
3813 { 4070 {
3814 base::HistogramTester histogram_tester; 4071 base::HistogramTester histogram_tester;
3815 base::UserActionTester user_action_tester; 4072 base::UserActionTester user_action_tester;
4073 autofill_manager_->form_interactions_ukm_logger()
4074 ->set_form_loaded_timestamp(TimeTicks::Now());
3816 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4075 autofill_manager_->SubmitForm(form, TimeTicks::Now());
3817 histogram_tester.ExpectUniqueSample( 4076 histogram_tester.ExpectUniqueSample(
3818 "Autofill.FormSubmittedState", 4077 "Autofill.FormSubmittedState",
3819 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); 4078 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1);
3820 EXPECT_EQ(1, user_action_tester.GetActionCount( 4079 EXPECT_EQ(1, user_action_tester.GetActionCount(
3821 "Autofill_FormSubmitted_NonFillable")); 4080 "Autofill_FormSubmitted_NonFillable"));
4081
4082 ASSERT_EQ(1U, ukm_service->entries_count());
4083 ASSERT_EQ(1U, ukm_service->sources_count());
4084 VerifyFormInteractionsUkm(
4085 form, ukm_service,
4086 {{internal::kUKMAutofillFormSubmittedStateName,
4087 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
4088 ukm_service->Purge();
3822 } 4089 }
3823 4090
3824 // Fill in the third field. 4091 // Fill in the third field.
3825 form.fields[2].value = ASCIIToUTF16("12345678901"); 4092 form.fields[2].value = ASCIIToUTF16("12345678901");
3826 forms.front() = form; 4093 forms.front() = form;
3827 4094
3828 // Autofilled none with no suggestions shown. 4095 // Autofilled none with no suggestions shown.
3829 { 4096 {
3830 base::HistogramTester histogram_tester; 4097 base::HistogramTester histogram_tester;
3831 base::UserActionTester user_action_tester; 4098 base::UserActionTester user_action_tester;
4099 autofill_manager_->form_interactions_ukm_logger()
4100 ->set_form_loaded_timestamp(TimeTicks::Now());
3832 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4101 autofill_manager_->SubmitForm(form, TimeTicks::Now());
3833 histogram_tester.ExpectUniqueSample( 4102 histogram_tester.ExpectUniqueSample(
3834 "Autofill.FormSubmittedState", 4103 "Autofill.FormSubmittedState",
3835 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS, 4104 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS,
3836 1); 4105 1);
3837 EXPECT_EQ(1, user_action_tester.GetActionCount( 4106 EXPECT_EQ(1, user_action_tester.GetActionCount(
3838 "Autofill_FormSubmitted_FilledNone_SuggestionsNotShown")); 4107 "Autofill_FormSubmitted_FilledNone_SuggestionsNotShown"));
4108
4109 ASSERT_EQ(1U, ukm_service->entries_count());
4110 ASSERT_EQ(1U, ukm_service->sources_count());
4111 VerifyFormInteractionsUkm(
4112 form, ukm_service,
4113 {{internal::kUKMAutofillFormSubmittedStateName,
4114 AutofillMetrics::
4115 FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS}});
4116 ukm_service->Purge();
3839 } 4117 }
3840 4118
3841 // Autofilled none with suggestions shown. 4119 // Autofilled none with suggestions shown.
4120 autofill_manager_->form_interactions_ukm_logger()->set_form_loaded_timestamp(
4121 TimeTicks::Now());
3842 autofill_manager_->DidShowSuggestions(true, form, form.fields[2]); 4122 autofill_manager_->DidShowSuggestions(true, form, form.fields[2]);
3843 { 4123 {
3844 base::HistogramTester histogram_tester; 4124 base::HistogramTester histogram_tester;
3845 base::UserActionTester user_action_tester; 4125 base::UserActionTester user_action_tester;
3846 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4126 autofill_manager_->SubmitForm(form, TimeTicks::Now());
3847 histogram_tester.ExpectUniqueSample( 4127 histogram_tester.ExpectUniqueSample(
3848 "Autofill.FormSubmittedState", 4128 "Autofill.FormSubmittedState",
3849 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS, 1); 4129 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS, 1);
3850 EXPECT_EQ(1, user_action_tester.GetActionCount( 4130 EXPECT_EQ(1, user_action_tester.GetActionCount(
3851 "Autofill_FormSubmitted_FilledNone_SuggestionsShown")); 4131 "Autofill_FormSubmitted_FilledNone_SuggestionsShown"));
4132
4133 ASSERT_EQ(2U, ukm_service->entries_count());
4134 ASSERT_EQ(1U, ukm_service->sources_count());
4135 VerifyFormInteractionsUkm(
4136 form, ukm_service,
4137 {{internal::kUKMAddressFormEventName,
4138 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN},
4139 {internal::kUKMAutofillFormSubmittedStateName,
4140 AutofillMetrics::
4141 FILLABLE_FORM_AUTOFILLED_NONE_DID_SHOW_SUGGESTIONS}});
4142 ukm_service->Purge();
3852 } 4143 }
3853 4144
3854 // Mark one of the fields as autofilled. 4145 // Mark one of the fields as autofilled.
3855 form.fields[1].is_autofilled = true; 4146 form.fields[1].is_autofilled = true;
3856 forms.front() = form; 4147 forms.front() = form;
3857 4148
3858 // Autofilled some of the fields. 4149 // Autofilled some of the fields.
3859 { 4150 {
3860 base::HistogramTester histogram_tester; 4151 base::HistogramTester histogram_tester;
3861 base::UserActionTester user_action_tester; 4152 base::UserActionTester user_action_tester;
4153 autofill_manager_->form_interactions_ukm_logger()
4154 ->set_form_loaded_timestamp(TimeTicks::Now());
3862 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4155 autofill_manager_->SubmitForm(form, TimeTicks::Now());
3863 histogram_tester.ExpectUniqueSample( 4156 histogram_tester.ExpectUniqueSample(
3864 "Autofill.FormSubmittedState", 4157 "Autofill.FormSubmittedState",
3865 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME, 1); 4158 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME, 1);
3866 EXPECT_EQ(1, user_action_tester.GetActionCount( 4159 EXPECT_EQ(1, user_action_tester.GetActionCount(
3867 "Autofill_FormSubmitted_FilledSome")); 4160 "Autofill_FormSubmitted_FilledSome"));
4161
4162 ASSERT_EQ(1U, ukm_service->entries_count());
4163 ASSERT_EQ(1U, ukm_service->sources_count());
4164 VerifyFormInteractionsUkm(
4165 form, ukm_service,
4166 {{internal::kUKMAutofillFormSubmittedStateName,
4167 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_SOME}});
4168 ukm_service->Purge();
3868 } 4169 }
3869 4170
3870 // Mark all of the fillable fields as autofilled. 4171 // Mark all of the fillable fields as autofilled.
3871 form.fields[0].is_autofilled = true; 4172 form.fields[0].is_autofilled = true;
3872 form.fields[2].is_autofilled = true; 4173 form.fields[2].is_autofilled = true;
3873 forms.front() = form; 4174 forms.front() = form;
3874 4175
3875 // Autofilled all the fields. 4176 // Autofilled all the fields.
3876 { 4177 {
3877 base::HistogramTester histogram_tester; 4178 base::HistogramTester histogram_tester;
3878 base::UserActionTester user_action_tester; 4179 base::UserActionTester user_action_tester;
4180 autofill_manager_->form_interactions_ukm_logger()
4181 ->set_form_loaded_timestamp(TimeTicks::Now());
3879 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4182 autofill_manager_->SubmitForm(form, TimeTicks::Now());
3880 histogram_tester.ExpectUniqueSample( 4183 histogram_tester.ExpectUniqueSample(
3881 "Autofill.FormSubmittedState", 4184 "Autofill.FormSubmittedState",
3882 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL, 1); 4185 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL, 1);
3883 EXPECT_EQ(1, user_action_tester.GetActionCount( 4186 EXPECT_EQ(1, user_action_tester.GetActionCount(
3884 "Autofill_FormSubmitted_FilledAll")); 4187 "Autofill_FormSubmitted_FilledAll"));
4188
4189 ASSERT_EQ(1U, ukm_service->entries_count());
4190 ASSERT_EQ(1U, ukm_service->sources_count());
4191 VerifyFormInteractionsUkm(
4192 form, ukm_service,
4193 {{internal::kUKMAutofillFormSubmittedStateName,
4194 AutofillMetrics::FILLABLE_FORM_AUTOFILLED_ALL}});
4195 ukm_service->Purge();
3885 } 4196 }
3886 4197
3887 // Clear out the third field's value. 4198 // Clear out the third field's value.
3888 form.fields[2].value = base::string16(); 4199 form.fields[2].value = base::string16();
3889 forms.front() = form; 4200 forms.front() = form;
3890 4201
3891 // Non fillable form. 4202 // Non fillable form.
3892 { 4203 {
3893 base::HistogramTester histogram_tester; 4204 base::HistogramTester histogram_tester;
3894 base::UserActionTester user_action_tester; 4205 base::UserActionTester user_action_tester;
4206 autofill_manager_->form_interactions_ukm_logger()
4207 ->set_form_loaded_timestamp(TimeTicks::Now());
3895 autofill_manager_->SubmitForm(form, TimeTicks::Now()); 4208 autofill_manager_->SubmitForm(form, TimeTicks::Now());
3896 histogram_tester.ExpectUniqueSample( 4209 histogram_tester.ExpectUniqueSample(
3897 "Autofill.FormSubmittedState", 4210 "Autofill.FormSubmittedState",
3898 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1); 4211 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA, 1);
3899 EXPECT_EQ(1, user_action_tester.GetActionCount( 4212 EXPECT_EQ(1, user_action_tester.GetActionCount(
3900 "Autofill_FormSubmitted_NonFillable")); 4213 "Autofill_FormSubmitted_NonFillable"));
4214
4215 ASSERT_EQ(1U, ukm_service->entries_count());
4216 ASSERT_EQ(1U, ukm_service->sources_count());
4217 VerifyFormInteractionsUkm(
4218 form, ukm_service,
4219 {{internal::kUKMAutofillFormSubmittedStateName,
4220 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA}});
4221 ukm_service->Purge();
3901 } 4222 }
3902 } 4223 }
3903 4224
3904 // Verify that we correctly log user happiness metrics dealing with form 4225 // Verify that we correctly log user happiness metrics dealing with form
3905 // interaction. 4226 // interaction.
3906 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) { 4227 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) {
4228 EnableUkmLogging();
4229 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
4230
3907 // Load a fillable form. 4231 // Load a fillable form.
3908 FormData form; 4232 FormData form;
3909 form.name = ASCIIToUTF16("TestForm"); 4233 form.name = ASCIIToUTF16("TestForm");
3910 form.origin = GURL("http://example.com/form.html"); 4234 form.origin = GURL("http://example.com/form.html");
3911 form.action = GURL("http://example.com/submit.html"); 4235 form.action = GURL("http://example.com/submit.html");
3912 4236
3913 FormFieldData field; 4237 FormFieldData field;
3914 test::CreateTestFormField("Name", "name", "", "text", &field); 4238 test::CreateTestFormField("Name", "name", "", "text", &field);
3915 form.fields.push_back(field); 4239 form.fields.push_back(field);
3916 test::CreateTestFormField("Email", "email", "", "text", &field); 4240 test::CreateTestFormField("Email", "email", "", "text", &field);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
3996 } 4320 }
3997 4321
3998 // Simulate editing another autofilled field. 4322 // Simulate editing another autofilled field.
3999 { 4323 {
4000 base::HistogramTester histogram_tester; 4324 base::HistogramTester histogram_tester;
4001 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks()); 4325 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks());
4002 histogram_tester.ExpectUniqueSample( 4326 histogram_tester.ExpectUniqueSample(
4003 "Autofill.UserHappiness", 4327 "Autofill.UserHappiness",
4004 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD, 1); 4328 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD, 1);
4005 } 4329 }
4330
4331 autofill_manager_->Reset();
4332
4333 // Verify UKM logs.
4334 VerifyFormInteractionsUkm(
4335 form, ukm_service,
4336 {{internal::kUKMUserHappinessMetricName, AutofillMetrics::FORMS_LOADED},
4337 {internal::kUKMUserHappinessMetricName, AutofillMetrics::USER_DID_TYPE},
4338 {internal::kUKMAddressFormEventName,
4339 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN},
4340 {internal::kUKMAddressFormEventName,
4341 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN},
4342 {internal::kUKMUserHappinessMetricName,
4343 AutofillMetrics::USER_DID_AUTOFILL},
4344 {internal::kUKMAddressFormEventName,
4345 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED},
4346 {internal::kUKMUserHappinessMetricName,
4347 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD},
4348 {internal::kUKMUserHappinessMetricName,
4349 AutofillMetrics::USER_DID_AUTOFILL},
4350 {internal::kUKMUserHappinessMetricName,
4351 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD}});
4006 } 4352 }
4007 4353
4008 // Verify that we correctly log metrics tracking the duration of form fill. 4354 // Verify that we correctly log metrics tracking the duration of form fill.
4009 TEST_F(AutofillMetricsTest, FormFillDuration) { 4355 TEST_F(AutofillMetricsTest, FormFillDuration) {
4010 // Load a fillable form. 4356 // Load a fillable form.
4011 FormData form; 4357 FormData form;
4012 form.name = ASCIIToUTF16("TestForm"); 4358 form.name = ASCIIToUTF16("TestForm");
4013 form.origin = GURL("http://example.com/form.html"); 4359 form.origin = GURL("http://example.com/form.html");
4014 form.action = GURL("http://example.com/submit.html"); 4360 form.action = GURL("http://example.com/submit.html");
4015 4361
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
4573 ["Autofill.FormEvents.CreditCard.OnNonsecurePage"]); 4919 ["Autofill.FormEvents.CreditCard.OnNonsecurePage"]);
4574 } 4920 }
4575 } 4921 }
4576 4922
4577 // Tests that logging CardUploadDecision UKM works as expected. 4923 // Tests that logging CardUploadDecision UKM works as expected.
4578 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric) { 4924 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric) {
4579 EnableUkmLogging(); 4925 EnableUkmLogging();
4580 ukm::UkmServiceTestingHarness ukm_service_test_harness; 4926 ukm::UkmServiceTestingHarness ukm_service_test_harness;
4581 GURL url("https://www.google.com"); 4927 GURL url("https://www.google.com");
4582 int upload_decision = 1; 4928 int upload_decision = 1;
4583 std::map<std::string, int> metrics = { 4929 std::vector<std::pair<const char*, int>> metrics = {
4584 {internal::kUKMCardUploadDecisionMetricName, upload_decision}}; 4930 {internal::kUKMCardUploadDecisionMetricName, upload_decision}};
4585 4931
4586 EXPECT_TRUE(AutofillMetrics::LogUkm( 4932 EXPECT_TRUE(AutofillMetrics::LogUkm(
4587 ukm_service_test_harness.test_ukm_service(), url, 4933 ukm_service_test_harness.test_ukm_service(), url,
4588 internal::kUKMCardUploadDecisionEntryName, metrics)); 4934 internal::kUKMCardUploadDecisionEntryName, metrics));
4589 4935
4590 // Make sure that the UKM was logged correctly. 4936 // Make sure that the UKM was logged correctly.
4591 ukm::TestUkmService* ukm_service = 4937 ukm::TestUkmService* ukm_service =
4592 ukm_service_test_harness.test_ukm_service(); 4938 ukm_service_test_harness.test_ukm_service();
4593 4939
(...skipping 20 matching lines...) Expand all
4614 ASSERT_NE(nullptr, metric); 4960 ASSERT_NE(nullptr, metric);
4615 EXPECT_EQ(upload_decision, metric->value()); 4961 EXPECT_EQ(upload_decision, metric->value());
4616 } 4962 }
4617 4963
4618 // Tests that logging DeveloperEngagement UKM works as expected. 4964 // Tests that logging DeveloperEngagement UKM works as expected.
4619 TEST_F(AutofillMetricsTest, RecordDeveloperEngagementMetric) { 4965 TEST_F(AutofillMetricsTest, RecordDeveloperEngagementMetric) {
4620 EnableUkmLogging(); 4966 EnableUkmLogging();
4621 ukm::UkmServiceTestingHarness ukm_service_test_harness; 4967 ukm::UkmServiceTestingHarness ukm_service_test_harness;
4622 GURL url("https://www.google.com"); 4968 GURL url("https://www.google.com");
4623 int form_structure_metric = 1; 4969 int form_structure_metric = 1;
4624 std::map<std::string, int> metrics = { 4970 std::vector<std::pair<const char*, int>> metrics = {
4625 {internal::kUKMDeveloperEngagementMetricName, form_structure_metric}}; 4971 {internal::kUKMDeveloperEngagementMetricName, form_structure_metric}};
4626 4972
4627 EXPECT_TRUE(AutofillMetrics::LogUkm( 4973 EXPECT_TRUE(AutofillMetrics::LogUkm(
4628 ukm_service_test_harness.test_ukm_service(), url, 4974 ukm_service_test_harness.test_ukm_service(), url,
4629 internal::kUKMDeveloperEngagementEntryName, metrics)); 4975 internal::kUKMDeveloperEngagementEntryName, metrics));
4630 4976
4631 // Make sure that the UKM was logged correctly. 4977 // Make sure that the UKM was logged correctly.
4632 ukm::TestUkmService* ukm_service = 4978 ukm::TestUkmService* ukm_service =
4633 ukm_service_test_harness.test_ukm_service(); 4979 ukm_service_test_harness.test_ukm_service();
4634 4980
(...skipping 19 matching lines...) Expand all
4654 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics()); 5000 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics());
4655 ASSERT_NE(nullptr, metric); 5001 ASSERT_NE(nullptr, metric);
4656 EXPECT_EQ(form_structure_metric, metric->value()); 5002 EXPECT_EQ(form_structure_metric, metric->value());
4657 } 5003 }
4658 5004
4659 // Tests that no UKM is logged when the URL is not valid. 5005 // Tests that no UKM is logged when the URL is not valid.
4660 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_InvalidUrl) { 5006 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_InvalidUrl) {
4661 EnableUkmLogging(); 5007 EnableUkmLogging();
4662 ukm::UkmServiceTestingHarness ukm_service_test_harness; 5008 ukm::UkmServiceTestingHarness ukm_service_test_harness;
4663 GURL url(""); 5009 GURL url("");
4664 std::map<std::string, int> metrics = {{"metric", 1}}; 5010 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}};
4665 5011
4666 EXPECT_FALSE(AutofillMetrics::LogUkm( 5012 EXPECT_FALSE(AutofillMetrics::LogUkm(
4667 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); 5013 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics));
4668 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); 5014 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count());
4669 } 5015 }
4670 5016
4671 // Tests that no UKM is logged when the metrics map is empty. 5017 // Tests that no UKM is logged when the metrics map is empty.
4672 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoMetrics) { 5018 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoMetrics) {
4673 EnableUkmLogging(); 5019 EnableUkmLogging();
4674 ukm::UkmServiceTestingHarness ukm_service_test_harness; 5020 ukm::UkmServiceTestingHarness ukm_service_test_harness;
4675 GURL url("https://www.google.com"); 5021 GURL url("https://www.google.com");
4676 std::map<std::string, int> metrics; 5022 std::vector<std::pair<const char*, int>> metrics;
4677 5023
4678 EXPECT_FALSE(AutofillMetrics::LogUkm( 5024 EXPECT_FALSE(AutofillMetrics::LogUkm(
4679 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); 5025 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics));
4680 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); 5026 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count());
4681 } 5027 }
4682 5028
4683 // Tests that no UKM is logged when the ukm service is null. 5029 // Tests that no UKM is logged when the ukm service is null.
4684 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmService) { 5030 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmService) {
4685 EnableUkmLogging(); 5031 EnableUkmLogging();
4686 ukm::UkmServiceTestingHarness ukm_service_test_harness; 5032 ukm::UkmServiceTestingHarness ukm_service_test_harness;
4687 GURL url("https://www.google.com"); 5033 GURL url("https://www.google.com");
4688 std::map<std::string, int> metrics = {{"metric", 1}}; 5034 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}};
4689 5035
4690 EXPECT_FALSE(AutofillMetrics::LogUkm(nullptr, url, "test_ukm", metrics)); 5036 EXPECT_FALSE(AutofillMetrics::LogUkm(nullptr, url, "test_ukm", metrics));
4691 ASSERT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); 5037 ASSERT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count());
4692 } 5038 }
4693 5039
4694 // Tests that no UKM is logged when the ukm logging feature is disabled. 5040 // Tests that no UKM is logged when the ukm logging feature is disabled.
4695 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_FeatureDisabled) { 5041 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_FeatureDisabled) {
4696 ukm::UkmServiceTestingHarness ukm_service_test_harness; 5042 ukm::UkmServiceTestingHarness ukm_service_test_harness;
4697 GURL url("https://www.google.com"); 5043 GURL url("https://www.google.com");
4698 std::map<std::string, int> metrics = {{"metric", 1}}; 5044 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}};
4699 5045
4700 EXPECT_FALSE(AutofillMetrics::LogUkm( 5046 EXPECT_FALSE(AutofillMetrics::LogUkm(
4701 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); 5047 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics));
4702 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); 5048 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count());
4703 } 5049 }
4704 5050
4705 } // namespace autofill 5051 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698