Commit e0e2e0b6 authored by Clemens Arbesser's avatar Clemens Arbesser Committed by Commit Bot

[Autofill Assistant] Added integration test for server cards.

For now, this is simply a smoke test that opens the edit dialog for a
server card and verifies that this does not break the client. b/155624806
tracks progress for adding a more elaborate test, this CL is merely to
get the effort started.

Bug: b/155624806
Bug: b/153498495
Change-Id: I02cdef5115d011748410b72de38913c2cb262ede
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2179883Reviewed-by: default avatarSandro Maggi <sandromaggi@google.com>
Reviewed-by: default avatarMarian Fechete <marianfe@google.com>
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Cr-Commit-Position: refs/heads/master@{#766337}
parent a4b2edcb
...@@ -275,12 +275,13 @@ public class AutofillAssistantCollectUserDataTestHelper { ...@@ -275,12 +275,13 @@ public class AutofillAssistantCollectUserDataTestHelper {
} }
/** /**
* Add a new credit card to the PersonalDataManager. * Add a new local credit card to the PersonalDataManager.
* *
* @param card The credit card to add. * @param card The credit card to add.
* @return the GUID of the created credit card. * @return the GUID of the created credit card.
*/ */
public String setCreditCard(final CreditCard card) throws TimeoutException { public String setCreditCard(final CreditCard card) throws TimeoutException {
assert card.getIsLocal();
int callCount = mOnPersonalDataChangedHelper.getCallCount(); int callCount = mOnPersonalDataChangedHelper.getCallCount();
String guid = TestThreadUtils.runOnUiThreadBlockingNoException( String guid = TestThreadUtils.runOnUiThreadBlockingNoException(
() -> PersonalDataManager.getInstance().setCreditCard(card)); () -> PersonalDataManager.getInstance().setCreditCard(card));
...@@ -288,6 +289,19 @@ public class AutofillAssistantCollectUserDataTestHelper { ...@@ -288,6 +289,19 @@ public class AutofillAssistantCollectUserDataTestHelper {
return guid; return guid;
} }
/**
* Add a new server credit card to the PersonalDataManager.
*
* @param card The credit card to add.
*/
public void addServerCreditCard(CreditCard card) throws TimeoutException {
assert !card.getIsLocal();
int callCount = mOnPersonalDataChangedHelper.getCallCount();
TestThreadUtils.runOnUiThreadBlocking(
() -> PersonalDataManager.getInstance().addServerCreditCardForTest(card));
mOnPersonalDataChangedHelper.waitForCallback(callCount);
}
/** /**
* Add a credit card with dummy data to the PersonalDataManager. * Add a credit card with dummy data to the PersonalDataManager.
* *
...@@ -327,18 +341,31 @@ public class AutofillAssistantCollectUserDataTestHelper { ...@@ -327,18 +341,31 @@ public class AutofillAssistantCollectUserDataTestHelper {
* *
* @param billingAddressId The billing address profile GUID. * @param billingAddressId The billing address profile GUID.
* @param cardNumber The card number. * @param cardNumber The card number.
* @param isLocal Whether the card is local or not.
* @return the card. * @return the card.
*/ */
public CreditCard createDummyCreditCard(String billingAddressId, String cardNumber) { public CreditCard createDummyCreditCard(
String billingAddressId, String cardNumber, boolean isLocal) {
String profileName = TestThreadUtils.runOnUiThreadBlockingNoException( String profileName = TestThreadUtils.runOnUiThreadBlockingNoException(
() -> PersonalDataManager.getInstance().getProfile(billingAddressId).getFullName()); () -> PersonalDataManager.getInstance().getProfile(billingAddressId).getFullName());
return new CreditCard("", "https://example.com", true, true, profileName, cardNumber, return new CreditCard("", "https://example.com", /* isLocal = */ isLocal, true, profileName,
"1111", "12", "2050", "visa", cardNumber, "1111", "12", "2050", "visa",
org.chromium.chrome.autofill_assistant.R.drawable.visa_card, billingAddressId, org.chromium.chrome.autofill_assistant.R.drawable.visa_card, billingAddressId,
/* serverId= */ ""); /* serverId= */ "");
} }
/**
* Create a credit card with dummy data.
*
* @param billingAddressId The billing address profile GUID.
* @param cardNumber The card number.
* @return the card.
*/
public CreditCard createDummyCreditCard(String billingAddressId, String cardNumber) {
return createDummyCreditCard(billingAddressId, cardNumber, /* isLocal = */ true);
}
/** /**
* Create a credit card with dummy data. * Create a credit card with dummy data.
* *
......
...@@ -685,6 +685,45 @@ public class AutofillAssistantPersonalDataManagerTest { ...@@ -685,6 +685,45 @@ public class AutofillAssistantPersonalDataManagerTest {
isCompletelyDisplayed()); isCompletelyDisplayed());
} }
/**
* Opens the edit dialog for a server card.
*/
@Test
@MediumTest
public void testEditOfServerCard() throws Exception {
String profileId = mHelper.addDummyProfile("Adam West", "adamwest@google.com");
mHelper.addServerCreditCard(mHelper.createDummyCreditCard(
profileId, "4111111111111111", /* isLocal = */ false));
ArrayList<ActionProto> list = new ArrayList<>();
list.add((ActionProto) ActionProto.newBuilder()
.setCollectUserData(CollectUserDataProto.newBuilder()
.setRequestPaymentMethod(true)
.setBillingAddressName("billing_address")
.setRequestTermsAndConditions(false))
.build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("form_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Payment")))
.build(),
list);
AutofillAssistantTestService testService =
new AutofillAssistantTestService(Collections.singletonList(script));
startAutofillAssistant(mTestRule.getActivity(), testService);
waitUntilViewMatchesCondition(withText("Continue"), isCompletelyDisplayed());
onView(withText("Payment method")).perform(click());
waitUntilViewMatchesCondition(withContentDescription("Edit card"), isDisplayed());
onView(withContentDescription("Edit card")).perform(click());
waitUntilViewMatchesCondition(withText("Billing address*"), isDisplayed());
// TODO(b/155624806) edit billing address and fill/check values on test website.
onView(withId(org.chromium.chrome.R.id.payments_edit_cancel_button)).perform(click());
}
private void runScript(AutofillAssistantTestScript script) { private void runScript(AutofillAssistantTestScript script) {
AutofillAssistantTestService testService = AutofillAssistantTestService testService =
new AutofillAssistantTestService(Collections.singletonList(script)); new AutofillAssistantTestService(Collections.singletonList(script));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment