Skip to content

Commit

Permalink
Re-enable PaymentRequestMultipleContactDetailsTest tests
Browse files Browse the repository at this point in the history
The main fix here was to migrate the tests from using basic-card
to using a Payment App for testing. In addition to that, this CL
also switches to triggering the Payment Request via JavaScript
directly rather than using triggerUIAndWait. Finally, it also
renames some variables and adds comments to make it clearer why the
test behavior is as expected.

Bug: 1431558, 1428701, 1409682, 1463732, 1404595
Bug: 1403852
Change-Id: I48414d61de3afd7928830913d6ef3c386b1f9422
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4784309
Commit-Queue: Stephen McGruer <smcgruer@chromium.org>
Reviewed-by: Nick Burris <nburris@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1184723}
  • Loading branch information
stephenmcgruer authored and Chromium LUCI CQ committed Aug 17, 2023
1 parent 1f4a3dc commit 756f328
Showing 1 changed file with 98 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.junit.runner.RunWith;

import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.autofill.AutofillTestHelper;
import org.chromium.chrome.browser.flags.ChromeSwitches;
Expand All @@ -37,8 +36,7 @@ public class PaymentRequestMultipleContactDetailsTest {
public PaymentRequestTestRule mPaymentRequestTestRule =
new PaymentRequestTestRule("payment_request_contact_details_test.html");

private static final AutofillProfile[] AUTOFILL_PROFILES = {
// 0 - Incomplete (no phone) profile.
private static final AutofillProfile INCOMPLETE_PROFILE_NO_PHONE =
AutofillProfile.builder()
.setFullName("Bart Simpson")
.setCompanyName("Acme Inc.")
Expand All @@ -48,9 +46,9 @@ public class PaymentRequestMultipleContactDetailsTest {
.setPostalCode("90210")
.setCountryCode("US")
.setEmailAddress("bart@simpson.com")
.build(),
.build();

// 1 - Incomplete (no email) profile.
private static final AutofillProfile INCOMPLETE_PROFILE_NO_EMAIL =
AutofillProfile.builder()
.setFullName("Homer Simpson")
.setCompanyName("Acme Inc.")
Expand All @@ -60,9 +58,9 @@ public class PaymentRequestMultipleContactDetailsTest {
.setPostalCode("90210")
.setCountryCode("US")
.setPhoneNumber("555 123-4567")
.build(),
.build();

// 2 - Complete profile.
private static final AutofillProfile COMPLETE_PROFILE_1 =
AutofillProfile.builder()
.setFullName("Lisa Simpson")
.setCompanyName("Acme Inc.")
Expand All @@ -73,9 +71,9 @@ public class PaymentRequestMultipleContactDetailsTest {
.setCountryCode("US")
.setPhoneNumber("555 123-4567")
.setEmailAddress("lisa@simpson.com")
.build(),
.build();

// 3 - Complete profile.
private static final AutofillProfile COMPLETE_PROFILE_2 =
AutofillProfile.builder()
.setFullName("Maggie Simpson")
.setCompanyName("Acme Inc.")
Expand All @@ -86,9 +84,9 @@ public class PaymentRequestMultipleContactDetailsTest {
.setCountryCode("US")
.setPhoneNumber("555 123-4567")
.setEmailAddress("maggie@simpson.com")
.build(),
.build();

// 4 - Incomplete (no phone and email) profile.
private static final AutofillProfile INCOMPLETE_PROFILE_NO_PHONE_OR_EMAIL =
AutofillProfile.builder()
.setFullName("Marge Simpson")
.setCompanyName("Acme Inc.")
Expand All @@ -97,9 +95,9 @@ public class PaymentRequestMultipleContactDetailsTest {
.setLocality("Los Angeles")
.setPostalCode("90210")
.setCountryCode("US")
.build(),
.build();

// 5 - Incomplete (no name) profile.
private static final AutofillProfile INCOMPLETE_PROFILE_NO_NAME =
AutofillProfile.builder()
.setCompanyName("Acme Inc.")
.setStreetAddress("123 Main")
Expand All @@ -109,12 +107,12 @@ public class PaymentRequestMultipleContactDetailsTest {
.setCountryCode("US")
.setPhoneNumber("555 123-4567")
.setEmailAddress("marge@simpson.com")
.build(),
.build();

// These profiles are used to test the dedupe of subset suggestions. They are based on
// The Lisa Simpson profile.
// These profiles are used to test the dedupe of subset suggestions. They are based on
// The Lisa Simpson profile.

// 6 - Same as original, but with no name.
private static final AutofillProfile DUPLICATE_PROFILE_WITH_NO_NAME =
AutofillProfile.builder()
.setCompanyName("Acme Inc.")
.setStreetAddress("123 Main")
Expand All @@ -124,9 +122,9 @@ public class PaymentRequestMultipleContactDetailsTest {
.setCountryCode("US")
.setPhoneNumber("555 123-4567")
.setEmailAddress("lisa@simpson.com")
.build(),
.build();

// 7 - Same as original, but with no phone.
private static final AutofillProfile DUPLICATE_PROFILE_WITH_NO_PHONE =
AutofillProfile.builder()
.setFullName("Lisa Simpson")
.setCompanyName("Acme Inc.")
Expand All @@ -136,9 +134,9 @@ public class PaymentRequestMultipleContactDetailsTest {
.setPostalCode("90210")
.setCountryCode("US")
.setEmailAddress("lisa@simpson.com")
.build(),
.build();

// 8 - Same as original, but with no email.
private static final AutofillProfile DUPLICATE_PROFILE_WITH_NO_EMAIL =
AutofillProfile.builder()
.setFullName("Lisa Simpson")
.setCompanyName("Acme Inc.")
Expand All @@ -148,9 +146,9 @@ public class PaymentRequestMultipleContactDetailsTest {
.setPostalCode("90210")
.setCountryCode("US")
.setPhoneNumber("555 123-4567")
.build(),
.build();

// 9 - Same as original, but with no phone and no email.
private static final AutofillProfile DUPLICATE_PROFILE_WITH_NO_PHONE_OR_EMAIL =
AutofillProfile.builder()
.setFullName("Lisa Simpson")
.setCompanyName("Acme Inc.")
Expand All @@ -159,9 +157,11 @@ public class PaymentRequestMultipleContactDetailsTest {
.setLocality("Los Angeles")
.setPostalCode("90210")
.setCountryCode("US")
.build(),
.build();

// 10 - Has an email address that is a superset of the original profile's email.
// This profile is a duplicate except that its email address is a superset of the original
// profile (that is, the original profile's email is a suffix of this one).
private static final AutofillProfile DUPLICATE_PROFILE_WITH_SUPERSET_EMAIL =
AutofillProfile.builder()
.setFullName("Lisa Simpson")
.setCompanyName("Acme Inc.")
Expand All @@ -172,9 +172,9 @@ public class PaymentRequestMultipleContactDetailsTest {
.setCountryCode("US")
.setPhoneNumber("555 123-4567")
.setEmailAddress("fakelisa@simpson.com")
.build(),
.build();

// 11 - Has the same name as the original but with no capitalization in the name.
private static final AutofillProfile DUPLICATE_PROFILE_WITH_MISMATCHED_CAPITALIZATION =
AutofillProfile.builder()
.setFullName("lisa simpson")
.setCompanyName("Acme Inc.")
Expand All @@ -185,34 +185,28 @@ public class PaymentRequestMultipleContactDetailsTest {
.setCountryCode("US")
.setPhoneNumber("555 123-4567")
.setEmailAddress("lisa@simpson.com")
.build(),

};

private AutofillProfile[] mProfilesToAdd;
private int[] mCountsToSet;
private int[] mDatesToSet;
.build();

@Before
public void setUp() throws TimeoutException {
public void setUp() {
mPaymentRequestTestRule.addPaymentAppFactory(
"https://bobpay.test", AppPresence.HAVE_APPS, FactorySpeed.FAST_FACTORY);
}

private void setUpAutofillProfiles(AutofillProfile[] profiles, int[] counts,
int[] daysSinceLastUsed) throws TimeoutException {
AutofillTestHelper helper = new AutofillTestHelper();

// Add the profiles.
ArrayList<String> guids = new ArrayList<>();
for (int i = 0; i < mProfilesToAdd.length; i++) {
guids.add(helper.setProfile(mProfilesToAdd[i]));
for (int i = 0; i < profiles.length; i++) {
guids.add(helper.setProfile(profiles[i]));
}

// Set up the profile use stats.
for (int i = 0; i < guids.size(); i++) {
// TODO(crbug.com/1463732): Update Disabled Test Callsites of
// SetProfileUseStatsForTesting and SetCreditCardUseStatsForTesting since the underlying
// logic has changed.
helper.setProfileUseStatsForTesting(guids.get(i), mCountsToSet[i], mDatesToSet[i]);
helper.setProfileUseStatsForTesting(guids.get(i), counts[i], daysSinceLastUsed[i]);
}

mPaymentRequestTestRule.addPaymentAppFactory(
AppPresence.HAVE_APPS, FactorySpeed.FAST_FACTORY);
}

/**
Expand All @@ -222,18 +216,23 @@ public void setUp() throws TimeoutException {
*/
@Test
@MediumTest
@DisabledTest(message = "crbug.com/1182234")
@Feature({"Payments"})
public void testContactDetailsSuggestionOrdering() throws TimeoutException {
// Set the use stats so that profile[0] has the highest frecency score, profile[1] the
// second highest, profile[2] the third lowest, profile[3] the second lowest and profile[4]
// the lowest.
mProfilesToAdd = new AutofillProfile[] {AUTOFILL_PROFILES[0], AUTOFILL_PROFILES[1],
AUTOFILL_PROFILES[2], AUTOFILL_PROFILES[3], AUTOFILL_PROFILES[4]};
mCountsToSet = new int[] {20, 15, 10, 5, 1};
mDatesToSet = new int[] {5000, 5000, 5000, 5000, 1};

mPaymentRequestTestRule.triggerUIAndWait("buy", mPaymentRequestTestRule.getReadyForInput());
// Set the use stats such that the profiles are in descending frecency score.
AutofillProfile[] profiles = new AutofillProfile[] {INCOMPLETE_PROFILE_NO_PHONE,
INCOMPLETE_PROFILE_NO_EMAIL, COMPLETE_PROFILE_1, COMPLETE_PROFILE_2,
INCOMPLETE_PROFILE_NO_PHONE_OR_EMAIL};
int[] counts = new int[] {20, 15, 10, 5, 1};
int[] daysSinceLastUsed = new int[] {5, 5, 5, 5, 5};

setUpAutofillProfiles(profiles, counts, daysSinceLastUsed);

// The complete profiles should still come first, despite having a lower frecency score. The
// profile without either a phone or email should have been sorted to last, and is then not
// shown because we have more than PaymentUiService.SUGGESTIONS_LIMIT profiles.
mPaymentRequestTestRule.runJavaScriptAndWaitForUIEvent(
"buyWithMethods([{supportedMethods:'https://bobpay.test'}]);",
mPaymentRequestTestRule.getReadyForInput());
mPaymentRequestTestRule.clickInContactInfoAndWait(
R.id.payments_section, mPaymentRequestTestRule.getReadyForInput());
Assert.assertEquals(4, mPaymentRequestTestRule.getNumberOfContactDetailSuggestions());
Expand All @@ -253,15 +252,19 @@ public void testContactDetailsSuggestionOrdering() throws TimeoutException {
*/
@Test
@MediumTest
@DisabledTest(message = "crbug.com/1182234")
@Feature({"Payments"})
public void testContactDetailsEditRequiredMessage() throws TimeoutException {
mProfilesToAdd = new AutofillProfile[] {AUTOFILL_PROFILES[0], AUTOFILL_PROFILES[1],
AUTOFILL_PROFILES[4], AUTOFILL_PROFILES[5]};
mCountsToSet = new int[] {15, 10, 5, 1};
mDatesToSet = new int[] {5000, 5000, 5000, 5000};
AutofillProfile[] profiles =
new AutofillProfile[] {INCOMPLETE_PROFILE_NO_PHONE, INCOMPLETE_PROFILE_NO_EMAIL,
INCOMPLETE_PROFILE_NO_PHONE_OR_EMAIL, INCOMPLETE_PROFILE_NO_NAME};
int[] counts = new int[] {15, 10, 5, 1};
int[] daysSinceLastUsed = new int[] {5, 5, 5, 5};

mPaymentRequestTestRule.triggerUIAndWait("buy", mPaymentRequestTestRule.getReadyForInput());
setUpAutofillProfiles(profiles, counts, daysSinceLastUsed);

mPaymentRequestTestRule.runJavaScriptAndWaitForUIEvent(
"buyWithMethods([{supportedMethods:'https://bobpay.test'}]);",
mPaymentRequestTestRule.getReadyForInput());
mPaymentRequestTestRule.clickInContactInfoAndWait(
R.id.payments_section, mPaymentRequestTestRule.getReadyForInput());
Assert.assertEquals(4, mPaymentRequestTestRule.getNumberOfContactDetailSuggestions());
Expand All @@ -281,22 +284,25 @@ public void testContactDetailsEditRequiredMessage() throws TimeoutException {
@Test
@MediumTest
@Feature({"Payments"})
@DisabledTest(message = "https://crbug.com/1182590")
public void testContactDetailsDedupe_EmptyFields() throws TimeoutException {
// Add the original profile and a bunch of similar profiles with missing fields.
// Make sure the original profile is suggested last, to test that the suggestions are
// sorted by completeness.
mProfilesToAdd = new AutofillProfile[] {
AUTOFILL_PROFILES[2],
AUTOFILL_PROFILES[6],
AUTOFILL_PROFILES[7],
AUTOFILL_PROFILES[8],
AUTOFILL_PROFILES[9],
AutofillProfile[] profiles = new AutofillProfile[] {
COMPLETE_PROFILE_1,
DUPLICATE_PROFILE_WITH_NO_NAME,
DUPLICATE_PROFILE_WITH_NO_PHONE,
DUPLICATE_PROFILE_WITH_NO_EMAIL,
DUPLICATE_PROFILE_WITH_NO_PHONE_OR_EMAIL,
};
mCountsToSet = new int[] {1, 20, 15, 10, 5};
mDatesToSet = new int[] {1000, 4000, 3000, 2000, 1000};
int[] counts = new int[] {1, 20, 15, 10, 5};
int[] daysSinceLastUsed = new int[] {4, 1, 2, 3, 4};

setUpAutofillProfiles(profiles, counts, daysSinceLastUsed);

mPaymentRequestTestRule.triggerUIAndWait("buy", mPaymentRequestTestRule.getReadyForInput());
mPaymentRequestTestRule.runJavaScriptAndWaitForUIEvent(
"buyWithMethods([{supportedMethods:'https://bobpay.test'}]);",
mPaymentRequestTestRule.getReadyForInput());
mPaymentRequestTestRule.clickInContactInfoAndWait(
R.id.payments_section, mPaymentRequestTestRule.getReadyForInput());

Expand All @@ -312,16 +318,22 @@ public void testContactDetailsDedupe_EmptyFields() throws TimeoutException {
*/
@Test
@MediumTest
@DisabledTest(message = "crbug.com/1182234")
@Feature({"Payments"})
public void testContactDetailsDedupe_Capitalization() throws TimeoutException {
// Add the original profile and the one where the the name is not capitalized.
// Make sure the original profile is suggested first (no particular reason).
mProfilesToAdd = new AutofillProfile[] {AUTOFILL_PROFILES[2], AUTOFILL_PROFILES[11]};
mCountsToSet = new int[] {15, 5};
mDatesToSet = new int[] {5000, 2000};
AutofillProfile[] profiles = new AutofillProfile[] {
COMPLETE_PROFILE_1,
DUPLICATE_PROFILE_WITH_MISMATCHED_CAPITALIZATION,
};
int[] counts = new int[] {15, 5};
int[] daysSinceLastUsed = new int[] {2, 5};

mPaymentRequestTestRule.triggerUIAndWait("buy", mPaymentRequestTestRule.getReadyForInput());
setUpAutofillProfiles(profiles, counts, daysSinceLastUsed);

mPaymentRequestTestRule.runJavaScriptAndWaitForUIEvent(
"buyWithMethods([{supportedMethods:'https://bobpay.test'}]);",
mPaymentRequestTestRule.getReadyForInput());
mPaymentRequestTestRule.clickInContactInfoAndWait(
R.id.payments_section, mPaymentRequestTestRule.getReadyForInput());
Assert.assertEquals(1, mPaymentRequestTestRule.getNumberOfContactDetailSuggestions());
Expand All @@ -335,17 +347,23 @@ public void testContactDetailsDedupe_Capitalization() throws TimeoutException {
*/
@Test
@MediumTest
@DisabledTest(message = "crbug.com/1182234")
@Feature({"Payments"})
public void testContactDetailsDontDedupe_FieldSubset() throws TimeoutException {
// Add the original profile and the one where the email is a superset of the original.
// Make sure the one with the superset is suggested first, because to test the subset one
// needs to be added after.
mProfilesToAdd = new AutofillProfile[] {AUTOFILL_PROFILES[2], AUTOFILL_PROFILES[10]};
mCountsToSet = new int[] {15, 25};
mDatesToSet = new int[] {5000, 7000};
AutofillProfile[] profiles = new AutofillProfile[] {
COMPLETE_PROFILE_1,
DUPLICATE_PROFILE_WITH_SUPERSET_EMAIL,
};
int[] counts = new int[] {15, 25};
int[] daysSinceLastUsed = new int[] {7, 5};

setUpAutofillProfiles(profiles, counts, daysSinceLastUsed);

mPaymentRequestTestRule.triggerUIAndWait("buy", mPaymentRequestTestRule.getReadyForInput());
mPaymentRequestTestRule.runJavaScriptAndWaitForUIEvent(
"buyWithMethods([{supportedMethods:'https://bobpay.test'}]);",
mPaymentRequestTestRule.getReadyForInput());
mPaymentRequestTestRule.clickInContactInfoAndWait(
R.id.payments_section, mPaymentRequestTestRule.getReadyForInput());
Assert.assertEquals(2, mPaymentRequestTestRule.getNumberOfContactDetailSuggestions());
Expand Down

0 comments on commit 756f328

Please sign in to comment.