| 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" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 logger.SetCanMakePaymentValue(false); | 142 logger.SetCanMakePaymentValue(false); |
| 143 logger.SetAborted(JourneyLogger::ABORT_REASON_OTHER); | 143 logger.SetAborted(JourneyLogger::ABORT_REASON_OTHER); |
| 144 | 144 |
| 145 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", | 145 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 146 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); | 146 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
| 147 | 147 |
| 148 // 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 |
| 149 // shown. | 149 // shown. |
| 150 histogram_tester.ExpectBucketCount( | 150 histogram_tester.ExpectBucketCount( |
| 151 "PaymentRequest.CanMakePayment.Used.EffectOnShow", | 151 "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
| 152 JourneyLogger::CMP_SHOW_COULD_NOT_MAKE_PAYMENT_AND_DID_NOT_SHOW, 1); | 152 JourneyLogger::CMP_EFFECT_ON_SHOW_COULD_NOT_MAKE_PAYMENT_AND_DID_NOT_SHOW, |
| 153 1); |
| 153 | 154 |
| 154 // There should be no completion stats since PR was not shown to the user. | 155 // There should be no completion stats since PR was not shown to the user. |
| 155 EXPECT_THAT( | 156 EXPECT_THAT( |
| 156 histogram_tester.GetTotalCountsForPrefix( | 157 histogram_tester.GetTotalCountsForPrefix( |
| 157 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion"), | 158 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion"), |
| 158 testing::ContainerEq(base::HistogramTester::CountsMap())); | 159 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 159 } | 160 } |
| 160 | 161 |
| 161 // Tests the canMakePayment stats for the case where the merchant uses it, | 162 // Tests the canMakePayment stats for the case where the merchant uses it, |
| 162 // returns true and show is not called. | 163 // returns true and show is not called. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 175 logger.SetCanMakePaymentValue(true); | 176 logger.SetCanMakePaymentValue(true); |
| 176 logger.SetAborted(JourneyLogger::ABORT_REASON_OTHER); | 177 logger.SetAborted(JourneyLogger::ABORT_REASON_OTHER); |
| 177 | 178 |
| 178 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", | 179 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 179 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); | 180 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
| 180 | 181 |
| 181 // The CanMakePayment effect on show should be recorded as being true and not | 182 // The CanMakePayment effect on show should be recorded as being true and not |
| 182 // shown. | 183 // shown. |
| 183 histogram_tester.ExpectBucketCount( | 184 histogram_tester.ExpectBucketCount( |
| 184 "PaymentRequest.CanMakePayment.Used.EffectOnShow", | 185 "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
| 185 JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT, 1); | 186 JourneyLogger::CMP_EFFECT_ON_SHOW_COULD_MAKE_PAYMENT, 1); |
| 186 | 187 |
| 187 // There should be no completion stats since PR was not shown to the user. | 188 // There should be no completion stats since PR was not shown to the user. |
| 188 EXPECT_THAT( | 189 EXPECT_THAT( |
| 189 histogram_tester.GetTotalCountsForPrefix( | 190 histogram_tester.GetTotalCountsForPrefix( |
| 190 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion"), | 191 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion"), |
| 191 testing::ContainerEq(base::HistogramTester::CountsMap())); | 192 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 192 } | 193 } |
| 193 | 194 |
| 194 // Tests the canMakePayment stats for the case where the merchant uses it, | 195 // Tests the canMakePayment stats for the case where the merchant uses it, |
| 195 // returns false, show is called but the transaction is aborted by the user. | 196 // returns false, show is called but the transaction is aborted by the user. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 209 logger.SetCanMakePaymentValue(false); | 210 logger.SetCanMakePaymentValue(false); |
| 210 logger.SetAborted(JourneyLogger::ABORT_REASON_ABORTED_BY_USER); | 211 logger.SetAborted(JourneyLogger::ABORT_REASON_ABORTED_BY_USER); |
| 211 | 212 |
| 212 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", | 213 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 213 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); | 214 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
| 214 | 215 |
| 215 // The CanMakePayment effect on show should be recorded as being false and | 216 // The CanMakePayment effect on show should be recorded as being false and |
| 216 // shown. | 217 // shown. |
| 217 histogram_tester.ExpectBucketCount( | 218 histogram_tester.ExpectBucketCount( |
| 218 "PaymentRequest.CanMakePayment.Used.EffectOnShow", | 219 "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
| 219 JourneyLogger::CMP_SHOW_DID_SHOW, 1); | 220 JourneyLogger::CMP_EFFECT_ON_SHOW_DID_SHOW, 1); |
| 220 // There should be a record for an abort when CanMakePayment is false but the | 221 // There should be a record for an abort when CanMakePayment is false but the |
| 221 // PR is shown to the user. | 222 // PR is shown to the user. |
| 222 histogram_tester.ExpectBucketCount( | 223 histogram_tester.ExpectBucketCount( |
| 223 "PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion", | 224 "PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion", |
| 224 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); | 225 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); |
| 225 } | 226 } |
| 226 | 227 |
| 227 // Tests the canMakePayment stats for the case where the merchant uses it, | 228 // Tests the canMakePayment stats for the case where the merchant uses it, |
| 228 // returns false, show is called but the transaction is aborted. | 229 // returns false, show is called but the transaction is aborted. |
| 229 TEST(JourneyLoggerTest, | 230 TEST(JourneyLoggerTest, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 242 logger.SetCanMakePaymentValue(false); | 243 logger.SetCanMakePaymentValue(false); |
| 243 logger.SetAborted(JourneyLogger::ABORT_REASON_OTHER); | 244 logger.SetAborted(JourneyLogger::ABORT_REASON_OTHER); |
| 244 | 245 |
| 245 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", | 246 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 246 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); | 247 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
| 247 | 248 |
| 248 // The CanMakePayment effect on show should be recorded as being false and | 249 // The CanMakePayment effect on show should be recorded as being false and |
| 249 // shown. | 250 // shown. |
| 250 histogram_tester.ExpectBucketCount( | 251 histogram_tester.ExpectBucketCount( |
| 251 "PaymentRequest.CanMakePayment.Used.EffectOnShow", | 252 "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
| 252 JourneyLogger::CMP_SHOW_DID_SHOW, 1); | 253 JourneyLogger::CMP_EFFECT_ON_SHOW_DID_SHOW, 1); |
| 253 // There should be a record for an abort when CanMakePayment is false but the | 254 // There should be a record for an abort when CanMakePayment is false but the |
| 254 // PR is shown to the user. | 255 // PR is shown to the user. |
| 255 histogram_tester.ExpectBucketCount( | 256 histogram_tester.ExpectBucketCount( |
| 256 "PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion", | 257 "PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion", |
| 257 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1); | 258 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1); |
| 258 } | 259 } |
| 259 | 260 |
| 260 // Tests the canMakePayment stats for the case where the merchant uses it, | 261 // Tests the canMakePayment stats for the case where the merchant uses it, |
| 261 // returns false, show is called and the transaction is completed. | 262 // returns false, show is called and the transaction is completed. |
| 262 TEST(JourneyLoggerTest, | 263 TEST(JourneyLoggerTest, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 275 logger.SetCanMakePaymentValue(false); | 276 logger.SetCanMakePaymentValue(false); |
| 276 logger.SetCompleted(); | 277 logger.SetCompleted(); |
| 277 | 278 |
| 278 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", | 279 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 279 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); | 280 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
| 280 | 281 |
| 281 // The CanMakePayment effect on show should be recorded as being false and | 282 // The CanMakePayment effect on show should be recorded as being false and |
| 282 // shown. | 283 // shown. |
| 283 histogram_tester.ExpectBucketCount( | 284 histogram_tester.ExpectBucketCount( |
| 284 "PaymentRequest.CanMakePayment.Used.EffectOnShow", | 285 "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
| 285 JourneyLogger::CMP_SHOW_DID_SHOW, 1); | 286 JourneyLogger::CMP_EFFECT_ON_SHOW_DID_SHOW, 1); |
| 286 | 287 |
| 287 // There should be a record for an completion when CanMakePayment is false but | 288 // There should be a record for an completion when CanMakePayment is false but |
| 288 // the PR is shown to the user. | 289 // the PR is shown to the user. |
| 289 histogram_tester.ExpectBucketCount( | 290 histogram_tester.ExpectBucketCount( |
| 290 "PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion", | 291 "PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion", |
| 291 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); | 292 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); |
| 292 } | 293 } |
| 293 | 294 |
| 294 // Tests the canMakePayment stats for the case where the merchant uses it, | 295 // Tests the canMakePayment stats for the case where the merchant uses it, |
| 295 // returns true, show is called but the transaction is aborted by the user. | 296 // returns true, show is called but the transaction is aborted by the user. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 309 logger.SetCanMakePaymentValue(true); | 310 logger.SetCanMakePaymentValue(true); |
| 310 logger.SetAborted(JourneyLogger::ABORT_REASON_ABORTED_BY_USER); | 311 logger.SetAborted(JourneyLogger::ABORT_REASON_ABORTED_BY_USER); |
| 311 | 312 |
| 312 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", | 313 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 313 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); | 314 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
| 314 | 315 |
| 315 // The CanMakePayment effect on show should be recorded as being true and not | 316 // The CanMakePayment effect on show should be recorded as being true and not |
| 316 // shown. | 317 // shown. |
| 317 histogram_tester.ExpectBucketCount( | 318 histogram_tester.ExpectBucketCount( |
| 318 "PaymentRequest.CanMakePayment.Used.EffectOnShow", | 319 "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
| 319 JourneyLogger::CMP_SHOW_DID_SHOW | | 320 JourneyLogger::CMP_EFFECT_ON_SHOW_DID_SHOW | |
| 320 JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT, | 321 JourneyLogger::CMP_EFFECT_ON_SHOW_COULD_MAKE_PAYMENT, |
| 321 1); | 322 1); |
| 322 // There should be a record for an abort when CanMakePayment is true and the | 323 // There should be a record for an abort when CanMakePayment is true and the |
| 323 // PR is shown to the user. | 324 // PR is shown to the user. |
| 324 histogram_tester.ExpectBucketCount( | 325 histogram_tester.ExpectBucketCount( |
| 325 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion", | 326 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion", |
| 326 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); | 327 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); |
| 327 } | 328 } |
| 328 | 329 |
| 329 // Tests the canMakePayment stats for the case where the merchant uses it, | 330 // Tests the canMakePayment stats for the case where the merchant uses it, |
| 330 // returns true, show is called but the transaction is aborted. | 331 // returns true, show is called but the transaction is aborted. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 344 logger.SetCanMakePaymentValue(true); | 345 logger.SetCanMakePaymentValue(true); |
| 345 logger.SetAborted(JourneyLogger::ABORT_REASON_OTHER); | 346 logger.SetAborted(JourneyLogger::ABORT_REASON_OTHER); |
| 346 | 347 |
| 347 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", | 348 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 348 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); | 349 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
| 349 | 350 |
| 350 // The CanMakePayment effect on show should be recorded as being true and not | 351 // The CanMakePayment effect on show should be recorded as being true and not |
| 351 // shown. | 352 // shown. |
| 352 histogram_tester.ExpectBucketCount( | 353 histogram_tester.ExpectBucketCount( |
| 353 "PaymentRequest.CanMakePayment.Used.EffectOnShow", | 354 "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
| 354 JourneyLogger::CMP_SHOW_DID_SHOW | | 355 JourneyLogger::CMP_EFFECT_ON_SHOW_DID_SHOW | |
| 355 JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT, | 356 JourneyLogger::CMP_EFFECT_ON_SHOW_COULD_MAKE_PAYMENT, |
| 356 1); | 357 1); |
| 357 // There should be a record for an abort when CanMakePayment is true and the | 358 // There should be a record for an abort when CanMakePayment is true and the |
| 358 // PR is shown to the user. | 359 // PR is shown to the user. |
| 359 histogram_tester.ExpectBucketCount( | 360 histogram_tester.ExpectBucketCount( |
| 360 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion", | 361 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion", |
| 361 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1); | 362 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1); |
| 362 } | 363 } |
| 363 | 364 |
| 364 // Tests the canMakePayment stats for the case where the merchant uses it, | 365 // Tests the canMakePayment stats for the case where the merchant uses it, |
| 365 // returns true, show is called and the transaction is completed. | 366 // returns true, show is called and the transaction is completed. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 379 logger.SetCanMakePaymentValue(true); | 380 logger.SetCanMakePaymentValue(true); |
| 380 logger.SetCompleted(); | 381 logger.SetCompleted(); |
| 381 | 382 |
| 382 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", | 383 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 383 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); | 384 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
| 384 | 385 |
| 385 // The CanMakePayment effect on show should be recorded as being true and not | 386 // The CanMakePayment effect on show should be recorded as being true and not |
| 386 // shown. | 387 // shown. |
| 387 histogram_tester.ExpectBucketCount( | 388 histogram_tester.ExpectBucketCount( |
| 388 "PaymentRequest.CanMakePayment.Used.EffectOnShow", | 389 "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
| 389 JourneyLogger::CMP_SHOW_DID_SHOW | | 390 JourneyLogger::CMP_EFFECT_ON_SHOW_DID_SHOW | |
| 390 JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT, | 391 JourneyLogger::CMP_EFFECT_ON_SHOW_COULD_MAKE_PAYMENT, |
| 391 1); | 392 1); |
| 392 // There should be a record for a completion when CanMakePayment is true and | 393 // There should be a record for a completion when CanMakePayment is true and |
| 393 // the PR is shown to the user. | 394 // the PR is shown to the user. |
| 394 histogram_tester.ExpectBucketCount( | 395 histogram_tester.ExpectBucketCount( |
| 395 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion", | 396 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion", |
| 396 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); | 397 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); |
| 397 } | 398 } |
| 398 | 399 |
| 399 // Tests the canMakePayment metrics are not logged if the Payment Request was | 400 // Tests the canMakePayment metrics are not logged if the Payment Request was |
| 400 // done in an incognito tab. | 401 // done in an incognito tab. |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 status_metric->value); | 697 status_metric->value); |
| 697 | 698 |
| 698 const ukm::mojom::UkmMetric* step_metric = | 699 const ukm::mojom::UkmMetric* step_metric = |
| 699 ukm::TestUkmRecorder::FindMetric(entry, internal::kUKMEventsMetricName); | 700 ukm::TestUkmRecorder::FindMetric(entry, internal::kUKMEventsMetricName); |
| 700 ASSERT_NE(nullptr, step_metric); | 701 ASSERT_NE(nullptr, step_metric); |
| 701 EXPECT_EQ(JourneyLogger::EVENT_SHOWN | JourneyLogger::EVENT_PAY_CLICKED, | 702 EXPECT_EQ(JourneyLogger::EVENT_SHOWN | JourneyLogger::EVENT_PAY_CLICKED, |
| 702 step_metric->value); | 703 step_metric->value); |
| 703 } | 704 } |
| 704 | 705 |
| 705 } // namespace payments | 706 } // namespace payments |
| OLD | NEW |