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

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

Issue 884843002: Recording in UMA when a user interacted with an address form or a credit card form. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixing duplicate emission of CreditCard histograms Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/core/browser/autofill_metrics.h" 5 #include "components/autofill/core/browser/autofill_metrics.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 18 matching lines...) Expand all
29 29
30 using base::ASCIIToUTF16; 30 using base::ASCIIToUTF16;
31 using base::TimeTicks; 31 using base::TimeTicks;
32 32
33 namespace autofill { 33 namespace autofill {
34 namespace { 34 namespace {
35 35
36 class TestPersonalDataManager : public PersonalDataManager { 36 class TestPersonalDataManager : public PersonalDataManager {
37 public: 37 public:
38 TestPersonalDataManager() 38 TestPersonalDataManager()
39 : PersonalDataManager("en-US"), autofill_enabled_(true) { 39 : PersonalDataManager("en-US"),
40 autofill_enabled_(true) {
41 test_force_wallet_card_sync_enabled_ = true;
40 CreateTestAutofillProfiles(&web_profiles_); 42 CreateTestAutofillProfiles(&web_profiles_);
41 } 43 }
42 44
43 using PersonalDataManager::set_database; 45 using PersonalDataManager::set_database;
44 using PersonalDataManager::SetPrefService; 46 using PersonalDataManager::SetPrefService;
45 47
46 // Overridden to avoid a trip to the database. This should be a no-op except 48 // Overridden to avoid a trip to the database. This should be a no-op except
47 // for the side-effect of logging the profile count. 49 // for the side-effect of logging the profile count.
48 void LoadProfiles() override { 50 void LoadProfiles() override {
49 std::vector<AutofillProfile*> profiles; 51 {
50 web_profiles_.release(&profiles); 52 std::vector<AutofillProfile*> profiles;
51 WDResult<std::vector<AutofillProfile*> > result(AUTOFILL_PROFILES_RESULT, 53 web_profiles_.release(&profiles);
52 profiles); 54 WDResult<std::vector<AutofillProfile*> > result(AUTOFILL_PROFILES_RESULT,
53 pending_profiles_query_ = 123; 55 profiles);
54 OnWebDataServiceRequestDone(pending_profiles_query_, &result); 56 pending_profiles_query_ = 123;
57 OnWebDataServiceRequestDone(pending_profiles_query_, &result);
58 }
59 {
60 std::vector<AutofillProfile*> profiles;
61 server_profiles_.release(&profiles);
62 WDResult<std::vector<AutofillProfile*> > result(AUTOFILL_PROFILES_RESULT,
63 profiles);
64 pending_server_profiles_query_ = 124;
65 OnWebDataServiceRequestDone(pending_server_profiles_query_, &result);
66 }
55 } 67 }
56 68
57 // Overridden to avoid a trip to the database. 69 // Overridden to avoid a trip to the database.
58 void LoadCreditCards() override {} 70 void LoadCreditCards() override {
71 {
72 std::vector<CreditCard*> credit_cards;
73 local_credit_cards_.release(&credit_cards);
74 WDResult<std::vector<CreditCard*> > result(
75 AUTOFILL_CREDITCARDS_RESULT, credit_cards);
76 pending_creditcards_query_ = 125;
77 OnWebDataServiceRequestDone(pending_creditcards_query_, &result);
78 }
79 {
80 std::vector<CreditCard*> credit_cards;
81 server_credit_cards_.release(&credit_cards);
82 WDResult<std::vector<CreditCard*> > result(
83 AUTOFILL_CREDITCARDS_RESULT, credit_cards);
84 pending_server_creditcards_query_ = 126;
85 OnWebDataServiceRequestDone(pending_server_creditcards_query_, &result);
86 }
87 }
59 88
60 void set_autofill_enabled(bool autofill_enabled) { 89 void set_autofill_enabled(bool autofill_enabled) {
61 autofill_enabled_ = autofill_enabled; 90 autofill_enabled_ = autofill_enabled;
62 } 91 }
63 92
93 // Removes all existing profiles and creates 0 or 1 local profiles and 0 or 1
94 // server profile according to the paramters.
95 void RecreateProfiles(bool include_local_profile,
96 bool include_server_profile) {
97 web_profiles_.clear();
98 server_profiles_.clear();
99 if (include_local_profile) {
100 AutofillProfile* profile = new AutofillProfile;
101 test::SetProfileInfo(profile, "Elvis", "Aaron",
102 "Presley", "theking@gmail.com", "RCA",
103 "3734 Elvis Presley Blvd.", "Apt. 10",
104 "Memphis", "Tennessee", "38116", "US",
105 "12345678901");
106 profile->set_guid("00000000-0000-0000-0000-000000000001");
107 web_profiles_.push_back(profile);
108 }
109 if (include_server_profile) {
110 AutofillProfile* profile = new AutofillProfile(
111 AutofillProfile::SERVER_PROFILE, "server_id");
112 test::SetProfileInfo(profile, "Charles", "Hardin",
113 "Holley", "buddy@gmail.com", "Decca",
114 "123 Apple St.", "unit 6", "Lubbock",
115 "Texas", "79401", "US", "2345678901");
116 profile->set_guid("00000000-0000-0000-0000-000000000002");
117 server_profiles_.push_back(profile);
118 }
119 Refresh();
120 }
121
122 // Removes all existing credit cards and creates 0 or 1 local profiles and
123 // 0 or 1 server profile according to the paramters.
124 void RecreateCreditCards(bool include_local_credit_card,
125 bool include_masked_server_credit_card,
126 bool include_full_server_credit_card) {
127 local_credit_cards_.clear();
128 server_credit_cards_.clear();
129 if (include_local_credit_card) {
130 CreditCard* credit_card = new CreditCard;
131 credit_card->set_guid("10000000-0000-0000-0000-000000000001");
132 local_credit_cards_.push_back(credit_card);
133 }
134 if (include_masked_server_credit_card) {
135 CreditCard* credit_card = new CreditCard(
136 CreditCard::MASKED_SERVER_CARD, "server_id");
137 credit_card->set_guid("10000000-0000-0000-0000-000000000002");
138 server_credit_cards_.push_back(credit_card);
139 }
140 if (include_full_server_credit_card) {
141 CreditCard* credit_card = new CreditCard(
142 CreditCard::FULL_SERVER_CARD, "server_id");
143 credit_card->set_guid("10000000-0000-0000-0000-000000000003");
144 server_credit_cards_.push_back(credit_card);
145 }
146 Refresh();
147 }
148
64 bool IsAutofillEnabled() const override { return autofill_enabled_; } 149 bool IsAutofillEnabled() const override { return autofill_enabled_; }
65 150
66 private: 151 private:
67 void CreateTestAutofillProfiles(ScopedVector<AutofillProfile>* profiles) { 152 void CreateTestAutofillProfiles(ScopedVector<AutofillProfile>* profiles) {
68 AutofillProfile* profile = new AutofillProfile; 153 AutofillProfile* profile = new AutofillProfile;
69 test::SetProfileInfo(profile, "Elvis", "Aaron", 154 test::SetProfileInfo(profile, "Elvis", "Aaron",
70 "Presley", "theking@gmail.com", "RCA", 155 "Presley", "theking@gmail.com", "RCA",
71 "3734 Elvis Presley Blvd.", "Apt. 10", 156 "3734 Elvis Presley Blvd.", "Apt. 10",
72 "Memphis", "Tennessee", "38116", "US", 157 "Memphis", "Tennessee", "38116", "US",
73 "12345678901"); 158 "12345678901");
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 { 758 {
674 // Simulate activating the autofill popup for the email field after typing. 759 // Simulate activating the autofill popup for the email field after typing.
675 form.fields[0].is_autofilled = true; 760 form.fields[0].is_autofilled = true;
676 base::HistogramTester histogram_tester; 761 base::HistogramTester histogram_tester;
677 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(), 762 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
678 false); 763 false);
679 histogram_tester.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0); 764 histogram_tester.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0);
680 } 765 }
681 } 766 }
682 767
768 // Test that we log interacted form event for credit cards only once.
769 TEST_F(AutofillMetricsTest, CreditCardInteractedOnce) {
770 // Set up our form data.
771 FormData form;
772 form.name = ASCIIToUTF16("TestForm");
773 form.origin = GURL("http://example.com/form.html");
774 form.action = GURL("http://example.com/submit.html");
775 form.user_submitted = true;
776
777 FormFieldData field;
778 std::vector<ServerFieldType> field_types;
779 test::CreateTestFormField("Month", "card_month", "", "text", &field);
780 form.fields.push_back(field);
781 field_types.push_back(CREDIT_CARD_EXP_MONTH);
782 test::CreateTestFormField("Year", "card_year", "", "text", &field);
783 form.fields.push_back(field);
784 field_types.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR);
785 test::CreateTestFormField("Credit card", "card", "", "text", &field);
786 form.fields.push_back(field);
787 field_types.push_back(CREDIT_CARD_NUMBER);
788
789 // Simulate having seen this form on page load.
790 // |form_structure| will be owned by |autofill_manager_|.
791 autofill_manager_->AddSeenForm(form, field_types, field_types);
792
793 {
794 // Simulate activating the autofill popup for the credit card field.
795 base::HistogramTester histogram_tester;
796 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
797 false);
798 histogram_tester.ExpectUniqueSample(
799 "Autofill.FormEvents.CreditCard", AutofillMetrics::INTERACTED_ONCE, 1);
800 }
801
802 // Reset the autofill manager state.
803 autofill_manager_->Reset();
804 autofill_manager_->AddSeenForm(form, field_types, field_types);
805
806 {
807 // Simulate activating the autofill popup for the credit card field twice.
808 base::HistogramTester histogram_tester;
809 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
810 false);
811 autofill_manager_->OnQueryFormFieldAutofill(1, form, field, gfx::Rect(),
812 false);
813 histogram_tester.ExpectUniqueSample(
814 "Autofill.FormEvents.CreditCard", AutofillMetrics::INTERACTED_ONCE, 1);
815 }
816 }
817
818 // Test that we log interacted form event for address only once.
819 TEST_F(AutofillMetricsTest, AddressInteractedOnce) {
820 // Set up our form data.
821 FormData form;
822 form.name = ASCIIToUTF16("TestForm");
823 form.origin = GURL("http://example.com/form.html");
824 form.action = GURL("http://example.com/submit.html");
825 form.user_submitted = true;
826
827 FormFieldData field;
828 std::vector<ServerFieldType> field_types;
829 test::CreateTestFormField("State", "state", "", "text", &field);
830 form.fields.push_back(field);
831 field_types.push_back(ADDRESS_HOME_STATE);
832 test::CreateTestFormField("City", "city", "", "text", &field);
833 form.fields.push_back(field);
834 field_types.push_back(ADDRESS_HOME_CITY);
835 test::CreateTestFormField("Street", "street", "", "text", &field);
836 form.fields.push_back(field);
837 field_types.push_back(ADDRESS_HOME_STREET_ADDRESS);
838
839 // Simulate having seen this form on page load.
840 // |form_structure| will be owned by |autofill_manager_|.
841 autofill_manager_->AddSeenForm(form, field_types, field_types);
842
843 {
844 // Simulate activating the autofill popup for the street field.
845 base::HistogramTester histogram_tester;
846 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
847 false);
848 histogram_tester.ExpectUniqueSample(
849 "Autofill.FormEvents.Address", AutofillMetrics::INTERACTED_ONCE, 1);
850 }
851
852 // Reset the autofill manager state.
853 autofill_manager_->Reset();
854 autofill_manager_->AddSeenForm(form, field_types, field_types);
855
856 {
857 // Simulate activating the autofill popup for the street field twice.
858 base::HistogramTester histogram_tester;
859 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
860 false);
861 autofill_manager_->OnQueryFormFieldAutofill(1, form, field, gfx::Rect(),
862 false);
863 histogram_tester.ExpectUniqueSample(
864 "Autofill.FormEvents.Address", AutofillMetrics::INTERACTED_ONCE, 1);
865 }
866 }
867
868 // Test that we log interacted form event for credit cards only once.
869 TEST_F(AutofillMetricsTest, CreditCardFormEventsAreSegmented) {
870 // Set up our form data.
871 FormData form;
872 form.name = ASCIIToUTF16("TestForm");
873 form.origin = GURL("http://example.com/form.html");
874 form.action = GURL("http://example.com/submit.html");
875 form.user_submitted = true;
876
877 FormFieldData field;
878 std::vector<ServerFieldType> field_types;
879 test::CreateTestFormField("Month", "card_month", "", "text", &field);
880 form.fields.push_back(field);
881 field_types.push_back(CREDIT_CARD_EXP_MONTH);
882 test::CreateTestFormField("Year", "card_year", "", "text", &field);
883 form.fields.push_back(field);
884 field_types.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR);
885 test::CreateTestFormField("Credit card", "card", "", "text", &field);
886 form.fields.push_back(field);
887 field_types.push_back(CREDIT_CARD_NUMBER);
888
889 // Simulate having seen this form on page load.
890 // |form_structure| will be owned by |autofill_manager_|.
891 autofill_manager_->AddSeenForm(form, field_types, field_types);
892 personal_data_->RecreateCreditCards(
893 false /* include_local_credit_card */,
894 false /* include_masked_server_credit_card */,
895 false /* include_full_server_credit_card */);
896
897 {
898 // Simulate activating the autofill popup for the credit card field.
899 base::HistogramTester histogram_tester;
900 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
901 false);
902 histogram_tester.ExpectUniqueSample(
903 "Autofill.FormEvents.CreditCard.WithNoData",
904 AutofillMetrics::INTERACTED_ONCE, 1);
905 }
906
907 // Reset the autofill manager state.
908 autofill_manager_->Reset();
909 autofill_manager_->AddSeenForm(form, field_types, field_types);
910 personal_data_->RecreateCreditCards(
911 true /* include_local_credit_card */,
912 false /* include_masked_server_credit_card */,
913 false /* include_full_server_credit_card */);
914
915 {
916 // Simulate activating the autofill popup for the credit card field.
917 base::HistogramTester histogram_tester;
918 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
919 false);
920 histogram_tester.ExpectUniqueSample(
921 "Autofill.FormEvents.CreditCard.WithOnlyLocalData",
922 AutofillMetrics::INTERACTED_ONCE, 1);
923 }
924
925 // Reset the autofill manager state.
926 autofill_manager_->Reset();
927 autofill_manager_->AddSeenForm(form, field_types, field_types);
928 personal_data_->RecreateCreditCards(
929 false /* include_local_credit_card */,
930 true /* include_masked_server_credit_card */,
931 false /* include_full_server_credit_card */);
932
933 {
934 // Simulate activating the autofill popup for the credit card field.
935 base::HistogramTester histogram_tester;
936 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
937 false);
938 histogram_tester.ExpectUniqueSample(
939 "Autofill.FormEvents.CreditCard.WithOnlyServerData",
940 AutofillMetrics::INTERACTED_ONCE, 1);
941 }
942
943 // Reset the autofill manager state.
944 autofill_manager_->Reset();
945 autofill_manager_->AddSeenForm(form, field_types, field_types);
946 personal_data_->RecreateCreditCards(
947 false /* include_local_credit_card */,
948 false /* include_masked_server_credit_card */,
949 true /* include_full_server_credit_card */);
950
951 {
952 // Simulate activating the autofill popup for the credit card field.
953 base::HistogramTester histogram_tester;
954 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
955 false);
956 histogram_tester.ExpectUniqueSample(
957 "Autofill.FormEvents.CreditCard.WithOnlyServerData",
958 AutofillMetrics::INTERACTED_ONCE, 1);
959 }
960
961 // Reset the autofill manager state.
962 autofill_manager_->Reset();
963 autofill_manager_->AddSeenForm(form, field_types, field_types);
964 personal_data_->RecreateCreditCards(
965 true /* include_local_credit_card */,
966 false /* include_masked_server_credit_card */,
967 true /* include_full_server_credit_card */);
968
969 {
970 // Simulate activating the autofill popup for the credit card field.
971 base::HistogramTester histogram_tester;
972 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
973 false);
974 histogram_tester.ExpectUniqueSample(
975 "Autofill.FormEvents.CreditCard.WithBothServerAndLocalData",
976 AutofillMetrics::INTERACTED_ONCE, 1);
977 }
978 }
979
980 // Test that we log interacted form event for address only once.
981 TEST_F(AutofillMetricsTest, AddressFormEventsAreSegmented) {
982 // Set up our form data.
983 FormData form;
984 form.name = ASCIIToUTF16("TestForm");
985 form.origin = GURL("http://example.com/form.html");
986 form.action = GURL("http://example.com/submit.html");
987 form.user_submitted = true;
988
989 FormFieldData field;
990 std::vector<ServerFieldType> field_types;
991 test::CreateTestFormField("State", "state", "", "text", &field);
992 form.fields.push_back(field);
993 field_types.push_back(ADDRESS_HOME_STATE);
994 test::CreateTestFormField("City", "city", "", "text", &field);
995 form.fields.push_back(field);
996 field_types.push_back(ADDRESS_HOME_CITY);
997 test::CreateTestFormField("Street", "street", "", "text", &field);
998 form.fields.push_back(field);
999 field_types.push_back(ADDRESS_HOME_STREET_ADDRESS);
1000
1001 // Simulate having seen this form on page load.
1002 // |form_structure| will be owned by |autofill_manager_|.
1003 autofill_manager_->AddSeenForm(form, field_types, field_types);
1004 personal_data_->RecreateProfiles(false /* include_local_profile */,
1005 false /* include_server_profile */);
1006
1007 {
1008 // Simulate activating the autofill popup for the street field.
1009 base::HistogramTester histogram_tester;
1010 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
1011 false);
1012 histogram_tester.ExpectUniqueSample(
1013 "Autofill.FormEvents.Address.WithNoData",
1014 AutofillMetrics::INTERACTED_ONCE, 1);
1015 }
1016
1017 // Reset the autofill manager state.
1018 autofill_manager_->Reset();
1019 autofill_manager_->AddSeenForm(form, field_types, field_types);
1020 personal_data_->RecreateProfiles(true /* include_local_profile */,
1021 false /* include_server_profile */);
1022
1023 {
1024 // Simulate activating the autofill popup for the street field.
1025 base::HistogramTester histogram_tester;
1026 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
1027 false);
1028 histogram_tester.ExpectUniqueSample(
1029 "Autofill.FormEvents.Address.WithOnlyLocalData",
1030 AutofillMetrics::INTERACTED_ONCE, 1);
1031 }
1032
1033 // Reset the autofill manager state.
1034 autofill_manager_->Reset();
1035 autofill_manager_->AddSeenForm(form, field_types, field_types);
1036 personal_data_->RecreateProfiles(false /* include_local_profile */,
1037 true /* include_server_profile */);
1038
1039 {
1040 // Simulate activating the autofill popup for the street field.
1041 base::HistogramTester histogram_tester;
1042 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
1043 false);
1044 histogram_tester.ExpectUniqueSample(
1045 "Autofill.FormEvents.Address.WithOnlyServerData",
1046 AutofillMetrics::INTERACTED_ONCE, 1);
1047 }
1048
1049 // Reset the autofill manager state.
1050 autofill_manager_->Reset();
1051 autofill_manager_->AddSeenForm(form, field_types, field_types);
1052 personal_data_->RecreateProfiles(true /* include_local_profile */,
1053 true /* include_server_profile */);
1054
1055 {
1056 // Simulate activating the autofill popup for the street field.
1057 base::HistogramTester histogram_tester;
1058 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
1059 false);
1060 histogram_tester.ExpectUniqueSample(
1061 "Autofill.FormEvents.Address.WithBothServerAndLocalData",
1062 AutofillMetrics::INTERACTED_ONCE, 1);
1063 }
1064 }
1065
1066
683 // Test that we log that Autofill is enabled when filling a form. 1067 // Test that we log that Autofill is enabled when filling a form.
684 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtPageLoad) { 1068 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtPageLoad) {
685 base::HistogramTester histogram_tester; 1069 base::HistogramTester histogram_tester;
686 autofill_manager_->set_autofill_enabled(true); 1070 autofill_manager_->set_autofill_enabled(true);
687 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks()); 1071 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks());
688 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.PageLoad", true, 1); 1072 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.PageLoad", true, 1);
689 } 1073 }
690 1074
691 // Test that we log that Autofill is disabled when filling a form. 1075 // Test that we log that Autofill is disabled when filling a form.
692 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtPageLoad) { 1076 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtPageLoad) {
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 histogram_tester.ExpectTotalCount( 1477 histogram_tester.ExpectTotalCount(
1094 "Autofill.FillDuration.FromInteraction.WithAutofill", 0); 1478 "Autofill.FillDuration.FromInteraction.WithAutofill", 0);
1095 histogram_tester.ExpectTotalCount( 1479 histogram_tester.ExpectTotalCount(
1096 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0); 1480 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
1097 1481
1098 autofill_manager_->Reset(); 1482 autofill_manager_->Reset();
1099 } 1483 }
1100 } 1484 }
1101 1485
1102 } // namespace autofill 1486 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698