| 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 "components/autofill/core/browser/autofill_cc_infobar_delegate.h" | 5 #include "components/autofill/core/browser/autofill_save_card_infobar_delegate_m
obile.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/test/histogram_tester.h" | 9 #include "base/test/histogram_tester.h" |
| 10 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 10 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 11 #include "chrome/browser/ui/autofill/chrome_autofill_client.h" | 11 #include "chrome/browser/ui/autofill/chrome_autofill_client.h" |
| 12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
| 14 #include "components/autofill/core/browser/autofill_test_utils.h" | 14 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 15 #include "components/autofill/core/browser/personal_data_manager.h" | 15 #include "components/autofill/core/browser/personal_data_manager.h" |
| 16 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 using testing::_; | 20 using testing::_; |
| 20 | 21 |
| 21 namespace autofill { | 22 namespace autofill { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 class TestPersonalDataManager : public PersonalDataManager { | 26 class TestPersonalDataManager : public PersonalDataManager { |
| 26 public: | 27 public: |
| 27 TestPersonalDataManager() : PersonalDataManager("en-US") {} | 28 TestPersonalDataManager() : PersonalDataManager("en-US") {} |
| 28 | 29 |
| 29 using PersonalDataManager::set_database; | 30 using PersonalDataManager::set_database; |
| 30 using PersonalDataManager::SetPrefService; | 31 using PersonalDataManager::SetPrefService; |
| 31 | 32 |
| 32 // Overridden to avoid a trip to the database. | 33 // Overridden to avoid a trip to the database. |
| 33 void LoadProfiles() override {} | 34 void LoadProfiles() override {} |
| 34 void LoadCreditCards() override {} | 35 void LoadCreditCards() override {} |
| 35 | 36 |
| 36 MOCK_METHOD1(SaveImportedCreditCard, | 37 MOCK_METHOD1(SaveImportedCreditCard, |
| 37 std::string(const CreditCard& imported_credit_card)); | 38 std::string(const CreditCard& imported_credit_card)); |
| 38 | 39 |
| 39 private: | 40 private: |
| 40 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); | 41 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); |
| 41 }; | 42 }; |
| 42 | 43 |
| 43 } // namespace | 44 } // namespace |
| 44 | 45 |
| 45 class AutofillCCInfobarDelegateTest : public ChromeRenderViewHostTestHarness { | 46 class AutofillSaveCardInfoBarDelegateMobileTest |
| 47 : public ChromeRenderViewHostTestHarness { |
| 46 public: | 48 public: |
| 47 AutofillCCInfobarDelegateTest(); | 49 AutofillSaveCardInfoBarDelegateMobileTest(); |
| 48 ~AutofillCCInfobarDelegateTest() override; | 50 ~AutofillSaveCardInfoBarDelegateMobileTest() override; |
| 49 | 51 |
| 50 void SetUp() override; | 52 void SetUp() override; |
| 51 void TearDown() override; | 53 void TearDown() override; |
| 52 | 54 |
| 53 protected: | 55 protected: |
| 54 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(); | 56 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(); |
| 55 | 57 |
| 56 scoped_ptr<TestPersonalDataManager> personal_data_; | 58 scoped_ptr<TestPersonalDataManager> personal_data_; |
| 57 | 59 |
| 58 private: | 60 private: |
| 59 DISALLOW_COPY_AND_ASSIGN(AutofillCCInfobarDelegateTest); | 61 DISALLOW_COPY_AND_ASSIGN(AutofillSaveCardInfoBarDelegateMobileTest); |
| 60 }; | 62 }; |
| 61 | 63 |
| 62 AutofillCCInfobarDelegateTest::AutofillCCInfobarDelegateTest() { | 64 AutofillSaveCardInfoBarDelegateMobileTest:: |
| 63 } | 65 AutofillSaveCardInfoBarDelegateMobileTest() {} |
| 64 | 66 |
| 65 AutofillCCInfobarDelegateTest::~AutofillCCInfobarDelegateTest() {} | 67 AutofillSaveCardInfoBarDelegateMobileTest:: |
| 68 ~AutofillSaveCardInfoBarDelegateMobileTest() {} |
| 66 | 69 |
| 67 void AutofillCCInfobarDelegateTest::SetUp() { | 70 void AutofillSaveCardInfoBarDelegateMobileTest::SetUp() { |
| 68 ChromeRenderViewHostTestHarness::SetUp(); | 71 ChromeRenderViewHostTestHarness::SetUp(); |
| 69 | 72 |
| 70 // Ensure Mac OS X does not pop up a modal dialog for the Address Book. | |
| 71 test::DisableSystemServices(profile()->GetPrefs()); | |
| 72 | |
| 73 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL); | 73 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL); |
| 74 | 74 |
| 75 ChromeAutofillClient::CreateForWebContents(web_contents()); | 75 ChromeAutofillClient::CreateForWebContents(web_contents()); |
| 76 ChromeAutofillClient* autofill_client = | 76 ChromeAutofillClient* autofill_client = |
| 77 ChromeAutofillClient::FromWebContents(web_contents()); | 77 ChromeAutofillClient::FromWebContents(web_contents()); |
| 78 | 78 |
| 79 personal_data_.reset(new TestPersonalDataManager()); | 79 personal_data_.reset(new TestPersonalDataManager()); |
| 80 personal_data_->set_database(autofill_client->GetDatabase()); | 80 personal_data_->set_database(autofill_client->GetDatabase()); |
| 81 personal_data_->SetPrefService(profile()->GetPrefs()); | 81 personal_data_->SetPrefService(profile()->GetPrefs()); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void AutofillCCInfobarDelegateTest::TearDown() { | 84 void AutofillSaveCardInfoBarDelegateMobileTest::TearDown() { |
| 85 personal_data_.reset(); | 85 personal_data_.reset(); |
| 86 ChromeRenderViewHostTestHarness::TearDown(); | 86 ChromeRenderViewHostTestHarness::TearDown(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 scoped_ptr<ConfirmInfoBarDelegate> | 89 scoped_ptr<ConfirmInfoBarDelegate> |
| 90 AutofillCCInfobarDelegateTest::CreateDelegate() { | 90 AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegate() { |
| 91 base::HistogramTester histogram_tester; | 91 base::HistogramTester histogram_tester; |
| 92 CreditCard credit_card; | 92 CreditCard credit_card; |
| 93 scoped_ptr<ConfirmInfoBarDelegate> delegate(AutofillCCInfoBarDelegate::Create( | 93 scoped_ptr<base::DictionaryValue> legal_message; |
| 94 base::Bind( | 94 scoped_ptr<ConfirmInfoBarDelegate> delegate( |
| 95 base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard), | 95 new AutofillSaveCardInfoBarDelegateMobile( |
| 96 base::Unretained(personal_data_.get()), credit_card))); | 96 false, credit_card, std::move(legal_message), |
| 97 base::Bind(base::IgnoreResult( |
| 98 &TestPersonalDataManager::SaveImportedCreditCard), |
| 99 base::Unretained(personal_data_.get()), credit_card))); |
| 97 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", | 100 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", |
| 98 AutofillMetrics::INFOBAR_SHOWN, 1); | 101 AutofillMetrics::INFOBAR_SHOWN, 1); |
| 99 return delegate; | 102 return delegate; |
| 100 } | 103 } |
| 101 | 104 |
| 102 // Test that credit card infobar metrics are logged correctly. | 105 // Test that credit card infobar metrics are logged correctly. |
| 103 TEST_F(AutofillCCInfobarDelegateTest, Metrics) { | 106 TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics) { |
| 104 ::testing::InSequence dummy; | 107 ::testing::InSequence dummy; |
| 105 | 108 |
| 106 // Accept the infobar. | 109 // Accept the infobar. |
| 107 { | 110 { |
| 108 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); | 111 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); |
| 109 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); | 112 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); |
| 110 | 113 |
| 111 base::HistogramTester histogram_tester; | 114 base::HistogramTester histogram_tester; |
| 112 EXPECT_TRUE(infobar->Accept()); | 115 EXPECT_TRUE(infobar->Accept()); |
| 113 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", | 116 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", |
| (...skipping 25 matching lines...) Expand all Loading... |
| 139 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); | 142 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); |
| 140 | 143 |
| 141 base::HistogramTester histogram_tester; | 144 base::HistogramTester histogram_tester; |
| 142 infobar.reset(); | 145 infobar.reset(); |
| 143 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", | 146 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", |
| 144 AutofillMetrics::INFOBAR_IGNORED, 1); | 147 AutofillMetrics::INFOBAR_IGNORED, 1); |
| 145 } | 148 } |
| 146 } | 149 } |
| 147 | 150 |
| 148 } // namespace autofill | 151 } // namespace autofill |
| OLD | NEW |