| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/autofill/autocheckout_infobar_delegate.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_manager_delegate.h" | 15 #include "chrome/browser/autofill/autofill_manager_delegate.h" |
| 15 #include "chrome/browser/autofill/autofill_metrics.h" | 16 #include "chrome/browser/autofill/autofill_metrics.h" |
| 16 #include "chrome/browser/autofill/personal_data_manager.h" | 17 #include "chrome/browser/autofill/personal_data_manager.h" |
| 17 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 18 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 18 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" | 19 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" |
| 19 #include "chrome/browser/webdata/web_data_service.h" | 20 #include "chrome/browser/webdata/web_data_service.h" |
| 20 #include "chrome/common/form_data.h" | 21 #include "chrome/common/form_data.h" |
| 21 #include "chrome/common/form_field_data.h" | 22 #include "chrome/common/form_field_data.h" |
| 22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 23 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 23 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
| 24 #include "content/public/test/test_browser_thread.h" | 25 #include "content/public/test/test_browser_thread.h" |
| 26 #include "googleurl/src/gurl.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "ui/gfx/rect.h" | 29 #include "ui/gfx/rect.h" |
| 28 | 30 |
| 29 using content::BrowserThread; | 31 using content::BrowserThread; |
| 30 using ::testing::_; | 32 using ::testing::_; |
| 31 using ::testing::AnyNumber; | 33 using ::testing::AnyNumber; |
| 32 using ::testing::Mock; | 34 using ::testing::Mock; |
| 33 using base::TimeTicks; | 35 using base::TimeTicks; |
| 34 using base::TimeDelta; | 36 using base::TimeDelta; |
| 35 | 37 |
| 36 namespace { | 38 namespace { |
| 37 | 39 |
| 38 class MockAutofillMetrics : public AutofillMetrics { | 40 class MockAutofillMetrics : public AutofillMetrics { |
| 39 public: | 41 public: |
| 40 MockAutofillMetrics() {} | 42 MockAutofillMetrics() {} |
| 41 MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric)); | 43 MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric)); |
| 44 MOCK_CONST_METHOD1(LogAutocheckoutInfoBarMetric, void(InfoBarMetric metric)); |
| 42 MOCK_CONST_METHOD1(LogDeveloperEngagementMetric, | 45 MOCK_CONST_METHOD1(LogDeveloperEngagementMetric, |
| 43 void(DeveloperEngagementMetric metric)); | 46 void(DeveloperEngagementMetric metric)); |
| 44 MOCK_CONST_METHOD3(LogHeuristicTypePrediction, | 47 MOCK_CONST_METHOD3(LogHeuristicTypePrediction, |
| 45 void(FieldTypeQualityMetric metric, | 48 void(FieldTypeQualityMetric metric, |
| 46 AutofillFieldType field_type, | 49 AutofillFieldType field_type, |
| 47 const std::string& experiment_id)); | 50 const std::string& experiment_id)); |
| 48 MOCK_CONST_METHOD3(LogOverallTypePrediction, | 51 MOCK_CONST_METHOD3(LogOverallTypePrediction, |
| 49 void(FieldTypeQualityMetric metric, | 52 void(FieldTypeQualityMetric metric, |
| 50 AutofillFieldType field_type, | 53 AutofillFieldType field_type, |
| 51 const std::string& experiment_id)); | 54 const std::string& experiment_id)); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 // AutofillManager is ref counted. | 253 // AutofillManager is ref counted. |
| 251 virtual ~TestAutofillManager() {} | 254 virtual ~TestAutofillManager() {} |
| 252 | 255 |
| 253 bool autofill_enabled_; | 256 bool autofill_enabled_; |
| 254 bool did_finish_async_form_submit_; | 257 bool did_finish_async_form_submit_; |
| 255 bool message_loop_is_running_; | 258 bool message_loop_is_running_; |
| 256 | 259 |
| 257 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 260 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
| 258 }; | 261 }; |
| 259 | 262 |
| 263 class TestAutocheckoutManager : public AutocheckoutManager { |
| 264 public: |
| 265 explicit TestAutocheckoutManager(AutofillManager* autofill_manager) |
| 266 : AutocheckoutManager(autofill_manager) { |
| 267 } |
| 268 |
| 269 virtual void ShowAutocheckoutDialog( |
| 270 const GURL& frame_url, |
| 271 const content::SSLStatus& ssl_status) OVERRIDE { |
| 272 // no-op. Just used as callback from autocheckout_infobar_delegate. |
| 273 } |
| 274 |
| 275 virtual ~TestAutocheckoutManager() { |
| 276 } |
| 277 |
| 278 private: |
| 279 DISALLOW_COPY_AND_ASSIGN(TestAutocheckoutManager); |
| 280 }; |
| 281 |
| 260 } // namespace | 282 } // namespace |
| 261 | 283 |
| 262 class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { | 284 class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { |
| 263 public: | 285 public: |
| 264 AutofillMetricsTest(); | 286 AutofillMetricsTest(); |
| 265 virtual ~AutofillMetricsTest(); | 287 virtual ~AutofillMetricsTest(); |
| 266 | 288 |
| 267 virtual void SetUp() OVERRIDE; | 289 virtual void SetUp() OVERRIDE; |
| 268 virtual void TearDown() OVERRIDE; | 290 virtual void TearDown() OVERRIDE; |
| 269 | 291 |
| 270 protected: | 292 protected: |
| 271 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( | 293 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( |
| 272 MockAutofillMetrics* metric_logger, | 294 MockAutofillMetrics* metric_logger, |
| 273 CreditCard** created_card); | 295 CreditCard** created_card); |
| 274 | 296 |
| 297 scoped_ptr<ConfirmInfoBarDelegate> CreateAutocheckoutDelegate( |
| 298 MockAutofillMetrics* metric_logger); |
| 299 |
| 275 content::TestBrowserThread ui_thread_; | 300 content::TestBrowserThread ui_thread_; |
| 276 content::TestBrowserThread file_thread_; | 301 content::TestBrowserThread file_thread_; |
| 277 | 302 |
| 278 scoped_refptr<TestAutofillManager> autofill_manager_; | 303 scoped_refptr<TestAutofillManager> autofill_manager_; |
| 279 TestPersonalDataManager personal_data_; | 304 TestPersonalDataManager personal_data_; |
| 280 | 305 |
| 281 private: | 306 private: |
| 282 std::string default_gmock_verbosity_level_; | 307 std::string default_gmock_verbosity_level_; |
| 283 | 308 |
| 284 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); | 309 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 EXPECT_CALL(*metric_logger, | 365 EXPECT_CALL(*metric_logger, |
| 341 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); | 366 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); |
| 342 // The delegate created below will take ownership of this object. | 367 // The delegate created below will take ownership of this object. |
| 343 CreditCard* credit_card = new CreditCard(); | 368 CreditCard* credit_card = new CreditCard(); |
| 344 if (created_card) | 369 if (created_card) |
| 345 *created_card = credit_card; | 370 *created_card = credit_card; |
| 346 return AutofillCCInfoBarDelegate::Create(credit_card, &personal_data_, | 371 return AutofillCCInfoBarDelegate::Create(credit_card, &personal_data_, |
| 347 metric_logger); | 372 metric_logger); |
| 348 } | 373 } |
| 349 | 374 |
| 375 scoped_ptr<ConfirmInfoBarDelegate> |
| 376 AutofillMetricsTest::CreateAutocheckoutDelegate( |
| 377 MockAutofillMetrics* metric_logger) { |
| 378 EXPECT_CALL(*metric_logger, |
| 379 LogAutocheckoutInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); |
| 380 GURL url("www.google.com"); |
| 381 content::SSLStatus ssl_status; |
| 382 return AutocheckoutInfoBarDelegate::Create( |
| 383 *metric_logger, |
| 384 url, |
| 385 ssl_status, |
| 386 new TestAutocheckoutManager(NULL)); |
| 387 } |
| 388 |
| 350 // Test that we log quality metrics appropriately. | 389 // Test that we log quality metrics appropriately. |
| 351 TEST_F(AutofillMetricsTest, QualityMetrics) { | 390 TEST_F(AutofillMetricsTest, QualityMetrics) { |
| 352 // Set up our form data. | 391 // Set up our form data. |
| 353 FormData form; | 392 FormData form; |
| 354 form.name = ASCIIToUTF16("TestForm"); | 393 form.name = ASCIIToUTF16("TestForm"); |
| 355 form.method = ASCIIToUTF16("POST"); | 394 form.method = ASCIIToUTF16("POST"); |
| 356 form.origin = GURL("http://example.com/form.html"); | 395 form.origin = GURL("http://example.com/form.html"); |
| 357 form.action = GURL("http://example.com/submit.html"); | 396 form.action = GURL("http://example.com/submit.html"); |
| 358 form.user_submitted = true; | 397 form.user_submitted = true; |
| 359 | 398 |
| (...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1179 // Ignore the infobar. | 1218 // Ignore the infobar. |
| 1180 { | 1219 { |
| 1181 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger, | 1220 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger, |
| 1182 NULL)); | 1221 NULL)); |
| 1183 ASSERT_TRUE(infobar); | 1222 ASSERT_TRUE(infobar); |
| 1184 EXPECT_CALL(metric_logger, | 1223 EXPECT_CALL(metric_logger, |
| 1185 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(1); | 1224 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(1); |
| 1186 } | 1225 } |
| 1187 } | 1226 } |
| 1188 | 1227 |
| 1228 // Test that autofill flow infobar metrics are logged correctly. |
| 1229 TEST_F(AutofillMetricsTest, AutocheckoutInfoBar) { |
| 1230 MockAutofillMetrics metric_logger; |
| 1231 ::testing::InSequence dummy; |
| 1232 |
| 1233 // Accept the infobar. |
| 1234 { |
| 1235 scoped_ptr<ConfirmInfoBarDelegate> infobar( |
| 1236 CreateAutocheckoutDelegate(&metric_logger)); |
| 1237 ASSERT_TRUE(infobar); |
| 1238 EXPECT_CALL(metric_logger, |
| 1239 LogAutocheckoutInfoBarMetric( |
| 1240 AutofillMetrics::INFOBAR_ACCEPTED)).Times(1); |
| 1241 EXPECT_CALL(metric_logger, |
| 1242 LogAutocheckoutInfoBarMetric( |
| 1243 AutofillMetrics::INFOBAR_IGNORED)).Times(0); |
| 1244 EXPECT_TRUE(infobar->Accept()); |
| 1245 } |
| 1246 |
| 1247 // Cancel the infobar. |
| 1248 { |
| 1249 scoped_ptr<ConfirmInfoBarDelegate> infobar( |
| 1250 CreateAutocheckoutDelegate(&metric_logger)); |
| 1251 ASSERT_TRUE(infobar); |
| 1252 EXPECT_CALL(metric_logger, |
| 1253 LogAutocheckoutInfoBarMetric( |
| 1254 AutofillMetrics::INFOBAR_DENIED)).Times(1); |
| 1255 EXPECT_CALL(metric_logger, |
| 1256 LogAutocheckoutInfoBarMetric( |
| 1257 AutofillMetrics::INFOBAR_IGNORED)).Times(0); |
| 1258 EXPECT_TRUE(infobar->Cancel()); |
| 1259 } |
| 1260 |
| 1261 // Dismiss the infobar. |
| 1262 { |
| 1263 scoped_ptr<ConfirmInfoBarDelegate> infobar( |
| 1264 CreateAutocheckoutDelegate(&metric_logger)); |
| 1265 ASSERT_TRUE(infobar); |
| 1266 EXPECT_CALL(metric_logger, |
| 1267 LogAutocheckoutInfoBarMetric( |
| 1268 AutofillMetrics::INFOBAR_DENIED)).Times(1); |
| 1269 EXPECT_CALL(metric_logger, |
| 1270 LogAutocheckoutInfoBarMetric( |
| 1271 AutofillMetrics::INFOBAR_IGNORED)).Times(0); |
| 1272 infobar->InfoBarDismissed(); |
| 1273 } |
| 1274 |
| 1275 // Ignore the infobar. |
| 1276 { |
| 1277 scoped_ptr<ConfirmInfoBarDelegate> infobar( |
| 1278 CreateAutocheckoutDelegate(&metric_logger)); |
| 1279 ASSERT_TRUE(infobar); |
| 1280 EXPECT_CALL(metric_logger, |
| 1281 LogAutocheckoutInfoBarMetric( |
| 1282 AutofillMetrics::INFOBAR_IGNORED)).Times(1); |
| 1283 } |
| 1284 } |
| 1285 |
| 1286 |
| 1189 // Test that server query response experiment id metrics are logged correctly. | 1287 // Test that server query response experiment id metrics are logged correctly. |
| 1190 TEST_F(AutofillMetricsTest, ServerQueryExperimentIdForQuery) { | 1288 TEST_F(AutofillMetricsTest, ServerQueryExperimentIdForQuery) { |
| 1191 MockAutofillMetrics metric_logger; | 1289 MockAutofillMetrics metric_logger; |
| 1192 ::testing::InSequence dummy; | 1290 ::testing::InSequence dummy; |
| 1193 | 1291 |
| 1194 // No experiment specified. | 1292 // No experiment specified. |
| 1195 EXPECT_CALL(metric_logger, | 1293 EXPECT_CALL(metric_logger, |
| 1196 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED)); | 1294 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED)); |
| 1197 EXPECT_CALL(metric_logger, | 1295 EXPECT_CALL(metric_logger, |
| 1198 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_PARSED)); | 1296 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_PARSED)); |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1562 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); | 1660 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); |
| 1563 autofill_manager_->OnDidFillAutofillFormData( | 1661 autofill_manager_->OnDidFillAutofillFormData( |
| 1564 TimeTicks::FromInternalValue(5)); | 1662 TimeTicks::FromInternalValue(5)); |
| 1565 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), | 1663 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), |
| 1566 TimeTicks::FromInternalValue(3)); | 1664 TimeTicks::FromInternalValue(3)); |
| 1567 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); | 1665 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); |
| 1568 autofill_manager_->Reset(); | 1666 autofill_manager_->Reset(); |
| 1569 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); | 1667 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); |
| 1570 } | 1668 } |
| 1571 } | 1669 } |
| OLD | NEW |