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

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

Issue 7740070: Add metrics to measure time elapsed between form load and form submission with or without Autofill. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Serialize in all the right places Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
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/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/time.h"
10 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" 12 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h"
12 #include "chrome/browser/autofill/autofill_common_test.h" 13 #include "chrome/browser/autofill/autofill_common_test.h"
13 #include "chrome/browser/autofill/autofill_manager.h" 14 #include "chrome/browser/autofill/autofill_manager.h"
14 #include "chrome/browser/autofill/autofill_metrics.h" 15 #include "chrome/browser/autofill/autofill_metrics.h"
15 #include "chrome/browser/autofill/personal_data_manager.h" 16 #include "chrome/browser/autofill/personal_data_manager.h"
16 #include "chrome/browser/webdata/web_data_service.h" 17 #include "chrome/browser/webdata/web_data_service.h"
17 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" 18 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h"
18 #include "content/browser/browser_thread.h" 19 #include "content/browser/browser_thread.h"
19 #include "content/browser/tab_contents/test_tab_contents.h" 20 #include "content/browser/tab_contents/test_tab_contents.h"
20 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 #include "webkit/glue/form_data.h" 23 #include "webkit/glue/form_data.h"
23 #include "webkit/glue/form_field.h" 24 #include "webkit/glue/form_field.h"
24 25
26 using ::testing::_;
27 using ::testing::AnyNumber;
28 using ::testing::Mock;
29 using base::TimeTicks;
30 using base::TimeDelta;
25 using webkit_glue::FormData; 31 using webkit_glue::FormData;
26 using webkit_glue::FormField; 32 using webkit_glue::FormField;
27 33
28 namespace { 34 namespace {
29 35
30 class MockAutofillMetrics : public AutofillMetrics { 36 class MockAutofillMetrics : public AutofillMetrics {
31 public: 37 public:
32 MockAutofillMetrics() {} 38 MockAutofillMetrics() {}
33 MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric)); 39 MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric));
34 MOCK_CONST_METHOD3(LogHeuristicTypePrediction, 40 MOCK_CONST_METHOD3(LogHeuristicTypePrediction,
35 void(FieldTypeQualityMetric metric, 41 void(FieldTypeQualityMetric metric,
36 AutofillFieldType field_type, 42 AutofillFieldType field_type,
37 const std::string& experiment_id)); 43 const std::string& experiment_id));
38 MOCK_CONST_METHOD3(LogOverallTypePrediction, 44 MOCK_CONST_METHOD3(LogOverallTypePrediction,
39 void(FieldTypeQualityMetric metric, 45 void(FieldTypeQualityMetric metric,
40 AutofillFieldType field_type, 46 AutofillFieldType field_type,
41 const std::string& experiment_id)); 47 const std::string& experiment_id));
42 MOCK_CONST_METHOD3(LogServerTypePrediction, 48 MOCK_CONST_METHOD3(LogServerTypePrediction,
43 void(FieldTypeQualityMetric metric, 49 void(FieldTypeQualityMetric metric,
44 AutofillFieldType field_type, 50 AutofillFieldType field_type,
45 const std::string& experiment_id)); 51 const std::string& experiment_id));
46 MOCK_CONST_METHOD2(LogQualityMetric, void(QualityMetric metric, 52 MOCK_CONST_METHOD2(LogQualityMetric, void(QualityMetric metric,
47 const std::string& experiment_id)); 53 const std::string& experiment_id));
48 MOCK_CONST_METHOD1(LogServerQueryMetric, void(ServerQueryMetric metric)); 54 MOCK_CONST_METHOD1(LogServerQueryMetric, void(ServerQueryMetric metric));
49 MOCK_CONST_METHOD1(LogUserHappinessMetric, void(UserHappinessMetric metric)); 55 MOCK_CONST_METHOD1(LogUserHappinessMetric, void(UserHappinessMetric metric));
56 MOCK_CONST_METHOD1(LogAutofilledFormSubmittedAfterDuration,
57 void(const TimeDelta& duration));
58 MOCK_CONST_METHOD1(LogNonAutofilledFormSubmittedAfterDuration,
59 void(const TimeDelta& duration));
50 MOCK_CONST_METHOD1(LogIsAutofillEnabledAtPageLoad, void(bool enabled)); 60 MOCK_CONST_METHOD1(LogIsAutofillEnabledAtPageLoad, void(bool enabled));
51 MOCK_CONST_METHOD1(LogIsAutofillEnabledAtStartup, void(bool enabled)); 61 MOCK_CONST_METHOD1(LogIsAutofillEnabledAtStartup, void(bool enabled));
52 MOCK_CONST_METHOD1(LogStoredProfileCount, void(size_t num_profiles)); 62 MOCK_CONST_METHOD1(LogStoredProfileCount, void(size_t num_profiles));
53 MOCK_CONST_METHOD1(LogAddressSuggestionsCount, void(size_t num_suggestions)); 63 MOCK_CONST_METHOD1(LogAddressSuggestionsCount, void(size_t num_suggestions));
54 MOCK_CONST_METHOD1(LogServerExperimentIdForQuery, 64 MOCK_CONST_METHOD1(LogServerExperimentIdForQuery,
55 void(const std::string& experiment_id)); 65 void(const std::string& experiment_id));
56 MOCK_CONST_METHOD1(LogServerExperimentIdForUpload, 66 MOCK_CONST_METHOD1(LogServerExperimentIdForUpload,
57 void(const std::string& experiment_id)); 67 void(const std::string& experiment_id));
58 68
59 private: 69 private:
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 set_metric_logger(new MockAutofillMetrics); 172 set_metric_logger(new MockAutofillMetrics);
163 } 173 }
164 virtual ~TestAutofillManager() {} 174 virtual ~TestAutofillManager() {}
165 175
166 virtual bool IsAutofillEnabled() const { return autofill_enabled_; } 176 virtual bool IsAutofillEnabled() const { return autofill_enabled_; }
167 177
168 void set_autofill_enabled(bool autofill_enabled) { 178 void set_autofill_enabled(bool autofill_enabled) {
169 autofill_enabled_ = autofill_enabled; 179 autofill_enabled_ = autofill_enabled;
170 } 180 }
171 181
172 const MockAutofillMetrics* metric_logger() const { 182 MockAutofillMetrics* metric_logger() {
173 return static_cast<const MockAutofillMetrics*>( 183 return static_cast<MockAutofillMetrics*>(const_cast<AutofillMetrics*>(
174 AutofillManager::metric_logger()); 184 AutofillManager::metric_logger()));
175 } 185 }
176 186
177 void AddSeenForm(const FormData& form, 187 void AddSeenForm(const FormData& form,
178 const std::vector<AutofillFieldType>& heuristic_types, 188 const std::vector<AutofillFieldType>& heuristic_types,
179 const std::vector<AutofillFieldType>& server_types, 189 const std::vector<AutofillFieldType>& server_types,
180 const std::string& experiment_id) { 190 const std::string& experiment_id) {
181 FormData empty_form = form; 191 FormData empty_form = form;
182 for (size_t i = 0; i < empty_form.fields.size(); ++i) { 192 for (size_t i = 0; i < empty_form.fields.size(); ++i) {
183 empty_form.fields[i].value = string16(); 193 empty_form.fields[i].value = string16();
184 } 194 }
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 LogOverallTypePrediction(AutofillMetrics::TYPE_MATCH, 398 LogOverallTypePrediction(AutofillMetrics::TYPE_MATCH,
389 PHONE_HOME_WHOLE_NUMBER, std::string())); 399 PHONE_HOME_WHOLE_NUMBER, std::string()));
390 EXPECT_CALL(*autofill_manager_->metric_logger(), 400 EXPECT_CALL(*autofill_manager_->metric_logger(),
391 LogQualityMetric(AutofillMetrics::FIELD_AUTOFILLED, 401 LogQualityMetric(AutofillMetrics::FIELD_AUTOFILLED,
392 std::string())); 402 std::string()));
393 EXPECT_CALL(*autofill_manager_->metric_logger(), 403 EXPECT_CALL(*autofill_manager_->metric_logger(),
394 LogUserHappinessMetric( 404 LogUserHappinessMetric(
395 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME)); 405 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME));
396 406
397 // Simulate form submission. 407 // Simulate form submission.
398 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form)); 408 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form,
409 TimeTicks()));
399 } 410 }
400 411
401 // Test that we log the appropriate additional metrics when Autofill failed. 412 // Test that we log the appropriate additional metrics when Autofill failed.
402 TEST_F(AutofillMetricsTest, QualityMetricsForFailure) { 413 TEST_F(AutofillMetricsTest, QualityMetricsForFailure) {
403 // Set up our form data. 414 // Set up our form data.
404 FormData form; 415 FormData form;
405 form.name = ASCIIToUTF16("TestForm"); 416 form.name = ASCIIToUTF16("TestForm");
406 form.method = ASCIIToUTF16("POST"); 417 form.method = ASCIIToUTF16("POST");
407 form.origin = GURL("http://example.com/form.html"); 418 form.origin = GURL("http://example.com/form.html");
408 form.action = GURL("http://example.com/submit.html"); 419 form.action = GURL("http://example.com/submit.html");
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 std::string())); 516 std::string()));
506 EXPECT_CALL(*autofill_manager_->metric_logger(), 517 EXPECT_CALL(*autofill_manager_->metric_logger(),
507 LogQualityMetric(failure_cases[i].heuristic_metric, 518 LogQualityMetric(failure_cases[i].heuristic_metric,
508 std::string())); 519 std::string()));
509 EXPECT_CALL(*autofill_manager_->metric_logger(), 520 EXPECT_CALL(*autofill_manager_->metric_logger(),
510 LogQualityMetric(failure_cases[i].server_metric, 521 LogQualityMetric(failure_cases[i].server_metric,
511 std::string())); 522 std::string()));
512 } 523 }
513 524
514 // Simulate form submission. 525 // Simulate form submission.
515 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form)); 526 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form,
527 TimeTicks()));
516 } 528 }
517 529
518 // Test that we behave sanely when the cached form differs from the submitted 530 // Test that we behave sanely when the cached form differs from the submitted
519 // one. 531 // one.
520 TEST_F(AutofillMetricsTest, SaneMetricsWithCacheMismatch) { 532 TEST_F(AutofillMetricsTest, SaneMetricsWithCacheMismatch) {
521 // Set up our form data. 533 // Set up our form data.
522 FormData form; 534 FormData form;
523 form.name = ASCIIToUTF16("TestForm"); 535 form.name = ASCIIToUTF16("TestForm");
524 form.method = ASCIIToUTF16("POST"); 536 form.method = ASCIIToUTF16("POST");
525 form.origin = GURL("http://example.com/form.html"); 537 form.origin = GURL("http://example.com/form.html");
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 LogServerTypePrediction(AutofillMetrics::TYPE_MATCH, 674 LogServerTypePrediction(AutofillMetrics::TYPE_MATCH,
663 NAME_FULL, std::string())); 675 NAME_FULL, std::string()));
664 EXPECT_CALL(*autofill_manager_->metric_logger(), 676 EXPECT_CALL(*autofill_manager_->metric_logger(),
665 LogOverallTypePrediction(AutofillMetrics::TYPE_MATCH, 677 LogOverallTypePrediction(AutofillMetrics::TYPE_MATCH,
666 NAME_FULL, std::string())); 678 NAME_FULL, std::string()));
667 EXPECT_CALL(*autofill_manager_->metric_logger(), 679 EXPECT_CALL(*autofill_manager_->metric_logger(),
668 LogQualityMetric(AutofillMetrics::FIELD_AUTOFILLED, 680 LogQualityMetric(AutofillMetrics::FIELD_AUTOFILLED,
669 std::string())); 681 std::string()));
670 682
671 // Simulate form submission. 683 // Simulate form submission.
672 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form)); 684 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form,
685 TimeTicks()));
673 } 686 }
674 687
675 // Test that we don't log quality metrics for non-autofillable forms. 688 // Test that we don't log quality metrics for non-autofillable forms.
676 TEST_F(AutofillMetricsTest, NoQualityMetricsForNonAutofillableForms) { 689 TEST_F(AutofillMetricsTest, NoQualityMetricsForNonAutofillableForms) {
677 // Forms must include at least three fields to be auto-fillable. 690 // Forms must include at least three fields to be auto-fillable.
678 FormData form; 691 FormData form;
679 form.name = ASCIIToUTF16("TestForm"); 692 form.name = ASCIIToUTF16("TestForm");
680 form.method = ASCIIToUTF16("POST"); 693 form.method = ASCIIToUTF16("POST");
681 form.origin = GURL("http://example.com/form.html"); 694 form.origin = GURL("http://example.com/form.html");
682 form.action = GURL("http://example.com/submit.html"); 695 form.action = GURL("http://example.com/submit.html");
683 form.user_submitted = true; 696 form.user_submitted = true;
684 697
685 FormField field; 698 FormField field;
686 autofill_test::CreateTestFormField( 699 autofill_test::CreateTestFormField(
687 "Autofilled", "autofilled", "Elvis Presley", "text", &field); 700 "Autofilled", "autofilled", "Elvis Presley", "text", &field);
688 field.is_autofilled = true; 701 field.is_autofilled = true;
689 form.fields.push_back(field); 702 form.fields.push_back(field);
690 autofill_test::CreateTestFormField( 703 autofill_test::CreateTestFormField(
691 "Autofill Failed", "autofillfailed", "buddy@gmail.com", "text", &field); 704 "Autofill Failed", "autofillfailed", "buddy@gmail.com", "text", &field);
692 form.fields.push_back(field); 705 form.fields.push_back(field);
693 706
694 // Simulate form submission. 707 // Simulate form submission.
695 EXPECT_CALL(*autofill_manager_->metric_logger(), 708 EXPECT_CALL(*autofill_manager_->metric_logger(),
696 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED, 709 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
697 std::string())).Times(0); 710 std::string())).Times(0);
698 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form)); 711 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form,
712 TimeTicks()));
699 713
700 // Search forms are not auto-fillable. 714 // Search forms are not auto-fillable.
701 form.action = GURL("http://example.com/search?q=Elvis%20Presley"); 715 form.action = GURL("http://example.com/search?q=Elvis%20Presley");
702 autofill_test::CreateTestFormField( 716 autofill_test::CreateTestFormField(
703 "Empty", "empty", "", "text", &field); 717 "Empty", "empty", "", "text", &field);
704 form.fields.push_back(field); 718 form.fields.push_back(field);
705 719
706 // Simulate form submission. 720 // Simulate form submission.
707 EXPECT_CALL(*autofill_manager_->metric_logger(), 721 EXPECT_CALL(*autofill_manager_->metric_logger(),
708 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED, 722 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
709 std::string())).Times(0); 723 std::string())).Times(0);
710 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form)); 724 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form,
725 TimeTicks()));
711 } 726 }
712 727
713 // Test that we recored the experiment id appropriately. 728 // Test that we recored the experiment id appropriately.
714 TEST_F(AutofillMetricsTest, QualityMetricsWithExperimentId) { 729 TEST_F(AutofillMetricsTest, QualityMetricsWithExperimentId) {
715 // Set up our form data. 730 // Set up our form data.
716 FormData form; 731 FormData form;
717 form.name = ASCIIToUTF16("TestForm"); 732 form.name = ASCIIToUTF16("TestForm");
718 form.method = ASCIIToUTF16("POST"); 733 form.method = ASCIIToUTF16("POST");
719 form.origin = GURL("http://example.com/form.html"); 734 form.origin = GURL("http://example.com/form.html");
720 form.action = GURL("http://example.com/submit.html"); 735 form.action = GURL("http://example.com/submit.html");
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 LogHeuristicTypePrediction(AutofillMetrics::TYPE_UNKNOWN, 840 LogHeuristicTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
826 ADDRESS_HOME_COUNTRY, experiment_id)); 841 ADDRESS_HOME_COUNTRY, experiment_id));
827 EXPECT_CALL(*autofill_manager_->metric_logger(), 842 EXPECT_CALL(*autofill_manager_->metric_logger(),
828 LogServerTypePrediction(AutofillMetrics::TYPE_UNKNOWN, 843 LogServerTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
829 ADDRESS_HOME_COUNTRY, experiment_id)); 844 ADDRESS_HOME_COUNTRY, experiment_id));
830 EXPECT_CALL(*autofill_manager_->metric_logger(), 845 EXPECT_CALL(*autofill_manager_->metric_logger(),
831 LogOverallTypePrediction(AutofillMetrics::TYPE_UNKNOWN, 846 LogOverallTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
832 ADDRESS_HOME_COUNTRY, experiment_id)); 847 ADDRESS_HOME_COUNTRY, experiment_id));
833 848
834 // Simulate form submission. 849 // Simulate form submission.
835 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form)); 850 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form,
851 TimeTicks()));
836 } 852 }
837 853
838 // Test that the profile count is logged correctly. 854 // Test that the profile count is logged correctly.
839 TEST_F(AutofillMetricsTest, StoredProfileCount) { 855 TEST_F(AutofillMetricsTest, StoredProfileCount) {
840 // The metric should be logged when the profiles are first loaded. 856 // The metric should be logged when the profiles are first loaded.
841 EXPECT_CALL(*test_personal_data_->metric_logger(), 857 EXPECT_CALL(*test_personal_data_->metric_logger(),
842 LogStoredProfileCount(2)).Times(1); 858 LogStoredProfileCount(2)).Times(1);
843 test_personal_data_->LoadProfiles(); 859 test_personal_data_->LoadProfiles();
844 860
845 // The metric should only be logged once. 861 // The metric should only be logged once.
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 LogUserHappinessMetric( 1085 LogUserHappinessMetric(
1070 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME)).Times(0); 1086 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME)).Times(0);
1071 EXPECT_CALL( 1087 EXPECT_CALL(
1072 *autofill_manager_->metric_logger(), 1088 *autofill_manager_->metric_logger(),
1073 LogUserHappinessMetric( 1089 LogUserHappinessMetric(
1074 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE)).Times(0); 1090 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE)).Times(0);
1075 EXPECT_CALL( 1091 EXPECT_CALL(
1076 *autofill_manager_->metric_logger(), 1092 *autofill_manager_->metric_logger(),
1077 LogUserHappinessMetric( 1093 LogUserHappinessMetric(
1078 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM)).Times(0); 1094 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM)).Times(0);
1079 autofill_manager_->OnFormSubmitted(form); 1095 autofill_manager_->OnFormSubmitted(form, TimeTicks());
1080 } 1096 }
1081 1097
1082 // Add more fields to the form. 1098 // Add more fields to the form.
1083 autofill_test::CreateTestFormField("Phone", "phone", "", "text", &field); 1099 autofill_test::CreateTestFormField("Phone", "phone", "", "text", &field);
1084 form.fields.push_back(field); 1100 form.fields.push_back(field);
1085 autofill_test::CreateTestFormField("Unknown", "unknown", "", "text", &field); 1101 autofill_test::CreateTestFormField("Unknown", "unknown", "", "text", &field);
1086 form.fields.push_back(field); 1102 form.fields.push_back(field);
1087 forms.front() = form; 1103 forms.front() = form;
1088 1104
1089 // Expect a notification when the form is first seen. 1105 // Expect a notification when the form is first seen.
1090 { 1106 {
1091 EXPECT_CALL(*autofill_manager_->metric_logger(), 1107 EXPECT_CALL(*autofill_manager_->metric_logger(),
1092 LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED)); 1108 LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED));
1093 autofill_manager_->OnFormsSeen(forms); 1109 autofill_manager_->OnFormsSeen(forms);
1094 } 1110 }
1095 1111
1096 // Expect a notification when the form is submitted. 1112 // Expect a notification when the form is submitted.
1097 { 1113 {
1098 EXPECT_CALL(*autofill_manager_->metric_logger(), 1114 EXPECT_CALL(*autofill_manager_->metric_logger(),
1099 LogUserHappinessMetric( 1115 LogUserHappinessMetric(
1100 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM)); 1116 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM));
1101 autofill_manager_->OnFormSubmitted(form); 1117 autofill_manager_->OnFormSubmitted(form, TimeTicks());
1102 } 1118 }
1103 1119
1104 // Fill in two of the fields. 1120 // Fill in two of the fields.
1105 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley"); 1121 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley");
1106 form.fields[1].value = ASCIIToUTF16("theking@gmail.com"); 1122 form.fields[1].value = ASCIIToUTF16("theking@gmail.com");
1107 forms.front() = form; 1123 forms.front() = form;
1108 1124
1109 // Expect a notification when the form is submitted. 1125 // Expect a notification when the form is submitted.
1110 { 1126 {
1111 EXPECT_CALL(*autofill_manager_->metric_logger(), 1127 EXPECT_CALL(*autofill_manager_->metric_logger(),
1112 LogUserHappinessMetric( 1128 LogUserHappinessMetric(
1113 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM)); 1129 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM));
1114 autofill_manager_->OnFormSubmitted(form); 1130 autofill_manager_->OnFormSubmitted(form, TimeTicks());
1115 } 1131 }
1116 1132
1117 // Fill in the third field. 1133 // Fill in the third field.
1118 form.fields[2].value = ASCIIToUTF16("12345678901"); 1134 form.fields[2].value = ASCIIToUTF16("12345678901");
1119 forms.front() = form; 1135 forms.front() = form;
1120 1136
1121 // Expect notifications when the form is submitted. 1137 // Expect notifications when the form is submitted.
1122 { 1138 {
1123 EXPECT_CALL(*autofill_manager_->metric_logger(), 1139 EXPECT_CALL(*autofill_manager_->metric_logger(),
1124 LogUserHappinessMetric( 1140 LogUserHappinessMetric(
1125 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE)); 1141 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE));
1126 autofill_manager_->OnFormSubmitted(form); 1142 autofill_manager_->OnFormSubmitted(form, TimeTicks());
1127 } 1143 }
1128 1144
1129 1145
1130 // Mark one of the fields as autofilled. 1146 // Mark one of the fields as autofilled.
1131 form.fields[1].is_autofilled = true; 1147 form.fields[1].is_autofilled = true;
1132 forms.front() = form; 1148 forms.front() = form;
1133 1149
1134 // Expect notifications when the form is submitted. 1150 // Expect notifications when the form is submitted.
1135 { 1151 {
1136 EXPECT_CALL(*autofill_manager_->metric_logger(), 1152 EXPECT_CALL(*autofill_manager_->metric_logger(),
1137 LogUserHappinessMetric( 1153 LogUserHappinessMetric(
1138 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME)); 1154 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME));
1139 autofill_manager_->OnFormSubmitted(form); 1155 autofill_manager_->OnFormSubmitted(form, TimeTicks());
1140 } 1156 }
1141 1157
1142 // Mark all of the fillable fields as autofilled. 1158 // Mark all of the fillable fields as autofilled.
1143 form.fields[0].is_autofilled = true; 1159 form.fields[0].is_autofilled = true;
1144 form.fields[2].is_autofilled = true; 1160 form.fields[2].is_autofilled = true;
1145 forms.front() = form; 1161 forms.front() = form;
1146 1162
1147 // Expect notifications when the form is submitted. 1163 // Expect notifications when the form is submitted.
1148 { 1164 {
1149 EXPECT_CALL(*autofill_manager_->metric_logger(), 1165 EXPECT_CALL(*autofill_manager_->metric_logger(),
1150 LogUserHappinessMetric( 1166 LogUserHappinessMetric(
1151 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL)); 1167 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL));
1152 autofill_manager_->OnFormSubmitted(form); 1168 autofill_manager_->OnFormSubmitted(form, TimeTicks());
1153 } 1169 }
1154 1170
1155 // Clear out the third field's value. 1171 // Clear out the third field's value.
1156 form.fields[2].value = string16(); 1172 form.fields[2].value = string16();
1157 forms.front() = form; 1173 forms.front() = form;
1158 1174
1159 // Expect notifications when the form is submitted. 1175 // Expect notifications when the form is submitted.
1160 { 1176 {
1161 EXPECT_CALL(*autofill_manager_->metric_logger(), 1177 EXPECT_CALL(*autofill_manager_->metric_logger(),
1162 LogUserHappinessMetric( 1178 LogUserHappinessMetric(
1163 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM)); 1179 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM));
1164 autofill_manager_->OnFormSubmitted(form); 1180 autofill_manager_->OnFormSubmitted(form, TimeTicks());
1165 } 1181 }
1166 } 1182 }
1167 1183
1168 // Verify that we correctly log user happiness metrics dealing with form 1184 // Verify that we correctly log user happiness metrics dealing with form
1169 // interaction. 1185 // interaction.
1170 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) { 1186 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) {
1171 // Load a fillable form. 1187 // Load a fillable form.
1172 FormData form; 1188 FormData form;
1173 form.name = ASCIIToUTF16("TestForm"); 1189 form.name = ASCIIToUTF16("TestForm");
1174 form.method = ASCIIToUTF16("POST"); 1190 form.method = ASCIIToUTF16("POST");
(...skipping 15 matching lines...) Expand all
1190 { 1206 {
1191 EXPECT_CALL(*autofill_manager_->metric_logger(), 1207 EXPECT_CALL(*autofill_manager_->metric_logger(),
1192 LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED)); 1208 LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED));
1193 autofill_manager_->OnFormsSeen(forms); 1209 autofill_manager_->OnFormsSeen(forms);
1194 } 1210 }
1195 1211
1196 // Simulate typing. 1212 // Simulate typing.
1197 { 1213 {
1198 EXPECT_CALL(*autofill_manager_->metric_logger(), 1214 EXPECT_CALL(*autofill_manager_->metric_logger(),
1199 LogUserHappinessMetric(AutofillMetrics::USER_DID_TYPE)); 1215 LogUserHappinessMetric(AutofillMetrics::USER_DID_TYPE));
1200 autofill_manager_->OnTextFieldDidChange(form, form.fields.front()); 1216 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1217 TimeTicks());
1201 } 1218 }
1202 1219
1203 // Simulate suggestions shown twice for a single edit (i.e. multiple 1220 // Simulate suggestions shown twice for a single edit (i.e. multiple
1204 // keystrokes in a single field). 1221 // keystrokes in a single field).
1205 { 1222 {
1206 EXPECT_CALL(*autofill_manager_->metric_logger(), 1223 EXPECT_CALL(*autofill_manager_->metric_logger(),
1207 LogUserHappinessMetric( 1224 LogUserHappinessMetric(
1208 AutofillMetrics::SUGGESTIONS_SHOWN)).Times(1); 1225 AutofillMetrics::SUGGESTIONS_SHOWN)).Times(1);
1209 EXPECT_CALL(*autofill_manager_->metric_logger(), 1226 EXPECT_CALL(*autofill_manager_->metric_logger(),
1210 LogUserHappinessMetric( 1227 LogUserHappinessMetric(
(...skipping 12 matching lines...) Expand all
1223 autofill_manager_->OnDidShowAutofillSuggestions(true); 1240 autofill_manager_->OnDidShowAutofillSuggestions(true);
1224 } 1241 }
1225 1242
1226 // Simulate invoking autofill. 1243 // Simulate invoking autofill.
1227 { 1244 {
1228 EXPECT_CALL(*autofill_manager_->metric_logger(), 1245 EXPECT_CALL(*autofill_manager_->metric_logger(),
1229 LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL)); 1246 LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL));
1230 EXPECT_CALL(*autofill_manager_->metric_logger(), 1247 EXPECT_CALL(*autofill_manager_->metric_logger(),
1231 LogUserHappinessMetric( 1248 LogUserHappinessMetric(
1232 AutofillMetrics::USER_DID_AUTOFILL_ONCE)); 1249 AutofillMetrics::USER_DID_AUTOFILL_ONCE));
1233 autofill_manager_->OnDidFillAutofillFormData(); 1250 autofill_manager_->OnDidFillAutofillFormData(TimeTicks());
1234 } 1251 }
1235 1252
1236 // Simulate editing an autofilled field. 1253 // Simulate editing an autofilled field.
1237 { 1254 {
1238 EXPECT_CALL(*autofill_manager_->metric_logger(), 1255 EXPECT_CALL(*autofill_manager_->metric_logger(),
1239 LogUserHappinessMetric( 1256 LogUserHappinessMetric(
1240 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD)); 1257 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD));
1241 EXPECT_CALL(*autofill_manager_->metric_logger(), 1258 EXPECT_CALL(*autofill_manager_->metric_logger(),
1242 LogUserHappinessMetric( 1259 LogUserHappinessMetric(
1243 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE)); 1260 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE));
1244 AutofillManager::GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); 1261 AutofillManager::GUIDPair guid("00000000-0000-0000-0000-000000000001", 0);
1245 AutofillManager::GUIDPair empty(std::string(), 0); 1262 AutofillManager::GUIDPair empty(std::string(), 0);
1246 autofill_manager_->OnFillAutofillFormData( 1263 autofill_manager_->OnFillAutofillFormData(
1247 0, form, form.fields.front(), 1264 0, form, form.fields.front(),
1248 autofill_manager_->PackGUIDs(empty, guid)); 1265 autofill_manager_->PackGUIDs(empty, guid));
1249 autofill_manager_->OnTextFieldDidChange(form, form.fields.front()); 1266 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1267 TimeTicks());
1250 // Simulate a second keystroke; make sure we don't log the metric twice. 1268 // Simulate a second keystroke; make sure we don't log the metric twice.
1251 autofill_manager_->OnTextFieldDidChange(form, form.fields.front()); 1269 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1270 TimeTicks());
1252 } 1271 }
1253 1272
1254 // Simulate invoking autofill again. 1273 // Simulate invoking autofill again.
1255 EXPECT_CALL(*autofill_manager_->metric_logger(), 1274 EXPECT_CALL(*autofill_manager_->metric_logger(),
1256 LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL)); 1275 LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL));
1257 EXPECT_CALL(*autofill_manager_->metric_logger(), 1276 EXPECT_CALL(*autofill_manager_->metric_logger(),
1258 LogUserHappinessMetric( 1277 LogUserHappinessMetric(
1259 AutofillMetrics::USER_DID_AUTOFILL_ONCE)).Times(0); 1278 AutofillMetrics::USER_DID_AUTOFILL_ONCE)).Times(0);
1260 autofill_manager_->OnDidFillAutofillFormData(); 1279 autofill_manager_->OnDidFillAutofillFormData(TimeTicks());
1261 1280
1262 // Simulate editing another autofilled field. 1281 // Simulate editing another autofilled field.
1263 { 1282 {
1264 EXPECT_CALL(*autofill_manager_->metric_logger(), 1283 EXPECT_CALL(*autofill_manager_->metric_logger(),
1265 LogUserHappinessMetric( 1284 LogUserHappinessMetric(
1266 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD)); 1285 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD));
1267 autofill_manager_->OnTextFieldDidChange(form, form.fields[1]); 1286 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks());
1268 } 1287 }
1269 } 1288 }
1289
1290 // Verify that we correctly log metrics tracking the duration of form fill.
1291 TEST_F(AutofillMetricsTest, FormFillDuration) {
1292 // Load a fillable form.
1293 FormData form;
1294 form.name = ASCIIToUTF16("TestForm");
1295 form.method = ASCIIToUTF16("POST");
1296 form.origin = GURL("http://example.com/form.html");
1297 form.action = GURL("http://example.com/submit.html");
1298 form.user_submitted = true;
1299
1300 FormField field;
1301 autofill_test::CreateTestFormField("Name", "name", "", "text", &field);
1302 form.fields.push_back(field);
1303 autofill_test::CreateTestFormField("Email", "email", "", "text", &field);
1304 form.fields.push_back(field);
1305 autofill_test::CreateTestFormField("Phone", "phone", "", "text", &field);
1306 form.fields.push_back(field);
1307
1308 std::vector<FormData> forms(1, form);
1309
1310 // Fill the field values for form submission.
1311 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley");
1312 form.fields[1].value = ASCIIToUTF16("theking@gmail.com");
1313 form.fields[2].value = ASCIIToUTF16("12345678901");
1314
1315 // Ignore any non-timing metrics.
1316 // CAUTION: This is a global variable. So as to not affect other tests, this
1317 // _must_ be restored to "warning" at the end of the test.
1318 ::testing::FLAGS_gmock_verbose = "error";
1319
1320 // Expect no metric to be logged if the form is submitted without user
1321 // interaction.
1322 {
1323 EXPECT_CALL(*autofill_manager_->metric_logger(),
1324 LogAutofilledFormSubmittedAfterDuration(_)).Times(0);
1325 EXPECT_CALL(*autofill_manager_->metric_logger(),
1326 LogNonAutofilledFormSubmittedAfterDuration(_)).Times(0);
1327 autofill_manager_->OnFormsSeen(forms);
1328 autofill_manager_->OnFormSubmitted(form, TimeTicks::FromInternalValue(17));
1329 autofill_manager_->Reset();
1330 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1331 }
1332
1333 // Expect metric to be logged if the user manually edited a form field.
1334 {
1335 EXPECT_CALL(*autofill_manager_->metric_logger(),
1336 LogAutofilledFormSubmittedAfterDuration(_)).Times(0);
1337 EXPECT_CALL(*autofill_manager_->metric_logger(),
1338 LogNonAutofilledFormSubmittedAfterDuration(
1339 TimeDelta::FromInternalValue(14)));
1340 autofill_manager_->OnFormsSeen(forms);
1341 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1342 TimeTicks::FromInternalValue(3));
1343 autofill_manager_->OnFormSubmitted(form, TimeTicks::FromInternalValue(17));
1344 autofill_manager_->Reset();
1345 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1346 }
1347
1348 // Expect metric to be logged if the user autofilled the form.
1349 form.fields[0].is_autofilled = true;
1350 {
1351 EXPECT_CALL(*autofill_manager_->metric_logger(),
1352 LogAutofilledFormSubmittedAfterDuration(
1353 TimeDelta::FromInternalValue(12)));
1354 EXPECT_CALL(*autofill_manager_->metric_logger(),
1355 LogNonAutofilledFormSubmittedAfterDuration(_)).Times(0);
1356 autofill_manager_->OnFormsSeen(forms);
1357 autofill_manager_->OnDidFillAutofillFormData(
1358 TimeTicks::FromInternalValue(5));
1359 autofill_manager_->OnFormSubmitted(form, TimeTicks::FromInternalValue(17));
1360 autofill_manager_->Reset();
1361 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1362 }
1363
1364 // Expect metric to be logged if the user both manually filled some fields
1365 // and autofilled others. Messages can arrive out of order, so make sure they
1366 // take precedence appropriately.
1367 {
1368 EXPECT_CALL(*autofill_manager_->metric_logger(),
1369 LogAutofilledFormSubmittedAfterDuration(
1370 TimeDelta::FromInternalValue(14)));
1371 EXPECT_CALL(*autofill_manager_->metric_logger(),
1372 LogNonAutofilledFormSubmittedAfterDuration(_)).Times(0);
1373 autofill_manager_->OnFormsSeen(forms);
1374 autofill_manager_->OnDidFillAutofillFormData(
1375 TimeTicks::FromInternalValue(5));
1376 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1377 TimeTicks::FromInternalValue(3));
1378 autofill_manager_->OnFormSubmitted(form, TimeTicks::FromInternalValue(17));
1379 autofill_manager_->Reset();
1380 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1381 }
1382
1383 // Expect no metric to be logged if the form submission time appears to be
1384 // prior to the first form interaction.
1385 {
1386 EXPECT_CALL(*autofill_manager_->metric_logger(),
1387 LogAutofilledFormSubmittedAfterDuration(_)).Times(0);
1388 EXPECT_CALL(*autofill_manager_->metric_logger(),
1389 LogNonAutofilledFormSubmittedAfterDuration(_)).Times(0);
1390 autofill_manager_->OnFormsSeen(forms);
1391 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1392 TimeTicks::FromInternalValue(23));
1393 autofill_manager_->OnFormSubmitted(form, TimeTicks::FromInternalValue(17));
1394 autofill_manager_->Reset();
1395 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1396 }
1397
1398 // Restore the global Gmock verbosity level to its default value.
1399 ::testing::FLAGS_gmock_verbose = "warning";
1400 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698