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

Side by Side Diff: chrome/browser/autofill/autofill_metrics_unittest.cc

Issue 8387016: Move some Autofill processing logic on form submit to a background thread. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Don't rely on any particular order of evaluation for the arguments to PostTaskAndReply Created 9 years, 1 month 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <vector> 5 #include <vector>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 private: 171 private:
172 std::string server_experiment_id_; 172 std::string server_experiment_id_;
173 DISALLOW_COPY_AND_ASSIGN(TestFormStructure); 173 DISALLOW_COPY_AND_ASSIGN(TestFormStructure);
174 }; 174 };
175 175
176 class TestAutofillManager : public AutofillManager { 176 class TestAutofillManager : public AutofillManager {
177 public: 177 public:
178 TestAutofillManager(TabContentsWrapper* tab_contents, 178 TestAutofillManager(TabContentsWrapper* tab_contents,
179 TestPersonalDataManager* personal_manager) 179 TestPersonalDataManager* personal_manager)
180 : AutofillManager(tab_contents, personal_manager), 180 : AutofillManager(tab_contents, personal_manager),
181 autofill_enabled_(true) { 181 autofill_enabled_(true),
182 did_finish_async_form_submit_(false),
183 message_loop_is_running_(false) {
182 set_metric_logger(new MockAutofillMetrics); 184 set_metric_logger(new MockAutofillMetrics);
183 } 185 }
184 virtual ~TestAutofillManager() {}
185 186
186 virtual bool IsAutofillEnabled() const { return autofill_enabled_; } 187 virtual bool IsAutofillEnabled() const { return autofill_enabled_; }
187 188
188 void set_autofill_enabled(bool autofill_enabled) { 189 void set_autofill_enabled(bool autofill_enabled) {
189 autofill_enabled_ = autofill_enabled; 190 autofill_enabled_ = autofill_enabled;
190 } 191 }
191 192
192 MockAutofillMetrics* metric_logger() { 193 MockAutofillMetrics* metric_logger() {
193 return static_cast<MockAutofillMetrics*>(const_cast<AutofillMetrics*>( 194 return static_cast<MockAutofillMetrics*>(const_cast<AutofillMetrics*>(
194 AutofillManager::metric_logger())); 195 AutofillManager::metric_logger()));
195 } 196 }
196 197
197 void AddSeenForm(const FormData& form, 198 void AddSeenForm(const FormData& form,
198 const std::vector<AutofillFieldType>& heuristic_types, 199 const std::vector<AutofillFieldType>& heuristic_types,
199 const std::vector<AutofillFieldType>& server_types, 200 const std::vector<AutofillFieldType>& server_types,
200 const std::string& experiment_id) { 201 const std::string& experiment_id) {
201 FormData empty_form = form; 202 FormData empty_form = form;
202 for (size_t i = 0; i < empty_form.fields.size(); ++i) { 203 for (size_t i = 0; i < empty_form.fields.size(); ++i) {
203 empty_form.fields[i].value = string16(); 204 empty_form.fields[i].value = string16();
204 } 205 }
205 206
206 // |form_structure| will be owned by |form_structures()|. 207 // |form_structure| will be owned by |form_structures()|.
207 TestFormStructure* form_structure = new TestFormStructure(empty_form); 208 TestFormStructure* form_structure = new TestFormStructure(empty_form);
208 form_structure->SetFieldTypes(heuristic_types, server_types); 209 form_structure->SetFieldTypes(heuristic_types, server_types);
209 form_structure->set_server_experiment_id(experiment_id); 210 form_structure->set_server_experiment_id(experiment_id);
210 form_structures()->push_back(form_structure); 211 form_structures()->push_back(form_structure);
211 } 212 }
212 213
214 void FormSubmitted(const FormData& form, const TimeTicks& timestamp) {
215 if (!OnFormSubmitted(form, timestamp))
216 return;
217
218 // Wait for the asynchronous FormSubmitted() call to complete.
219 if (!did_finish_async_form_submit_) {
220 // TODO(isherman): It seems silly to need this variable. Is there some
221 // way I can just query the message loop's state?
222 message_loop_is_running_ = true;
223 MessageLoop::current()->Run();
224 } else {
225 did_finish_async_form_submit_ = false;
226 }
227 }
228
229 virtual void UploadFormDataAsyncCallback(
230 const FormStructure* submitted_form,
231 const base::TimeTicks& load_time,
232 const base::TimeTicks& interaction_time,
233 const base::TimeTicks& submission_time) OVERRIDE {
234 if (message_loop_is_running_) {
235 MessageLoop::current()->Quit();
236 message_loop_is_running_ = false;
237 } else {
238 did_finish_async_form_submit_ = true;
239 }
240
241 AutofillManager::UploadFormDataAsyncCallback(submitted_form,
242 load_time,
243 interaction_time,
244 submission_time);
245 }
246
213 private: 247 private:
248 // AutofillManager is ref counted.
249 virtual ~TestAutofillManager() {}
250
214 bool autofill_enabled_; 251 bool autofill_enabled_;
252 bool did_finish_async_form_submit_;
253 bool message_loop_is_running_;
215 254
216 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); 255 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager);
217 }; 256 };
218 257
219 } // namespace 258 } // namespace
220 259
221 class AutofillMetricsTest : public TabContentsWrapperTestHarness { 260 class AutofillMetricsTest : public TabContentsWrapperTestHarness {
222 public: 261 public:
223 AutofillMetricsTest(); 262 AutofillMetricsTest();
224 virtual ~AutofillMetricsTest(); 263 virtual ~AutofillMetricsTest();
225 264
226 virtual void SetUp(); 265 virtual void SetUp() OVERRIDE;
266 virtual void TearDown() OVERRIDE;
227 267
228 protected: 268 protected:
229 AutofillCCInfoBarDelegate* CreateDelegate(MockAutofillMetrics* metric_logger, 269 AutofillCCInfoBarDelegate* CreateDelegate(MockAutofillMetrics* metric_logger,
230 CreditCard** created_card); 270 CreditCard** created_card);
231 271
232 scoped_ptr<TestAutofillManager> autofill_manager_; 272 content::TestBrowserThread ui_thread_;
273 content::TestBrowserThread file_thread_;
274
275 scoped_refptr<TestAutofillManager> autofill_manager_;
233 TestPersonalDataManager personal_data_; 276 TestPersonalDataManager personal_data_;
234 277
235 private: 278 private:
236 content::TestBrowserThread browser_thread_;
237
238 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); 279 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest);
239 }; 280 };
240 281
241 AutofillMetricsTest::AutofillMetricsTest() 282 AutofillMetricsTest::AutofillMetricsTest()
242 : TabContentsWrapperTestHarness(), 283 : TabContentsWrapperTestHarness(),
243 browser_thread_(BrowserThread::UI, &message_loop_) { 284 ui_thread_(BrowserThread::UI, &message_loop_),
285 file_thread_(BrowserThread::FILE) {
244 } 286 }
245 287
246 AutofillMetricsTest::~AutofillMetricsTest() { 288 AutofillMetricsTest::~AutofillMetricsTest() {
247 // Order of destruction is important as AutofillManager relies on 289 // Order of destruction is important as AutofillManager relies on
248 // PersonalDataManager to be around when it gets destroyed. 290 // PersonalDataManager to be around when it gets destroyed.
249 autofill_manager_.reset(NULL); 291 autofill_manager_ = NULL;
250 } 292 }
251 293
252 void AutofillMetricsTest::SetUp() { 294 void AutofillMetricsTest::SetUp() {
253 Profile* profile = new TestingProfile(); 295 Profile* profile = new TestingProfile();
254 browser_context_.reset(profile); 296 browser_context_.reset(profile);
255 PersonalDataManagerFactory::GetInstance()->SetTestingFactory( 297 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(
256 profile, TestPersonalDataManager::Build); 298 profile, TestPersonalDataManager::Build);
257 299
258 TabContentsWrapperTestHarness::SetUp(); 300 TabContentsWrapperTestHarness::SetUp();
259 autofill_manager_.reset(new TestAutofillManager(contents_wrapper(), 301 autofill_manager_ = new TestAutofillManager(contents_wrapper(),
260 &personal_data_)); 302 &personal_data_);
303
304 file_thread_.Start();
305 }
306
307 void AutofillMetricsTest::TearDown() {
308 file_thread_.Stop();
309 TabContentsWrapperTestHarness::TearDown();
261 } 310 }
262 311
263 AutofillCCInfoBarDelegate* AutofillMetricsTest::CreateDelegate( 312 AutofillCCInfoBarDelegate* AutofillMetricsTest::CreateDelegate(
264 MockAutofillMetrics* metric_logger, 313 MockAutofillMetrics* metric_logger,
265 CreditCard** created_card) { 314 CreditCard** created_card) {
266 EXPECT_CALL(*metric_logger, 315 EXPECT_CALL(*metric_logger,
267 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); 316 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
268 // The delegate created below will take ownership of this object. 317 // The delegate created below will take ownership of this object.
269 CreditCard* credit_card = new CreditCard(); 318 CreditCard* credit_card = new CreditCard();
270 if (created_card) 319 if (created_card)
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 LogOverallTypePrediction(AutofillMetrics::TYPE_MATCH, 462 LogOverallTypePrediction(AutofillMetrics::TYPE_MATCH,
414 PHONE_HOME_WHOLE_NUMBER, std::string())); 463 PHONE_HOME_WHOLE_NUMBER, std::string()));
415 EXPECT_CALL(*autofill_manager_->metric_logger(), 464 EXPECT_CALL(*autofill_manager_->metric_logger(),
416 LogQualityMetric(AutofillMetrics::FIELD_AUTOFILLED, 465 LogQualityMetric(AutofillMetrics::FIELD_AUTOFILLED,
417 std::string())); 466 std::string()));
418 EXPECT_CALL(*autofill_manager_->metric_logger(), 467 EXPECT_CALL(*autofill_manager_->metric_logger(),
419 LogUserHappinessMetric( 468 LogUserHappinessMetric(
420 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME)); 469 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME));
421 470
422 // Simulate form submission. 471 // Simulate form submission.
423 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form, 472 EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form,
424 TimeTicks::Now())); 473 TimeTicks::Now()));
425 } 474 }
426 475
427 // Test that we log the appropriate additional metrics when Autofill failed. 476 // Test that we log the appropriate additional metrics when Autofill failed.
428 TEST_F(AutofillMetricsTest, QualityMetricsForFailure) { 477 TEST_F(AutofillMetricsTest, QualityMetricsForFailure) {
429 // Set up our form data. 478 // Set up our form data.
430 FormData form; 479 FormData form;
431 form.name = ASCIIToUTF16("TestForm"); 480 form.name = ASCIIToUTF16("TestForm");
432 form.method = ASCIIToUTF16("POST"); 481 form.method = ASCIIToUTF16("POST");
433 form.origin = GURL("http://example.com/form.html"); 482 form.origin = GURL("http://example.com/form.html");
434 form.action = GURL("http://example.com/submit.html"); 483 form.action = GURL("http://example.com/submit.html");
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 std::string())); 580 std::string()));
532 EXPECT_CALL(*autofill_manager_->metric_logger(), 581 EXPECT_CALL(*autofill_manager_->metric_logger(),
533 LogQualityMetric(failure_cases[i].heuristic_metric, 582 LogQualityMetric(failure_cases[i].heuristic_metric,
534 std::string())); 583 std::string()));
535 EXPECT_CALL(*autofill_manager_->metric_logger(), 584 EXPECT_CALL(*autofill_manager_->metric_logger(),
536 LogQualityMetric(failure_cases[i].server_metric, 585 LogQualityMetric(failure_cases[i].server_metric,
537 std::string())); 586 std::string()));
538 } 587 }
539 588
540 // Simulate form submission. 589 // Simulate form submission.
541 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form, 590 EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form,
542 TimeTicks::Now())); 591 TimeTicks::Now()));
543 } 592 }
544 593
545 // Test that we behave sanely when the cached form differs from the submitted 594 // Test that we behave sanely when the cached form differs from the submitted
546 // one. 595 // one.
547 TEST_F(AutofillMetricsTest, SaneMetricsWithCacheMismatch) { 596 TEST_F(AutofillMetricsTest, SaneMetricsWithCacheMismatch) {
548 // Set up our form data. 597 // Set up our form data.
549 FormData form; 598 FormData form;
550 form.name = ASCIIToUTF16("TestForm"); 599 form.name = ASCIIToUTF16("TestForm");
551 form.method = ASCIIToUTF16("POST"); 600 form.method = ASCIIToUTF16("POST");
552 form.origin = GURL("http://example.com/form.html"); 601 form.origin = GURL("http://example.com/form.html");
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 LogServerTypePrediction(AutofillMetrics::TYPE_MATCH, 738 LogServerTypePrediction(AutofillMetrics::TYPE_MATCH,
690 NAME_FULL, std::string())); 739 NAME_FULL, std::string()));
691 EXPECT_CALL(*autofill_manager_->metric_logger(), 740 EXPECT_CALL(*autofill_manager_->metric_logger(),
692 LogOverallTypePrediction(AutofillMetrics::TYPE_MATCH, 741 LogOverallTypePrediction(AutofillMetrics::TYPE_MATCH,
693 NAME_FULL, std::string())); 742 NAME_FULL, std::string()));
694 EXPECT_CALL(*autofill_manager_->metric_logger(), 743 EXPECT_CALL(*autofill_manager_->metric_logger(),
695 LogQualityMetric(AutofillMetrics::FIELD_AUTOFILLED, 744 LogQualityMetric(AutofillMetrics::FIELD_AUTOFILLED,
696 std::string())); 745 std::string()));
697 746
698 // Simulate form submission. 747 // Simulate form submission.
699 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form, 748 EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form,
700 TimeTicks::Now())); 749 TimeTicks::Now()));
701 } 750 }
702 751
703 // Test that we don't log quality metrics for non-autofillable forms. 752 // Test that we don't log quality metrics for non-autofillable forms.
704 TEST_F(AutofillMetricsTest, NoQualityMetricsForNonAutofillableForms) { 753 TEST_F(AutofillMetricsTest, NoQualityMetricsForNonAutofillableForms) {
705 // Forms must include at least three fields to be auto-fillable. 754 // Forms must include at least three fields to be auto-fillable.
706 FormData form; 755 FormData form;
707 form.name = ASCIIToUTF16("TestForm"); 756 form.name = ASCIIToUTF16("TestForm");
708 form.method = ASCIIToUTF16("POST"); 757 form.method = ASCIIToUTF16("POST");
709 form.origin = GURL("http://example.com/form.html"); 758 form.origin = GURL("http://example.com/form.html");
710 form.action = GURL("http://example.com/submit.html"); 759 form.action = GURL("http://example.com/submit.html");
711 form.user_submitted = true; 760 form.user_submitted = true;
712 761
713 FormField field; 762 FormField field;
714 autofill_test::CreateTestFormField( 763 autofill_test::CreateTestFormField(
715 "Autofilled", "autofilled", "Elvis Presley", "text", &field); 764 "Autofilled", "autofilled", "Elvis Presley", "text", &field);
716 field.is_autofilled = true; 765 field.is_autofilled = true;
717 form.fields.push_back(field); 766 form.fields.push_back(field);
718 autofill_test::CreateTestFormField( 767 autofill_test::CreateTestFormField(
719 "Autofill Failed", "autofillfailed", "buddy@gmail.com", "text", &field); 768 "Autofill Failed", "autofillfailed", "buddy@gmail.com", "text", &field);
720 form.fields.push_back(field); 769 form.fields.push_back(field);
721 770
722 // Simulate form submission. 771 // Simulate form submission.
723 EXPECT_CALL(*autofill_manager_->metric_logger(), 772 EXPECT_CALL(*autofill_manager_->metric_logger(),
724 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED, 773 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
725 std::string())).Times(0); 774 std::string())).Times(0);
726 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form, 775 EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form,
727 TimeTicks::Now())); 776 TimeTicks::Now()));
728 777
729 // Search forms are not auto-fillable. 778 // Search forms are not auto-fillable.
730 form.action = GURL("http://example.com/search?q=Elvis%20Presley"); 779 form.action = GURL("http://example.com/search?q=Elvis%20Presley");
731 autofill_test::CreateTestFormField( 780 autofill_test::CreateTestFormField(
732 "Empty", "empty", "", "text", &field); 781 "Empty", "empty", "", "text", &field);
733 form.fields.push_back(field); 782 form.fields.push_back(field);
734 783
735 // Simulate form submission. 784 // Simulate form submission.
736 EXPECT_CALL(*autofill_manager_->metric_logger(), 785 EXPECT_CALL(*autofill_manager_->metric_logger(),
737 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED, 786 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
738 std::string())).Times(0); 787 std::string())).Times(0);
739 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form, 788 EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form,
740 TimeTicks::Now())); 789 TimeTicks::Now()));
741 } 790 }
742 791
743 // Test that we recored the experiment id appropriately. 792 // Test that we recored the experiment id appropriately.
744 TEST_F(AutofillMetricsTest, QualityMetricsWithExperimentId) { 793 TEST_F(AutofillMetricsTest, QualityMetricsWithExperimentId) {
745 // Set up our form data. 794 // Set up our form data.
746 FormData form; 795 FormData form;
747 form.name = ASCIIToUTF16("TestForm"); 796 form.name = ASCIIToUTF16("TestForm");
748 form.method = ASCIIToUTF16("POST"); 797 form.method = ASCIIToUTF16("POST");
749 form.origin = GURL("http://example.com/form.html"); 798 form.origin = GURL("http://example.com/form.html");
750 form.action = GURL("http://example.com/submit.html"); 799 form.action = GURL("http://example.com/submit.html");
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 LogHeuristicTypePrediction(AutofillMetrics::TYPE_UNKNOWN, 904 LogHeuristicTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
856 ADDRESS_HOME_COUNTRY, experiment_id)); 905 ADDRESS_HOME_COUNTRY, experiment_id));
857 EXPECT_CALL(*autofill_manager_->metric_logger(), 906 EXPECT_CALL(*autofill_manager_->metric_logger(),
858 LogServerTypePrediction(AutofillMetrics::TYPE_UNKNOWN, 907 LogServerTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
859 ADDRESS_HOME_COUNTRY, experiment_id)); 908 ADDRESS_HOME_COUNTRY, experiment_id));
860 EXPECT_CALL(*autofill_manager_->metric_logger(), 909 EXPECT_CALL(*autofill_manager_->metric_logger(),
861 LogOverallTypePrediction(AutofillMetrics::TYPE_UNKNOWN, 910 LogOverallTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
862 ADDRESS_HOME_COUNTRY, experiment_id)); 911 ADDRESS_HOME_COUNTRY, experiment_id));
863 912
864 // Simulate form submission. 913 // Simulate form submission.
865 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form, 914 EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form,
866 TimeTicks::Now())); 915 TimeTicks::Now()));
867 } 916 }
868 917
869 // Test that the profile count is logged correctly. 918 // Test that the profile count is logged correctly.
870 TEST_F(AutofillMetricsTest, StoredProfileCount) { 919 TEST_F(AutofillMetricsTest, StoredProfileCount) {
871 // The metric should be logged when the profiles are first loaded. 920 // The metric should be logged when the profiles are first loaded.
872 EXPECT_CALL(*personal_data_.metric_logger(), 921 EXPECT_CALL(*personal_data_.metric_logger(),
873 LogStoredProfileCount(2)).Times(1); 922 LogStoredProfileCount(2)).Times(1);
874 personal_data_.LoadProfiles(); 923 personal_data_.LoadProfiles();
875 924
876 // The metric should only be logged once. 925 // The metric should only be logged once.
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 LogUserHappinessMetric( 1148 LogUserHappinessMetric(
1100 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME)).Times(0); 1149 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME)).Times(0);
1101 EXPECT_CALL( 1150 EXPECT_CALL(
1102 *autofill_manager_->metric_logger(), 1151 *autofill_manager_->metric_logger(),
1103 LogUserHappinessMetric( 1152 LogUserHappinessMetric(
1104 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE)).Times(0); 1153 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE)).Times(0);
1105 EXPECT_CALL( 1154 EXPECT_CALL(
1106 *autofill_manager_->metric_logger(), 1155 *autofill_manager_->metric_logger(),
1107 LogUserHappinessMetric( 1156 LogUserHappinessMetric(
1108 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM)).Times(0); 1157 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM)).Times(0);
1109 autofill_manager_->OnFormSubmitted(form, TimeTicks::Now()); 1158 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
1110 } 1159 }
1111 1160
1112 // Add more fields to the form. 1161 // Add more fields to the form.
1113 autofill_test::CreateTestFormField("Phone", "phone", "", "text", &field); 1162 autofill_test::CreateTestFormField("Phone", "phone", "", "text", &field);
1114 form.fields.push_back(field); 1163 form.fields.push_back(field);
1115 autofill_test::CreateTestFormField("Unknown", "unknown", "", "text", &field); 1164 autofill_test::CreateTestFormField("Unknown", "unknown", "", "text", &field);
1116 form.fields.push_back(field); 1165 form.fields.push_back(field);
1117 forms.front() = form; 1166 forms.front() = form;
1118 1167
1119 // Expect a notification when the form is first seen. 1168 // Expect a notification when the form is first seen.
1120 { 1169 {
1121 EXPECT_CALL(*autofill_manager_->metric_logger(), 1170 EXPECT_CALL(*autofill_manager_->metric_logger(),
1122 LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED)); 1171 LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED));
1123 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 1172 autofill_manager_->OnFormsSeen(forms, TimeTicks());
1124 } 1173 }
1125 1174
1126 // Expect a notification when the form is submitted. 1175 // Expect a notification when the form is submitted.
1127 { 1176 {
1128 EXPECT_CALL(*autofill_manager_->metric_logger(), 1177 EXPECT_CALL(*autofill_manager_->metric_logger(),
1129 LogUserHappinessMetric( 1178 LogUserHappinessMetric(
1130 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM)); 1179 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM));
1131 autofill_manager_->OnFormSubmitted(form, TimeTicks::Now()); 1180 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
1132 } 1181 }
1133 1182
1134 // Fill in two of the fields. 1183 // Fill in two of the fields.
1135 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley"); 1184 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley");
1136 form.fields[1].value = ASCIIToUTF16("theking@gmail.com"); 1185 form.fields[1].value = ASCIIToUTF16("theking@gmail.com");
1137 forms.front() = form; 1186 forms.front() = form;
1138 1187
1139 // Expect a notification when the form is submitted. 1188 // Expect a notification when the form is submitted.
1140 { 1189 {
1141 EXPECT_CALL(*autofill_manager_->metric_logger(), 1190 EXPECT_CALL(*autofill_manager_->metric_logger(),
1142 LogUserHappinessMetric( 1191 LogUserHappinessMetric(
1143 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM)); 1192 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM));
1144 autofill_manager_->OnFormSubmitted(form, TimeTicks::Now()); 1193 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
1145 } 1194 }
1146 1195
1147 // Fill in the third field. 1196 // Fill in the third field.
1148 form.fields[2].value = ASCIIToUTF16("12345678901"); 1197 form.fields[2].value = ASCIIToUTF16("12345678901");
1149 forms.front() = form; 1198 forms.front() = form;
1150 1199
1151 // Expect notifications when the form is submitted. 1200 // Expect notifications when the form is submitted.
1152 { 1201 {
1153 EXPECT_CALL(*autofill_manager_->metric_logger(), 1202 EXPECT_CALL(*autofill_manager_->metric_logger(),
1154 LogUserHappinessMetric( 1203 LogUserHappinessMetric(
1155 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE)); 1204 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE));
1156 autofill_manager_->OnFormSubmitted(form, TimeTicks::Now()); 1205 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
1157 } 1206 }
1158 1207
1159 1208
1160 // Mark one of the fields as autofilled. 1209 // Mark one of the fields as autofilled.
1161 form.fields[1].is_autofilled = true; 1210 form.fields[1].is_autofilled = true;
1162 forms.front() = form; 1211 forms.front() = form;
1163 1212
1164 // Expect notifications when the form is submitted. 1213 // Expect notifications when the form is submitted.
1165 { 1214 {
1166 EXPECT_CALL(*autofill_manager_->metric_logger(), 1215 EXPECT_CALL(*autofill_manager_->metric_logger(),
1167 LogUserHappinessMetric( 1216 LogUserHappinessMetric(
1168 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME)); 1217 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME));
1169 autofill_manager_->OnFormSubmitted(form, TimeTicks::Now()); 1218 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
1170 } 1219 }
1171 1220
1172 // Mark all of the fillable fields as autofilled. 1221 // Mark all of the fillable fields as autofilled.
1173 form.fields[0].is_autofilled = true; 1222 form.fields[0].is_autofilled = true;
1174 form.fields[2].is_autofilled = true; 1223 form.fields[2].is_autofilled = true;
1175 forms.front() = form; 1224 forms.front() = form;
1176 1225
1177 // Expect notifications when the form is submitted. 1226 // Expect notifications when the form is submitted.
1178 { 1227 {
1179 EXPECT_CALL(*autofill_manager_->metric_logger(), 1228 EXPECT_CALL(*autofill_manager_->metric_logger(),
1180 LogUserHappinessMetric( 1229 LogUserHappinessMetric(
1181 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL)); 1230 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL));
1182 autofill_manager_->OnFormSubmitted(form, TimeTicks::Now()); 1231 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
1183 } 1232 }
1184 1233
1185 // Clear out the third field's value. 1234 // Clear out the third field's value.
1186 form.fields[2].value = string16(); 1235 form.fields[2].value = string16();
1187 forms.front() = form; 1236 forms.front() = form;
1188 1237
1189 // Expect notifications when the form is submitted. 1238 // Expect notifications when the form is submitted.
1190 { 1239 {
1191 EXPECT_CALL(*autofill_manager_->metric_logger(), 1240 EXPECT_CALL(*autofill_manager_->metric_logger(),
1192 LogUserHappinessMetric( 1241 LogUserHappinessMetric(
1193 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM)); 1242 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM));
1194 autofill_manager_->OnFormSubmitted(form, TimeTicks::Now()); 1243 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
1195 } 1244 }
1196 } 1245 }
1197 1246
1198 // Verify that we correctly log user happiness metrics dealing with form 1247 // Verify that we correctly log user happiness metrics dealing with form
1199 // interaction. 1248 // interaction.
1200 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) { 1249 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) {
1201 // Load a fillable form. 1250 // Load a fillable form.
1202 FormData form; 1251 FormData form;
1203 form.name = ASCIIToUTF16("TestForm"); 1252 form.name = ASCIIToUTF16("TestForm");
1204 form.method = ASCIIToUTF16("POST"); 1253 form.method = ASCIIToUTF16("POST");
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 EXPECT_CALL(*autofill_manager_->metric_logger(), 1386 EXPECT_CALL(*autofill_manager_->metric_logger(),
1338 LogFormFillDurationFromLoadWithAutofill(_)).Times(0); 1387 LogFormFillDurationFromLoadWithAutofill(_)).Times(0);
1339 EXPECT_CALL(*autofill_manager_->metric_logger(), 1388 EXPECT_CALL(*autofill_manager_->metric_logger(),
1340 LogFormFillDurationFromLoadWithoutAutofill( 1389 LogFormFillDurationFromLoadWithoutAutofill(
1341 TimeDelta::FromInternalValue(16))); 1390 TimeDelta::FromInternalValue(16)));
1342 EXPECT_CALL(*autofill_manager_->metric_logger(), 1391 EXPECT_CALL(*autofill_manager_->metric_logger(),
1343 LogFormFillDurationFromInteractionWithAutofill(_)).Times(0); 1392 LogFormFillDurationFromInteractionWithAutofill(_)).Times(0);
1344 EXPECT_CALL(*autofill_manager_->metric_logger(), 1393 EXPECT_CALL(*autofill_manager_->metric_logger(),
1345 LogFormFillDurationFromInteractionWithoutAutofill(_)).Times(0); 1394 LogFormFillDurationFromInteractionWithoutAutofill(_)).Times(0);
1346 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 1395 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
1347 autofill_manager_->OnFormSubmitted(form, TimeTicks::FromInternalValue(17)); 1396 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1348 autofill_manager_->Reset(); 1397 autofill_manager_->Reset();
1349 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 1398 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1350 } 1399 }
1351 1400
1352 // Expect metric to be logged if the user manually edited a form field. 1401 // Expect metric to be logged if the user manually edited a form field.
1353 { 1402 {
1354 EXPECT_CALL(*autofill_manager_->metric_logger(), 1403 EXPECT_CALL(*autofill_manager_->metric_logger(),
1355 LogFormFillDurationFromLoadWithAutofill(_)).Times(0); 1404 LogFormFillDurationFromLoadWithAutofill(_)).Times(0);
1356 EXPECT_CALL(*autofill_manager_->metric_logger(), 1405 EXPECT_CALL(*autofill_manager_->metric_logger(),
1357 LogFormFillDurationFromLoadWithoutAutofill( 1406 LogFormFillDurationFromLoadWithoutAutofill(
1358 TimeDelta::FromInternalValue(16))); 1407 TimeDelta::FromInternalValue(16)));
1359 EXPECT_CALL(*autofill_manager_->metric_logger(), 1408 EXPECT_CALL(*autofill_manager_->metric_logger(),
1360 LogFormFillDurationFromInteractionWithAutofill(_)).Times(0); 1409 LogFormFillDurationFromInteractionWithAutofill(_)).Times(0);
1361 EXPECT_CALL(*autofill_manager_->metric_logger(), 1410 EXPECT_CALL(*autofill_manager_->metric_logger(),
1362 LogFormFillDurationFromInteractionWithoutAutofill( 1411 LogFormFillDurationFromInteractionWithoutAutofill(
1363 TimeDelta::FromInternalValue(14))); 1412 TimeDelta::FromInternalValue(14)));
1364 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 1413 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
1365 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 1414 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1366 TimeTicks::FromInternalValue(3)); 1415 TimeTicks::FromInternalValue(3));
1367 autofill_manager_->OnFormSubmitted(form, TimeTicks::FromInternalValue(17)); 1416 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1368 autofill_manager_->Reset(); 1417 autofill_manager_->Reset();
1369 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 1418 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1370 } 1419 }
1371 1420
1372 // Expect metric to be logged if the user autofilled the form. 1421 // Expect metric to be logged if the user autofilled the form.
1373 form.fields[0].is_autofilled = true; 1422 form.fields[0].is_autofilled = true;
1374 { 1423 {
1375 EXPECT_CALL(*autofill_manager_->metric_logger(), 1424 EXPECT_CALL(*autofill_manager_->metric_logger(),
1376 LogFormFillDurationFromLoadWithAutofill( 1425 LogFormFillDurationFromLoadWithAutofill(
1377 TimeDelta::FromInternalValue(16))); 1426 TimeDelta::FromInternalValue(16)));
1378 EXPECT_CALL(*autofill_manager_->metric_logger(), 1427 EXPECT_CALL(*autofill_manager_->metric_logger(),
1379 LogFormFillDurationFromLoadWithoutAutofill(_)).Times(0); 1428 LogFormFillDurationFromLoadWithoutAutofill(_)).Times(0);
1380 EXPECT_CALL(*autofill_manager_->metric_logger(), 1429 EXPECT_CALL(*autofill_manager_->metric_logger(),
1381 LogFormFillDurationFromInteractionWithAutofill( 1430 LogFormFillDurationFromInteractionWithAutofill(
1382 TimeDelta::FromInternalValue(12))); 1431 TimeDelta::FromInternalValue(12)));
1383 EXPECT_CALL(*autofill_manager_->metric_logger(), 1432 EXPECT_CALL(*autofill_manager_->metric_logger(),
1384 LogFormFillDurationFromInteractionWithoutAutofill(_)).Times(0); 1433 LogFormFillDurationFromInteractionWithoutAutofill(_)).Times(0);
1385 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 1434 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
1386 autofill_manager_->OnDidFillAutofillFormData( 1435 autofill_manager_->OnDidFillAutofillFormData(
1387 TimeTicks::FromInternalValue(5)); 1436 TimeTicks::FromInternalValue(5));
1388 autofill_manager_->OnFormSubmitted(form, TimeTicks::FromInternalValue(17)); 1437 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1389 autofill_manager_->Reset(); 1438 autofill_manager_->Reset();
1390 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 1439 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1391 } 1440 }
1392 1441
1393 // Expect metric to be logged if the user both manually filled some fields 1442 // Expect metric to be logged if the user both manually filled some fields
1394 // and autofilled others. Messages can arrive out of order, so make sure they 1443 // and autofilled others. Messages can arrive out of order, so make sure they
1395 // take precedence appropriately. 1444 // take precedence appropriately.
1396 { 1445 {
1397 EXPECT_CALL(*autofill_manager_->metric_logger(), 1446 EXPECT_CALL(*autofill_manager_->metric_logger(),
1398 LogFormFillDurationFromLoadWithAutofill( 1447 LogFormFillDurationFromLoadWithAutofill(
1399 TimeDelta::FromInternalValue(16))); 1448 TimeDelta::FromInternalValue(16)));
1400 EXPECT_CALL(*autofill_manager_->metric_logger(), 1449 EXPECT_CALL(*autofill_manager_->metric_logger(),
1401 LogFormFillDurationFromLoadWithoutAutofill(_)).Times(0); 1450 LogFormFillDurationFromLoadWithoutAutofill(_)).Times(0);
1402 EXPECT_CALL(*autofill_manager_->metric_logger(), 1451 EXPECT_CALL(*autofill_manager_->metric_logger(),
1403 LogFormFillDurationFromInteractionWithAutofill( 1452 LogFormFillDurationFromInteractionWithAutofill(
1404 TimeDelta::FromInternalValue(14))); 1453 TimeDelta::FromInternalValue(14)));
1405 EXPECT_CALL(*autofill_manager_->metric_logger(), 1454 EXPECT_CALL(*autofill_manager_->metric_logger(),
1406 LogFormFillDurationFromInteractionWithoutAutofill(_)).Times(0); 1455 LogFormFillDurationFromInteractionWithoutAutofill(_)).Times(0);
1407 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 1456 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
1408 autofill_manager_->OnDidFillAutofillFormData( 1457 autofill_manager_->OnDidFillAutofillFormData(
1409 TimeTicks::FromInternalValue(5)); 1458 TimeTicks::FromInternalValue(5));
1410 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 1459 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1411 TimeTicks::FromInternalValue(3)); 1460 TimeTicks::FromInternalValue(3));
1412 autofill_manager_->OnFormSubmitted(form, TimeTicks::FromInternalValue(17)); 1461 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1413 autofill_manager_->Reset(); 1462 autofill_manager_->Reset();
1414 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 1463 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1415 } 1464 }
1416 1465
1417 // Restore the global Gmock verbosity level to its default value. 1466 // Restore the global Gmock verbosity level to its default value.
1418 ::testing::FLAGS_gmock_verbose = "warning"; 1467 ::testing::FLAGS_gmock_verbose = "warning";
1419 } 1468 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_manager_unittest.cc ('k') | chrome/browser/ui/tab_contents/tab_contents_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698