Commit 24d1d608 authored by sebsg's avatar sebsg Committed by Commit bot

[Payments] Move JourneyLogger unit tests from Java to C++.

BUG=709529

TBR=rouslan@chromium.org

Review-Url: https://codereview.chromium.org/2805913002
Cr-Commit-Position: refs/heads/master@{#462983}
parent 333a6242
......@@ -1463,7 +1463,6 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/payments/PaymentRequestIncompletePhoneTest.java",
"javatests/src/org/chromium/chrome/browser/payments/PaymentRequestIncompleteServerCardTest.java",
"javatests/src/org/chromium/chrome/browser/payments/PaymentRequestJourneyLoggerTest.java",
"javatests/src/org/chromium/chrome/browser/payments/PaymentRequestJourneyLoggerUnitTest.java",
"javatests/src/org/chromium/chrome/browser/payments/PaymentRequestMetricsUnitTest.java",
"javatests/src/org/chromium/chrome/browser/payments/PaymentRequestMultipleContactDetailsTest.java",
"javatests/src/org/chromium/chrome/browser/payments/PaymentRequestMetricsTest.java",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.payments;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.test.util.ApplicationData;
import org.chromium.components.payments.JourneyLogger;
import org.chromium.content.browser.test.NativeLibraryTestRule;
/**
* Tests for the PaymentRequestJourneyLogger class.
*/
@RunWith(BaseJUnit4ClassRunner.class)
public class PaymentRequestJourneyLoggerUnitTest {
@Rule
public NativeLibraryTestRule mNativeLibraryTestRule = new NativeLibraryTestRule();
@Before
public void setUp() throws Exception {
ApplicationData.clearAppData(
InstrumentationRegistry.getInstrumentation().getTargetContext());
mNativeLibraryTestRule.loadNativeLibraryAndInitBrowserProcess();
}
/**
* Tests the canMakePayment stats for the case where the merchant does not use it and does not
* show the PaymentRequest to the user.
*/
@Test
@SmallTest
@Feature({"Payments"})
public void testRecordJourneyStatsHistograms_CanMakePaymentNotCalled_NoShow() {
JourneyLogger logger = new JourneyLogger(false /* is_incognito */);
assertNoLogForCanMakePayment();
logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_USER_ABORTED);
// CanMakePayment was not used.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Usage",
JourneyLogger.CAN_MAKE_PAYMENT_NOT_USED));
// There should be no completion stats since PR was not shown to the user
Assert.assertEquals(0,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_USER_ABORTED));
Assert.assertEquals(0,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_COMPLETED));
}
/**
* Tests the canMakePayment stats for the case where the merchant does not use it and the
* transaction is aborted.
*/
@Test
@SmallTest
@Feature({"Payments"})
public void testRecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndUserAbort() {
JourneyLogger logger = new JourneyLogger(false /* is_incognito */);
assertNoLogForCanMakePayment();
// The merchant does not query CanMakePayment, show the PaymentRequest and the user
// aborts it.
logger.setShowCalled();
logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_USER_ABORTED);
// CanMakePayment was not used.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Usage",
JourneyLogger.CAN_MAKE_PAYMENT_NOT_USED));
// There should be a record for an abort when CanMakePayment is not used but the PR is shown
// to the user.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_USER_ABORTED));
}
/**
* Tests the canMakePayment stats for the case where the merchant does not use it and the
* transaction is aborted.
*/
@Test
@SmallTest
@Feature({"Payments"})
public void testRecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndOtherAbort() {
JourneyLogger logger = new JourneyLogger(false /* is_incognito */);
assertNoLogForCanMakePayment();
// The merchant does not query CanMakePayment, show the PaymentRequest and the user
// aborts it.
logger.setShowCalled();
logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED);
// CanMakePayment was not used.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Usage",
JourneyLogger.CAN_MAKE_PAYMENT_NOT_USED));
// There should be a record for an abort when CanMakePayment is not used but the PR is shown
// to the user.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED));
}
/**
* Tests the canMakePayment stats for the case where the merchant does not use it and the
* transaction is completed.
*/
@Test
@SmallTest
@Feature({"Payments"})
public void testRecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndComplete() {
JourneyLogger logger = new JourneyLogger(false /* is_incognito */);
assertNoLogForCanMakePayment();
// The merchant does not query CanMakePayment, show the PaymentRequest and the user
// completes it.
logger.setShowCalled();
logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_COMPLETED);
// CanMakePayment was not used.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Usage",
JourneyLogger.CAN_MAKE_PAYMENT_NOT_USED));
// There should be a record for a completion when CanMakePayment is not used but the PR is
// shown to the user.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_COMPLETED));
}
/**
* Tests the canMakePayment stats for the case where the merchant uses it, returns false and
* show is not called.
*/
@Test
@SmallTest
@Feature({"Payments"})
public void testRecordJourneyStatsHistograms_CanMakePaymentCalled_FalseAndNoShow() {
JourneyLogger logger = new JourneyLogger(false /* is_incognito */);
assertNoLogForCanMakePayment();
// The user cannot make payment and the PaymentRequest is not shown.
logger.setCanMakePaymentValue(false);
logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED);
// CanMakePayment was used.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Usage",
JourneyLogger.CAN_MAKE_PAYMENT_USED));
// The CanMakePayment effect on show should be recorded as being false and not shown.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Used.EffectOnShow",
JourneyLogger.CMP_SHOW_COULD_NOT_MAKE_PAYMENT_AND_DID_NOT_SHOW));
// There should be no completion stats since PR was not shown to the user.
Assert.assertEquals(0,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED));
Assert.assertEquals(0,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_COMPLETED));
}
/**
* Tests the canMakePayment stats for the case where the merchant uses it, returns true and
* show is not called.
*/
@Test
@SmallTest
@Feature({"Payments"})
public void testRecordJourneyStatsHistograms_CanMakePaymentCalled_TrueAndNoShow() {
JourneyLogger logger = new JourneyLogger(false /* is_incognito */);
assertNoLogForCanMakePayment();
// The user can make a payment but the Payment Request is not shown.
logger.setCanMakePaymentValue(true);
logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED);
// CanMakePayment was used.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Usage",
JourneyLogger.CAN_MAKE_PAYMENT_USED));
// The CanMakePayment effect on show should be recorded as being true and not shown.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Used.EffectOnShow",
JourneyLogger.CMP_SHOW_COULD_MAKE_PAYMENT));
// There should be no completion stats since PR was not shown to the user.
Assert.assertEquals(0,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED));
Assert.assertEquals(0,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_COMPLETED));
}
/**
* Tests the canMakePayment stats for the case where the merchant uses it, returns false, show
* is called but the transaction is aborted by the user.
*/
@Test
@SmallTest
@Feature({"Payments"})
public void testRecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowAndUserAbort() {
JourneyLogger logger = new JourneyLogger(false /* is_incognito */);
assertNoLogForCanMakePayment();
// The user cannot make a payment. the payment request is shown but aborted.
logger.setShowCalled();
logger.setCanMakePaymentValue(false);
logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_USER_ABORTED);
// CanMakePayment was used.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Usage",
JourneyLogger.CAN_MAKE_PAYMENT_USED));
// The CanMakePayment effect on show should be recorded as being true and not shown.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Used.EffectOnShow",
JourneyLogger.CMP_SHOW_DID_SHOW));
// There should be a record for an abort when CanMakePayment is false but the PR is shown to
// the user.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_USER_ABORTED));
}
/**
* Tests the canMakePayment stats for the case where the merchant uses it, returns false, show
* is called but the transaction is aborted.
*/
@Test
@SmallTest
@Feature({"Payments"})
public void testRecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowAndOtherAbort() {
JourneyLogger logger = new JourneyLogger(false /* is_incognito */);
assertNoLogForCanMakePayment();
// The user cannot make a payment. the payment request is shown but aborted.
logger.setShowCalled();
logger.setCanMakePaymentValue(false);
logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED);
// CanMakePayment was used.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Usage",
JourneyLogger.CAN_MAKE_PAYMENT_USED));
// The CanMakePayment effect on show should be recorded as being true and not shown.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Used.EffectOnShow",
JourneyLogger.CMP_SHOW_DID_SHOW));
// There should be a record for an abort when CanMakePayment is false but the PR is shown to
// the user.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED));
}
/**
* Tests the canMakePayment stats for the case where the merchant uses it, returns false,
* show is called and the transaction is completed.
*/
@Test
@SmallTest
@Feature({"Payments"})
public void testRecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowAndComplete() {
JourneyLogger logger = new JourneyLogger(false /* is_incognito */);
assertNoLogForCanMakePayment();
// The user cannot make a payment. the payment request is shown and completed.
logger.setShowCalled();
logger.setCanMakePaymentValue(false);
logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_COMPLETED);
// CanMakePayment was used.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Usage",
JourneyLogger.CAN_MAKE_PAYMENT_USED));
// The CanMakePayment effect on show should be recorded as being true and not shown.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Used.EffectOnShow",
JourneyLogger.CMP_SHOW_DID_SHOW));
// There should be a record for a completion when CanMakePayment is false and the PR is
// shown to the user.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_COMPLETED));
}
/**
* Tests the canMakePayment stats for the case where the merchant uses it, returns true, show
* is called but the transaction is aborted by the user.
*/
@Test
@SmallTest
@Feature({"Payments"})
public void testRecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAndUserAbort() {
JourneyLogger logger = new JourneyLogger(false /* is_incognito */);
assertNoLogForCanMakePayment();
// The user cannot make a payment. the payment request is shown and completed.
logger.setShowCalled();
logger.setCanMakePaymentValue(true);
logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_USER_ABORTED);
// CanMakePayment was used.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Usage",
JourneyLogger.CAN_MAKE_PAYMENT_USED));
// The CanMakePayment effect on show should be recorded as being true and not shown.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Used.EffectOnShow",
JourneyLogger.CMP_SHOW_DID_SHOW
| JourneyLogger.CMP_SHOW_COULD_MAKE_PAYMENT));
// There should be a record for an abort when CanMakePayment is true and the PR is shown to
// the user.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_USER_ABORTED));
}
/**
* Tests the canMakePayment stats for the case where the merchant uses it, returns true, show
* is called but the transaction is aborted.
*/
@Test
@SmallTest
@Feature({"Payments"})
public void testRecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAndOtherAbort() {
JourneyLogger logger = new JourneyLogger(false /* is_incognito */);
assertNoLogForCanMakePayment();
// The user cannot make a payment. the payment request is shown and completed.
logger.setShowCalled();
logger.setCanMakePaymentValue(true);
logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED);
// CanMakePayment was used.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Usage",
JourneyLogger.CAN_MAKE_PAYMENT_USED));
// The CanMakePayment effect on show should be recorded as being true and not shown.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Used.EffectOnShow",
JourneyLogger.CMP_SHOW_DID_SHOW
| JourneyLogger.CMP_SHOW_COULD_MAKE_PAYMENT));
// There should be a record for an abort when CanMakePayment is true and the PR is shown to
// the user.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED));
}
/**
* Tests the canMakePayment stats for the case where the merchant uses it, returns true, show
* is called and the transaction is completed.
*/
@Test
@SmallTest
@Feature({"Payments"})
public void testRecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAndComplete() {
JourneyLogger logger = new JourneyLogger(false /* is_incognito */);
assertNoLogForCanMakePayment();
// The user cannot make a payment. the payment request is shown and completed.
logger.setShowCalled();
logger.setCanMakePaymentValue(true);
logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_COMPLETED);
// CanMakePayment was used.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Usage",
JourneyLogger.CAN_MAKE_PAYMENT_USED));
// The CanMakePayment effect on show should be recorded as being true and not shown.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Used.EffectOnShow",
JourneyLogger.CMP_SHOW_DID_SHOW
| JourneyLogger.CMP_SHOW_COULD_MAKE_PAYMENT));
// There should be a record for a completion when CanMakePayment is true and the PR is shown
// to the user.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_COMPLETED));
}
/**
* Tests the canMakePayment metrics are not logged if the Payment Request was done in an
* incognito tab.
*/
@Test
@SmallTest
@Feature({"Payments"})
public void testRecordJourneyStatsHistograms_CanMakePayment_IncognitoTab() {
JourneyLogger logger = new JourneyLogger(true /* is_incognito */);
assertNoLogForCanMakePayment();
// The user is in an incognito tab so CanMakePayment is always true;
logger.setShowCalled();
logger.setCanMakePaymentValue(true);
logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_COMPLETED);
// There should be no CanMakePayment metrics logged.
assertNoLogForCanMakePayment();
}
/**
* Tests that the completion status metrics based on whether the user had suggestions for all
* the requested sections are logged as correctly.
*/
@Test
@SmallTest
@Feature({"Payments"})
public void testRecordJourneyStatsHistograms_SuggestionsForEverything_Completed() {
JourneyLogger logger = new JourneyLogger(false /* is_incognito */);
// Simulate that the user had suggestions for all the requested sections.
logger.setNumberOfSuggestionsShown(JourneyLogger.SECTION_CREDIT_CARDS, 1);
// Simulate that the user completes the checkout.
logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_COMPLETED);
// Make sure the appropriate metric was logged.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_COMPLETED));
Assert.assertEquals(0,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.UserDidNotHaveSuggestionsForEverything.EffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_COMPLETED));
}
/**
* Tests that the completion status metrics based on whether the user had suggestions for all
* the requested sections are logged as correctly.
*/
@Test
@SmallTest
@Feature({"Payments"})
public void testRecordJourneyStatsHistograms_SuggestionsForEverything_UserAborted() {
JourneyLogger logger = new JourneyLogger(false /* is_incognito */);
// Simulate that the user had suggestions for all the requested sections.
logger.setNumberOfSuggestionsShown(JourneyLogger.SECTION_CREDIT_CARDS, 1);
// Simulate that the user aborts the checkout.
logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_USER_ABORTED);
// Make sure the appropriate metric was logged.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_USER_ABORTED));
Assert.assertEquals(0,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.UserDidNotHaveSuggestionsForEverything.EffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_USER_ABORTED));
}
/**
* Tests that the completion status metrics based on whether the user had suggestions for all
* the requested sections are logged as correctly.
*/
@Test
@SmallTest
@Feature({"Payments"})
public void testRecordJourneyStatsHistograms_SuggestionsForEverything_OtherAborted() {
JourneyLogger logger = new JourneyLogger(false /* is_incognito */);
// Simulate that the user had suggestions for all the requested sections.
logger.setNumberOfSuggestionsShown(JourneyLogger.SECTION_CREDIT_CARDS, 1);
// Simulate that the user aborts the checkout.
logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED);
// Make sure the appropriate metric was logged.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED));
Assert.assertEquals(0,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.UserDidNotHaveSuggestionsForEverything.EffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED));
}
/**
* Tests that the completion status metrics based on whether the user had suggestions for all
* the requested sections are logged as correctly.
*/
@Test
@SmallTest
@Feature({"Payments"})
public void testRecordJourneyStatsHistograms_NoSuggestionsForEverything_Completed() {
JourneyLogger logger = new JourneyLogger(false /* is_incognito */);
// Simulate that the user did not have suggestions for all the requested sections.
logger.setNumberOfSuggestionsShown(JourneyLogger.SECTION_CREDIT_CARDS, 0);
// Simulate that the user completes the checkout.
logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_COMPLETED);
// Make sure the appropriate metric was logged.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.UserDidNotHaveSuggestionsForEverything.EffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_COMPLETED));
Assert.assertEquals(0,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_COMPLETED));
}
/**
* Tests that the completion status metrics based on whether the user had suggestions for all
* the requested sections are logged as correctly.
*/
@Test
@SmallTest
@Feature({"Payments"})
public void testRecordJourneyStatsHistograms_NoSuggestionsForEverything_UserAborted() {
JourneyLogger logger = new JourneyLogger(false /* is_incognito */);
// Simulate that the user did not have suggestions for all the requested sections.
logger.setNumberOfSuggestionsShown(JourneyLogger.SECTION_CREDIT_CARDS, 0);
// Simulate that the user aborts the checkout.
logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_USER_ABORTED);
// Make sure the appropriate metric was logged.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.UserDidNotHaveSuggestionsForEverything.EffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_USER_ABORTED));
Assert.assertEquals(0,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_USER_ABORTED));
}
/**
* Tests that the completion status metrics based on whether the user had suggestions for all
* the requested sections are logged as correctly.
*/
@Test
@SmallTest
@Feature({"Payments"})
public void testRecordJourneyStatsHistograms_NoSuggestionsForEverything_OtherAborted() {
JourneyLogger logger = new JourneyLogger(false /* is_incognito */);
// Simulate that the user did not have suggestions for all the requested sections.
logger.setNumberOfSuggestionsShown(JourneyLogger.SECTION_CREDIT_CARDS, 0);
// Simulate that the user aborts the checkout.
logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED);
// Make sure the appropriate metric was logged.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.UserDidNotHaveSuggestionsForEverything.EffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED));
Assert.assertEquals(0,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED));
}
/**
* Tests that the metrics are logged correctly for two simultaneous Payment Requests.
*/
@Test
@SmallTest
@Feature({"Payments"})
public void testRecordJourneyStatsHistograms_TwoPaymentRequests() {
JourneyLogger logger1 = new JourneyLogger(false /* is_incognito */);
JourneyLogger logger2 = new JourneyLogger(false /* is_incognito */);
// Make the two loggers have different data.
logger1.setShowCalled();
logger2.setShowCalled();
logger1.setCanMakePaymentValue(true);
logger1.setNumberOfSuggestionsShown(JourneyLogger.SECTION_CREDIT_CARDS, 1);
logger2.setNumberOfSuggestionsShown(JourneyLogger.SECTION_CREDIT_CARDS, 0);
// Simulate that the user completes one checkout and aborts the other.
logger1.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_COMPLETED);
logger2.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_USER_ABORTED);
// Make sure the appropriate metric was logged for logger1.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_COMPLETED));
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Usage",
JourneyLogger.CAN_MAKE_PAYMENT_USED));
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_COMPLETED));
// Make sure the appropriate metric was logged for logger2.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.UserDidNotHaveSuggestionsForEverything.EffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_USER_ABORTED));
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Usage",
JourneyLogger.CAN_MAKE_PAYMENT_NOT_USED));
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
JourneyLogger.COMPLETION_STATUS_USER_ABORTED));
}
/**
* Asserts that no histogram is logged.
*/
private void assertNoLogForCanMakePayment() {
// Use stats.
for (int i = 0; i < JourneyLogger.CAN_MAKE_PAYMENT_USE_MAX; ++i) {
Assert.assertEquals(0,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Usage", i));
}
// Effect on show stats.
for (int i = 0; i < JourneyLogger.CMP_SHOW_MAX; ++i) {
Assert.assertEquals(0,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Used.EffectOnShow", i));
}
// Effect on completion stats.
for (int i = 0; i < JourneyLogger.COMPLETION_STATUS_MAX; ++i) {
Assert.assertEquals(0,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion", i));
Assert.assertEquals(0,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion",
i));
Assert.assertEquals(0,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion",
i));
}
}
}
......@@ -49,6 +49,7 @@ source_set("unit_tests") {
"address_normalizer_unittest.cc",
"basic_card_response_unittest.cc",
"currency_formatter_unittest.cc",
"journey_logger_unittest.cc",
"payment_address_unittest.cc",
"payment_method_data_unittest.cc",
"payment_request_data_util_unittest.cc",
......@@ -61,6 +62,7 @@ source_set("unit_tests") {
"//base/test:test_support",
"//components/autofill/core/browser",
"//components/autofill/core/browser:test_support",
"//testing/gmock",
"//testing/gtest",
"//third_party/libaddressinput:test_support",
]
......
......@@ -175,7 +175,7 @@ void JourneyLogger::RecordCanMakePaymentEffectOnShow() {
if (was_show_called_)
effect_on_show |= CMP_SHOW_DID_SHOW;
if (could_make_payment_)
effect_on_show |= CMP_SHOW_COULD_MAKE_PAYMENT_;
effect_on_show |= CMP_SHOW_COULD_MAKE_PAYMENT;
UMA_HISTOGRAM_ENUMERATION("PaymentRequest.CanMakePayment.Used.EffectOnShow",
effect_on_show, CMP_SHOW_MAX);
......
......@@ -50,7 +50,7 @@ class JourneyLogger {
// Payment Request is shown to the user.
static const int CMP_SHOW_COULD_NOT_MAKE_PAYMENT_AND_DID_NOT_SHOW = 0;
static const int CMP_SHOW_DID_SHOW = 1 << 0;
static const int CMP_SHOW_COULD_MAKE_PAYMENT_ = 1 << 1;
static const int CMP_SHOW_COULD_MAKE_PAYMENT = 1 << 1;
static const int CMP_SHOW_MAX = 4;
explicit JourneyLogger(bool is_incognito);
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/payments/core/journey_logger.h"
#include "base/test/histogram_tester.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using testing::ContainerEq;
namespace payments {
// Tests the canMakePayment stats for the case where the merchant does not use
// it and does not show the PaymentRequest to the user.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_CanMakePaymentNotCalled_NoShow) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/false);
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_COMPLETED);
histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED,
1);
// There should be no completion stats since PR was not shown to the user
EXPECT_THAT(
histogram_tester.GetTotalCountsForPrefix(
"PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
}
// Tests the canMakePayment stats for the case where the merchant does not use
// it and the transaction is aborted.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndUserAbort) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/false);
// Expect no log for CanMakePayment.
EXPECT_THAT(
histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
// The merchant does not query CanMakePayment, show the PaymentRequest and the
// user aborts it.
logger.SetShowCalled();
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED,
1);
// There should be a record for an abort when CanMakePayment is not used but
// the PR is shown to the user.
histogram_tester.ExpectBucketCount(
"PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1);
}
// Tests the canMakePayment stats for the case where the merchant does not use
// it and the transaction is aborted.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndOtherAbort) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/false);
// Expect no log for CanMakePayment.
EXPECT_THAT(
histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
// The merchant does not query CanMakePayment, show the PaymentRequest and
// there is an abort not initiated by the user.
logger.SetShowCalled();
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED,
1);
// There should be a record for an abort when CanMakePayment is not used but
// the PR is shown to the user.
histogram_tester.ExpectBucketCount(
"PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1);
}
// Tests the canMakePayment stats for the case where the merchant does not use
// it and the transaction is completed.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndComplete) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/false);
// Expect no log for CanMakePayment.
EXPECT_THAT(
histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
// The merchant does not query CanMakePayment, show the PaymentRequest and the
// user completes it.
logger.SetShowCalled();
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_COMPLETED);
histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED,
1);
// There should be a record for an abort when CanMakePayment is not used but
// the PR is shown to the user.
histogram_tester.ExpectBucketCount(
"PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
}
// Tests the canMakePayment stats for the case where the merchant uses it,
// returns false and show is not called.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseAndNoShow) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/false);
// Expect no log for CanMakePayment.
EXPECT_THAT(
histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
// The user cannot make payment and the PaymentRequest is not shown.
logger.SetCanMakePaymentValue(false);
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
// The CanMakePayment effect on show should be recorded as being false and not
// shown.
histogram_tester.ExpectBucketCount(
"PaymentRequest.CanMakePayment.Used.EffectOnShow",
JourneyLogger::CMP_SHOW_COULD_NOT_MAKE_PAYMENT_AND_DID_NOT_SHOW, 1);
// There should be no completion stats since PR was not shown to the user.
EXPECT_THAT(
histogram_tester.GetTotalCountsForPrefix(
"PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
}
// Tests the canMakePayment stats for the case where the merchant uses it,
// returns true and show is not called.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_CanMakePaymentCalled_TrueAndNoShow) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/false);
// Expect no log for CanMakePayment.
EXPECT_THAT(
histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
// The user cannot make payment and the PaymentRequest is not shown.
logger.SetCanMakePaymentValue(true);
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
// The CanMakePayment effect on show should be recorded as being true and not
// shown.
histogram_tester.ExpectBucketCount(
"PaymentRequest.CanMakePayment.Used.EffectOnShow",
JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT, 1);
// There should be no completion stats since PR was not shown to the user.
EXPECT_THAT(
histogram_tester.GetTotalCountsForPrefix(
"PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
}
// Tests the canMakePayment stats for the case where the merchant uses it,
// returns false, show is called but the transaction is aborted by the user.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowAndUserAbort) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/false);
// Expect no log for CanMakePayment.
EXPECT_THAT(
histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
// The user cannot make payment and the PaymentRequest is not shown.
logger.SetShowCalled();
logger.SetCanMakePaymentValue(false);
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
// The CanMakePayment effect on show should be recorded as being false and
// shown.
histogram_tester.ExpectBucketCount(
"PaymentRequest.CanMakePayment.Used.EffectOnShow",
JourneyLogger::CMP_SHOW_DID_SHOW, 1);
// There should be a record for an abort when CanMakePayment is false but the
// PR is shown to the user.
histogram_tester.ExpectBucketCount(
"PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1);
}
// Tests the canMakePayment stats for the case where the merchant uses it,
// returns false, show is called but the transaction is aborted.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowAndOtherAbort) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/false);
// Expect no log for CanMakePayment.
EXPECT_THAT(
histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
// The user cannot make payment and the PaymentRequest is not shown.
logger.SetShowCalled();
logger.SetCanMakePaymentValue(false);
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
// The CanMakePayment effect on show should be recorded as being false and
// shown.
histogram_tester.ExpectBucketCount(
"PaymentRequest.CanMakePayment.Used.EffectOnShow",
JourneyLogger::CMP_SHOW_DID_SHOW, 1);
// There should be a record for an abort when CanMakePayment is false but the
// PR is shown to the user.
histogram_tester.ExpectBucketCount(
"PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1);
}
// Tests the canMakePayment stats for the case where the merchant uses it,
// returns false, show is called and the transaction is completed.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowAndComplete) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/false);
// Expect no log for CanMakePayment.
EXPECT_THAT(
histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
// The user cannot make payment and the PaymentRequest is not shown.
logger.SetShowCalled();
logger.SetCanMakePaymentValue(false);
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_COMPLETED);
histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
// The CanMakePayment effect on show should be recorded as being false and
// shown.
histogram_tester.ExpectBucketCount(
"PaymentRequest.CanMakePayment.Used.EffectOnShow",
JourneyLogger::CMP_SHOW_DID_SHOW, 1);
// There should be a record for an completion when CanMakePayment is false but
// the PR is shown to the user.
histogram_tester.ExpectBucketCount(
"PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
}
// Tests the canMakePayment stats for the case where the merchant uses it,
// returns true, show is called but the transaction is aborted by the user.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAndUserAbort) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/false);
// Expect no log for CanMakePayment.
EXPECT_THAT(
histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
// The user cannot make payment and the PaymentRequest is not shown.
logger.SetShowCalled();
logger.SetCanMakePaymentValue(true);
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
// The CanMakePayment effect on show should be recorded as being true and not
// shown.
histogram_tester.ExpectBucketCount(
"PaymentRequest.CanMakePayment.Used.EffectOnShow",
JourneyLogger::CMP_SHOW_DID_SHOW |
JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT,
1);
// There should be a record for an abort when CanMakePayment is true and the
// PR is shown to the user.
histogram_tester.ExpectBucketCount(
"PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1);
}
// Tests the canMakePayment stats for the case where the merchant uses it,
// returns true, show is called but the transaction is aborted.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAndOtherAbort) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/false);
// Expect no log for CanMakePayment.
EXPECT_THAT(
histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
// The user cannot make payment and the PaymentRequest is not shown.
logger.SetShowCalled();
logger.SetCanMakePaymentValue(true);
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
// The CanMakePayment effect on show should be recorded as being true and not
// shown.
histogram_tester.ExpectBucketCount(
"PaymentRequest.CanMakePayment.Used.EffectOnShow",
JourneyLogger::CMP_SHOW_DID_SHOW |
JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT,
1);
// There should be a record for an abort when CanMakePayment is true and the
// PR is shown to the user.
histogram_tester.ExpectBucketCount(
"PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1);
}
// Tests the canMakePayment stats for the case where the merchant uses it,
// returns true, show is called and the transaction is completed.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAndComplete) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/false);
// Expect no log for CanMakePayment.
EXPECT_THAT(
histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
// The user cannot make payment and the PaymentRequest is not shown.
logger.SetShowCalled();
logger.SetCanMakePaymentValue(true);
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_COMPLETED);
histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
// The CanMakePayment effect on show should be recorded as being true and not
// shown.
histogram_tester.ExpectBucketCount(
"PaymentRequest.CanMakePayment.Used.EffectOnShow",
JourneyLogger::CMP_SHOW_DID_SHOW |
JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT,
1);
// There should be a record for a completion when CanMakePayment is true and
// the PR is shown to the user.
histogram_tester.ExpectBucketCount(
"PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
}
// Tests the canMakePayment metrics are not logged if the Payment Request was
// done in an incognito tab.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_CanMakePayment_IncognitoTab) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/true);
// Expect no log for CanMakePayment.
EXPECT_THAT(
histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
// The user cannot make payment and the PaymentRequest is not shown.
logger.SetShowCalled();
logger.SetCanMakePaymentValue(true);
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_COMPLETED);
// Expect no log for CanMakePayment.
EXPECT_THAT(
histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
}
// Tests that the completion status metrics based on whether the user had
// suggestions for all the requested sections are logged as correctly.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_SuggestionsForEverything_Completed) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/false);
// Simulate that the user had suggestions for all the requested sections.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1);
// Simulate that the user completes the checkout.
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_COMPLETED);
histogram_tester.ExpectBucketCount(
"PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
"PaymentRequest.UserDidNotHaveSuggestionsForEverything."
"EffectOnCompletion"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
}
// Tests that the completion status metrics based on whether the user had
// suggestions for all the requested sections are logged as correctly.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_SuggestionsForEverything_UserAborted) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/false);
// Simulate that the user had suggestions for all the requested sections.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1);
// Simulate that the user aborts the checkout.
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
histogram_tester.ExpectBucketCount(
"PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1);
EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
"PaymentRequest.UserDidNotHaveSuggestionsForEverything."
"EffectOnCompletion"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
}
// Tests that the completion status metrics based on whether the user had
// suggestions for all the requested sections are logged as correctly.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_SuggestionsForEverything_OtherAborted) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/false);
// Simulate that the user had suggestions for all the requested sections.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1);
// Simulate that the checkout is aborted.
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
histogram_tester.ExpectBucketCount(
"PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1);
EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
"PaymentRequest.UserDidNotHaveSuggestionsForEverything."
"EffectOnCompletion"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
}
// Tests that the completion status metrics based on whether the user had
// suggestions for all the requested sections are logged as correctly, even in
// incognito mode.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_SuggestionsForEverything_Incognito) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/true);
// Simulate that the user had suggestions for all the requested sections.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1);
// Simulate that the user completes the checkout.
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_COMPLETED);
histogram_tester.ExpectBucketCount(
"PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
"PaymentRequest.UserDidNotHaveSuggestionsForEverything."
"EffectOnCompletion"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
}
// Tests that the completion status metrics based on whether the user had
// suggestions for all the requested sections are logged as correctly.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_NoSuggestionsForEverything_Completed) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/false);
// Simulate that the user had suggestions for all the requested sections.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0);
// Simulate that the user completes the checkout.
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_COMPLETED);
histogram_tester.ExpectBucketCount(
"PaymentRequest.UserDidNotHaveSuggestionsForEverything."
"EffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
EXPECT_THAT(
histogram_tester.GetTotalCountsForPrefix(
"PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
}
// Tests that the completion status metrics based on whether the user had
// suggestions for all the requested sections are logged as correctly.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_NoSuggestionsForEverything_UserAborted) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/false);
// Simulate that the user had suggestions for all the requested sections.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0);
// Simulate that the user aborts the checkout.
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
histogram_tester.ExpectBucketCount(
"PaymentRequest.UserDidNotHaveSuggestionsForEverything."
"EffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1);
EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
"PaymentRequest.UserHadSuggestionsForEverything."
"EffectOnCompletion"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
}
// Tests that the completion status metrics based on whether the user had
// suggestions for all the requested sections are logged as correctly.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_NoSuggestionsForEverything_OtherAborted) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/false);
// Simulate that the user had suggestions for all the requested sections.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0);
// Simulate that the user aborts the checkout.
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED);
histogram_tester.ExpectBucketCount(
"PaymentRequest.UserDidNotHaveSuggestionsForEverything."
"EffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1);
EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
"PaymentRequest.UserHadSuggestionsForEverything."
"EffectOnCompletion"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
}
// Tests that the completion status metrics based on whether the user had
// suggestions for all the requested sections are logged as correctly, even in
// incognito mode.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_NoSuggestionsForEverything_Incognito) {
base::HistogramTester histogram_tester;
JourneyLogger logger(/*is_incognito=*/true);
// Simulate that the user had suggestions for all the requested sections.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0);
// Simulate that the user aborts the checkout.
logger.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
histogram_tester.ExpectBucketCount(
"PaymentRequest.UserDidNotHaveSuggestionsForEverything."
"EffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1);
EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(
"PaymentRequest.UserHadSuggestionsForEverything."
"EffectOnCompletion"),
testing::ContainerEq(base::HistogramTester::CountsMap()));
}
// Tests that the metrics are logged correctly for two simultaneous Payment
// Requests.
TEST(JourneyLoggerTest, RecordJourneyStatsHistograms_TwoPaymentRequests) {
base::HistogramTester histogram_tester;
JourneyLogger logger1(/*is_incognito=*/false);
JourneyLogger logger2(/*is_incognito=*/false);
// Make the two loggers have different data.
logger1.SetShowCalled();
logger2.SetShowCalled();
logger1.SetCanMakePaymentValue(true);
logger1.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1);
logger2.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0);
// Simulate that the user completes one checkout and aborts the other.
logger1.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_COMPLETED);
logger2.RecordJourneyStatsHistograms(
JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
// Make sure the appropriate metrics were logged for logger1.
histogram_tester.ExpectBucketCount(
"PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
JourneyLogger::CAN_MAKE_PAYMENT_USED, 1);
histogram_tester.ExpectBucketCount(
"PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_COMPLETED, 1);
// Make sure the appropriate metrics were logged for logger2.
histogram_tester.ExpectBucketCount(
"PaymentRequest.UserDidNotHaveSuggestionsForEverything."
"EffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1);
histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage",
JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED,
1);
histogram_tester.ExpectBucketCount(
"PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion",
JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1);
}
} // namespace payments
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment