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