| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.payments; | 5 package org.chromium.chrome.browser.payments; |
| 6 | 6 |
| 7 import android.test.suitebuilder.annotation.MediumTest; | 7 import android.test.suitebuilder.annotation.MediumTest; |
| 8 | 8 |
| 9 import org.chromium.base.test.util.Feature; | 9 import org.chromium.base.test.util.Feature; |
| 10 import org.chromium.chrome.R; | 10 import org.chromium.chrome.R; |
| 11 import org.chromium.chrome.browser.autofill.AutofillTestHelper; | 11 import org.chromium.chrome.browser.autofill.AutofillTestHelper; |
| 12 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; | 12 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; |
| 13 import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; | 13 import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; |
| 14 | 14 |
| 15 import java.util.concurrent.ExecutionException; | 15 import java.util.concurrent.ExecutionException; |
| 16 import java.util.concurrent.TimeoutException; | 16 import java.util.concurrent.TimeoutException; |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * A payment integration test for biling addresses. | 19 * A payment integration test for biling addresses. |
| 20 */ | 20 */ |
| 21 public class PaymentRequestBillingAddressTest extends PaymentRequestTestBase { | 21 public class PaymentRequestBillingAddressTest extends PaymentRequestTestBase { |
| 22 // The index at which the option to add a billing address is located in the
billing address | 22 /* |
| 23 // selection dropdown. | 23 * The index at which the option to add a billing address is located in the
billing address |
| 24 * selection dropdown. |
| 25 */ |
| 24 private static final int ADD_BILLING_ADDRESS = 3; | 26 private static final int ADD_BILLING_ADDRESS = 3; |
| 25 | 27 |
| 28 /** The index of the billing address dropdown in the card editor. */ |
| 29 private static final int BILLING_ADDRESS_DROPDOWN_INDEX = 2; |
| 30 |
| 26 public PaymentRequestBillingAddressTest() { | 31 public PaymentRequestBillingAddressTest() { |
| 27 super("payment_request_no_shipping_test.html"); | 32 super("payment_request_free_shipping_test.html"); |
| 28 } | 33 } |
| 29 | 34 |
| 30 @Override | 35 @Override |
| 31 public void onMainActivityStarted() | 36 public void onMainActivityStarted() |
| 32 throws InterruptedException, ExecutionException, TimeoutException { | 37 throws InterruptedException, ExecutionException, TimeoutException { |
| 33 AutofillTestHelper helper = new AutofillTestHelper(); | 38 AutofillTestHelper helper = new AutofillTestHelper(); |
| 34 String profile1 = helper.setProfile(new AutofillProfile("", "https://exa
mple.com", true, | 39 String profile1 = helper.setProfile(new AutofillProfile("", "https://exa
mple.com", true, |
| 35 "Jon Doe", "Google", "340 Main St", "CA", "Los Angeles", "", "90
291", "", "US", | 40 "Jon Doe", "Google", "340 Main St", "CA", "Los Angeles", "", "90
291", "", "US", |
| 36 "310-310-6000", "jon.doe@gmail.com", "en-US")); | 41 "310-310-6000", "jon.doe@gmail.com", "en-US")); |
| 37 helper.setCreditCard(new CreditCard("", "https://example.com", true, tru
e, "Jon Doe", | 42 helper.setCreditCard(new CreditCard("", "https://example.com", true, tru
e, "Jon Doe", |
| (...skipping 14 matching lines...) Expand all Loading... |
| 52 | 57 |
| 53 /** Verifies the format of the billing address suggestions when adding a new
credit card. */ | 58 /** Verifies the format of the billing address suggestions when adding a new
credit card. */ |
| 54 @MediumTest | 59 @MediumTest |
| 55 @Feature({"Payments"}) | 60 @Feature({"Payments"}) |
| 56 public void testNewCardBillingAddressFormat() | 61 public void testNewCardBillingAddressFormat() |
| 57 throws InterruptedException, ExecutionException, TimeoutException { | 62 throws InterruptedException, ExecutionException, TimeoutException { |
| 58 triggerUIAndWait(mReadyToPay); | 63 triggerUIAndWait(mReadyToPay); |
| 59 clickInPaymentMethodAndWait(R.id.payments_section, mReadyForInput); | 64 clickInPaymentMethodAndWait(R.id.payments_section, mReadyForInput); |
| 60 clickInPaymentMethodAndWait(R.id.payments_add_option_button, mReadyToEdi
t); | 65 clickInPaymentMethodAndWait(R.id.payments_add_option_button, mReadyToEdi
t); |
| 61 setTextInCardEditorAndWait(new String[] {"5454-5454-5454-5454", "Bob"},
mEditorTextUpdate); | 66 setTextInCardEditorAndWait(new String[] {"5454-5454-5454-5454", "Bob"},
mEditorTextUpdate); |
| 62 setSpinnerSelectionsInCardEditorAndWait(new int[] {11, 1, 0}, | 67 setSpinnerSelectionsInCardEditorAndWait( |
| 68 new int[] {DECEMBER, NEXT_YEAR, FIRST_BILLING_ADDRESS}, |
| 63 mBillingAddressChangeProcessed); | 69 mBillingAddressChangeProcessed); |
| 64 // The billing address suggestions should include only the name, address
, city, state and | 70 // The billing address suggestions should include only the name, address
, city, state and |
| 65 // zip code of the profile. | 71 // zip code of the profile. |
| 66 assertTrue(getSpinnerSelectionTextInCardEditor(2).equals( | 72 assertTrue(getSpinnerSelectionTextInCardEditor(BILLING_ADDRESS_DROPDOWN_
INDEX) |
| 67 "Rob Doe, 340 Main St, Los Angeles, CA 90291")); | 73 .equals("Rob Doe, 340 Main St, Los Angeles, CA 90291"
)); |
| 68 } | 74 } |
| 69 | 75 |
| 70 /** | 76 /** |
| 71 * Verifies that the correct number of billing address suggestions are shown
when adding a new | 77 * Verifies that the correct number of billing address suggestions are shown
when adding a new |
| 72 * credit card. | 78 * credit card. |
| 73 */ | 79 */ |
| 74 @MediumTest | 80 @MediumTest |
| 75 @Feature({"Payments"}) | 81 @Feature({"Payments"}) |
| 76 public void testNumberOfBillingAddressSuggestions() | 82 public void testNumberOfBillingAddressSuggestions() |
| 77 throws InterruptedException, ExecutionException, TimeoutException { | 83 throws InterruptedException, ExecutionException, TimeoutException { |
| 78 triggerUIAndWait(mReadyToPay); | 84 triggerUIAndWait(mReadyToPay); |
| 79 clickInPaymentMethodAndWait(R.id.payments_section, mReadyForInput); | 85 clickInPaymentMethodAndWait(R.id.payments_section, mReadyForInput); |
| 80 clickInPaymentMethodAndWait(R.id.payments_add_option_button, mReadyToEdi
t); | 86 clickInPaymentMethodAndWait(R.id.payments_add_option_button, mReadyToEdi
t); |
| 81 | 87 |
| 82 // There should only be 4 suggestions, the 3 saved addresses and the opt
ion to add a new | 88 // There should only be 4 suggestions, the 3 saved addresses and the opt
ion to add a new |
| 83 // address. | 89 // address. |
| 84 assertEquals(4, getSpinnerItemCountInCardEditor(2)); | 90 assertEquals(4, getSpinnerItemCountInCardEditor(BILLING_ADDRESS_DROPDOWN
_INDEX)); |
| 85 } | 91 } |
| 86 | 92 |
| 87 /** | 93 /** |
| 88 * Verifies that the correct number of billing address suggestions are shown
when adding a new | 94 * Verifies that the correct number of billing address suggestions are shown
when adding a new |
| 89 * credit card, even after cancelling out of adding a new billing address. | 95 * credit card, even after cancelling out of adding a new billing address. |
| 90 */ | 96 */ |
| 91 @MediumTest | 97 @MediumTest |
| 92 @Feature({"Payments"}) | 98 @Feature({"Payments"}) |
| 93 public void testNumberOfBillingAddressSuggestions_AfterCancellingNewBillingA
ddress() | 99 public void testNumberOfBillingAddressSuggestions_AfterCancellingNewBillingA
ddress() |
| 94 throws InterruptedException, ExecutionException, TimeoutException { | 100 throws InterruptedException, ExecutionException, TimeoutException { |
| 95 // Add a payment method and add a new billing address. | 101 // Add a payment method and add a new billing address. |
| 96 triggerUIAndWait(mReadyToPay); | 102 triggerUIAndWait(mReadyToPay); |
| 97 clickInPaymentMethodAndWait(R.id.payments_section, mReadyForInput); | 103 clickInPaymentMethodAndWait(R.id.payments_section, mReadyForInput); |
| 98 clickInPaymentMethodAndWait(R.id.payments_add_option_button, mReadyToEdi
t); | 104 clickInPaymentMethodAndWait(R.id.payments_add_option_button, mReadyToEdi
t); |
| 99 | 105 |
| 100 // Select the "+ ADD ADDRESS" option for the billing address. | 106 // Select the "+ ADD ADDRESS" option for the billing address. |
| 101 setSpinnerSelectionsInCardEditorAndWait( | 107 setSpinnerSelectionsInCardEditorAndWait( |
| 102 new int[] {11, 1, ADD_BILLING_ADDRESS}, mReadyToEdit); | 108 new int[] {DECEMBER, NEXT_YEAR, ADD_BILLING_ADDRESS}, mReadyToEd
it); |
| 103 | 109 |
| 104 // Cancel the creation of a new billing address. | 110 // Cancel the creation of a new billing address. |
| 105 clickInEditorAndWait(R.id.payments_edit_cancel_button, mReadyToEdit); | 111 clickInEditorAndWait(R.id.payments_edit_cancel_button, mReadyToEdit); |
| 106 | 112 |
| 107 // There should still only be 4 suggestions, the 3 saved addresses and t
he option to add a | 113 // There should still only be 4 suggestions, the 3 saved addresses and t
he option to add a |
| 108 // new address. | 114 // new address. |
| 109 assertEquals(4, getSpinnerItemCountInCardEditor(2)); | 115 assertEquals(4, getSpinnerItemCountInCardEditor(BILLING_ADDRESS_DROPDOWN
_INDEX)); |
| 110 } | 116 } |
| 111 | 117 |
| 112 /** | 118 /** |
| 113 * Verifies that the billing address suggestions are ordered by frecency. | 119 * Verifies that the billing address suggestions are ordered by frecency. |
| 114 */ | 120 */ |
| 115 @MediumTest | 121 @MediumTest |
| 116 @Feature({"Payments"}) | 122 @Feature({"Payments"}) |
| 117 public void testBillingAddressSortedByFrecency() | 123 public void testBillingAddressSortedByFrecency() |
| 118 throws InterruptedException, ExecutionException, TimeoutException { | 124 throws InterruptedException, ExecutionException, TimeoutException { |
| 119 // Add a payment method. | 125 // Add a payment method. |
| 120 triggerUIAndWait(mReadyToPay); | 126 triggerUIAndWait(mReadyToPay); |
| 121 clickInPaymentMethodAndWait(R.id.payments_section, mReadyForInput); | 127 clickInPaymentMethodAndWait(R.id.payments_section, mReadyForInput); |
| 122 clickInPaymentMethodAndWait(R.id.payments_add_option_button, mReadyToEdi
t); | 128 clickInPaymentMethodAndWait(R.id.payments_add_option_button, mReadyToEdi
t); |
| 123 | 129 |
| 124 // There should be 4 suggestions, the 3 saved addresses and the option t
o add a new address. | 130 // There should be 4 suggestions, the 3 saved addresses and the option t
o add a new address. |
| 125 assertEquals(4, getSpinnerItemCountInCardEditor(2)); | 131 assertEquals(4, getSpinnerItemCountInCardEditor(BILLING_ADDRESS_DROPDOWN
_INDEX)); |
| 126 | 132 |
| 127 // The billing address suggestions should be ordered by frecency. | 133 // The billing address suggestions should be ordered by frecency. |
| 128 assertTrue(getSpinnerTextAtPositionInCardEditor(2, 0).equals( | 134 assertTrue(getSpinnerTextAtPositionInCardEditor(BILLING_ADDRESS_DROPDOWN
_INDEX, |
| 129 "Rob Doe, 340 Main St, Los Angeles, CA 90291")); | 135 0).equals("Rob Doe, 340 Main St, Los Angeles, CA 90291")); |
| 130 assertTrue(getSpinnerTextAtPositionInCardEditor(2, 1).equals( | 136 assertTrue(getSpinnerTextAtPositionInCardEditor(BILLING_ADDRESS_DROPDOWN
_INDEX, |
| 131 "Jon Doe, 340 Main St, Los Angeles, CA 90291")); | 137 1).equals("Jon Doe, 340 Main St, Los Angeles, CA 90291")); |
| 132 assertTrue(getSpinnerTextAtPositionInCardEditor(2, 2).equals( | 138 assertTrue(getSpinnerTextAtPositionInCardEditor(BILLING_ADDRESS_DROPDOWN
_INDEX, |
| 133 "Tom Doe, 340 Main St, Los Angeles, CA 90291")); | 139 2).equals("Tom Doe, 340 Main St, Los Angeles, CA 90291")); |
| 134 assertTrue(getSpinnerTextAtPositionInCardEditor(2, 3).equals("Add addres
s")); | 140 assertTrue(getSpinnerTextAtPositionInCardEditor(BILLING_ADDRESS_DROPDOWN
_INDEX, |
| 141 3).equals("Add address")); |
| 135 } | 142 } |
| 136 | 143 |
| 137 /** | 144 /** |
| 138 * Verifies that the billing address suggestions are ordered by frecency, ex
cept for a newly | 145 * Verifies that the billing address suggestions are ordered by frecency, ex
cept for a newly |
| 139 * created address which should be suggested first. | 146 * created address which should be suggested first. |
| 140 */ | 147 */ |
| 141 @MediumTest | 148 @MediumTest |
| 142 @Feature({"Payments"}) | 149 @Feature({"Payments"}) |
| 143 public void testBillingAddressSortedByFrecency_AddNewAddress() | 150 public void testBillingAddressSortedByFrecency_AddNewAddress() |
| 144 throws InterruptedException, ExecutionException, TimeoutException { | 151 throws InterruptedException, ExecutionException, TimeoutException { |
| 145 // Add a payment method. | 152 // Add a payment method. |
| 146 triggerUIAndWait(mReadyToPay); | 153 triggerUIAndWait(mReadyToPay); |
| 147 clickInPaymentMethodAndWait(R.id.payments_section, mReadyForInput); | 154 clickInPaymentMethodAndWait(R.id.payments_section, mReadyForInput); |
| 148 clickInPaymentMethodAndWait(R.id.payments_add_option_button, mReadyToEdi
t); | 155 clickInPaymentMethodAndWait(R.id.payments_add_option_button, mReadyToEdi
t); |
| 149 | 156 |
| 150 // Add a new billing address. | 157 // Add a new billing address. |
| 151 setSpinnerSelectionsInCardEditorAndWait( | 158 setSpinnerSelectionsInCardEditorAndWait( |
| 152 new int[] {11, 1, ADD_BILLING_ADDRESS}, mReadyToEdit); | 159 new int[] {DECEMBER, NEXT_YEAR, ADD_BILLING_ADDRESS}, mReadyToEd
it); |
| 153 setTextInEditorAndWait(new String[] {"Seb Doe", "Google", "340 Main St",
"Los Angeles", | 160 setTextInEditorAndWait(new String[] {"Seb Doe", "Google", "340 Main St",
"Los Angeles", |
| 154 "CA", "90291", "999-999-9999"}, mEditorTextUpdate); | 161 "CA", "90291", "999-999-9999"}, mEditorTextUpdate); |
| 155 clickInEditorAndWait(R.id.payments_edit_done_button, mReadyToEdit); | 162 clickInEditorAndWait(R.id.payments_edit_done_button, mReadyToEdit); |
| 156 | 163 |
| 157 // There should be 5 suggestions, the 3 initial addresses, the newly add
ed address and the | 164 // There should be 5 suggestions, the 3 initial addresses, the newly add
ed address and the |
| 158 // option to add a new address. | 165 // option to add a new address. |
| 159 assertEquals(5, getSpinnerItemCountInCardEditor(2)); | 166 assertEquals(5, getSpinnerItemCountInCardEditor(BILLING_ADDRESS_DROPDOWN
_INDEX)); |
| 160 | 167 |
| 161 // TODO(crbug.com/666048): New billing address label is wrong. | 168 // TODO(crbug.com/666048): New billing address label is wrong. |
| 162 // The fist suggestion should be the newly added address. | 169 // The fist suggestion should be the newly added address. |
| 163 assertTrue(getSpinnerTextAtPositionInCardEditor(2, 0).equals( | 170 assertTrue(getSpinnerTextAtPositionInCardEditor(BILLING_ADDRESS_DROPDOWN
_INDEX, |
| 164 "Google, 340 Main St, Los Angeles, CA 90291, United States")); | 171 0).equals("Google, 340 Main St, Los Angeles, CA 90291, United St
ates")); |
| 165 | 172 |
| 166 // The rest of the billing address suggestions should be ordered by frec
ency. | 173 // The rest of the billing address suggestions should be ordered by frec
ency. |
| 167 assertTrue(getSpinnerTextAtPositionInCardEditor(2, 1).equals( | 174 assertTrue(getSpinnerTextAtPositionInCardEditor(BILLING_ADDRESS_DROPDOWN
_INDEX, |
| 168 "Rob Doe, 340 Main St, Los Angeles, CA 90291")); | 175 1).equals("Rob Doe, 340 Main St, Los Angeles, CA 90291")); |
| 169 assertTrue(getSpinnerTextAtPositionInCardEditor(2, 2).equals( | 176 assertTrue(getSpinnerTextAtPositionInCardEditor(BILLING_ADDRESS_DROPDOWN
_INDEX, |
| 170 "Jon Doe, 340 Main St, Los Angeles, CA 90291")); | 177 2).equals("Jon Doe, 340 Main St, Los Angeles, CA 90291")); |
| 171 assertTrue(getSpinnerTextAtPositionInCardEditor(2, 3).equals( | 178 assertTrue(getSpinnerTextAtPositionInCardEditor(BILLING_ADDRESS_DROPDOWN
_INDEX, |
| 172 "Tom Doe, 340 Main St, Los Angeles, CA 90291")); | 179 3).equals("Tom Doe, 340 Main St, Los Angeles, CA 90291")); |
| 173 assertTrue(getSpinnerTextAtPositionInCardEditor(2, 4).equals("Add addres
s")); | 180 assertTrue(getSpinnerTextAtPositionInCardEditor(BILLING_ADDRESS_DROPDOWN
_INDEX, |
| 181 4).equals("Add address")); |
| 182 } |
| 183 |
| 184 /** |
| 185 * Verifies that a newly created shipping address is offered as the first bi
lling address |
| 186 * suggestion. |
| 187 */ |
| 188 @MediumTest |
| 189 @Feature({"Payments"}) |
| 190 public void testNewShippingAddressSuggestedFirst() |
| 191 throws InterruptedException, ExecutionException, TimeoutException { |
| 192 triggerUIAndWait(mReadyToPay); |
| 193 |
| 194 // Add a shipping address. |
| 195 clickInShippingSummaryAndWait(R.id.payments_section, mReadyForInput); |
| 196 clickInShippingAddressAndWait(R.id.payments_add_option_button, mReadyToE
dit); |
| 197 setTextInEditorAndWait(new String[] {"Seb Doe", "Google", "340 Main St",
"Los Angeles", |
| 198 "CA", "90291", "999-999-9999"}, mEditorTextUpdate); |
| 199 clickInEditorAndWait(R.id.payments_edit_done_button, mReadyToPay); |
| 200 |
| 201 // Navigate to the card editor UI. |
| 202 clickInPaymentMethodAndWait(R.id.payments_section, mReadyForInput); |
| 203 clickInPaymentMethodAndWait(R.id.payments_add_option_button, mReadyToEdi
t); |
| 204 |
| 205 // There should be 5 suggestions, the 3 initial addresses, the newly add
ed address and the |
| 206 // option to add a new address. |
| 207 assertEquals(5, getSpinnerItemCountInCardEditor(BILLING_ADDRESS_DROPDOWN
_INDEX)); |
| 208 |
| 209 // TODO(crbug.com/666048): New billing address label is wrong. |
| 210 // The new address should be suggested first. |
| 211 assertTrue(getSpinnerTextAtPositionInCardEditor(BILLING_ADDRESS_DROPDOWN
_INDEX, |
| 212 0).equals("Google, 340 Main St, Los Angeles, CA 90291, United St
ates")); |
| 174 } | 213 } |
| 175 } | 214 } |
| OLD | NEW |