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

Side by Side Diff: components/payments/core/journey_logger_unittest.cc

Issue 2805913002: [Payments] Move JourneyLogger unit tests from Java to C++. (Closed)
Patch Set: Created 3 years, 8 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 | « components/payments/core/journey_logger.cc ('k') | no next file » | 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 2017 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 "components/payments/core/journey_logger.h"
6
7 #include "base/test/histogram_tester.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
Mathieu 2017/04/07 18:28:01 can you do using testing::ContainerEq; here?
sebsg 2017/04/07 19:05:48 Done.
11 namespace payments {
12
13 namespace {
14 using ::testing::ContainerEq;
15 } // namespace
16
17 // Tests the canMakePayment stats for the case where the merchant does not use
18 // it and does not show the PaymentRequest to the user.
19 TEST(JourneyLoggerTest,
20 RecordJourneyStatsHistograms_CanMakePaymentNotCalled_NoShow) {
21 base::HistogramTester histogram_tester;
22 JourneyLogger logger(false /* is_incognito */);
Mathieu 2017/04/07 18:28:01 nit: I like /*is_incognito=*/false It makes sure
sebsg 2017/04/07 19:05:48 Done.
23
24 logger.RecordJourneyStatsHistograms(
25 JourneyLogger::COMPLETION_STATUS_COMPLETED);
26
27 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
28 JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED,
29 1);
30
31 // There should be no completion stats since PR was not shown to the user
32 EXPECT_THAT(
33 histogram_tester.GetTotalCountsForPrefix(
34 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion"),
35 testing::ContainerEq(base::HistogramTester::CountsMap()));
36 }
37
38 // Tests the canMakePayment stats for the case where the merchant does not use
39 // it and the transaction is aborted.
40 TEST(JourneyLoggerTest,
41 RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndUserAbort) {
42 base::HistogramTester histogram_tester;
43 JourneyLogger logger(false /* is_incognito */);
44
45 // Expect no log for CanMakePayment.
46 EXPECT_THAT(
47 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
48 testing::ContainerEq(base::HistogramTester::CountsMap()));
49
50 // The merchant does not query CanMakePayment, show the PaymentRequest and the
51 // user aborts it.
52 logger.SetShowCalled();
53 logger.RecordJourneyStatsHistograms(
54 JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
55
56 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
57 JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED,
58 1);
59
60 // There should be a record for an abort when CanMakePayment is not used but
61 // the PR is shown to the user.
62 histogram_tester.ExpectBucketCount(
63 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
64 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1);
65 }
66
67 // Tests the canMakePayment stats for the case where the merchant does not use
68 // it and the transaction is aborted.
69 TEST(JourneyLoggerTest,
70 RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndOtherAbort) {
71 base::HistogramTester histogram_tester;
72 JourneyLogger logger(false /* is_incognito */);
73
74 // Expect no log for CanMakePayment.
75 EXPECT_THAT(
76 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
77 testing::ContainerEq(base::HistogramTester::CountsMap()));
78
79 // The merchant does not query CanMakePayment, show the PaymentRequest and
80 // there is an abort not initiated by the user.
81 logger.SetShowCalled();
82 logger.RecordJourneyStatsHistograms(
83 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
84
85 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
86 JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED,
87 1);
88
89 // There should be a record for an abort when CanMakePayment is not used but
90 // the PR is shown to the user.
91 histogram_tester.ExpectBucketCount(
92 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
93 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1);
94 }
95
96 // Tests the canMakePayment stats for the case where the merchant does not use
97 // it and the transaction is completed.
98 TEST(JourneyLoggerTest,
99 RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndComplete) {
100 base::HistogramTester histogram_tester;
101 JourneyLogger logger(false /* is_incognito */);
102
103 // Expect no log for CanMakePayment.
104 EXPECT_THAT(
105 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
106 testing::ContainerEq(base::HistogramTester::CountsMap()));
107
108 // The merchant does not query CanMakePayment, show the PaymentRequest and the
109 // user completes it.
110 logger.SetShowCalled();
111 logger.RecordJourneyStatsHistograms(
112 JourneyLogger::COMPLETION_STATUS_COMPLETED);
113
114 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
115 JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED,
116 1);
117
118 // There should be a record for an abort when CanMakePayment is not used but
119 // the PR is shown to the user.
120 histogram_tester.ExpectBucketCount(
121 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
122 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
123 }
124
125 // Tests the canMakePayment stats for the case where the merchant uses it,
126 // returns false and show is not called.
127 TEST(JourneyLoggerTest,
128 RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseAndNoShow) {
129 base::HistogramTester histogram_tester;
130 JourneyLogger logger(false /* is_incognito */);
131
132 // Expect no log for CanMakePayment.
133 EXPECT_THAT(
134 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
135 testing::ContainerEq(base::HistogramTester::CountsMap()));
136
137 // The user cannot make payment and the PaymentRequest is not shown.
138 logger.SetCanMakePaymentValue(false);
139 logger.RecordJourneyStatsHistograms(
140 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
141
142 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
143 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
144
145 // The CanMakePayment effect on show should be recorded as being false and not
146 // shown.
147 histogram_tester.ExpectBucketCount(
148 "PaymentRequest.CanMakePayment.Used.EffectOnShow",
149 JourneyLogger::CMP_SHOW_COULD_NOT_MAKE_PAYMENT_AND_DID_NOT_SHOW, 1);
150
151 // There should be no completion stats since PR was not shown to the user.
152 EXPECT_THAT(
153 histogram_tester.GetTotalCountsForPrefix(
154 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion"),
155 testing::ContainerEq(base::HistogramTester::CountsMap()));
156 }
157
158 // Tests the canMakePayment stats for the case where the merchant uses it,
159 // returns true and show is not called.
160 TEST(JourneyLoggerTest,
161 RecordJourneyStatsHistograms_CanMakePaymentCalled_TrueAndNoShow) {
162 base::HistogramTester histogram_tester;
163 JourneyLogger logger(false /* is_incognito */);
164
165 // Expect no log for CanMakePayment.
166 EXPECT_THAT(
167 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
168 testing::ContainerEq(base::HistogramTester::CountsMap()));
169
170 // The user cannot make payment and the PaymentRequest is not shown.
171 logger.SetCanMakePaymentValue(true);
172 logger.RecordJourneyStatsHistograms(
173 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
174
175 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
176 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
177
178 // The CanMakePayment effect on show should be recorded as being true and not
179 // shown.
180 histogram_tester.ExpectBucketCount(
181 "PaymentRequest.CanMakePayment.Used.EffectOnShow",
182 JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT, 1);
183
184 // There should be no completion stats since PR was not shown to the user.
185 EXPECT_THAT(
186 histogram_tester.GetTotalCountsForPrefix(
187 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion"),
188 testing::ContainerEq(base::HistogramTester::CountsMap()));
189 }
190
191 // Tests the canMakePayment stats for the case where the merchant uses it,
192 // returns false, show is called but the transaction is aborted by the user.
193 TEST(JourneyLoggerTest,
194 RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowAndUserAbort) {
195 base::HistogramTester histogram_tester;
196 JourneyLogger logger(false /* is_incognito */);
197
198 // Expect no log for CanMakePayment.
199 EXPECT_THAT(
200 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
201 testing::ContainerEq(base::HistogramTester::CountsMap()));
202
203 // The user cannot make payment and the PaymentRequest is not shown.
204 logger.SetShowCalled();
205 logger.SetCanMakePaymentValue(false);
206 logger.RecordJourneyStatsHistograms(
207 JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
208
209 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
210 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
211
212 // The CanMakePayment effect on show should be recorded as being false and
213 // shown.
214 histogram_tester.ExpectBucketCount(
215 "PaymentRequest.CanMakePayment.Used.EffectOnShow",
216 JourneyLogger::CMP_SHOW_DID_SHOW, 1);
217 // There should be a record for an abort when CanMakePayment is false but the
218 // PR is shown to the user.
219 histogram_tester.ExpectBucketCount(
220 "PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion",
221 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1);
222 }
223
224 // Tests the canMakePayment stats for the case where the merchant uses it,
225 // returns false, show is called but the transaction is aborted.
226 TEST(JourneyLoggerTest,
227 RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowAndOtherAbort) {
228 base::HistogramTester histogram_tester;
229 JourneyLogger logger(false /* is_incognito */);
230
231 // Expect no log for CanMakePayment.
232 EXPECT_THAT(
233 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
234 testing::ContainerEq(base::HistogramTester::CountsMap()));
235
236 // The user cannot make payment and the PaymentRequest is not shown.
237 logger.SetShowCalled();
238 logger.SetCanMakePaymentValue(false);
239 logger.RecordJourneyStatsHistograms(
240 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
241
242 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
243 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
244
245 // The CanMakePayment effect on show should be recorded as being false and
246 // shown.
247 histogram_tester.ExpectBucketCount(
248 "PaymentRequest.CanMakePayment.Used.EffectOnShow",
249 JourneyLogger::CMP_SHOW_DID_SHOW, 1);
250 // There should be a record for an abort when CanMakePayment is false but the
251 // PR is shown to the user.
252 histogram_tester.ExpectBucketCount(
253 "PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion",
254 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1);
255 }
256
257 // Tests the canMakePayment stats for the case where the merchant uses it,
258 // returns false, show is called and the transaction is completed.
259 TEST(JourneyLoggerTest,
260 RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowAndComplete) {
261 base::HistogramTester histogram_tester;
262 JourneyLogger logger(false /* is_incognito */);
263
264 // Expect no log for CanMakePayment.
265 EXPECT_THAT(
266 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
267 testing::ContainerEq(base::HistogramTester::CountsMap()));
268
269 // The user cannot make payment and the PaymentRequest is not shown.
270 logger.SetShowCalled();
271 logger.SetCanMakePaymentValue(false);
272 logger.RecordJourneyStatsHistograms(
273 JourneyLogger::COMPLETION_STATUS_COMPLETED);
274
275 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
276 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
277
278 // The CanMakePayment effect on show should be recorded as being false and
279 // shown.
280 histogram_tester.ExpectBucketCount(
281 "PaymentRequest.CanMakePayment.Used.EffectOnShow",
282 JourneyLogger::CMP_SHOW_DID_SHOW, 1);
283
284 // There should be a record for an completion when CanMakePayment is false but
285 // the PR is shown to the user.
286 histogram_tester.ExpectBucketCount(
287 "PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion",
288 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
289 }
290
291 // Tests the canMakePayment stats for the case where the merchant uses it,
292 // returns true, show is called but the transaction is aborted by the user.
293 TEST(JourneyLoggerTest,
294 RecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAndUserAbort) {
295 base::HistogramTester histogram_tester;
296 JourneyLogger logger(false /* is_incognito */);
297
298 // Expect no log for CanMakePayment.
299 EXPECT_THAT(
300 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
301 testing::ContainerEq(base::HistogramTester::CountsMap()));
302
303 // The user cannot make payment and the PaymentRequest is not shown.
304 logger.SetShowCalled();
305 logger.SetCanMakePaymentValue(true);
306 logger.RecordJourneyStatsHistograms(
307 JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
308
309 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
310 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
311
312 // The CanMakePayment effect on show should be recorded as being true and not
313 // shown.
314 histogram_tester.ExpectBucketCount(
315 "PaymentRequest.CanMakePayment.Used.EffectOnShow",
316 JourneyLogger::CMP_SHOW_DID_SHOW |
317 JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT,
318 1);
319 // There should be a record for an abort when CanMakePayment is true and the
320 // PR is shown to the user.
321 histogram_tester.ExpectBucketCount(
322 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion",
323 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1);
324 }
325
326 // Tests the canMakePayment stats for the case where the merchant uses it,
327 // returns true, show is called but the transaction is aborted.
328 TEST(JourneyLoggerTest,
329 RecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAndOtherAbort) {
330 base::HistogramTester histogram_tester;
331 JourneyLogger logger(false /* is_incognito */);
332
333 // Expect no log for CanMakePayment.
334 EXPECT_THAT(
335 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
336 testing::ContainerEq(base::HistogramTester::CountsMap()));
337
338 // The user cannot make payment and the PaymentRequest is not shown.
339 logger.SetShowCalled();
340 logger.SetCanMakePaymentValue(true);
341 logger.RecordJourneyStatsHistograms(
342 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
343
344 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
345 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
346
347 // The CanMakePayment effect on show should be recorded as being true and not
348 // shown.
349 histogram_tester.ExpectBucketCount(
350 "PaymentRequest.CanMakePayment.Used.EffectOnShow",
351 JourneyLogger::CMP_SHOW_DID_SHOW |
352 JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT,
353 1);
354 // There should be a record for an abort when CanMakePayment is true and the
355 // PR is shown to the user.
356 histogram_tester.ExpectBucketCount(
357 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion",
358 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1);
359 }
360
361 // Tests the canMakePayment stats for the case where the merchant uses it,
362 // returns true, show is called and the transaction is completed.
363 TEST(JourneyLoggerTest,
364 RecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAndComplete) {
365 base::HistogramTester histogram_tester;
366 JourneyLogger logger(false /* is_incognito */);
367
368 // Expect no log for CanMakePayment.
369 EXPECT_THAT(
370 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
371 testing::ContainerEq(base::HistogramTester::CountsMap()));
372
373 // The user cannot make payment and the PaymentRequest is not shown.
374 logger.SetShowCalled();
375 logger.SetCanMakePaymentValue(true);
376 logger.RecordJourneyStatsHistograms(
377 JourneyLogger::COMPLETION_STATUS_COMPLETED);
378
379 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
380 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
381
382 // The CanMakePayment effect on show should be recorded as being true and not
383 // shown.
384 histogram_tester.ExpectBucketCount(
385 "PaymentRequest.CanMakePayment.Used.EffectOnShow",
386 JourneyLogger::CMP_SHOW_DID_SHOW |
387 JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT,
388 1);
389 // There should be a record for a completion when CanMakePayment is true and
390 // the PR is shown to the user.
391 histogram_tester.ExpectBucketCount(
392 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion",
393 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
394 }
395
396 // Tests the canMakePayment metrics are not logged if the Payment Request was
397 // done in an incognito tab.
398 TEST(JourneyLoggerTest,
399 RecordJourneyStatsHistograms_CanMakePayment_IncognitoTab) {
400 base::HistogramTester histogram_tester;
401 JourneyLogger logger(true /* is_incognito */);
402
403 // Expect no log for CanMakePayment.
404 EXPECT_THAT(
405 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
406 testing::ContainerEq(base::HistogramTester::CountsMap()));
407
408 // The user cannot make payment and the PaymentRequest is not shown.
409 logger.SetShowCalled();
410 logger.SetCanMakePaymentValue(true);
411 logger.RecordJourneyStatsHistograms(
412 JourneyLogger::COMPLETION_STATUS_COMPLETED);
413
414 // Expect no log for CanMakePayment.
415 EXPECT_THAT(
416 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
417 testing::ContainerEq(base::HistogramTester::CountsMap()));
418 }
419
420 // Tests that the completion status metrics based on whether the user had
421 // suggestions for all the requested sections are logged as correctly.
422 TEST(JourneyLoggerTest,
423 RecordJourneyStatsHistograms_SuggestionsForEverything_Completed) {
424 base::HistogramTester histogram_tester;
425 JourneyLogger logger(false /* is_incognito */);
426
427 // Simulate that the user had suggestions for all the requested sections.
428 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1);
429
430 // Simulate that the user completes the checkout.
431 logger.RecordJourneyStatsHistograms(
432 JourneyLogger::COMPLETION_STATUS_COMPLETED);
433
434 histogram_tester.ExpectBucketCount(
435 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
436 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
437
438 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
439 "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
440 "EffectOnCompletion"),
441 testing::ContainerEq(base::HistogramTester::CountsMap()));
442 }
443
444 // Tests that the completion status metrics based on whether the user had
445 // suggestions for all the requested sections are logged as correctly.
446 TEST(JourneyLoggerTest,
447 RecordJourneyStatsHistograms_SuggestionsForEverything_UserAborted) {
448 base::HistogramTester histogram_tester;
449 JourneyLogger logger(false /* is_incognito */);
450
451 // Simulate that the user had suggestions for all the requested sections.
452 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1);
453
454 // Simulate that the user aborts the checkout.
455 logger.RecordJourneyStatsHistograms(
456 JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
457
458 histogram_tester.ExpectBucketCount(
459 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
460 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1);
461
462 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
463 "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
464 "EffectOnCompletion"),
465 testing::ContainerEq(base::HistogramTester::CountsMap()));
466 }
467
468 // Tests that the completion status metrics based on whether the user had
469 // suggestions for all the requested sections are logged as correctly.
470 TEST(JourneyLoggerTest,
471 RecordJourneyStatsHistograms_SuggestionsForEverything_OtherAborted) {
472 base::HistogramTester histogram_tester;
473 JourneyLogger logger(false /* is_incognito */);
474
475 // Simulate that the user had suggestions for all the requested sections.
476 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1);
477
478 // Simulate that the checkout is aborted.
479 logger.RecordJourneyStatsHistograms(
480 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
481
482 histogram_tester.ExpectBucketCount(
483 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
484 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1);
485
486 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
487 "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
488 "EffectOnCompletion"),
489 testing::ContainerEq(base::HistogramTester::CountsMap()));
490 }
491
492 // Tests that the completion status metrics based on whether the user had
493 // suggestions for all the requested sections are logged as correctly, even in
494 // incognito mode.
495 TEST(JourneyLoggerTest,
496 RecordJourneyStatsHistograms_SuggestionsForEverything_Incognito) {
497 base::HistogramTester histogram_tester;
498 JourneyLogger logger(true /* is_incognito */);
499
500 // Simulate that the user had suggestions for all the requested sections.
501 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1);
502
503 // Simulate that the user completes the checkout.
504 logger.RecordJourneyStatsHistograms(
505 JourneyLogger::COMPLETION_STATUS_COMPLETED);
506
507 histogram_tester.ExpectBucketCount(
508 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
509 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
510
511 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
512 "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
513 "EffectOnCompletion"),
514 testing::ContainerEq(base::HistogramTester::CountsMap()));
515 }
516
517 // Tests that the completion status metrics based on whether the user had
518 // suggestions for all the requested sections are logged as correctly.
519 TEST(JourneyLoggerTest,
520 RecordJourneyStatsHistograms_NoSuggestionsForEverything_Completed) {
521 base::HistogramTester histogram_tester;
522 JourneyLogger logger(false /* is_incognito */);
523
524 // Simulate that the user had suggestions for all the requested sections.
525 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0);
526
527 // Simulate that the user completes the checkout.
528 logger.RecordJourneyStatsHistograms(
529 JourneyLogger::COMPLETION_STATUS_COMPLETED);
530
531 histogram_tester.ExpectBucketCount(
532 "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
533 "EffectOnCompletion",
534 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
535
536 EXPECT_THAT(
537 histogram_tester.GetTotalCountsForPrefix(
538 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion"),
539 testing::ContainerEq(base::HistogramTester::CountsMap()));
540 }
541
542 // Tests that the completion status metrics based on whether the user had
543 // suggestions for all the requested sections are logged as correctly.
544 TEST(JourneyLoggerTest,
545 RecordJourneyStatsHistograms_NoSuggestionsForEverything_UserAborted) {
546 base::HistogramTester histogram_tester;
547 JourneyLogger logger(false /* is_incognito */);
548
549 // Simulate that the user had suggestions for all the requested sections.
550 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0);
551
552 // Simulate that the user aborts the checkout.
553 logger.RecordJourneyStatsHistograms(
554 JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
555
556 histogram_tester.ExpectBucketCount(
557 "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
558 "EffectOnCompletion",
559 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1);
560
561 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
562 "PaymentRequest.UserHadSuggestionsForEverything."
563 "EffectOnCompletion"),
564 testing::ContainerEq(base::HistogramTester::CountsMap()));
565 }
566
567 // Tests that the completion status metrics based on whether the user had
568 // suggestions for all the requested sections are logged as correctly.
569 TEST(JourneyLoggerTest,
570 RecordJourneyStatsHistograms_NoSuggestionsForEverything_OtherAborted) {
571 base::HistogramTester histogram_tester;
572 JourneyLogger logger(false /* is_incognito */);
573
574 // Simulate that the user had suggestions for all the requested sections.
575 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0);
576
577 // Simulate that the user aborts the checkout.
578 logger.RecordJourneyStatsHistograms(
579 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
580
581 histogram_tester.ExpectBucketCount(
582 "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
583 "EffectOnCompletion",
584 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1);
585
586 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
587 "PaymentRequest.UserHadSuggestionsForEverything."
588 "EffectOnCompletion"),
589 testing::ContainerEq(base::HistogramTester::CountsMap()));
590 }
591
592 // Tests that the completion status metrics based on whether the user had
593 // suggestions for all the requested sections are logged as correctly, even in
594 // incognito mode.
595 TEST(JourneyLoggerTest,
596 RecordJourneyStatsHistograms_NoSuggestionsForEverything_Incognito) {
597 base::HistogramTester histogram_tester;
598 JourneyLogger logger(true /* is_incognito */);
599
600 // Simulate that the user had suggestions for all the requested sections.
601 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0);
602
603 // Simulate that the user aborts the checkout.
604 logger.RecordJourneyStatsHistograms(
605 JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
606
607 histogram_tester.ExpectBucketCount(
608 "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
609 "EffectOnCompletion",
610 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1);
611
612 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
613 "PaymentRequest.UserHadSuggestionsForEverything."
614 "EffectOnCompletion"),
615 testing::ContainerEq(base::HistogramTester::CountsMap()));
616 }
617
618 // Tests that the metrics are logged correctly for two simultaneous Payment
619 // Requests.
620 TEST(JourneyLoggerTest, RecordJourneyStatsHistograms_TwoPaymentRequests) {
621 base::HistogramTester histogram_tester;
622 JourneyLogger logger1(false /* is_incognito */);
623 JourneyLogger logger2(false /* is_incognito */);
624
625 // Make the two loggers have different data.
626 logger1.SetShowCalled();
627 logger2.SetShowCalled();
628
629 logger1.SetCanMakePaymentValue(true);
630
631 logger1.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1);
632 logger2.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0);
633
634 // Simulate that the user completes one checkout and aborts the other.
635 logger1.RecordJourneyStatsHistograms(
636 JourneyLogger::COMPLETION_STATUS_COMPLETED);
637 logger2.RecordJourneyStatsHistograms(
638 JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
639
640 // Make sure the appropriate metrics were logged for logger1.
641 histogram_tester.ExpectBucketCount(
642 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
643 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
644 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
645 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
646 histogram_tester.ExpectBucketCount(
647 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion",
648 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
649
650 // Make sure the appropriate metrics were logged for logger2.
651 histogram_tester.ExpectBucketCount(
652 "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
653 "EffectOnCompletion",
654 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1);
655 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
656 JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED,
657 1);
658 histogram_tester.ExpectBucketCount(
659 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
660 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1);
661 }
662
663 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/core/journey_logger.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698