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.Assert; 10 import org.junit.ClassRule; 11 import org.junit.Rule; 12 import org.junit.Test; 13 import org.junit.runner.RunWith; 14 15 import org.chromium.base.test.util.CommandLineFlags; 16 import org.chromium.base.test.util.Feature; 17 import org.chromium.chrome.R; 18 import org.chromium.chrome.browser.autofill.AutofillTestHelper; 19 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; 20 import org.chromium.chrome.browser.flags.ChromeSwitches; 21 import org.chromium.chrome.browser.payments.PaymentRequestTestRule.AppPresence; 22 import org.chromium.chrome.browser.payments.PaymentRequestTestRule.FactorySpeed; 23 import org.chromium.chrome.browser.payments.PaymentRequestTestRule.MainActivityStartCallback; 24 import org.chromium.chrome.browser.payments.ui.PaymentRequestSection; 25 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; 26 import org.chromium.ui.test.util.DisableAnimationsTestRule; 27 28 import java.util.concurrent.TimeoutException; 29 30 /** 31 * A payment integration test for a merchant that requests contact details from a user that has 32 * incomplete contact details stored on disk. 33 */ 34 @RunWith(ChromeJUnit4ClassRunner.class) 35 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) 36 public class PaymentRequestIncompleteContactDetailsTest implements MainActivityStartCallback { 37 // Disable animations to reduce flakiness. 38 @ClassRule 39 public static DisableAnimationsTestRule sNoAnimationsRule = new DisableAnimationsTestRule(); 40 41 @Rule 42 public PaymentRequestTestRule mPaymentRequestTestRule = 43 new PaymentRequestTestRule("payment_request_contact_details_test.html", this); 44 45 @Override onMainActivityStarted()46 public void onMainActivityStarted() throws TimeoutException { 47 AutofillTestHelper helper = new AutofillTestHelper(); 48 // The user has an invalid email address on disk. 49 helper.setProfile( 50 new AutofillProfile("", "https://example.com", true, "" /* honorific prefix */, 51 "Jon Doe", "Google", "340 Main St", "CA", "Los Angeles", "", "90291", "", 52 "US", "333-333-3333", "jon.doe" /* invalid email address */, "en-US")); 53 54 mPaymentRequestTestRule.addPaymentAppFactory( 55 AppPresence.HAVE_APPS, FactorySpeed.FAST_FACTORY); 56 } 57 58 /** Attempt to update the contact information with invalid data and cancel the transaction. */ 59 @Test 60 @MediumTest 61 @Feature({"Payments"}) testEditIncompleteContactAndCancel()62 public void testEditIncompleteContactAndCancel() throws TimeoutException { 63 // Not ready to pay since Contact email is invalid. 64 mPaymentRequestTestRule.triggerUIAndWait(mPaymentRequestTestRule.getReadyForInput()); 65 // Check that there is a selected payment method (makes sure we are not ready to pay because 66 // of the Contact Details). 67 mPaymentRequestTestRule.expectPaymentMethodRowIsSelected(0); 68 // Updating contact with an invalid value and cancelling means we're still not 69 // ready to pay (the value is still the original value). 70 mPaymentRequestTestRule.clickInContactInfoAndWait( 71 R.id.payments_section, mPaymentRequestTestRule.getReadyForInput()); 72 mPaymentRequestTestRule.clickInContactInfoAndWait( 73 R.id.payments_first_radio_button, mPaymentRequestTestRule.getReadyToEdit()); 74 mPaymentRequestTestRule.setTextInEditorAndWait(new String[] {"", "---", "jane.jones"}, 75 mPaymentRequestTestRule.getEditorTextUpdate()); 76 mPaymentRequestTestRule.clickInEditorAndWait( 77 R.id.editor_dialog_done_button, mPaymentRequestTestRule.getEditorValidationError()); 78 // The section collapses and the [CHOOSE] button is active. 79 mPaymentRequestTestRule.clickInEditorAndWait( 80 R.id.payments_edit_cancel_button, mPaymentRequestTestRule.getReadyForInput()); 81 Assert.assertEquals(PaymentRequestSection.EDIT_BUTTON_CHOOSE, 82 mPaymentRequestTestRule.getContactDetailsButtonState()); 83 84 mPaymentRequestTestRule.clickAndWait( 85 R.id.close_button, mPaymentRequestTestRule.getDismissed()); 86 mPaymentRequestTestRule.expectResultContains( 87 new String[] {"User closed the Payment Request UI."}); 88 } 89 90 /** Attempt to add invalid contact info alongside the already invalid info, and cancel. */ 91 @Test 92 @MediumTest 93 @Feature({"Payments"}) testAddIncompleteContactAndCancel()94 public void testAddIncompleteContactAndCancel() throws TimeoutException { 95 // Not ready to pay since Contact email is invalid. 96 mPaymentRequestTestRule.triggerUIAndWait(mPaymentRequestTestRule.getReadyForInput()); 97 // Check that there is a selected payment method (makes sure we are not ready to pay because 98 // of the Contact Details). 99 mPaymentRequestTestRule.expectPaymentMethodRowIsSelected(0); 100 // Adding contact with an invalid value and cancelling means we're still not 101 // ready to pay (the value is still the original value). 102 mPaymentRequestTestRule.clickInContactInfoAndWait( 103 R.id.payments_section, mPaymentRequestTestRule.getReadyForInput()); 104 mPaymentRequestTestRule.clickInContactInfoAndWait( 105 R.id.payments_add_option_button, mPaymentRequestTestRule.getReadyToEdit()); 106 mPaymentRequestTestRule.setTextInEditorAndWait(new String[] {"", "---", "jane.jones"}, 107 mPaymentRequestTestRule.getEditorTextUpdate()); 108 mPaymentRequestTestRule.clickInEditorAndWait( 109 R.id.editor_dialog_done_button, mPaymentRequestTestRule.getEditorValidationError()); 110 // The section collapses and the [CHOOSE] button is active. 111 mPaymentRequestTestRule.clickInEditorAndWait( 112 R.id.payments_edit_cancel_button, mPaymentRequestTestRule.getReadyForInput()); 113 Assert.assertEquals(PaymentRequestSection.EDIT_BUTTON_CHOOSE, 114 mPaymentRequestTestRule.getContactDetailsButtonState()); 115 116 mPaymentRequestTestRule.clickAndWait( 117 R.id.close_button, mPaymentRequestTestRule.getDismissed()); 118 mPaymentRequestTestRule.expectResultContains( 119 new String[] {"User closed the Payment Request UI."}); 120 } 121 122 /** Update the contact information with valid data and provide that to the merchant. */ 123 @Test 124 @MediumTest 125 @Feature({"Payments"}) testEditIncompleteContactAndPay()126 public void testEditIncompleteContactAndPay() throws TimeoutException { 127 mPaymentRequestTestRule.triggerUIAndWait(mPaymentRequestTestRule.getReadyForInput()); 128 mPaymentRequestTestRule.clickInContactInfoAndWait( 129 R.id.payments_section, mPaymentRequestTestRule.getReadyForInput()); 130 mPaymentRequestTestRule.clickInContactInfoAndWait( 131 R.id.payments_first_radio_button, mPaymentRequestTestRule.getReadyToEdit()); 132 mPaymentRequestTestRule.setTextInEditorAndWait( 133 new String[] {"Jon Doe", "555-555-5555", "jon.doe@google.com"}, 134 mPaymentRequestTestRule.getEditorTextUpdate()); 135 mPaymentRequestTestRule.clickInEditorAndWait( 136 R.id.editor_dialog_done_button, mPaymentRequestTestRule.getReadyToPay()); 137 mPaymentRequestTestRule.clickAndWait( 138 R.id.button_primary, mPaymentRequestTestRule.getDismissed()); 139 mPaymentRequestTestRule.expectResultContains( 140 new String[] {"Jon Doe", "+15555555555", "jon.doe@google.com"}); 141 } 142 } 143