blob: ed0c70f0adecf482c8fc2efbfa222551b432fb4a [file] [log] [blame]
// 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.support.test.filters.MediumTest;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.autofill.AutofillTestHelper;
import org.chromium.chrome.browser.autofill.CardType;
import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard;
import org.chromium.chrome.browser.payments.PaymentRequestTestRule.MainActivityStartCallback;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
/**
* A payment integration test for a merchant that requests payer name.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({
ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG,
})
public class PaymentRequestNameTest implements MainActivityStartCallback {
@Rule
public PaymentRequestTestRule mPaymentRequestTestRule =
new PaymentRequestTestRule("payment_request_name_test.html", this);
@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.visa_card,
CardType.UNKNOWN, billingAddressId, "" /* serverId */));
// Add the same profile but with a different address.
helper.setProfile(new AutofillProfile("", "https://example.com", true, "", "Google",
"999 Main St", "CA", "Los Angeles", "", "90291", "", "US", "555-555-5555",
"jon.doe@google.com", "en-US"));
// Add the same profile but without a phone number.
helper.setProfile(new AutofillProfile("", "https://example.com", true, "Jon Doe", "Google",
"340 Main St", "CA", "Los Angeles", "", "90291", "", "US", "" /* phone_number */,
"jon.doe@google.com", "en-US"));
// Add the same profile but without an email.
helper.setProfile(new AutofillProfile("", "https://example.com", true, "Jon Doe", "Google",
"340 Main St", "CA", "Los Angeles", "", "90291", "", "US", "555-555-5555",
"" /* emailAddress */, "en-US"));
// Add the same profile but without a name.
helper.setProfile(new AutofillProfile("" /* name */, "https://example.com", true, "",
"Google", "340 Main St", "CA", "Los Angeles", "", "90291", "", "US", "555-555-5555",
"jon.doe@google.com", "en-US"));
}
/** Provide the existing valid payer name to the merchant. */
@Test
@MediumTest
@Feature({"Payments"})
public void testPay() throws InterruptedException, ExecutionException, TimeoutException {
mPaymentRequestTestRule.triggerUIAndWait(mPaymentRequestTestRule.getReadyToPay());
mPaymentRequestTestRule.clickAndWait(
R.id.button_primary, mPaymentRequestTestRule.getReadyForUnmaskInput());
mPaymentRequestTestRule.setTextInCardUnmaskDialogAndWait(
R.id.card_unmask_input, "123", mPaymentRequestTestRule.getReadyToUnmask());
mPaymentRequestTestRule.clickCardUnmaskButtonAndWait(
DialogInterface.BUTTON_POSITIVE, mPaymentRequestTestRule.getDismissed());
mPaymentRequestTestRule.expectResultContains(new String[] {"Jon Doe"});
}
/** Attempt to add an invalid payer name and cancel the transaction. */
@Test
@MediumTest
@Feature({"Payments"})
public void testAddInvalidNameAndCancel()
throws InterruptedException, ExecutionException, TimeoutException {
mPaymentRequestTestRule.triggerUIAndWait(mPaymentRequestTestRule.getReadyToPay());
mPaymentRequestTestRule.clickInContactInfoAndWait(
R.id.payments_section, mPaymentRequestTestRule.getReadyForInput());
mPaymentRequestTestRule.clickInContactInfoAndWait(
R.id.payments_add_option_button, mPaymentRequestTestRule.getReadyToEdit());
mPaymentRequestTestRule.setTextInEditorAndWait(
new String[] {""}, mPaymentRequestTestRule.getEditorTextUpdate());
mPaymentRequestTestRule.clickInEditorAndWait(
R.id.payments_edit_done_button, mPaymentRequestTestRule.getEditorValidationError());
mPaymentRequestTestRule.clickInEditorAndWait(
R.id.payments_edit_cancel_button, mPaymentRequestTestRule.getReadyToPay());
mPaymentRequestTestRule.clickAndWait(
R.id.close_button, mPaymentRequestTestRule.getDismissed());
mPaymentRequestTestRule.expectResultContains(new String[] {"Request cancelled"});
}
/** Add a new payer name and provide that to the merchant. */
@Test
@MediumTest
@Feature({"Payments"})
public void testAddNameAndPay()
throws InterruptedException, ExecutionException, TimeoutException {
mPaymentRequestTestRule.triggerUIAndWait(mPaymentRequestTestRule.getReadyToPay());
mPaymentRequestTestRule.clickInContactInfoAndWait(
R.id.payments_section, mPaymentRequestTestRule.getReadyForInput());
mPaymentRequestTestRule.clickInContactInfoAndWait(
R.id.payments_add_option_button, mPaymentRequestTestRule.getReadyToEdit());
mPaymentRequestTestRule.setTextInEditorAndWait(
new String[] {"Jane Jones"}, mPaymentRequestTestRule.getEditorTextUpdate());
mPaymentRequestTestRule.clickInEditorAndWait(
R.id.payments_edit_done_button, mPaymentRequestTestRule.getReadyToPay());
mPaymentRequestTestRule.clickAndWait(
R.id.button_primary, mPaymentRequestTestRule.getReadyForUnmaskInput());
mPaymentRequestTestRule.setTextInCardUnmaskDialogAndWait(
R.id.card_unmask_input, "123", mPaymentRequestTestRule.getReadyToUnmask());
mPaymentRequestTestRule.clickCardUnmaskButtonAndWait(
DialogInterface.BUTTON_POSITIVE, mPaymentRequestTestRule.getDismissed());
mPaymentRequestTestRule.expectResultContains(new String[] {"Jane Jones"});
}
/**
* Makes sure that suggestions that are equal to or subsets of other suggestions are not shown
* to the user.
*/
@Test
@MediumTest
@Feature({"Payments"})
public void testSuggestionsDeduped()
throws InterruptedException, ExecutionException, TimeoutException {
mPaymentRequestTestRule.triggerUIAndWait(mPaymentRequestTestRule.getReadyToPay());
mPaymentRequestTestRule.clickInContactInfoAndWait(
R.id.payments_section, mPaymentRequestTestRule.getReadyForInput());
Assert.assertEquals(1, mPaymentRequestTestRule.getNumberOfContactDetailSuggestions());
}
/**
* Test that ending a payment request that requires only the user's payer name results in
* the appropriate metric being logged in PaymentRequest.Events.
*/
@Test
@MediumTest
@Feature({"Payments"})
public void testPaymentRequestEventsMetric()
throws InterruptedException, ExecutionException, TimeoutException {
// Start and complete the Payment Request.
mPaymentRequestTestRule.triggerUIAndWait(mPaymentRequestTestRule.getReadyToPay());
mPaymentRequestTestRule.clickAndWait(
R.id.button_primary, mPaymentRequestTestRule.getReadyForUnmaskInput());
mPaymentRequestTestRule.setTextInCardUnmaskDialogAndWait(
R.id.card_unmask_input, "123", mPaymentRequestTestRule.getReadyToUnmask());
mPaymentRequestTestRule.clickCardUnmaskButtonAndWait(
DialogInterface.BUTTON_POSITIVE, mPaymentRequestTestRule.getDismissed());
mPaymentRequestTestRule.expectResultContains(new String[] {"Jon Doe"});
int expectedSample = Event.SHOWN | Event.PAY_CLICKED | Event.RECEIVED_INSTRUMENT_DETAILS
| Event.COMPLETED | Event.HAD_INITIAL_FORM_OF_PAYMENT
| Event.HAD_NECESSARY_COMPLETE_SUGGESTIONS | Event.REQUEST_PAYER_NAME
| Event.REQUEST_METHOD_BASIC_CARD;
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.Events", expectedSample));
}
}