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

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

Issue 1780443002: Cleanup: roll AutofillCCInfoBarDelegate into AutofillSaveCardInfoBarDelegateMobile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pay_mac_bubble_default
Patch Set: Make overriden methods public. Created 4 years, 9 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
« no previous file with comments | « no previous file | chrome/browser/autofill/autofill_save_card_infobar_delegate_mobile_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/autofill/core/browser/autofill_cc_infobar_delegate.h"
6
7 #include "base/macros.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/test/histogram_tester.h"
10 #include "chrome/browser/autofill/personal_data_manager_factory.h"
11 #include "chrome/browser/ui/autofill/chrome_autofill_client.h"
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
13 #include "chrome/test/base/testing_profile.h"
14 #include "components/autofill/core/browser/autofill_test_utils.h"
15 #include "components/autofill/core/browser/personal_data_manager.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 using testing::_;
20
21 namespace autofill {
22
23 namespace {
24
25 class TestPersonalDataManager : public PersonalDataManager {
26 public:
27 TestPersonalDataManager() : PersonalDataManager("en-US") {}
28
29 using PersonalDataManager::set_database;
30 using PersonalDataManager::SetPrefService;
31
32 // Overridden to avoid a trip to the database.
33 void LoadProfiles() override {}
34 void LoadCreditCards() override {}
35
36 MOCK_METHOD1(SaveImportedCreditCard,
37 std::string(const CreditCard& imported_credit_card));
38
39 private:
40 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager);
41 };
42
43 } // namespace
44
45 class AutofillCCInfobarDelegateTest : public ChromeRenderViewHostTestHarness {
46 public:
47 AutofillCCInfobarDelegateTest();
48 ~AutofillCCInfobarDelegateTest() override;
49
50 void SetUp() override;
51 void TearDown() override;
52
53 protected:
54 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate();
55
56 scoped_ptr<TestPersonalDataManager> personal_data_;
57
58 private:
59 DISALLOW_COPY_AND_ASSIGN(AutofillCCInfobarDelegateTest);
60 };
61
62 AutofillCCInfobarDelegateTest::AutofillCCInfobarDelegateTest() {
63 }
64
65 AutofillCCInfobarDelegateTest::~AutofillCCInfobarDelegateTest() {}
66
67 void AutofillCCInfobarDelegateTest::SetUp() {
68 ChromeRenderViewHostTestHarness::SetUp();
69
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);
74
75 ChromeAutofillClient::CreateForWebContents(web_contents());
76 ChromeAutofillClient* autofill_client =
77 ChromeAutofillClient::FromWebContents(web_contents());
78
79 personal_data_.reset(new TestPersonalDataManager());
80 personal_data_->set_database(autofill_client->GetDatabase());
81 personal_data_->SetPrefService(profile()->GetPrefs());
82 }
83
84 void AutofillCCInfobarDelegateTest::TearDown() {
85 personal_data_.reset();
86 ChromeRenderViewHostTestHarness::TearDown();
87 }
88
89 scoped_ptr<ConfirmInfoBarDelegate>
90 AutofillCCInfobarDelegateTest::CreateDelegate() {
91 base::HistogramTester histogram_tester;
92 CreditCard credit_card;
93 scoped_ptr<ConfirmInfoBarDelegate> delegate(AutofillCCInfoBarDelegate::Create(
94 base::Bind(
95 base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard),
96 base::Unretained(personal_data_.get()), credit_card)));
97 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar",
98 AutofillMetrics::INFOBAR_SHOWN, 1);
99 return delegate;
100 }
101
102 // Test that credit card infobar metrics are logged correctly.
103 TEST_F(AutofillCCInfobarDelegateTest, Metrics) {
104 ::testing::InSequence dummy;
105
106 // Accept the infobar.
107 {
108 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate());
109 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_));
110
111 base::HistogramTester histogram_tester;
112 EXPECT_TRUE(infobar->Accept());
113 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar",
114 AutofillMetrics::INFOBAR_ACCEPTED, 1);
115 }
116
117 // Cancel the infobar.
118 {
119 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate());
120
121 base::HistogramTester histogram_tester;
122 EXPECT_TRUE(infobar->Cancel());
123 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar",
124 AutofillMetrics::INFOBAR_DENIED, 1);
125 }
126
127 // Dismiss the infobar.
128 {
129 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate());
130
131 base::HistogramTester histogram_tester;
132 infobar->InfoBarDismissed();
133 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar",
134 AutofillMetrics::INFOBAR_DENIED, 1);
135 }
136
137 // Ignore the infobar.
138 {
139 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate());
140
141 base::HistogramTester histogram_tester;
142 infobar.reset();
143 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar",
144 AutofillMetrics::INFOBAR_IGNORED, 1);
145 }
146 }
147
148 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autofill/autofill_save_card_infobar_delegate_mobile_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698