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