forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautofill_cc_infobar_delegate_unittest.cc
140 lines (107 loc) · 4.53 KB
/
autofill_cc_infobar_delegate_unittest.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/autofill/autofill_cc_infobar_delegate.h"
#include "base/memory/scoped_ptr.h"
#include "base/test/histogram_tester.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/ui/autofill/chrome_autofill_client.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using testing::_;
namespace autofill {
namespace {
class TestPersonalDataManager : public PersonalDataManager {
public:
TestPersonalDataManager() : PersonalDataManager("en-US") {}
using PersonalDataManager::set_database;
using PersonalDataManager::SetPrefService;
// Overridden to avoid a trip to the database.
virtual void LoadProfiles() override {}
virtual void LoadCreditCards() override {}
MOCK_METHOD1(SaveImportedCreditCard,
std::string(const CreditCard& imported_credit_card));
private:
DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager);
};
} // namespace
class AutofillCCInfobarDelegateTest : public ChromeRenderViewHostTestHarness {
public:
~AutofillCCInfobarDelegateTest() override;
void SetUp() override;
void TearDown() override;
protected:
scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate();
scoped_ptr<TestPersonalDataManager> personal_data_;
};
AutofillCCInfobarDelegateTest::~AutofillCCInfobarDelegateTest() {}
void AutofillCCInfobarDelegateTest::SetUp() {
ChromeRenderViewHostTestHarness::SetUp();
// Ensure Mac OS X does not pop up a modal dialog for the Address Book.
test::DisableSystemServices(profile()->GetPrefs());
PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL);
ChromeAutofillClient::CreateForWebContents(web_contents());
ChromeAutofillClient* autofill_client =
ChromeAutofillClient::FromWebContents(web_contents());
personal_data_.reset(new TestPersonalDataManager());
personal_data_->set_database(autofill_client->GetDatabase());
personal_data_->SetPrefService(profile()->GetPrefs());
}
void AutofillCCInfobarDelegateTest::TearDown() {
personal_data_.reset();
ChromeRenderViewHostTestHarness::TearDown();
}
scoped_ptr<ConfirmInfoBarDelegate>
AutofillCCInfobarDelegateTest::CreateDelegate() {
base::HistogramTester histogram_tester;
CreditCard credit_card;
scoped_ptr<ConfirmInfoBarDelegate> delegate(
AutofillCCInfoBarDelegate::Create(base::Bind(
base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard),
base::Unretained(personal_data_.get()), credit_card)));
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar",
AutofillMetrics::INFOBAR_SHOWN, 1);
return delegate.Pass();
}
// Test that credit card infobar metrics are logged correctly.
TEST_F(AutofillCCInfobarDelegateTest, Metrics) {
::testing::InSequence dummy;
// Accept the infobar.
{
scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate());
EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_));
base::HistogramTester histogram_tester;
EXPECT_TRUE(infobar->Accept());
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar",
AutofillMetrics::INFOBAR_ACCEPTED, 1);
}
// Cancel the infobar.
{
scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate());
base::HistogramTester histogram_tester;
EXPECT_TRUE(infobar->Cancel());
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar",
AutofillMetrics::INFOBAR_DENIED, 1);
}
// Dismiss the infobar.
{
scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate());
base::HistogramTester histogram_tester;
infobar->InfoBarDismissed();
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar",
AutofillMetrics::INFOBAR_DENIED, 1);
}
// Ignore the infobar.
{
scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate());
base::HistogramTester histogram_tester;
infobar.reset();
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar",
AutofillMetrics::INFOBAR_IGNORED, 1);
}
}
} // namespace autofill