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

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: Addresses Sylvain's review comments. Created 5 years, 12 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 20 matching lines...) Expand all
43 46
44 class AutofillCCInfobarDelegateTest : public ChromeRenderViewHostTestHarness { 47 class AutofillCCInfobarDelegateTest : public ChromeRenderViewHostTestHarness {
45 public: 48 public:
46 ~AutofillCCInfobarDelegateTest() override; 49 ~AutofillCCInfobarDelegateTest() override;
47 50
48 void SetUp() override; 51 void SetUp() override;
49 void TearDown() override; 52 void TearDown() override;
50 53
51 protected: 54 protected:
52 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(); 55 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate();
56 ContentAutofillDriver* GetAutofillDriverForMainFrame();
53 57
54 scoped_ptr<TestPersonalDataManager> personal_data_; 58 scoped_ptr<TestPersonalDataManager> personal_data_;
55 }; 59 };
Peter Kasting 2014/12/23 21:20:34 Nit: While here: DISALLOW_COPY_AND_ASSIGN()
Pritam Nikam 2014/12/24 11:16:57 Done.
56 60
57 AutofillCCInfobarDelegateTest::~AutofillCCInfobarDelegateTest() {} 61 AutofillCCInfobarDelegateTest::~AutofillCCInfobarDelegateTest() {}
58 62
59 void AutofillCCInfobarDelegateTest::SetUp() { 63 void AutofillCCInfobarDelegateTest::SetUp() {
60 ChromeRenderViewHostTestHarness::SetUp(); 64 ChromeRenderViewHostTestHarness::SetUp();
61 65
62 // Ensure Mac OS X does not pop up a modal dialog for the Address Book. 66 // Ensure Mac OS X does not pop up a modal dialog for the Address Book.
63 test::DisableSystemServices(profile()->GetPrefs()); 67 test::DisableSystemServices(profile()->GetPrefs());
64 68
65 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL); 69 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL);
66 70
67 ChromeAutofillClient::CreateForWebContents(web_contents()); 71 ChromeAutofillClient::CreateForWebContents(web_contents());
68 ChromeAutofillClient* autofill_client = 72 ChromeAutofillClient* autofill_client =
69 ChromeAutofillClient::FromWebContents(web_contents()); 73 ChromeAutofillClient::FromWebContents(web_contents());
70 74
75 // Associate the |ContentAutofillDriverFactory| to the |WebContents|.
Peter Kasting 2014/12/23 21:20:34 Nit: Only use ||s for variable names, not type nam
Pritam Nikam 2014/12/24 11:16:57 Done.
76 ContentAutofillDriverFactory::CreateForWebContentsAndDelegate(
77 web_contents(), autofill_client, "en-US",
78 AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER);
79
71 personal_data_.reset(new TestPersonalDataManager()); 80 personal_data_.reset(new TestPersonalDataManager());
72 personal_data_->set_database(autofill_client->GetDatabase()); 81 personal_data_->set_database(autofill_client->GetDatabase());
73 personal_data_->SetPrefService(profile()->GetPrefs()); 82 personal_data_->SetPrefService(profile()->GetPrefs());
74 } 83 }
75 84
76 void AutofillCCInfobarDelegateTest::TearDown() { 85 void AutofillCCInfobarDelegateTest::TearDown() {
77 personal_data_.reset(); 86 personal_data_.reset();
78 ChromeRenderViewHostTestHarness::TearDown(); 87 ChromeRenderViewHostTestHarness::TearDown();
79 } 88 }
80 89
90 ContentAutofillDriver*
91 AutofillCCInfobarDelegateTest::GetAutofillDriverForMainFrame() {
92 ContentAutofillDriverFactory* autofill_driver_factory =
93 ContentAutofillDriverFactory::FromWebContents(web_contents());
94
Peter Kasting 2014/12/23 21:20:34 Nit: Blank here is unnecessary
Pritam Nikam 2014/12/24 11:16:57 Done.
95 return autofill_driver_factory->DriverForFrame(
96 web_contents()->GetMainFrame());
97 }
98
81 scoped_ptr<ConfirmInfoBarDelegate> 99 scoped_ptr<ConfirmInfoBarDelegate>
82 AutofillCCInfobarDelegateTest::CreateDelegate() { 100 AutofillCCInfobarDelegateTest::CreateDelegate() {
83 base::HistogramTester histogram_tester; 101 base::HistogramTester histogram_tester;
84 CreditCard credit_card; 102 CreditCard credit_card;
85 scoped_ptr<ConfirmInfoBarDelegate> delegate( 103 scoped_ptr<ConfirmInfoBarDelegate> delegate(AutofillCCInfoBarDelegate::Create(
86 AutofillCCInfoBarDelegate::Create(base::Bind( 104 GetAutofillDriverForMainFrame(),
105 base::Bind(
87 base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard), 106 base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard),
88 base::Unretained(personal_data_.get()), credit_card))); 107 base::Unretained(personal_data_.get()), credit_card)));
89 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", 108 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar",
90 AutofillMetrics::INFOBAR_SHOWN, 1); 109 AutofillMetrics::INFOBAR_SHOWN, 1);
91 return delegate.Pass(); 110 return delegate.Pass();
92 } 111 }
93 112
94 // Test that credit card infobar metrics are logged correctly. 113 // Test that credit card infobar metrics are logged correctly.
95 TEST_F(AutofillCCInfobarDelegateTest, Metrics) { 114 TEST_F(AutofillCCInfobarDelegateTest, Metrics) {
96 ::testing::InSequence dummy; 115 ::testing::InSequence dummy;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); 150 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate());
132 151
133 base::HistogramTester histogram_tester; 152 base::HistogramTester histogram_tester;
134 infobar.reset(); 153 infobar.reset();
135 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", 154 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar",
136 AutofillMetrics::INFOBAR_IGNORED, 1); 155 AutofillMetrics::INFOBAR_IGNORED, 1);
137 } 156 }
138 } 157 }
139 158
140 } // namespace autofill 159 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698