| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/core/browser/autofill_metrics.h" | 5 #include "components/autofill/core/browser/autofill_metrics.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>( | 182 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>( |
| 183 CreditCard::FULL_SERVER_CARD, "server_id"); | 183 CreditCard::FULL_SERVER_CARD, "server_id"); |
| 184 credit_card->set_guid("10000000-0000-0000-0000-000000000003"); | 184 credit_card->set_guid("10000000-0000-0000-0000-000000000003"); |
| 185 server_credit_cards_.push_back(std::move(credit_card)); | 185 server_credit_cards_.push_back(std::move(credit_card)); |
| 186 } | 186 } |
| 187 Refresh(); | 187 Refresh(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 bool IsAutofillEnabled() const override { return autofill_enabled_; } | 190 bool IsAutofillEnabled() const override { return autofill_enabled_; } |
| 191 | 191 |
| 192 void CreateAmbiguousProfiles() { |
| 193 web_profiles_.clear(); |
| 194 CreateTestAutofillProfiles(&web_profiles_); |
| 195 |
| 196 auto profile = base::MakeUnique<AutofillProfile>(); |
| 197 test::SetProfileInfo(profile.get(), "John", "Decca", "Public", |
| 198 "john@gmail.com", "Company", "123 Main St.", "unit 7", |
| 199 "Springfield", "Texas", "79401", "US", "2345678901"); |
| 200 profile->set_guid("00000000-0000-0000-0000-000000000003"); |
| 201 web_profiles_.push_back(std::move(profile)); |
| 202 Refresh(); |
| 203 } |
| 204 |
| 192 private: | 205 private: |
| 193 void CreateTestAutofillProfiles( | 206 void CreateTestAutofillProfiles( |
| 194 std::vector<std::unique_ptr<AutofillProfile>>* profiles) { | 207 std::vector<std::unique_ptr<AutofillProfile>>* profiles) { |
| 195 std::unique_ptr<AutofillProfile> profile = | 208 std::unique_ptr<AutofillProfile> profile = |
| 196 base::MakeUnique<AutofillProfile>(); | 209 base::MakeUnique<AutofillProfile>(); |
| 197 test::SetProfileInfo(profile.get(), "Elvis", "Aaron", "Presley", | 210 test::SetProfileInfo(profile.get(), "Elvis", "Aaron", "Presley", |
| 198 "theking@gmail.com", "RCA", "3734 Elvis Presley Blvd.", | 211 "theking@gmail.com", "RCA", "3734 Elvis Presley Blvd.", |
| 199 "Apt. 10", "Memphis", "Tennessee", "38116", "US", | 212 "Apt. 10", "Memphis", "Tennessee", "38116", "US", |
| 200 "12345678901"); | 213 "12345678901"); |
| 201 profile->set_guid("00000000-0000-0000-0000-000000000001"); | 214 profile->set_guid("00000000-0000-0000-0000-000000000001"); |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 server_types.push_back(PHONE_HOME_CITY_AND_NUMBER); | 528 server_types.push_back(PHONE_HOME_CITY_AND_NUMBER); |
| 516 | 529 |
| 517 // Simulate having seen this form on page load. | 530 // Simulate having seen this form on page load. |
| 518 autofill_manager_->AddSeenForm(form, heuristic_types, server_types); | 531 autofill_manager_->AddSeenForm(form, heuristic_types, server_types); |
| 519 | 532 |
| 520 // Simulate form submission. | 533 // Simulate form submission. |
| 521 base::HistogramTester histogram_tester; | 534 base::HistogramTester histogram_tester; |
| 522 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 535 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
| 523 | 536 |
| 524 // Heuristic predictions. | 537 // Heuristic predictions. |
| 525 // Unknown: | 538 { |
| 526 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType", | 539 std::string aggregate_histogram = |
| 527 AutofillMetrics::TYPE_UNKNOWN, 1); | 540 "Autofill.FieldPredictionQuality.Aggregate.Heuristic"; |
| 528 histogram_tester.ExpectBucketCount( | 541 std::string by_field_type_histogram = |
| 529 "Autofill.Quality.HeuristicType.ByFieldType", | 542 "Autofill.FieldPredictionQuality.ByFieldType.Heuristic"; |
| 530 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, | 543 |
| 531 AutofillMetrics::TYPE_UNKNOWN), | 544 // Unknown: |
| 532 1); | 545 histogram_tester.ExpectBucketCount( |
| 533 // Match: | 546 aggregate_histogram, AutofillMetrics::FALSE_NEGATIVE_UNKNOWN, 1); |
| 534 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType", | 547 histogram_tester.ExpectBucketCount( |
| 535 AutofillMetrics::TYPE_MATCH, 2); | 548 by_field_type_histogram, |
| 536 histogram_tester.ExpectBucketCount( | 549 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, |
| 537 "Autofill.Quality.HeuristicType.ByFieldType", | 550 AutofillMetrics::FALSE_NEGATIVE_UNKNOWN), |
| 538 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MATCH), 1); | 551 1); |
| 539 histogram_tester.ExpectBucketCount( | 552 // Match: |
| 540 "Autofill.Quality.HeuristicType.ByFieldType", | 553 histogram_tester.ExpectBucketCount(aggregate_histogram, |
| 541 GetFieldTypeGroupMetric(PHONE_HOME_CITY_AND_NUMBER, | 554 AutofillMetrics::TRUE_POSITIVE, 2); |
| 542 AutofillMetrics::TYPE_MATCH), | 555 histogram_tester.ExpectBucketCount( |
| 543 1); | 556 by_field_type_histogram, |
| 544 // Mismatch: | 557 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TRUE_POSITIVE), 1); |
| 545 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType", | 558 histogram_tester.ExpectBucketCount( |
| 546 AutofillMetrics::TYPE_MISMATCH, 1); | 559 by_field_type_histogram, |
| 547 histogram_tester.ExpectBucketCount( | 560 GetFieldTypeGroupMetric(PHONE_HOME_CITY_AND_NUMBER, |
| 548 "Autofill.Quality.HeuristicType.ByFieldType", | 561 AutofillMetrics::TRUE_POSITIVE), |
| 549 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MISMATCH), | 562 1); |
| 550 1); | 563 // Mismatch: |
| 551 | 564 histogram_tester.ExpectBucketCount( |
| 552 // Server predictions: | 565 aggregate_histogram, AutofillMetrics::FALSE_NEGATIVE_MISMATCH, 1); |
| 553 // Unknown: | 566 histogram_tester.ExpectBucketCount( |
| 554 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType", | 567 by_field_type_histogram, |
| 555 AutofillMetrics::TYPE_UNKNOWN, 1); | 568 GetFieldTypeGroupMetric(EMAIL_ADDRESS, |
| 556 histogram_tester.ExpectBucketCount( | 569 AutofillMetrics::FALSE_NEGATIVE_MISMATCH), |
| 557 "Autofill.Quality.ServerType.ByFieldType", | 570 1); |
| 558 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, | 571 histogram_tester.ExpectBucketCount( |
| 559 AutofillMetrics::TYPE_UNKNOWN), | 572 by_field_type_histogram, |
| 560 1); | 573 GetFieldTypeGroupMetric(PHONE_HOME_NUMBER, |
| 561 // Match: | 574 AutofillMetrics::FALSE_POSITIVE_MISMATCH), |
| 562 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType", | 575 1); |
| 563 AutofillMetrics::TYPE_MATCH, 2); | 576 // False Positive Unknown: |
| 564 histogram_tester.ExpectBucketCount( | 577 histogram_tester.ExpectBucketCount( |
| 565 "Autofill.Quality.ServerType.ByFieldType", | 578 aggregate_histogram, AutofillMetrics::FALSE_POSITIVE_UNKNOWN, 1); |
| 566 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MATCH), 1); | 579 histogram_tester.ExpectBucketCount( |
| 567 histogram_tester.ExpectBucketCount( | 580 by_field_type_histogram, |
| 568 "Autofill.Quality.ServerType.ByFieldType", | 581 GetFieldTypeGroupMetric(PHONE_HOME_NUMBER, |
| 569 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER, | 582 AutofillMetrics::FALSE_POSITIVE_UNKNOWN), |
| 570 AutofillMetrics::TYPE_MATCH), | 583 1); |
| 571 1); | 584 // False Positive Empty: |
| 572 // Mismatch: | 585 histogram_tester.ExpectBucketCount( |
| 573 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType", | 586 aggregate_histogram, AutofillMetrics::FALSE_POSITIVE_EMPTY, 1); |
| 574 AutofillMetrics::TYPE_MISMATCH, 1); | 587 histogram_tester.ExpectBucketCount( |
| 575 histogram_tester.ExpectBucketCount( | 588 by_field_type_histogram, |
| 576 "Autofill.Quality.ServerType.ByFieldType", | 589 GetFieldTypeGroupMetric(NAME_FULL, |
| 577 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MISMATCH), 1); | 590 AutofillMetrics::FALSE_POSITIVE_EMPTY), |
| 578 | 591 1); |
| 579 // Overall predictions: | 592 |
| 580 // Unknown: | 593 // Sanity Check: |
| 581 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType", | 594 histogram_tester.ExpectTotalCount(aggregate_histogram, 6); |
| 582 AutofillMetrics::TYPE_UNKNOWN, 1); | 595 histogram_tester.ExpectTotalCount(by_field_type_histogram, 7); |
| 583 histogram_tester.ExpectBucketCount( | 596 } |
| 584 "Autofill.Quality.PredictedType.ByFieldType", | 597 |
| 585 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, | 598 // Server overrides heuristic so Overall and Server are the same predictions |
| 586 AutofillMetrics::TYPE_UNKNOWN), | 599 // (as there were no test fields where server == NO_SERVER_DATA and heuristic |
| 587 1); | 600 // != UNKNOWN_TYPE). |
| 588 // Match: | 601 for (const std::string source : {"Server", "Overall"}) { |
| 589 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType", | 602 std::string aggregate_histogram = |
| 590 AutofillMetrics::TYPE_MATCH, 2); | 603 "Autofill.FieldPredictionQuality.Aggregate." + source; |
| 591 histogram_tester.ExpectBucketCount( | 604 std::string by_field_type_histogram = |
| 592 "Autofill.Quality.PredictedType.ByFieldType", | 605 "Autofill.FieldPredictionQuality.ByFieldType." + source; |
| 593 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MATCH), 1); | 606 |
| 594 histogram_tester.ExpectBucketCount( | 607 // Unknown: |
| 595 "Autofill.Quality.PredictedType.ByFieldType", | 608 histogram_tester.ExpectBucketCount( |
| 596 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER, | 609 aggregate_histogram, AutofillMetrics::FALSE_NEGATIVE_UNKNOWN, 1); |
| 597 AutofillMetrics::TYPE_MATCH), | 610 histogram_tester.ExpectBucketCount( |
| 598 1); | 611 by_field_type_histogram, |
| 599 // Mismatch: | 612 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, |
| 600 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType", | 613 AutofillMetrics::FALSE_NEGATIVE_UNKNOWN), |
| 601 AutofillMetrics::TYPE_MISMATCH, 1); | 614 1); |
| 602 histogram_tester.ExpectBucketCount( | 615 // Match: |
| 603 "Autofill.Quality.PredictedType.ByFieldType", | 616 histogram_tester.ExpectBucketCount(aggregate_histogram, |
| 604 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MISMATCH), 1); | 617 AutofillMetrics::TRUE_POSITIVE, 2); |
| 618 histogram_tester.ExpectBucketCount( |
| 619 by_field_type_histogram, |
| 620 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TRUE_POSITIVE), |
| 621 1); |
| 622 histogram_tester.ExpectBucketCount( |
| 623 by_field_type_histogram, |
| 624 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER, |
| 625 AutofillMetrics::TRUE_POSITIVE), |
| 626 1); |
| 627 // Mismatch: |
| 628 histogram_tester.ExpectBucketCount( |
| 629 aggregate_histogram, AutofillMetrics::FALSE_NEGATIVE_MISMATCH, 1); |
| 630 histogram_tester.ExpectBucketCount( |
| 631 by_field_type_histogram, |
| 632 GetFieldTypeGroupMetric(NAME_FULL, |
| 633 AutofillMetrics::FALSE_NEGATIVE_MISMATCH), |
| 634 1); |
| 635 histogram_tester.ExpectBucketCount( |
| 636 by_field_type_histogram, |
| 637 GetFieldTypeGroupMetric(NAME_FIRST, |
| 638 AutofillMetrics::FALSE_POSITIVE_MISMATCH), |
| 639 1); |
| 640 |
| 641 // False Positive Unknown: |
| 642 histogram_tester.ExpectBucketCount( |
| 643 aggregate_histogram, AutofillMetrics::FALSE_POSITIVE_UNKNOWN, 1); |
| 644 histogram_tester.ExpectBucketCount( |
| 645 by_field_type_histogram, |
| 646 GetFieldTypeGroupMetric(EMAIL_ADDRESS, |
| 647 AutofillMetrics::FALSE_POSITIVE_UNKNOWN), |
| 648 1); |
| 649 // False Positive Empty: |
| 650 histogram_tester.ExpectBucketCount( |
| 651 aggregate_histogram, AutofillMetrics::FALSE_POSITIVE_EMPTY, 1); |
| 652 histogram_tester.ExpectBucketCount( |
| 653 by_field_type_histogram, |
| 654 GetFieldTypeGroupMetric(NAME_FIRST, |
| 655 AutofillMetrics::FALSE_POSITIVE_EMPTY), |
| 656 1); |
| 657 |
| 658 // Sanity Check: |
| 659 histogram_tester.ExpectTotalCount(aggregate_histogram, 6); |
| 660 histogram_tester.ExpectTotalCount(by_field_type_histogram, 7); |
| 661 } |
| 605 } | 662 } |
| 606 | 663 |
| 607 // Tests the true negatives (empty + no prediction and unknown + no prediction) | 664 // Tests the true negatives (empty + no prediction and unknown + no prediction) |
| 608 // and false positives (empty + bad prediction and unknown + bad prediction) | 665 // and false positives (empty + bad prediction and unknown + bad prediction) |
| 609 // are counted correctly. | 666 // are counted correctly. |
| 610 | 667 |
| 611 struct UnrecognizedOrEmptyFieldsCase { | 668 struct QualityMetricsTestCase { |
| 669 const ServerFieldType predicted_field_type; |
| 612 const ServerFieldType actual_field_type; | 670 const ServerFieldType actual_field_type; |
| 613 const bool make_prediction; | |
| 614 const AutofillMetrics::FieldTypeQualityMetric metric_to_test; | |
| 615 }; | 671 }; |
| 616 | 672 |
| 617 class UnrecognizedOrEmptyFieldsTest | 673 class QualityMetricsTest |
| 618 : public AutofillMetricsTest, | 674 : public AutofillMetricsTest, |
| 619 public testing::WithParamInterface<UnrecognizedOrEmptyFieldsCase> {}; | 675 public testing::WithParamInterface<QualityMetricsTestCase> { |
| 620 | 676 public: |
| 621 TEST_P(UnrecognizedOrEmptyFieldsTest, QualityMetrics) { | 677 const char* ValueForType(ServerFieldType type) { |
| 678 switch (type) { |
| 679 case EMPTY_TYPE: |
| 680 return ""; |
| 681 case UNKNOWN_TYPE: |
| 682 return "unknown"; |
| 683 case COMPANY_NAME: |
| 684 return "RCA"; |
| 685 case NAME_FIRST: |
| 686 return "Elvis"; |
| 687 case NAME_MIDDLE: |
| 688 return "Aaron"; |
| 689 case NAME_LAST: |
| 690 return "Presley"; |
| 691 case NAME_FULL: |
| 692 return "Elvis Aaron Presley"; |
| 693 case EMAIL_ADDRESS: |
| 694 return "buddy@gmail.com"; |
| 695 case PHONE_HOME_NUMBER: |
| 696 case PHONE_HOME_WHOLE_NUMBER: |
| 697 case PHONE_HOME_CITY_AND_NUMBER: |
| 698 return "2345678901"; |
| 699 case ADDRESS_HOME_STREET_ADDRESS: |
| 700 return "123 Apple St.\nunit 6"; |
| 701 case ADDRESS_HOME_LINE1: |
| 702 return "123 Apple St."; |
| 703 case ADDRESS_HOME_LINE2: |
| 704 return "unit 6"; |
| 705 case ADDRESS_HOME_CITY: |
| 706 return "Lubbock"; |
| 707 case ADDRESS_HOME_STATE: |
| 708 return "Texas"; |
| 709 case ADDRESS_HOME_ZIP: |
| 710 return "79401"; |
| 711 case ADDRESS_HOME_COUNTRY: |
| 712 return "US"; |
| 713 case AMBIGUOUS_TYPE: |
| 714 // This occurs as both a company name and a middle name once ambiguous |
| 715 // profiles are created. |
| 716 personal_data_->CreateAmbiguousProfiles(); |
| 717 return "Decca"; |
| 718 |
| 719 default: |
| 720 NOTREACHED(); // Fall through |
| 721 return "unexpected!"; |
| 722 } |
| 723 } |
| 724 |
| 725 bool IsExampleOf(AutofillMetrics::FieldTypeQualityMetric metric, |
| 726 ServerFieldType predicted_type, |
| 727 ServerFieldType actual_type) { |
| 728 switch (metric) { |
| 729 case AutofillMetrics::TRUE_POSITIVE: |
| 730 return unknown_equivalent_types_.count(actual_type) == 0 && |
| 731 predicted_type == actual_type; |
| 732 |
| 733 case AutofillMetrics::TRUE_NEGATIVE_AMBIGUOUS: |
| 734 return actual_type == AMBIGUOUS_TYPE && predicted_type == UNKNOWN_TYPE; |
| 735 |
| 736 case AutofillMetrics::TRUE_NEGATIVE_UNKNOWN: |
| 737 return actual_type == UNKNOWN_TYPE && predicted_type == UNKNOWN_TYPE; |
| 738 |
| 739 case AutofillMetrics::TRUE_NEGATIVE_EMPTY: |
| 740 return actual_type == EMPTY_TYPE && predicted_type == UNKNOWN_TYPE; |
| 741 |
| 742 case AutofillMetrics::FALSE_POSITIVE_AMBIGUOUS: |
| 743 return actual_type == AMBIGUOUS_TYPE && predicted_type != UNKNOWN_TYPE; |
| 744 |
| 745 case AutofillMetrics::FALSE_POSITIVE_UNKNOWN: |
| 746 return actual_type == UNKNOWN_TYPE && predicted_type != UNKNOWN_TYPE; |
| 747 |
| 748 case AutofillMetrics::FALSE_POSITIVE_EMPTY: |
| 749 return actual_type == EMPTY_TYPE && predicted_type != UNKNOWN_TYPE; |
| 750 |
| 751 // False negative mismatch and false positive mismatch trigger on the same |
| 752 // conditions: |
| 753 // - False positive prediction of predicted type |
| 754 // - False negative prediction of actual type |
| 755 case AutofillMetrics::FALSE_POSITIVE_MISMATCH: |
| 756 case AutofillMetrics::FALSE_NEGATIVE_MISMATCH: |
| 757 return unknown_equivalent_types_.count(actual_type) == 0 && |
| 758 actual_type != predicted_type && predicted_type != UNKNOWN_TYPE; |
| 759 |
| 760 case AutofillMetrics::FALSE_NEGATIVE_UNKNOWN: |
| 761 return unknown_equivalent_types_.count(actual_type) == 0 && |
| 762 actual_type != predicted_type && predicted_type == UNKNOWN_TYPE; |
| 763 |
| 764 default: |
| 765 NOTREACHED(); |
| 766 } |
| 767 return false; |
| 768 } |
| 769 |
| 770 static int FieldTypeCross(ServerFieldType predicted_type, |
| 771 ServerFieldType actual_type) { |
| 772 EXPECT_LE(predicted_type, UINT16_MAX); |
| 773 EXPECT_LE(actual_type, UINT16_MAX); |
| 774 return (predicted_type << 16) | actual_type; |
| 775 } |
| 776 |
| 777 const ServerFieldTypeSet unknown_equivalent_types_{UNKNOWN_TYPE, EMPTY_TYPE, |
| 778 AMBIGUOUS_TYPE}; |
| 779 }; |
| 780 |
| 781 TEST_P(QualityMetricsTest, Classification) { |
| 782 const std::vector<std::string> prediction_sources{"Heuristic", "Server", |
| 783 "Overall"}; |
| 622 // Setup the test parameters. | 784 // Setup the test parameters. |
| 623 const ServerFieldType actual_field_type = GetParam().actual_field_type; | 785 ServerFieldType actual_field_type = GetParam().actual_field_type; |
| 624 const ServerFieldType heuristic_type = | 786 ServerFieldType predicted_type = GetParam().predicted_field_type; |
| 625 GetParam().make_prediction ? EMAIL_ADDRESS : UNKNOWN_TYPE; | 787 |
| 626 const ServerFieldType server_type = | 788 VLOG(2) << "Test Case = Predicted: " |
| 627 GetParam().make_prediction ? EMAIL_ADDRESS : NO_SERVER_DATA; | 789 << AutofillType(predicted_type).ToString() << "; " |
| 628 const AutofillMetrics::FieldTypeQualityMetric metric_to_test = | 790 << "Actual: " << AutofillType(actual_field_type).ToString(); |
| 629 GetParam().metric_to_test; | |
| 630 | 791 |
| 631 // Set up our form data. | 792 // Set up our form data. |
| 632 FormData form; | 793 FormData form; |
| 633 form.name = ASCIIToUTF16("TestForm"); | 794 form.name = ASCIIToUTF16("TestForm"); |
| 634 form.origin = GURL("http://example.com/form.html"); | 795 form.origin = GURL("http://example.com/form.html"); |
| 635 form.action = GURL("http://example.com/submit.html"); | 796 form.action = GURL("http://example.com/submit.html"); |
| 636 | 797 |
| 637 std::vector<ServerFieldType> heuristic_types, server_types; | 798 std::vector<ServerFieldType> heuristic_types, server_types; |
| 638 AutofillField field; | 799 AutofillField field; |
| 639 | 800 |
| 640 // Add a first name field, that is predicted correctly. | 801 // Add a first name field, that is predicted correctly. |
| 641 test::CreateTestFormField("first", "first", "Elvis", "text", &field); | 802 test::CreateTestFormField("first", "first", ValueForType(NAME_FIRST), "text", |
| 642 field.set_possible_types({NAME_FIRST}); | 803 &field); |
| 643 form.fields.push_back(field); | 804 form.fields.push_back(field); |
| 644 heuristic_types.push_back(NAME_FIRST); | 805 heuristic_types.push_back(NAME_FIRST); |
| 645 server_types.push_back(NAME_FIRST); | 806 server_types.push_back(NAME_FIRST); |
| 646 | 807 |
| 647 // Add a last name field, that is predicted correctly. | 808 // Add a last name field, that is predicted correctly. |
| 648 test::CreateTestFormField("last", "last", "Presley", "test", &field); | 809 test::CreateTestFormField("last", "last", ValueForType(NAME_LAST), "test", |
| 649 field.set_possible_types({NAME_LAST}); | 810 &field); |
| 650 form.fields.push_back(field); | 811 form.fields.push_back(field); |
| 651 heuristic_types.push_back(NAME_LAST); | 812 heuristic_types.push_back(NAME_LAST); |
| 652 server_types.push_back(NAME_LAST); | 813 server_types.push_back(NAME_LAST); |
| 653 | 814 |
| 654 // Add an empty or unknown field, that is predicted as per the test params. | 815 // Add an empty or unknown field, that is predicted as per the test params. |
| 655 test::CreateTestFormField("Unknown", "Unknown", | 816 test::CreateTestFormField("Unknown", "Unknown", |
| 656 (actual_field_type == EMPTY_TYPE ? "" : "unknown"), | 817 ValueForType(actual_field_type), "text", &field); |
| 657 "text", &field); | |
| 658 field.set_possible_types({actual_field_type}); | |
| 659 form.fields.push_back(field); | 818 form.fields.push_back(field); |
| 660 heuristic_types.push_back(heuristic_type); | 819 heuristic_types.push_back(predicted_type); |
| 661 server_types.push_back(server_type); | 820 server_types.push_back(predicted_type == UNKNOWN_TYPE ? NO_SERVER_DATA |
| 821 : predicted_type); |
| 662 | 822 |
| 663 // Simulate having seen this form on page load. | 823 // Simulate having seen this form on page load. |
| 664 autofill_manager_->AddSeenForm(form, heuristic_types, server_types); | 824 autofill_manager_->AddSeenForm(form, heuristic_types, server_types); |
| 665 | 825 |
| 666 // Run the form submission code while tracking the histograms. | 826 // Run the form submission code while tracking the histograms. |
| 667 base::HistogramTester histogram_tester; | 827 base::HistogramTester histogram_tester; |
| 668 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 828 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
| 669 | 829 |
| 670 // Validate the histogram counter values. | 830 // Resolve any field type ambiguity. |
| 831 if (actual_field_type == AMBIGUOUS_TYPE) { |
| 832 if (predicted_type == COMPANY_NAME || predicted_type == NAME_MIDDLE) |
| 833 actual_field_type = predicted_type; |
| 834 } |
| 835 |
| 836 // Validate the total samples and the crossed (predicted-to-actual) samples. |
| 837 for (const auto& source : prediction_sources) { |
| 838 const std::string crossed_histogram = "Autofill.FieldPrediction." + source; |
| 839 const std::string aggregate_histogram = |
| 840 "Autofill.FieldPredictionQuality.Aggregate." + source; |
| 841 const std::string by_field_type_histogram = |
| 842 "Autofill.FieldPredictionQuality.ByFieldType." + source; |
| 843 |
| 844 // Sanity Check: |
| 845 histogram_tester.ExpectTotalCount(crossed_histogram, 3); |
| 846 histogram_tester.ExpectTotalCount(aggregate_histogram, 3); |
| 847 histogram_tester.ExpectTotalCount( |
| 848 by_field_type_histogram, |
| 849 2 + |
| 850 (predicted_type != UNKNOWN_TYPE && |
| 851 predicted_type != actual_field_type) + |
| 852 (unknown_equivalent_types_.count(actual_field_type) == 0)); |
| 853 |
| 854 // The Crossed Histogram: |
| 855 histogram_tester.ExpectBucketCount( |
| 856 crossed_histogram, FieldTypeCross(NAME_FIRST, NAME_FIRST), 1); |
| 857 histogram_tester.ExpectBucketCount(crossed_histogram, |
| 858 FieldTypeCross(NAME_LAST, NAME_LAST), 1); |
| 859 histogram_tester.ExpectBucketCount( |
| 860 crossed_histogram, |
| 861 FieldTypeCross((source == "Server" && predicted_type == UNKNOWN_TYPE |
| 862 ? NO_SERVER_DATA |
| 863 : predicted_type), |
| 864 actual_field_type), |
| 865 1); |
| 866 } |
| 867 |
| 868 // Validate the individual histogram counter values. |
| 671 for (int i = 0; i < AutofillMetrics::NUM_FIELD_TYPE_QUALITY_METRICS; ++i) { | 869 for (int i = 0; i < AutofillMetrics::NUM_FIELD_TYPE_QUALITY_METRICS; ++i) { |
| 672 // The metric enum value we're currently examining. | 870 // The metric enum value we're currently examining. |
| 673 auto metric = static_cast<AutofillMetrics::FieldTypeQualityMetric>(i); | 871 auto metric = static_cast<AutofillMetrics::FieldTypeQualityMetric>(i); |
| 674 | 872 |
| 675 // For the overall metric counts... | 873 // The type specific expected count is 1 if (predicted, actual) is an |
| 676 // If the current metric is the metric we're testing, then we expect its | 874 // example |
| 677 // count to be 1. Otherwise, the metric's count should be zero (0) except | 875 int basic_expected_count = |
| 678 // for the TYPE_MATCH metric which should be 2 (because of the matching | 876 IsExampleOf(metric, predicted_type, actual_field_type) ? 1 : 0; |
| 679 // first and last name fields) | |
| 680 int overall_expected_count = | |
| 681 (metric == metric_to_test) | |
| 682 ? 1 | |
| 683 : ((metric == AutofillMetrics::TYPE_MATCH) ? 2 : 0); | |
| 684 | 877 |
| 685 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType", metric, | 878 // For aggregate metrics don't capture aggregate FALSE_POSITIVE_MISMATCH. |
| 686 overall_expected_count); | 879 // Note there are two true positive values (first and last name) hard- |
| 687 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType", metric, | 880 // coded into the test. |
| 688 overall_expected_count); | 881 int aggregate_expected_count = |
| 689 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType", metric, | 882 (metric == AutofillMetrics::TRUE_POSITIVE ? 2 : 0) + |
| 690 overall_expected_count); | 883 (metric == AutofillMetrics::FALSE_POSITIVE_MISMATCH |
| 884 ? 0 |
| 885 : basic_expected_count); |
| 691 | 886 |
| 692 // For the ByFieldType metric counts... | 887 // If this test exercises the ambiguous middle name match, then validation |
| 693 // We only examine the counter for the field_type being tested. If the | 888 // of the name-specific metrics must include the true-positives created by |
| 694 // current metric is the metric we're testing, then we expect its | 889 // the first and last name fields. |
| 695 // count to be 1 otherwise it should be 0. | 890 if (metric == AutofillMetrics::TRUE_POSITIVE && |
| 696 int field_type_expected_count = (metric == metric_to_test) ? 1 : 0; | 891 predicted_type == NAME_MIDDLE && actual_field_type == NAME_MIDDLE) { |
| 892 basic_expected_count += 2; |
| 893 } |
| 697 | 894 |
| 698 histogram_tester.ExpectBucketCount( | 895 // For metrics keyed to the actual field type, we don't capture unknown, |
| 699 "Autofill.Quality.HeuristicType.ByFieldType", | 896 // empty or ambiguous and we don't capture false positive mismatches. |
| 700 GetFieldTypeGroupMetric(actual_field_type, metric), | 897 int expected_count_for_actual_type = |
| 701 field_type_expected_count); | 898 (unknown_equivalent_types_.count(actual_field_type) == 0 && |
| 702 histogram_tester.ExpectBucketCount( | 899 metric != AutofillMetrics::FALSE_POSITIVE_MISMATCH) |
| 703 "Autofill.Quality.ServerType.ByFieldType", | 900 ? basic_expected_count |
| 704 GetFieldTypeGroupMetric(actual_field_type, metric), | 901 : 0; |
| 705 field_type_expected_count); | 902 |
| 706 histogram_tester.ExpectBucketCount( | 903 // For metrics keyed to the predicted field type, we don't capture unknown |
| 707 "Autofill.Quality.PredictedType.ByFieldType", | 904 // (empty is not a predictable value) and we don't capture false negative |
| 708 GetFieldTypeGroupMetric(actual_field_type, metric), | 905 // mismatches. |
| 709 field_type_expected_count); | 906 int expected_count_for_predicted_type = |
| 907 (predicted_type != UNKNOWN_TYPE && |
| 908 metric != AutofillMetrics::FALSE_NEGATIVE_MISMATCH) |
| 909 ? basic_expected_count |
| 910 : 0; |
| 911 |
| 912 for (const auto& source : prediction_sources) { |
| 913 std::string aggregate_histogram = |
| 914 "Autofill.FieldPredictionQuality.Aggregate." + source; |
| 915 std::string by_field_type_histogram = |
| 916 "Autofill.FieldPredictionQuality.ByFieldType." + source; |
| 917 histogram_tester.ExpectBucketCount(aggregate_histogram, metric, |
| 918 aggregate_expected_count); |
| 919 histogram_tester.ExpectBucketCount( |
| 920 by_field_type_histogram, |
| 921 GetFieldTypeGroupMetric(actual_field_type, metric), |
| 922 expected_count_for_actual_type); |
| 923 histogram_tester.ExpectBucketCount( |
| 924 by_field_type_histogram, |
| 925 GetFieldTypeGroupMetric(predicted_type, metric), |
| 926 expected_count_for_predicted_type); |
| 927 } |
| 710 } | 928 } |
| 711 } | 929 } |
| 712 | 930 |
| 713 INSTANTIATE_TEST_CASE_P( | 931 INSTANTIATE_TEST_CASE_P( |
| 714 AutofillMetricsTest, | 932 AutofillMetricsTest, |
| 715 UnrecognizedOrEmptyFieldsTest, | 933 QualityMetricsTest, |
| 716 testing::Values( | 934 testing::Values(QualityMetricsTestCase{UNKNOWN_TYPE, EMPTY_TYPE}, |
| 717 UnrecognizedOrEmptyFieldsCase{EMPTY_TYPE, | 935 QualityMetricsTestCase{UNKNOWN_TYPE, UNKNOWN_TYPE}, |
| 718 /* make_prediction = */ false, | 936 QualityMetricsTestCase{UNKNOWN_TYPE, AMBIGUOUS_TYPE}, |
| 719 AutofillMetrics::TYPE_MATCH_EMPTY}, | 937 QualityMetricsTestCase{UNKNOWN_TYPE, EMAIL_ADDRESS}, |
| 720 UnrecognizedOrEmptyFieldsCase{UNKNOWN_TYPE, | 938 QualityMetricsTestCase{EMAIL_ADDRESS, EMPTY_TYPE}, |
| 721 /* make_prediction = */ false, | 939 QualityMetricsTestCase{EMAIL_ADDRESS, UNKNOWN_TYPE}, |
| 722 AutofillMetrics::TYPE_MATCH_UNKNOWN}, | 940 QualityMetricsTestCase{EMAIL_ADDRESS, AMBIGUOUS_TYPE}, |
| 723 UnrecognizedOrEmptyFieldsCase{EMPTY_TYPE, | 941 QualityMetricsTestCase{EMAIL_ADDRESS, EMAIL_ADDRESS}, |
| 724 /* make_prediction = */ true, | 942 QualityMetricsTestCase{EMAIL_ADDRESS, COMPANY_NAME}, |
| 725 AutofillMetrics::TYPE_MISMATCH_EMPTY}, | 943 QualityMetricsTestCase{COMPANY_NAME, EMAIL_ADDRESS}, |
| 726 UnrecognizedOrEmptyFieldsCase{UNKNOWN_TYPE, | 944 QualityMetricsTestCase{NAME_MIDDLE, AMBIGUOUS_TYPE}, |
| 727 /* make_prediction = */ true, | 945 QualityMetricsTestCase{COMPANY_NAME, AMBIGUOUS_TYPE})); |
| 728 AutofillMetrics::TYPE_MISMATCH_UNKNOWN})); | |
| 729 | 946 |
| 730 // Ensures that metrics that measure timing some important Autofill functions | 947 // Ensures that metrics that measure timing some important Autofill functions |
| 731 // actually are recorded and retrieved. | 948 // actually are recorded and retrieved. |
| 732 TEST_F(AutofillMetricsTest, TimingMetrics) { | 949 TEST_F(AutofillMetricsTest, TimingMetrics) { |
| 733 base::HistogramTester histogram_tester; | 950 base::HistogramTester histogram_tester; |
| 734 | 951 |
| 735 FormData form; | 952 FormData form; |
| 736 form.name = ASCIIToUTF16("TestForm"); | 953 form.name = ASCIIToUTF16("TestForm"); |
| 737 form.origin = GURL("http://example.com/form.html"); | 954 form.origin = GURL("http://example.com/form.html"); |
| 738 form.action = GURL("http://example.com/submit.html"); | 955 form.action = GURL("http://example.com/submit.html"); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 autofill_manager_->OnTextFieldDidChange(form, form.fields[0], TimeTicks()); | 1041 autofill_manager_->OnTextFieldDidChange(form, form.fields[0], TimeTicks()); |
| 825 | 1042 |
| 826 // Trigger a form upload and metrics by Resetting the manager. | 1043 // Trigger a form upload and metrics by Resetting the manager. |
| 827 base::HistogramTester histogram_tester; | 1044 base::HistogramTester histogram_tester; |
| 828 | 1045 |
| 829 autofill_manager_->ResetRunLoop(); | 1046 autofill_manager_->ResetRunLoop(); |
| 830 autofill_manager_->Reset(); | 1047 autofill_manager_->Reset(); |
| 831 autofill_manager_->RunRunLoop(); | 1048 autofill_manager_->RunRunLoop(); |
| 832 | 1049 |
| 833 // Heuristic predictions. | 1050 // Heuristic predictions. |
| 834 // Unknown: | 1051 { |
| 835 histogram_tester.ExpectBucketCount( | 1052 std::string aggregate_histogram = |
| 836 "Autofill.Quality.HeuristicType.NoSubmission", | 1053 "Autofill.FieldPredictionQuality.Aggregate.Heuristic.NoSubmission"; |
| 837 AutofillMetrics::TYPE_UNKNOWN, 1); | 1054 std::string by_field_type_histogram = |
| 838 histogram_tester.ExpectBucketCount( | 1055 "Autofill.FieldPredictionQuality.ByFieldType.Heuristic.NoSubmission"; |
| 839 "Autofill.Quality.HeuristicType.ByFieldType.NoSubmission", | 1056 // False Negative: |
| 840 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, | 1057 histogram_tester.ExpectBucketCount( |
| 841 AutofillMetrics::TYPE_UNKNOWN), | 1058 aggregate_histogram, AutofillMetrics::FALSE_NEGATIVE_UNKNOWN, 1); |
| 842 1); | 1059 histogram_tester.ExpectBucketCount( |
| 843 // Match: | 1060 by_field_type_histogram, |
| 844 histogram_tester.ExpectBucketCount( | 1061 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, |
| 845 "Autofill.Quality.HeuristicType.NoSubmission", | 1062 AutofillMetrics::FALSE_NEGATIVE_UNKNOWN), |
| 846 AutofillMetrics::TYPE_MATCH, 2); | 1063 1); |
| 847 histogram_tester.ExpectBucketCount( | 1064 // Match: |
| 848 "Autofill.Quality.HeuristicType.ByFieldType.NoSubmission", | 1065 histogram_tester.ExpectBucketCount(aggregate_histogram, |
| 849 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MATCH), 1); | 1066 AutofillMetrics::TRUE_POSITIVE, 2); |
| 850 histogram_tester.ExpectBucketCount( | 1067 histogram_tester.ExpectBucketCount( |
| 851 "Autofill.Quality.HeuristicType.ByFieldType.NoSubmission", | 1068 by_field_type_histogram, |
| 852 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER, | 1069 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TRUE_POSITIVE), 1); |
| 853 AutofillMetrics::TYPE_MATCH), | 1070 histogram_tester.ExpectBucketCount( |
| 854 1); | 1071 by_field_type_histogram, |
| 855 // Mismatch: | 1072 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER, |
| 856 histogram_tester.ExpectBucketCount( | 1073 AutofillMetrics::TRUE_POSITIVE), |
| 857 "Autofill.Quality.HeuristicType.NoSubmission", | 1074 1); |
| 858 AutofillMetrics::TYPE_MISMATCH, 1); | 1075 // Mismatch: |
| 859 histogram_tester.ExpectBucketCount( | 1076 histogram_tester.ExpectBucketCount( |
| 860 "Autofill.Quality.HeuristicType.ByFieldType.NoSubmission", | 1077 aggregate_histogram, AutofillMetrics::FALSE_NEGATIVE_MISMATCH, 1); |
| 861 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MISMATCH), | 1078 histogram_tester.ExpectBucketCount( |
| 862 1); | 1079 by_field_type_histogram, |
| 1080 GetFieldTypeGroupMetric(EMAIL_ADDRESS, |
| 1081 AutofillMetrics::FALSE_NEGATIVE_MISMATCH), |
| 1082 1); |
| 1083 histogram_tester.ExpectBucketCount( |
| 1084 by_field_type_histogram, |
| 1085 GetFieldTypeGroupMetric(PHONE_HOME_NUMBER, |
| 1086 AutofillMetrics::FALSE_POSITIVE_MISMATCH), |
| 1087 1); |
| 1088 // False Positives: |
| 1089 histogram_tester.ExpectBucketCount( |
| 1090 aggregate_histogram, AutofillMetrics::FALSE_POSITIVE_EMPTY, 1); |
| 1091 histogram_tester.ExpectBucketCount( |
| 1092 by_field_type_histogram, |
| 1093 GetFieldTypeGroupMetric(NAME_FULL, |
| 1094 AutofillMetrics::FALSE_POSITIVE_EMPTY), |
| 1095 1); |
| 1096 histogram_tester.ExpectBucketCount( |
| 1097 aggregate_histogram, AutofillMetrics::FALSE_POSITIVE_UNKNOWN, 1); |
| 1098 histogram_tester.ExpectBucketCount( |
| 1099 by_field_type_histogram, |
| 1100 GetFieldTypeGroupMetric(PHONE_HOME_NUMBER, |
| 1101 AutofillMetrics::FALSE_POSITIVE_UNKNOWN), |
| 1102 1); |
| 863 | 1103 |
| 864 // Server predictions: | 1104 // Sanity Check: |
| 865 // Unknown: | 1105 histogram_tester.ExpectTotalCount(aggregate_histogram, 6); |
| 866 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType.NoSubmission", | 1106 histogram_tester.ExpectTotalCount(by_field_type_histogram, 7); |
| 867 AutofillMetrics::TYPE_UNKNOWN, 1); | 1107 } |
| 868 histogram_tester.ExpectBucketCount( | |
| 869 "Autofill.Quality.ServerType.ByFieldType.NoSubmission", | |
| 870 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, | |
| 871 AutofillMetrics::TYPE_UNKNOWN), | |
| 872 1); | |
| 873 // Match: | |
| 874 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType.NoSubmission", | |
| 875 AutofillMetrics::TYPE_MATCH, 2); | |
| 876 histogram_tester.ExpectBucketCount( | |
| 877 "Autofill.Quality.ServerType.ByFieldType.NoSubmission", | |
| 878 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MATCH), 1); | |
| 879 histogram_tester.ExpectBucketCount( | |
| 880 "Autofill.Quality.ServerType.ByFieldType.NoSubmission", | |
| 881 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER, | |
| 882 AutofillMetrics::TYPE_MATCH), | |
| 883 1); | |
| 884 // Mismatch: | |
| 885 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType.NoSubmission", | |
| 886 AutofillMetrics::TYPE_MISMATCH, 1); | |
| 887 histogram_tester.ExpectBucketCount( | |
| 888 "Autofill.Quality.ServerType.ByFieldType.NoSubmission", | |
| 889 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MISMATCH), 1); | |
| 890 | 1108 |
| 891 // Overall predictions: | 1109 // Server predictions override heuristics, so server and overall will be the |
| 892 // Unknown: | 1110 // same. |
| 893 histogram_tester.ExpectBucketCount( | 1111 for (const std::string source : {"Server", "Overall"}) { |
| 894 "Autofill.Quality.PredictedType.NoSubmission", | 1112 std::string aggregate_histogram = |
| 895 AutofillMetrics::TYPE_UNKNOWN, 1); | 1113 "Autofill.FieldPredictionQuality.Aggregate." + source + ".NoSubmission"; |
| 896 histogram_tester.ExpectBucketCount( | 1114 std::string by_field_type_histogram = |
| 897 "Autofill.Quality.PredictedType.ByFieldType.NoSubmission", | 1115 "Autofill.FieldPredictionQuality.ByFieldType." + source + |
| 898 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, | 1116 ".NoSubmission"; |
| 899 AutofillMetrics::TYPE_UNKNOWN), | 1117 |
| 900 1); | 1118 // Unknown. |
| 901 // Match: | 1119 histogram_tester.ExpectBucketCount( |
| 902 histogram_tester.ExpectBucketCount( | 1120 aggregate_histogram, AutofillMetrics::FALSE_NEGATIVE_UNKNOWN, 1); |
| 903 "Autofill.Quality.PredictedType.NoSubmission", | 1121 histogram_tester.ExpectBucketCount( |
| 904 AutofillMetrics::TYPE_MATCH, 2); | 1122 by_field_type_histogram, |
| 905 histogram_tester.ExpectBucketCount( | 1123 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, |
| 906 "Autofill.Quality.PredictedType.ByFieldType.NoSubmission", | 1124 AutofillMetrics::FALSE_NEGATIVE_UNKNOWN), |
| 907 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MATCH), 1); | 1125 1); |
| 908 histogram_tester.ExpectBucketCount( | 1126 // Match: |
| 909 "Autofill.Quality.PredictedType.ByFieldType.NoSubmission", | 1127 histogram_tester.ExpectBucketCount(aggregate_histogram, |
| 910 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER, | 1128 AutofillMetrics::TRUE_POSITIVE, 2); |
| 911 AutofillMetrics::TYPE_MATCH), | 1129 histogram_tester.ExpectBucketCount( |
| 912 1); | 1130 by_field_type_histogram, |
| 913 // Mismatch: | 1131 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TRUE_POSITIVE), |
| 914 histogram_tester.ExpectBucketCount( | 1132 1); |
| 915 "Autofill.Quality.PredictedType.NoSubmission", | 1133 histogram_tester.ExpectBucketCount( |
| 916 AutofillMetrics::TYPE_MISMATCH, 1); | 1134 by_field_type_histogram, |
| 917 histogram_tester.ExpectBucketCount( | 1135 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER, |
| 918 "Autofill.Quality.PredictedType.ByFieldType.NoSubmission", | 1136 AutofillMetrics::TRUE_POSITIVE), |
| 919 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MISMATCH), 1); | 1137 1); |
| 1138 // Mismatch: |
| 1139 histogram_tester.ExpectBucketCount( |
| 1140 aggregate_histogram, AutofillMetrics::FALSE_NEGATIVE_MISMATCH, 1); |
| 1141 histogram_tester.ExpectBucketCount( |
| 1142 by_field_type_histogram, |
| 1143 GetFieldTypeGroupMetric(NAME_FULL, |
| 1144 AutofillMetrics::FALSE_NEGATIVE_MISMATCH), |
| 1145 1); |
| 1146 histogram_tester.ExpectBucketCount( |
| 1147 by_field_type_histogram, |
| 1148 GetFieldTypeGroupMetric(NAME_FIRST, |
| 1149 AutofillMetrics::FALSE_POSITIVE_MISMATCH), |
| 1150 1); |
| 1151 |
| 1152 // False Positives: |
| 1153 histogram_tester.ExpectBucketCount( |
| 1154 aggregate_histogram, AutofillMetrics::FALSE_POSITIVE_EMPTY, 1); |
| 1155 histogram_tester.ExpectBucketCount( |
| 1156 by_field_type_histogram, |
| 1157 GetFieldTypeGroupMetric(NAME_FIRST, |
| 1158 AutofillMetrics::FALSE_POSITIVE_EMPTY), |
| 1159 1); |
| 1160 histogram_tester.ExpectBucketCount( |
| 1161 aggregate_histogram, AutofillMetrics::FALSE_POSITIVE_UNKNOWN, 1); |
| 1162 histogram_tester.ExpectBucketCount( |
| 1163 by_field_type_histogram, |
| 1164 GetFieldTypeGroupMetric(EMAIL_ADDRESS, |
| 1165 AutofillMetrics::FALSE_POSITIVE_UNKNOWN), |
| 1166 1); |
| 1167 |
| 1168 // Sanity Check: |
| 1169 histogram_tester.ExpectTotalCount(aggregate_histogram, 6); |
| 1170 histogram_tester.ExpectTotalCount(by_field_type_histogram, 7); |
| 1171 } |
| 920 } | 1172 } |
| 921 | 1173 |
| 922 // Test that we log quality metrics for heuristics and server predictions based | 1174 // Test that we log quality metrics for heuristics and server predictions based |
| 923 // on autocomplete attributes present on the fields. | 1175 // on autocomplete attributes present on the fields. |
| 924 TEST_F(AutofillMetricsTest, QualityMetrics_BasedOnAutocomplete) { | 1176 TEST_F(AutofillMetricsTest, QualityMetrics_BasedOnAutocomplete) { |
| 925 FormData form; | 1177 FormData form; |
| 926 form.name = ASCIIToUTF16("MyForm"); | 1178 form.name = ASCIIToUTF16("MyForm"); |
| 927 form.origin = GURL("http://myform.com/form.html"); | 1179 form.origin = GURL("http://myform.com/form.html"); |
| 928 form.action = GURL("http://myform.com/submit.html"); | 1180 form.action = GURL("http://myform.com/submit.html"); |
| 929 | 1181 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse", | 1232 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse", |
| 981 AutofillMetrics::QUERY_RESPONSE_PARSED, 1); | 1233 AutofillMetrics::QUERY_RESPONSE_PARSED, 1); |
| 982 | 1234 |
| 983 // Autocomplete-derived types are eventually what's inferred. | 1235 // Autocomplete-derived types are eventually what's inferred. |
| 984 EXPECT_EQ(NAME_LAST, form_structure_ptr->field(0)->Type().GetStorableType()); | 1236 EXPECT_EQ(NAME_LAST, form_structure_ptr->field(0)->Type().GetStorableType()); |
| 985 EXPECT_EQ(NAME_MIDDLE, | 1237 EXPECT_EQ(NAME_MIDDLE, |
| 986 form_structure_ptr->field(1)->Type().GetStorableType()); | 1238 form_structure_ptr->field(1)->Type().GetStorableType()); |
| 987 EXPECT_EQ(ADDRESS_HOME_ZIP, | 1239 EXPECT_EQ(ADDRESS_HOME_ZIP, |
| 988 form_structure_ptr->field(2)->Type().GetStorableType()); | 1240 form_structure_ptr->field(2)->Type().GetStorableType()); |
| 989 | 1241 |
| 990 // Heuristic predictions. | 1242 for (const std::string source : {"Heuristic", "Server"}) { |
| 991 // Unknown: | 1243 std::string aggregate_histogram = |
| 992 histogram_tester.ExpectBucketCount( | 1244 "Autofill.FieldPredictionQuality.Aggregate." + source + |
| 993 "Autofill.Quality.HeuristicType.BasedOnAutocomplete", | 1245 ".BasedOnAutocomplete"; |
| 994 AutofillMetrics::TYPE_UNKNOWN, 1); | 1246 std::string by_field_type_histogram = |
| 995 histogram_tester.ExpectBucketCount( | 1247 "Autofill.FieldPredictionQuality.ByFieldType." + source + |
| 996 "Autofill.Quality.HeuristicType.ByFieldType.BasedOnAutocomplete", | 1248 ".BasedOnAutocomplete"; |
| 997 GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP, AutofillMetrics::TYPE_UNKNOWN), | |
| 998 1); | |
| 999 // Match: | |
| 1000 histogram_tester.ExpectBucketCount( | |
| 1001 "Autofill.Quality.HeuristicType.BasedOnAutocomplete", | |
| 1002 AutofillMetrics::TYPE_MATCH, 1); | |
| 1003 histogram_tester.ExpectBucketCount( | |
| 1004 "Autofill.Quality.HeuristicType.ByFieldType.BasedOnAutocomplete", | |
| 1005 GetFieldTypeGroupMetric(NAME_LAST, AutofillMetrics::TYPE_MATCH), 1); | |
| 1006 // Mismatch: | |
| 1007 histogram_tester.ExpectBucketCount( | |
| 1008 "Autofill.Quality.HeuristicType.BasedOnAutocomplete", | |
| 1009 AutofillMetrics::TYPE_MISMATCH, 1); | |
| 1010 histogram_tester.ExpectBucketCount( | |
| 1011 "Autofill.Quality.HeuristicType.ByFieldType.BasedOnAutocomplete", | |
| 1012 GetFieldTypeGroupMetric(NAME_MIDDLE, AutofillMetrics::TYPE_MISMATCH), 1); | |
| 1013 | 1249 |
| 1014 // Server predictions. | 1250 // Unknown: |
| 1015 // Unknown: | 1251 histogram_tester.ExpectBucketCount( |
| 1016 histogram_tester.ExpectBucketCount( | 1252 aggregate_histogram, AutofillMetrics::FALSE_NEGATIVE_UNKNOWN, 1); |
| 1017 "Autofill.Quality.ServerType.BasedOnAutocomplete", | 1253 histogram_tester.ExpectBucketCount( |
| 1018 AutofillMetrics::TYPE_UNKNOWN, 1); | 1254 by_field_type_histogram, |
| 1019 histogram_tester.ExpectBucketCount( | 1255 GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP, |
| 1020 "Autofill.Quality.ServerType.ByFieldType.BasedOnAutocomplete", | 1256 AutofillMetrics::FALSE_NEGATIVE_UNKNOWN), |
| 1021 GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP, AutofillMetrics::TYPE_UNKNOWN), | 1257 1); |
| 1022 1); | 1258 // Match: |
| 1023 // Match: | 1259 histogram_tester.ExpectBucketCount(aggregate_histogram, |
| 1024 histogram_tester.ExpectBucketCount( | 1260 AutofillMetrics::TRUE_POSITIVE, 1); |
| 1025 "Autofill.Quality.ServerType.BasedOnAutocomplete", | 1261 histogram_tester.ExpectBucketCount( |
| 1026 AutofillMetrics::TYPE_MATCH, 1); | 1262 by_field_type_histogram, |
| 1027 histogram_tester.ExpectBucketCount( | 1263 GetFieldTypeGroupMetric(NAME_LAST, AutofillMetrics::TRUE_POSITIVE), 1); |
| 1028 "Autofill.Quality.ServerType.ByFieldType.BasedOnAutocomplete", | 1264 // Mismatch: |
| 1029 GetFieldTypeGroupMetric(NAME_LAST, AutofillMetrics::TYPE_MATCH), 1); | 1265 histogram_tester.ExpectBucketCount( |
| 1030 // Mismatch: | 1266 aggregate_histogram, AutofillMetrics::FALSE_NEGATIVE_MISMATCH, 1); |
| 1031 histogram_tester.ExpectBucketCount( | 1267 histogram_tester.ExpectBucketCount( |
| 1032 "Autofill.Quality.ServerType.BasedOnAutocomplete", | 1268 by_field_type_histogram, |
| 1033 AutofillMetrics::TYPE_MISMATCH, 1); | 1269 GetFieldTypeGroupMetric(NAME_FIRST, |
| 1034 histogram_tester.ExpectBucketCount( | 1270 AutofillMetrics::FALSE_POSITIVE_MISMATCH), |
| 1035 "Autofill.Quality.ServerType.ByFieldType.BasedOnAutocomplete", | 1271 1); |
| 1036 GetFieldTypeGroupMetric(NAME_MIDDLE, AutofillMetrics::TYPE_MISMATCH), 1); | 1272 histogram_tester.ExpectBucketCount( |
| 1273 by_field_type_histogram, |
| 1274 GetFieldTypeGroupMetric(NAME_MIDDLE, |
| 1275 AutofillMetrics::FALSE_POSITIVE_MISMATCH), |
| 1276 1); |
| 1277 |
| 1278 // Sanity check. |
| 1279 histogram_tester.ExpectTotalCount(aggregate_histogram, 3); |
| 1280 histogram_tester.ExpectTotalCount(by_field_type_histogram, 4); |
| 1281 } |
| 1037 } | 1282 } |
| 1038 | 1283 |
| 1039 // Test that we log UPI Virtual Payment Address. | 1284 // Test that we log UPI Virtual Payment Address. |
| 1040 TEST_F(AutofillMetricsTest, UpiVirtualPaymentAddress) { | 1285 TEST_F(AutofillMetricsTest, UpiVirtualPaymentAddress) { |
| 1041 // Set up our form data. | 1286 // Set up our form data. |
| 1042 FormData form; | 1287 FormData form; |
| 1043 form.name = ASCIIToUTF16("TestForm"); | 1288 form.name = ASCIIToUTF16("TestForm"); |
| 1044 form.origin = GURL("http://example.com/form.html"); | 1289 form.origin = GURL("http://example.com/form.html"); |
| 1045 form.action = GURL("http://example.com/submit.html"); | 1290 form.action = GURL("http://example.com/submit.html"); |
| 1046 | 1291 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1070 autofill_manager_->AddSeenForm(form, heuristic_types, server_types); | 1315 autofill_manager_->AddSeenForm(form, heuristic_types, server_types); |
| 1071 | 1316 |
| 1072 // Simulate form submission. | 1317 // Simulate form submission. |
| 1073 base::HistogramTester histogram_tester; | 1318 base::HistogramTester histogram_tester; |
| 1074 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 1319 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
| 1075 | 1320 |
| 1076 histogram_tester.ExpectBucketCount( | 1321 histogram_tester.ExpectBucketCount( |
| 1077 "Autofill.UserHappiness", AutofillMetrics::USER_DID_ENTER_UPI_VPA, 1); | 1322 "Autofill.UserHappiness", AutofillMetrics::USER_DID_ENTER_UPI_VPA, 1); |
| 1078 } | 1323 } |
| 1079 | 1324 |
| 1080 // Test that we do not log RAPPOR metrics when the number of mismatches is not | |
| 1081 // high enough. | |
| 1082 TEST_F(AutofillMetricsTest, Rappor_LowMismatchRate_NoMetricsReported) { | |
| 1083 // Set up our form data. | |
| 1084 FormData form; | |
| 1085 form.name = ASCIIToUTF16("TestForm"); | |
| 1086 form.origin = GURL("http://example.com/form.html"); | |
| 1087 form.action = GURL("http://example.com/submit.html"); | |
| 1088 | |
| 1089 std::vector<ServerFieldType> heuristic_types, server_types; | |
| 1090 FormFieldData field; | |
| 1091 | |
| 1092 test::CreateTestFormField("Autofilled", "autofilled", "Elvis Aaron Presley", | |
| 1093 "text", &field); | |
| 1094 field.is_autofilled = true; | |
| 1095 form.fields.push_back(field); | |
| 1096 heuristic_types.push_back(NAME_FULL); | |
| 1097 server_types.push_back(NAME_FULL); | |
| 1098 | |
| 1099 test::CreateTestFormField("Autofill Failed", "autofillfailed", | |
| 1100 "buddy@gmail.com", "text", &field); | |
| 1101 field.is_autofilled = false; | |
| 1102 form.fields.push_back(field); | |
| 1103 heuristic_types.push_back(EMAIL_ADDRESS); | |
| 1104 server_types.push_back(NAME_LAST); | |
| 1105 | |
| 1106 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field); | |
| 1107 field.is_autofilled = true; | |
| 1108 form.fields.push_back(field); | |
| 1109 heuristic_types.push_back(PHONE_HOME_CITY_AND_NUMBER); | |
| 1110 server_types.push_back(EMAIL_ADDRESS); | |
| 1111 | |
| 1112 // Simulate having seen this form on page load. | |
| 1113 autofill_manager_->AddSeenForm(form, heuristic_types, server_types); | |
| 1114 | |
| 1115 // Simulate form submission. | |
| 1116 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | |
| 1117 | |
| 1118 // The number of mismatches did not trigger the RAPPOR metric logging. | |
| 1119 EXPECT_EQ(0, autofill_client_.test_rappor_service()->GetReportsCount()); | |
| 1120 } | |
| 1121 | |
| 1122 // Test that we don't log RAPPOR metrics in the case heuristics and/or server | |
| 1123 // have no data. | |
| 1124 TEST_F(AutofillMetricsTest, Rappor_NoDataServerAndHeuristic_NoMetricsReported) { | |
| 1125 // Set up our form data. | |
| 1126 FormData form; | |
| 1127 form.name = ASCIIToUTF16("TestForm"); | |
| 1128 form.origin = GURL("http://example.com/form.html"); | |
| 1129 form.action = GURL("http://example.com/submit.html"); | |
| 1130 | |
| 1131 std::vector<ServerFieldType> heuristic_types, server_types; | |
| 1132 FormFieldData field; | |
| 1133 | |
| 1134 test::CreateTestFormField("Autofilled", "autofilled", "Elvis Aaron Presley", | |
| 1135 "text", &field); | |
| 1136 field.is_autofilled = true; | |
| 1137 form.fields.push_back(field); | |
| 1138 heuristic_types.push_back(UNKNOWN_TYPE); | |
| 1139 server_types.push_back(NO_SERVER_DATA); | |
| 1140 | |
| 1141 test::CreateTestFormField("Autofill Failed", "autofillfailed", | |
| 1142 "buddy@gmail.com", "text", &field); | |
| 1143 field.is_autofilled = false; | |
| 1144 form.fields.push_back(field); | |
| 1145 heuristic_types.push_back(UNKNOWN_TYPE); | |
| 1146 server_types.push_back(NO_SERVER_DATA); | |
| 1147 | |
| 1148 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field); | |
| 1149 field.is_autofilled = true; | |
| 1150 form.fields.push_back(field); | |
| 1151 heuristic_types.push_back(UNKNOWN_TYPE); | |
| 1152 server_types.push_back(NO_SERVER_DATA); | |
| 1153 | |
| 1154 // Simulate having seen this form on page load. | |
| 1155 autofill_manager_->AddSeenForm(form, heuristic_types, server_types); | |
| 1156 | |
| 1157 // Simulate form submission. | |
| 1158 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | |
| 1159 | |
| 1160 // No RAPPOR metrics are logged in the case of multiple UNKNOWN_TYPE and | |
| 1161 // NO_SERVER_DATA for heuristics and server predictions, respectively. | |
| 1162 EXPECT_EQ(0, autofill_client_.test_rappor_service()->GetReportsCount()); | |
| 1163 } | |
| 1164 | |
| 1165 // Test that we log high number of mismatches for the server prediction. | |
| 1166 TEST_F(AutofillMetricsTest, Rappor_HighServerMismatchRate_MetricsReported) { | |
| 1167 // Set up our form data. | |
| 1168 FormData form; | |
| 1169 form.name = ASCIIToUTF16("TestForm"); | |
| 1170 form.origin = GURL("http://example.com/form.html"); | |
| 1171 form.action = GURL("http://example.com/submit.html"); | |
| 1172 | |
| 1173 std::vector<ServerFieldType> heuristic_types, server_types; | |
| 1174 FormFieldData field; | |
| 1175 | |
| 1176 test::CreateTestFormField("Autofilled", "autofilled", "Elvis Aaron Presley", | |
| 1177 "text", &field); | |
| 1178 field.is_autofilled = true; | |
| 1179 form.fields.push_back(field); | |
| 1180 heuristic_types.push_back(NAME_FULL); | |
| 1181 server_types.push_back(NAME_FIRST); | |
| 1182 | |
| 1183 test::CreateTestFormField("Autofill Failed", "autofillfailed", | |
| 1184 "buddy@gmail.com", "text", &field); | |
| 1185 field.is_autofilled = false; | |
| 1186 form.fields.push_back(field); | |
| 1187 heuristic_types.push_back(PHONE_HOME_NUMBER); | |
| 1188 server_types.push_back(NAME_LAST); | |
| 1189 | |
| 1190 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field); | |
| 1191 field.is_autofilled = true; | |
| 1192 form.fields.push_back(field); | |
| 1193 heuristic_types.push_back(PHONE_HOME_CITY_AND_NUMBER); | |
| 1194 server_types.push_back(EMAIL_ADDRESS); | |
| 1195 | |
| 1196 // Simulate having seen this form on page load. | |
| 1197 autofill_manager_->AddSeenForm(form, heuristic_types, server_types); | |
| 1198 | |
| 1199 // Simulate form submission. | |
| 1200 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | |
| 1201 | |
| 1202 // The number of mismatches did trigger the RAPPOR metric logging for server | |
| 1203 // predictions. | |
| 1204 EXPECT_EQ(1, autofill_client_.test_rappor_service()->GetReportsCount()); | |
| 1205 std::string sample; | |
| 1206 rappor::RapporType type; | |
| 1207 EXPECT_FALSE( | |
| 1208 autofill_client_.test_rappor_service()->GetRecordedSampleForMetric( | |
| 1209 "Autofill.HighNumberOfHeuristicMismatches", &sample, &type)); | |
| 1210 EXPECT_TRUE( | |
| 1211 autofill_client_.test_rappor_service()->GetRecordedSampleForMetric( | |
| 1212 "Autofill.HighNumberOfServerMismatches", &sample, &type)); | |
| 1213 EXPECT_EQ("example.com", sample); | |
| 1214 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | |
| 1215 } | |
| 1216 | |
| 1217 // Test that we log high number of mismatches for the heuristic predictions. | |
| 1218 TEST_F(AutofillMetricsTest, Rappor_HighHeuristicMismatchRate_MetricsReported) { | |
| 1219 // Set up our form data. | |
| 1220 FormData form; | |
| 1221 form.name = ASCIIToUTF16("TestForm"); | |
| 1222 form.origin = GURL("http://example.com/form.html"); | |
| 1223 form.action = GURL("http://example.com/submit.html"); | |
| 1224 | |
| 1225 std::vector<ServerFieldType> heuristic_types, server_types; | |
| 1226 FormFieldData field; | |
| 1227 | |
| 1228 test::CreateTestFormField("Autofilled", "autofilled", "Elvis Aaron Presley", | |
| 1229 "text", &field); | |
| 1230 field.is_autofilled = true; | |
| 1231 form.fields.push_back(field); | |
| 1232 heuristic_types.push_back(NAME_FIRST); | |
| 1233 server_types.push_back(NAME_FULL); | |
| 1234 | |
| 1235 test::CreateTestFormField("Autofill Failed", "autofillfailed", | |
| 1236 "buddy@gmail.com", "text", &field); | |
| 1237 field.is_autofilled = false; | |
| 1238 form.fields.push_back(field); | |
| 1239 heuristic_types.push_back(PHONE_HOME_NUMBER); | |
| 1240 server_types.push_back(NAME_LAST); | |
| 1241 | |
| 1242 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field); | |
| 1243 field.is_autofilled = true; | |
| 1244 form.fields.push_back(field); | |
| 1245 heuristic_types.push_back(EMAIL_ADDRESS); | |
| 1246 server_types.push_back(PHONE_HOME_WHOLE_NUMBER); | |
| 1247 | |
| 1248 // Simulate having seen this form on page load. | |
| 1249 autofill_manager_->AddSeenForm(form, heuristic_types, server_types); | |
| 1250 | |
| 1251 // Simulate form submission. | |
| 1252 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | |
| 1253 | |
| 1254 // The number of mismatches did trigger the RAPPOR metric logging for | |
| 1255 // heuristic predictions. | |
| 1256 EXPECT_EQ(1, autofill_client_.test_rappor_service()->GetReportsCount()); | |
| 1257 std::string sample; | |
| 1258 rappor::RapporType type; | |
| 1259 EXPECT_FALSE( | |
| 1260 autofill_client_.test_rappor_service()->GetRecordedSampleForMetric( | |
| 1261 "Autofill.HighNumberOfServerMismatches", &sample, &type)); | |
| 1262 EXPECT_TRUE( | |
| 1263 autofill_client_.test_rappor_service()->GetRecordedSampleForMetric( | |
| 1264 "Autofill.HighNumberOfHeuristicMismatches", &sample, &type)); | |
| 1265 EXPECT_EQ("example.com", sample); | |
| 1266 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | |
| 1267 } | |
| 1268 | |
| 1269 // Verify that when a field is annotated with the autocomplete attribute, its | 1325 // Verify that when a field is annotated with the autocomplete attribute, its |
| 1270 // predicted type is remembered when quality metrics are logged. | 1326 // predicted type is remembered when quality metrics are logged. |
| 1271 TEST_F(AutofillMetricsTest, PredictedMetricsWithAutocomplete) { | 1327 TEST_F(AutofillMetricsTest, PredictedMetricsWithAutocomplete) { |
| 1272 // Set up our form data. | 1328 // Set up our form data. |
| 1273 FormData form; | 1329 FormData form; |
| 1274 form.name = ASCIIToUTF16("TestForm"); | 1330 form.name = ASCIIToUTF16("TestForm"); |
| 1275 form.origin = GURL("http://example.com/form.html"); | 1331 form.origin = GURL("http://example.com/form.html"); |
| 1276 form.action = GURL("http://example.com/submit.html"); | 1332 form.action = GURL("http://example.com/submit.html"); |
| 1277 | 1333 |
| 1278 FormFieldData field1; | 1334 FormFieldData field1; |
| 1279 test::CreateTestFormField("Select", "select", "USA", "select-one", &field1); | 1335 test::CreateTestFormField("Select", "select", "USA", "select-one", &field1); |
| 1280 field1.autocomplete_attribute = "country"; | 1336 field1.autocomplete_attribute = "country"; |
| 1281 form.fields.push_back(field1); | 1337 form.fields.push_back(field1); |
| 1282 | 1338 |
| 1283 // Two other fields to have the minimum of 3 to be parsed by autofill. Note | 1339 // Two other fields to have the minimum of 3 to be parsed by autofill. Note |
| 1284 // that they have default values not found in the user profiles. They will be | 1340 // that they have default values not found in the user profiles. They will be |
| 1285 // changed between the time the form is seen/parsed, and the time it is | 1341 // changed between the time the form is seen/parsed, and the time it is |
| 1286 // submitted. | 1342 // submitted. |
| 1287 FormFieldData field2; | 1343 FormFieldData field2; |
| 1288 test::CreateTestFormField("Unknown", "Unknown", "", "text", &field2); | 1344 test::CreateTestFormField("Unknown", "Unknown", "", "text", &field2); |
| 1289 form.fields.push_back(field2); | 1345 form.fields.push_back(field2); |
| 1290 FormFieldData field3; | 1346 FormFieldData field3; |
| 1291 test::CreateTestFormField("Phone", "phone", "", "tel", &field3); | 1347 test::CreateTestFormField("Phone", "phone", "", "tel", &field3); |
| 1292 form.fields.push_back(field3); | 1348 form.fields.push_back(field3); |
| 1293 | 1349 |
| 1294 std::vector<FormData> forms(1, form); | 1350 std::vector<FormData> forms(1, form); |
| 1295 | 1351 |
| 1296 { | 1352 base::HistogramTester histogram_tester; |
| 1297 base::HistogramTester histogram_tester; | 1353 autofill_manager_->OnFormsSeen(forms, TimeTicks()); |
| 1298 autofill_manager_->OnFormsSeen(forms, TimeTicks()); | |
| 1299 // We change the value of the text fields to change the default/seen values | |
| 1300 // (hence the values are not cleared in UpdateFromCache). The new values | |
| 1301 // match what is in the test profile. | |
| 1302 form.fields[1].value = base::ASCIIToUTF16("79401"); | |
| 1303 form.fields[2].value = base::ASCIIToUTF16("2345678901"); | |
| 1304 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | |
| 1305 | 1354 |
| 1355 // We change the value of the text fields to change the default/seen values |
| 1356 // (hence the values are not cleared in UpdateFromCache). The new values |
| 1357 // match what is in the test profile. |
| 1358 form.fields[1].value = base::ASCIIToUTF16("79401"); |
| 1359 form.fields[2].value = base::ASCIIToUTF16("2345678901"); |
| 1360 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
| 1361 |
| 1362 for (const std::string source : {"Heuristic", "Server", "Overall"}) { |
| 1363 std::string histogram_name = |
| 1364 "Autofill.FieldPredictionQuality.ByFieldType." + source; |
| 1306 // First verify that country was not predicted by client or server. | 1365 // First verify that country was not predicted by client or server. |
| 1307 histogram_tester.ExpectBucketCount( | 1366 histogram_tester.ExpectBucketCount( |
| 1308 "Autofill.Quality.ServerType.ByFieldType", | 1367 histogram_name, |
| 1309 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, | 1368 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, |
| 1310 AutofillMetrics::TYPE_UNKNOWN), | 1369 source == "Overall" |
| 1311 1); | 1370 ? AutofillMetrics::TRUE_POSITIVE |
| 1312 histogram_tester.ExpectBucketCount( | 1371 : AutofillMetrics::FALSE_NEGATIVE_UNKNOWN), |
| 1313 "Autofill.Quality.HeuristicType.ByFieldType", | |
| 1314 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, | |
| 1315 AutofillMetrics::TYPE_UNKNOWN), | |
| 1316 1); | |
| 1317 // We expect a match for country because it had |autocomplete_attribute|. | |
| 1318 histogram_tester.ExpectBucketCount( | |
| 1319 "Autofill.Quality.PredictedType.ByFieldType", | |
| 1320 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, | |
| 1321 AutofillMetrics::TYPE_MATCH), | |
| 1322 1); | 1372 1); |
| 1323 | 1373 |
| 1324 // We did not predict zip code or phone number, because they did not have | 1374 // We did not predict zip code or phone number, because they did not have |
| 1325 // |autocomplete_attribute|, nor client or server predictions. | 1375 // |autocomplete_attribute|, nor client or server predictions. |
| 1326 histogram_tester.ExpectBucketCount( | 1376 histogram_tester.ExpectBucketCount( |
| 1327 "Autofill.Quality.ServerType.ByFieldType", | 1377 histogram_name, |
| 1328 GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP, | 1378 GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP, |
| 1329 AutofillMetrics::TYPE_UNKNOWN), | 1379 AutofillMetrics::FALSE_NEGATIVE_UNKNOWN), |
| 1330 1); | 1380 1); |
| 1331 histogram_tester.ExpectBucketCount( | 1381 histogram_tester.ExpectBucketCount( |
| 1332 "Autofill.Quality.HeuristicType.ByFieldType", | 1382 histogram_name, |
| 1333 GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP, | |
| 1334 AutofillMetrics::TYPE_UNKNOWN), | |
| 1335 1); | |
| 1336 histogram_tester.ExpectBucketCount( | |
| 1337 "Autofill.Quality.PredictedType.ByFieldType", | |
| 1338 GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP, | |
| 1339 AutofillMetrics::TYPE_UNKNOWN), | |
| 1340 1); | |
| 1341 histogram_tester.ExpectBucketCount( | |
| 1342 "Autofill.Quality.ServerType.ByFieldType", | |
| 1343 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER, | 1383 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER, |
| 1344 AutofillMetrics::TYPE_UNKNOWN), | 1384 AutofillMetrics::FALSE_NEGATIVE_UNKNOWN), |
| 1345 1); | |
| 1346 histogram_tester.ExpectBucketCount( | |
| 1347 "Autofill.Quality.HeuristicType.ByFieldType", | |
| 1348 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER, | |
| 1349 AutofillMetrics::TYPE_UNKNOWN), | |
| 1350 1); | |
| 1351 histogram_tester.ExpectBucketCount( | |
| 1352 "Autofill.Quality.PredictedType.ByFieldType", | |
| 1353 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER, | |
| 1354 AutofillMetrics::TYPE_UNKNOWN), | |
| 1355 1); | 1385 1); |
| 1356 | 1386 |
| 1357 // Sanity check. | 1387 // Sanity check. |
| 1358 histogram_tester.ExpectTotalCount("Autofill.Quality.PredictedType", 3); | 1388 histogram_tester.ExpectTotalCount(histogram_name, 3); |
| 1359 } | 1389 } |
| 1360 } | 1390 } |
| 1361 | 1391 |
| 1362 // Test that we behave sanely when the cached form differs from the submitted | 1392 // Test that we behave sanely when the cached form differs from the submitted |
| 1363 // one. | 1393 // one. |
| 1364 TEST_F(AutofillMetricsTest, SaneMetricsWithCacheMismatch) { | 1394 TEST_F(AutofillMetricsTest, SaneMetricsWithCacheMismatch) { |
| 1365 // Set up our form data. | 1395 // Set up our form data. |
| 1366 FormData form; | 1396 FormData form; |
| 1367 form.name = ASCIIToUTF16("TestForm"); | 1397 form.name = ASCIIToUTF16("TestForm"); |
| 1368 form.origin = GURL("http://example.com/form.html"); | 1398 form.origin = GURL("http://example.com/form.html"); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1408 form.fields.push_back(field); | 1438 form.fields.push_back(field); |
| 1409 form.fields.push_back(cached_fields[2]); | 1439 form.fields.push_back(cached_fields[2]); |
| 1410 form.fields.push_back(cached_fields[1]); | 1440 form.fields.push_back(cached_fields[1]); |
| 1411 form.fields.push_back(cached_fields[3]); | 1441 form.fields.push_back(cached_fields[3]); |
| 1412 form.fields.push_back(cached_fields[0]); | 1442 form.fields.push_back(cached_fields[0]); |
| 1413 | 1443 |
| 1414 // Simulate form submission. | 1444 // Simulate form submission. |
| 1415 base::HistogramTester histogram_tester; | 1445 base::HistogramTester histogram_tester; |
| 1416 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | 1446 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
| 1417 | 1447 |
| 1418 // Heuristic predictions. | 1448 for (const std::string source : {"Heuristic", "Server", "Overall"}) { |
| 1419 // Unknown: | 1449 std::string aggregate_histogram = |
| 1420 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType", | 1450 "Autofill.FieldPredictionQuality.Aggregate." + source; |
| 1421 AutofillMetrics::TYPE_UNKNOWN, 1); | 1451 std::string by_field_type_histogram = |
| 1422 histogram_tester.ExpectBucketCount( | 1452 "Autofill.FieldPredictionQuality.ByFieldType." + source; |
| 1423 "Autofill.Quality.HeuristicType.ByFieldType", | |
| 1424 GetFieldTypeGroupMetric(ADDRESS_HOME_STATE, | |
| 1425 AutofillMetrics::TYPE_UNKNOWN), | |
| 1426 1); | |
| 1427 // Match: | |
| 1428 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType", | |
| 1429 AutofillMetrics::TYPE_MATCH, 2); | |
| 1430 histogram_tester.ExpectBucketCount( | |
| 1431 "Autofill.Quality.HeuristicType.ByFieldType", | |
| 1432 GetFieldTypeGroupMetric(ADDRESS_HOME_CITY, AutofillMetrics::TYPE_MATCH), | |
| 1433 1); | |
| 1434 histogram_tester.ExpectBucketCount( | |
| 1435 "Autofill.Quality.HeuristicType.ByFieldType", | |
| 1436 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MATCH), 1); | |
| 1437 // Mismatch: | |
| 1438 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType", | |
| 1439 AutofillMetrics::TYPE_MISMATCH, 1); | |
| 1440 histogram_tester.ExpectBucketCount( | |
| 1441 "Autofill.Quality.HeuristicType.ByFieldType", | |
| 1442 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MISMATCH), | |
| 1443 1); | |
| 1444 | 1453 |
| 1445 // Server predictions: | 1454 // Unknown: |
| 1446 // Unknown: | 1455 histogram_tester.ExpectBucketCount( |
| 1447 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType", | 1456 aggregate_histogram, AutofillMetrics::FALSE_NEGATIVE_UNKNOWN, 1); |
| 1448 AutofillMetrics::TYPE_UNKNOWN, 1); | 1457 histogram_tester.ExpectBucketCount( |
| 1449 histogram_tester.ExpectBucketCount( | 1458 by_field_type_histogram, |
| 1450 "Autofill.Quality.ServerType.ByFieldType", | 1459 GetFieldTypeGroupMetric(ADDRESS_HOME_STATE, |
| 1451 GetFieldTypeGroupMetric(ADDRESS_HOME_STATE, | 1460 AutofillMetrics::FALSE_NEGATIVE_UNKNOWN), |
| 1452 AutofillMetrics::TYPE_UNKNOWN), | 1461 1); |
| 1453 1); | 1462 // Match: |
| 1454 // Match: | 1463 histogram_tester.ExpectBucketCount(aggregate_histogram, |
| 1455 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType", | 1464 AutofillMetrics::TRUE_POSITIVE, |
| 1456 AutofillMetrics::TYPE_MATCH, 1); | 1465 source == "Heuristic" ? 2 : 1); |
| 1457 histogram_tester.ExpectBucketCount( | 1466 histogram_tester.ExpectBucketCount( |
| 1458 "Autofill.Quality.ServerType.ByFieldType", | 1467 by_field_type_histogram, |
| 1459 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MATCH), 1); | 1468 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TRUE_POSITIVE), 1); |
| 1460 // Mismatch: | 1469 // Mismatch: |
| 1461 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType", | 1470 histogram_tester.ExpectBucketCount(aggregate_histogram, |
| 1462 AutofillMetrics::TYPE_MISMATCH, 2); | 1471 AutofillMetrics::FALSE_NEGATIVE_MISMATCH, |
| 1463 histogram_tester.ExpectBucketCount( | 1472 source == "Heuristic" ? 1 : 2); |
| 1464 "Autofill.Quality.ServerType.ByFieldType", | 1473 histogram_tester.ExpectBucketCount( |
| 1465 GetFieldTypeGroupMetric(ADDRESS_HOME_CITY, | 1474 by_field_type_histogram, |
| 1466 AutofillMetrics::TYPE_MISMATCH), | 1475 GetFieldTypeGroupMetric(EMAIL_ADDRESS, |
| 1467 1); | 1476 AutofillMetrics::FALSE_NEGATIVE_MISMATCH), |
| 1468 histogram_tester.ExpectBucketCount( | 1477 1); |
| 1469 "Autofill.Quality.ServerType.ByFieldType", | 1478 // Source dependent: |
| 1470 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MISMATCH), | 1479 histogram_tester.ExpectBucketCount( |
| 1471 1); | 1480 by_field_type_histogram, |
| 1472 | 1481 GetFieldTypeGroupMetric(ADDRESS_HOME_CITY, |
| 1473 // Overall predictions: | 1482 source == "Heuristic" |
| 1474 // Unknown: | 1483 ? AutofillMetrics::TRUE_POSITIVE |
| 1475 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType", | 1484 : AutofillMetrics::FALSE_NEGATIVE_MISMATCH), |
| 1476 AutofillMetrics::TYPE_UNKNOWN, 1); | 1485 1); |
| 1477 histogram_tester.ExpectBucketCount( | 1486 } |
| 1478 "Autofill.Quality.PredictedType.ByFieldType", | |
| 1479 GetFieldTypeGroupMetric(ADDRESS_HOME_STATE, | |
| 1480 AutofillMetrics::TYPE_UNKNOWN), | |
| 1481 1); | |
| 1482 // Match: | |
| 1483 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType", | |
| 1484 AutofillMetrics::TYPE_MATCH, 1); | |
| 1485 histogram_tester.ExpectBucketCount( | |
| 1486 "Autofill.Quality.PredictedType.ByFieldType", | |
| 1487 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MATCH), 1); | |
| 1488 // Mismatch: | |
| 1489 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType", | |
| 1490 AutofillMetrics::TYPE_MISMATCH, 2); | |
| 1491 histogram_tester.ExpectBucketCount( | |
| 1492 "Autofill.Quality.PredictedType.ByFieldType", | |
| 1493 GetFieldTypeGroupMetric(ADDRESS_HOME_CITY, | |
| 1494 AutofillMetrics::TYPE_MISMATCH), | |
| 1495 1); | |
| 1496 histogram_tester.ExpectBucketCount( | |
| 1497 "Autofill.Quality.PredictedType.ByFieldType", | |
| 1498 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MISMATCH), | |
| 1499 1); | |
| 1500 } | 1487 } |
| 1501 | 1488 |
| 1502 // Verify that when submitting an autofillable form, the stored profile metric | 1489 // Verify that when submitting an autofillable form, the stored profile metric |
| 1503 // is logged. | 1490 // is logged. |
| 1504 TEST_F(AutofillMetricsTest, StoredProfileCountAutofillableFormSubmission) { | 1491 TEST_F(AutofillMetricsTest, StoredProfileCountAutofillableFormSubmission) { |
| 1505 // Construct a fillable form. | 1492 // Construct a fillable form. |
| 1506 FormData form; | 1493 FormData form; |
| 1507 form.name = ASCIIToUTF16("TestForm"); | 1494 form.name = ASCIIToUTF16("TestForm"); |
| 1508 form.origin = GURL("http://example.com/form.html"); | 1495 form.origin = GURL("http://example.com/form.html"); |
| 1509 form.action = GURL("http://example.com/submit.html"); | 1496 form.action = GURL("http://example.com/submit.html"); |
| (...skipping 3606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5116 // Tests that no UKM is logged when the ukm service is null. | 5103 // Tests that no UKM is logged when the ukm service is null. |
| 5117 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmService) { | 5104 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmService) { |
| 5118 GURL url("https://www.google.com"); | 5105 GURL url("https://www.google.com"); |
| 5119 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; | 5106 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; |
| 5120 | 5107 |
| 5121 EXPECT_FALSE(AutofillMetrics::LogUkm(nullptr, url, "test_ukm", metrics)); | 5108 EXPECT_FALSE(AutofillMetrics::LogUkm(nullptr, url, "test_ukm", metrics)); |
| 5122 ASSERT_EQ(0U, test_ukm_recorder_.sources_count()); | 5109 ASSERT_EQ(0U, test_ukm_recorder_.sources_count()); |
| 5123 } | 5110 } |
| 5124 | 5111 |
| 5125 } // namespace autofill | 5112 } // namespace autofill |
| OLD | NEW |