OLD | NEW |
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/json/json_reader.h" |
9 #include "base/macros.h" | 10 #include "base/macros.h" |
10 #include "base/test/histogram_tester.h" | 11 #include "base/test/histogram_tester.h" |
11 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 12 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
12 #include "chrome/browser/ui/autofill/chrome_autofill_client.h" | 13 #include "chrome/browser/ui/autofill/chrome_autofill_client.h" |
13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
14 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
15 #include "components/autofill/core/browser/autofill_test_utils.h" | 16 #include "components/autofill/core/browser/autofill_test_utils.h" |
16 #include "components/autofill/core/browser/personal_data_manager.h" | 17 #include "components/autofill/core/browser/personal_data_manager.h" |
17 #include "components/autofill/core/common/autofill_pref_names.h" | 18 #include "components/autofill/core/common/autofill_pref_names.h" |
18 #include "components/infobars/core/confirm_infobar_delegate.h" | 19 #include "components/infobars/core/confirm_infobar_delegate.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 ~AutofillSaveCardInfoBarDelegateMobileTest() override; | 54 ~AutofillSaveCardInfoBarDelegateMobileTest() override; |
54 | 55 |
55 void SetUp() override; | 56 void SetUp() override; |
56 void TearDown() override; | 57 void TearDown() override; |
57 | 58 |
58 protected: | 59 protected: |
59 std::unique_ptr<ConfirmInfoBarDelegate> CreateDelegate( | 60 std::unique_ptr<ConfirmInfoBarDelegate> CreateDelegate( |
60 bool is_uploading, | 61 bool is_uploading, |
61 prefs::PreviousSaveCreditCardPromptUserDecision | 62 prefs::PreviousSaveCreditCardPromptUserDecision |
62 previous_save_credit_card_prompt_user_decision); | 63 previous_save_credit_card_prompt_user_decision); |
| 64 std::unique_ptr<ConfirmInfoBarDelegate> CreateDelegateWithLegalMessage( |
| 65 bool is_uploading, |
| 66 std::string legal_message_string, |
| 67 prefs::PreviousSaveCreditCardPromptUserDecision |
| 68 previous_save_credit_card_prompt_user_decision); |
63 | 69 |
64 std::unique_ptr<TestPersonalDataManager> personal_data_; | 70 std::unique_ptr<TestPersonalDataManager> personal_data_; |
65 | 71 |
66 private: | 72 private: |
67 DISALLOW_COPY_AND_ASSIGN(AutofillSaveCardInfoBarDelegateMobileTest); | 73 DISALLOW_COPY_AND_ASSIGN(AutofillSaveCardInfoBarDelegateMobileTest); |
68 }; | 74 }; |
69 | 75 |
70 AutofillSaveCardInfoBarDelegateMobileTest:: | 76 AutofillSaveCardInfoBarDelegateMobileTest:: |
71 AutofillSaveCardInfoBarDelegateMobileTest() {} | 77 AutofillSaveCardInfoBarDelegateMobileTest() {} |
72 | 78 |
(...skipping 21 matching lines...) Expand all Loading... |
94 void AutofillSaveCardInfoBarDelegateMobileTest::TearDown() { | 100 void AutofillSaveCardInfoBarDelegateMobileTest::TearDown() { |
95 personal_data_.reset(); | 101 personal_data_.reset(); |
96 ChromeRenderViewHostTestHarness::TearDown(); | 102 ChromeRenderViewHostTestHarness::TearDown(); |
97 } | 103 } |
98 | 104 |
99 std::unique_ptr<ConfirmInfoBarDelegate> | 105 std::unique_ptr<ConfirmInfoBarDelegate> |
100 AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegate( | 106 AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegate( |
101 bool is_uploading, | 107 bool is_uploading, |
102 prefs::PreviousSaveCreditCardPromptUserDecision | 108 prefs::PreviousSaveCreditCardPromptUserDecision |
103 previous_save_credit_card_prompt_user_decision) { | 109 previous_save_credit_card_prompt_user_decision) { |
104 base::HistogramTester histogram_tester; | 110 return CreateDelegateWithLegalMessage( |
| 111 is_uploading, "", previous_save_credit_card_prompt_user_decision); |
| 112 } |
| 113 |
| 114 std::unique_ptr<ConfirmInfoBarDelegate> |
| 115 AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegateWithLegalMessage( |
| 116 bool is_uploading, |
| 117 std::string legal_message_string, |
| 118 prefs::PreviousSaveCreditCardPromptUserDecision |
| 119 previous_save_credit_card_prompt_user_decision) { |
105 CreditCard credit_card; | 120 CreditCard credit_card; |
106 std::unique_ptr<base::DictionaryValue> legal_message; | 121 std::unique_ptr<base::DictionaryValue> legal_message; |
| 122 if (!legal_message_string.empty()) { |
| 123 std::unique_ptr<base::Value> value( |
| 124 base::JSONReader::Read(legal_message_string)); |
| 125 EXPECT_TRUE(value); |
| 126 base::DictionaryValue* dictionary; |
| 127 EXPECT_TRUE(value->GetAsDictionary(&dictionary)); |
| 128 legal_message = dictionary->CreateDeepCopy(); |
| 129 } |
107 std::unique_ptr<ConfirmInfoBarDelegate> delegate( | 130 std::unique_ptr<ConfirmInfoBarDelegate> delegate( |
108 new AutofillSaveCardInfoBarDelegateMobile( | 131 new AutofillSaveCardInfoBarDelegateMobile( |
109 is_uploading, credit_card, std::move(legal_message), | 132 is_uploading, credit_card, std::move(legal_message), |
110 base::Bind(base::IgnoreResult( | 133 base::Bind(base::IgnoreResult( |
111 &TestPersonalDataManager::SaveImportedCreditCard), | 134 &TestPersonalDataManager::SaveImportedCreditCard), |
112 base::Unretained(personal_data_.get()), credit_card), | 135 base::Unretained(personal_data_.get()), credit_card), |
113 profile()->GetPrefs())); | 136 profile()->GetPrefs())); |
114 std::string destination = is_uploading ? ".Server" : ".Local"; | 137 std::string destination = is_uploading ? ".Server" : ".Local"; |
115 std::string previous_response; | 138 std::string previous_response; |
116 switch (previous_save_credit_card_prompt_user_decision) { | 139 switch (previous_save_credit_card_prompt_user_decision) { |
117 case prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_ACCEPTED: | 140 case prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_ACCEPTED: |
118 previous_response = ".PreviouslyAccepted"; | 141 previous_response = ".PreviouslyAccepted"; |
119 break; | 142 break; |
120 case prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_DENIED: | 143 case prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_DENIED: |
121 previous_response = ".PreviouslyDenied"; | 144 previous_response = ".PreviouslyDenied"; |
122 break; | 145 break; |
123 default: | 146 default: |
124 EXPECT_EQ(previous_save_credit_card_prompt_user_decision, | 147 EXPECT_EQ(previous_save_credit_card_prompt_user_decision, |
125 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_NONE); | 148 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_NONE); |
126 break; | 149 break; |
127 } | 150 } |
128 histogram_tester.ExpectUniqueSample( | |
129 "Autofill.CreditCardInfoBar" + destination + previous_response, | |
130 AutofillMetrics::INFOBAR_SHOWN, 1); | |
131 return delegate; | 151 return delegate; |
132 } | 152 } |
133 | 153 |
134 // Test that local credit card save infobar metrics are logged correctly. | 154 // Test that local credit card save infobar metrics are logged correctly. |
135 TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Local) { | 155 TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Local) { |
136 ::testing::InSequence dummy; | 156 ::testing::InSequence dummy; |
137 | 157 |
| 158 // Infobar is shown. |
| 159 { |
| 160 base::HistogramTester histogram_tester; |
| 161 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
| 162 /* is_uploading= */ false, |
| 163 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_NONE)); |
| 164 |
| 165 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local", |
| 166 AutofillMetrics::INFOBAR_SHOWN, 1); |
| 167 } |
| 168 |
138 // Accept the infobar. | 169 // Accept the infobar. |
139 { | 170 { |
140 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( | 171 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
141 /* is_uploading= */ false, | 172 /* is_uploading= */ false, |
142 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_NONE)); | 173 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_DENIED)); |
143 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); | 174 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); |
144 | 175 |
145 base::HistogramTester histogram_tester; | 176 base::HistogramTester histogram_tester; |
146 EXPECT_TRUE(infobar->Accept()); | 177 EXPECT_TRUE(infobar->Accept()); |
147 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local", | 178 histogram_tester.ExpectUniqueSample( |
148 AutofillMetrics::INFOBAR_ACCEPTED, 1); | 179 "Autofill.CreditCardInfoBar.Local.PreviouslyDenied", |
| 180 AutofillMetrics::INFOBAR_ACCEPTED, 1); |
149 } | 181 } |
150 | 182 |
151 // Cancel the infobar. | 183 // Cancel the infobar. |
152 { | 184 { |
153 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( | 185 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
154 /* is_uploading= */ false, | 186 /* is_uploading= */ false, |
155 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_ACCEPTED)); | 187 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_ACCEPTED)); |
156 | 188 |
157 base::HistogramTester histogram_tester; | 189 base::HistogramTester histogram_tester; |
158 EXPECT_TRUE(infobar->Cancel()); | 190 EXPECT_TRUE(infobar->Cancel()); |
(...skipping 26 matching lines...) Expand all Loading... |
185 histogram_tester.ExpectUniqueSample( | 217 histogram_tester.ExpectUniqueSample( |
186 "Autofill.CreditCardInfoBar.Local.PreviouslyDenied", | 218 "Autofill.CreditCardInfoBar.Local.PreviouslyDenied", |
187 AutofillMetrics::INFOBAR_IGNORED, 1); | 219 AutofillMetrics::INFOBAR_IGNORED, 1); |
188 } | 220 } |
189 } | 221 } |
190 | 222 |
191 // Test that server credit card save infobar metrics are logged correctly. | 223 // Test that server credit card save infobar metrics are logged correctly. |
192 TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Server) { | 224 TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Server) { |
193 ::testing::InSequence dummy; | 225 ::testing::InSequence dummy; |
194 | 226 |
| 227 // Infobar is shown. |
| 228 { |
| 229 base::HistogramTester histogram_tester; |
| 230 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
| 231 /* is_uploading= */ true, |
| 232 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_NONE)); |
| 233 |
| 234 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server", |
| 235 AutofillMetrics::INFOBAR_SHOWN, 1); |
| 236 } |
| 237 |
| 238 // Infobar is still shown when the legal message is successfully parsed. |
| 239 { |
| 240 base::HistogramTester histogram_tester; |
| 241 std::string good_legal_message = |
| 242 "{" |
| 243 " \"line\" : [ {" |
| 244 " \"template\": \"This is the entire message.\"" |
| 245 " } ]" |
| 246 "}"; |
| 247 std::unique_ptr<ConfirmInfoBarDelegate> infobar( |
| 248 CreateDelegateWithLegalMessage( |
| 249 /* is_uploading= */ true, std::move(good_legal_message), |
| 250 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_DENIED)); |
| 251 |
| 252 histogram_tester.ExpectUniqueSample( |
| 253 "Autofill.CreditCardInfoBar.Server.PreviouslyDenied", |
| 254 AutofillMetrics::INFOBAR_SHOWN, 1); |
| 255 } |
| 256 |
| 257 // Infobar is not shown because the provided legal message is invalid. |
| 258 { |
| 259 base::HistogramTester histogram_tester; |
| 260 // Legal message is invalid because it's missing the url. |
| 261 std::string bad_legal_message = |
| 262 "{" |
| 263 " \"line\" : [ {" |
| 264 " \"template\": \"Panda {0}.\"," |
| 265 " \"template_parameter\": [ {" |
| 266 " \"display_text\": \"bear\"" |
| 267 " } ]" |
| 268 " } ]" |
| 269 "}"; |
| 270 std::unique_ptr<ConfirmInfoBarDelegate> infobar( |
| 271 CreateDelegateWithLegalMessage( |
| 272 /* is_uploading= */ true, std::move(bad_legal_message), |
| 273 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_DENIED)); |
| 274 |
| 275 histogram_tester.ExpectUniqueSample( |
| 276 "Autofill.CreditCardInfoBar.Server.PreviouslyDenied", |
| 277 AutofillMetrics::INFOBAR_NOT_SHOWN_INVALID_LEGAL_MESSAGE, 1); |
| 278 } |
| 279 |
195 // Accept the infobar. | 280 // Accept the infobar. |
196 { | 281 { |
197 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( | 282 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
198 /* is_uploading= */ true, | 283 /* is_uploading= */ true, |
199 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_NONE)); | 284 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_NONE)); |
200 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); | 285 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); |
201 | 286 |
202 base::HistogramTester histogram_tester; | 287 base::HistogramTester histogram_tester; |
203 EXPECT_TRUE(infobar->Accept()); | 288 EXPECT_TRUE(infobar->Accept()); |
204 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server", | 289 histogram_tester.ExpectUniqueSample( |
205 AutofillMetrics::INFOBAR_ACCEPTED, 1); | 290 "Autofill.CreditCardInfoBar.Server.PreviouslyDenied", |
| 291 AutofillMetrics::INFOBAR_ACCEPTED, 1); |
206 } | 292 } |
207 | 293 |
208 // Cancel the infobar. | 294 // Cancel the infobar. |
209 { | 295 { |
210 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( | 296 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
211 /* is_uploading= */ true, | 297 /* is_uploading= */ true, |
212 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_ACCEPTED)); | 298 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_ACCEPTED)); |
213 | 299 |
214 base::HistogramTester histogram_tester; | 300 base::HistogramTester histogram_tester; |
215 EXPECT_TRUE(infobar->Cancel()); | 301 EXPECT_TRUE(infobar->Cancel()); |
(...skipping 23 matching lines...) Expand all Loading... |
239 | 325 |
240 base::HistogramTester histogram_tester; | 326 base::HistogramTester histogram_tester; |
241 infobar.reset(); | 327 infobar.reset(); |
242 histogram_tester.ExpectUniqueSample( | 328 histogram_tester.ExpectUniqueSample( |
243 "Autofill.CreditCardInfoBar.Server.PreviouslyDenied", | 329 "Autofill.CreditCardInfoBar.Server.PreviouslyDenied", |
244 AutofillMetrics::INFOBAR_IGNORED, 1); | 330 AutofillMetrics::INFOBAR_IGNORED, 1); |
245 } | 331 } |
246 } | 332 } |
247 | 333 |
248 } // namespace autofill | 334 } // namespace autofill |
OLD | NEW |