Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2967)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestDynamicShippingMultipleAddressesTest.java

Issue 2170603006: [Payments] Use the correct index when checking addresses (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestDynamicShippingMultipleAddressesTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestDynamicShippingMultipleAddressesTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestDynamicShippingMultipleAddressesTest.java
index 12f84b774da70be3972146c78c0eb2b8194811ac..5ab509851ab0c53b170031517a7dd91c78246b02 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestDynamicShippingMultipleAddressesTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestDynamicShippingMultipleAddressesTest.java
@@ -9,8 +9,8 @@ import android.test.suitebuilder.annotation.MediumTest;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.autofill.AutofillTestHelper;
import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
-import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard;
+import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
@@ -19,6 +19,37 @@ import java.util.concurrent.TimeoutException;
* and user that has 5 addresses stored in autofill settings.
*/
public class PaymentRequestDynamicShippingMultipleAddressesTest extends PaymentRequestTestBase {
+ private static final AutofillProfile[] AUTOFILL_PROFILES = {
+ // Incomplete profile (missing phone number)
+ new AutofillProfile("" /* guid */, "https://www.example.com" /* origin */,
+ "Bart Simpson", "Acme Inc.", "123 Main", "California", "Los Angeles", "",
+ "90210", "", "US", "", "bart@simpson.com", ""),
+
+ // Incomplete profile.
+ new AutofillProfile("" /* guid */, "https://www.example.com" /* origin */,
+ "Homer Simpson", "Acme Inc.", "123 Main", "California", "Los Angeles", "",
+ "90210", "", "US", "", "homer@simpson.com", ""),
+
+ // Complete profile.
+ new AutofillProfile("" /* guid */, "https://www.example.com" /* origin */,
+ "Lisa Simpson", "Acme Inc.", "123 Main", "California", "Los Angeles", "",
+ "90210", "", "US", "555 123-4567", "lisa@simpson.com", ""),
+
+ // Complete profile in another country.
+ new AutofillProfile("" /* guid */, "https://www.example.com" /* origin */,
+ "Maggie Simpson", "Acme Inc.", "123 Main", "California", "Los Angeles", "",
+ "90210", "", "Uzbekistan", "555 123-4567", "maggie@simpson.com", ""),
+
+ // Incomplete profile.
+ new AutofillProfile("" /* guid */, "https://www.example.com" /* origin */,
+ "Marge Simpson", "Acme Inc.", "123 Main", "California", "Los Angeles", "",
+ "90210", "", "US", "", "marge@simpson.com", "")
+ };
+
+ private AutofillProfile[] mProfilesToAdd;
+ private int[] mCountsToSet;
+ private int[] mDatesToSet;
+
public PaymentRequestDynamicShippingMultipleAddressesTest() {
// This merchant requests the shipping address first before providing any shipping options.
super("payment_request_dynamic_shipping_test.html");
@@ -28,48 +59,17 @@ public class PaymentRequestDynamicShippingMultipleAddressesTest extends PaymentR
public void onMainActivityStarted()
throws InterruptedException, ExecutionException, TimeoutException {
AutofillTestHelper helper = new AutofillTestHelper();
- // Create an incomplete (no phone) profile with the highest frecency score.
- String guid1 = helper.setProfile(
- new AutofillProfile("" /* guid */, "https://www.example.com" /* origin */,
- "Bart Simpson", "Acme Inc.", "123 Main", "California", "Los Angeles", "",
- "90210", "", "US", "", "bart@simpson.com", ""));
-
- // Create an incomplete (no phone) profile with a the second highest frecency score.
- String guid2 = helper.setProfile(
- new AutofillProfile("" /* guid */, "https://www.example.com" /* origin */,
- "Homer Simpson", "Acme Inc.", "123 Main", "California", "Los Angeles", "",
- "90210", "", "US", "", "homer@simpson.com", ""));
-
- // Create a complete profile with a middle frecency score.
- String guid3 = helper.setProfile(
- new AutofillProfile("" /* guid */, "https://www.example.com" /* origin */,
- "Lisa Simpson", "Acme Inc.", "123 Main", "California", "Los Angeles", "",
- "90210", "", "US", "555 123-4567", "lisa@simpson.com", ""));
-
- // Create a complete profile with the second lowest frecency score.
- String guid4 = helper.setProfile(
- new AutofillProfile("" /* guid */, "https://www.example.com" /* origin */,
- "Maggie Simpson", "Acme Inc.", "123 Main", "California", "Los Angeles", "",
- "90210", "", "US", "555 123-4567", "maggie@simpson.com", ""));
-
- // Create an incomplete profile with the lowest frecency score.
- String guid5 = helper.setProfile(
- new AutofillProfile("" /* guid */, "https://www.example.com" /* origin */,
- "Marge Simpson", "Acme Inc.", "123 Main", "California", "Los Angeles", "",
- "90210", "", "US", "", "marge@simpson.com", ""));
-
- // Create a credit card associated witht the fourth profile.
- helper.setCreditCard(new CreditCard("", "https://example.com", true, true, "Jon Doe",
- "4111111111111111", "1111", "12", "2050", "visa", R.drawable.pr_visa,
- guid4));
-
- // Set the use stats so that profile1 has the highest frecency score, profile2 the second
- // highest, profile 3 the second lowest and profile4 the lowest.
- helper.setProfileUseStatsForTesting(guid1, 20, 5000);
- helper.setProfileUseStatsForTesting(guid2, 15, 5000);
- helper.setProfileUseStatsForTesting(guid3, 10, 5000);
- helper.setProfileUseStatsForTesting(guid4, 5, 5000);
- helper.setProfileUseStatsForTesting(guid5, 1, 1);
+
+ // Add the profiles.
+ ArrayList<String> guids = new ArrayList<>();
+ for (int i = 0; i < mProfilesToAdd.length; i++) {
+ guids.add(helper.setProfile(mProfilesToAdd[i]));
+ }
+
+ // Set up the profile use stats.
+ for (int i = 0; i < guids.size(); i++) {
+ helper.setProfileUseStatsForTesting(guids.get(i), mCountsToSet[i], mDatesToSet[i]);
+ }
}
/**
@@ -80,6 +80,14 @@ public class PaymentRequestDynamicShippingMultipleAddressesTest extends PaymentR
@MediumTest
public void testShippingAddressSuggestionOrdering()
throws InterruptedException, ExecutionException, TimeoutException {
+ // Create a bunch of profiles, some complete, some incomplete. Values are set so that the
+ // profiles are ordered by frecency.
+ 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};
+
triggerUIAndWait(mReadyForInput);
clickInShippingSummaryAndWait(R.id.payments_section, mReadyForInput);
assertEquals(4, getNumberOfShippingAddressSuggestions());
@@ -88,4 +96,30 @@ public class PaymentRequestDynamicShippingMultipleAddressesTest extends PaymentR
assertTrue(getShippingAddressSuggestionLabel(2).contains("Bart Simpson"));
assertTrue(getShippingAddressSuggestionLabel(3).contains("Homer Simpson"));
}
+
+ /**
+ * Select a shipping address that the website refuses to accept, which should force the dialog
+ * to show an error.
+ */
+ @MediumTest
+ public void testShippingAddresNotAcceptedByMerchant()
+ throws InterruptedException, ExecutionException, TimeoutException {
+ // Add a profile that is not accepted by the website.
+ mProfilesToAdd = new AutofillProfile[] {AUTOFILL_PROFILES[3]};
+ mCountsToSet = new int[] {5};
+ mDatesToSet = new int[] {5000};
+
+ // Click on the unacceptable shipping address.
+ triggerUIAndWait(mReadyForInput);
+ clickInShippingSummaryAndWait(R.id.payments_section, mReadyForInput);
+ assertTrue(getShippingAddressSuggestionLabel(0).contains(
+ AUTOFILL_PROFILES[3].getFullName()));
+ clickOnShippingAddressSuggestionOptionAndWait(0, mSelectionChecked);
+
+ // The string should indicate that the shipping address isn't valid.
+ CharSequence actualString = getShippingAddressOptionRowAtIndex(0).getLabelText();
+ CharSequence expectedString = getInstrumentation().getTargetContext().getString(
+ R.string.payments_unsupported_shipping_address);
+ assertEquals(expectedString, actualString);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698