Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: chrome/browser/autofill/autofill_cc_infobar_delegate_unittest.cc

Issue 710453002: [Autofill] Componentize AutofillCCInfoBarDelegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove infobar if its associated page content is destroyed. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/content/browser/content_autofill_driver.h"
14 #include "components/autofill/content/browser/content_autofill_driver_factory.h"
15 #include "components/autofill/core/browser/autofill_manager.h"
13 #include "components/autofill/core/browser/autofill_test_utils.h" 16 #include "components/autofill/core/browser/autofill_test_utils.h"
14 #include "components/autofill/core/browser/personal_data_manager.h" 17 #include "components/autofill/core/browser/personal_data_manager.h"
15 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
17 20
18 using testing::_; 21 using testing::_;
19 22
20 namespace autofill { 23 namespace autofill {
21 24
22 namespace { 25 namespace {
(...skipping 13 matching lines...) Expand all
36 std::string(const CreditCard& imported_credit_card)); 39 std::string(const CreditCard& imported_credit_card));
37 40
38 private: 41 private:
39 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); 42 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager);
40 }; 43 };
41 44
42 } // namespace 45 } // namespace
43 46
44 class AutofillCCInfobarDelegateTest : public ChromeRenderViewHostTestHarness { 47 class AutofillCCInfobarDelegateTest : public ChromeRenderViewHostTestHarness {
45 public: 48 public:
49 AutofillCCInfobarDelegateTest();
46 ~AutofillCCInfobarDelegateTest() override; 50 ~AutofillCCInfobarDelegateTest() override;
47 51
48 void SetUp() override; 52 void SetUp() override;
49 void TearDown() override; 53 void TearDown() override;
50 54
51 protected: 55 protected:
52 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(); 56 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate();
57 ContentAutofillDriver* GetAutofillDriverForMainFrame();
53 58
54 scoped_ptr<TestPersonalDataManager> personal_data_; 59 scoped_ptr<TestPersonalDataManager> personal_data_;
60
61 private:
62 DISALLOW_COPY_AND_ASSIGN(AutofillCCInfobarDelegateTest);
55 }; 63 };
56 64
65 AutofillCCInfobarDelegateTest::AutofillCCInfobarDelegateTest() {
66 }
67
57 AutofillCCInfobarDelegateTest::~AutofillCCInfobarDelegateTest() {} 68 AutofillCCInfobarDelegateTest::~AutofillCCInfobarDelegateTest() {}
58 69
59 void AutofillCCInfobarDelegateTest::SetUp() { 70 void AutofillCCInfobarDelegateTest::SetUp() {
60 ChromeRenderViewHostTestHarness::SetUp(); 71 ChromeRenderViewHostTestHarness::SetUp();
61 72
62 // Ensure Mac OS X does not pop up a modal dialog for the Address Book. 73 // Ensure Mac OS X does not pop up a modal dialog for the Address Book.
63 test::DisableSystemServices(profile()->GetPrefs()); 74 test::DisableSystemServices(profile()->GetPrefs());
64 75
65 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL); 76 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL);
66 77
67 ChromeAutofillClient::CreateForWebContents(web_contents()); 78 ChromeAutofillClient::CreateForWebContents(web_contents());
68 ChromeAutofillClient* autofill_client = 79 ChromeAutofillClient* autofill_client =
69 ChromeAutofillClient::FromWebContents(web_contents()); 80 ChromeAutofillClient::FromWebContents(web_contents());
70 81
82 ContentAutofillDriverFactory::CreateForWebContentsAndDelegate(
83 web_contents(), autofill_client, "en-US",
84 AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER);
85
71 personal_data_.reset(new TestPersonalDataManager()); 86 personal_data_.reset(new TestPersonalDataManager());
72 personal_data_->set_database(autofill_client->GetDatabase()); 87 personal_data_->set_database(autofill_client->GetDatabase());
73 personal_data_->SetPrefService(profile()->GetPrefs()); 88 personal_data_->SetPrefService(profile()->GetPrefs());
74 } 89 }
75 90
76 void AutofillCCInfobarDelegateTest::TearDown() { 91 void AutofillCCInfobarDelegateTest::TearDown() {
77 personal_data_.reset(); 92 personal_data_.reset();
78 ChromeRenderViewHostTestHarness::TearDown(); 93 ChromeRenderViewHostTestHarness::TearDown();
79 } 94 }
80 95
96 ContentAutofillDriver*
97 AutofillCCInfobarDelegateTest::GetAutofillDriverForMainFrame() {
98 ContentAutofillDriverFactory* autofill_driver_factory =
99 ContentAutofillDriverFactory::FromWebContents(web_contents());
100 return autofill_driver_factory->DriverForFrame(
101 web_contents()->GetMainFrame());
102 }
103
81 scoped_ptr<ConfirmInfoBarDelegate> 104 scoped_ptr<ConfirmInfoBarDelegate>
82 AutofillCCInfobarDelegateTest::CreateDelegate() { 105 AutofillCCInfobarDelegateTest::CreateDelegate() {
83 base::HistogramTester histogram_tester; 106 base::HistogramTester histogram_tester;
84 CreditCard credit_card; 107 CreditCard credit_card;
85 scoped_ptr<ConfirmInfoBarDelegate> delegate( 108 scoped_ptr<ConfirmInfoBarDelegate> delegate(AutofillCCInfoBarDelegate::Create(
86 AutofillCCInfoBarDelegate::Create(base::Bind( 109 GetAutofillDriverForMainFrame(),
110 base::Bind(
87 base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard), 111 base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard),
88 base::Unretained(personal_data_.get()), credit_card))); 112 base::Unretained(personal_data_.get()), credit_card)));
89 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", 113 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar",
90 AutofillMetrics::INFOBAR_SHOWN, 1); 114 AutofillMetrics::INFOBAR_SHOWN, 1);
91 return delegate.Pass(); 115 return delegate.Pass();
92 } 116 }
93 117
94 // Test that credit card infobar metrics are logged correctly. 118 // Test that credit card infobar metrics are logged correctly.
95 TEST_F(AutofillCCInfobarDelegateTest, Metrics) { 119 TEST_F(AutofillCCInfobarDelegateTest, Metrics) {
96 ::testing::InSequence dummy; 120 ::testing::InSequence dummy;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); 155 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate());
132 156
133 base::HistogramTester histogram_tester; 157 base::HistogramTester histogram_tester;
134 infobar.reset(); 158 infobar.reset();
135 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", 159 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar",
136 AutofillMetrics::INFOBAR_IGNORED, 1); 160 AutofillMetrics::INFOBAR_IGNORED, 1);
137 } 161 }
138 } 162 }
139 163
140 } // namespace autofill 164 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698