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 27 matching lines...) Expand all Loading... |
43 | 43 |
44 class AutofillCCInfobarDelegateTest : public ChromeRenderViewHostTestHarness { | 44 class AutofillCCInfobarDelegateTest : public ChromeRenderViewHostTestHarness { |
45 public: | 45 public: |
46 ~AutofillCCInfobarDelegateTest() override; | 46 ~AutofillCCInfobarDelegateTest() override; |
47 | 47 |
48 void SetUp() override; | 48 void SetUp() override; |
49 void TearDown() override; | 49 void TearDown() override; |
50 | 50 |
51 protected: | 51 protected: |
52 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(); | 52 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(); |
| 53 ContentAutofillDriver* GetAutofillDriverForMainFrame(); |
53 | 54 |
54 scoped_ptr<TestPersonalDataManager> personal_data_; | 55 scoped_ptr<TestPersonalDataManager> personal_data_; |
55 }; | 56 }; |
56 | 57 |
57 AutofillCCInfobarDelegateTest::~AutofillCCInfobarDelegateTest() {} | 58 AutofillCCInfobarDelegateTest::~AutofillCCInfobarDelegateTest() {} |
58 | 59 |
59 void AutofillCCInfobarDelegateTest::SetUp() { | 60 void AutofillCCInfobarDelegateTest::SetUp() { |
60 ChromeRenderViewHostTestHarness::SetUp(); | 61 ChromeRenderViewHostTestHarness::SetUp(); |
61 | 62 |
62 // Ensure Mac OS X does not pop up a modal dialog for the Address Book. | 63 // Ensure Mac OS X does not pop up a modal dialog for the Address Book. |
63 test::DisableSystemServices(profile()->GetPrefs()); | 64 test::DisableSystemServices(profile()->GetPrefs()); |
64 | 65 |
65 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL); | 66 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL); |
66 | 67 |
67 ChromeAutofillClient::CreateForWebContents(web_contents()); | 68 ChromeAutofillClient::CreateForWebContents(web_contents()); |
68 ChromeAutofillClient* autofill_client = | 69 ChromeAutofillClient* autofill_client = |
69 ChromeAutofillClient::FromWebContents(web_contents()); | 70 ChromeAutofillClient::FromWebContents(web_contents()); |
70 | 71 |
| 72 // Associate the |ContentAutofillDriverFactory| to the |WebContents|. |
| 73 ContentAutofillDriverFactory::CreateForWebContentsAndDelegate( |
| 74 web_contents(), autofill_client, |
| 75 g_browser_process->GetApplicationLocale(), |
| 76 AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER); |
| 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 |
| 88 ContentAutofillDriver* |
| 89 AutofillCCInfobarDelegateTest::GetAutofillDriverForMainFrame() { |
| 90 ContentAutofillDriverFactory* autofill_driver_factory = |
| 91 ContentAutofillDriverFactory::FromWebContents(web_contents()); |
| 92 |
| 93 return autofill_driver_factory->DriverForFrame( |
| 94 web_contents()->GetMainFrame()); |
| 95 } |
| 96 |
81 scoped_ptr<ConfirmInfoBarDelegate> | 97 scoped_ptr<ConfirmInfoBarDelegate> |
82 AutofillCCInfobarDelegateTest::CreateDelegate() { | 98 AutofillCCInfobarDelegateTest::CreateDelegate() { |
83 base::HistogramTester histogram_tester; | 99 base::HistogramTester histogram_tester; |
84 CreditCard credit_card; | 100 CreditCard credit_card; |
85 scoped_ptr<ConfirmInfoBarDelegate> delegate( | 101 scoped_ptr<ConfirmInfoBarDelegate> delegate(AutofillCCInfoBarDelegate::Create( |
86 AutofillCCInfoBarDelegate::Create(base::Bind( | 102 GetAutofillDriverForMainFrame(), |
| 103 base::Bind( |
87 base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard), | 104 base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard), |
88 base::Unretained(personal_data_.get()), credit_card))); | 105 base::Unretained(personal_data_.get()), credit_card))); |
89 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", | 106 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", |
90 AutofillMetrics::INFOBAR_SHOWN, 1); | 107 AutofillMetrics::INFOBAR_SHOWN, 1); |
91 return delegate.Pass(); | 108 return delegate.Pass(); |
92 } | 109 } |
93 | 110 |
94 // Test that credit card infobar metrics are logged correctly. | 111 // Test that credit card infobar metrics are logged correctly. |
95 TEST_F(AutofillCCInfobarDelegateTest, Metrics) { | 112 TEST_F(AutofillCCInfobarDelegateTest, Metrics) { |
96 ::testing::InSequence dummy; | 113 ::testing::InSequence dummy; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); | 148 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); |
132 | 149 |
133 base::HistogramTester histogram_tester; | 150 base::HistogramTester histogram_tester; |
134 infobar.reset(); | 151 infobar.reset(); |
135 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", | 152 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", |
136 AutofillMetrics::INFOBAR_IGNORED, 1); | 153 AutofillMetrics::INFOBAR_IGNORED, 1); |
137 } | 154 } |
138 } | 155 } |
139 | 156 |
140 } // namespace autofill | 157 } // namespace autofill |
OLD | NEW |