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

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

Issue 2899313002: [Payments] Move the logging for checkout flow to native. (Closed)
Patch Set: Addressed comments Created 3 years, 6 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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/payments/core/journey_logger.h" 5 #include "components/payments/core/journey_logger.h"
6 6
7 #include "base/metrics/metrics_hashes.h" 7 #include "base/metrics/metrics_hashes.h"
8 #include "base/test/histogram_tester.h" 8 #include "base/test/histogram_tester.h"
9 #include "base/test/scoped_feature_list.h" 9 #include "base/test/scoped_feature_list.h"
10 #include "components/metrics/proto/ukm/entry.pb.h" 10 #include "components/metrics/proto/ukm/entry.pb.h"
11 #include "components/ukm/test_ukm_recorder.h" 11 #include "components/ukm/test_ukm_recorder.h"
12 #include "components/ukm/ukm_source.h" 12 #include "components/ukm/ukm_source.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 using testing::ContainerEq; 16 using testing::ContainerEq;
17 17
18 namespace payments { 18 namespace payments {
19 19
20 // Tests the canMakePayment stats for the case where the merchant does not use 20 // Tests the canMakePayment stats for the case where the merchant does not use
21 // it and does not show the PaymentRequest to the user. 21 // it and does not show the PaymentRequest to the user.
22 TEST(JourneyLoggerTest, 22 TEST(JourneyLoggerTest,
23 RecordJourneyStatsHistograms_CanMakePaymentNotCalled_NoShow) { 23 RecordJourneyStatsHistograms_CanMakePaymentNotCalled_NoShow) {
24 base::HistogramTester histogram_tester; 24 base::HistogramTester histogram_tester;
25 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""), 25 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
26 /*ukm_recorder=*/nullptr); 26 /*ukm_recorder=*/nullptr);
27 27
28 logger.RecordJourneyStatsHistograms( 28 logger.SetCompleted();
29 JourneyLogger::COMPLETION_STATUS_COMPLETED);
30 29
31 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", 30 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
32 JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED, 31 JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED,
33 1); 32 1);
34 33
35 // There should be no completion stats since PR was not shown to the user 34 // There should be no completion stats since PR was not shown to the user
36 EXPECT_THAT( 35 EXPECT_THAT(
37 histogram_tester.GetTotalCountsForPrefix( 36 histogram_tester.GetTotalCountsForPrefix(
38 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion"), 37 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion"),
39 testing::ContainerEq(base::HistogramTester::CountsMap())); 38 testing::ContainerEq(base::HistogramTester::CountsMap()));
40 } 39 }
41 40
42 // Tests the canMakePayment stats for the case where the merchant does not use 41 // Tests the canMakePayment stats for the case where the merchant does not use
43 // it and the transaction is aborted. 42 // it and the transaction is aborted.
44 TEST(JourneyLoggerTest, 43 TEST(JourneyLoggerTest,
45 RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndUserAbort) { 44 RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndUserAbort) {
46 base::HistogramTester histogram_tester; 45 base::HistogramTester histogram_tester;
47 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""), 46 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
48 /*ukm_recorder=*/nullptr); 47 /*ukm_recorder=*/nullptr);
49 48
50 // Expect no log for CanMakePayment. 49 // Expect no log for CanMakePayment.
51 EXPECT_THAT( 50 EXPECT_THAT(
52 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), 51 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
53 testing::ContainerEq(base::HistogramTester::CountsMap())); 52 testing::ContainerEq(base::HistogramTester::CountsMap()));
54 53
55 // The merchant does not query CanMakePayment, show the PaymentRequest and the 54 // The merchant does not query CanMakePayment, show the PaymentRequest and the
56 // user aborts it. 55 // user aborts it.
57 logger.SetShowCalled(); 56 logger.SetShowCalled();
58 logger.RecordJourneyStatsHistograms( 57 logger.SetAborted(JourneyLogger::ABORT_REASON_ABORTED_BY_USER);
59 JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
60 58
61 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", 59 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
62 JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED, 60 JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED,
63 1); 61 1);
64 62
65 // There should be a record for an abort when CanMakePayment is not used but 63 // There should be a record for an abort when CanMakePayment is not used but
66 // the PR is shown to the user. 64 // the PR is shown to the user.
67 histogram_tester.ExpectBucketCount( 65 histogram_tester.ExpectBucketCount(
68 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion", 66 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
69 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); 67 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1);
70 } 68 }
71 69
72 // Tests the canMakePayment stats for the case where the merchant does not use 70 // Tests the canMakePayment stats for the case where the merchant does not use
73 // it and the transaction is aborted. 71 // it and the transaction is aborted.
74 TEST(JourneyLoggerTest, 72 TEST(JourneyLoggerTest,
75 RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndOtherAbort) { 73 RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndOtherAbort) {
76 base::HistogramTester histogram_tester; 74 base::HistogramTester histogram_tester;
77 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""), 75 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
78 /*ukm_recorder=*/nullptr); 76 /*ukm_recorder=*/nullptr);
79 77
80 // Expect no log for CanMakePayment. 78 // Expect no log for CanMakePayment.
81 EXPECT_THAT( 79 EXPECT_THAT(
82 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), 80 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
83 testing::ContainerEq(base::HistogramTester::CountsMap())); 81 testing::ContainerEq(base::HistogramTester::CountsMap()));
84 82
85 // The merchant does not query CanMakePayment, show the PaymentRequest and 83 // The merchant does not query CanMakePayment, show the PaymentRequest and
86 // there is an abort not initiated by the user. 84 // there is an abort not initiated by the user.
87 logger.SetShowCalled(); 85 logger.SetShowCalled();
88 logger.RecordJourneyStatsHistograms( 86 logger.SetAborted(JourneyLogger::ABORT_REASON_OTHER);
89 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
90 87
91 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", 88 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
92 JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED, 89 JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED,
93 1); 90 1);
94 91
95 // There should be a record for an abort when CanMakePayment is not used but 92 // There should be a record for an abort when CanMakePayment is not used but
96 // the PR is shown to the user. 93 // the PR is shown to the user.
97 histogram_tester.ExpectBucketCount( 94 histogram_tester.ExpectBucketCount(
98 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion", 95 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
99 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1); 96 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1);
100 } 97 }
101 98
102 // Tests the canMakePayment stats for the case where the merchant does not use 99 // Tests the canMakePayment stats for the case where the merchant does not use
103 // it and the transaction is completed. 100 // it and the transaction is completed.
104 TEST(JourneyLoggerTest, 101 TEST(JourneyLoggerTest,
105 RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndComplete) { 102 RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndComplete) {
106 base::HistogramTester histogram_tester; 103 base::HistogramTester histogram_tester;
107 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""), 104 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
108 /*ukm_recorder=*/nullptr); 105 /*ukm_recorder=*/nullptr);
109 106
110 // Expect no log for CanMakePayment. 107 // Expect no log for CanMakePayment.
111 EXPECT_THAT( 108 EXPECT_THAT(
112 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), 109 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
113 testing::ContainerEq(base::HistogramTester::CountsMap())); 110 testing::ContainerEq(base::HistogramTester::CountsMap()));
114 111
115 // The merchant does not query CanMakePayment, show the PaymentRequest and the 112 // The merchant does not query CanMakePayment, show the PaymentRequest and the
116 // user completes it. 113 // user completes it.
117 logger.SetShowCalled(); 114 logger.SetShowCalled();
118 logger.RecordJourneyStatsHistograms( 115 logger.SetCompleted();
119 JourneyLogger::COMPLETION_STATUS_COMPLETED);
120 116
121 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", 117 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
122 JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED, 118 JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED,
123 1); 119 1);
124 120
125 // There should be a record for an abort when CanMakePayment is not used but 121 // There should be a record for an abort when CanMakePayment is not used but
126 // the PR is shown to the user. 122 // the PR is shown to the user.
127 histogram_tester.ExpectBucketCount( 123 histogram_tester.ExpectBucketCount(
128 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion", 124 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
129 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); 125 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
130 } 126 }
131 127
132 // Tests the canMakePayment stats for the case where the merchant uses it, 128 // Tests the canMakePayment stats for the case where the merchant uses it,
133 // returns false and show is not called. 129 // returns false and show is not called.
134 TEST(JourneyLoggerTest, 130 TEST(JourneyLoggerTest,
135 RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseAndNoShow) { 131 RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseAndNoShow) {
136 base::HistogramTester histogram_tester; 132 base::HistogramTester histogram_tester;
137 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""), 133 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
138 /*ukm_recorder=*/nullptr); 134 /*ukm_recorder=*/nullptr);
139 135
140 // Expect no log for CanMakePayment. 136 // Expect no log for CanMakePayment.
141 EXPECT_THAT( 137 EXPECT_THAT(
142 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), 138 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
143 testing::ContainerEq(base::HistogramTester::CountsMap())); 139 testing::ContainerEq(base::HistogramTester::CountsMap()));
144 140
145 // The user cannot make payment and the PaymentRequest is not shown. 141 // The user cannot make payment and the PaymentRequest is not shown.
146 logger.SetCanMakePaymentValue(false); 142 logger.SetCanMakePaymentValue(false);
147 logger.RecordJourneyStatsHistograms( 143 logger.SetAborted(JourneyLogger::ABORT_REASON_OTHER);
148 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
149 144
150 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", 145 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
151 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); 146 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
152 147
153 // The CanMakePayment effect on show should be recorded as being false and not 148 // The CanMakePayment effect on show should be recorded as being false and not
154 // shown. 149 // shown.
155 histogram_tester.ExpectBucketCount( 150 histogram_tester.ExpectBucketCount(
156 "PaymentRequest.CanMakePayment.Used.EffectOnShow", 151 "PaymentRequest.CanMakePayment.Used.EffectOnShow",
157 JourneyLogger::CMP_SHOW_COULD_NOT_MAKE_PAYMENT_AND_DID_NOT_SHOW, 1); 152 JourneyLogger::CMP_SHOW_COULD_NOT_MAKE_PAYMENT_AND_DID_NOT_SHOW, 1);
158 153
(...skipping 12 matching lines...) Expand all
171 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""), 166 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
172 /*ukm_recorder=*/nullptr); 167 /*ukm_recorder=*/nullptr);
173 168
174 // Expect no log for CanMakePayment. 169 // Expect no log for CanMakePayment.
175 EXPECT_THAT( 170 EXPECT_THAT(
176 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), 171 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
177 testing::ContainerEq(base::HistogramTester::CountsMap())); 172 testing::ContainerEq(base::HistogramTester::CountsMap()));
178 173
179 // The user cannot make payment and the PaymentRequest is not shown. 174 // The user cannot make payment and the PaymentRequest is not shown.
180 logger.SetCanMakePaymentValue(true); 175 logger.SetCanMakePaymentValue(true);
181 logger.RecordJourneyStatsHistograms( 176 logger.SetAborted(JourneyLogger::ABORT_REASON_OTHER);
182 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
183 177
184 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", 178 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
185 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); 179 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
186 180
187 // The CanMakePayment effect on show should be recorded as being true and not 181 // The CanMakePayment effect on show should be recorded as being true and not
188 // shown. 182 // shown.
189 histogram_tester.ExpectBucketCount( 183 histogram_tester.ExpectBucketCount(
190 "PaymentRequest.CanMakePayment.Used.EffectOnShow", 184 "PaymentRequest.CanMakePayment.Used.EffectOnShow",
191 JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT, 1); 185 JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT, 1);
192 186
(...skipping 13 matching lines...) Expand all
206 /*ukm_recorder=*/nullptr); 200 /*ukm_recorder=*/nullptr);
207 201
208 // Expect no log for CanMakePayment. 202 // Expect no log for CanMakePayment.
209 EXPECT_THAT( 203 EXPECT_THAT(
210 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), 204 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
211 testing::ContainerEq(base::HistogramTester::CountsMap())); 205 testing::ContainerEq(base::HistogramTester::CountsMap()));
212 206
213 // The user cannot make payment and the PaymentRequest is not shown. 207 // The user cannot make payment and the PaymentRequest is not shown.
214 logger.SetShowCalled(); 208 logger.SetShowCalled();
215 logger.SetCanMakePaymentValue(false); 209 logger.SetCanMakePaymentValue(false);
216 logger.RecordJourneyStatsHistograms( 210 logger.SetAborted(JourneyLogger::ABORT_REASON_ABORTED_BY_USER);
217 JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
218 211
219 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", 212 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
220 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); 213 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
221 214
222 // The CanMakePayment effect on show should be recorded as being false and 215 // The CanMakePayment effect on show should be recorded as being false and
223 // shown. 216 // shown.
224 histogram_tester.ExpectBucketCount( 217 histogram_tester.ExpectBucketCount(
225 "PaymentRequest.CanMakePayment.Used.EffectOnShow", 218 "PaymentRequest.CanMakePayment.Used.EffectOnShow",
226 JourneyLogger::CMP_SHOW_DID_SHOW, 1); 219 JourneyLogger::CMP_SHOW_DID_SHOW, 1);
227 // There should be a record for an abort when CanMakePayment is false but the 220 // There should be a record for an abort when CanMakePayment is false but the
(...skipping 12 matching lines...) Expand all
240 /*ukm_recorder=*/nullptr); 233 /*ukm_recorder=*/nullptr);
241 234
242 // Expect no log for CanMakePayment. 235 // Expect no log for CanMakePayment.
243 EXPECT_THAT( 236 EXPECT_THAT(
244 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), 237 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
245 testing::ContainerEq(base::HistogramTester::CountsMap())); 238 testing::ContainerEq(base::HistogramTester::CountsMap()));
246 239
247 // The user cannot make payment and the PaymentRequest is not shown. 240 // The user cannot make payment and the PaymentRequest is not shown.
248 logger.SetShowCalled(); 241 logger.SetShowCalled();
249 logger.SetCanMakePaymentValue(false); 242 logger.SetCanMakePaymentValue(false);
250 logger.RecordJourneyStatsHistograms( 243 logger.SetAborted(JourneyLogger::ABORT_REASON_OTHER);
251 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
252 244
253 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", 245 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
254 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); 246 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
255 247
256 // The CanMakePayment effect on show should be recorded as being false and 248 // The CanMakePayment effect on show should be recorded as being false and
257 // shown. 249 // shown.
258 histogram_tester.ExpectBucketCount( 250 histogram_tester.ExpectBucketCount(
259 "PaymentRequest.CanMakePayment.Used.EffectOnShow", 251 "PaymentRequest.CanMakePayment.Used.EffectOnShow",
260 JourneyLogger::CMP_SHOW_DID_SHOW, 1); 252 JourneyLogger::CMP_SHOW_DID_SHOW, 1);
261 // There should be a record for an abort when CanMakePayment is false but the 253 // There should be a record for an abort when CanMakePayment is false but the
(...skipping 12 matching lines...) Expand all
274 /*ukm_recorder=*/nullptr); 266 /*ukm_recorder=*/nullptr);
275 267
276 // Expect no log for CanMakePayment. 268 // Expect no log for CanMakePayment.
277 EXPECT_THAT( 269 EXPECT_THAT(
278 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), 270 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
279 testing::ContainerEq(base::HistogramTester::CountsMap())); 271 testing::ContainerEq(base::HistogramTester::CountsMap()));
280 272
281 // The user cannot make payment and the PaymentRequest is not shown. 273 // The user cannot make payment and the PaymentRequest is not shown.
282 logger.SetShowCalled(); 274 logger.SetShowCalled();
283 logger.SetCanMakePaymentValue(false); 275 logger.SetCanMakePaymentValue(false);
284 logger.RecordJourneyStatsHistograms( 276 logger.SetCompleted();
285 JourneyLogger::COMPLETION_STATUS_COMPLETED);
286 277
287 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", 278 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
288 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); 279 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
289 280
290 // The CanMakePayment effect on show should be recorded as being false and 281 // The CanMakePayment effect on show should be recorded as being false and
291 // shown. 282 // shown.
292 histogram_tester.ExpectBucketCount( 283 histogram_tester.ExpectBucketCount(
293 "PaymentRequest.CanMakePayment.Used.EffectOnShow", 284 "PaymentRequest.CanMakePayment.Used.EffectOnShow",
294 JourneyLogger::CMP_SHOW_DID_SHOW, 1); 285 JourneyLogger::CMP_SHOW_DID_SHOW, 1);
295 286
(...skipping 13 matching lines...) Expand all
309 /*ukm_recorder=*/nullptr); 300 /*ukm_recorder=*/nullptr);
310 301
311 // Expect no log for CanMakePayment. 302 // Expect no log for CanMakePayment.
312 EXPECT_THAT( 303 EXPECT_THAT(
313 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), 304 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
314 testing::ContainerEq(base::HistogramTester::CountsMap())); 305 testing::ContainerEq(base::HistogramTester::CountsMap()));
315 306
316 // The user cannot make payment and the PaymentRequest is not shown. 307 // The user cannot make payment and the PaymentRequest is not shown.
317 logger.SetShowCalled(); 308 logger.SetShowCalled();
318 logger.SetCanMakePaymentValue(true); 309 logger.SetCanMakePaymentValue(true);
319 logger.RecordJourneyStatsHistograms( 310 logger.SetAborted(JourneyLogger::ABORT_REASON_ABORTED_BY_USER);
320 JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
321 311
322 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", 312 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
323 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); 313 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
324 314
325 // The CanMakePayment effect on show should be recorded as being true and not 315 // The CanMakePayment effect on show should be recorded as being true and not
326 // shown. 316 // shown.
327 histogram_tester.ExpectBucketCount( 317 histogram_tester.ExpectBucketCount(
328 "PaymentRequest.CanMakePayment.Used.EffectOnShow", 318 "PaymentRequest.CanMakePayment.Used.EffectOnShow",
329 JourneyLogger::CMP_SHOW_DID_SHOW | 319 JourneyLogger::CMP_SHOW_DID_SHOW |
330 JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT, 320 JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT,
(...skipping 14 matching lines...) Expand all
345 /*ukm_recorder=*/nullptr); 335 /*ukm_recorder=*/nullptr);
346 336
347 // Expect no log for CanMakePayment. 337 // Expect no log for CanMakePayment.
348 EXPECT_THAT( 338 EXPECT_THAT(
349 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), 339 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
350 testing::ContainerEq(base::HistogramTester::CountsMap())); 340 testing::ContainerEq(base::HistogramTester::CountsMap()));
351 341
352 // The user cannot make payment and the PaymentRequest is not shown. 342 // The user cannot make payment and the PaymentRequest is not shown.
353 logger.SetShowCalled(); 343 logger.SetShowCalled();
354 logger.SetCanMakePaymentValue(true); 344 logger.SetCanMakePaymentValue(true);
355 logger.RecordJourneyStatsHistograms( 345 logger.SetAborted(JourneyLogger::ABORT_REASON_OTHER);
356 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
357 346
358 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", 347 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
359 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); 348 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
360 349
361 // The CanMakePayment effect on show should be recorded as being true and not 350 // The CanMakePayment effect on show should be recorded as being true and not
362 // shown. 351 // shown.
363 histogram_tester.ExpectBucketCount( 352 histogram_tester.ExpectBucketCount(
364 "PaymentRequest.CanMakePayment.Used.EffectOnShow", 353 "PaymentRequest.CanMakePayment.Used.EffectOnShow",
365 JourneyLogger::CMP_SHOW_DID_SHOW | 354 JourneyLogger::CMP_SHOW_DID_SHOW |
366 JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT, 355 JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT,
(...skipping 14 matching lines...) Expand all
381 /*ukm_recorder=*/nullptr); 370 /*ukm_recorder=*/nullptr);
382 371
383 // Expect no log for CanMakePayment. 372 // Expect no log for CanMakePayment.
384 EXPECT_THAT( 373 EXPECT_THAT(
385 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), 374 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
386 testing::ContainerEq(base::HistogramTester::CountsMap())); 375 testing::ContainerEq(base::HistogramTester::CountsMap()));
387 376
388 // The user cannot make payment and the PaymentRequest is not shown. 377 // The user cannot make payment and the PaymentRequest is not shown.
389 logger.SetShowCalled(); 378 logger.SetShowCalled();
390 logger.SetCanMakePaymentValue(true); 379 logger.SetCanMakePaymentValue(true);
391 logger.RecordJourneyStatsHistograms( 380 logger.SetCompleted();
392 JourneyLogger::COMPLETION_STATUS_COMPLETED);
393 381
394 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", 382 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
395 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); 383 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
396 384
397 // The CanMakePayment effect on show should be recorded as being true and not 385 // The CanMakePayment effect on show should be recorded as being true and not
398 // shown. 386 // shown.
399 histogram_tester.ExpectBucketCount( 387 histogram_tester.ExpectBucketCount(
400 "PaymentRequest.CanMakePayment.Used.EffectOnShow", 388 "PaymentRequest.CanMakePayment.Used.EffectOnShow",
401 JourneyLogger::CMP_SHOW_DID_SHOW | 389 JourneyLogger::CMP_SHOW_DID_SHOW |
402 JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT, 390 JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT,
(...skipping 14 matching lines...) Expand all
417 /*ukm_recorder=*/nullptr); 405 /*ukm_recorder=*/nullptr);
418 406
419 // Expect no log for CanMakePayment. 407 // Expect no log for CanMakePayment.
420 EXPECT_THAT( 408 EXPECT_THAT(
421 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), 409 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
422 testing::ContainerEq(base::HistogramTester::CountsMap())); 410 testing::ContainerEq(base::HistogramTester::CountsMap()));
423 411
424 // The user cannot make payment and the PaymentRequest is not shown. 412 // The user cannot make payment and the PaymentRequest is not shown.
425 logger.SetShowCalled(); 413 logger.SetShowCalled();
426 logger.SetCanMakePaymentValue(true); 414 logger.SetCanMakePaymentValue(true);
427 logger.RecordJourneyStatsHistograms( 415 logger.SetCompleted();
428 JourneyLogger::COMPLETION_STATUS_COMPLETED);
429 416
430 // Expect no log for CanMakePayment. 417 // Expect no log for CanMakePayment.
431 EXPECT_THAT( 418 EXPECT_THAT(
432 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), 419 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
433 testing::ContainerEq(base::HistogramTester::CountsMap())); 420 testing::ContainerEq(base::HistogramTester::CountsMap()));
434 } 421 }
435 422
436 // Tests that the completion status metrics based on whether the user had 423 // Tests that the completion status metrics based on whether the user had
437 // suggestions for all the requested sections are logged as correctly. 424 // suggestions for all the requested sections are logged as correctly.
438 TEST(JourneyLoggerTest, 425 TEST(JourneyLoggerTest,
439 RecordJourneyStatsHistograms_SuggestionsForEverything_Completed) { 426 RecordJourneyStatsHistograms_SuggestionsForEverything_Completed) {
440 base::HistogramTester histogram_tester; 427 base::HistogramTester histogram_tester;
441 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""), 428 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
442 /*ukm_recorder=*/nullptr); 429 /*ukm_recorder=*/nullptr);
443 430
444 // Simulate that the user had suggestions for all the requested sections. 431 // Simulate that the user had suggestions for all the requested sections.
445 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1); 432 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1);
446 433
447 // Simulate that the user completes the checkout. 434 // Simulate that the user completes the checkout.
448 logger.RecordJourneyStatsHistograms( 435 logger.SetCompleted();
449 JourneyLogger::COMPLETION_STATUS_COMPLETED);
450 436
451 histogram_tester.ExpectBucketCount( 437 histogram_tester.ExpectBucketCount(
452 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion", 438 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
453 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); 439 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
454 440
455 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( 441 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
456 "PaymentRequest.UserDidNotHaveSuggestionsForEverything." 442 "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
457 "EffectOnCompletion"), 443 "EffectOnCompletion"),
458 testing::ContainerEq(base::HistogramTester::CountsMap())); 444 testing::ContainerEq(base::HistogramTester::CountsMap()));
459 } 445 }
460 446
461 // Tests that the completion status metrics based on whether the user had 447 // Tests that the completion status metrics based on whether the user had
462 // suggestions for all the requested sections are logged as correctly. 448 // suggestions for all the requested sections are logged as correctly.
463 TEST(JourneyLoggerTest, 449 TEST(JourneyLoggerTest,
464 RecordJourneyStatsHistograms_SuggestionsForEverything_UserAborted) { 450 RecordJourneyStatsHistograms_SuggestionsForEverything_UserAborted) {
465 base::HistogramTester histogram_tester; 451 base::HistogramTester histogram_tester;
466 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""), 452 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
467 /*ukm_recorder=*/nullptr); 453 /*ukm_recorder=*/nullptr);
468 454
469 // Simulate that the user had suggestions for all the requested sections. 455 // Simulate that the user had suggestions for all the requested sections.
470 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1); 456 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1);
471 457
472 // Simulate that the user aborts the checkout. 458 // Simulate that the user aborts the checkout.
473 logger.RecordJourneyStatsHistograms( 459 logger.SetAborted(JourneyLogger::ABORT_REASON_ABORTED_BY_USER);
474 JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
475 460
476 histogram_tester.ExpectBucketCount( 461 histogram_tester.ExpectBucketCount(
477 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion", 462 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
478 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); 463 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1);
479 464
480 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( 465 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
481 "PaymentRequest.UserDidNotHaveSuggestionsForEverything." 466 "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
482 "EffectOnCompletion"), 467 "EffectOnCompletion"),
483 testing::ContainerEq(base::HistogramTester::CountsMap())); 468 testing::ContainerEq(base::HistogramTester::CountsMap()));
484 } 469 }
485 470
486 // Tests that the completion status metrics based on whether the user had 471 // Tests that the completion status metrics based on whether the user had
487 // suggestions for all the requested sections are logged as correctly. 472 // suggestions for all the requested sections are logged as correctly.
488 TEST(JourneyLoggerTest, 473 TEST(JourneyLoggerTest,
489 RecordJourneyStatsHistograms_SuggestionsForEverything_OtherAborted) { 474 RecordJourneyStatsHistograms_SuggestionsForEverything_OtherAborted) {
490 base::HistogramTester histogram_tester; 475 base::HistogramTester histogram_tester;
491 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""), 476 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
492 /*ukm_recorder=*/nullptr); 477 /*ukm_recorder=*/nullptr);
493 478
494 // Simulate that the user had suggestions for all the requested sections. 479 // Simulate that the user had suggestions for all the requested sections.
495 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1); 480 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1);
496 481
497 // Simulate that the checkout is aborted. 482 // Simulate that the checkout is aborted.
498 logger.RecordJourneyStatsHistograms( 483 logger.SetAborted(JourneyLogger::ABORT_REASON_OTHER);
499 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
500 484
501 histogram_tester.ExpectBucketCount( 485 histogram_tester.ExpectBucketCount(
502 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion", 486 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
503 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1); 487 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1);
504 488
505 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( 489 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
506 "PaymentRequest.UserDidNotHaveSuggestionsForEverything." 490 "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
507 "EffectOnCompletion"), 491 "EffectOnCompletion"),
508 testing::ContainerEq(base::HistogramTester::CountsMap())); 492 testing::ContainerEq(base::HistogramTester::CountsMap()));
509 } 493 }
510 494
511 // Tests that the completion status metrics based on whether the user had 495 // Tests that the completion status metrics based on whether the user had
512 // suggestions for all the requested sections are logged as correctly, even in 496 // suggestions for all the requested sections are logged as correctly, even in
513 // incognito mode. 497 // incognito mode.
514 TEST(JourneyLoggerTest, 498 TEST(JourneyLoggerTest,
515 RecordJourneyStatsHistograms_SuggestionsForEverything_Incognito) { 499 RecordJourneyStatsHistograms_SuggestionsForEverything_Incognito) {
516 base::HistogramTester histogram_tester; 500 base::HistogramTester histogram_tester;
517 JourneyLogger logger(/*is_incognito=*/true, /*url=*/GURL(""), 501 JourneyLogger logger(/*is_incognito=*/true, /*url=*/GURL(""),
518 /*ukm_recorder=*/nullptr); 502 /*ukm_recorder=*/nullptr);
519 503
520 // Simulate that the user had suggestions for all the requested sections. 504 // Simulate that the user had suggestions for all the requested sections.
521 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1); 505 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1);
522 506
523 // Simulate that the user completes the checkout. 507 // Simulate that the user completes the checkout.
524 logger.RecordJourneyStatsHistograms( 508 logger.SetCompleted();
525 JourneyLogger::COMPLETION_STATUS_COMPLETED);
526 509
527 histogram_tester.ExpectBucketCount( 510 histogram_tester.ExpectBucketCount(
528 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion", 511 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
529 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); 512 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
530 513
531 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( 514 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
532 "PaymentRequest.UserDidNotHaveSuggestionsForEverything." 515 "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
533 "EffectOnCompletion"), 516 "EffectOnCompletion"),
534 testing::ContainerEq(base::HistogramTester::CountsMap())); 517 testing::ContainerEq(base::HistogramTester::CountsMap()));
535 } 518 }
536 519
537 // Tests that the completion status metrics based on whether the user had 520 // Tests that the completion status metrics based on whether the user had
538 // suggestions for all the requested sections are logged as correctly. 521 // suggestions for all the requested sections are logged as correctly.
539 TEST(JourneyLoggerTest, 522 TEST(JourneyLoggerTest,
540 RecordJourneyStatsHistograms_NoSuggestionsForEverything_Completed) { 523 RecordJourneyStatsHistograms_NoSuggestionsForEverything_Completed) {
541 base::HistogramTester histogram_tester; 524 base::HistogramTester histogram_tester;
542 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""), 525 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
543 /*ukm_recorder=*/nullptr); 526 /*ukm_recorder=*/nullptr);
544 527
545 // Simulate that the user had suggestions for all the requested sections. 528 // Simulate that the user had suggestions for all the requested sections.
546 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0); 529 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0);
547 530
548 // Simulate that the user completes the checkout. 531 // Simulate that the user completes the checkout.
549 logger.RecordJourneyStatsHistograms( 532 logger.SetCompleted();
550 JourneyLogger::COMPLETION_STATUS_COMPLETED);
551 533
552 histogram_tester.ExpectBucketCount( 534 histogram_tester.ExpectBucketCount(
553 "PaymentRequest.UserDidNotHaveSuggestionsForEverything." 535 "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
554 "EffectOnCompletion", 536 "EffectOnCompletion",
555 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); 537 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
556 538
557 EXPECT_THAT( 539 EXPECT_THAT(
558 histogram_tester.GetTotalCountsForPrefix( 540 histogram_tester.GetTotalCountsForPrefix(
559 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion"), 541 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion"),
560 testing::ContainerEq(base::HistogramTester::CountsMap())); 542 testing::ContainerEq(base::HistogramTester::CountsMap()));
561 } 543 }
562 544
563 // Tests that the completion status metrics based on whether the user had 545 // Tests that the completion status metrics based on whether the user had
564 // suggestions for all the requested sections are logged as correctly. 546 // suggestions for all the requested sections are logged as correctly.
565 TEST(JourneyLoggerTest, 547 TEST(JourneyLoggerTest,
566 RecordJourneyStatsHistograms_NoSuggestionsForEverything_UserAborted) { 548 RecordJourneyStatsHistograms_NoSuggestionsForEverything_UserAborted) {
567 base::HistogramTester histogram_tester; 549 base::HistogramTester histogram_tester;
568 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""), 550 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
569 /*ukm_recorder=*/nullptr); 551 /*ukm_recorder=*/nullptr);
570 552
571 // Simulate that the user had suggestions for all the requested sections. 553 // Simulate that the user had suggestions for all the requested sections.
572 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0); 554 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0);
573 555
574 // Simulate that the user aborts the checkout. 556 // Simulate that the user aborts the checkout.
575 logger.RecordJourneyStatsHistograms( 557 logger.SetAborted(JourneyLogger::ABORT_REASON_ABORTED_BY_USER);
576 JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
577 558
578 histogram_tester.ExpectBucketCount( 559 histogram_tester.ExpectBucketCount(
579 "PaymentRequest.UserDidNotHaveSuggestionsForEverything." 560 "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
580 "EffectOnCompletion", 561 "EffectOnCompletion",
581 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); 562 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1);
582 563
583 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( 564 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
584 "PaymentRequest.UserHadSuggestionsForEverything." 565 "PaymentRequest.UserHadSuggestionsForEverything."
585 "EffectOnCompletion"), 566 "EffectOnCompletion"),
586 testing::ContainerEq(base::HistogramTester::CountsMap())); 567 testing::ContainerEq(base::HistogramTester::CountsMap()));
587 } 568 }
588 569
589 // Tests that the completion status metrics based on whether the user had 570 // Tests that the completion status metrics based on whether the user had
590 // suggestions for all the requested sections are logged as correctly. 571 // suggestions for all the requested sections are logged as correctly.
591 TEST(JourneyLoggerTest, 572 TEST(JourneyLoggerTest,
592 RecordJourneyStatsHistograms_NoSuggestionsForEverything_OtherAborted) { 573 RecordJourneyStatsHistograms_NoSuggestionsForEverything_OtherAborted) {
593 base::HistogramTester histogram_tester; 574 base::HistogramTester histogram_tester;
594 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""), 575 JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
595 /*ukm_recorder=*/nullptr); 576 /*ukm_recorder=*/nullptr);
596 577
597 // Simulate that the user had suggestions for all the requested sections. 578 // Simulate that the user had suggestions for all the requested sections.
598 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0); 579 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0);
599 580
600 // Simulate that the user aborts the checkout. 581 // Simulate that the the checkout is aborted.
601 logger.RecordJourneyStatsHistograms( 582 logger.SetAborted(JourneyLogger::ABORT_REASON_OTHER);
602 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
603 583
604 histogram_tester.ExpectBucketCount( 584 histogram_tester.ExpectBucketCount(
605 "PaymentRequest.UserDidNotHaveSuggestionsForEverything." 585 "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
606 "EffectOnCompletion", 586 "EffectOnCompletion",
607 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1); 587 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1);
608 588
609 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( 589 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
610 "PaymentRequest.UserHadSuggestionsForEverything." 590 "PaymentRequest.UserHadSuggestionsForEverything."
611 "EffectOnCompletion"), 591 "EffectOnCompletion"),
612 testing::ContainerEq(base::HistogramTester::CountsMap())); 592 testing::ContainerEq(base::HistogramTester::CountsMap()));
613 } 593 }
614 594
615 // Tests that the completion status metrics based on whether the user had 595 // Tests that the completion status metrics based on whether the user had
616 // suggestions for all the requested sections are logged as correctly, even in 596 // suggestions for all the requested sections are logged as correctly, even in
617 // incognito mode. 597 // incognito mode.
618 TEST(JourneyLoggerTest, 598 TEST(JourneyLoggerTest,
619 RecordJourneyStatsHistograms_NoSuggestionsForEverything_Incognito) { 599 RecordJourneyStatsHistograms_NoSuggestionsForEverything_Incognito) {
620 base::HistogramTester histogram_tester; 600 base::HistogramTester histogram_tester;
621 JourneyLogger logger(/*is_incognito=*/true, /*url=*/GURL(""), 601 JourneyLogger logger(/*is_incognito=*/true, /*url=*/GURL(""),
622 /*ukm_recorder=*/nullptr); 602 /*ukm_recorder=*/nullptr);
623 603
624 // Simulate that the user had suggestions for all the requested sections. 604 // Simulate that the user had suggestions for all the requested sections.
625 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0); 605 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0);
626 606
627 // Simulate that the user aborts the checkout. 607 // Simulate that the user aborts the checkout.
628 logger.RecordJourneyStatsHistograms( 608 logger.SetAborted(JourneyLogger::ABORT_REASON_ABORTED_BY_USER);
629 JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
630 609
631 histogram_tester.ExpectBucketCount( 610 histogram_tester.ExpectBucketCount(
632 "PaymentRequest.UserDidNotHaveSuggestionsForEverything." 611 "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
633 "EffectOnCompletion", 612 "EffectOnCompletion",
634 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); 613 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1);
635 614
636 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( 615 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
637 "PaymentRequest.UserHadSuggestionsForEverything." 616 "PaymentRequest.UserHadSuggestionsForEverything."
638 "EffectOnCompletion"), 617 "EffectOnCompletion"),
639 testing::ContainerEq(base::HistogramTester::CountsMap())); 618 testing::ContainerEq(base::HistogramTester::CountsMap()));
(...skipping 11 matching lines...) Expand all
651 // Make the two loggers have different data. 630 // Make the two loggers have different data.
652 logger1.SetShowCalled(); 631 logger1.SetShowCalled();
653 logger2.SetShowCalled(); 632 logger2.SetShowCalled();
654 633
655 logger1.SetCanMakePaymentValue(true); 634 logger1.SetCanMakePaymentValue(true);
656 635
657 logger1.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1); 636 logger1.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1);
658 logger2.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0); 637 logger2.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0);
659 638
660 // Simulate that the user completes one checkout and aborts the other. 639 // Simulate that the user completes one checkout and aborts the other.
661 logger1.RecordJourneyStatsHistograms( 640 logger1.SetCompleted();
662 JourneyLogger::COMPLETION_STATUS_COMPLETED); 641 logger2.SetAborted(JourneyLogger::ABORT_REASON_ABORTED_BY_USER);
663 logger2.RecordJourneyStatsHistograms(
664 JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
665 642
666 // Make sure the appropriate metrics were logged for logger1. 643 // Make sure the appropriate metrics were logged for logger1.
667 histogram_tester.ExpectBucketCount( 644 histogram_tester.ExpectBucketCount(
668 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion", 645 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
669 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); 646 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
670 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", 647 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
671 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); 648 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
672 histogram_tester.ExpectBucketCount( 649 histogram_tester.ExpectBucketCount(
673 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion", 650 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion",
674 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); 651 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
(...skipping 17 matching lines...) Expand all
692 char test_url[] = "http://www.google.com/"; 669 char test_url[] = "http://www.google.com/";
693 670
694 base::HistogramTester histogram_tester; 671 base::HistogramTester histogram_tester;
695 JourneyLogger logger(/*is_incognito=*/true, /*url=*/GURL(test_url), 672 JourneyLogger logger(/*is_incognito=*/true, /*url=*/GURL(test_url),
696 /*ukm_recorder=*/&ukm_recorder); 673 /*ukm_recorder=*/&ukm_recorder);
697 674
698 // Simulate that the user aborts after being shown the Payment Request and 675 // Simulate that the user aborts after being shown the Payment Request and
699 // clicking pay. 676 // clicking pay.
700 logger.SetEventOccurred(JourneyLogger::EVENT_SHOWN); 677 logger.SetEventOccurred(JourneyLogger::EVENT_SHOWN);
701 logger.SetEventOccurred(JourneyLogger::EVENT_PAY_CLICKED); 678 logger.SetEventOccurred(JourneyLogger::EVENT_PAY_CLICKED);
702 logger.RecordJourneyStatsHistograms( 679 logger.SetAborted(JourneyLogger::ABORT_REASON_ABORTED_BY_USER);
703 JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
704 680
705 // Make sure the UKM was logged correctly. 681 // Make sure the UKM was logged correctly.
706 ASSERT_EQ(1U, ukm_recorder.sources_count()); 682 ASSERT_EQ(1U, ukm_recorder.sources_count());
707 const ukm::UkmSource* source = ukm_recorder.GetSourceForUrl(test_url); 683 const ukm::UkmSource* source = ukm_recorder.GetSourceForUrl(test_url);
708 ASSERT_NE(nullptr, source); 684 ASSERT_NE(nullptr, source);
709 685
710 ASSERT_EQ(1U, ukm_recorder.entries_count()); 686 ASSERT_EQ(1U, ukm_recorder.entries_count());
711 const ukm::mojom::UkmEntry* entry = ukm_recorder.GetEntry(0); 687 const ukm::mojom::UkmEntry* entry = ukm_recorder.GetEntry(0);
712 EXPECT_EQ(source->id(), entry->source_id); 688 EXPECT_EQ(source->id(), entry->source_id);
713 EXPECT_EQ(base::HashMetricName(internal::kUKMCheckoutEventsEntryName), 689 EXPECT_EQ(base::HashMetricName(internal::kUKMCheckoutEventsEntryName),
714 entry->event_hash); 690 entry->event_hash);
715 691
716 const ukm::mojom::UkmMetric* status_metric = ukm::TestUkmRecorder::FindMetric( 692 const ukm::mojom::UkmMetric* status_metric = ukm::TestUkmRecorder::FindMetric(
717 entry, internal::kUKMCompletionStatusMetricName); 693 entry, internal::kUKMCompletionStatusMetricName);
718 ASSERT_NE(nullptr, status_metric); 694 ASSERT_NE(nullptr, status_metric);
719 EXPECT_EQ(JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 695 EXPECT_EQ(JourneyLogger::COMPLETION_STATUS_USER_ABORTED,
720 status_metric->value); 696 status_metric->value);
721 697
722 const ukm::mojom::UkmMetric* step_metric = 698 const ukm::mojom::UkmMetric* step_metric =
723 ukm::TestUkmRecorder::FindMetric(entry, internal::kUKMEventsMetricName); 699 ukm::TestUkmRecorder::FindMetric(entry, internal::kUKMEventsMetricName);
724 ASSERT_NE(nullptr, step_metric); 700 ASSERT_NE(nullptr, step_metric);
725 EXPECT_EQ(JourneyLogger::EVENT_SHOWN | JourneyLogger::EVENT_PAY_CLICKED, 701 EXPECT_EQ(JourneyLogger::EVENT_SHOWN | JourneyLogger::EVENT_PAY_CLICKED,
726 step_metric->value); 702 step_metric->value);
727 } 703 }
728 704
729 } // namespace payments 705 } // 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