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