Chromium Code Reviews| 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 field_type; | |
|
Mathieu
2017/04/12 16:59:45
nit: field_type -> actual_field_type?
Roger McFarlane (Chromium)
2017/04/12 17:10:51
Done.
| |
| 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 field_type = GetParam().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 (field_type == EMPTY_TYPE ? "" : "unknown"), "text", | |
| 596 &field); | |
| 597 field.set_possible_types({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 counte values. | |
|
Mathieu
2017/04/12 16:59:45
*count
Roger McFarlane (Chromium)
2017/04/12 17:10:51
Done.
| |
| 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(field_type, metric), field_type_expected_count); | |
| 640 histogram_tester.ExpectBucketCount( | |
| 641 "Autofill.Quality.ServerType.ByFieldType", | |
| 642 GetFieldTypeGroupMetric(field_type, metric), field_type_expected_count); | |
| 643 histogram_tester.ExpectBucketCount( | |
| 644 "Autofill.Quality.PredictedType.ByFieldType", | |
| 645 GetFieldTypeGroupMetric(field_type, metric), field_type_expected_count); | |
| 646 } | |
| 647 } | |
| 648 | |
| 649 INSTANTIATE_TEST_CASE_P( | |
| 650 AutofillMetricsTest, | |
| 651 UnrecognizedOrEmptyFieldsTest, | |
| 652 testing::Values( | |
| 653 UnrecognizedOrEmptyFieldsCase{EMPTY_TYPE, false, | |
|
Mathieu
2017/04/12 16:59:45
nit: /*make_prediction=*/false
Roger McFarlane (Chromium)
2017/04/12 17:10:51
Done.
| |
| 654 AutofillMetrics::TYPE_MATCH_EMPTY}, | |
| 655 UnrecognizedOrEmptyFieldsCase{UNKNOWN_TYPE, false, | |
| 656 AutofillMetrics::TYPE_MATCH_UNKNOWN}, | |
| 657 UnrecognizedOrEmptyFieldsCase{EMPTY_TYPE, true, | |
| 658 AutofillMetrics::TYPE_MISMATCH_EMPTY}, | |
| 659 UnrecognizedOrEmptyFieldsCase{UNKNOWN_TYPE, true, | |
| 660 AutofillMetrics::TYPE_MISMATCH_UNKNOWN})); | |
| 661 | |
| 546 // Ensures that metrics that measure timing some important Autofill functions | 662 // Ensures that metrics that measure timing some important Autofill functions |
| 547 // actually are recorded and retrieved. | 663 // actually are recorded and retrieved. |
| 548 TEST_F(AutofillMetricsTest, TimingMetrics) { | 664 TEST_F(AutofillMetricsTest, TimingMetrics) { |
| 549 base::HistogramTester histogram_tester; | 665 base::HistogramTester histogram_tester; |
| 550 | 666 |
| 551 FormData form; | 667 FormData form; |
| 552 form.name = ASCIIToUTF16("TestForm"); | 668 form.name = ASCIIToUTF16("TestForm"); |
| 553 form.origin = GURL("http://example.com/form.html"); | 669 form.origin = GURL("http://example.com/form.html"); |
| 554 form.action = GURL("http://example.com/submit.html"); | 670 form.action = GURL("http://example.com/submit.html"); |
| 555 | 671 |
| (...skipping 4140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4696 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 4812 ukm::UkmServiceTestingHarness ukm_service_test_harness; |
| 4697 GURL url("https://www.google.com"); | 4813 GURL url("https://www.google.com"); |
| 4698 std::map<std::string, int> metrics = {{"metric", 1}}; | 4814 std::map<std::string, int> metrics = {{"metric", 1}}; |
| 4699 | 4815 |
| 4700 EXPECT_FALSE(AutofillMetrics::LogUkm( | 4816 EXPECT_FALSE(AutofillMetrics::LogUkm( |
| 4701 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); | 4817 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); |
| 4702 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); | 4818 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); |
| 4703 } | 4819 } |
| 4704 | 4820 |
| 4705 } // namespace autofill | 4821 } // namespace autofill |
| OLD | NEW |