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 {
......
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