Commit 7ef0d7d9 authored by Danyao Wang's avatar Danyao Wang Committed by Commit Bot

[Payment Request] Update test expectations for hasEnrolledInstrument.

This patch explicitly enables hasEnrolledInstrument in tests in
preparation for enabling this feature by default.

Fixed a bug where new canMakePayment() is not turned off when
canMakePayment is turned off in pref settings.

Intent to Ship: https://groups.google.com/a/chromium.org/d/msg/blink-dev/6rZ7kBLwmhg/lqEpsHLiDgAJ

Bug: 915907
Change-Id: I24445f3242dcc3d30ed50cb1dc38f13fd1331bcd
Reviewed-on: https://chromium-review.googlesource.com/c/1483355
Commit-Queue: Danyao Wang <danyao@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636218}
parent 09ab01ff
...@@ -1602,6 +1602,7 @@ public class PaymentRequestImpl ...@@ -1602,6 +1602,7 @@ public class PaymentRequestImpl
mIsCanMakePaymentResponsePending = false; mIsCanMakePaymentResponsePending = false;
boolean response = legacyMode ? mHasEnrolledInstrument : mArePaymentMethodsSupported; boolean response = legacyMode ? mHasEnrolledInstrument : mArePaymentMethodsSupported;
response &= PrefServiceBridge.getInstance().getBoolean(Pref.CAN_MAKE_PAYMENT_ENABLED);
// Only need to enforce query quota in legacy mode. Per-method quota not supported. // Only need to enforce query quota in legacy mode. Per-method quota not supported.
if (legacyMode if (legacyMode
......
...@@ -30,7 +30,8 @@ import java.util.concurrent.TimeoutException; ...@@ -30,7 +30,8 @@ import java.util.concurrent.TimeoutException;
* depending on whether Google Pay cards are returned in basic-card. * depending on whether Google Pay cards are returned in basic-card.
*/ */
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
"enable-features=PaymentRequestHasEnrolledInstrument"})
public class PaymentRequestCanMakePaymentGooglePayTest implements MainActivityStartCallback { public class PaymentRequestCanMakePaymentGooglePayTest implements MainActivityStartCallback {
@Rule @Rule
public PaymentRequestTestRule mPaymentRequestTestRule = public PaymentRequestTestRule mPaymentRequestTestRule =
...@@ -61,6 +62,10 @@ public class PaymentRequestCanMakePaymentGooglePayTest implements MainActivitySt ...@@ -61,6 +62,10 @@ public class PaymentRequestCanMakePaymentGooglePayTest implements MainActivitySt
mPaymentRequestTestRule.openPageAndClickBuyAndWait( mPaymentRequestTestRule.openPageAndClickBuyAndWait(
mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"true"}); mPaymentRequestTestRule.expectResultContains(new String[] {"true"});
mPaymentRequestTestRule.clickNodeAndWait("hasEnrolledInstrument",
mPaymentRequestTestRule.getHasEnrolledInstrumentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"true"});
} }
@Test @Test
...@@ -72,6 +77,10 @@ public class PaymentRequestCanMakePaymentGooglePayTest implements MainActivitySt ...@@ -72,6 +77,10 @@ public class PaymentRequestCanMakePaymentGooglePayTest implements MainActivitySt
throws InterruptedException, ExecutionException, TimeoutException { throws InterruptedException, ExecutionException, TimeoutException {
mPaymentRequestTestRule.openPageAndClickBuyAndWait( mPaymentRequestTestRule.openPageAndClickBuyAndWait(
mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"true"});
mPaymentRequestTestRule.clickNodeAndWait("hasEnrolledInstrument",
mPaymentRequestTestRule.getHasEnrolledInstrumentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"false"}); mPaymentRequestTestRule.expectResultContains(new String[] {"false"});
} }
} }
...@@ -38,7 +38,8 @@ import java.util.concurrent.TimeoutException; ...@@ -38,7 +38,8 @@ import java.util.concurrent.TimeoutException;
* A payment integration test for the correct log of the CanMakePayment metrics. * A payment integration test for the correct log of the CanMakePayment metrics.
*/ */
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
"enable-features=PaymentRequestHasEnrolledInstrument"})
public class PaymentRequestCanMakePaymentMetricsTest implements MainActivityStartCallback { public class PaymentRequestCanMakePaymentMetricsTest implements MainActivityStartCallback {
@Rule @Rule
public PaymentRequestTestRule mPaymentRequestTestRule = public PaymentRequestTestRule mPaymentRequestTestRule =
...@@ -76,8 +77,9 @@ public class PaymentRequestCanMakePaymentMetricsTest implements MainActivityStar ...@@ -76,8 +77,9 @@ public class PaymentRequestCanMakePaymentMetricsTest implements MainActivityStar
mPaymentRequestTestRule.expectResultContains(new String[] {"Request cancelled"}); mPaymentRequestTestRule.expectResultContains(new String[] {"Request cancelled"});
// Make sure the canMakePayment events were logged correctly. // Make sure the canMakePayment events were logged correctly.
int expectedSample = Event.SHOWN | Event.USER_ABORTED | Event.CAN_MAKE_PAYMENT_FALSE int expectedSample = Event.SHOWN | Event.USER_ABORTED | Event.CAN_MAKE_PAYMENT_TRUE
| Event.REQUEST_METHOD_BASIC_CARD | Event.REQUEST_METHOD_OTHER; | Event.HAS_ENROLLED_INSTRUMENT_FALSE | Event.REQUEST_METHOD_BASIC_CARD
| Event.REQUEST_METHOD_OTHER;
Assert.assertEquals(1, Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting( RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.Events", expectedSample)); "PaymentRequest.Events", expectedSample));
...@@ -118,7 +120,8 @@ public class PaymentRequestCanMakePaymentMetricsTest implements MainActivityStar ...@@ -118,7 +120,8 @@ public class PaymentRequestCanMakePaymentMetricsTest implements MainActivityStar
// Make sure the canMakePayment events were logged correctly. // Make sure the canMakePayment events were logged correctly.
int expectedSample = Event.SHOWN | Event.PAY_CLICKED | Event.RECEIVED_INSTRUMENT_DETAILS int expectedSample = Event.SHOWN | Event.PAY_CLICKED | Event.RECEIVED_INSTRUMENT_DETAILS
| Event.COMPLETED | Event.CAN_MAKE_PAYMENT_FALSE | Event.REQUEST_METHOD_BASIC_CARD | Event.COMPLETED | Event.CAN_MAKE_PAYMENT_TRUE
| Event.HAS_ENROLLED_INSTRUMENT_FALSE | Event.REQUEST_METHOD_BASIC_CARD
| Event.REQUEST_METHOD_OTHER | Event.SELECTED_CREDIT_CARD; | Event.REQUEST_METHOD_OTHER | Event.SELECTED_CREDIT_CARD;
Assert.assertEquals(1, Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting( RecordHistogram.getHistogramValueCountForTesting(
...@@ -149,7 +152,8 @@ public class PaymentRequestCanMakePaymentMetricsTest implements MainActivityStar ...@@ -149,7 +152,8 @@ public class PaymentRequestCanMakePaymentMetricsTest implements MainActivityStar
// Make sure the canMakePayment events were logged correctly. // Make sure the canMakePayment events were logged correctly.
int expectedSample = Event.SHOWN | Event.OTHER_ABORTED | Event.HAD_INITIAL_FORM_OF_PAYMENT int expectedSample = Event.SHOWN | Event.OTHER_ABORTED | Event.HAD_INITIAL_FORM_OF_PAYMENT
| Event.HAD_NECESSARY_COMPLETE_SUGGESTIONS | Event.CAN_MAKE_PAYMENT_TRUE | Event.HAD_NECESSARY_COMPLETE_SUGGESTIONS | Event.CAN_MAKE_PAYMENT_TRUE
| Event.REQUEST_METHOD_BASIC_CARD | Event.REQUEST_METHOD_OTHER; | Event.HAS_ENROLLED_INSTRUMENT_TRUE | Event.REQUEST_METHOD_BASIC_CARD
| Event.REQUEST_METHOD_OTHER;
Assert.assertEquals(1, Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting( RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.Events", expectedSample)); "PaymentRequest.Events", expectedSample));
...@@ -178,8 +182,8 @@ public class PaymentRequestCanMakePaymentMetricsTest implements MainActivityStar ...@@ -178,8 +182,8 @@ public class PaymentRequestCanMakePaymentMetricsTest implements MainActivityStar
int expectedSample = Event.SHOWN | Event.PAY_CLICKED | Event.RECEIVED_INSTRUMENT_DETAILS int expectedSample = Event.SHOWN | Event.PAY_CLICKED | Event.RECEIVED_INSTRUMENT_DETAILS
| Event.COMPLETED | Event.HAD_INITIAL_FORM_OF_PAYMENT | Event.COMPLETED | Event.HAD_INITIAL_FORM_OF_PAYMENT
| Event.HAD_NECESSARY_COMPLETE_SUGGESTIONS | Event.CAN_MAKE_PAYMENT_TRUE | Event.HAD_NECESSARY_COMPLETE_SUGGESTIONS | Event.CAN_MAKE_PAYMENT_TRUE
| Event.REQUEST_METHOD_BASIC_CARD | Event.REQUEST_METHOD_OTHER | Event.HAS_ENROLLED_INSTRUMENT_TRUE | Event.REQUEST_METHOD_BASIC_CARD
| Event.SELECTED_OTHER; | Event.REQUEST_METHOD_OTHER | Event.SELECTED_OTHER;
Assert.assertEquals(1, Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting( RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.Events", expectedSample)); "PaymentRequest.Events", expectedSample));
...@@ -212,8 +216,8 @@ public class PaymentRequestCanMakePaymentMetricsTest implements MainActivityStar ...@@ -212,8 +216,8 @@ public class PaymentRequestCanMakePaymentMetricsTest implements MainActivityStar
int expectedSample = Event.SHOWN | Event.PAY_CLICKED | Event.RECEIVED_INSTRUMENT_DETAILS int expectedSample = Event.SHOWN | Event.PAY_CLICKED | Event.RECEIVED_INSTRUMENT_DETAILS
| Event.COMPLETED | Event.HAD_INITIAL_FORM_OF_PAYMENT | Event.COMPLETED | Event.HAD_INITIAL_FORM_OF_PAYMENT
| Event.HAD_NECESSARY_COMPLETE_SUGGESTIONS | Event.CAN_MAKE_PAYMENT_FALSE | Event.HAD_NECESSARY_COMPLETE_SUGGESTIONS | Event.CAN_MAKE_PAYMENT_FALSE
| Event.REQUEST_METHOD_BASIC_CARD | Event.REQUEST_METHOD_OTHER | Event.HAS_ENROLLED_INSTRUMENT_FALSE | Event.REQUEST_METHOD_BASIC_CARD
| Event.SELECTED_OTHER; | Event.REQUEST_METHOD_OTHER | Event.SELECTED_OTHER;
Assert.assertEquals(1, Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting( RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.Events", expectedSample)); "PaymentRequest.Events", expectedSample));
......
...@@ -33,7 +33,8 @@ import java.util.concurrent.TimeoutException; ...@@ -33,7 +33,8 @@ import java.util.concurrent.TimeoutException;
* app or a credit card. This user does not have a complete credit card on file. * app or a credit card. This user does not have a complete credit card on file.
*/ */
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
"enable-features=PaymentRequestHasEnrolledInstrument"})
public class PaymentRequestCanMakePaymentQueryNoCardTest implements MainActivityStartCallback { public class PaymentRequestCanMakePaymentQueryNoCardTest implements MainActivityStartCallback {
@Rule @Rule
public PaymentRequestTestRule mPaymentRequestTestRule = public PaymentRequestTestRule mPaymentRequestTestRule =
...@@ -57,6 +58,10 @@ public class PaymentRequestCanMakePaymentQueryNoCardTest implements MainActivity ...@@ -57,6 +58,10 @@ public class PaymentRequestCanMakePaymentQueryNoCardTest implements MainActivity
throws InterruptedException, ExecutionException, TimeoutException { throws InterruptedException, ExecutionException, TimeoutException {
mPaymentRequestTestRule.openPageAndClickBuyAndWait( mPaymentRequestTestRule.openPageAndClickBuyAndWait(
mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"true"});
mPaymentRequestTestRule.clickNodeAndWait("hasEnrolledInstrument",
mPaymentRequestTestRule.getHasEnrolledInstrumentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"false"}); mPaymentRequestTestRule.expectResultContains(new String[] {"false"});
} }
...@@ -68,6 +73,10 @@ public class PaymentRequestCanMakePaymentQueryNoCardTest implements MainActivity ...@@ -68,6 +73,10 @@ public class PaymentRequestCanMakePaymentQueryNoCardTest implements MainActivity
mPaymentRequestTestRule.installPaymentApp(NO_INSTRUMENTS, IMMEDIATE_RESPONSE); mPaymentRequestTestRule.installPaymentApp(NO_INSTRUMENTS, IMMEDIATE_RESPONSE);
mPaymentRequestTestRule.openPageAndClickBuyAndWait( mPaymentRequestTestRule.openPageAndClickBuyAndWait(
mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"true"});
mPaymentRequestTestRule.clickNodeAndWait("hasEnrolledInstrument",
mPaymentRequestTestRule.getHasEnrolledInstrumentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"false"}); mPaymentRequestTestRule.expectResultContains(new String[] {"false"});
} }
...@@ -79,6 +88,10 @@ public class PaymentRequestCanMakePaymentQueryNoCardTest implements MainActivity ...@@ -79,6 +88,10 @@ public class PaymentRequestCanMakePaymentQueryNoCardTest implements MainActivity
mPaymentRequestTestRule.installPaymentApp(NO_INSTRUMENTS, DELAYED_RESPONSE); mPaymentRequestTestRule.installPaymentApp(NO_INSTRUMENTS, DELAYED_RESPONSE);
mPaymentRequestTestRule.openPageAndClickBuyAndWait( mPaymentRequestTestRule.openPageAndClickBuyAndWait(
mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"true"});
mPaymentRequestTestRule.clickNodeAndWait("hasEnrolledInstrument",
mPaymentRequestTestRule.getHasEnrolledInstrumentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"false"}); mPaymentRequestTestRule.expectResultContains(new String[] {"false"});
} }
......
...@@ -32,7 +32,8 @@ import java.util.concurrent.TimeoutException; ...@@ -32,7 +32,8 @@ import java.util.concurrent.TimeoutException;
* user has a valid credit card without a billing address on file. * user has a valid credit card without a billing address on file.
*/ */
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
"enable-features=PaymentRequestHasEnrolledInstrument"})
public class PaymentRequestCcCanMakePaymentQueryTest implements MainActivityStartCallback { public class PaymentRequestCcCanMakePaymentQueryTest implements MainActivityStartCallback {
@Rule @Rule
public PaymentRequestTestRule mPaymentRequestTestRule = public PaymentRequestTestRule mPaymentRequestTestRule =
...@@ -62,7 +63,7 @@ public class PaymentRequestCcCanMakePaymentQueryTest implements MainActivityStar ...@@ -62,7 +63,7 @@ public class PaymentRequestCcCanMakePaymentQueryTest implements MainActivityStar
mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"true"}); mPaymentRequestTestRule.expectResultContains(new String[] {"true"});
// Repeating a query does not count against the quota. // canMakePayment() is not throttled at all.
mPaymentRequestTestRule.clickNodeAndWait( mPaymentRequestTestRule.clickNodeAndWait(
"buy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); "buy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"true"}); mPaymentRequestTestRule.expectResultContains(new String[] {"true"});
...@@ -71,16 +72,25 @@ public class PaymentRequestCcCanMakePaymentQueryTest implements MainActivityStar ...@@ -71,16 +72,25 @@ public class PaymentRequestCcCanMakePaymentQueryTest implements MainActivityStar
"buy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); "buy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"true"}); mPaymentRequestTestRule.expectResultContains(new String[] {"true"});
// Different queries are throttled for a period of time.
mPaymentRequestTestRule.clickNodeAndWait( mPaymentRequestTestRule.clickNodeAndWait(
"other-buy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); "other-buy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains( mPaymentRequestTestRule.expectResultContains(new String[] {"true"});
new String[] {"Not allowed to check whether can make payment"});
// Repeating the same query again does not count against the quota. // hasEnrolledInstrument() is throttled, but repeating the same query does not count against
mPaymentRequestTestRule.clickNodeAndWait( // quota.
"buy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); mPaymentRequestTestRule.clickNodeAndWait("has-enrolled-instrument-visa",
mPaymentRequestTestRule.getHasEnrolledInstrumentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"true"}); mPaymentRequestTestRule.expectResultContains(new String[] {"true"});
mPaymentRequestTestRule.clickNodeAndWait("has-enrolled-instrument-visa",
mPaymentRequestTestRule.getHasEnrolledInstrumentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"true"});
// Different hasEnrolledInstrument() queries are throttled.
mPaymentRequestTestRule.clickNodeAndWait("has-enrolled-instrument-mastercard",
mPaymentRequestTestRule.getHasEnrolledInstrumentQueryResponded());
mPaymentRequestTestRule.expectResultContains(
new String[] {"Exceeded query quota for hasEnrolledInstrument"});
} }
@Test @Test
...@@ -96,7 +106,7 @@ public class PaymentRequestCcCanMakePaymentQueryTest implements MainActivityStar ...@@ -96,7 +106,7 @@ public class PaymentRequestCcCanMakePaymentQueryTest implements MainActivityStar
mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"false"}); mPaymentRequestTestRule.expectResultContains(new String[] {"false"});
// Repeating a query does not count against the quota. // canMakePayment() is not throttled at all.
mPaymentRequestTestRule.clickNodeAndWait( mPaymentRequestTestRule.clickNodeAndWait(
"buy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); "buy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"false"}); mPaymentRequestTestRule.expectResultContains(new String[] {"false"});
...@@ -105,15 +115,24 @@ public class PaymentRequestCcCanMakePaymentQueryTest implements MainActivityStar ...@@ -105,15 +115,24 @@ public class PaymentRequestCcCanMakePaymentQueryTest implements MainActivityStar
"buy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); "buy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"false"}); mPaymentRequestTestRule.expectResultContains(new String[] {"false"});
// Different queries are throttled for a period of time.
mPaymentRequestTestRule.clickNodeAndWait( mPaymentRequestTestRule.clickNodeAndWait(
"other-buy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); "other-buy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains( mPaymentRequestTestRule.expectResultContains(new String[] {"false"});
new String[] {"Not allowed to check whether can make payment"});
// Repeating the same query again does not count against the quota. // hasEnrolledInstrument() is throttled, but repeating the same query does not count against
mPaymentRequestTestRule.clickNodeAndWait( // quota.
"buy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); mPaymentRequestTestRule.clickNodeAndWait("has-enrolled-instrument-visa",
mPaymentRequestTestRule.getHasEnrolledInstrumentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"false"}); mPaymentRequestTestRule.expectResultContains(new String[] {"false"});
mPaymentRequestTestRule.clickNodeAndWait("has-enrolled-instrument-visa",
mPaymentRequestTestRule.getHasEnrolledInstrumentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"false"});
// Different hasEnrolledInstrument() queries are throttled.
mPaymentRequestTestRule.clickNodeAndWait("has-enrolled-instrument-mastercard",
mPaymentRequestTestRule.getHasEnrolledInstrumentQueryResponded());
mPaymentRequestTestRule.expectResultContains(
new String[] {"Exceeded query quota for hasEnrolledInstrument"});
} }
} }
...@@ -34,7 +34,8 @@ import java.util.concurrent.TimeoutException; ...@@ -34,7 +34,8 @@ import java.util.concurrent.TimeoutException;
* A payment integration test for supported payment methods. * A payment integration test for supported payment methods.
*/ */
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
"enable-features=PaymentRequestHasEnrolledInstrument"})
public class PaymentRequestPaymentMethodIdentifierTest implements MainActivityStartCallback { public class PaymentRequestPaymentMethodIdentifierTest implements MainActivityStartCallback {
@Rule @Rule
public PaymentRequestTestRule mPaymentRequestTestRule = public PaymentRequestTestRule mPaymentRequestTestRule =
...@@ -91,7 +92,7 @@ public class PaymentRequestPaymentMethodIdentifierTest implements MainActivitySt ...@@ -91,7 +92,7 @@ public class PaymentRequestPaymentMethodIdentifierTest implements MainActivitySt
throws InterruptedException, ExecutionException, TimeoutException { throws InterruptedException, ExecutionException, TimeoutException {
mPaymentRequestTestRule.openPageAndClickNodeAndWait( mPaymentRequestTestRule.openPageAndClickNodeAndWait(
"checkBasicMasterCard", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); "checkBasicMasterCard", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"false"}); mPaymentRequestTestRule.expectResultContains(new String[] {"true"});
mPaymentRequestTestRule.reTriggerUIAndWait( mPaymentRequestTestRule.reTriggerUIAndWait(
"buyBasicMasterCard", mPaymentRequestTestRule.getReadyForInput()); "buyBasicMasterCard", mPaymentRequestTestRule.getReadyForInput());
...@@ -108,8 +109,7 @@ public class PaymentRequestPaymentMethodIdentifierTest implements MainActivitySt ...@@ -108,8 +109,7 @@ public class PaymentRequestPaymentMethodIdentifierTest implements MainActivitySt
mPaymentRequestTestRule.clickNodeAndWait( mPaymentRequestTestRule.clickNodeAndWait(
"checkBasicMasterCard", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); "checkBasicMasterCard", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains( mPaymentRequestTestRule.expectResultContains(new String[] {"true"});
new String[] {"Not allowed to check whether can make payment"});
mPaymentRequestTestRule.clickNodeAndWait( mPaymentRequestTestRule.clickNodeAndWait(
"checkBasicVisa", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); "checkBasicVisa", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
...@@ -127,8 +127,7 @@ public class PaymentRequestPaymentMethodIdentifierTest implements MainActivitySt ...@@ -127,8 +127,7 @@ public class PaymentRequestPaymentMethodIdentifierTest implements MainActivitySt
mPaymentRequestTestRule.clickNodeAndWait( mPaymentRequestTestRule.clickNodeAndWait(
"checkBasicDebit", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); "checkBasicDebit", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains( mPaymentRequestTestRule.expectResultContains(new String[] {"true"});
new String[] {"Not allowed to check whether can make payment"});
mPaymentRequestTestRule.clickNodeAndWait( mPaymentRequestTestRule.clickNodeAndWait(
"checkBasicVisa", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); "checkBasicVisa", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
......
...@@ -7,12 +7,14 @@ ...@@ -7,12 +7,14 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h" #include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h"
#include "components/autofill/core/browser/autofill_profile.h" #include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/autofill_test_utils.h" #include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/credit_card.h" #include "components/autofill/core/browser/credit_card.h"
#include "components/payments/core/journey_logger.h" #include "components/payments/core/journey_logger.h"
#include "content/public/common/content_features.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -21,9 +23,14 @@ namespace payments { ...@@ -21,9 +23,14 @@ namespace payments {
class PaymentRequestCompletionStatusMetricsTest class PaymentRequestCompletionStatusMetricsTest
: public PaymentRequestBrowserTestBase { : public PaymentRequestBrowserTestBase {
protected: protected:
PaymentRequestCompletionStatusMetricsTest() {} PaymentRequestCompletionStatusMetricsTest() {
feature_list_.InitAndEnableFeature(
::features::kPaymentRequestHasEnrolledInstrument);
}
private: private:
base::test::ScopedFeatureList feature_list_;
DISALLOW_COPY_AND_ASSIGN(PaymentRequestCompletionStatusMetricsTest); DISALLOW_COPY_AND_ASSIGN(PaymentRequestCompletionStatusMetricsTest);
}; };
...@@ -43,6 +50,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, Completed) { ...@@ -43,6 +50,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, Completed) {
// Payment Request is shown. // Payment Request is shown.
ResetEventWaiterForSequence({DialogEvent::CAN_MAKE_PAYMENT_CALLED, ResetEventWaiterForSequence({DialogEvent::CAN_MAKE_PAYMENT_CALLED,
DialogEvent::CAN_MAKE_PAYMENT_RETURNED, DialogEvent::CAN_MAKE_PAYMENT_RETURNED,
DialogEvent::HAS_ENROLLED_INSTRUMENT_CALLED,
DialogEvent::HAS_ENROLLED_INSTRUMENT_RETURNED,
DialogEvent::PROCESSING_SPINNER_SHOWN, DialogEvent::PROCESSING_SPINNER_SHOWN,
DialogEvent::PROCESSING_SPINNER_HIDDEN, DialogEvent::PROCESSING_SPINNER_HIDDEN,
DialogEvent::DIALOG_OPENED}); DialogEvent::DIALOG_OPENED});
...@@ -74,6 +83,10 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, Completed) { ...@@ -74,6 +83,10 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, Completed) {
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_REQUEST_PAYER_EMAIL); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_REQUEST_PAYER_EMAIL);
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_FALSE); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_FALSE);
EXPECT_TRUE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_TRUE); EXPECT_TRUE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_TRUE);
EXPECT_TRUE(buckets[0].min &
JourneyLogger::EVENT_HAS_ENROLLED_INSTRUMENT_TRUE);
EXPECT_FALSE(buckets[0].min &
JourneyLogger::EVENT_HAS_ENROLLED_INSTRUMENT_FALSE);
} }
IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
...@@ -119,6 +132,10 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, ...@@ -119,6 +132,10 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_REQUEST_PAYER_EMAIL); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_REQUEST_PAYER_EMAIL);
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_FALSE); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_FALSE);
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_TRUE); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_TRUE);
EXPECT_FALSE(buckets[0].min &
JourneyLogger::EVENT_HAS_ENROLLED_INSTRUMENT_TRUE);
EXPECT_FALSE(buckets[0].min &
JourneyLogger::EVENT_HAS_ENROLLED_INSTRUMENT_FALSE);
} }
IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
...@@ -166,6 +183,10 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, ...@@ -166,6 +183,10 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_REQUEST_PAYER_EMAIL); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_REQUEST_PAYER_EMAIL);
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_FALSE); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_FALSE);
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_TRUE); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_TRUE);
EXPECT_FALSE(buckets[0].min &
JourneyLogger::EVENT_HAS_ENROLLED_INSTRUMENT_TRUE);
EXPECT_FALSE(buckets[0].min &
JourneyLogger::EVENT_HAS_ENROLLED_INSTRUMENT_FALSE);
} }
IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
...@@ -214,6 +235,10 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, ...@@ -214,6 +235,10 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_REQUEST_PAYER_EMAIL); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_REQUEST_PAYER_EMAIL);
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_FALSE); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_FALSE);
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_TRUE); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_TRUE);
EXPECT_FALSE(buckets[0].min &
JourneyLogger::EVENT_HAS_ENROLLED_INSTRUMENT_TRUE);
EXPECT_FALSE(buckets[0].min &
JourneyLogger::EVENT_HAS_ENROLLED_INSTRUMENT_FALSE);
} }
IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
...@@ -256,6 +281,10 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, ...@@ -256,6 +281,10 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_REQUEST_PAYER_EMAIL); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_REQUEST_PAYER_EMAIL);
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_FALSE); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_FALSE);
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_TRUE); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_TRUE);
EXPECT_FALSE(buckets[0].min &
JourneyLogger::EVENT_HAS_ENROLLED_INSTRUMENT_TRUE);
EXPECT_FALSE(buckets[0].min &
JourneyLogger::EVENT_HAS_ENROLLED_INSTRUMENT_FALSE);
} }
IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
...@@ -298,6 +327,10 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, ...@@ -298,6 +327,10 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_REQUEST_PAYER_EMAIL); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_REQUEST_PAYER_EMAIL);
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_FALSE); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_FALSE);
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_TRUE); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_TRUE);
EXPECT_FALSE(buckets[0].min &
JourneyLogger::EVENT_HAS_ENROLLED_INSTRUMENT_TRUE);
EXPECT_FALSE(buckets[0].min &
JourneyLogger::EVENT_HAS_ENROLLED_INSTRUMENT_FALSE);
} }
IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
...@@ -342,6 +375,10 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, ...@@ -342,6 +375,10 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_REQUEST_PAYER_EMAIL); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_REQUEST_PAYER_EMAIL);
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_FALSE); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_FALSE);
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_TRUE); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_TRUE);
EXPECT_FALSE(buckets[0].min &
JourneyLogger::EVENT_HAS_ENROLLED_INSTRUMENT_TRUE);
EXPECT_FALSE(buckets[0].min &
JourneyLogger::EVENT_HAS_ENROLLED_INSTRUMENT_FALSE);
} }
IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
...@@ -386,14 +423,23 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, ...@@ -386,14 +423,23 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_REQUEST_PAYER_EMAIL); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_REQUEST_PAYER_EMAIL);
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_FALSE); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_FALSE);
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_TRUE); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_CAN_MAKE_PAYMENT_TRUE);
EXPECT_FALSE(buckets[0].min &
JourneyLogger::EVENT_HAS_ENROLLED_INSTRUMENT_TRUE);
EXPECT_FALSE(buckets[0].min &
JourneyLogger::EVENT_HAS_ENROLLED_INSTRUMENT_FALSE);
} }
class PaymentRequestInitiatedCompletionStatusMetricsTest class PaymentRequestInitiatedCompletionStatusMetricsTest
: public PaymentRequestBrowserTestBase { : public PaymentRequestBrowserTestBase {
protected: protected:
PaymentRequestInitiatedCompletionStatusMetricsTest() {} PaymentRequestInitiatedCompletionStatusMetricsTest() {
feature_list_.InitAndEnableFeature(
::features::kPaymentRequestHasEnrolledInstrument);
}
private: private:
base::test::ScopedFeatureList feature_list_;
DISALLOW_COPY_AND_ASSIGN(PaymentRequestInitiatedCompletionStatusMetricsTest); DISALLOW_COPY_AND_ASSIGN(PaymentRequestInitiatedCompletionStatusMetricsTest);
}; };
......
...@@ -4,11 +4,13 @@ ...@@ -4,11 +4,13 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h" #include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h"
#include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
#include "components/autofill/core/browser/autofill_test_utils.h" #include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/credit_card.h" #include "components/autofill/core/browser/credit_card.h"
#include "components/payments/core/features.h" #include "components/payments/core/features.h"
#include "content/public/common/content_features.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
namespace payments { namespace payments {
...@@ -22,7 +24,10 @@ constexpr auto UNKNOWN = ::autofill::CreditCard::CardType::CARD_TYPE_UNKNOWN; ...@@ -22,7 +24,10 @@ constexpr auto UNKNOWN = ::autofill::CreditCard::CardType::CARD_TYPE_UNKNOWN;
class PaymentRequestDebitTest : public PaymentRequestBrowserTestBase { class PaymentRequestDebitTest : public PaymentRequestBrowserTestBase {
protected: protected:
PaymentRequestDebitTest() { PaymentRequestDebitTest() {
features_.InitAndEnableFeature(features::kReturnGooglePayInBasicCard); std::vector<base::Feature> enabled_features = {
features::kReturnGooglePayInBasicCard,
::features::kPaymentRequestHasEnrolledInstrument};
features_.InitWithFeatures(enabled_features, /*disabled_feautres=*/{});
} }
const std::string& GetOrCreateBillingAddressId() { const std::string& GetOrCreateBillingAddressId() {
...@@ -50,6 +55,15 @@ class PaymentRequestDebitTest : public PaymentRequestBrowserTestBase { ...@@ -50,6 +55,15 @@ class PaymentRequestDebitTest : public PaymentRequestBrowserTestBase {
WaitForObservedEvent(); WaitForObservedEvent();
} }
void CallHasEnrolledInstrument() {
ResetEventWaiterForSequence(
{DialogEvent::HAS_ENROLLED_INSTRUMENT_CALLED,
DialogEvent::HAS_ENROLLED_INSTRUMENT_RETURNED});
ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(),
"hasEnrolledInstrument();"));
WaitForObservedEvent();
}
private: private:
base::test::ScopedFeatureList features_; base::test::ScopedFeatureList features_;
std::string billing_address_id_; std::string billing_address_id_;
...@@ -62,6 +76,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestDebitTest, CanMakePaymentWithDebitCard) { ...@@ -62,6 +76,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestDebitTest, CanMakePaymentWithDebitCard) {
AddServerCardWithType(DEBIT); AddServerCardWithType(DEBIT);
CallCanMakePayment(); CallCanMakePayment();
ExpectBodyContains({"true"}); ExpectBodyContains({"true"});
CallHasEnrolledInstrument();
ExpectBodyContains({"true"});
} }
IN_PROC_BROWSER_TEST_F(PaymentRequestDebitTest, IN_PROC_BROWSER_TEST_F(PaymentRequestDebitTest,
...@@ -70,6 +86,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestDebitTest, ...@@ -70,6 +86,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestDebitTest,
AddServerCardWithType(UNKNOWN); AddServerCardWithType(UNKNOWN);
CallCanMakePayment(); CallCanMakePayment();
ExpectBodyContains({"true"}); ExpectBodyContains({"true"});
CallHasEnrolledInstrument();
ExpectBodyContains({"true"});
} }
IN_PROC_BROWSER_TEST_F(PaymentRequestDebitTest, IN_PROC_BROWSER_TEST_F(PaymentRequestDebitTest,
...@@ -78,6 +96,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestDebitTest, ...@@ -78,6 +96,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestDebitTest,
AddServerCardWithType(CREDIT); AddServerCardWithType(CREDIT);
AddServerCardWithType(PREPAID); AddServerCardWithType(PREPAID);
CallCanMakePayment(); CallCanMakePayment();
ExpectBodyContains({"true"});
CallHasEnrolledInstrument();
ExpectBodyContains({"false"}); ExpectBodyContains({"false"});
} }
......
...@@ -23,16 +23,22 @@ ...@@ -23,16 +23,22 @@
namespace payments { namespace payments {
class PaymentRequestJourneyLoggerSelectedPaymentInstrumentTest class PaymentRequestJourneyLoggerTestBase
: public PaymentRequestBrowserTestBase { : public PaymentRequestBrowserTestBase {
protected: protected:
PaymentRequestJourneyLoggerSelectedPaymentInstrumentTest() {} PaymentRequestJourneyLoggerTestBase() {
feature_list_.InitAndEnableFeature(
::features::kPaymentRequestHasEnrolledInstrument);
}
private: private:
DISALLOW_COPY_AND_ASSIGN( base::test::ScopedFeatureList feature_list_;
PaymentRequestJourneyLoggerSelectedPaymentInstrumentTest); DISALLOW_COPY_AND_ASSIGN(PaymentRequestJourneyLoggerTestBase);
}; };
using PaymentRequestJourneyLoggerSelectedPaymentInstrumentTest =
PaymentRequestJourneyLoggerTestBase;
// Tests that the selected instrument metric is correctly logged when the // Tests that the selected instrument metric is correctly logged when the
// Payment Request is completed with a credit card. // Payment Request is completed with a credit card.
IN_PROC_BROWSER_TEST_F(PaymentRequestJourneyLoggerSelectedPaymentInstrumentTest, IN_PROC_BROWSER_TEST_F(PaymentRequestJourneyLoggerSelectedPaymentInstrumentTest,
...@@ -82,15 +88,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestJourneyLoggerSelectedPaymentInstrumentTest, ...@@ -82,15 +88,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestJourneyLoggerSelectedPaymentInstrumentTest,
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_SELECTED_OTHER); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_SELECTED_OTHER);
} }
class PaymentRequestJourneyLoggerNoSupportedPaymentMethodTest using PaymentRequestJourneyLoggerNoSupportedPaymentMethodTest =
: public PaymentRequestBrowserTestBase { PaymentRequestJourneyLoggerTestBase;
protected:
PaymentRequestJourneyLoggerNoSupportedPaymentMethodTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(
PaymentRequestJourneyLoggerNoSupportedPaymentMethodTest);
};
IN_PROC_BROWSER_TEST_F(PaymentRequestJourneyLoggerNoSupportedPaymentMethodTest, IN_PROC_BROWSER_TEST_F(PaymentRequestJourneyLoggerNoSupportedPaymentMethodTest,
OnlyBobpaySupported) { OnlyBobpaySupported) {
...@@ -140,14 +139,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestJourneyLoggerNoSupportedPaymentMethodTest, ...@@ -140,14 +139,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestJourneyLoggerNoSupportedPaymentMethodTest,
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_SELECTED_OTHER); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_SELECTED_OTHER);
} }
class PaymentRequestJourneyLoggerMultipleShowTest using PaymentRequestJourneyLoggerMultipleShowTest =
: public PaymentRequestBrowserTestBase { PaymentRequestJourneyLoggerTestBase;
protected:
PaymentRequestJourneyLoggerMultipleShowTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(PaymentRequestJourneyLoggerMultipleShowTest);
};
IN_PROC_BROWSER_TEST_F(PaymentRequestJourneyLoggerMultipleShowTest, IN_PROC_BROWSER_TEST_F(PaymentRequestJourneyLoggerMultipleShowTest,
ShowSameRequest) { ShowSameRequest) {
...@@ -415,14 +408,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestJourneyLoggerMultipleShowTest, ...@@ -415,14 +408,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestJourneyLoggerMultipleShowTest,
EXPECT_FALSE(buckets[1].min & JourneyLogger::EVENT_SELECTED_OTHER); EXPECT_FALSE(buckets[1].min & JourneyLogger::EVENT_SELECTED_OTHER);
} }
class PaymentRequestJourneyLoggerAllSectionStatsTest using PaymentRequestJourneyLoggerAllSectionStatsTest =
: public PaymentRequestBrowserTestBase { PaymentRequestJourneyLoggerTestBase;
protected:
PaymentRequestJourneyLoggerAllSectionStatsTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(PaymentRequestJourneyLoggerAllSectionStatsTest);
};
// Tests that the correct number of suggestions shown for each section is logged // Tests that the correct number of suggestions shown for each section is logged
// when a Payment Request is completed. // when a Payment Request is completed.
...@@ -546,15 +533,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestJourneyLoggerAllSectionStatsTest, ...@@ -546,15 +533,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestJourneyLoggerAllSectionStatsTest,
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_SELECTED_OTHER); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_SELECTED_OTHER);
} }
class PaymentRequestJourneyLoggerNoShippingSectionStatsTest using PaymentRequestJourneyLoggerNoShippingSectionStatsTest =
: public PaymentRequestBrowserTestBase { PaymentRequestJourneyLoggerTestBase;
protected:
PaymentRequestJourneyLoggerNoShippingSectionStatsTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(
PaymentRequestJourneyLoggerNoShippingSectionStatsTest);
};
// Tests that the correct number of suggestions shown for each section is logged // Tests that the correct number of suggestions shown for each section is logged
// when a Payment Request is completed. // when a Payment Request is completed.
...@@ -680,15 +660,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestJourneyLoggerNoShippingSectionStatsTest, ...@@ -680,15 +660,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestJourneyLoggerNoShippingSectionStatsTest,
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_SELECTED_OTHER); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_SELECTED_OTHER);
} }
class PaymentRequestJourneyLoggerNoContactDetailSectionStatsTest using PaymentRequestJourneyLoggerNoContactDetailSectionStatsTest =
: public PaymentRequestBrowserTestBase { PaymentRequestJourneyLoggerTestBase;
protected:
PaymentRequestJourneyLoggerNoContactDetailSectionStatsTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(
PaymentRequestJourneyLoggerNoContactDetailSectionStatsTest);
};
// Tests that the correct number of suggestions shown for each section is logged // Tests that the correct number of suggestions shown for each section is logged
// when a Payment Request is completed. // when a Payment Request is completed.
...@@ -820,20 +793,16 @@ IN_PROC_BROWSER_TEST_F( ...@@ -820,20 +793,16 @@ IN_PROC_BROWSER_TEST_F(
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_SELECTED_OTHER); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_SELECTED_OTHER);
} }
class PaymentRequestNotShownTest : public PaymentRequestBrowserTestBase { using PaymentRequestNotShownTest = PaymentRequestJourneyLoggerTestBase;
protected:
PaymentRequestNotShownTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(PaymentRequestNotShownTest);
};
IN_PROC_BROWSER_TEST_F(PaymentRequestNotShownTest, OnlyNotShownMetricsLogged) { IN_PROC_BROWSER_TEST_F(PaymentRequestNotShownTest, OnlyNotShownMetricsLogged) {
NavigateTo("/payment_request_can_make_payment_metrics_test.html"); NavigateTo("/payment_request_can_make_payment_metrics_test.html");
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
ResetEventWaiterForSequence({DialogEvent::CAN_MAKE_PAYMENT_CALLED, ResetEventWaiterForSequence({DialogEvent::CAN_MAKE_PAYMENT_CALLED,
DialogEvent::CAN_MAKE_PAYMENT_RETURNED}); DialogEvent::CAN_MAKE_PAYMENT_RETURNED,
DialogEvent::HAS_ENROLLED_INSTRUMENT_CALLED,
DialogEvent::HAS_ENROLLED_INSTRUMENT_RETURNED});
// Initiate a Payment Request without showing it. // Initiate a Payment Request without showing it.
ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "queryNoShow();")); ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "queryNoShow();"));
...@@ -850,9 +819,9 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestNotShownTest, OnlyNotShownMetricsLogged) { ...@@ -850,9 +819,9 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestNotShownTest, OnlyNotShownMetricsLogged) {
std::vector<base::Bucket> buckets = std::vector<base::Bucket> buckets =
histogram_tester.GetAllSamples("PaymentRequest.Events"); histogram_tester.GetAllSamples("PaymentRequest.Events");
ASSERT_EQ(1U, buckets.size()); ASSERT_EQ(1U, buckets.size());
// Only USER_ABORTED and CAN_MAKE_PAYMENT_FALSE should be logged.
EXPECT_EQ(JourneyLogger::EVENT_USER_ABORTED | EXPECT_EQ(JourneyLogger::EVENT_USER_ABORTED |
JourneyLogger::EVENT_CAN_MAKE_PAYMENT_FALSE | JourneyLogger::EVENT_CAN_MAKE_PAYMENT_TRUE |
JourneyLogger::EVENT_HAS_ENROLLED_INSTRUMENT_FALSE |
JourneyLogger::EVENT_REQUEST_METHOD_OTHER | JourneyLogger::EVENT_REQUEST_METHOD_OTHER |
JourneyLogger::EVENT_REQUEST_METHOD_BASIC_CARD, JourneyLogger::EVENT_REQUEST_METHOD_BASIC_CARD,
buckets[0].min); buckets[0].min);
...@@ -868,14 +837,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestNotShownTest, OnlyNotShownMetricsLogged) { ...@@ -868,14 +837,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestNotShownTest, OnlyNotShownMetricsLogged) {
0); 0);
} }
class PaymentRequestCompleteSuggestionsForEverythingTest using PaymentRequestCompleteSuggestionsForEverythingTest =
: public PaymentRequestBrowserTestBase { PaymentRequestJourneyLoggerTestBase;
protected:
PaymentRequestCompleteSuggestionsForEverythingTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(PaymentRequestCompleteSuggestionsForEverythingTest);
};
IN_PROC_BROWSER_TEST_F(PaymentRequestCompleteSuggestionsForEverythingTest, IN_PROC_BROWSER_TEST_F(PaymentRequestCompleteSuggestionsForEverythingTest,
UserHadCompleteSuggestionsForEverything) { UserHadCompleteSuggestionsForEverything) {
...@@ -1019,7 +982,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1019,7 +982,7 @@ IN_PROC_BROWSER_TEST_F(
EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_SELECTED_OTHER); EXPECT_FALSE(buckets[0].min & JourneyLogger::EVENT_SELECTED_OTHER);
} }
class PaymentRequestIframeTest : public PaymentRequestBrowserTestBase { class PaymentRequestIframeTest : public PaymentRequestJourneyLoggerTestBase {
protected: protected:
PaymentRequestIframeTest() {} PaymentRequestIframeTest() {}
......
...@@ -7,22 +7,37 @@ ...@@ -7,22 +7,37 @@
/* global PaymentRequest:false */ /* global PaymentRequest:false */
/* global print:false */ /* global print:false */
// Global variable. Used by abort().
var request; var request;
const bobPayMethod = Object.freeze({
supportedMethods: 'https://bobpay.com',
});
const visaMethod = Object.freeze({
supportedMethods: 'basic-card',
data: {
supportedNetworks: ['visa'],
},
});
const defaultDetails = Object.freeze({
total: {
label: 'Total',
amount: {
currency: 'USD',
value: '5.00',
},
},
});
/** /**
* Do not query CanMakePayment before showing the Payment Request. * Do not query CanMakePayment before showing the Payment Request.
*/ */
function noQueryShow() { // eslint-disable-line no-unused-vars function noQueryShow() { // eslint-disable-line no-unused-vars
try { try {
request = new PaymentRequest( request = new PaymentRequest([bobPayMethod, visaMethod], defaultDetails);
[
{supportedMethods: 'https://bobpay.com'},
{
supportedMethods: 'basic-card',
data: {supportedNetworks: ['visa']},
},
],
{total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}});
request.show() request.show()
.then(function(resp) { .then(function(resp) {
resp.complete('success') resp.complete('success')
...@@ -44,30 +59,16 @@ function noQueryShow() { // eslint-disable-line no-unused-vars ...@@ -44,30 +59,16 @@ function noQueryShow() { // eslint-disable-line no-unused-vars
/** /**
* Queries CanMakePayment and the shows the PaymentRequest after. * Queries CanMakePayment and the shows the PaymentRequest after.
*/ */
function queryShow() { // eslint-disable-line no-unused-vars async function queryShow() { // eslint-disable-line no-unused-vars
try { try {
request = new PaymentRequest( request = new PaymentRequest([bobPayMethod, visaMethod], defaultDetails);
[ print(await request.canMakePayment());
{supportedMethods: 'https://bobpay.com'}, print(await request.hasEnrolledInstrument());
{ request.show()
supportedMethods: 'basic-card', .then(function(resp) {
data: {supportedNetworks: ['visa']}, resp.complete('success')
}, .then(function() {
], print(JSON.stringify(resp, undefined, 2));
{total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}});
request.canMakePayment()
.then(function(result) {
print(result);
request.show()
.then(function(resp) {
resp.complete('success')
.then(function() {
print(JSON.stringify(resp, undefined, 2));
})
.catch(function(error) {
print(error);
});
}) })
.catch(function(error) { .catch(function(error) {
print(error); print(error);
...@@ -84,24 +85,11 @@ function queryShow() { // eslint-disable-line no-unused-vars ...@@ -84,24 +85,11 @@ function queryShow() { // eslint-disable-line no-unused-vars
/** /**
* Queries CanMakePayment but does not show the PaymentRequest after. * Queries CanMakePayment but does not show the PaymentRequest after.
*/ */
function queryNoShow() { // eslint-disable-line no-unused-vars async function queryNoShow() { // eslint-disable-line no-unused-vars
try { try {
request = new PaymentRequest( request = new PaymentRequest([bobPayMethod, visaMethod], defaultDetails);
[ print(await request.canMakePayment());
{supportedMethods: 'https://bobpay.com'}, print(await request.hasEnrolledInstrument());
{
supportedMethods: 'basic-card',
data: {supportedNetworks: ['visa']},
},
],
{total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}});
request.canMakePayment()
.then(function(result) {
print(result);
})
.catch(function(error) {
print(error);
});
} catch (error) { } catch (error) {
print(error.message); print(error.message);
} }
......
...@@ -65,3 +65,19 @@ function canMakePayment() { // eslint-disable-line no-unused-vars ...@@ -65,3 +65,19 @@ function canMakePayment() { // eslint-disable-line no-unused-vars
print(error); print(error);
} }
} }
/** Checks whether an active debit card is ready for payment. */
function hasEnrolledInstrument() { // eslint-disable-line no-unused-vars
try {
buildPaymentRequest()
.hasEnrolledInstrument()
.then(function(result) {
print(result);
})
.catch(function(error) {
print(error);
});
} catch (error) {
print(error);
}
}
...@@ -16,6 +16,9 @@ found in the LICENSE file. ...@@ -16,6 +16,9 @@ found in the LICENSE file.
<button onclick="hasEnrolledInstrument('visa')" id="has-enrolled-instrument-visa"> <button onclick="hasEnrolledInstrument('visa')" id="has-enrolled-instrument-visa">
VISA hasEnrolledInstrument Test VISA hasEnrolledInstrument Test
</button> </button>
<button onclick="hasEnrolledInstrument('mastercard')" id="has-enrolled-instrument-mastercard">
Mastercard hasEnrolledInstrument Test
</button>
<pre id="result"></pre> <pre id="result"></pre>
<script src="util.js"></script> <script src="util.js"></script>
<script src="can_make_payment_query_cc.js"></script> <script src="can_make_payment_query_cc.js"></script>
......
...@@ -13,6 +13,7 @@ found in the LICENSE file. ...@@ -13,6 +13,7 @@ found in the LICENSE file.
</head> </head>
<body> <body>
<button onclick="buy()" id="buy">Active Payment Query Test</button> <button onclick="buy()" id="buy">Active Payment Query Test</button>
<button onclick="hasEnrolledInstrument()" id="hasEnrolledInstrument">Check hasEnrolledInstrument</button>
<pre id="result"></pre> <pre id="result"></pre>
<script src="util.js"></script> <script src="util.js"></script>
<script src="can_make_payment_query.js"></script> <script src="can_make_payment_query.js"></script>
......
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