1 // Copyright 2016 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package org.chromium.chrome.browser.payments; 6 7 import androidx.test.filters.MediumTest; 8 9 import org.junit.ClassRule; 10 import org.junit.Rule; 11 import org.junit.Test; 12 import org.junit.runner.RunWith; 13 14 import org.chromium.base.test.util.CommandLineFlags; 15 import org.chromium.base.test.util.Feature; 16 import org.chromium.chrome.browser.flags.ChromeSwitches; 17 import org.chromium.chrome.browser.payments.PaymentRequestTestRule.AppPresence; 18 import org.chromium.chrome.browser.payments.PaymentRequestTestRule.FactorySpeed; 19 import org.chromium.chrome.browser.payments.PaymentRequestTestRule.MainActivityStartCallback; 20 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; 21 import org.chromium.ui.test.util.DisableAnimationsTestRule; 22 23 import java.util.concurrent.TimeoutException; 24 25 /** 26 * A payment integration test for checking whether user can make a payment using a payment app. 27 */ 28 @RunWith(ChromeJUnit4ClassRunner.class) 29 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) 30 public class PaymentRequestPaymentAppCanMakePaymentQueryTest implements MainActivityStartCallback { 31 // Disable animations to reduce flakiness. 32 @ClassRule 33 public static DisableAnimationsTestRule sNoAnimationsRule = new DisableAnimationsTestRule(); 34 35 @Rule 36 public PaymentRequestTestRule mPaymentRequestTestRule = new PaymentRequestTestRule( 37 "payment_request_can_make_payment_query_bobpay_test.html", this); 38 39 @Override onMainActivityStarted()40 public void onMainActivityStarted() {} 41 42 @Test 43 @MediumTest 44 @Feature({"Payments"}) testBobPayInstalledLater()45 public void testBobPayInstalledLater() throws InterruptedException, TimeoutException { 46 // hasEnrolledInstrument returns false, since BobPay is not installed. 47 mPaymentRequestTestRule.openPageAndClickNodeAndWait("hasEnrolledInstrument", 48 mPaymentRequestTestRule.getHasEnrolledInstrumentQueryResponded()); 49 mPaymentRequestTestRule.expectResultContains(new String[] {"false, false"}); 50 51 mPaymentRequestTestRule.addPaymentAppFactory( 52 AppPresence.HAVE_APPS, FactorySpeed.FAST_FACTORY); 53 Thread.sleep(10000); 54 55 // hasEnrolledInstrument returns true now for BobPay, but still returns false for AlicePay. 56 mPaymentRequestTestRule.clickNodeAndWait("hasEnrolledInstrument", 57 mPaymentRequestTestRule.getHasEnrolledInstrumentQueryResponded()); 58 mPaymentRequestTestRule.expectResultContains(new String[] {"true, false"}); 59 } 60 61 @Test 62 @MediumTest 63 @Feature({"Payments"}) testNoAppsInFastBobPayFactory()64 public void testNoAppsInFastBobPayFactory() throws TimeoutException { 65 mPaymentRequestTestRule.addPaymentAppFactory( 66 AppPresence.NO_APPS, FactorySpeed.FAST_FACTORY); 67 68 // canMakePayment returns true for BobPay and false for AlicePay. 69 mPaymentRequestTestRule.openPageAndClickNodeAndWait( 70 "otherBuy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); 71 mPaymentRequestTestRule.expectResultContains(new String[] {"true, false"}); 72 73 // hasEnrolledInstrument returns false for BobPay (installed but no instrument) and 74 // false for AlicePay (not installed). 75 mPaymentRequestTestRule.clickNodeAndWait("hasEnrolledInstrument", 76 mPaymentRequestTestRule.getHasEnrolledInstrumentQueryResponded()); 77 mPaymentRequestTestRule.expectResultContains(new String[] {"false, false"}); 78 } 79 80 @Test 81 @MediumTest 82 @Feature({"Payments"}) testNoAppsInSlowBobPayFactory()83 public void testNoAppsInSlowBobPayFactory() throws TimeoutException { 84 // Add BobPay factory. 85 mPaymentRequestTestRule.addPaymentAppFactory( 86 AppPresence.NO_APPS, FactorySpeed.SLOW_FACTORY); 87 88 // canMakePayment returns true for BobPay and false for AlicePay. 89 mPaymentRequestTestRule.openPageAndClickNodeAndWait( 90 "otherBuy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); 91 mPaymentRequestTestRule.expectResultContains(new String[] {"true, false"}); 92 93 // hasEnrolledInstrument returns false for BobPay (installed but no instrument) and 94 // false for AlicePay (not installed). 95 mPaymentRequestTestRule.clickNodeAndWait("hasEnrolledInstrument", 96 mPaymentRequestTestRule.getHasEnrolledInstrumentQueryResponded()); 97 mPaymentRequestTestRule.expectResultContains(new String[] {"false, false"}); 98 } 99 100 @Test 101 @MediumTest 102 @Feature({"Payments"}) testPayViaFastBobPay()103 public void testPayViaFastBobPay() throws TimeoutException { 104 // Install BobPay. 105 mPaymentRequestTestRule.addPaymentAppFactory( 106 AppPresence.HAVE_APPS, FactorySpeed.FAST_FACTORY); 107 108 // canMakePayment returns true for BobPay and false for AlicePay. 109 mPaymentRequestTestRule.openPageAndClickNodeAndWait( 110 "otherBuy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); 111 mPaymentRequestTestRule.expectResultContains(new String[] {"true, false"}); 112 113 // hasEnrolledInstrument returns true for BobPay and false for AlicePay. 114 mPaymentRequestTestRule.clickNodeAndWait("hasEnrolledInstrument", 115 mPaymentRequestTestRule.getHasEnrolledInstrumentQueryResponded()); 116 mPaymentRequestTestRule.expectResultContains(new String[] {"true, false"}); 117 } 118 119 @Test 120 @MediumTest 121 @Feature({"Payments"}) testPayViaSlowBobPayFactory()122 public void testPayViaSlowBobPayFactory() throws TimeoutException { 123 // Install BobPay. 124 mPaymentRequestTestRule.addPaymentAppFactory( 125 AppPresence.HAVE_APPS, FactorySpeed.SLOW_FACTORY); 126 127 // canMakePayment returns true for BobPay and false for AlicePay. 128 mPaymentRequestTestRule.openPageAndClickNodeAndWait( 129 "otherBuy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); 130 mPaymentRequestTestRule.expectResultContains(new String[] {"true, false"}); 131 132 // hasEnrolledInstrument returns true for BobPay and false for AlicePay. 133 mPaymentRequestTestRule.clickNodeAndWait("hasEnrolledInstrument", 134 mPaymentRequestTestRule.getHasEnrolledInstrumentQueryResponded()); 135 mPaymentRequestTestRule.expectResultContains(new String[] {"true, false"}); 136 } 137 } 138