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 | 13 |
14 import java.util.ArrayList; | 14 import java.util.ArrayList; |
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 a merchant that requires shipping address to c
alculate shipping | 19 * A payment integration test for a merchant that requires shipping address to c
alculate shipping |
20 * and user that has 5 addresses stored in autofill settings. | 20 * and user that has 5 addresses stored in autofill settings. |
21 */ | 21 */ |
22 public class PaymentRequestDynamicShippingMultipleAddressesTest extends PaymentR
equestTestBase { | 22 public class PaymentRequestDynamicShippingMultipleAddressesTest extends PaymentR
equestTestBase { |
23 private static final AutofillProfile[] AUTOFILL_PROFILES = { | 23 private static final AutofillProfile[] AUTOFILL_PROFILES = { |
24 // Incomplete profile (missing phone number) | 24 // Incomplete profile (missing phone number) |
25 new AutofillProfile("" /* guid */, "https://www.example.com" /* origin *
/, | 25 new AutofillProfile("" /* guid */, "https://www.example.com" /* origin *
/, |
26 "Bart Simpson", "Acme Inc.", "123 Main", "California", "Los Ange
les", "", | 26 "Bart Simpson", "Acme Inc.", "123 Main", "California", "Los Ange
les", "", |
27 "90210", "", "US", "", "bart@simpson.com", ""), | 27 "90210", "", "US", "", "bart@simpson.com", ""), |
28 | 28 |
29 // Incomplete profile. | 29 // Incomplete profile (missing street address). |
30 new AutofillProfile("" /* guid */, "https://www.example.com" /* origin *
/, | 30 new AutofillProfile("" /* guid */, "https://www.example.com" /* origin *
/, |
31 "Homer Simpson", "Acme Inc.", "123 Main", "California", "Los Ang
eles", "", | 31 "Homer Simpson", "Acme Inc.", "", "California", "Los Angeles", "
", |
32 "90210", "", "US", "", "homer@simpson.com", ""), | 32 "90210", "", "US", "555 123-4567", "homer@simpson.com", ""), |
33 | 33 |
34 // Complete profile. | 34 // Complete profile. |
35 new AutofillProfile("" /* guid */, "https://www.example.com" /* origin *
/, | 35 new AutofillProfile("" /* guid */, "https://www.example.com" /* origin *
/, |
36 "Lisa Simpson", "Acme Inc.", "123 Main", "California", "Los Ange
les", "", | 36 "Lisa Simpson", "Acme Inc.", "123 Main", "California", "Los Ange
les", "", |
37 "90210", "", "US", "555 123-4567", "lisa@simpson.com", ""), | 37 "90210", "", "US", "555 123-4567", "lisa@simpson.com", ""), |
38 | 38 |
39 // Complete profile in another country. | 39 // Complete profile in another country. |
40 new AutofillProfile("" /* guid */, "https://www.example.com" /* origin *
/, | 40 new AutofillProfile("" /* guid */, "https://www.example.com" /* origin *
/, |
41 "Maggie Simpson", "Acme Inc.", "123 Main", "California", "Los An
geles", "", | 41 "Maggie Simpson", "Acme Inc.", "123 Main", "California", "Los An
geles", "", |
42 "90210", "", "Uzbekistan", "555 123-4567", "maggie@simpson.com",
""), | 42 "90210", "", "Uzbekistan", "555 123-4567", "maggie@simpson.com",
""), |
43 | 43 |
44 // Incomplete profile. | 44 // Incomplete profile. |
45 new AutofillProfile("" /* guid */, "https://www.example.com" /* origin *
/, | 45 new AutofillProfile("" /* guid */, "https://www.example.com" /* origin *
/, |
46 "Marge Simpson", "Acme Inc.", "123 Main", "California", "Los Ang
eles", "", | 46 "Marge Simpson", "Acme Inc.", "123 Main", "California", "Los Ang
eles", "", |
47 "90210", "", "US", "", "marge@simpson.com", "") | 47 "90210", "", "US", "", "marge@simpson.com", ""), |
| 48 |
| 49 // Incomplete profile. |
| 50 new AutofillProfile("" /* guid */, "https://www.example.com" /* origin *
/, |
| 51 "Professor Frink", "Acme Inc.", "123 Main", "California", "", ""
, |
| 52 "90210", "", "US", "555 123-4567", "lisa@simpson.com", ""), |
48 }; | 53 }; |
49 | 54 |
50 private AutofillProfile[] mProfilesToAdd; | 55 private AutofillProfile[] mProfilesToAdd; |
51 private int[] mCountsToSet; | 56 private int[] mCountsToSet; |
52 private int[] mDatesToSet; | 57 private int[] mDatesToSet; |
53 | 58 |
54 public PaymentRequestDynamicShippingMultipleAddressesTest() { | 59 public PaymentRequestDynamicShippingMultipleAddressesTest() { |
55 // This merchant requests the shipping address first before providing an
y shipping options. | 60 // This merchant requests the shipping address first before providing an
y shipping options. |
56 super("payment_request_dynamic_shipping_test.html"); | 61 super("payment_request_dynamic_shipping_test.html"); |
57 } | 62 } |
(...skipping 17 matching lines...) Expand all Loading... |
75 | 80 |
76 /** | 81 /** |
77 * Make sure the address suggestions are in the correct order and that only
the top 4 | 82 * Make sure the address suggestions are in the correct order and that only
the top 4 |
78 * suggestions are shown. They should be ordered by frecency and complete ad
dresses should be | 83 * suggestions are shown. They should be ordered by frecency and complete ad
dresses should be |
79 * suggested first. | 84 * suggested first. |
80 */ | 85 */ |
81 @MediumTest | 86 @MediumTest |
82 @Feature({"Payments"}) | 87 @Feature({"Payments"}) |
83 public void testShippingAddressSuggestionOrdering() | 88 public void testShippingAddressSuggestionOrdering() |
84 throws InterruptedException, ExecutionException, TimeoutException { | 89 throws InterruptedException, ExecutionException, TimeoutException { |
85 // Create a bunch of profiles, some complete, some incomplete. Values a
re set so that the | 90 // Create two complete and two incomplete profiles. Values are set so th
at the profiles are |
86 // profiles are ordered by frecency. | 91 // ordered by frecency. |
87 mProfilesToAdd = new AutofillProfile[] { | 92 mProfilesToAdd = new AutofillProfile[] { |
88 AUTOFILL_PROFILES[0], AUTOFILL_PROFILES[1], AUTOFILL_PROFILES[2]
, | 93 AUTOFILL_PROFILES[0], AUTOFILL_PROFILES[2], AUTOFILL_PROFILES[3]
, |
89 AUTOFILL_PROFILES[3], AUTOFILL_PROFILES[4]}; | 94 AUTOFILL_PROFILES[4]}; |
90 mCountsToSet = new int[] {20, 15, 10, 5, 1}; | 95 mCountsToSet = new int[] {20, 15, 10, 5, 1}; |
91 mDatesToSet = new int[] {5000, 5000, 5000, 5000, 1}; | 96 mDatesToSet = new int[] {5000, 5000, 5000, 5000, 1}; |
92 | 97 |
93 triggerUIAndWait(mReadyForInput); | 98 triggerUIAndWait(mReadyForInput); |
94 clickInShippingSummaryAndWait(R.id.payments_section, mReadyForInput); | 99 clickInShippingSummaryAndWait(R.id.payments_section, mReadyForInput); |
95 assertEquals(4, getNumberOfShippingAddressSuggestions()); | 100 assertEquals(4, getNumberOfShippingAddressSuggestions()); |
96 assertTrue(getShippingAddressSuggestionLabel(0).contains("Lisa Simpson")
); | 101 assertTrue(getShippingAddressSuggestionLabel(0).contains("Lisa Simpson")
); |
97 assertTrue(getShippingAddressSuggestionLabel(1).contains("Maggie Simpson
")); | 102 assertTrue(getShippingAddressSuggestionLabel(1).contains("Maggie Simpson
")); |
98 assertTrue(getShippingAddressSuggestionLabel(2).contains("Bart Simpson")
); | 103 assertTrue(getShippingAddressSuggestionLabel(2).contains("Bart Simpson")
); |
99 assertTrue(getShippingAddressSuggestionLabel(3).contains("Homer Simpson"
)); | 104 assertTrue(getShippingAddressSuggestionLabel(3).contains("Marge Simpson"
)); |
100 } | 105 } |
101 | 106 |
102 /** | 107 /** |
| 108 * Make sure that a maximum of four profiles are shown to the user. |
| 109 */ |
| 110 @MediumTest |
| 111 @Feature({"Payments"}) |
| 112 public void testShippingAddressSuggestionLimit() |
| 113 throws InterruptedException, ExecutionException, TimeoutException { |
| 114 // Create five profiles that can be suggested to the user. |
| 115 mProfilesToAdd = new AutofillProfile[] { |
| 116 AUTOFILL_PROFILES[0], AUTOFILL_PROFILES[2], AUTOFILL_PROFILES[3]
, |
| 117 AUTOFILL_PROFILES[4], AUTOFILL_PROFILES[5]}; |
| 118 mCountsToSet = new int[] {20, 15, 10, 5, 2, 1}; |
| 119 mDatesToSet = new int[] {5000, 5000, 5000, 5000, 2, 1}; |
| 120 |
| 121 triggerUIAndWait(mReadyForInput); |
| 122 clickInShippingSummaryAndWait(R.id.payments_section, mReadyForInput); |
| 123 // Only four profiles should be suggested to the user. |
| 124 assertEquals(4, getNumberOfShippingAddressSuggestions()); |
| 125 assertTrue(getShippingAddressSuggestionLabel(0).contains("Lisa Simpson")
); |
| 126 assertTrue(getShippingAddressSuggestionLabel(1).contains("Maggie Simpson
")); |
| 127 assertTrue(getShippingAddressSuggestionLabel(2).contains("Bart Simpson")
); |
| 128 assertTrue(getShippingAddressSuggestionLabel(3).contains("Marge Simpson"
)); |
| 129 } |
| 130 |
| 131 /** |
| 132 * Make sure that only profiles with a street address are suggested to the u
ser. |
| 133 */ |
| 134 @MediumTest |
| 135 @Feature({"Payments"}) |
| 136 public void testShippingAddressSuggestion_OnlyIncludeProfilesWithStreetAddre
ss() |
| 137 throws InterruptedException, ExecutionException, TimeoutException { |
| 138 // Create two complete profiles and two incomplete profiles, one of whic
h has no street |
| 139 // address. |
| 140 mProfilesToAdd = new AutofillProfile[] { |
| 141 AUTOFILL_PROFILES[0], AUTOFILL_PROFILES[1], AUTOFILL_PROFILES[2]
, |
| 142 AUTOFILL_PROFILES[3]}; |
| 143 mCountsToSet = new int[] {15, 10, 5, 1}; |
| 144 mDatesToSet = new int[] {5000, 5000, 5000, 1}; |
| 145 |
| 146 triggerUIAndWait(mReadyForInput); |
| 147 clickInShippingSummaryAndWait(R.id.payments_section, mReadyForInput); |
| 148 // Only 3 profiles should be suggested, the two complete ones and the in
complete one that |
| 149 // has a street address. |
| 150 assertEquals(3, getNumberOfShippingAddressSuggestions()); |
| 151 assertTrue(getShippingAddressSuggestionLabel(0).contains("Lisa Simpson")
); |
| 152 assertTrue(getShippingAddressSuggestionLabel(1).contains("Maggie Simpson
")); |
| 153 assertTrue(getShippingAddressSuggestionLabel(2).contains("Bart Simpson")
); |
| 154 } |
| 155 |
| 156 /** |
103 * Select a shipping address that the website refuses to accept, which shoul
d force the dialog | 157 * Select a shipping address that the website refuses to accept, which shoul
d force the dialog |
104 * to show an error. | 158 * to show an error. |
105 */ | 159 */ |
106 @MediumTest | 160 @MediumTest |
107 @Feature({"Payments"}) | 161 @Feature({"Payments"}) |
108 public void testShippingAddresNotAcceptedByMerchant() | 162 public void testShippingAddresNotAcceptedByMerchant() |
109 throws InterruptedException, ExecutionException, TimeoutException { | 163 throws InterruptedException, ExecutionException, TimeoutException { |
110 // Add a profile that is not accepted by the website. | 164 // Add a profile that is not accepted by the website. |
111 mProfilesToAdd = new AutofillProfile[] {AUTOFILL_PROFILES[3]}; | 165 mProfilesToAdd = new AutofillProfile[] {AUTOFILL_PROFILES[3]}; |
112 mCountsToSet = new int[] {5}; | 166 mCountsToSet = new int[] {5}; |
113 mDatesToSet = new int[] {5000}; | 167 mDatesToSet = new int[] {5000}; |
114 | 168 |
115 // Click on the unacceptable shipping address. | 169 // Click on the unacceptable shipping address. |
116 triggerUIAndWait(mReadyForInput); | 170 triggerUIAndWait(mReadyForInput); |
117 clickInShippingSummaryAndWait(R.id.payments_section, mReadyForInput); | 171 clickInShippingSummaryAndWait(R.id.payments_section, mReadyForInput); |
118 assertTrue(getShippingAddressSuggestionLabel(0).contains( | 172 assertTrue(getShippingAddressSuggestionLabel(0).contains( |
119 AUTOFILL_PROFILES[3].getFullName())); | 173 AUTOFILL_PROFILES[3].getFullName())); |
120 clickOnShippingAddressSuggestionOptionAndWait(0, mSelectionChecked); | 174 clickOnShippingAddressSuggestionOptionAndWait(0, mSelectionChecked); |
121 | 175 |
122 // The string should indicate that the shipping address isn't valid. | 176 // The string should indicate that the shipping address isn't valid. |
123 CharSequence actualString = getShippingAddressOptionRowAtIndex(0).getLab
elText(); | 177 CharSequence actualString = getShippingAddressOptionRowAtIndex(0).getLab
elText(); |
124 CharSequence expectedString = getInstrumentation().getTargetContext().ge
tString( | 178 CharSequence expectedString = getInstrumentation().getTargetContext().ge
tString( |
125 R.string.payments_unsupported_shipping_address); | 179 R.string.payments_unsupported_shipping_address); |
126 assertEquals(expectedString, actualString); | 180 assertEquals(expectedString, actualString); |
127 } | 181 } |
128 } | 182 } |
OLD | NEW |