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