Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/core/browser/autofill_metrics.h" | 5 #include "components/autofill/core/browser/autofill_metrics.h" |
| 6 | 6 |
| 7 #include <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" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" | 14 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" |
| 15 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 15 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 16 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" | 16 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" |
| 17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 18 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 19 #include "components/autofill/content/browser/autocheckout_page_meta_data.h" | |
| 20 #include "components/autofill/core/browser/autofill_common_test.h" | 19 #include "components/autofill/core/browser/autofill_common_test.h" |
| 21 #include "components/autofill/core/browser/autofill_external_delegate.h" | 20 #include "components/autofill/core/browser/autofill_external_delegate.h" |
| 22 #include "components/autofill/core/browser/autofill_manager.h" | 21 #include "components/autofill/core/browser/autofill_manager.h" |
| 23 #include "components/autofill/core/browser/autofill_manager_delegate.h" | 22 #include "components/autofill/core/browser/autofill_manager_delegate.h" |
| 24 #include "components/autofill/core/browser/personal_data_manager.h" | 23 #include "components/autofill/core/browser/personal_data_manager.h" |
| 25 #include "components/autofill/core/browser/test_autofill_driver.h" | 24 #include "components/autofill/core/browser/test_autofill_driver.h" |
| 26 #include "components/autofill/core/common/form_data.h" | 25 #include "components/autofill/core/common/form_data.h" |
| 27 #include "components/autofill/core/common/form_field_data.h" | 26 #include "components/autofill/core/common/form_field_data.h" |
| 28 #include "components/autofill/core/common/forms_seen_state.h" | 27 #include "components/autofill/core/common/forms_seen_state.h" |
| 29 #include "components/webdata/common/web_data_results.h" | 28 #include "components/webdata/common/web_data_results.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 } | 147 } |
| 149 | 148 |
| 150 bool autofill_enabled_; | 149 bool autofill_enabled_; |
| 151 | 150 |
| 152 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); | 151 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); |
| 153 }; | 152 }; |
| 154 | 153 |
| 155 class TestFormStructure : public FormStructure { | 154 class TestFormStructure : public FormStructure { |
| 156 public: | 155 public: |
| 157 explicit TestFormStructure(const FormData& form) | 156 explicit TestFormStructure(const FormData& form) |
| 158 : FormStructure(form, std::string()) {} | 157 : FormStructure(form) {} |
|
Ilya Sherman
2013/08/27 18:57:57
nit: Looks like this ought to now fit on the previ
Raman Kakilate
2013/08/27 21:52:59
Done.
| |
| 159 virtual ~TestFormStructure() {} | 158 virtual ~TestFormStructure() {} |
| 160 | 159 |
| 161 void SetFieldTypes(const std::vector<ServerFieldType>& heuristic_types, | 160 void SetFieldTypes(const std::vector<ServerFieldType>& heuristic_types, |
| 162 const std::vector<ServerFieldType>& server_types) { | 161 const std::vector<ServerFieldType>& server_types) { |
| 163 ASSERT_EQ(field_count(), heuristic_types.size()); | 162 ASSERT_EQ(field_count(), heuristic_types.size()); |
| 164 ASSERT_EQ(field_count(), server_types.size()); | 163 ASSERT_EQ(field_count(), server_types.size()); |
| 165 | 164 |
| 166 for (size_t i = 0; i < field_count(); ++i) { | 165 for (size_t i = 0; i < field_count(); ++i) { |
| 167 AutofillField* form_field = field(i); | 166 AutofillField* form_field = field(i); |
| 168 ASSERT_TRUE(form_field); | 167 ASSERT_TRUE(form_field); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 189 public: | 188 public: |
| 190 TestAutofillManager(AutofillDriver* driver, | 189 TestAutofillManager(AutofillDriver* driver, |
| 191 AutofillManagerDelegate* manager_delegate, | 190 AutofillManagerDelegate* manager_delegate, |
| 192 TestPersonalDataManager* personal_manager) | 191 TestPersonalDataManager* personal_manager) |
| 193 : AutofillManager(driver, manager_delegate, personal_manager), | 192 : AutofillManager(driver, manager_delegate, personal_manager), |
| 194 autofill_enabled_(true) { | 193 autofill_enabled_(true) { |
| 195 set_metric_logger(new testing::NiceMock<MockAutofillMetrics>); | 194 set_metric_logger(new testing::NiceMock<MockAutofillMetrics>); |
| 196 } | 195 } |
| 197 virtual ~TestAutofillManager() {} | 196 virtual ~TestAutofillManager() {} |
| 198 | 197 |
| 199 virtual std::string GetAutocheckoutURLPrefix() const OVERRIDE { | |
| 200 return std::string(); | |
| 201 } | |
| 202 | |
| 203 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } | 198 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } |
| 204 | 199 |
| 205 void set_autofill_enabled(bool autofill_enabled) { | 200 void set_autofill_enabled(bool autofill_enabled) { |
| 206 autofill_enabled_ = autofill_enabled; | 201 autofill_enabled_ = autofill_enabled; |
| 207 } | 202 } |
| 208 | 203 |
| 209 MockAutofillMetrics* metric_logger() { | 204 MockAutofillMetrics* metric_logger() { |
| 210 return static_cast<MockAutofillMetrics*>(const_cast<AutofillMetrics*>( | 205 return static_cast<MockAutofillMetrics*>(const_cast<AutofillMetrics*>( |
| 211 AutofillManager::metric_logger())); | 206 AutofillManager::metric_logger())); |
| 212 } | 207 } |
| (...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1169 // No experiment specified. | 1164 // No experiment specified. |
| 1170 EXPECT_CALL(metric_logger, | 1165 EXPECT_CALL(metric_logger, |
| 1171 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED)); | 1166 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED)); |
| 1172 EXPECT_CALL(metric_logger, | 1167 EXPECT_CALL(metric_logger, |
| 1173 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_PARSED)); | 1168 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_PARSED)); |
| 1174 EXPECT_CALL(metric_logger, | 1169 EXPECT_CALL(metric_logger, |
| 1175 LogServerExperimentIdForQuery(std::string())); | 1170 LogServerExperimentIdForQuery(std::string())); |
| 1176 EXPECT_CALL(metric_logger, | 1171 EXPECT_CALL(metric_logger, |
| 1177 LogServerQueryMetric( | 1172 LogServerQueryMetric( |
| 1178 AutofillMetrics::QUERY_RESPONSE_MATCHED_LOCAL_HEURISTICS)); | 1173 AutofillMetrics::QUERY_RESPONSE_MATCHED_LOCAL_HEURISTICS)); |
| 1179 AutocheckoutPageMetaData page_meta_data; | |
| 1180 FormStructure::ParseQueryResponse( | 1174 FormStructure::ParseQueryResponse( |
| 1181 "<autofillqueryresponse></autofillqueryresponse>", | 1175 "<autofillqueryresponse></autofillqueryresponse>", |
| 1182 std::vector<FormStructure*>(), | 1176 std::vector<FormStructure*>(), |
| 1183 &page_meta_data, | |
| 1184 metric_logger); | 1177 metric_logger); |
| 1185 | 1178 |
| 1186 // Experiment "ar1" specified. | 1179 // Experiment "ar1" specified. |
| 1187 EXPECT_CALL(metric_logger, | 1180 EXPECT_CALL(metric_logger, |
| 1188 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED)); | 1181 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED)); |
| 1189 EXPECT_CALL(metric_logger, | 1182 EXPECT_CALL(metric_logger, |
| 1190 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_PARSED)); | 1183 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_PARSED)); |
| 1191 EXPECT_CALL(metric_logger, | 1184 EXPECT_CALL(metric_logger, |
| 1192 LogServerExperimentIdForQuery("ar1")); | 1185 LogServerExperimentIdForQuery("ar1")); |
| 1193 EXPECT_CALL(metric_logger, | 1186 EXPECT_CALL(metric_logger, |
| 1194 LogServerQueryMetric( | 1187 LogServerQueryMetric( |
| 1195 AutofillMetrics::QUERY_RESPONSE_MATCHED_LOCAL_HEURISTICS)); | 1188 AutofillMetrics::QUERY_RESPONSE_MATCHED_LOCAL_HEURISTICS)); |
| 1196 FormStructure::ParseQueryResponse( | 1189 FormStructure::ParseQueryResponse( |
| 1197 "<autofillqueryresponse experimentid=\"ar1\"></autofillqueryresponse>", | 1190 "<autofillqueryresponse experimentid=\"ar1\"></autofillqueryresponse>", |
| 1198 std::vector<FormStructure*>(), | 1191 std::vector<FormStructure*>(), |
| 1199 &page_meta_data, | |
| 1200 metric_logger); | 1192 metric_logger); |
| 1201 } | 1193 } |
| 1202 | 1194 |
| 1203 // Verify that we correctly log user happiness metrics dealing with form loading | 1195 // Verify that we correctly log user happiness metrics dealing with form loading |
| 1204 // and form submission. | 1196 // and form submission. |
| 1205 TEST_F(AutofillMetricsTest, UserHappinessFormLoadAndSubmission) { | 1197 TEST_F(AutofillMetricsTest, UserHappinessFormLoadAndSubmission) { |
| 1206 // Start with a form with insufficiently many fields. | 1198 // Start with a form with insufficiently many fields. |
| 1207 FormData form; | 1199 FormData form; |
| 1208 form.name = ASCIIToUTF16("TestForm"); | 1200 form.name = ASCIIToUTF16("TestForm"); |
| 1209 form.method = ASCIIToUTF16("POST"); | 1201 form.method = ASCIIToUTF16("POST"); |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1555 TimeTicks::FromInternalValue(5)); | 1547 TimeTicks::FromInternalValue(5)); |
| 1556 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), | 1548 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), |
| 1557 TimeTicks::FromInternalValue(3)); | 1549 TimeTicks::FromInternalValue(3)); |
| 1558 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); | 1550 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); |
| 1559 autofill_manager_->Reset(); | 1551 autofill_manager_->Reset(); |
| 1560 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); | 1552 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); |
| 1561 } | 1553 } |
| 1562 } | 1554 } |
| 1563 | 1555 |
| 1564 } // namespace autofill | 1556 } // namespace autofill |
| OLD | NEW |