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

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

Issue 177923004: Moved CCInfobarDelegate tests out of AutofillMetricsTest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Response to review Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/chrome_tests_unit.gypi » ('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 2013 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 "chrome/browser/autofill/autofill_cc_infobar_delegate.h"
6
7 #include <vector>
Ilya Sherman 2014/03/07 23:35:45 nit: Doesn't seem like this is needed.
blundell 2014/03/08 08:51:58 Done.
8
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/autofill/personal_data_manager_factory.h"
11 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.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_metrics.h"
15 #include "components/autofill/core/browser/autofill_test_utils.h"
16 #include "components/autofill/core/browser/personal_data_manager.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 using testing::_;
21
22 namespace autofill {
23
24 namespace {
25
26 class MockAutofillMetrics : public AutofillMetrics {
27 public:
28 MockAutofillMetrics() {}
29 MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric));
30
31 private:
32 DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics);
33 };
34
35 class TestPersonalDataManager : public PersonalDataManager {
36 public:
37 TestPersonalDataManager() : PersonalDataManager("en-US") {}
38
39 using PersonalDataManager::set_database;
40 using PersonalDataManager::SetPrefService;
41
42 // Overridden to avoid a trip to the database. This should be a no-op.
43 virtual void LoadProfiles() OVERRIDE {}
44
45 // Overridden to avoid a trip to the database.
Ilya Sherman 2014/03/07 23:35:45 nit: Maybe drop this comment as well as the blank
blundell 2014/03/08 08:51:58 Done.
46 virtual void LoadCreditCards() OVERRIDE {}
47
48 MOCK_METHOD1(SaveImportedCreditCard,
49 std::string(const CreditCard& imported_credit_card));
50
51 private:
52 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager);
53 };
54
55 } // namespace
56
57 class AutofillCCInfobarDelegateTest : public ChromeRenderViewHostTestHarness {
58 public:
59 virtual ~AutofillCCInfobarDelegateTest();
60
61 virtual void SetUp() OVERRIDE;
62 virtual void TearDown() OVERRIDE;
63
64 protected:
65 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(
66 MockAutofillMetrics* metric_logger);
67
68 scoped_ptr<TestPersonalDataManager> personal_data_;
69 };
70
71 AutofillCCInfobarDelegateTest::~AutofillCCInfobarDelegateTest() {}
72
73 void AutofillCCInfobarDelegateTest::SetUp() {
74 ChromeRenderViewHostTestHarness::SetUp();
75
76 // Ensure Mac OS X does not pop up a modal dialog for the Address Book.
77 autofill::test::DisableSystemServices(profile()->GetPrefs());
78
79 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL);
80
81 TabAutofillManagerDelegate::CreateForWebContents(web_contents());
82 autofill::TabAutofillManagerDelegate* manager_delegate =
83 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents());
84
85 personal_data_.reset(new TestPersonalDataManager());
86 personal_data_->set_database(manager_delegate->GetDatabase());
87 personal_data_->SetPrefService(profile()->GetPrefs());
88 }
89
90 void AutofillCCInfobarDelegateTest::TearDown() {
91 personal_data_.reset();
92 ChromeRenderViewHostTestHarness::TearDown();
93 }
94
95 scoped_ptr<ConfirmInfoBarDelegate>
96 AutofillCCInfobarDelegateTest::CreateDelegate(
97 MockAutofillMetrics* metric_logger) {
98 EXPECT_CALL(*metric_logger,
99 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
100
101 CreditCard credit_card;
102 return AutofillCCInfoBarDelegate::Create(
103 metric_logger,
104 base::Bind(
105 base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard),
106 base::Unretained(personal_data_.get()),
107 credit_card));
108 }
109
110 // Test that credit card infobar metrics are logged correctly.
111 TEST_F(AutofillCCInfobarDelegateTest, Metrics) {
112 MockAutofillMetrics metric_logger;
113 ::testing::InSequence dummy;
114
115 // Accept the infobar.
116 {
117 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
118 ASSERT_TRUE(infobar);
119 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_));
120 EXPECT_CALL(metric_logger,
121 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED));
122
123 EXPECT_CALL(metric_logger,
124 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED))
125 .Times(0);
126 EXPECT_TRUE(infobar->Accept());
127 }
128
129 // Cancel the infobar.
130 {
131 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
132 ASSERT_TRUE(infobar);
133 EXPECT_CALL(metric_logger,
134 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED))
135 .Times(1);
136 EXPECT_CALL(metric_logger,
137 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED))
138 .Times(0);
139 EXPECT_TRUE(infobar->Cancel());
140 }
141
142 // Dismiss the infobar.
143 {
144 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
145 ASSERT_TRUE(infobar);
146 EXPECT_CALL(metric_logger,
147 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED))
148 .Times(1);
149 EXPECT_CALL(metric_logger,
150 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED))
151 .Times(0);
152 infobar->InfoBarDismissed();
153 }
154
155 // Ignore the infobar.
156 {
157 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
158 ASSERT_TRUE(infobar);
159 EXPECT_CALL(metric_logger,
160 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED))
161 .Times(1);
162 }
163 }
164
165 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698