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

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

Issue 2434543003: [Autofill] Separate Autofill.CreditCardInfoBar into .Local and .Server (Closed)
Patch Set: Add base=true value to histogram Created 4 years, 2 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 | components/autofill/core/browser/autofill_metrics.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/autofill/core/browser/autofill_save_card_infobar_delegate_m obile.h" 5 #include "components/autofill/core/browser/autofill_save_card_infobar_delegate_m obile.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/test/histogram_tester.h" 10 #include "base/test/histogram_tester.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 class AutofillSaveCardInfoBarDelegateMobileTest 47 class AutofillSaveCardInfoBarDelegateMobileTest
48 : public ChromeRenderViewHostTestHarness { 48 : public ChromeRenderViewHostTestHarness {
49 public: 49 public:
50 AutofillSaveCardInfoBarDelegateMobileTest(); 50 AutofillSaveCardInfoBarDelegateMobileTest();
51 ~AutofillSaveCardInfoBarDelegateMobileTest() override; 51 ~AutofillSaveCardInfoBarDelegateMobileTest() override;
52 52
53 void SetUp() override; 53 void SetUp() override;
54 void TearDown() override; 54 void TearDown() override;
55 55
56 protected: 56 protected:
57 std::unique_ptr<ConfirmInfoBarDelegate> CreateDelegate(); 57 std::unique_ptr<ConfirmInfoBarDelegate> CreateDelegate(bool is_uploading);
58 58
59 std::unique_ptr<TestPersonalDataManager> personal_data_; 59 std::unique_ptr<TestPersonalDataManager> personal_data_;
60 60
61 private: 61 private:
62 DISALLOW_COPY_AND_ASSIGN(AutofillSaveCardInfoBarDelegateMobileTest); 62 DISALLOW_COPY_AND_ASSIGN(AutofillSaveCardInfoBarDelegateMobileTest);
63 }; 63 };
64 64
65 AutofillSaveCardInfoBarDelegateMobileTest:: 65 AutofillSaveCardInfoBarDelegateMobileTest::
66 AutofillSaveCardInfoBarDelegateMobileTest() {} 66 AutofillSaveCardInfoBarDelegateMobileTest() {}
67 67
(...skipping 13 matching lines...) Expand all
81 personal_data_->set_database(autofill_client->GetDatabase()); 81 personal_data_->set_database(autofill_client->GetDatabase());
82 personal_data_->SetPrefService(profile()->GetPrefs()); 82 personal_data_->SetPrefService(profile()->GetPrefs());
83 } 83 }
84 84
85 void AutofillSaveCardInfoBarDelegateMobileTest::TearDown() { 85 void AutofillSaveCardInfoBarDelegateMobileTest::TearDown() {
86 personal_data_.reset(); 86 personal_data_.reset();
87 ChromeRenderViewHostTestHarness::TearDown(); 87 ChromeRenderViewHostTestHarness::TearDown();
88 } 88 }
89 89
90 std::unique_ptr<ConfirmInfoBarDelegate> 90 std::unique_ptr<ConfirmInfoBarDelegate>
91 AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegate() { 91 AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegate(bool is_uploading) {
92 base::HistogramTester histogram_tester; 92 base::HistogramTester histogram_tester;
93 CreditCard credit_card; 93 CreditCard credit_card;
94 std::unique_ptr<base::DictionaryValue> legal_message; 94 std::unique_ptr<base::DictionaryValue> legal_message;
95 std::unique_ptr<ConfirmInfoBarDelegate> delegate( 95 std::unique_ptr<ConfirmInfoBarDelegate> delegate(
96 new AutofillSaveCardInfoBarDelegateMobile( 96 new AutofillSaveCardInfoBarDelegateMobile(
97 false, credit_card, std::move(legal_message), 97 is_uploading, credit_card, std::move(legal_message),
98 base::Bind(base::IgnoreResult( 98 base::Bind(base::IgnoreResult(
99 &TestPersonalDataManager::SaveImportedCreditCard), 99 &TestPersonalDataManager::SaveImportedCreditCard),
100 base::Unretained(personal_data_.get()), credit_card))); 100 base::Unretained(personal_data_.get()), credit_card)));
101 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", 101 std::string destination = is_uploading ? ".Server" : ".Local";
102 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar"
103 + destination,
102 AutofillMetrics::INFOBAR_SHOWN, 1); 104 AutofillMetrics::INFOBAR_SHOWN, 1);
103 return delegate; 105 return delegate;
104 } 106 }
105 107
106 // Test that credit card infobar metrics are logged correctly. 108 // Test that local credit card save infobar metrics are logged correctly.
107 TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics) { 109 TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Local) {
108 ::testing::InSequence dummy; 110 ::testing::InSequence dummy;
109 111
110 // Accept the infobar. 112 // Accept the infobar.
111 { 113 {
112 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); 114 std::unique_ptr<ConfirmInfoBarDelegate> infobar(
115 CreateDelegate(/* is_uploading= */ false));
113 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); 116 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_));
114 117
115 base::HistogramTester histogram_tester; 118 base::HistogramTester histogram_tester;
116 EXPECT_TRUE(infobar->Accept()); 119 EXPECT_TRUE(infobar->Accept());
117 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", 120 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local",
118 AutofillMetrics::INFOBAR_ACCEPTED, 1); 121 AutofillMetrics::INFOBAR_ACCEPTED, 1);
119 } 122 }
120 123
121 // Cancel the infobar. 124 // Cancel the infobar.
122 { 125 {
123 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); 126 std::unique_ptr<ConfirmInfoBarDelegate> infobar(
127 CreateDelegate(/* is_uploading= */ false));
124 128
125 base::HistogramTester histogram_tester; 129 base::HistogramTester histogram_tester;
126 EXPECT_TRUE(infobar->Cancel()); 130 EXPECT_TRUE(infobar->Cancel());
127 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", 131 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local",
128 AutofillMetrics::INFOBAR_DENIED, 1); 132 AutofillMetrics::INFOBAR_DENIED, 1);
129 } 133 }
130 134
131 // Dismiss the infobar. 135 // Dismiss the infobar.
132 { 136 {
133 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); 137 std::unique_ptr<ConfirmInfoBarDelegate> infobar(
138 CreateDelegate(/* is_uploading= */ false));
134 139
135 base::HistogramTester histogram_tester; 140 base::HistogramTester histogram_tester;
136 infobar->InfoBarDismissed(); 141 infobar->InfoBarDismissed();
137 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", 142 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local",
138 AutofillMetrics::INFOBAR_DENIED, 1); 143 AutofillMetrics::INFOBAR_DENIED, 1);
139 } 144 }
140 145
141 // Ignore the infobar. 146 // Ignore the infobar.
142 { 147 {
143 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); 148 std::unique_ptr<ConfirmInfoBarDelegate> infobar(
149 CreateDelegate(/* is_uploading= */ false));
144 150
145 base::HistogramTester histogram_tester; 151 base::HistogramTester histogram_tester;
146 infobar.reset(); 152 infobar.reset();
147 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", 153 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local",
148 AutofillMetrics::INFOBAR_IGNORED, 1); 154 AutofillMetrics::INFOBAR_IGNORED, 1);
149 } 155 }
150 } 156 }
157
158 // Test that server credit card save infobar metrics are logged correctly.
159 TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Server) {
160 ::testing::InSequence dummy;
161
162 // Accept the infobar.
163 {
164 std::unique_ptr<ConfirmInfoBarDelegate> infobar(
165 CreateDelegate(/* is_uploading= */ true));
166 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_));
167
168 base::HistogramTester histogram_tester;
169 EXPECT_TRUE(infobar->Accept());
170 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
171 AutofillMetrics::INFOBAR_ACCEPTED, 1);
172 }
173
174 // Cancel the infobar.
175 {
176 std::unique_ptr<ConfirmInfoBarDelegate> infobar(
177 CreateDelegate(/* is_uploading= */ true));
178
179 base::HistogramTester histogram_tester;
180 EXPECT_TRUE(infobar->Cancel());
181 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
182 AutofillMetrics::INFOBAR_DENIED, 1);
183 }
184
185 // Dismiss the infobar.
186 {
187 std::unique_ptr<ConfirmInfoBarDelegate> infobar(
188 CreateDelegate(/* is_uploading= */ true));
189
190 base::HistogramTester histogram_tester;
191 infobar->InfoBarDismissed();
192 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
193 AutofillMetrics::INFOBAR_DENIED, 1);
194 }
195
196 // Ignore the infobar.
197 {
198 std::unique_ptr<ConfirmInfoBarDelegate> infobar(
199 CreateDelegate(/* is_uploading= */ true));
200
201 base::HistogramTester histogram_tester;
202 infobar.reset();
203 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
204 AutofillMetrics::INFOBAR_IGNORED, 1);
205 }
206 }
151 207
152 } // namespace autofill 208 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_metrics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698