| // Copyright 2016 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.content.DialogInterface; |
| import android.test.suitebuilder.annotation.MediumTest; |
| |
| import org.chromium.base.metrics.RecordHistogram; |
| import org.chromium.base.test.util.Feature; |
| import org.chromium.chrome.R; |
| import org.chromium.chrome.browser.autofill.AutofillTestHelper; |
| import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; |
| import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; |
| |
| import java.util.concurrent.ExecutionException; |
| import java.util.concurrent.TimeoutException; |
| |
| /** |
| * A payment integration test for a merchant that requests payer name. |
| */ |
| public class PaymentRequestNameTest extends PaymentRequestTestBase { |
| public PaymentRequestNameTest() { |
| // This merchant request a payer name. |
| super("payment_request_name_test.html"); |
| } |
| |
| @Override |
| public void onMainActivityStarted() |
| throws InterruptedException, ExecutionException, TimeoutException { |
| AutofillTestHelper helper = new AutofillTestHelper(); |
| // The user has a valid payer name on disk. |
| String billingAddressId = helper.setProfile(new AutofillProfile("", "https://example.com", |
| true, "Jon Doe", "Google", "340 Main St", "CA", "Los Angeles", "", "90291", "", |
| "US", "555-555-5555", "jon.doe@google.com", "en-US")); |
| helper.setCreditCard(new CreditCard("", "https://example.com", true, true, "Jon Doe", |
| "4111111111111111", "1111", "12", "2050", "visa", R.drawable.pr_visa, |
| billingAddressId, "" /* serverId */)); |
| } |
| |
| /** Provide the existing valid payer name to the merchant. */ |
| @MediumTest |
| @Feature({"Payments"}) |
| public void testPay() throws InterruptedException, ExecutionException, TimeoutException { |
| triggerUIAndWait(mReadyToPay); |
| clickAndWait(R.id.button_primary, mReadyForUnmaskInput); |
| setTextInCardUnmaskDialogAndWait(R.id.card_unmask_input, "123", mReadyToUnmask); |
| clickCardUnmaskButtonAndWait(DialogInterface.BUTTON_POSITIVE, mDismissed); |
| expectResultContains(new String[] {"Jon Doe"}); |
| } |
| |
| /** Attempt to add an invalid payer name and cancel the transaction. */ |
| @MediumTest |
| @Feature({"Payments"}) |
| public void testAddInvalidNameAndCancel() |
| throws InterruptedException, ExecutionException, TimeoutException { |
| triggerUIAndWait(mReadyToPay); |
| clickInContactInfoAndWait(R.id.payments_section, mReadyForInput); |
| clickInContactInfoAndWait(R.id.payments_add_option_button, mReadyToEdit); |
| setTextInEditorAndWait(new String[] {""}, mEditorTextUpdate); |
| clickInEditorAndWait(R.id.payments_edit_done_button, mEditorValidationError); |
| clickInEditorAndWait(R.id.payments_edit_cancel_button, mReadyForInput); |
| clickAndWait(R.id.close_button, mDismissed); |
| expectResultContains(new String[] {"Request cancelled"}); |
| } |
| |
| /** Add a new payer name and provide that to the merchant. */ |
| @MediumTest |
| @Feature({"Payments"}) |
| public void testAddNameAndPay() |
| throws InterruptedException, ExecutionException, TimeoutException { |
| triggerUIAndWait(mReadyToPay); |
| clickInContactInfoAndWait(R.id.payments_section, mReadyForInput); |
| clickInContactInfoAndWait(R.id.payments_add_option_button, mReadyToEdit); |
| setTextInEditorAndWait(new String[] {"Jane Jones"}, mEditorTextUpdate); |
| clickInEditorAndWait(R.id.payments_edit_done_button, mReadyToPay); |
| clickAndWait(R.id.button_primary, mReadyForUnmaskInput); |
| setTextInCardUnmaskDialogAndWait(R.id.card_unmask_input, "123", mReadyToUnmask); |
| clickCardUnmaskButtonAndWait(DialogInterface.BUTTON_POSITIVE, mDismissed); |
| expectResultContains(new String[] {"Jane Jones"}); |
| } |
| |
| /** |
| * Test that starting a payment request that requires only the user's payer name results in |
| * the appropriate metric being logged in the PaymentRequest.RequestedInformation histogram. |
| */ |
| @MediumTest |
| @Feature({"Payments"}) |
| public void testRequestedInformationMetric() throws InterruptedException, ExecutionException, |
| TimeoutException { |
| // Start the Payment Request. |
| triggerUIAndWait(mReadyToPay); |
| |
| // Make sure that only the appropriate enum value was logged. |
| for (int i = 0; i < PaymentRequestMetrics.REQUESTED_INFORMATION_MAX; ++i) { |
| assertEquals((i == PaymentRequestMetrics.REQUESTED_INFORMATION_EMAIL ? 1 : 0), |
| RecordHistogram.getHistogramValueCountForTesting( |
| "PaymentRequest.RequestedInformation", i)); |
| } |
| } |
| } |