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> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" |
13 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
14 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
16 #include "base/test/histogram_tester.h" | 17 #include "base/test/histogram_tester.h" |
17 #include "base/test/user_action_tester.h" | 18 #include "base/test/user_action_tester.h" |
18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
19 #include "components/autofill/core/browser/autofill_external_delegate.h" | 20 #include "components/autofill/core/browser/autofill_external_delegate.h" |
20 #include "components/autofill/core/browser/autofill_manager.h" | 21 #include "components/autofill/core/browser/autofill_manager.h" |
21 #include "components/autofill/core/browser/autofill_test_utils.h" | 22 #include "components/autofill/core/browser/autofill_test_utils.h" |
22 #include "components/autofill/core/browser/payments/payments_client.h" | 23 #include "components/autofill/core/browser/payments/payments_client.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 58 |
58 using PersonalDataManager::set_account_tracker; | 59 using PersonalDataManager::set_account_tracker; |
59 using PersonalDataManager::set_signin_manager; | 60 using PersonalDataManager::set_signin_manager; |
60 using PersonalDataManager::set_database; | 61 using PersonalDataManager::set_database; |
61 using PersonalDataManager::SetPrefService; | 62 using PersonalDataManager::SetPrefService; |
62 | 63 |
63 // Overridden to avoid a trip to the database. This should be a no-op except | 64 // Overridden to avoid a trip to the database. This should be a no-op except |
64 // for the side-effect of logging the profile count. | 65 // for the side-effect of logging the profile count. |
65 void LoadProfiles() override { | 66 void LoadProfiles() override { |
66 { | 67 { |
67 std::vector<AutofillProfile*> profiles; | 68 std::vector<std::unique_ptr<AutofillProfile>> profiles; |
68 web_profiles_.release(&profiles); | 69 web_profiles_.swap(profiles); |
69 WDResult<std::vector<AutofillProfile*> > result(AUTOFILL_PROFILES_RESULT, | 70 std::unique_ptr<WDTypedResult> result = base::MakeUnique< |
70 profiles); | 71 WDResult<std::vector<std::unique_ptr<AutofillProfile>>>>( |
| 72 AUTOFILL_PROFILES_RESULT, std::move(profiles)); |
71 pending_profiles_query_ = 123; | 73 pending_profiles_query_ = 123; |
72 OnWebDataServiceRequestDone(pending_profiles_query_, &result); | 74 OnWebDataServiceRequestDone(pending_profiles_query_, std::move(result)); |
73 } | 75 } |
74 { | 76 { |
75 std::vector<AutofillProfile*> profiles; | 77 std::vector<std::unique_ptr<AutofillProfile>> profiles; |
76 server_profiles_.release(&profiles); | 78 server_profiles_.swap(profiles); |
77 WDResult<std::vector<AutofillProfile*> > result(AUTOFILL_PROFILES_RESULT, | 79 std::unique_ptr<WDTypedResult> result = base::MakeUnique< |
78 profiles); | 80 WDResult<std::vector<std::unique_ptr<AutofillProfile>>>>( |
| 81 AUTOFILL_PROFILES_RESULT, std::move(profiles)); |
79 pending_server_profiles_query_ = 124; | 82 pending_server_profiles_query_ = 124; |
80 OnWebDataServiceRequestDone(pending_server_profiles_query_, &result); | 83 OnWebDataServiceRequestDone(pending_server_profiles_query_, |
| 84 std::move(result)); |
81 } | 85 } |
82 } | 86 } |
83 | 87 |
84 // Overridden to avoid a trip to the database. | 88 // Overridden to avoid a trip to the database. |
85 void LoadCreditCards() override { | 89 void LoadCreditCards() override { |
86 { | 90 { |
87 std::vector<CreditCard*> credit_cards; | 91 std::vector<std::unique_ptr<CreditCard>> credit_cards; |
88 local_credit_cards_.release(&credit_cards); | 92 local_credit_cards_.swap(credit_cards); |
89 WDResult<std::vector<CreditCard*> > result( | 93 std::unique_ptr<WDTypedResult> result = |
90 AUTOFILL_CREDITCARDS_RESULT, credit_cards); | 94 base::MakeUnique<WDResult<std::vector<std::unique_ptr<CreditCard>>>>( |
| 95 AUTOFILL_CREDITCARDS_RESULT, std::move(credit_cards)); |
91 pending_creditcards_query_ = 125; | 96 pending_creditcards_query_ = 125; |
92 OnWebDataServiceRequestDone(pending_creditcards_query_, &result); | 97 OnWebDataServiceRequestDone(pending_creditcards_query_, |
| 98 std::move(result)); |
93 } | 99 } |
94 { | 100 { |
95 std::vector<CreditCard*> credit_cards; | 101 std::vector<std::unique_ptr<CreditCard>> credit_cards; |
96 server_credit_cards_.release(&credit_cards); | 102 server_credit_cards_.swap(credit_cards); |
97 WDResult<std::vector<CreditCard*> > result( | 103 std::unique_ptr<WDTypedResult> result = |
98 AUTOFILL_CREDITCARDS_RESULT, credit_cards); | 104 base::MakeUnique<WDResult<std::vector<std::unique_ptr<CreditCard>>>>( |
| 105 AUTOFILL_CREDITCARDS_RESULT, std::move(credit_cards)); |
99 pending_server_creditcards_query_ = 126; | 106 pending_server_creditcards_query_ = 126; |
100 OnWebDataServiceRequestDone(pending_server_creditcards_query_, &result); | 107 OnWebDataServiceRequestDone(pending_server_creditcards_query_, |
| 108 std::move(result)); |
101 } | 109 } |
102 } | 110 } |
103 | 111 |
104 // Overridden to add potential new profiles to the |web_profiles_|. Since | 112 // Overridden to add potential new profiles to the |web_profiles_|. Since |
105 // there is no database set for the test, the original method would do | 113 // there is no database set for the test, the original method would do |
106 // nothing. | 114 // nothing. |
107 void SetProfiles(std::vector<AutofillProfile>* profiles) override { | 115 void SetProfiles(std::vector<AutofillProfile>* profiles) override { |
108 // Only need to copy all the profiles. This adds any new profiles created at | 116 // Only need to copy all the profiles. This adds any new profiles created at |
109 // form submission. | 117 // form submission. |
110 web_profiles_.clear(); | 118 web_profiles_.clear(); |
111 for (std::vector<AutofillProfile>::iterator iter = profiles->begin(); | 119 for (const auto& profile : *profiles) |
112 iter != profiles->end(); ++iter) { | 120 web_profiles_.push_back(base::MakeUnique<AutofillProfile>(profile)); |
113 web_profiles_.push_back(new AutofillProfile(*iter)); | |
114 } | |
115 } | 121 } |
116 | 122 |
117 void set_autofill_enabled(bool autofill_enabled) { | 123 void set_autofill_enabled(bool autofill_enabled) { |
118 autofill_enabled_ = autofill_enabled; | 124 autofill_enabled_ = autofill_enabled; |
119 } | 125 } |
120 | 126 |
121 // Removes all existing profiles and creates 0 or 1 local profiles and 0 or 1 | 127 // Removes all existing profiles and creates 0 or 1 local profiles and 0 or 1 |
122 // server profile according to the paramters. | 128 // server profile according to the parameters. |
123 void RecreateProfiles(bool include_local_profile, | 129 void RecreateProfiles(bool include_local_profile, |
124 bool include_server_profile) { | 130 bool include_server_profile) { |
125 web_profiles_.clear(); | 131 web_profiles_.clear(); |
126 server_profiles_.clear(); | 132 server_profiles_.clear(); |
127 if (include_local_profile) { | 133 if (include_local_profile) { |
128 AutofillProfile* profile = new AutofillProfile; | 134 std::unique_ptr<AutofillProfile> profile = |
129 test::SetProfileInfo(profile, "Elvis", "Aaron", | 135 base::MakeUnique<AutofillProfile>(); |
130 "Presley", "theking@gmail.com", "RCA", | 136 test::SetProfileInfo(profile.get(), "Elvis", "Aaron", "Presley", |
131 "3734 Elvis Presley Blvd.", "Apt. 10", | 137 "theking@gmail.com", "RCA", |
132 "Memphis", "Tennessee", "38116", "US", | 138 "3734 Elvis Presley Blvd.", "Apt. 10", "Memphis", |
133 "12345678901"); | 139 "Tennessee", "38116", "US", "12345678901"); |
134 profile->set_guid("00000000-0000-0000-0000-000000000001"); | 140 profile->set_guid("00000000-0000-0000-0000-000000000001"); |
135 web_profiles_.push_back(profile); | 141 web_profiles_.push_back(std::move(profile)); |
136 } | 142 } |
137 if (include_server_profile) { | 143 if (include_server_profile) { |
138 AutofillProfile* profile = new AutofillProfile( | 144 std::unique_ptr<AutofillProfile> profile = |
139 AutofillProfile::SERVER_PROFILE, "server_id"); | 145 base::MakeUnique<AutofillProfile>(AutofillProfile::SERVER_PROFILE, |
140 test::SetProfileInfo(profile, "Charles", "Hardin", | 146 "server_id"); |
141 "Holley", "buddy@gmail.com", "Decca", | 147 test::SetProfileInfo(profile.get(), "Charles", "Hardin", "Holley", |
142 "123 Apple St.", "unit 6", "Lubbock", | 148 "buddy@gmail.com", "Decca", "123 Apple St.", |
143 "Texas", "79401", "US", "2345678901"); | 149 "unit 6", "Lubbock", "Texas", "79401", "US", |
| 150 "2345678901"); |
144 profile->set_guid("00000000-0000-0000-0000-000000000002"); | 151 profile->set_guid("00000000-0000-0000-0000-000000000002"); |
145 server_profiles_.push_back(profile); | 152 server_profiles_.push_back(std::move(profile)); |
146 } | 153 } |
147 Refresh(); | 154 Refresh(); |
148 } | 155 } |
149 | 156 |
150 // Removes all existing credit cards and creates 0 or 1 local profiles and | 157 // Removes all existing credit cards and creates 0 or 1 local profiles and |
151 // 0 or 1 server profile according to the paramters. | 158 // 0 or 1 server profile according to the parameters. |
152 void RecreateCreditCards(bool include_local_credit_card, | 159 void RecreateCreditCards(bool include_local_credit_card, |
153 bool include_masked_server_credit_card, | 160 bool include_masked_server_credit_card, |
154 bool include_full_server_credit_card) { | 161 bool include_full_server_credit_card) { |
155 local_credit_cards_.clear(); | 162 local_credit_cards_.clear(); |
156 server_credit_cards_.clear(); | 163 server_credit_cards_.clear(); |
157 if (include_local_credit_card) { | 164 if (include_local_credit_card) { |
158 std::unique_ptr<CreditCard> credit_card(new CreditCard( | 165 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>( |
159 "10000000-0000-0000-0000-000000000001", std::string())); | 166 "10000000-0000-0000-0000-000000000001", std::string()); |
160 test::SetCreditCardInfo(credit_card.get(), nullptr, "4111111111111111", | 167 test::SetCreditCardInfo(credit_card.get(), nullptr, "4111111111111111", |
161 "12", "24"); | 168 "12", "24"); |
162 local_credit_cards_.push_back(credit_card.release()); | 169 local_credit_cards_.push_back(std::move(credit_card)); |
163 } | 170 } |
164 if (include_masked_server_credit_card) { | 171 if (include_masked_server_credit_card) { |
165 std::unique_ptr<CreditCard> credit_card(new CreditCard( | 172 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>( |
166 CreditCard::MASKED_SERVER_CARD, "server_id")); | 173 CreditCard::MASKED_SERVER_CARD, "server_id"); |
167 credit_card->set_guid("10000000-0000-0000-0000-000000000002"); | 174 credit_card->set_guid("10000000-0000-0000-0000-000000000002"); |
168 credit_card->SetTypeForMaskedCard(kDiscoverCard); | 175 credit_card->SetTypeForMaskedCard(kDiscoverCard); |
169 server_credit_cards_.push_back(credit_card.release()); | 176 server_credit_cards_.push_back(std::move(credit_card)); |
170 } | 177 } |
171 if (include_full_server_credit_card) { | 178 if (include_full_server_credit_card) { |
172 std::unique_ptr<CreditCard> credit_card(new CreditCard( | 179 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>( |
173 CreditCard::FULL_SERVER_CARD, "server_id")); | 180 CreditCard::FULL_SERVER_CARD, "server_id"); |
174 credit_card->set_guid("10000000-0000-0000-0000-000000000003"); | 181 credit_card->set_guid("10000000-0000-0000-0000-000000000003"); |
175 server_credit_cards_.push_back(credit_card.release()); | 182 server_credit_cards_.push_back(std::move(credit_card)); |
176 } | 183 } |
177 Refresh(); | 184 Refresh(); |
178 } | 185 } |
179 | 186 |
180 bool IsAutofillEnabled() const override { return autofill_enabled_; } | 187 bool IsAutofillEnabled() const override { return autofill_enabled_; } |
181 | 188 |
182 private: | 189 private: |
183 void CreateTestAutofillProfiles(ScopedVector<AutofillProfile>* profiles) { | 190 void CreateTestAutofillProfiles( |
184 AutofillProfile* profile = new AutofillProfile; | 191 std::vector<std::unique_ptr<AutofillProfile>>* profiles) { |
185 test::SetProfileInfo(profile, "Elvis", "Aaron", | 192 std::unique_ptr<AutofillProfile> profile = |
186 "Presley", "theking@gmail.com", "RCA", | 193 base::MakeUnique<AutofillProfile>(); |
187 "3734 Elvis Presley Blvd.", "Apt. 10", | 194 test::SetProfileInfo(profile.get(), "Elvis", "Aaron", "Presley", |
188 "Memphis", "Tennessee", "38116", "US", | 195 "theking@gmail.com", "RCA", "3734 Elvis Presley Blvd.", |
| 196 "Apt. 10", "Memphis", "Tennessee", "38116", "US", |
189 "12345678901"); | 197 "12345678901"); |
190 profile->set_guid("00000000-0000-0000-0000-000000000001"); | 198 profile->set_guid("00000000-0000-0000-0000-000000000001"); |
191 profiles->push_back(profile); | 199 profiles->push_back(std::move(profile)); |
192 profile = new AutofillProfile; | 200 profile = base::MakeUnique<AutofillProfile>(); |
193 test::SetProfileInfo(profile, "Charles", "Hardin", | 201 test::SetProfileInfo(profile.get(), "Charles", "Hardin", "Holley", |
194 "Holley", "buddy@gmail.com", "Decca", | 202 "buddy@gmail.com", "Decca", "123 Apple St.", "unit 6", |
195 "123 Apple St.", "unit 6", "Lubbock", | 203 "Lubbock", "Texas", "79401", "US", "2345678901"); |
196 "Texas", "79401", "US", "2345678901"); | |
197 profile->set_guid("00000000-0000-0000-0000-000000000002"); | 204 profile->set_guid("00000000-0000-0000-0000-000000000002"); |
198 profiles->push_back(profile); | 205 profiles->push_back(std::move(profile)); |
199 } | 206 } |
200 | 207 |
201 bool autofill_enabled_; | 208 bool autofill_enabled_; |
202 | 209 |
203 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); | 210 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); |
204 }; | 211 }; |
205 | 212 |
206 class TestFormStructure : public FormStructure { | 213 class TestFormStructure : public FormStructure { |
207 public: | 214 public: |
208 explicit TestFormStructure(const FormData& form) : FormStructure(form) {} | 215 explicit TestFormStructure(const FormData& form) : FormStructure(form) {} |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 } | 250 } |
244 | 251 |
245 void AddSeenForm(const FormData& form, | 252 void AddSeenForm(const FormData& form, |
246 const std::vector<ServerFieldType>& heuristic_types, | 253 const std::vector<ServerFieldType>& heuristic_types, |
247 const std::vector<ServerFieldType>& server_types) { | 254 const std::vector<ServerFieldType>& server_types) { |
248 FormData empty_form = form; | 255 FormData empty_form = form; |
249 for (size_t i = 0; i < empty_form.fields.size(); ++i) { | 256 for (size_t i = 0; i < empty_form.fields.size(); ++i) { |
250 empty_form.fields[i].value = base::string16(); | 257 empty_form.fields[i].value = base::string16(); |
251 } | 258 } |
252 | 259 |
253 // |form_structure| will be owned by |form_structures()|. | 260 std::unique_ptr<TestFormStructure> form_structure = |
254 TestFormStructure* form_structure = new TestFormStructure(empty_form); | 261 base::MakeUnique<TestFormStructure>(empty_form); |
255 form_structure->SetFieldTypes(heuristic_types, server_types); | 262 form_structure->SetFieldTypes(heuristic_types, server_types); |
256 form_structures()->push_back(form_structure); | 263 form_structures()->push_back(std::move(form_structure)); |
257 } | 264 } |
258 | 265 |
259 // Calls AutofillManager::OnWillSubmitForm and waits for it to complete. | 266 // Calls AutofillManager::OnWillSubmitForm and waits for it to complete. |
260 void WillSubmitForm(const FormData& form, const TimeTicks& timestamp) { | 267 void WillSubmitForm(const FormData& form, const TimeTicks& timestamp) { |
261 ResetRunLoop(); | 268 ResetRunLoop(); |
262 if (!OnWillSubmitForm(form, timestamp)) | 269 if (!OnWillSubmitForm(form, timestamp)) |
263 return; | 270 return; |
264 | 271 |
265 // Wait for the asynchronous OnWillSubmitForm() call to complete. | 272 // Wait for the asynchronous OnWillSubmitForm() call to complete. |
266 RunRunLoop(); | 273 RunRunLoop(); |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 // Heuristic value will be unknown. | 737 // Heuristic value will be unknown. |
731 test::CreateTestFormField("Garbage label", "garbage", "", "text", &field); | 738 test::CreateTestFormField("Garbage label", "garbage", "", "text", &field); |
732 field.autocomplete_attribute = "postal-code"; | 739 field.autocomplete_attribute = "postal-code"; |
733 form.fields.push_back(field); | 740 form.fields.push_back(field); |
734 | 741 |
735 // No autocomplete attribute. No metric logged. | 742 // No autocomplete attribute. No metric logged. |
736 test::CreateTestFormField("Address", "address", "", "text", &field); | 743 test::CreateTestFormField("Address", "address", "", "text", &field); |
737 field.autocomplete_attribute = ""; | 744 field.autocomplete_attribute = ""; |
738 form.fields.push_back(field); | 745 form.fields.push_back(field); |
739 | 746 |
740 TestFormStructure* form_structure = new TestFormStructure(form); | 747 std::unique_ptr<TestFormStructure> form_structure = |
| 748 base::MakeUnique<TestFormStructure>(form); |
| 749 TestFormStructure* form_structure_ptr = form_structure.get(); |
741 form_structure->DetermineHeuristicTypes(); | 750 form_structure->DetermineHeuristicTypes(); |
742 autofill_manager_->form_structures()->push_back(form_structure); | 751 autofill_manager_->form_structures()->push_back(std::move(form_structure)); |
743 | 752 |
744 AutofillQueryResponseContents response; | 753 AutofillQueryResponseContents response; |
745 // Server response will match with autocomplete. | 754 // Server response will match with autocomplete. |
746 response.add_field()->set_autofill_type(NAME_LAST); | 755 response.add_field()->set_autofill_type(NAME_LAST); |
747 // Server response will NOT match with autocomplete. | 756 // Server response will NOT match with autocomplete. |
748 response.add_field()->set_autofill_type(NAME_FIRST); | 757 response.add_field()->set_autofill_type(NAME_FIRST); |
749 // Server response will have no data. | 758 // Server response will have no data. |
750 response.add_field()->set_autofill_type(NO_SERVER_DATA); | 759 response.add_field()->set_autofill_type(NO_SERVER_DATA); |
751 // Not logged. | 760 // Not logged. |
752 response.add_field()->set_autofill_type(NAME_MIDDLE); | 761 response.add_field()->set_autofill_type(NAME_MIDDLE); |
753 | 762 |
754 std::string response_string; | 763 std::string response_string; |
755 ASSERT_TRUE(response.SerializeToString(&response_string)); | 764 ASSERT_TRUE(response.SerializeToString(&response_string)); |
756 | 765 |
757 std::vector<std::string> signatures; | 766 std::vector<std::string> signatures; |
758 signatures.push_back(form_structure->FormSignatureAsStr()); | 767 signatures.push_back(form_structure_ptr->FormSignatureAsStr()); |
759 | 768 |
760 base::HistogramTester histogram_tester; | 769 base::HistogramTester histogram_tester; |
761 autofill_manager_->OnLoadedServerPredictions(response_string, signatures); | 770 autofill_manager_->OnLoadedServerPredictions(response_string, signatures); |
762 | 771 |
763 // Verify that FormStructure::ParseQueryResponse was called (here and below). | 772 // Verify that FormStructure::ParseQueryResponse was called (here and below). |
764 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse", | 773 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse", |
765 AutofillMetrics::QUERY_RESPONSE_RECEIVED, | 774 AutofillMetrics::QUERY_RESPONSE_RECEIVED, |
766 1); | 775 1); |
767 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse", | 776 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse", |
768 AutofillMetrics::QUERY_RESPONSE_PARSED, 1); | 777 AutofillMetrics::QUERY_RESPONSE_PARSED, 1); |
769 | 778 |
770 // Autocomplete-derived types are eventually what's inferred. | 779 // Autocomplete-derived types are eventually what's inferred. |
771 EXPECT_EQ(NAME_LAST, form_structure->field(0)->Type().GetStorableType()); | 780 EXPECT_EQ(NAME_LAST, form_structure_ptr->field(0)->Type().GetStorableType()); |
772 EXPECT_EQ(NAME_MIDDLE, form_structure->field(1)->Type().GetStorableType()); | 781 EXPECT_EQ(NAME_MIDDLE, |
| 782 form_structure_ptr->field(1)->Type().GetStorableType()); |
773 EXPECT_EQ(ADDRESS_HOME_ZIP, | 783 EXPECT_EQ(ADDRESS_HOME_ZIP, |
774 form_structure->field(2)->Type().GetStorableType()); | 784 form_structure_ptr->field(2)->Type().GetStorableType()); |
775 | 785 |
776 // Heuristic predictions. | 786 // Heuristic predictions. |
777 // Unknown: | 787 // Unknown: |
778 histogram_tester.ExpectBucketCount( | 788 histogram_tester.ExpectBucketCount( |
779 "Autofill.Quality.HeuristicType.BasedOnAutocomplete", | 789 "Autofill.Quality.HeuristicType.BasedOnAutocomplete", |
780 AutofillMetrics::TYPE_UNKNOWN, 1); | 790 AutofillMetrics::TYPE_UNKNOWN, 1); |
781 histogram_tester.ExpectBucketCount( | 791 histogram_tester.ExpectBucketCount( |
782 "Autofill.Quality.HeuristicType.ByFieldType.BasedOnAutocomplete", | 792 "Autofill.Quality.HeuristicType.ByFieldType.BasedOnAutocomplete", |
783 GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP, AutofillMetrics::TYPE_UNKNOWN), | 793 GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP, AutofillMetrics::TYPE_UNKNOWN), |
784 1); | 794 1); |
(...skipping 3209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3994 field.form_control_type = "text"; | 4004 field.form_control_type = "text"; |
3995 | 4005 |
3996 field.label = ASCIIToUTF16("fullname"); | 4006 field.label = ASCIIToUTF16("fullname"); |
3997 field.name = ASCIIToUTF16("fullname"); | 4007 field.name = ASCIIToUTF16("fullname"); |
3998 form.fields.push_back(field); | 4008 form.fields.push_back(field); |
3999 | 4009 |
4000 field.label = ASCIIToUTF16("address"); | 4010 field.label = ASCIIToUTF16("address"); |
4001 field.name = ASCIIToUTF16("address"); | 4011 field.name = ASCIIToUTF16("address"); |
4002 form.fields.push_back(field); | 4012 form.fields.push_back(field); |
4003 | 4013 |
4004 // Checkable fields should be ignored in parsing | 4014 // Checkable fields should be ignored in parsing. |
4005 FormFieldData checkable_field; | 4015 FormFieldData checkable_field; |
4006 checkable_field.label = ASCIIToUTF16("radio_button"); | 4016 checkable_field.label = ASCIIToUTF16("radio_button"); |
4007 checkable_field.form_control_type = "radio"; | 4017 checkable_field.form_control_type = "radio"; |
4008 checkable_field.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED; | 4018 checkable_field.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED; |
4009 form.fields.push_back(checkable_field); | 4019 form.fields.push_back(checkable_field); |
4010 | 4020 |
4011 forms_.push_back(new FormStructure(form)); | 4021 owned_forms_.push_back(base::MakeUnique<FormStructure>(form)); |
| 4022 forms_.push_back(owned_forms_.back().get()); |
4012 | 4023 |
4013 field.label = ASCIIToUTF16("email"); | 4024 field.label = ASCIIToUTF16("email"); |
4014 field.name = ASCIIToUTF16("email"); | 4025 field.name = ASCIIToUTF16("email"); |
4015 form.fields.push_back(field); | 4026 form.fields.push_back(field); |
4016 | 4027 |
4017 field.label = ASCIIToUTF16("password"); | 4028 field.label = ASCIIToUTF16("password"); |
4018 field.name = ASCIIToUTF16("password"); | 4029 field.name = ASCIIToUTF16("password"); |
4019 field.form_control_type = "password"; | 4030 field.form_control_type = "password"; |
4020 form.fields.push_back(field); | 4031 form.fields.push_back(field); |
4021 | 4032 |
4022 forms_.push_back(new FormStructure(form)); | 4033 owned_forms_.push_back(base::MakeUnique<FormStructure>(form)); |
| 4034 forms_.push_back(owned_forms_.back().get()); |
4023 } | 4035 } |
4024 | 4036 |
4025 protected: | 4037 protected: |
4026 TestRapporService rappor_service_; | 4038 TestRapporService rappor_service_; |
4027 ScopedVector<FormStructure> forms_; | 4039 std::vector<std::unique_ptr<FormStructure>> owned_forms_; |
| 4040 std::vector<FormStructure*> forms_; |
4028 }; | 4041 }; |
4029 | 4042 |
4030 TEST_F(AutofillMetricsParseQueryResponseTest, ServerHasData) { | 4043 TEST_F(AutofillMetricsParseQueryResponseTest, ServerHasData) { |
4031 AutofillQueryResponseContents response; | 4044 AutofillQueryResponseContents response; |
4032 response.add_field()->set_autofill_type(7); | 4045 response.add_field()->set_autofill_type(7); |
4033 response.add_field()->set_autofill_type(30); | 4046 response.add_field()->set_autofill_type(30); |
4034 response.add_field()->set_autofill_type(9); | 4047 response.add_field()->set_autofill_type(9); |
4035 response.add_field()->set_autofill_type(0); | 4048 response.add_field()->set_autofill_type(0); |
4036 | 4049 |
4037 std::string response_string; | 4050 std::string response_string; |
4038 ASSERT_TRUE(response.SerializeToString(&response_string)); | 4051 ASSERT_TRUE(response.SerializeToString(&response_string)); |
4039 | 4052 |
4040 base::HistogramTester histogram_tester; | 4053 base::HistogramTester histogram_tester; |
4041 FormStructure::ParseQueryResponse(response_string, forms_.get(), | 4054 FormStructure::ParseQueryResponse(response_string, forms_, &rappor_service_); |
4042 &rappor_service_); | |
4043 EXPECT_THAT( | 4055 EXPECT_THAT( |
4044 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), | 4056 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), |
4045 ElementsAre(Bucket(true, 2))); | 4057 ElementsAre(Bucket(true, 2))); |
4046 | 4058 |
4047 // No RAPPOR metrics are logged in the case there is server data available for | 4059 // No RAPPOR metrics are logged in the case there is server data available for |
4048 // all forms. | 4060 // all forms. |
4049 EXPECT_EQ(0, rappor_service_.GetReportsCount()); | 4061 EXPECT_EQ(0, rappor_service_.GetReportsCount()); |
4050 } | 4062 } |
4051 | 4063 |
4052 // If the server returns NO_SERVER_DATA for one of the forms, expect RAPPOR | 4064 // If the server returns NO_SERVER_DATA for one of the forms, expect RAPPOR |
4053 // logging. | 4065 // logging. |
4054 TEST_F(AutofillMetricsParseQueryResponseTest, OneFormNoServerData) { | 4066 TEST_F(AutofillMetricsParseQueryResponseTest, OneFormNoServerData) { |
4055 AutofillQueryResponseContents response; | 4067 AutofillQueryResponseContents response; |
4056 response.add_field()->set_autofill_type(0); | 4068 response.add_field()->set_autofill_type(0); |
4057 response.add_field()->set_autofill_type(0); | 4069 response.add_field()->set_autofill_type(0); |
4058 response.add_field()->set_autofill_type(9); | 4070 response.add_field()->set_autofill_type(9); |
4059 response.add_field()->set_autofill_type(0); | 4071 response.add_field()->set_autofill_type(0); |
4060 | 4072 |
4061 std::string response_string; | 4073 std::string response_string; |
4062 ASSERT_TRUE(response.SerializeToString(&response_string)); | 4074 ASSERT_TRUE(response.SerializeToString(&response_string)); |
4063 | 4075 |
4064 base::HistogramTester histogram_tester; | 4076 base::HistogramTester histogram_tester; |
4065 FormStructure::ParseQueryResponse(response_string, forms_.get(), | 4077 FormStructure::ParseQueryResponse(response_string, forms_, &rappor_service_); |
4066 &rappor_service_); | |
4067 EXPECT_THAT( | 4078 EXPECT_THAT( |
4068 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), | 4079 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), |
4069 ElementsAre(Bucket(false, 1), Bucket(true, 1))); | 4080 ElementsAre(Bucket(false, 1), Bucket(true, 1))); |
4070 | 4081 |
4071 EXPECT_EQ(1, rappor_service_.GetReportsCount()); | 4082 EXPECT_EQ(1, rappor_service_.GetReportsCount()); |
4072 std::string sample; | 4083 std::string sample; |
4073 rappor::RapporType type; | 4084 rappor::RapporType type; |
4074 EXPECT_TRUE(rappor_service_.GetRecordedSampleForMetric( | 4085 EXPECT_TRUE(rappor_service_.GetRecordedSampleForMetric( |
4075 "Autofill.QueryResponseHasNoServerDataForForm", &sample, &type)); | 4086 "Autofill.QueryResponseHasNoServerDataForForm", &sample, &type)); |
4076 EXPECT_EQ("foo.com", sample); | 4087 EXPECT_EQ("foo.com", sample); |
4077 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | 4088 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
4078 } | 4089 } |
4079 | 4090 |
4080 // If the server returns NO_SERVER_DATA for both of the forms, expect RAPPOR | 4091 // If the server returns NO_SERVER_DATA for both of the forms, expect RAPPOR |
4081 // logging. | 4092 // logging. |
4082 TEST_F(AutofillMetricsParseQueryResponseTest, AllFormsNoServerData) { | 4093 TEST_F(AutofillMetricsParseQueryResponseTest, AllFormsNoServerData) { |
4083 AutofillQueryResponseContents response; | 4094 AutofillQueryResponseContents response; |
4084 for (int i = 0; i < 4; ++i) { | 4095 for (int i = 0; i < 4; ++i) { |
4085 response.add_field()->set_autofill_type(0); | 4096 response.add_field()->set_autofill_type(0); |
4086 } | 4097 } |
4087 | 4098 |
4088 std::string response_string; | 4099 std::string response_string; |
4089 ASSERT_TRUE(response.SerializeToString(&response_string)); | 4100 ASSERT_TRUE(response.SerializeToString(&response_string)); |
4090 | 4101 |
4091 base::HistogramTester histogram_tester; | 4102 base::HistogramTester histogram_tester; |
4092 FormStructure::ParseQueryResponse(response_string, forms_.get(), | 4103 FormStructure::ParseQueryResponse(response_string, forms_, &rappor_service_); |
4093 &rappor_service_); | |
4094 EXPECT_THAT( | 4104 EXPECT_THAT( |
4095 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), | 4105 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), |
4096 ElementsAre(Bucket(false, 2))); | 4106 ElementsAre(Bucket(false, 2))); |
4097 | 4107 |
4098 // Even though both forms are logging to RAPPOR, there is only one sample for | 4108 // Even though both forms are logging to RAPPOR, there is only one sample for |
4099 // a given eTLD+1. | 4109 // a given eTLD+1. |
4100 EXPECT_EQ(1, rappor_service_.GetReportsCount()); | 4110 EXPECT_EQ(1, rappor_service_.GetReportsCount()); |
4101 std::string sample; | 4111 std::string sample; |
4102 rappor::RapporType type; | 4112 rappor::RapporType type; |
4103 EXPECT_TRUE(rappor_service_.GetRecordedSampleForMetric( | 4113 EXPECT_TRUE(rappor_service_.GetRecordedSampleForMetric( |
4104 "Autofill.QueryResponseHasNoServerDataForForm", &sample, &type)); | 4114 "Autofill.QueryResponseHasNoServerDataForForm", &sample, &type)); |
4105 EXPECT_EQ("foo.com", sample); | 4115 EXPECT_EQ("foo.com", sample); |
4106 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | 4116 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
4107 } | 4117 } |
4108 | 4118 |
4109 // If the server returns NO_SERVER_DATA for only some of the fields, expect no | 4119 // If the server returns NO_SERVER_DATA for only some of the fields, expect no |
4110 // RAPPOR logging, and expect the UMA metric to say there is data. | 4120 // RAPPOR logging, and expect the UMA metric to say there is data. |
4111 TEST_F(AutofillMetricsParseQueryResponseTest, PartialNoServerData) { | 4121 TEST_F(AutofillMetricsParseQueryResponseTest, PartialNoServerData) { |
4112 AutofillQueryResponseContents response; | 4122 AutofillQueryResponseContents response; |
4113 response.add_field()->set_autofill_type(0); | 4123 response.add_field()->set_autofill_type(0); |
4114 response.add_field()->set_autofill_type(10); | 4124 response.add_field()->set_autofill_type(10); |
4115 response.add_field()->set_autofill_type(0); | 4125 response.add_field()->set_autofill_type(0); |
4116 response.add_field()->set_autofill_type(11); | 4126 response.add_field()->set_autofill_type(11); |
4117 | 4127 |
4118 std::string response_string; | 4128 std::string response_string; |
4119 ASSERT_TRUE(response.SerializeToString(&response_string)); | 4129 ASSERT_TRUE(response.SerializeToString(&response_string)); |
4120 | 4130 |
4121 base::HistogramTester histogram_tester; | 4131 base::HistogramTester histogram_tester; |
4122 FormStructure::ParseQueryResponse(response_string, forms_.get(), | 4132 FormStructure::ParseQueryResponse(response_string, forms_, &rappor_service_); |
4123 &rappor_service_); | |
4124 EXPECT_THAT( | 4133 EXPECT_THAT( |
4125 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), | 4134 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), |
4126 ElementsAre(Bucket(true, 2))); | 4135 ElementsAre(Bucket(true, 2))); |
4127 | 4136 |
4128 // No RAPPOR metrics are logged in the case there is at least some server data | 4137 // No RAPPOR metrics are logged in the case there is at least some server data |
4129 // available for all forms. | 4138 // available for all forms. |
4130 EXPECT_EQ(0, rappor_service_.GetReportsCount()); | 4139 EXPECT_EQ(0, rappor_service_.GetReportsCount()); |
4131 } | 4140 } |
4132 | 4141 |
4133 } // namespace autofill | 4142 } // namespace autofill |
OLD | NEW |