| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/autofill/autofill_cc_infobar_delegate.h" | 5 #include "components/autofill/core/browser/autofill_cc_infobar_delegate.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/test/histogram_tester.h" | 8 #include "base/test/histogram_tester.h" |
| 9 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 9 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 10 #include "chrome/browser/ui/autofill/chrome_autofill_client.h" | 10 #include "chrome/browser/ui/autofill/chrome_autofill_client.h" |
| 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 12 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 13 #include "components/autofill/core/browser/autofill_test_utils.h" | 13 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 14 #include "components/autofill/core/browser/personal_data_manager.h" | 14 #include "components/autofill/core/browser/personal_data_manager.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 36 std::string(const CreditCard& imported_credit_card)); | 36 std::string(const CreditCard& imported_credit_card)); |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); | 39 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 class AutofillCCInfobarDelegateTest : public ChromeRenderViewHostTestHarness { | 44 class AutofillCCInfobarDelegateTest : public ChromeRenderViewHostTestHarness { |
| 45 public: | 45 public: |
| 46 AutofillCCInfobarDelegateTest(); |
| 46 ~AutofillCCInfobarDelegateTest() override; | 47 ~AutofillCCInfobarDelegateTest() override; |
| 47 | 48 |
| 48 void SetUp() override; | 49 void SetUp() override; |
| 49 void TearDown() override; | 50 void TearDown() override; |
| 50 | 51 |
| 51 protected: | 52 protected: |
| 52 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(); | 53 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(); |
| 53 | 54 |
| 54 scoped_ptr<TestPersonalDataManager> personal_data_; | 55 scoped_ptr<TestPersonalDataManager> personal_data_; |
| 56 |
| 57 private: |
| 58 DISALLOW_COPY_AND_ASSIGN(AutofillCCInfobarDelegateTest); |
| 55 }; | 59 }; |
| 56 | 60 |
| 61 AutofillCCInfobarDelegateTest::AutofillCCInfobarDelegateTest() { |
| 62 } |
| 63 |
| 57 AutofillCCInfobarDelegateTest::~AutofillCCInfobarDelegateTest() {} | 64 AutofillCCInfobarDelegateTest::~AutofillCCInfobarDelegateTest() {} |
| 58 | 65 |
| 59 void AutofillCCInfobarDelegateTest::SetUp() { | 66 void AutofillCCInfobarDelegateTest::SetUp() { |
| 60 ChromeRenderViewHostTestHarness::SetUp(); | 67 ChromeRenderViewHostTestHarness::SetUp(); |
| 61 | 68 |
| 62 // Ensure Mac OS X does not pop up a modal dialog for the Address Book. | 69 // Ensure Mac OS X does not pop up a modal dialog for the Address Book. |
| 63 test::DisableSystemServices(profile()->GetPrefs()); | 70 test::DisableSystemServices(profile()->GetPrefs()); |
| 64 | 71 |
| 65 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL); | 72 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL); |
| 66 | 73 |
| 67 ChromeAutofillClient::CreateForWebContents(web_contents()); | 74 ChromeAutofillClient::CreateForWebContents(web_contents()); |
| 68 ChromeAutofillClient* autofill_client = | 75 ChromeAutofillClient* autofill_client = |
| 69 ChromeAutofillClient::FromWebContents(web_contents()); | 76 ChromeAutofillClient::FromWebContents(web_contents()); |
| 70 | 77 |
| 71 personal_data_.reset(new TestPersonalDataManager()); | 78 personal_data_.reset(new TestPersonalDataManager()); |
| 72 personal_data_->set_database(autofill_client->GetDatabase()); | 79 personal_data_->set_database(autofill_client->GetDatabase()); |
| 73 personal_data_->SetPrefService(profile()->GetPrefs()); | 80 personal_data_->SetPrefService(profile()->GetPrefs()); |
| 74 } | 81 } |
| 75 | 82 |
| 76 void AutofillCCInfobarDelegateTest::TearDown() { | 83 void AutofillCCInfobarDelegateTest::TearDown() { |
| 77 personal_data_.reset(); | 84 personal_data_.reset(); |
| 78 ChromeRenderViewHostTestHarness::TearDown(); | 85 ChromeRenderViewHostTestHarness::TearDown(); |
| 79 } | 86 } |
| 80 | 87 |
| 81 scoped_ptr<ConfirmInfoBarDelegate> | 88 scoped_ptr<ConfirmInfoBarDelegate> |
| 82 AutofillCCInfobarDelegateTest::CreateDelegate() { | 89 AutofillCCInfobarDelegateTest::CreateDelegate() { |
| 83 base::HistogramTester histogram_tester; | 90 base::HistogramTester histogram_tester; |
| 84 CreditCard credit_card; | 91 CreditCard credit_card; |
| 85 scoped_ptr<ConfirmInfoBarDelegate> delegate( | 92 scoped_ptr<ConfirmInfoBarDelegate> delegate(AutofillCCInfoBarDelegate::Create( |
| 86 AutofillCCInfoBarDelegate::Create(base::Bind( | 93 ChromeAutofillClient::FromWebContents(web_contents()), |
| 94 base::Bind( |
| 87 base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard), | 95 base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard), |
| 88 base::Unretained(personal_data_.get()), credit_card))); | 96 base::Unretained(personal_data_.get()), credit_card))); |
| 89 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", | 97 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", |
| 90 AutofillMetrics::INFOBAR_SHOWN, 1); | 98 AutofillMetrics::INFOBAR_SHOWN, 1); |
| 91 return delegate.Pass(); | 99 return delegate.Pass(); |
| 92 } | 100 } |
| 93 | 101 |
| 94 // Test that credit card infobar metrics are logged correctly. | 102 // Test that credit card infobar metrics are logged correctly. |
| 95 TEST_F(AutofillCCInfobarDelegateTest, Metrics) { | 103 TEST_F(AutofillCCInfobarDelegateTest, Metrics) { |
| 96 ::testing::InSequence dummy; | 104 ::testing::InSequence dummy; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); | 139 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); |
| 132 | 140 |
| 133 base::HistogramTester histogram_tester; | 141 base::HistogramTester histogram_tester; |
| 134 infobar.reset(); | 142 infobar.reset(); |
| 135 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", | 143 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", |
| 136 AutofillMetrics::INFOBAR_IGNORED, 1); | 144 AutofillMetrics::INFOBAR_IGNORED, 1); |
| 137 } | 145 } |
| 138 } | 146 } |
| 139 | 147 |
| 140 } // namespace autofill | 148 } // namespace autofill |
| OLD | NEW |