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

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

Issue 22009003: [Autofill] Distinguish between native field types and potentially HTML field types. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/core/browser/autofill_metrics.h" 5 #include "components/autofill/core/browser/autofill_metrics.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 namespace { 44 namespace {
45 45
46 class MockAutofillMetrics : public AutofillMetrics { 46 class MockAutofillMetrics : public AutofillMetrics {
47 public: 47 public:
48 MockAutofillMetrics() {} 48 MockAutofillMetrics() {}
49 MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric)); 49 MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric));
50 MOCK_CONST_METHOD1(LogDeveloperEngagementMetric, 50 MOCK_CONST_METHOD1(LogDeveloperEngagementMetric,
51 void(DeveloperEngagementMetric metric)); 51 void(DeveloperEngagementMetric metric));
52 MOCK_CONST_METHOD3(LogHeuristicTypePrediction, 52 MOCK_CONST_METHOD3(LogHeuristicTypePrediction,
53 void(FieldTypeQualityMetric metric, 53 void(FieldTypeQualityMetric metric,
54 AutofillFieldType field_type, 54 ServerFieldType field_type,
55 const std::string& experiment_id)); 55 const std::string& experiment_id));
56 MOCK_CONST_METHOD3(LogOverallTypePrediction, 56 MOCK_CONST_METHOD3(LogOverallTypePrediction,
57 void(FieldTypeQualityMetric metric, 57 void(FieldTypeQualityMetric metric,
58 AutofillFieldType field_type, 58 ServerFieldType field_type,
59 const std::string& experiment_id)); 59 const std::string& experiment_id));
60 MOCK_CONST_METHOD3(LogServerTypePrediction, 60 MOCK_CONST_METHOD3(LogServerTypePrediction,
61 void(FieldTypeQualityMetric metric, 61 void(FieldTypeQualityMetric metric,
62 AutofillFieldType field_type, 62 ServerFieldType field_type,
63 const std::string& experiment_id)); 63 const std::string& experiment_id));
64 MOCK_CONST_METHOD2(LogQualityMetric, void(QualityMetric metric, 64 MOCK_CONST_METHOD2(LogQualityMetric, void(QualityMetric metric,
65 const std::string& experiment_id)); 65 const std::string& experiment_id));
66 MOCK_CONST_METHOD1(LogServerQueryMetric, void(ServerQueryMetric metric)); 66 MOCK_CONST_METHOD1(LogServerQueryMetric, void(ServerQueryMetric metric));
67 MOCK_CONST_METHOD1(LogUserHappinessMetric, void(UserHappinessMetric metric)); 67 MOCK_CONST_METHOD1(LogUserHappinessMetric, void(UserHappinessMetric metric));
68 MOCK_CONST_METHOD1(LogFormFillDurationFromLoadWithAutofill, 68 MOCK_CONST_METHOD1(LogFormFillDurationFromLoadWithAutofill,
69 void(const TimeDelta& duration)); 69 void(const TimeDelta& duration));
70 MOCK_CONST_METHOD1(LogFormFillDurationFromLoadWithoutAutofill, 70 MOCK_CONST_METHOD1(LogFormFillDurationFromLoadWithoutAutofill,
71 void(const TimeDelta& duration)); 71 void(const TimeDelta& duration));
72 MOCK_CONST_METHOD1(LogFormFillDurationFromInteractionWithAutofill, 72 MOCK_CONST_METHOD1(LogFormFillDurationFromInteractionWithAutofill,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 151
152 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); 152 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager);
153 }; 153 };
154 154
155 class TestFormStructure : public FormStructure { 155 class TestFormStructure : public FormStructure {
156 public: 156 public:
157 explicit TestFormStructure(const FormData& form) 157 explicit TestFormStructure(const FormData& form)
158 : FormStructure(form, std::string()) {} 158 : FormStructure(form, std::string()) {}
159 virtual ~TestFormStructure() {} 159 virtual ~TestFormStructure() {}
160 160
161 void SetFieldTypes(const std::vector<AutofillFieldType>& heuristic_types, 161 void SetFieldTypes(const std::vector<ServerFieldType>& heuristic_types,
162 const std::vector<AutofillFieldType>& server_types) { 162 const std::vector<ServerFieldType>& server_types) {
163 ASSERT_EQ(field_count(), heuristic_types.size()); 163 ASSERT_EQ(field_count(), heuristic_types.size());
164 ASSERT_EQ(field_count(), server_types.size()); 164 ASSERT_EQ(field_count(), server_types.size());
165 165
166 for (size_t i = 0; i < field_count(); ++i) { 166 for (size_t i = 0; i < field_count(); ++i) {
167 AutofillField* form_field = field(i); 167 AutofillField* form_field = field(i);
168 ASSERT_TRUE(form_field); 168 ASSERT_TRUE(form_field);
169 form_field->set_heuristic_type(heuristic_types[i]); 169 form_field->set_heuristic_type(heuristic_types[i]);
170 form_field->set_server_type(server_types[i]); 170 form_field->set_server_type(server_types[i]);
171 } 171 }
172 172
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 void set_autofill_enabled(bool autofill_enabled) { 205 void set_autofill_enabled(bool autofill_enabled) {
206 autofill_enabled_ = autofill_enabled; 206 autofill_enabled_ = autofill_enabled;
207 } 207 }
208 208
209 MockAutofillMetrics* metric_logger() { 209 MockAutofillMetrics* metric_logger() {
210 return static_cast<MockAutofillMetrics*>(const_cast<AutofillMetrics*>( 210 return static_cast<MockAutofillMetrics*>(const_cast<AutofillMetrics*>(
211 AutofillManager::metric_logger())); 211 AutofillManager::metric_logger()));
212 } 212 }
213 213
214 void AddSeenForm(const FormData& form, 214 void AddSeenForm(const FormData& form,
215 const std::vector<AutofillFieldType>& heuristic_types, 215 const std::vector<ServerFieldType>& heuristic_types,
216 const std::vector<AutofillFieldType>& server_types, 216 const std::vector<ServerFieldType>& server_types,
217 const std::string& experiment_id) { 217 const std::string& experiment_id) {
218 FormData empty_form = form; 218 FormData empty_form = form;
219 for (size_t i = 0; i < empty_form.fields.size(); ++i) { 219 for (size_t i = 0; i < empty_form.fields.size(); ++i) {
220 empty_form.fields[i].value = base::string16(); 220 empty_form.fields[i].value = base::string16();
221 } 221 }
222 222
223 // |form_structure| will be owned by |form_structures()|. 223 // |form_structure| will be owned by |form_structures()|.
224 TestFormStructure* form_structure = new TestFormStructure(empty_form); 224 TestFormStructure* form_structure = new TestFormStructure(empty_form);
225 form_structure->SetFieldTypes(heuristic_types, server_types); 225 form_structure->SetFieldTypes(heuristic_types, server_types);
226 form_structure->set_server_experiment_id(experiment_id); 226 form_structure->set_server_experiment_id(experiment_id);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 // Test that we log quality metrics appropriately. 332 // Test that we log quality metrics appropriately.
333 TEST_F(AutofillMetricsTest, QualityMetrics) { 333 TEST_F(AutofillMetricsTest, QualityMetrics) {
334 // Set up our form data. 334 // Set up our form data.
335 FormData form; 335 FormData form;
336 form.name = ASCIIToUTF16("TestForm"); 336 form.name = ASCIIToUTF16("TestForm");
337 form.method = ASCIIToUTF16("POST"); 337 form.method = ASCIIToUTF16("POST");
338 form.origin = GURL("http://example.com/form.html"); 338 form.origin = GURL("http://example.com/form.html");
339 form.action = GURL("http://example.com/submit.html"); 339 form.action = GURL("http://example.com/submit.html");
340 form.user_submitted = true; 340 form.user_submitted = true;
341 341
342 std::vector<AutofillFieldType> heuristic_types, server_types; 342 std::vector<ServerFieldType> heuristic_types, server_types;
343 FormFieldData field; 343 FormFieldData field;
344 344
345 test::CreateTestFormField( 345 test::CreateTestFormField(
346 "Autofilled", "autofilled", "Elvis Aaron Presley", "text", &field); 346 "Autofilled", "autofilled", "Elvis Aaron Presley", "text", &field);
347 field.is_autofilled = true; 347 field.is_autofilled = true;
348 form.fields.push_back(field); 348 form.fields.push_back(field);
349 heuristic_types.push_back(NAME_FULL); 349 heuristic_types.push_back(NAME_FULL);
350 server_types.push_back(NAME_FIRST); 350 server_types.push_back(NAME_FIRST);
351 351
352 test::CreateTestFormField( 352 test::CreateTestFormField(
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 form.name = ASCIIToUTF16("TestForm"); 481 form.name = ASCIIToUTF16("TestForm");
482 form.method = ASCIIToUTF16("POST"); 482 form.method = ASCIIToUTF16("POST");
483 form.origin = GURL("http://example.com/form.html"); 483 form.origin = GURL("http://example.com/form.html");
484 form.action = GURL("http://example.com/submit.html"); 484 form.action = GURL("http://example.com/submit.html");
485 form.user_submitted = true; 485 form.user_submitted = true;
486 486
487 struct { 487 struct {
488 const char* label; 488 const char* label;
489 const char* name; 489 const char* name;
490 const char* value; 490 const char* value;
491 AutofillFieldType heuristic_type; 491 ServerFieldType heuristic_type;
492 AutofillFieldType server_type; 492 ServerFieldType server_type;
493 AutofillMetrics::QualityMetric heuristic_metric; 493 AutofillMetrics::QualityMetric heuristic_metric;
494 AutofillMetrics::QualityMetric server_metric; 494 AutofillMetrics::QualityMetric server_metric;
495 } failure_cases[] = { 495 } failure_cases[] = {
496 { 496 {
497 "Heuristics unknown, server unknown", "0,0", "Elvis", 497 "Heuristics unknown, server unknown", "0,0", "Elvis",
498 UNKNOWN_TYPE, NO_SERVER_DATA, 498 UNKNOWN_TYPE, NO_SERVER_DATA,
499 AutofillMetrics::NOT_AUTOFILLED_HEURISTIC_TYPE_UNKNOWN, 499 AutofillMetrics::NOT_AUTOFILLED_HEURISTIC_TYPE_UNKNOWN,
500 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_UNKNOWN 500 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_UNKNOWN
501 }, 501 },
502 { 502 {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_MISMATCH 542 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_MISMATCH
543 }, 543 },
544 { 544 {
545 "Heuristics mismatch, server mismatch", "2,2", "38116", 545 "Heuristics mismatch, server mismatch", "2,2", "38116",
546 PHONE_HOME_NUMBER, PHONE_HOME_NUMBER, 546 PHONE_HOME_NUMBER, PHONE_HOME_NUMBER,
547 AutofillMetrics::NOT_AUTOFILLED_HEURISTIC_TYPE_MISMATCH, 547 AutofillMetrics::NOT_AUTOFILLED_HEURISTIC_TYPE_MISMATCH,
548 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_MISMATCH 548 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_MISMATCH
549 } 549 }
550 }; 550 };
551 551
552 std::vector<AutofillFieldType> heuristic_types, server_types; 552 std::vector<ServerFieldType> heuristic_types, server_types;
553 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(failure_cases); ++i) { 553 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(failure_cases); ++i) {
554 FormFieldData field; 554 FormFieldData field;
555 test::CreateTestFormField(failure_cases[i].label, 555 test::CreateTestFormField(failure_cases[i].label,
556 failure_cases[i].name, 556 failure_cases[i].name,
557 failure_cases[i].value, "text", &field); 557 failure_cases[i].value, "text", &field);
558 form.fields.push_back(field); 558 form.fields.push_back(field);
559 heuristic_types.push_back(failure_cases[i].heuristic_type); 559 heuristic_types.push_back(failure_cases[i].heuristic_type);
560 server_types.push_back(failure_cases[i].server_type); 560 server_types.push_back(failure_cases[i].server_type);
561 561
562 } 562 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 // one. 595 // one.
596 TEST_F(AutofillMetricsTest, SaneMetricsWithCacheMismatch) { 596 TEST_F(AutofillMetricsTest, SaneMetricsWithCacheMismatch) {
597 // Set up our form data. 597 // Set up our form data.
598 FormData form; 598 FormData form;
599 form.name = ASCIIToUTF16("TestForm"); 599 form.name = ASCIIToUTF16("TestForm");
600 form.method = ASCIIToUTF16("POST"); 600 form.method = ASCIIToUTF16("POST");
601 form.origin = GURL("http://example.com/form.html"); 601 form.origin = GURL("http://example.com/form.html");
602 form.action = GURL("http://example.com/submit.html"); 602 form.action = GURL("http://example.com/submit.html");
603 form.user_submitted = true; 603 form.user_submitted = true;
604 604
605 std::vector<AutofillFieldType> heuristic_types, server_types; 605 std::vector<ServerFieldType> heuristic_types, server_types;
606 606
607 FormFieldData field; 607 FormFieldData field;
608 test::CreateTestFormField( 608 test::CreateTestFormField(
609 "Both match", "match", "Elvis Aaron Presley", "text", &field); 609 "Both match", "match", "Elvis Aaron Presley", "text", &field);
610 field.is_autofilled = true; 610 field.is_autofilled = true;
611 form.fields.push_back(field); 611 form.fields.push_back(field);
612 heuristic_types.push_back(NAME_FULL); 612 heuristic_types.push_back(NAME_FULL);
613 server_types.push_back(NAME_FULL); 613 server_types.push_back(NAME_FULL);
614 test::CreateTestFormField( 614 test::CreateTestFormField(
615 "Both mismatch", "mismatch", "buddy@gmail.com", "text", &field); 615 "Both mismatch", "mismatch", "buddy@gmail.com", "text", &field);
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 // Test that we recored the experiment id appropriately. 871 // Test that we recored the experiment id appropriately.
872 TEST_F(AutofillMetricsTest, QualityMetricsWithExperimentId) { 872 TEST_F(AutofillMetricsTest, QualityMetricsWithExperimentId) {
873 // Set up our form data. 873 // Set up our form data.
874 FormData form; 874 FormData form;
875 form.name = ASCIIToUTF16("TestForm"); 875 form.name = ASCIIToUTF16("TestForm");
876 form.method = ASCIIToUTF16("POST"); 876 form.method = ASCIIToUTF16("POST");
877 form.origin = GURL("http://example.com/form.html"); 877 form.origin = GURL("http://example.com/form.html");
878 form.action = GURL("http://example.com/submit.html"); 878 form.action = GURL("http://example.com/submit.html");
879 form.user_submitted = true; 879 form.user_submitted = true;
880 880
881 std::vector<AutofillFieldType> heuristic_types, server_types; 881 std::vector<ServerFieldType> heuristic_types, server_types;
882 FormFieldData field; 882 FormFieldData field;
883 883
884 test::CreateTestFormField( 884 test::CreateTestFormField(
885 "Autofilled", "autofilled", "Elvis Aaron Presley", "text", &field); 885 "Autofilled", "autofilled", "Elvis Aaron Presley", "text", &field);
886 field.is_autofilled = true; 886 field.is_autofilled = true;
887 form.fields.push_back(field); 887 form.fields.push_back(field);
888 heuristic_types.push_back(NAME_FULL); 888 heuristic_types.push_back(NAME_FULL);
889 server_types.push_back(NAME_FIRST); 889 server_types.push_back(NAME_FIRST);
890 890
891 test::CreateTestFormField( 891 test::CreateTestFormField(
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) { 1024 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) {
1025 // Set up our form data. 1025 // Set up our form data.
1026 FormData form; 1026 FormData form;
1027 form.name = ASCIIToUTF16("TestForm"); 1027 form.name = ASCIIToUTF16("TestForm");
1028 form.method = ASCIIToUTF16("POST"); 1028 form.method = ASCIIToUTF16("POST");
1029 form.origin = GURL("http://example.com/form.html"); 1029 form.origin = GURL("http://example.com/form.html");
1030 form.action = GURL("http://example.com/submit.html"); 1030 form.action = GURL("http://example.com/submit.html");
1031 form.user_submitted = true; 1031 form.user_submitted = true;
1032 1032
1033 FormFieldData field; 1033 FormFieldData field;
1034 std::vector<AutofillFieldType> field_types; 1034 std::vector<ServerFieldType> field_types;
1035 test::CreateTestFormField("Name", "name", "", "text", &field); 1035 test::CreateTestFormField("Name", "name", "", "text", &field);
1036 form.fields.push_back(field); 1036 form.fields.push_back(field);
1037 field_types.push_back(NAME_FULL); 1037 field_types.push_back(NAME_FULL);
1038 test::CreateTestFormField("Email", "email", "", "email", &field); 1038 test::CreateTestFormField("Email", "email", "", "email", &field);
1039 form.fields.push_back(field); 1039 form.fields.push_back(field);
1040 field_types.push_back(EMAIL_ADDRESS); 1040 field_types.push_back(EMAIL_ADDRESS);
1041 test::CreateTestFormField("Phone", "phone", "", "tel", &field); 1041 test::CreateTestFormField("Phone", "phone", "", "tel", &field);
1042 form.fields.push_back(field); 1042 form.fields.push_back(field);
1043 field_types.push_back(PHONE_HOME_NUMBER); 1043 field_types.push_back(PHONE_HOME_NUMBER);
1044 1044
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 TimeTicks::FromInternalValue(5)); 1555 TimeTicks::FromInternalValue(5));
1556 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 1556 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1557 TimeTicks::FromInternalValue(3)); 1557 TimeTicks::FromInternalValue(3));
1558 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); 1558 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1559 autofill_manager_->Reset(); 1559 autofill_manager_->Reset();
1560 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 1560 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1561 } 1561 }
1562 } 1562 }
1563 1563
1564 } // namespace autofill 1564 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_metrics.cc ('k') | components/autofill/core/browser/autofill_profile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698