| OLD | NEW |
| (Empty) | |
| 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 android.content.DialogInterface; |
| 8 import android.test.suitebuilder.annotation.MediumTest; |
| 9 |
| 10 import org.chromium.base.test.util.CommandLineFlags; |
| 11 import org.chromium.base.test.util.Feature; |
| 12 import org.chromium.chrome.R; |
| 13 import org.chromium.chrome.browser.autofill.AutofillTestHelper; |
| 14 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; |
| 15 import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; |
| 16 |
| 17 import java.util.concurrent.ExecutionException; |
| 18 import java.util.concurrent.TimeoutException; |
| 19 |
| 20 /** |
| 21 * A payment integration test for "basic-card" payment method. |
| 22 */ |
| 23 @CommandLineFlags.Add("enable-blink-features=CanMakeActivePayment") |
| 24 public class PaymentRequestBasicCardTest extends PaymentRequestTestBase { |
| 25 public PaymentRequestBasicCardTest() { |
| 26 super("payment_request_basic_card_test.html"); |
| 27 } |
| 28 |
| 29 @Override |
| 30 public void onMainActivityStarted() throws InterruptedException, ExecutionEx
ception, |
| 31 TimeoutException { |
| 32 // The user has a valid "visa" card. |
| 33 AutofillTestHelper helper = new AutofillTestHelper(); |
| 34 String billingAddressId = helper.setProfile(new AutofillProfile("", "htt
ps://example.com", |
| 35 true, "Jon Doe", "Google", "340 Main St", "CA", "Los Angeles", "
", "90291", "", |
| 36 "US", "555-555-5555", "", "en-US")); |
| 37 helper.setCreditCard(new CreditCard("", "https://example.com", true, tru
e, "Jon Doe", |
| 38 "4111111111111111", "1111", "12", "2050", "visa", R.drawable.pr_
visa, |
| 39 billingAddressId, "" /* serverId */)); |
| 40 } |
| 41 |
| 42 @MediumTest |
| 43 @Feature({"Payments"}) |
| 44 public void testCannotMakeActivePaymentWithBasicDebitCard() throws Interrupt
edException, |
| 45 ExecutionException, TimeoutException { |
| 46 openPageAndClickNodeAndWait("checkBasicDebit", mActivePaymentQueryRespon
ded); |
| 47 expectResultContains(new String[]{"false"}); |
| 48 |
| 49 clickNodeAndWait("buyBasicDebit", mShowFailed); |
| 50 expectResultContains(new String[] {"The payment method is not supported"
}); |
| 51 } |
| 52 |
| 53 @MediumTest |
| 54 @Feature({"Payments"}) |
| 55 public void testCannotMakeActivePaymentWithBasicMasterCard() throws Interrup
tedException, |
| 56 ExecutionException, TimeoutException { |
| 57 openPageAndClickNodeAndWait("checkBasicMasterCard", mActivePaymentQueryR
esponded); |
| 58 expectResultContains(new String[]{"false"}); |
| 59 |
| 60 reTriggerUIAndWait("buyBasicMasterCard", mReadyForInput); |
| 61 } |
| 62 |
| 63 /** |
| 64 * To prevent fingerprinting the user, repeated queries for "basic-card" pay
ment method return |
| 65 * cached results, even if the queries were performed with different sets of
"supportedNetworks" |
| 66 * and "supportedTypes" every time. |
| 67 */ |
| 68 @MediumTest |
| 69 @Feature({"Payments"}) |
| 70 public void testReturnsCachedResultForBasiCard() throws InterruptedException
, |
| 71 ExecutionException, TimeoutException { |
| 72 openPageAndClickNodeAndWait("checkBasicVisa", mActivePaymentQueryRespond
ed); |
| 73 expectResultContains(new String[]{"true"}); |
| 74 |
| 75 clickNodeAndWait("checkBasicVisa", mActivePaymentQueryResponded); |
| 76 expectResultContains(new String[]{"true"}); |
| 77 |
| 78 // Cached result for "basic-card" is "true", even though the user does n
ot have a MasterCard |
| 79 // on file. |
| 80 clickNodeAndWait("checkBasicMasterCard", mActivePaymentQueryResponded); |
| 81 expectResultContains(new String[]{"true"}); |
| 82 |
| 83 // Cached result for "basic-card" is "true", even though Chrome cannot d
istinguish debit |
| 84 // cards from credit cards. |
| 85 clickNodeAndWait("checkBasicDebit", mActivePaymentQueryResponded); |
| 86 expectResultContains(new String[]{"true"}); |
| 87 |
| 88 // Checking for "visa" immediately after "basic-card" triggers throttlin
g. |
| 89 clickNodeAndWait("checkVisa", mActivePaymentQueryResponded); |
| 90 expectResultContains(new String[]{"Query quota exceeded"}); |
| 91 |
| 92 // Checking for "mastercard" immediately after "basic-card" triggers thr
ottling. |
| 93 clickNodeAndWait("checkMasterCard", mActivePaymentQueryResponded); |
| 94 expectResultContains(new String[]{"Query quota exceeded"}); |
| 95 } |
| 96 |
| 97 /** |
| 98 * If the merchant requests supported methods of "mastercard" and "basic-car
d" with "visa" |
| 99 * network support, then the user should be able to pay via their "visa" car
d. The merchant will |
| 100 * receive the "basic-card" method name. |
| 101 */ |
| 102 @MediumTest |
| 103 @Feature({"Payments"}) |
| 104 public void testPayWithBasicCard() throws InterruptedException, ExecutionEx
ception, |
| 105 TimeoutException { |
| 106 openPageAndClickNodeAndWait("checkBasicVisa", mActivePaymentQueryRespond
ed); |
| 107 expectResultContains(new String[]{"true"}); |
| 108 |
| 109 reTriggerUIAndWait("buy", mReadyToPay); |
| 110 clickAndWait(R.id.button_primary, mReadyForUnmaskInput); |
| 111 setTextInCardUnmaskDialogAndWait(R.id.card_unmask_input, "123", mReadyTo
Unmask); |
| 112 clickCardUnmaskButtonAndWait(DialogInterface.BUTTON_POSITIVE, mDismissed
); |
| 113 expectResultContains(new String[] {"Jon Doe", "4111111111111111", "12",
"2050", |
| 114 "basic-card", "123"}); |
| 115 } |
| 116 |
| 117 /** |
| 118 * If the merchant requests supported methods of "mastercard" and "basic-car
d" with "visa" |
| 119 * network support, then the user should be able to add a "mastercard" card
and pay with it. The |
| 120 * merchant will receive the "mastercard" method name. |
| 121 */ |
| 122 @MediumTest |
| 123 @Feature({"Payments"}) |
| 124 public void testAddMasterCard() throws InterruptedException, ExecutionExcep
tion, |
| 125 TimeoutException { |
| 126 triggerUIAndWait(mReadyToPay); |
| 127 clickInPaymentMethodAndWait(R.id.payments_section, mReadyForInput); |
| 128 clickInPaymentMethodAndWait(R.id.payments_add_option_button, mReadyToEdi
t); |
| 129 setTextInCardEditorAndWait(new String[] {"5555-5555-5555-4444", "Jane Jo
nes"}, |
| 130 mEditorTextUpdate); |
| 131 setSpinnerSelectionsInCardEditorAndWait( |
| 132 new int[] {DECEMBER, NEXT_YEAR, FIRST_BILLING_ADDRESS}, |
| 133 mBillingAddressChangeProcessed); |
| 134 clickInCardEditorAndWait(R.id.payments_edit_done_button, mReadyToPay); |
| 135 clickAndWait(R.id.button_primary, mReadyForUnmaskInput); |
| 136 setTextInCardUnmaskDialogAndWait(R.id.card_unmask_input, "123", mReadyTo
Unmask); |
| 137 clickCardUnmaskButtonAndWait(DialogInterface.BUTTON_POSITIVE, mDismissed
); |
| 138 expectResultContains( |
| 139 new String[] {"5555555555554444", "12", "Jane Jones", "123", "ma
stercard"}); |
| 140 } |
| 141 |
| 142 /** |
| 143 * If the merchant requests supported methods of "mastercard" and "basic-car
d" with "visa" |
| 144 * network support, then the user should be able to add a new "visa" card an
d pay with it. The |
| 145 * merchant will receive the "basic-card" method name. |
| 146 */ |
| 147 @MediumTest |
| 148 @Feature({"Payments"}) |
| 149 public void testAddBasicCard() throws InterruptedException, ExecutionExcept
ion, |
| 150 TimeoutException { |
| 151 triggerUIAndWait(mReadyToPay); |
| 152 clickInPaymentMethodAndWait(R.id.payments_section, mReadyForInput); |
| 153 clickInPaymentMethodAndWait(R.id.payments_add_option_button, mReadyToEdi
t); |
| 154 setTextInCardEditorAndWait(new String[] {"4242-4242-4242-4242", "Jane Jo
nes"}, |
| 155 mEditorTextUpdate); |
| 156 setSpinnerSelectionsInCardEditorAndWait( |
| 157 new int[] {DECEMBER, NEXT_YEAR, FIRST_BILLING_ADDRESS}, |
| 158 mBillingAddressChangeProcessed); |
| 159 clickInCardEditorAndWait(R.id.payments_edit_done_button, mReadyToPay); |
| 160 clickAndWait(R.id.button_primary, mReadyForUnmaskInput); |
| 161 setTextInCardUnmaskDialogAndWait(R.id.card_unmask_input, "123", mReadyTo
Unmask); |
| 162 clickCardUnmaskButtonAndWait(DialogInterface.BUTTON_POSITIVE, mDismissed
); |
| 163 expectResultContains( |
| 164 new String[] {"4242424242424242", "12", "Jane Jones", "123", "ba
sic-card"}); |
| 165 } |
| 166 } |
| OLD | NEW |