Commit ab4a459c authored by Michele Mancina's avatar Michele Mancina Committed by Commit Bot

[Autofill Assistant] Create label for profile if null, this only happens for...

[Autofill Assistant] Create label for profile if null, this only happens for those profiles that are created within the CollectUserData action.

Bug: b/158464101
Change-Id: Ia5df15a8d5244d981f42ad08588710d30b5e9067
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2246155
Commit-Queue: Michele Mancina <micantox@google.com>
Reviewed-by: default avatarClemens Arbesser <arbesser@google.com>
Reviewed-by: default avatarMarian Fechete <marianfe@google.com>
Cr-Commit-Position: refs/heads/master@{#779784}
parent 32176fa5
...@@ -212,10 +212,14 @@ public class AssistantPaymentMethodSection ...@@ -212,10 +212,14 @@ public class AssistantPaymentMethodSection
} }
private void addAutocompleteInformationToEditor(AutofillAddress address) { private void addAutocompleteInformationToEditor(AutofillAddress address) {
// The check for non-null label is necessary to prevent crash in editor when opening. if (mEditor == null) {
if (mEditor == null || address.getProfile().getLabel() == null) {
return; return;
} }
if (address.getProfile().getLabel() == null) {
address.getProfile().setLabel(
PersonalDataManager.getInstance().getBillingAddressLabelForPaymentRequest(
address.getProfile()));
}
mEditor.updateBillingAddressIfComplete(address); mEditor.updateBillingAddressIfComplete(address);
} }
......
...@@ -818,6 +818,62 @@ public class AutofillAssistantPersonalDataManagerTest { ...@@ -818,6 +818,62 @@ public class AutofillAssistantPersonalDataManagerTest {
onView(withId(org.chromium.chrome.R.id.payments_edit_cancel_button)).perform(click()); onView(withId(org.chromium.chrome.R.id.payments_edit_cancel_button)).perform(click());
} }
/**
* Adds a new shipping address and checks that it is available when adding a new credit card
* with Autofill Assistant UI and fill it into the form.
*/
@Test
@MediumTest
public void testCreateShippingAddressAndCreditCard() throws Exception {
ArrayList<ActionProto> list = new ArrayList<>();
list.add((ActionProto) ActionProto.newBuilder()
.setCollectUserData(CollectUserDataProto.newBuilder()
.setRequestPaymentMethod(true)
.setBillingAddressName("billing_address")
.setShippingAddressName("shipping_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("Shipping address"), isCompletelyDisplayed());
onView(allOf(withText("Add address"), isDisplayed())).perform(click());
waitUntilViewMatchesCondition(
withContentDescription("Name*"), allOf(isDisplayed(), isEnabled()));
onView(withContentDescription("Name*")).perform(scrollTo(), typeText("John Doe"));
onView(withContentDescription("Street address*"))
.perform(scrollTo(), typeText("123 Main St"));
onView(withContentDescription("City*")).perform(scrollTo(), typeText("Mountain View"));
onView(withContentDescription("State*")).perform(scrollTo(), typeText("California"));
onView(withContentDescription("ZIP code*")).perform(scrollTo(), typeText("1234"));
onView(withContentDescription("Phone*")).perform(scrollTo(), typeText("8008080808"));
onView(withText("Done")).perform(scrollTo(), click());
waitUntilViewMatchesCondition(
allOf(withId(R.id.section_title_add_button_label), withText("Add card")),
isCompletelyDisplayed());
onView(allOf(withId(R.id.section_title_add_button_label), withText("Add card")))
.perform(click());
waitUntilViewMatchesCondition(
withContentDescription("Card number*"), allOf(isDisplayed(), isEnabled()));
Espresso.closeSoftKeyboard();
onView(allOf(withId(org.chromium.chrome.R.id.spinner), withChild(withText("Select"))))
.perform(scrollTo(), click());
onData(anything())
.atPosition(1 /* address of John, 0 is SELECT (empty) */)
.inRoot(withDecorView(withClassName(containsString("Popup"))))
.perform(click());
waitUntilViewMatchesCondition(withText(containsString("John Doe")), isDisplayed());
}
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