Commit da29bda2 authored by sandromaggi's avatar sandromaggi Committed by Commit Bot

[Autofill Assistant] Add new tests for deleting items.

Bug: none
Change-Id: I1b8e0bbb52e0240075ee00e65020ee871e07118e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2015169
Commit-Queue: Sandro Maggi <sandromaggi@google.com>
Reviewed-by: default avatarMathias Carlen <mcarlen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734503}
parent 96cce24b
......@@ -16,6 +16,7 @@ import androidx.annotation.Nullable;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard;
import org.chromium.chrome.browser.autofill_assistant.user_data.AssistantChoiceList;
import org.chromium.chrome.browser.autofill_assistant.user_data.AssistantCollectUserDataCoordinator;
import org.chromium.chrome.browser.autofill_assistant.user_data.AssistantCollectUserDataDelegate;
......@@ -165,16 +166,22 @@ public class AutofillAssistantCollectUserDataTestHelper {
setSyncServiceForTesting();
}
void setRequestTimeoutForTesting() {
private void setRequestTimeoutForTesting() {
TestThreadUtils.runOnUiThreadBlocking(
() -> PersonalDataManager.setRequestTimeoutForTesting(0));
}
void setSyncServiceForTesting() {
private void setSyncServiceForTesting() {
TestThreadUtils.runOnUiThreadBlocking(
() -> PersonalDataManager.getInstance().setSyncServiceForTesting());
}
/**
* Add a new profile to the PersonalDataManager.
*
* @param profile The profile to add.
* @return the GUID of the created profile.
*/
public String setProfile(final AutofillProfile profile) throws TimeoutException {
int callCount = mOnPersonalDataChangedHelper.getCallCount();
String guid = TestThreadUtils.runOnUiThreadBlockingNoException(
......@@ -184,7 +191,19 @@ public class AutofillAssistantCollectUserDataTestHelper {
}
/**
* Adds a new profile with dummy data to the personal data manager.
* Delete a profile from the PersonalDataManager.
*
* @param guid The GUID of the profile to delete.
*/
public void deleteProfile(String guid) throws TimeoutException {
int callCount = mOnPersonalDataChangedHelper.getCallCount();
TestThreadUtils.runOnUiThreadBlocking(
() -> PersonalDataManager.getInstance().deleteProfile(guid));
mOnPersonalDataChangedHelper.waitForCallback(callCount);
}
/**
* Adds a new profile with dummy data to the PersonalDataManager.
*
* @param fullName The full name for the profile to create.
* @param email The email for the profile to create.
......@@ -197,6 +216,13 @@ public class AutofillAssistantCollectUserDataTestHelper {
return setProfile(profile);
}
/**
* Add a new profile with dummy data to the PersonalDataManager.
*
* @param fullName The full name for the profile to create.
* @param email The email for the profile to create.
* @return the GUID of the created profile.
*/
public String addDummyProfile(String fullName, String email) throws TimeoutException {
return addDummyProfile(fullName, email, "90210");
}
......@@ -211,45 +237,96 @@ public class AutofillAssistantCollectUserDataTestHelper {
*/
public PersonalDataManager.AutofillProfile createDummyProfile(
String fullName, String email, String postcode) {
return new PersonalDataManager.AutofillProfile("" /* guid */,
"https://www.example.com" /* origin */, fullName, "Acme Inc.", "123 Main",
"California", "Los Angeles", "", postcode, "", "UZ", "555 123-4567", email, "");
return new PersonalDataManager.AutofillProfile(/* guid= */ "", "https://www.example.com",
fullName, "Acme Inc.", "123 Main", "California", "Los Angeles",
/* dependentLocality= */ "", postcode, /* sortingCode= */ "", "UZ", "555 123-4567",
email, /* languageCode= */ "");
}
/**
* Create a new profile.
*
* @param fullName The full name for the profile to create.
* @param email The email for the profile to create.
* @return the profile.
*/
public PersonalDataManager.AutofillProfile createDummyProfile(String fullName, String email) {
return createDummyProfile(fullName, email, "90210");
}
/**
* Adds a credit card with dummy data to the personal data manager.
* Add a new credit card to the PersonalDataManager.
*
* @param card The credit card to add.
* @return the GUID of the created credit card.
*/
public String setCreditCard(final CreditCard card) throws TimeoutException {
int callCount = mOnPersonalDataChangedHelper.getCallCount();
String guid = TestThreadUtils.runOnUiThreadBlockingNoException(
() -> PersonalDataManager.getInstance().setCreditCard(card));
mOnPersonalDataChangedHelper.waitForCallback(callCount);
return guid;
}
/**
* Add a credit card with dummy data to the PersonalDataManager.
*
* @param billingAddressId The billing address profile GUID.
* @return the GUID of the created credit card
*/
public String addDummyCreditCard(String billingAddressId) throws TimeoutException {
PersonalDataManager.CreditCard card = createDummyCreditCard(billingAddressId);
return setCreditCard(createDummyCreditCard(billingAddressId));
}
/**
* Add a credit card with dummy data to the PersonalDataManager.
*
* @param billingAddressId The billing address profile GUID.
* @param cardNumber The card number.
* @return the GUID of the created credit card
*/
public String addDummyCreditCard(String billingAddressId, String cardNumber)
throws TimeoutException {
return setCreditCard(createDummyCreditCard(billingAddressId, cardNumber));
}
/**
* Delete a credit card from the PersonalDataManager.
*
* @param guid The GUID of the credit card to delete.
*/
public void deleteCreditCard(String guid) throws TimeoutException {
int callCount = mOnPersonalDataChangedHelper.getCallCount();
String guid = TestThreadUtils.runOnUiThreadBlockingNoException(
() -> PersonalDataManager.getInstance().setCreditCard(card));
TestThreadUtils.runOnUiThreadBlocking(
() -> PersonalDataManager.getInstance().deleteCreditCard(guid));
mOnPersonalDataChangedHelper.waitForCallback(callCount);
return guid;
}
/**
* Create a credit card with dummy data.
*
* @param billingAddressId The billing address profile GUID.
* @param cardNumber The card number.
* @return the card.
*/
public PersonalDataManager.CreditCard createDummyCreditCard(String billingAddressId) {
public CreditCard createDummyCreditCard(String billingAddressId, String cardNumber) {
String profileName = TestThreadUtils.runOnUiThreadBlockingNoException(
() -> PersonalDataManager.getInstance().getProfile(billingAddressId).getFullName());
return new PersonalDataManager.CreditCard("", "https://example.com", true, true,
profileName, "4111111111111111", "1111", "12", "2050", "visa",
return new CreditCard("", "https://example.com", true, true, profileName, cardNumber,
"1111", "12", "2050", "visa",
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.
* @return the card.
*/
public CreditCard createDummyCreditCard(String billingAddressId) {
return createDummyCreditCard(billingAddressId, "4111111111111111");
}
private void registerDataObserver() throws TimeoutException {
......
......@@ -10,17 +10,20 @@ import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
import static android.support.test.espresso.matcher.ViewMatchers.isChecked;
import static android.support.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isEnabled;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withParent;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.getElementValue;
......@@ -30,6 +33,7 @@ import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUi
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest;
import android.widget.RadioButton;
import org.junit.Before;
import org.junit.Rule;
......@@ -86,7 +90,7 @@ public class AutofillAssistantPersonalDataManagerTest {
}
/**
* Add a contact and fill it into the form.
* Add a contact with Autofill Assistant UI and fill it into the form.
*/
@Test
@MediumTest
......@@ -135,10 +139,7 @@ public class AutofillAssistantPersonalDataManagerTest {
ChipProto.newBuilder().setText("Address")))
.build(),
list);
AutofillAssistantTestService testService =
new AutofillAssistantTestService(Collections.singletonList(script));
startAutofillAssistant(mTestRule.getActivity(), testService);
runScript(script);
waitUntilViewMatchesCondition(
allOf(withId(R.id.section_title_add_button_label), withText("Add contact info")),
......@@ -162,11 +163,12 @@ public class AutofillAssistantPersonalDataManagerTest {
}
/**
* Catch live insert of a contact and fill it into the form.
* Catch the insert of a profile added outside of the Autofill Assistant, e.g. with the Chrome
* settings UI, and fill it into the form.
*/
@Test
@MediumTest
public void testLiveInsertAndEnterProfile() throws Exception {
public void testExternalAddAndEnterProfile() throws Exception {
ArrayList<ActionProto> list = new ArrayList<>();
list.add(
(ActionProto) ActionProto.newBuilder()
......@@ -197,10 +199,7 @@ public class AutofillAssistantPersonalDataManagerTest {
ChipProto.newBuilder().setText("Address")))
.build(),
list);
AutofillAssistantTestService testService =
new AutofillAssistantTestService(Collections.singletonList(script));
startAutofillAssistant(mTestRule.getActivity(), testService);
runScript(script);
waitUntilViewMatchesCondition(
allOf(withId(R.id.section_title_add_button_label), withText("Add contact info")),
......@@ -216,7 +215,8 @@ public class AutofillAssistantPersonalDataManagerTest {
}
/**
* A new profile added externally should not overwrite the current selection.
* A new profile added outside of the Autofill Assistant, e.g. with the Chrome settings UI,
* should not overwrite the current selection.
*/
@Test
@MediumTest
......@@ -253,10 +253,7 @@ public class AutofillAssistantPersonalDataManagerTest {
ChipProto.newBuilder().setText("Address")))
.build(),
list);
AutofillAssistantTestService testService =
new AutofillAssistantTestService(Collections.singletonList(script));
startAutofillAssistant(mTestRule.getActivity(), testService);
runScript(script);
waitUntilViewMatchesCondition(
withId(R.id.contact_summary), allOf(withText("johndoe@google.com"), isDisplayed()));
......@@ -277,7 +274,51 @@ public class AutofillAssistantPersonalDataManagerTest {
}
/**
* Editing the currently selected profile should keep selection.
* An existing profile deleted outside of the Autofill Assistant, e.g. with the Chrome settings
* UI, should be removed from the current list.
*/
@Test
@MediumTest
public void testExternalDeleteProfile() throws Exception {
String profileIdA = mHelper.addDummyProfile("Adam Doe", "adamdoe@google.com");
String profileIdB = mHelper.addDummyProfile("Berta Doe", "bertadoe@google.com");
ArrayList<ActionProto> list = new ArrayList<>();
list.add(
(ActionProto) ActionProto.newBuilder()
.setCollectUserData(
CollectUserDataProto.newBuilder()
.setContactDetails(ContactDetailsProto.newBuilder()
.setContactDetailsName("contact")
.setRequestPayerName(true)
.setRequestPayerEmail(true)
.setRequestPayerPhone(false))
.setRequestTermsAndConditions(false))
.build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("form_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Address")))
.build(),
list);
runScript(script);
waitUntilViewMatchesCondition(
withId(R.id.contact_summary), allOf(withText("adamdoe@google.com"), isDisplayed()));
// Delete first profile, expect second to be selected.
mHelper.deleteProfile(profileIdA);
waitUntilViewMatchesCondition(withId(R.id.contact_summary),
allOf(withText("bertadoe@google.com"), isDisplayed()));
// Delete second profile, expect nothing to be selected.
mHelper.deleteProfile(profileIdB);
waitUntilViewMatchesCondition(
allOf(withId(R.id.section_title_add_button_label), withText("Add contact info")),
isCompletelyDisplayed());
}
/**
* Editing the currently selected contact in the Assistant Autofill UI should keep selection.
*/
@Test
@MediumTest
......@@ -315,10 +356,7 @@ public class AutofillAssistantPersonalDataManagerTest {
ChipProto.newBuilder().setText("Address")))
.build(),
list);
AutofillAssistantTestService testService =
new AutofillAssistantTestService(Collections.singletonList(script));
startAutofillAssistant(mTestRule.getActivity(), testService);
runScript(script);
waitUntilViewMatchesCondition(withId(R.id.contact_summary),
allOf(withText("adamwest@google.com"), isDisplayed()));
......@@ -357,16 +395,16 @@ public class AutofillAssistantPersonalDataManagerTest {
// TODO(b/143265578): Add test where credit card is manually entered.
/**
* Catch live insert of a credit card.
* Catch the insert of a credit card added outside of the Autofill Assistant, e.g. with the
* Chrome settings UI, and fill it into the form.
*/
@Test
@MediumTest
public void testLiveInsertCreditCard() throws Exception {
public void testExternalAddCreditCard() throws Exception {
ArrayList<ActionProto> list = new ArrayList<>();
list.add((ActionProto) ActionProto.newBuilder()
.setCollectUserData(CollectUserDataProto.newBuilder()
.setRequestPaymentMethod(true)
.addSupportedBasicCardNetworks("visa")
.setRequestTermsAndConditions(false))
.build());
// No UseCreditCardAction, that is tested in PaymentTest.
......@@ -377,10 +415,7 @@ public class AutofillAssistantPersonalDataManagerTest {
ChipProto.newBuilder().setText("Payment")))
.build(),
list);
AutofillAssistantTestService testService =
new AutofillAssistantTestService(Collections.singletonList(script));
startAutofillAssistant(mTestRule.getActivity(), testService);
runScript(script);
waitUntilViewMatchesCondition(
allOf(withId(R.id.section_title_add_button_label), withText("Add card")),
......@@ -394,17 +429,18 @@ public class AutofillAssistantPersonalDataManagerTest {
}
/**
* Catch live insert of a credit card with billing address missing a postal code.
* Catch the insert of a credit card with a billing address missing the postal code added
* outside of the Autofill Assistant, e.g. with the Chrome settings UI, and fill it into the
* form.
*/
@Test
@MediumTest
public void testLiveInsertCreditCardWithoutBillingZip() throws Exception {
public void testExternalAddCreditCardWithoutBillingZip() throws Exception {
ArrayList<ActionProto> list = new ArrayList<>();
list.add((ActionProto) ActionProto.newBuilder()
.setCollectUserData(
CollectUserDataProto.newBuilder()
.setRequestPaymentMethod(true)
.addSupportedBasicCardNetworks("visa")
.setRequireBillingPostalCode(true)
.setBillingPostalCodeMissingText("Missing Billing Code")
.setRequestTermsAndConditions(false))
......@@ -416,10 +452,7 @@ public class AutofillAssistantPersonalDataManagerTest {
ChipProto.newBuilder().setText("Payment")))
.build(),
list);
AutofillAssistantTestService testService =
new AutofillAssistantTestService(Collections.singletonList(script));
startAutofillAssistant(mTestRule.getActivity(), testService);
runScript(script);
waitUntilViewMatchesCondition(
allOf(withId(R.id.section_title_add_button_label), withText("Add card")),
......@@ -432,4 +465,73 @@ public class AutofillAssistantPersonalDataManagerTest {
isDisplayed());
waitUntilViewMatchesCondition(withText("Continue"), isEnabled());
}
/**
* An existing credit card deleted outside of the Autofill Assistant, e.g. with the Chrome
* settings UI, should be removed from the current list.
*/
@Test
@MediumTest
public void testExternalDeleteCreditCard() throws Exception {
String profileId;
profileId = mHelper.addDummyProfile("Adam Doe", "adamdoe@google.com");
String cardIdA = mHelper.addDummyCreditCard(profileId, "4111111111111111");
profileId = mHelper.addDummyProfile("Berta Doe", "bertadoe@google.com");
String cardIdB = mHelper.addDummyCreditCard(profileId, "5555555555554444");
ArrayList<ActionProto> list = new ArrayList<>();
list.add((ActionProto) ActionProto.newBuilder()
.setCollectUserData(CollectUserDataProto.newBuilder()
.setRequestPaymentMethod(true)
.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);
runScript(script);
waitUntilViewMatchesCondition(allOf(withId(R.id.credit_card_number),
isDescendantOfA(withId(R.id.payment_method_summary))),
allOf(withText(containsString("1111")), isDisplayed()));
onView(withText("Payment method")).perform(click());
waitUntilViewMatchesCondition(
allOf(withId(R.id.credit_card_name), withText("Adam Doe")), isDisplayed());
onView(allOf(withId(R.id.credit_card_name),
withParent(allOf(withId(R.id.payment_method_full),
isNextAfterSibling(
allOf(instanceOf(RadioButton.class), isChecked()))))))
.check(matches(withText("Adam Doe")));
onView(withText("Payment method")).perform(click());
// Delete first card, expect second card to be selected.
mHelper.deleteCreditCard(cardIdA);
waitUntilViewMatchesCondition(allOf(withId(R.id.credit_card_number),
isDescendantOfA(withId(R.id.payment_method_summary))),
allOf(withText(containsString("4444")), isDisplayed()));
onView(withText("Payment method")).perform(click());
waitUntilViewMatchesCondition(
allOf(withId(R.id.credit_card_name), withText("Berta Doe")), isDisplayed());
onView(allOf(withId(R.id.credit_card_name),
withParent(allOf(withId(R.id.payment_method_full),
isNextAfterSibling(
allOf(instanceOf(RadioButton.class), isChecked()))))))
.check(matches(withText("Berta Doe")));
onView(withText("Payment method")).perform(click());
// Delete second card, expect nothing to be selected.
mHelper.deleteCreditCard(cardIdB);
waitUntilViewMatchesCondition(
allOf(withId(R.id.section_title_add_button_label), withText("Add card")),
isCompletelyDisplayed());
}
private void runScript(AutofillAssistantTestScript script) {
AutofillAssistantTestService testService =
new AutofillAssistantTestService(Collections.singletonList(script));
startAutofillAssistant(mTestRule.getActivity(), testService);
}
}
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