| 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 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 1); | 698 1); |
| 699 // Mismatch: | 699 // Mismatch: |
| 700 histogram_tester.ExpectBucketCount( | 700 histogram_tester.ExpectBucketCount( |
| 701 "Autofill.Quality.PredictedType.NoSubmission", | 701 "Autofill.Quality.PredictedType.NoSubmission", |
| 702 AutofillMetrics::TYPE_MISMATCH, 1); | 702 AutofillMetrics::TYPE_MISMATCH, 1); |
| 703 histogram_tester.ExpectBucketCount( | 703 histogram_tester.ExpectBucketCount( |
| 704 "Autofill.Quality.PredictedType.ByFieldType.NoSubmission", | 704 "Autofill.Quality.PredictedType.ByFieldType.NoSubmission", |
| 705 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MISMATCH), 1); | 705 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MISMATCH), 1); |
| 706 } | 706 } |
| 707 | 707 |
| 708 // Test that we log quality metrics for heuristics and server predictions based |
| 709 // on autocomplete attributes present on the fields. |
| 710 TEST_F(AutofillMetricsTest, QualityMetrics_BasedOnAutocomplete) { |
| 711 FormData form; |
| 712 form.name = ASCIIToUTF16("MyForm"); |
| 713 form.origin = GURL("http://myform.com/form.html"); |
| 714 form.action = GURL("http://myform.com/submit.html"); |
| 715 |
| 716 FormFieldData field; |
| 717 // Heuristic value will match with Autocomplete attribute. |
| 718 test::CreateTestFormField("Last Name", "lastname", "", "text", &field); |
| 719 field.autocomplete_attribute = "family-name"; |
| 720 form.fields.push_back(field); |
| 721 |
| 722 // Heuristic value will NOT match with Autocomplete attribute. |
| 723 test::CreateTestFormField("First Name", "firstname", "", "text", &field); |
| 724 field.autocomplete_attribute = "additional-name"; |
| 725 form.fields.push_back(field); |
| 726 |
| 727 // Heuristic value will be unknown. |
| 728 test::CreateTestFormField("Garbage label", "garbage", "", "text", &field); |
| 729 field.autocomplete_attribute = "postal-code"; |
| 730 form.fields.push_back(field); |
| 731 |
| 732 // No autocomplete attribute. No metric logged. |
| 733 test::CreateTestFormField("Address", "address", "", "text", &field); |
| 734 field.autocomplete_attribute = ""; |
| 735 form.fields.push_back(field); |
| 736 |
| 737 TestFormStructure* form_structure = new TestFormStructure(form); |
| 738 form_structure->DetermineHeuristicTypes(); |
| 739 autofill_manager_->form_structures()->push_back(form_structure); |
| 740 |
| 741 AutofillQueryResponseContents response; |
| 742 // Server response will match with autocomplete. |
| 743 response.add_field()->set_autofill_type(NAME_LAST); |
| 744 // Server response will NOT match with autocomplete. |
| 745 response.add_field()->set_autofill_type(NAME_FIRST); |
| 746 // Server response will have no data. |
| 747 response.add_field()->set_autofill_type(NO_SERVER_DATA); |
| 748 // Not logged. |
| 749 response.add_field()->set_autofill_type(NAME_MIDDLE); |
| 750 |
| 751 std::string response_string; |
| 752 ASSERT_TRUE(response.SerializeToString(&response_string)); |
| 753 |
| 754 std::vector<std::string> signatures; |
| 755 signatures.push_back(form_structure->FormSignature()); |
| 756 |
| 757 base::HistogramTester histogram_tester; |
| 758 autofill_manager_->OnLoadedServerPredictions(response_string, signatures); |
| 759 |
| 760 // Verify that FormStructure::ParseQueryResponse was called (here and below). |
| 761 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse", |
| 762 AutofillMetrics::QUERY_RESPONSE_RECEIVED, |
| 763 1); |
| 764 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse", |
| 765 AutofillMetrics::QUERY_RESPONSE_PARSED, 1); |
| 766 |
| 767 // Autocomplete-derived types are eventually what's inferred. |
| 768 EXPECT_EQ(NAME_LAST, form_structure->field(0)->Type().GetStorableType()); |
| 769 EXPECT_EQ(NAME_MIDDLE, form_structure->field(1)->Type().GetStorableType()); |
| 770 EXPECT_EQ(ADDRESS_HOME_ZIP, |
| 771 form_structure->field(2)->Type().GetStorableType()); |
| 772 |
| 773 // Heuristic predictions. |
| 774 // Unknown: |
| 775 histogram_tester.ExpectBucketCount( |
| 776 "Autofill.Quality.HeuristicType.BasedOnAutocomplete", |
| 777 AutofillMetrics::TYPE_UNKNOWN, 1); |
| 778 histogram_tester.ExpectBucketCount( |
| 779 "Autofill.Quality.HeuristicType.ByFieldType.BasedOnAutocomplete", |
| 780 GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP, AutofillMetrics::TYPE_UNKNOWN), |
| 781 1); |
| 782 // Match: |
| 783 histogram_tester.ExpectBucketCount( |
| 784 "Autofill.Quality.HeuristicType.BasedOnAutocomplete", |
| 785 AutofillMetrics::TYPE_MATCH, 1); |
| 786 histogram_tester.ExpectBucketCount( |
| 787 "Autofill.Quality.HeuristicType.ByFieldType.BasedOnAutocomplete", |
| 788 GetFieldTypeGroupMetric(NAME_LAST, AutofillMetrics::TYPE_MATCH), 1); |
| 789 // Mismatch: |
| 790 histogram_tester.ExpectBucketCount( |
| 791 "Autofill.Quality.HeuristicType.BasedOnAutocomplete", |
| 792 AutofillMetrics::TYPE_MISMATCH, 1); |
| 793 histogram_tester.ExpectBucketCount( |
| 794 "Autofill.Quality.HeuristicType.ByFieldType.BasedOnAutocomplete", |
| 795 GetFieldTypeGroupMetric(NAME_MIDDLE, AutofillMetrics::TYPE_MISMATCH), 1); |
| 796 |
| 797 // Server predictions. |
| 798 // Unknown: |
| 799 histogram_tester.ExpectBucketCount( |
| 800 "Autofill.Quality.ServerType.BasedOnAutocomplete", |
| 801 AutofillMetrics::TYPE_UNKNOWN, 1); |
| 802 histogram_tester.ExpectBucketCount( |
| 803 "Autofill.Quality.ServerType.ByFieldType.BasedOnAutocomplete", |
| 804 GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP, AutofillMetrics::TYPE_UNKNOWN), |
| 805 1); |
| 806 // Match: |
| 807 histogram_tester.ExpectBucketCount( |
| 808 "Autofill.Quality.ServerType.BasedOnAutocomplete", |
| 809 AutofillMetrics::TYPE_MATCH, 1); |
| 810 histogram_tester.ExpectBucketCount( |
| 811 "Autofill.Quality.ServerType.ByFieldType.BasedOnAutocomplete", |
| 812 GetFieldTypeGroupMetric(NAME_LAST, AutofillMetrics::TYPE_MATCH), 1); |
| 813 // Mismatch: |
| 814 histogram_tester.ExpectBucketCount( |
| 815 "Autofill.Quality.ServerType.BasedOnAutocomplete", |
| 816 AutofillMetrics::TYPE_MISMATCH, 1); |
| 817 histogram_tester.ExpectBucketCount( |
| 818 "Autofill.Quality.ServerType.ByFieldType.BasedOnAutocomplete", |
| 819 GetFieldTypeGroupMetric(NAME_MIDDLE, AutofillMetrics::TYPE_MISMATCH), 1); |
| 820 } |
| 821 |
| 708 // Test that we do not log RAPPOR metrics when the number of mismatches is not | 822 // Test that we do not log RAPPOR metrics when the number of mismatches is not |
| 709 // high enough. | 823 // high enough. |
| 710 TEST_F(AutofillMetricsTest, Rappor_LowMismatchRate_NoMetricsReported) { | 824 TEST_F(AutofillMetricsTest, Rappor_LowMismatchRate_NoMetricsReported) { |
| 711 // Set up our form data. | 825 // Set up our form data. |
| 712 FormData form; | 826 FormData form; |
| 713 form.name = ASCIIToUTF16("TestForm"); | 827 form.name = ASCIIToUTF16("TestForm"); |
| 714 form.origin = GURL("http://example.com/form.html"); | 828 form.origin = GURL("http://example.com/form.html"); |
| 715 form.action = GURL("http://example.com/submit.html"); | 829 form.action = GURL("http://example.com/submit.html"); |
| 716 | 830 |
| 717 std::vector<ServerFieldType> heuristic_types, server_types; | 831 std::vector<ServerFieldType> heuristic_types, server_types; |
| (...skipping 3047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3765 EXPECT_THAT( | 3879 EXPECT_THAT( |
| 3766 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), | 3880 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), |
| 3767 ElementsAre(Bucket(true, 2))); | 3881 ElementsAre(Bucket(true, 2))); |
| 3768 | 3882 |
| 3769 // No RAPPOR metrics are logged in the case there is at least some server data | 3883 // No RAPPOR metrics are logged in the case there is at least some server data |
| 3770 // available for all forms. | 3884 // available for all forms. |
| 3771 EXPECT_EQ(0, rappor_service_.GetReportsCount()); | 3885 EXPECT_EQ(0, rappor_service_.GetReportsCount()); |
| 3772 } | 3886 } |
| 3773 | 3887 |
| 3774 } // namespace autofill | 3888 } // namespace autofill |
| OLD | NEW |