| 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/api/infobars/infobar_service.h" | 11 #include "chrome/browser/api/infobars/infobar_service.h" |
| 12 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" | 12 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" |
| 13 #include "chrome/browser/autofill/autofill_common_test.h" | 13 #include "chrome/browser/autofill/autofill_common_test.h" |
| 14 #include "chrome/browser/autofill/autofill_manager.h" | 14 #include "chrome/browser/autofill/autofill_manager.h" |
| 15 #include "chrome/browser/autofill/autofill_manager_delegate.h" | 15 #include "chrome/browser/autofill/autofill_manager_delegate.h" |
| 16 #include "chrome/browser/autofill/autofill_metrics.h" | 16 #include "chrome/browser/autofill/autofill_metrics.h" |
| 17 #include "chrome/browser/autofill/personal_data_manager.h" | 17 #include "chrome/browser/autofill/personal_data_manager.h" |
| 18 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 18 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 19 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 19 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" | 20 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" |
| 20 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
| 21 #include "chrome/browser/ui/tab_contents/test_tab_contents.h" | |
| 22 #include "chrome/browser/webdata/web_data_service.h" | 21 #include "chrome/browser/webdata/web_data_service.h" |
| 23 #include "chrome/common/form_data.h" | 22 #include "chrome/common/form_data.h" |
| 24 #include "chrome/common/form_field_data.h" | 23 #include "chrome/common/form_field_data.h" |
| 24 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 25 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
| 26 #include "content/public/test/test_browser_thread.h" | 26 #include "content/public/test/test_browser_thread.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 29 #include "ui/gfx/rect.h" | 29 #include "ui/gfx/rect.h" |
| 30 | 30 |
| 31 using content::BrowserThread; | 31 using content::BrowserThread; |
| 32 using ::testing::_; | 32 using ::testing::_; |
| 33 using ::testing::AnyNumber; | 33 using ::testing::AnyNumber; |
| 34 using ::testing::Mock; | 34 using ::testing::Mock; |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 248 |
| 249 bool autofill_enabled_; | 249 bool autofill_enabled_; |
| 250 bool did_finish_async_form_submit_; | 250 bool did_finish_async_form_submit_; |
| 251 bool message_loop_is_running_; | 251 bool message_loop_is_running_; |
| 252 | 252 |
| 253 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 253 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
| 254 }; | 254 }; |
| 255 | 255 |
| 256 } // namespace | 256 } // namespace |
| 257 | 257 |
| 258 class AutofillMetricsTest : public TabContentsTestHarness { | 258 class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { |
| 259 public: | 259 public: |
| 260 AutofillMetricsTest(); | 260 AutofillMetricsTest(); |
| 261 virtual ~AutofillMetricsTest(); | 261 virtual ~AutofillMetricsTest(); |
| 262 | 262 |
| 263 virtual void SetUp() OVERRIDE; | 263 virtual void SetUp() OVERRIDE; |
| 264 virtual void TearDown() OVERRIDE; | 264 virtual void TearDown() OVERRIDE; |
| 265 | 265 |
| 266 protected: | 266 protected: |
| 267 AutofillCCInfoBarDelegate* CreateDelegate(MockAutofillMetrics* metric_logger, | 267 AutofillCCInfoBarDelegate* CreateDelegate(MockAutofillMetrics* metric_logger, |
| 268 CreditCard** created_card); | 268 CreditCard** created_card); |
| 269 | 269 |
| 270 content::TestBrowserThread ui_thread_; | 270 content::TestBrowserThread ui_thread_; |
| 271 content::TestBrowserThread file_thread_; | 271 content::TestBrowserThread file_thread_; |
| 272 | 272 |
| 273 scoped_refptr<TestAutofillManager> autofill_manager_; | 273 scoped_refptr<TestAutofillManager> autofill_manager_; |
| 274 TestPersonalDataManager personal_data_; | 274 TestPersonalDataManager personal_data_; |
| 275 | 275 |
| 276 private: | 276 private: |
| 277 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); | 277 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); |
| 278 }; | 278 }; |
| 279 | 279 |
| 280 AutofillMetricsTest::AutofillMetricsTest() | 280 AutofillMetricsTest::AutofillMetricsTest() |
| 281 : TabContentsTestHarness(), | 281 : ChromeRenderViewHostTestHarness(), |
| 282 ui_thread_(BrowserThread::UI, &message_loop_), | 282 ui_thread_(BrowserThread::UI, &message_loop_), |
| 283 file_thread_(BrowserThread::FILE) { | 283 file_thread_(BrowserThread::FILE) { |
| 284 } | 284 } |
| 285 | 285 |
| 286 AutofillMetricsTest::~AutofillMetricsTest() { | 286 AutofillMetricsTest::~AutofillMetricsTest() { |
| 287 // Order of destruction is important as AutofillManager relies on | 287 // Order of destruction is important as AutofillManager relies on |
| 288 // PersonalDataManager to be around when it gets destroyed. | 288 // PersonalDataManager to be around when it gets destroyed. |
| 289 autofill_manager_ = NULL; | 289 autofill_manager_ = NULL; |
| 290 } | 290 } |
| 291 | 291 |
| 292 void AutofillMetricsTest::SetUp() { | 292 void AutofillMetricsTest::SetUp() { |
| 293 Profile* profile = new TestingProfile(); | 293 Profile* profile = new TestingProfile(); |
| 294 browser_context_.reset(profile); | 294 browser_context_.reset(profile); |
| 295 PersonalDataManagerFactory::GetInstance()->SetTestingFactory( | 295 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile, NULL); |
| 296 profile, NULL); | |
| 297 | 296 |
| 298 TabContentsTestHarness::SetUp(); | 297 ChromeRenderViewHostTestHarness::SetUp(); |
| 299 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); | 298 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); |
| 300 autofill_manager_ = new TestAutofillManager( | 299 autofill_manager_ = new TestAutofillManager( |
| 301 web_contents(), | 300 web_contents(), |
| 302 TabAutofillManagerDelegate::FromWebContents(web_contents()), | 301 TabAutofillManagerDelegate::FromWebContents(web_contents()), |
| 303 &personal_data_); | 302 &personal_data_); |
| 304 | 303 |
| 305 file_thread_.Start(); | 304 file_thread_.Start(); |
| 306 } | 305 } |
| 307 | 306 |
| 308 void AutofillMetricsTest::TearDown() { | 307 void AutofillMetricsTest::TearDown() { |
| 309 // Order of destruction is important as AutofillManager relies on | 308 // Order of destruction is important as AutofillManager relies on |
| 310 // PersonalDataManager to be around when it gets destroyed. Also, a real | 309 // PersonalDataManager to be around when it gets destroyed. Also, a real |
| 311 // AutofillManager is tied to the lifetime of the WebContents, so it must | 310 // AutofillManager is tied to the lifetime of the WebContents, so it must |
| 312 // be destroyed at the destruction of the WebContents. | 311 // be destroyed at the destruction of the WebContents. |
| 313 autofill_manager_ = NULL; | 312 autofill_manager_ = NULL; |
| 314 file_thread_.Stop(); | 313 file_thread_.Stop(); |
| 315 TabContentsTestHarness::TearDown(); | 314 ChromeRenderViewHostTestHarness::TearDown(); |
| 316 } | 315 } |
| 317 | 316 |
| 318 AutofillCCInfoBarDelegate* AutofillMetricsTest::CreateDelegate( | 317 AutofillCCInfoBarDelegate* AutofillMetricsTest::CreateDelegate( |
| 319 MockAutofillMetrics* metric_logger, | 318 MockAutofillMetrics* metric_logger, |
| 320 CreditCard** created_card) { | 319 CreditCard** created_card) { |
| 321 EXPECT_CALL(*metric_logger, | 320 EXPECT_CALL(*metric_logger, |
| 322 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); | 321 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); |
| 323 // The delegate created below will take ownership of this object. | 322 // The delegate created below will take ownership of this object. |
| 324 CreditCard* credit_card = new CreditCard(); | 323 CreditCard* credit_card = new CreditCard(); |
| 325 if (created_card) | 324 if (created_card) |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 // Establish our expectations. | 1036 // Establish our expectations. |
| 1038 EXPECT_CALL(*autofill_manager_->metric_logger(), | 1037 EXPECT_CALL(*autofill_manager_->metric_logger(), |
| 1039 LogIsAutofillEnabledAtPageLoad(false)).Times(1); | 1038 LogIsAutofillEnabledAtPageLoad(false)).Times(1); |
| 1040 | 1039 |
| 1041 autofill_manager_->set_autofill_enabled(false); | 1040 autofill_manager_->set_autofill_enabled(false); |
| 1042 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks()); | 1041 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks()); |
| 1043 } | 1042 } |
| 1044 | 1043 |
| 1045 // Test that credit card infobar metrics are logged correctly. | 1044 // Test that credit card infobar metrics are logged correctly. |
| 1046 TEST_F(AutofillMetricsTest, CreditCardInfoBar) { | 1045 TEST_F(AutofillMetricsTest, CreditCardInfoBar) { |
| 1046 InfoBarTabHelper::CreateForWebContents(web_contents()); |
| 1047 |
| 1047 MockAutofillMetrics metric_logger; | 1048 MockAutofillMetrics metric_logger; |
| 1048 ::testing::InSequence dummy; | 1049 ::testing::InSequence dummy; |
| 1049 | 1050 |
| 1050 // Accept the infobar. | 1051 // Accept the infobar. |
| 1051 { | 1052 { |
| 1052 CreditCard* credit_card; | 1053 CreditCard* credit_card; |
| 1053 scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger, | 1054 scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger, |
| 1054 &credit_card)); | 1055 &credit_card)); |
| 1055 EXPECT_CALL(personal_data_, SaveImportedCreditCard(*credit_card)); | 1056 EXPECT_CALL(personal_data_, SaveImportedCreditCard(*credit_card)); |
| 1056 EXPECT_CALL(metric_logger, | 1057 EXPECT_CALL(metric_logger, |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1471 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), | 1472 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), |
| 1472 TimeTicks::FromInternalValue(3)); | 1473 TimeTicks::FromInternalValue(3)); |
| 1473 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); | 1474 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); |
| 1474 autofill_manager_->Reset(); | 1475 autofill_manager_->Reset(); |
| 1475 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); | 1476 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); |
| 1476 } | 1477 } |
| 1477 | 1478 |
| 1478 // Restore the global Gmock verbosity level to its default value. | 1479 // Restore the global Gmock verbosity level to its default value. |
| 1479 ::testing::FLAGS_gmock_verbose = "warning"; | 1480 ::testing::FLAGS_gmock_verbose = "warning"; |
| 1480 } | 1481 } |
| OLD | NEW |