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 (auto iter = profiles->begin(); iter != profiles->end(); ++iter) |
vabr (Chromium)
2016/10/14 07:24:43
optional: Since you already change the for-loop, w
Avi (use Gerrit)
2016/10/16 20:05:53
Done.
| |
112 iter != profiles->end(); ++iter) { | 120 web_profiles_.push_back(base::MakeUnique<AutofillProfile>(*iter)); |
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 3204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3989 field.form_control_type = "text"; | 3999 field.form_control_type = "text"; |
3990 | 4000 |
3991 field.label = ASCIIToUTF16("fullname"); | 4001 field.label = ASCIIToUTF16("fullname"); |
3992 field.name = ASCIIToUTF16("fullname"); | 4002 field.name = ASCIIToUTF16("fullname"); |
3993 form.fields.push_back(field); | 4003 form.fields.push_back(field); |
3994 | 4004 |
3995 field.label = ASCIIToUTF16("address"); | 4005 field.label = ASCIIToUTF16("address"); |
3996 field.name = ASCIIToUTF16("address"); | 4006 field.name = ASCIIToUTF16("address"); |
3997 form.fields.push_back(field); | 4007 form.fields.push_back(field); |
3998 | 4008 |
3999 // Checkable fields should be ignored in parsing | 4009 // Checkable fields should be ignored in parsing. |
4000 FormFieldData checkable_field; | 4010 FormFieldData checkable_field; |
4001 checkable_field.label = ASCIIToUTF16("radio_button"); | 4011 checkable_field.label = ASCIIToUTF16("radio_button"); |
4002 checkable_field.form_control_type = "radio"; | 4012 checkable_field.form_control_type = "radio"; |
4003 checkable_field.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED; | 4013 checkable_field.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED; |
4004 form.fields.push_back(checkable_field); | 4014 form.fields.push_back(checkable_field); |
4005 | 4015 |
4006 forms_.push_back(new FormStructure(form)); | 4016 owned_forms_.push_back(base::MakeUnique<FormStructure>(form)); |
4017 forms_.push_back(owned_forms_.back().get()); | |
4007 | 4018 |
4008 field.label = ASCIIToUTF16("email"); | 4019 field.label = ASCIIToUTF16("email"); |
4009 field.name = ASCIIToUTF16("email"); | 4020 field.name = ASCIIToUTF16("email"); |
4010 form.fields.push_back(field); | 4021 form.fields.push_back(field); |
4011 | 4022 |
4012 field.label = ASCIIToUTF16("password"); | 4023 field.label = ASCIIToUTF16("password"); |
4013 field.name = ASCIIToUTF16("password"); | 4024 field.name = ASCIIToUTF16("password"); |
4014 field.form_control_type = "password"; | 4025 field.form_control_type = "password"; |
4015 form.fields.push_back(field); | 4026 form.fields.push_back(field); |
4016 | 4027 |
4017 forms_.push_back(new FormStructure(form)); | 4028 owned_forms_.push_back(base::MakeUnique<FormStructure>(form)); |
4029 forms_.push_back(owned_forms_.back().get()); | |
4018 } | 4030 } |
4019 | 4031 |
4020 protected: | 4032 protected: |
4021 TestRapporService rappor_service_; | 4033 TestRapporService rappor_service_; |
4022 ScopedVector<FormStructure> forms_; | 4034 std::vector<std::unique_ptr<FormStructure>> owned_forms_; |
4035 std::vector<FormStructure*> forms_; | |
4023 }; | 4036 }; |
4024 | 4037 |
4025 TEST_F(AutofillMetricsParseQueryResponseTest, ServerHasData) { | 4038 TEST_F(AutofillMetricsParseQueryResponseTest, ServerHasData) { |
4026 AutofillQueryResponseContents response; | 4039 AutofillQueryResponseContents response; |
4027 response.add_field()->set_autofill_type(7); | 4040 response.add_field()->set_autofill_type(7); |
4028 response.add_field()->set_autofill_type(30); | 4041 response.add_field()->set_autofill_type(30); |
4029 response.add_field()->set_autofill_type(9); | 4042 response.add_field()->set_autofill_type(9); |
4030 response.add_field()->set_autofill_type(0); | 4043 response.add_field()->set_autofill_type(0); |
4031 | 4044 |
4032 std::string response_string; | 4045 std::string response_string; |
4033 ASSERT_TRUE(response.SerializeToString(&response_string)); | 4046 ASSERT_TRUE(response.SerializeToString(&response_string)); |
4034 | 4047 |
4035 base::HistogramTester histogram_tester; | 4048 base::HistogramTester histogram_tester; |
4036 FormStructure::ParseQueryResponse(response_string, forms_.get(), | 4049 FormStructure::ParseQueryResponse(response_string, forms_, &rappor_service_); |
4037 &rappor_service_); | |
4038 EXPECT_THAT( | 4050 EXPECT_THAT( |
4039 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), | 4051 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), |
4040 ElementsAre(Bucket(true, 2))); | 4052 ElementsAre(Bucket(true, 2))); |
4041 | 4053 |
4042 // No RAPPOR metrics are logged in the case there is server data available for | 4054 // No RAPPOR metrics are logged in the case there is server data available for |
4043 // all forms. | 4055 // all forms. |
4044 EXPECT_EQ(0, rappor_service_.GetReportsCount()); | 4056 EXPECT_EQ(0, rappor_service_.GetReportsCount()); |
4045 } | 4057 } |
4046 | 4058 |
4047 // If the server returns NO_SERVER_DATA for one of the forms, expect RAPPOR | 4059 // If the server returns NO_SERVER_DATA for one of the forms, expect RAPPOR |
4048 // logging. | 4060 // logging. |
4049 TEST_F(AutofillMetricsParseQueryResponseTest, OneFormNoServerData) { | 4061 TEST_F(AutofillMetricsParseQueryResponseTest, OneFormNoServerData) { |
4050 AutofillQueryResponseContents response; | 4062 AutofillQueryResponseContents response; |
4051 response.add_field()->set_autofill_type(0); | 4063 response.add_field()->set_autofill_type(0); |
4052 response.add_field()->set_autofill_type(0); | 4064 response.add_field()->set_autofill_type(0); |
4053 response.add_field()->set_autofill_type(9); | 4065 response.add_field()->set_autofill_type(9); |
4054 response.add_field()->set_autofill_type(0); | 4066 response.add_field()->set_autofill_type(0); |
4055 | 4067 |
4056 std::string response_string; | 4068 std::string response_string; |
4057 ASSERT_TRUE(response.SerializeToString(&response_string)); | 4069 ASSERT_TRUE(response.SerializeToString(&response_string)); |
4058 | 4070 |
4059 base::HistogramTester histogram_tester; | 4071 base::HistogramTester histogram_tester; |
4060 FormStructure::ParseQueryResponse(response_string, forms_.get(), | 4072 FormStructure::ParseQueryResponse(response_string, forms_, &rappor_service_); |
4061 &rappor_service_); | |
4062 EXPECT_THAT( | 4073 EXPECT_THAT( |
4063 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), | 4074 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), |
4064 ElementsAre(Bucket(false, 1), Bucket(true, 1))); | 4075 ElementsAre(Bucket(false, 1), Bucket(true, 1))); |
4065 | 4076 |
4066 EXPECT_EQ(1, rappor_service_.GetReportsCount()); | 4077 EXPECT_EQ(1, rappor_service_.GetReportsCount()); |
4067 std::string sample; | 4078 std::string sample; |
4068 rappor::RapporType type; | 4079 rappor::RapporType type; |
4069 EXPECT_TRUE(rappor_service_.GetRecordedSampleForMetric( | 4080 EXPECT_TRUE(rappor_service_.GetRecordedSampleForMetric( |
4070 "Autofill.QueryResponseHasNoServerDataForForm", &sample, &type)); | 4081 "Autofill.QueryResponseHasNoServerDataForForm", &sample, &type)); |
4071 EXPECT_EQ("foo.com", sample); | 4082 EXPECT_EQ("foo.com", sample); |
4072 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | 4083 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
4073 } | 4084 } |
4074 | 4085 |
4075 // If the server returns NO_SERVER_DATA for both of the forms, expect RAPPOR | 4086 // If the server returns NO_SERVER_DATA for both of the forms, expect RAPPOR |
4076 // logging. | 4087 // logging. |
4077 TEST_F(AutofillMetricsParseQueryResponseTest, AllFormsNoServerData) { | 4088 TEST_F(AutofillMetricsParseQueryResponseTest, AllFormsNoServerData) { |
4078 AutofillQueryResponseContents response; | 4089 AutofillQueryResponseContents response; |
4079 for (int i = 0; i < 4; ++i) { | 4090 for (int i = 0; i < 4; ++i) { |
4080 response.add_field()->set_autofill_type(0); | 4091 response.add_field()->set_autofill_type(0); |
4081 } | 4092 } |
4082 | 4093 |
4083 std::string response_string; | 4094 std::string response_string; |
4084 ASSERT_TRUE(response.SerializeToString(&response_string)); | 4095 ASSERT_TRUE(response.SerializeToString(&response_string)); |
4085 | 4096 |
4086 base::HistogramTester histogram_tester; | 4097 base::HistogramTester histogram_tester; |
4087 FormStructure::ParseQueryResponse(response_string, forms_.get(), | 4098 FormStructure::ParseQueryResponse(response_string, forms_, &rappor_service_); |
4088 &rappor_service_); | |
4089 EXPECT_THAT( | 4099 EXPECT_THAT( |
4090 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), | 4100 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), |
4091 ElementsAre(Bucket(false, 2))); | 4101 ElementsAre(Bucket(false, 2))); |
4092 | 4102 |
4093 // Even though both forms are logging to RAPPOR, there is only one sample for | 4103 // Even though both forms are logging to RAPPOR, there is only one sample for |
4094 // a given eTLD+1. | 4104 // a given eTLD+1. |
4095 EXPECT_EQ(1, rappor_service_.GetReportsCount()); | 4105 EXPECT_EQ(1, rappor_service_.GetReportsCount()); |
4096 std::string sample; | 4106 std::string sample; |
4097 rappor::RapporType type; | 4107 rappor::RapporType type; |
4098 EXPECT_TRUE(rappor_service_.GetRecordedSampleForMetric( | 4108 EXPECT_TRUE(rappor_service_.GetRecordedSampleForMetric( |
4099 "Autofill.QueryResponseHasNoServerDataForForm", &sample, &type)); | 4109 "Autofill.QueryResponseHasNoServerDataForForm", &sample, &type)); |
4100 EXPECT_EQ("foo.com", sample); | 4110 EXPECT_EQ("foo.com", sample); |
4101 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | 4111 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
4102 } | 4112 } |
4103 | 4113 |
4104 // If the server returns NO_SERVER_DATA for only some of the fields, expect no | 4114 // If the server returns NO_SERVER_DATA for only some of the fields, expect no |
4105 // RAPPOR logging, and expect the UMA metric to say there is data. | 4115 // RAPPOR logging, and expect the UMA metric to say there is data. |
4106 TEST_F(AutofillMetricsParseQueryResponseTest, PartialNoServerData) { | 4116 TEST_F(AutofillMetricsParseQueryResponseTest, PartialNoServerData) { |
4107 AutofillQueryResponseContents response; | 4117 AutofillQueryResponseContents response; |
4108 response.add_field()->set_autofill_type(0); | 4118 response.add_field()->set_autofill_type(0); |
4109 response.add_field()->set_autofill_type(10); | 4119 response.add_field()->set_autofill_type(10); |
4110 response.add_field()->set_autofill_type(0); | 4120 response.add_field()->set_autofill_type(0); |
4111 response.add_field()->set_autofill_type(11); | 4121 response.add_field()->set_autofill_type(11); |
4112 | 4122 |
4113 std::string response_string; | 4123 std::string response_string; |
4114 ASSERT_TRUE(response.SerializeToString(&response_string)); | 4124 ASSERT_TRUE(response.SerializeToString(&response_string)); |
4115 | 4125 |
4116 base::HistogramTester histogram_tester; | 4126 base::HistogramTester histogram_tester; |
4117 FormStructure::ParseQueryResponse(response_string, forms_.get(), | 4127 FormStructure::ParseQueryResponse(response_string, forms_, &rappor_service_); |
4118 &rappor_service_); | |
4119 EXPECT_THAT( | 4128 EXPECT_THAT( |
4120 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), | 4129 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), |
4121 ElementsAre(Bucket(true, 2))); | 4130 ElementsAre(Bucket(true, 2))); |
4122 | 4131 |
4123 // No RAPPOR metrics are logged in the case there is at least some server data | 4132 // No RAPPOR metrics are logged in the case there is at least some server data |
4124 // available for all forms. | 4133 // available for all forms. |
4125 EXPECT_EQ(0, rappor_service_.GetReportsCount()); | 4134 EXPECT_EQ(0, rappor_service_.GetReportsCount()); |
4126 } | 4135 } |
4127 | 4136 |
4128 } // namespace autofill | 4137 } // namespace autofill |
OLD | NEW |