| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/core/browser/autofill_metrics.h" | 5 #include "components/autofill/core/browser/autofill_metrics.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 AutofillMetrics::TYPE_MATCH), | 536 AutofillMetrics::TYPE_MATCH), |
| 537 1); | 537 1); |
| 538 // Mismatch: | 538 // Mismatch: |
| 539 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType", | 539 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType", |
| 540 AutofillMetrics::TYPE_MISMATCH, 1); | 540 AutofillMetrics::TYPE_MISMATCH, 1); |
| 541 histogram_tester.ExpectBucketCount( | 541 histogram_tester.ExpectBucketCount( |
| 542 "Autofill.Quality.PredictedType.ByFieldType", | 542 "Autofill.Quality.PredictedType.ByFieldType", |
| 543 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MISMATCH), 1); | 543 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MISMATCH), 1); |
| 544 } | 544 } |
| 545 | 545 |
| 546 // Tests the true negatives (empty + no prediction and unknown + no prediction) |
| 547 // and false positives (empty + bad prediction and unknown + bad prediction) |
| 548 // are counted correctly. |
| 549 |
| 550 struct UnrecognizedOrEmptyFieldsCase { |
| 551 const ServerFieldType actual_field_type; |
| 552 const bool make_prediction; |
| 553 const AutofillMetrics::FieldTypeQualityMetric metric_to_test; |
| 554 }; |
| 555 |
| 556 class UnrecognizedOrEmptyFieldsTest |
| 557 : public AutofillMetricsTest, |
| 558 public testing::WithParamInterface<UnrecognizedOrEmptyFieldsCase> {}; |
| 559 |
| 560 TEST_P(UnrecognizedOrEmptyFieldsTest, QualityMetrics) { |
| 561 // Setup the test parameters. |
| 562 const ServerFieldType actual_field_type = GetParam().actual_field_type; |
| 563 const ServerFieldType heuristic_type = |
| 564 GetParam().make_prediction ? EMAIL_ADDRESS : UNKNOWN_TYPE; |
| 565 const ServerFieldType server_type = |
| 566 GetParam().make_prediction ? EMAIL_ADDRESS : NO_SERVER_DATA; |
| 567 const AutofillMetrics::FieldTypeQualityMetric metric_to_test = |
| 568 GetParam().metric_to_test; |
| 569 |
| 570 // Set up our form data. |
| 571 FormData form; |
| 572 form.name = ASCIIToUTF16("TestForm"); |
| 573 form.origin = GURL("http://example.com/form.html"); |
| 574 form.action = GURL("http://example.com/submit.html"); |
| 575 |
| 576 std::vector<ServerFieldType> heuristic_types, server_types; |
| 577 AutofillField field; |
| 578 |
| 579 // Add a first name field, that is predicted correctly. |
| 580 test::CreateTestFormField("first", "first", "Elvis", "text", &field); |
| 581 field.set_possible_types({NAME_FIRST}); |
| 582 form.fields.push_back(field); |
| 583 heuristic_types.push_back(NAME_FIRST); |
| 584 server_types.push_back(NAME_FIRST); |
| 585 |
| 586 // Add a last name field, that is predicted correctly. |
| 587 test::CreateTestFormField("last", "last", "Presley", "test", &field); |
| 588 field.set_possible_types({NAME_LAST}); |
| 589 form.fields.push_back(field); |
| 590 heuristic_types.push_back(NAME_LAST); |
| 591 server_types.push_back(NAME_LAST); |
| 592 |
| 593 // Add an empty or unknown field, that is predicted as per the test params. |
| 594 test::CreateTestFormField("Unknown", "Unknown", |
| 595 (actual_field_type == EMPTY_TYPE ? "" : "unknown"), |
| 596 "text", &field); |
| 597 field.set_possible_types({actual_field_type}); |
| 598 form.fields.push_back(field); |
| 599 heuristic_types.push_back(heuristic_type); |
| 600 server_types.push_back(server_type); |
| 601 |
| 602 // Simulate having seen this form on page load. |
| 603 autofill_manager_->AddSeenForm(form, heuristic_types, server_types); |
| 604 |
| 605 // Run the form submission code while tracking the histograms. |
| 606 base::HistogramTester histogram_tester; |
| 607 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
| 608 |
| 609 // Validate the histogram counter values. |
| 610 for (int i = 0; i < AutofillMetrics::NUM_FIELD_TYPE_QUALITY_METRICS; ++i) { |
| 611 // The metric enum value we're currently examining. |
| 612 auto metric = static_cast<AutofillMetrics::FieldTypeQualityMetric>(i); |
| 613 |
| 614 // For the overall metric counts... |
| 615 // If the current metric is the metric we're testing, then we expect its |
| 616 // count to be 1. Otherwise, the metric's count should be zero (0) except |
| 617 // for the TYPE_MATCH metric which should be 2 (because of the matching |
| 618 // first and last name fields) |
| 619 int overall_expected_count = |
| 620 (metric == metric_to_test) |
| 621 ? 1 |
| 622 : ((metric == AutofillMetrics::TYPE_MATCH) ? 2 : 0); |
| 623 |
| 624 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType", metric, |
| 625 overall_expected_count); |
| 626 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType", metric, |
| 627 overall_expected_count); |
| 628 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType", metric, |
| 629 overall_expected_count); |
| 630 |
| 631 // For the ByFieldType metric counts... |
| 632 // We only examine the counter for the field_type being tested. If the |
| 633 // current metric is the metric we're testing, then we expect its |
| 634 // count to be 1 otherwise it should be 0. |
| 635 int field_type_expected_count = (metric == metric_to_test) ? 1 : 0; |
| 636 |
| 637 histogram_tester.ExpectBucketCount( |
| 638 "Autofill.Quality.HeuristicType.ByFieldType", |
| 639 GetFieldTypeGroupMetric(actual_field_type, metric), |
| 640 field_type_expected_count); |
| 641 histogram_tester.ExpectBucketCount( |
| 642 "Autofill.Quality.ServerType.ByFieldType", |
| 643 GetFieldTypeGroupMetric(actual_field_type, metric), |
| 644 field_type_expected_count); |
| 645 histogram_tester.ExpectBucketCount( |
| 646 "Autofill.Quality.PredictedType.ByFieldType", |
| 647 GetFieldTypeGroupMetric(actual_field_type, metric), |
| 648 field_type_expected_count); |
| 649 } |
| 650 } |
| 651 |
| 652 INSTANTIATE_TEST_CASE_P( |
| 653 AutofillMetricsTest, |
| 654 UnrecognizedOrEmptyFieldsTest, |
| 655 testing::Values( |
| 656 UnrecognizedOrEmptyFieldsCase{EMPTY_TYPE, |
| 657 /* make_prediction = */ false, |
| 658 AutofillMetrics::TYPE_MATCH_EMPTY}, |
| 659 UnrecognizedOrEmptyFieldsCase{UNKNOWN_TYPE, |
| 660 /* make_prediction = */ false, |
| 661 AutofillMetrics::TYPE_MATCH_UNKNOWN}, |
| 662 UnrecognizedOrEmptyFieldsCase{EMPTY_TYPE, |
| 663 /* make_prediction = */ true, |
| 664 AutofillMetrics::TYPE_MISMATCH_EMPTY}, |
| 665 UnrecognizedOrEmptyFieldsCase{UNKNOWN_TYPE, |
| 666 /* make_prediction = */ true, |
| 667 AutofillMetrics::TYPE_MISMATCH_UNKNOWN})); |
| 668 |
| 546 // Ensures that metrics that measure timing some important Autofill functions | 669 // Ensures that metrics that measure timing some important Autofill functions |
| 547 // actually are recorded and retrieved. | 670 // actually are recorded and retrieved. |
| 548 TEST_F(AutofillMetricsTest, TimingMetrics) { | 671 TEST_F(AutofillMetricsTest, TimingMetrics) { |
| 549 base::HistogramTester histogram_tester; | 672 base::HistogramTester histogram_tester; |
| 550 | 673 |
| 551 FormData form; | 674 FormData form; |
| 552 form.name = ASCIIToUTF16("TestForm"); | 675 form.name = ASCIIToUTF16("TestForm"); |
| 553 form.origin = GURL("http://example.com/form.html"); | 676 form.origin = GURL("http://example.com/form.html"); |
| 554 form.action = GURL("http://example.com/submit.html"); | 677 form.action = GURL("http://example.com/submit.html"); |
| 555 | 678 |
| (...skipping 4140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4696 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 4819 ukm::UkmServiceTestingHarness ukm_service_test_harness; |
| 4697 GURL url("https://www.google.com"); | 4820 GURL url("https://www.google.com"); |
| 4698 std::map<std::string, int> metrics = {{"metric", 1}}; | 4821 std::map<std::string, int> metrics = {{"metric", 1}}; |
| 4699 | 4822 |
| 4700 EXPECT_FALSE(AutofillMetrics::LogUkm( | 4823 EXPECT_FALSE(AutofillMetrics::LogUkm( |
| 4701 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); | 4824 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); |
| 4702 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); | 4825 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); |
| 4703 } | 4826 } |
| 4704 | 4827 |
| 4705 } // namespace autofill | 4828 } // namespace autofill |
| OLD | NEW |