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

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

Issue 2839683002: Logs different SaveCardPrompt histogram names depending on if user (Closed)
Patch Set: Uses LogUMAHistogramEnumeration instead of UMA_HISTOGRAM_ENUMERATION because we change histogram na… Created 3 years, 7 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 "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"
11 #include "chrome/browser/autofill/personal_data_manager_factory.h" 11 #include "chrome/browser/autofill/personal_data_manager_factory.h"
12 #include "chrome/browser/ui/autofill/chrome_autofill_client.h" 12 #include "chrome/browser/ui/autofill/chrome_autofill_client.h"
13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
14 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
15 #include "components/autofill/core/browser/autofill_test_utils.h" 15 #include "components/autofill/core/browser/autofill_test_utils.h"
16 #include "components/autofill/core/browser/personal_data_manager.h" 16 #include "components/autofill/core/browser/personal_data_manager.h"
17 #include "components/autofill/core/common/autofill_pref_names.h"
17 #include "components/infobars/core/confirm_infobar_delegate.h" 18 #include "components/infobars/core/confirm_infobar_delegate.h"
19 #include "components/prefs/pref_service.h"
18 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
20 22
21 using testing::_; 23 using testing::_;
22 24
23 namespace autofill { 25 namespace autofill {
24 26
25 namespace { 27 namespace {
26 28
27 class TestPersonalDataManager : public PersonalDataManager { 29 class TestPersonalDataManager : public PersonalDataManager {
(...skipping 19 matching lines...) Expand all
47 class AutofillSaveCardInfoBarDelegateMobileTest 49 class AutofillSaveCardInfoBarDelegateMobileTest
48 : public ChromeRenderViewHostTestHarness { 50 : public ChromeRenderViewHostTestHarness {
49 public: 51 public:
50 AutofillSaveCardInfoBarDelegateMobileTest(); 52 AutofillSaveCardInfoBarDelegateMobileTest();
51 ~AutofillSaveCardInfoBarDelegateMobileTest() override; 53 ~AutofillSaveCardInfoBarDelegateMobileTest() override;
52 54
53 void SetUp() override; 55 void SetUp() override;
54 void TearDown() override; 56 void TearDown() override;
55 57
56 protected: 58 protected:
57 std::unique_ptr<ConfirmInfoBarDelegate> CreateDelegate(bool is_uploading); 59 std::unique_ptr<ConfirmInfoBarDelegate> CreateDelegate(
60 bool is_uploading,
61 bool did_user_accept_previous_save_credit_card_prompt);
58 62
59 std::unique_ptr<TestPersonalDataManager> personal_data_; 63 std::unique_ptr<TestPersonalDataManager> personal_data_;
60 64
61 private: 65 private:
62 DISALLOW_COPY_AND_ASSIGN(AutofillSaveCardInfoBarDelegateMobileTest); 66 DISALLOW_COPY_AND_ASSIGN(AutofillSaveCardInfoBarDelegateMobileTest);
63 }; 67 };
64 68
65 AutofillSaveCardInfoBarDelegateMobileTest:: 69 AutofillSaveCardInfoBarDelegateMobileTest::
66 AutofillSaveCardInfoBarDelegateMobileTest() {} 70 AutofillSaveCardInfoBarDelegateMobileTest() {}
67 71
68 AutofillSaveCardInfoBarDelegateMobileTest:: 72 AutofillSaveCardInfoBarDelegateMobileTest::
69 ~AutofillSaveCardInfoBarDelegateMobileTest() {} 73 ~AutofillSaveCardInfoBarDelegateMobileTest() {}
70 74
71 void AutofillSaveCardInfoBarDelegateMobileTest::SetUp() { 75 void AutofillSaveCardInfoBarDelegateMobileTest::SetUp() {
72 ChromeRenderViewHostTestHarness::SetUp(); 76 ChromeRenderViewHostTestHarness::SetUp();
73 77
74 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL); 78 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL);
75 79
76 ChromeAutofillClient::CreateForWebContents(web_contents()); 80 ChromeAutofillClient::CreateForWebContents(web_contents());
77 ChromeAutofillClient* autofill_client = 81 ChromeAutofillClient* autofill_client =
78 ChromeAutofillClient::FromWebContents(web_contents()); 82 ChromeAutofillClient::FromWebContents(web_contents());
79 83
80 personal_data_.reset(new TestPersonalDataManager()); 84 personal_data_.reset(new TestPersonalDataManager());
81 personal_data_->set_database(autofill_client->GetDatabase()); 85 personal_data_->set_database(autofill_client->GetDatabase());
82 personal_data_->SetPrefService(profile()->GetPrefs()); 86 personal_data_->SetPrefService(profile()->GetPrefs());
87
88 profile()->GetPrefs()->SetBoolean(
89 prefs::kAutofillAcceptSaveCreditCardPromptState, true);
83 } 90 }
84 91
85 void AutofillSaveCardInfoBarDelegateMobileTest::TearDown() { 92 void AutofillSaveCardInfoBarDelegateMobileTest::TearDown() {
86 personal_data_.reset(); 93 personal_data_.reset();
87 ChromeRenderViewHostTestHarness::TearDown(); 94 ChromeRenderViewHostTestHarness::TearDown();
88 } 95 }
89 96
90 std::unique_ptr<ConfirmInfoBarDelegate> 97 std::unique_ptr<ConfirmInfoBarDelegate>
91 AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegate(bool is_uploading) { 98 AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegate(
99 bool is_uploading,
100 bool did_user_accept_previous_save_credit_card_prompt) {
92 base::HistogramTester histogram_tester; 101 base::HistogramTester histogram_tester;
93 CreditCard credit_card; 102 CreditCard credit_card;
94 std::unique_ptr<base::DictionaryValue> legal_message; 103 std::unique_ptr<base::DictionaryValue> legal_message;
95 std::unique_ptr<ConfirmInfoBarDelegate> delegate( 104 std::unique_ptr<ConfirmInfoBarDelegate> delegate(
96 new AutofillSaveCardInfoBarDelegateMobile( 105 new AutofillSaveCardInfoBarDelegateMobile(
97 is_uploading, credit_card, std::move(legal_message), 106 is_uploading, credit_card, std::move(legal_message),
98 base::Bind(base::IgnoreResult( 107 base::Bind(base::IgnoreResult(
99 &TestPersonalDataManager::SaveImportedCreditCard), 108 &TestPersonalDataManager::SaveImportedCreditCard),
100 base::Unretained(personal_data_.get()), credit_card))); 109 base::Unretained(personal_data_.get()), credit_card),
110 profile()->GetPrefs()));
101 std::string destination = is_uploading ? ".Server" : ".Local"; 111 std::string destination = is_uploading ? ".Server" : ".Local";
102 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar" 112 std::string previous_response =
103 + destination, 113 did_user_accept_previous_save_credit_card_prompt ? ".PreviouslyAccepted"
104 AutofillMetrics::INFOBAR_SHOWN, 1); 114 : ".PreviouslyDenied";
115 histogram_tester.ExpectUniqueSample(
116 "Autofill.CreditCardInfoBar" + destination + previous_response,
117 AutofillMetrics::INFOBAR_SHOWN, 1);
105 return delegate; 118 return delegate;
106 } 119 }
107 120
108 // Test that local credit card save infobar metrics are logged correctly. 121 // Test that local credit card save infobar metrics are logged correctly.
109 TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Local) { 122 TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Local) {
110 ::testing::InSequence dummy; 123 ::testing::InSequence dummy;
111 124
112 // Accept the infobar. 125 // Accept the infobar.
113 { 126 {
114 std::unique_ptr<ConfirmInfoBarDelegate> infobar( 127 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(
115 CreateDelegate(/* is_uploading= */ false)); 128 /* is_uploading= */ false,
129 /* did_user_accept_previous_save_credit_card_prompt= */ true));
116 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); 130 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_));
117 131
118 base::HistogramTester histogram_tester; 132 base::HistogramTester histogram_tester;
119 EXPECT_TRUE(infobar->Accept()); 133 EXPECT_TRUE(infobar->Accept());
120 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local", 134 histogram_tester.ExpectUniqueSample(
121 AutofillMetrics::INFOBAR_ACCEPTED, 1); 135 "Autofill.CreditCardInfoBar.Local.PreviouslyAccepted",
136 AutofillMetrics::INFOBAR_ACCEPTED, 1);
122 } 137 }
123 138
124 // Cancel the infobar. 139 // Cancel the infobar.
125 { 140 {
126 std::unique_ptr<ConfirmInfoBarDelegate> infobar( 141 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(
127 CreateDelegate(/* is_uploading= */ false)); 142 /* is_uploading= */ false,
143 /* did_user_accept_previous_save_credit_card_prompt= */ true));
128 144
129 base::HistogramTester histogram_tester; 145 base::HistogramTester histogram_tester;
130 EXPECT_TRUE(infobar->Cancel()); 146 EXPECT_TRUE(infobar->Cancel());
131 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local", 147 histogram_tester.ExpectUniqueSample(
132 AutofillMetrics::INFOBAR_DENIED, 1); 148 "Autofill.CreditCardInfoBar.Local.PreviouslyAccepted",
149 AutofillMetrics::INFOBAR_DENIED, 1);
133 } 150 }
134 151
135 // Dismiss the infobar. 152 // Dismiss the infobar.
136 { 153 {
137 std::unique_ptr<ConfirmInfoBarDelegate> infobar( 154 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(
138 CreateDelegate(/* is_uploading= */ false)); 155 /* is_uploading= */ false,
156 /* did_user_accept_previous_save_credit_card_prompt= */ false));
139 157
140 base::HistogramTester histogram_tester; 158 base::HistogramTester histogram_tester;
141 infobar->InfoBarDismissed(); 159 infobar->InfoBarDismissed();
142 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local", 160 histogram_tester.ExpectUniqueSample(
143 AutofillMetrics::INFOBAR_DENIED, 1); 161 "Autofill.CreditCardInfoBar.Local.PreviouslyDenied",
162 AutofillMetrics::INFOBAR_DENIED, 1);
144 } 163 }
145 164
146 // Ignore the infobar. 165 // Ignore the infobar.
147 { 166 {
148 std::unique_ptr<ConfirmInfoBarDelegate> infobar( 167 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(
149 CreateDelegate(/* is_uploading= */ false)); 168 /* is_uploading= */ false,
169 /* did_user_accept_previous_save_credit_card_prompt= */ false));
150 170
151 base::HistogramTester histogram_tester; 171 base::HistogramTester histogram_tester;
152 infobar.reset(); 172 infobar.reset();
153 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local", 173 histogram_tester.ExpectUniqueSample(
154 AutofillMetrics::INFOBAR_IGNORED, 1); 174 "Autofill.CreditCardInfoBar.Local.PreviouslyDenied",
175 AutofillMetrics::INFOBAR_IGNORED, 1);
155 } 176 }
156 } 177 }
157 178
158 // Test that server credit card save infobar metrics are logged correctly. 179 // Test that server credit card save infobar metrics are logged correctly.
159 TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Server) { 180 TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Server) {
160 ::testing::InSequence dummy; 181 ::testing::InSequence dummy;
161 182
162 // Accept the infobar. 183 // Accept the infobar.
163 { 184 {
164 std::unique_ptr<ConfirmInfoBarDelegate> infobar( 185 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(
165 CreateDelegate(/* is_uploading= */ true)); 186 /* is_uploading= */ true,
187 /* did_user_accept_previous_save_credit_card_prompt= */ true));
166 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); 188 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_));
167 189
168 base::HistogramTester histogram_tester; 190 base::HistogramTester histogram_tester;
169 EXPECT_TRUE(infobar->Accept()); 191 EXPECT_TRUE(infobar->Accept());
170 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server", 192 histogram_tester.ExpectUniqueSample(
171 AutofillMetrics::INFOBAR_ACCEPTED, 1); 193 "Autofill.CreditCardInfoBar.Server.PreviouslyAccepted",
194 AutofillMetrics::INFOBAR_ACCEPTED, 1);
172 } 195 }
173 196
174 // Cancel the infobar. 197 // Cancel the infobar.
175 { 198 {
176 std::unique_ptr<ConfirmInfoBarDelegate> infobar( 199 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(
177 CreateDelegate(/* is_uploading= */ true)); 200 /* is_uploading= */ true,
201 /* did_user_accept_previous_save_credit_card_prompt= */ true));
178 202
179 base::HistogramTester histogram_tester; 203 base::HistogramTester histogram_tester;
180 EXPECT_TRUE(infobar->Cancel()); 204 EXPECT_TRUE(infobar->Cancel());
181 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server", 205 histogram_tester.ExpectUniqueSample(
182 AutofillMetrics::INFOBAR_DENIED, 1); 206 "Autofill.CreditCardInfoBar.Server.PreviouslyAccepted",
207 AutofillMetrics::INFOBAR_DENIED, 1);
183 } 208 }
184 209
185 // Dismiss the infobar. 210 // Dismiss the infobar.
186 { 211 {
187 std::unique_ptr<ConfirmInfoBarDelegate> infobar( 212 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(
188 CreateDelegate(/* is_uploading= */ true)); 213 /* is_uploading= */ true,
214 /* did_user_accept_previous_save_credit_card_prompt= */ false));
189 215
190 base::HistogramTester histogram_tester; 216 base::HistogramTester histogram_tester;
191 infobar->InfoBarDismissed(); 217 infobar->InfoBarDismissed();
192 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server", 218 histogram_tester.ExpectUniqueSample(
193 AutofillMetrics::INFOBAR_DENIED, 1); 219 "Autofill.CreditCardInfoBar.Server.PreviouslyDenied",
220 AutofillMetrics::INFOBAR_DENIED, 1);
194 } 221 }
195 222
196 // Ignore the infobar. 223 // Ignore the infobar.
197 { 224 {
198 std::unique_ptr<ConfirmInfoBarDelegate> infobar( 225 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(
199 CreateDelegate(/* is_uploading= */ true)); 226 /* is_uploading= */ true,
227 /* did_user_accept_previous_save_credit_card_prompt= */ false));
200 228
201 base::HistogramTester histogram_tester; 229 base::HistogramTester histogram_tester;
202 infobar.reset(); 230 infobar.reset();
203 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server", 231 histogram_tester.ExpectUniqueSample(
204 AutofillMetrics::INFOBAR_IGNORED, 1); 232 "Autofill.CreditCardInfoBar.Server.PreviouslyDenied",
233 AutofillMetrics::INFOBAR_IGNORED, 1);
205 } 234 }
206 } 235 }
207 236
208 } // namespace autofill 237 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698