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 static org.chromium.chrome.browser.payments.PaymentRequestTestRule.DECEMBER; 8 import static org.chromium.chrome.browser.payments.PaymentRequestTestRule.FIRST_BILLING_ADDRESS; 9 import static org.chromium.chrome.browser.payments.PaymentRequestTestRule.NEXT_YEAR; 10 11 import androidx.test.filters.MediumTest; 12 13 import org.junit.Before; 14 import org.junit.ClassRule; 15 import org.junit.Rule; 16 import org.junit.Test; 17 import org.junit.runner.RunWith; 18 19 import org.chromium.base.test.util.CommandLineFlags; 20 import org.chromium.base.test.util.Feature; 21 import org.chromium.chrome.R; 22 import org.chromium.chrome.browser.autofill.AutofillTestHelper; 23 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; 24 import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; 25 import org.chromium.chrome.browser.flags.ChromeSwitches; 26 import org.chromium.chrome.browser.payments.PaymentRequestTestRule.MainActivityStartCallback; 27 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; 28 import org.chromium.components.payments.PaymentRequestService; 29 import org.chromium.ui.modaldialog.ModalDialogProperties; 30 import org.chromium.ui.test.util.DisableAnimationsTestRule; 31 32 import java.util.concurrent.TimeoutException; 33 34 /** 35 * A payment integration test for supported payment methods. 36 */ 37 @RunWith(ChromeJUnit4ClassRunner.class) 38 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) 39 public class PaymentRequestPaymentMethodIdentifierTest implements MainActivityStartCallback { 40 // Disable animations to reduce flakiness. 41 @ClassRule 42 public static DisableAnimationsTestRule sNoAnimationsRule = new DisableAnimationsTestRule(); 43 44 @Rule 45 public PaymentRequestTestRule mPaymentRequestTestRule = 46 new PaymentRequestTestRule("payment_request_payment_method_identifier_test.html", this); 47 48 @Before setUp()49 public void setUp() { 50 PaymentRequestService.setIsLocalHasEnrolledInstrumentQueryQuotaEnforcedForTest(); 51 } 52 53 @Override onMainActivityStarted()54 public void onMainActivityStarted() throws TimeoutException { 55 // The user has a valid "visa" card. 56 AutofillTestHelper helper = new AutofillTestHelper(); 57 String billingAddressId = helper.setProfile(new AutofillProfile("", "https://example.com", 58 true, "" /* honorific prefix */, "Jon Doe", "Google", "340 Main St", "CA", 59 "Los Angeles", "", "90291", "", "US", "555-555-5555", "", "en-US")); 60 helper.setCreditCard(new CreditCard("", "https://example.com", true, true, "Jon Doe", 61 "4111111111111111", "1111", "12", "2050", "visa", R.drawable.visa_card, 62 billingAddressId, "" /* serverId */)); 63 } 64 65 @Test 66 @MediumTest 67 @Feature({"Payments"}) testCanPayWithBasicCard()68 public void testCanPayWithBasicCard() throws TimeoutException { 69 mPaymentRequestTestRule.openPageAndClickNodeAndWait( 70 "checkBasicCard", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); 71 mPaymentRequestTestRule.expectResultContains(new String[] {"true"}); 72 73 mPaymentRequestTestRule.clickNodeAndWait( 74 "buyBasicCard", mPaymentRequestTestRule.getReadyForInput()); 75 } 76 77 @Test 78 @MediumTest 79 @Feature({"Payments"}) 80 @CommandLineFlags.Add("disable-features=StrictHasEnrolledAutofillInstrument") testCannotMakeActivePaymentWithBasicMasterCard()81 public void testCannotMakeActivePaymentWithBasicMasterCard() throws TimeoutException { 82 mPaymentRequestTestRule.openPageAndClickNodeAndWait( 83 "checkBasicMasterCard", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); 84 mPaymentRequestTestRule.expectResultContains(new String[] {"true"}); 85 86 mPaymentRequestTestRule.reTriggerUIAndWait( 87 "buyBasicMasterCard", mPaymentRequestTestRule.getReadyForInput()); 88 } 89 90 @Test 91 @MediumTest 92 @Feature({"Payments"}) testSupportedNetworksMustMatchForCanMakePayment()93 public void testSupportedNetworksMustMatchForCanMakePayment() throws TimeoutException { 94 mPaymentRequestTestRule.openPageAndClickNodeAndWait( 95 "checkBasicVisa", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); 96 mPaymentRequestTestRule.expectResultContains(new String[] {"true"}); 97 98 mPaymentRequestTestRule.clickNodeAndWait( 99 "checkBasicMasterCard", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); 100 mPaymentRequestTestRule.expectResultContains(new String[] {"true"}); 101 102 mPaymentRequestTestRule.clickNodeAndWait( 103 "checkBasicVisa", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); 104 mPaymentRequestTestRule.expectResultContains(new String[] {"true"}); 105 } 106 107 /** 108 * If the merchant requests supported method of "basic-card" with "mastercard" and "visa" 109 * network support, then the user should be able to pay via their "visa" card. The merchant will 110 * receive the "basic-card" method name. 111 */ 112 @Test 113 @MediumTest 114 @Feature({"Payments"}) testPayWithBasicCard()115 public void testPayWithBasicCard() throws TimeoutException { 116 mPaymentRequestTestRule.openPageAndClickNodeAndWait( 117 "checkBasicVisa", mPaymentRequestTestRule.getCanMakePaymentQueryResponded()); 118 mPaymentRequestTestRule.expectResultContains(new String[] {"true"}); 119 120 mPaymentRequestTestRule.reTriggerUIAndWait("buy", mPaymentRequestTestRule.getReadyToPay()); 121 mPaymentRequestTestRule.clickAndWait( 122 R.id.button_primary, mPaymentRequestTestRule.getReadyForUnmaskInput()); 123 mPaymentRequestTestRule.setTextInCardUnmaskDialogAndWait( 124 R.id.card_unmask_input, "123", mPaymentRequestTestRule.getReadyToUnmask()); 125 mPaymentRequestTestRule.clickCardUnmaskButtonAndWait( 126 ModalDialogProperties.ButtonType.POSITIVE, mPaymentRequestTestRule.getDismissed()); 127 mPaymentRequestTestRule.expectResultContains( 128 new String[] {"Jon Doe", "4111111111111111", "12", "2050", "basic-card", "123"}); 129 } 130 131 /** 132 * If the merchant requests supported method of "basic-card" with "mastercard" and "visa" 133 * network support, then the user should be able to add a "mastercard" card and pay with it. The 134 * merchant will receive the "basic-card" method name. 135 */ 136 @Test 137 @MediumTest 138 @Feature({"Payments"}) testAddMasterCard()139 public void testAddMasterCard() throws TimeoutException { 140 mPaymentRequestTestRule.triggerUIAndWait(mPaymentRequestTestRule.getReadyToPay()); 141 mPaymentRequestTestRule.clickInPaymentMethodAndWait( 142 R.id.payments_section, mPaymentRequestTestRule.getReadyForInput()); 143 mPaymentRequestTestRule.clickInPaymentMethodAndWait( 144 R.id.payments_add_option_button, mPaymentRequestTestRule.getReadyToEdit()); 145 mPaymentRequestTestRule.setTextInCardEditorAndWait( 146 new String[] {"5555-5555-5555-4444", "Jane Jones"}, 147 mPaymentRequestTestRule.getEditorTextUpdate()); 148 mPaymentRequestTestRule.setSpinnerSelectionsInCardEditorAndWait( 149 new int[] {DECEMBER, NEXT_YEAR, FIRST_BILLING_ADDRESS}, 150 mPaymentRequestTestRule.getBillingAddressChangeProcessed()); 151 mPaymentRequestTestRule.clickInCardEditorAndWait( 152 R.id.editor_dialog_done_button, mPaymentRequestTestRule.getReadyToPay()); 153 mPaymentRequestTestRule.clickAndWait( 154 R.id.button_primary, mPaymentRequestTestRule.getReadyForUnmaskInput()); 155 mPaymentRequestTestRule.setTextInCardUnmaskDialogAndWait( 156 R.id.card_unmask_input, "123", mPaymentRequestTestRule.getReadyToUnmask()); 157 mPaymentRequestTestRule.clickCardUnmaskButtonAndWait( 158 ModalDialogProperties.ButtonType.POSITIVE, mPaymentRequestTestRule.getDismissed()); 159 mPaymentRequestTestRule.expectResultContains( 160 new String[] {"5555555555554444", "12", "Jane Jones", "123", "basic-card"}); 161 } 162 163 /** 164 * If the merchant requests supported method of "basic-card" with "mastercard" and "visa" 165 * network support, then the user should be able to add a new "visa" card and pay with it. The 166 * merchant will receive the "basic-card" method name. 167 */ 168 @Test 169 @MediumTest 170 @Feature({"Payments"}) testAddBasicCard()171 public void testAddBasicCard() throws TimeoutException { 172 mPaymentRequestTestRule.triggerUIAndWait(mPaymentRequestTestRule.getReadyToPay()); 173 mPaymentRequestTestRule.clickInPaymentMethodAndWait( 174 R.id.payments_section, mPaymentRequestTestRule.getReadyForInput()); 175 mPaymentRequestTestRule.clickInPaymentMethodAndWait( 176 R.id.payments_add_option_button, mPaymentRequestTestRule.getReadyToEdit()); 177 mPaymentRequestTestRule.setTextInCardEditorAndWait( 178 new String[] {"4242-4242-4242-4242", "Jane Jones"}, 179 mPaymentRequestTestRule.getEditorTextUpdate()); 180 mPaymentRequestTestRule.setSpinnerSelectionsInCardEditorAndWait( 181 new int[] {DECEMBER, NEXT_YEAR, FIRST_BILLING_ADDRESS}, 182 mPaymentRequestTestRule.getBillingAddressChangeProcessed()); 183 mPaymentRequestTestRule.clickInCardEditorAndWait( 184 R.id.editor_dialog_done_button, mPaymentRequestTestRule.getReadyToPay()); 185 mPaymentRequestTestRule.clickAndWait( 186 R.id.button_primary, mPaymentRequestTestRule.getReadyForUnmaskInput()); 187 mPaymentRequestTestRule.setTextInCardUnmaskDialogAndWait( 188 R.id.card_unmask_input, "123", mPaymentRequestTestRule.getReadyToUnmask()); 189 mPaymentRequestTestRule.clickCardUnmaskButtonAndWait( 190 ModalDialogProperties.ButtonType.POSITIVE, mPaymentRequestTestRule.getDismissed()); 191 mPaymentRequestTestRule.expectResultContains( 192 new String[] {"4242424242424242", "12", "Jane Jones", "123", "basic-card"}); 193 } 194 } 195