OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include "components/payments/core/profile_util.h" | 5 #include "components/payments/core/payments_profile_comparator.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/guid.h" | 10 #include "base/guid.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "components/autofill/core/browser/autofill_profile.h" | 13 #include "components/autofill/core/browser/autofill_profile.h" |
14 #include "components/autofill/core/browser/autofill_test_utils.h" | 14 #include "components/autofill/core/browser/autofill_test_utils.h" |
15 #include "components/payments/core/payment_options_provider.h" | 15 #include "components/payments/core/payment_options_provider.h" |
| 16 #include "components/strings/grit/components_strings.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "ui/base/l10n/l10n_util.h" |
17 | 19 |
18 using autofill::AutofillProfile; | 20 using autofill::AutofillProfile; |
19 | 21 |
20 namespace payments { | 22 namespace payments { |
21 namespace profile_util { | |
22 | 23 |
23 constexpr uint32_t kRequestPayerName = 1 << 0; | 24 constexpr uint32_t kRequestPayerName = 1 << 0; |
24 constexpr uint32_t kRequestPayerEmail = 1 << 1; | 25 constexpr uint32_t kRequestPayerEmail = 1 << 1; |
25 constexpr uint32_t kRequestPayerPhone = 1 << 2; | 26 constexpr uint32_t kRequestPayerPhone = 1 << 2; |
26 constexpr uint32_t kRequestShipping = 1 << 3; | 27 constexpr uint32_t kRequestShipping = 1 << 3; |
27 | 28 |
28 class MockPaymentOptionsProvider : public PaymentOptionsProvider { | 29 class MockPaymentOptionsProvider : public PaymentOptionsProvider { |
29 public: | 30 public: |
30 MockPaymentOptionsProvider(uint32_t options) : options_(options) {} | 31 MockPaymentOptionsProvider(uint32_t options) : options_(options) {} |
31 | 32 |
(...skipping 18 matching lines...) Expand all Loading... |
50 | 51 |
51 AutofillProfile CreateProfileWithContactInfo(const char* name, | 52 AutofillProfile CreateProfileWithContactInfo(const char* name, |
52 const char* email, | 53 const char* email, |
53 const char* phone) { | 54 const char* phone) { |
54 AutofillProfile profile(base::GenerateGUID(), "http://www.example.com/"); | 55 AutofillProfile profile(base::GenerateGUID(), "http://www.example.com/"); |
55 autofill::test::SetProfileInfo(&profile, name, "", "", email, "", "", "", "", | 56 autofill::test::SetProfileInfo(&profile, name, "", "", email, "", "", "", "", |
56 "", "", "", phone); | 57 "", "", "", phone); |
57 return profile; | 58 return profile; |
58 } | 59 } |
59 | 60 |
| 61 AutofillProfile CreateProfileWithCompleteAddress(const char* name, |
| 62 const char* phone) { |
| 63 AutofillProfile profile(base::GenerateGUID(), "http://www.example.com/"); |
| 64 autofill::test::SetProfileInfo(&profile, name, "", "", "", "", "123 Fake St.", |
| 65 "", "Fakesville", "MN", "54000", "US", phone); |
| 66 return profile; |
| 67 } |
| 68 |
| 69 AutofillProfile CreateProfileWithPartialAddress(const char* name, |
| 70 const char* phone) { |
| 71 AutofillProfile profile(base::GenerateGUID(), "http://www.example.com/"); |
| 72 autofill::test::SetProfileInfo(&profile, name, "", "", "", "", "123 Fake St.", |
| 73 "", "", "", "54000", "", phone); |
| 74 return profile; |
| 75 } |
| 76 |
60 TEST(PaymentRequestProfileUtilTest, FilterProfilesForContact) { | 77 TEST(PaymentRequestProfileUtilTest, FilterProfilesForContact) { |
61 // These profiles are subset/equal, so only the first complete one is | 78 // These profiles are subset/equal, so only the first complete one is |
62 // included. | 79 // included. |
63 AutofillProfile exclude_1 = | 80 AutofillProfile exclude_1 = |
64 CreateProfileWithContactInfo("Homer", "", "5551234567"); | 81 CreateProfileWithContactInfo("Homer", "", "6515553226"); |
65 | 82 |
66 AutofillProfile exclude_2 = | 83 AutofillProfile exclude_2 = |
67 CreateProfileWithContactInfo("Homer", "homer@simpson.net", ""); | 84 CreateProfileWithContactInfo("Homer", "homer@simpson.net", ""); |
68 | 85 |
69 AutofillProfile include_1 = | 86 AutofillProfile include_1 = |
70 CreateProfileWithContactInfo("Homer", "homer@simpson.net", "5551234567"); | 87 CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226"); |
71 | 88 |
72 AutofillProfile exclude_3 = | 89 AutofillProfile exclude_3 = |
73 CreateProfileWithContactInfo("Homer", "homer@simpson.net", "5551234567"); | 90 CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226"); |
74 | 91 |
75 // This profile is different, so it should also be included. Since it is | 92 // This profile is different, so it should also be included. Since it is |
76 // less complete than |include_1|, it will appear after. | 93 // less complete than |include_1|, it will appear after. |
77 AutofillProfile include_2 = | 94 AutofillProfile include_2 = |
78 CreateProfileWithContactInfo("Marge", "marge@simpson.net", ""); | 95 CreateProfileWithContactInfo("Marge", "marge@simpson.net", ""); |
79 | 96 |
80 // This profile is different, so it should also be included. Since it is | 97 // This profile is different, so it should also be included. Since it is |
81 // equally complete with |include_1|, it will appear before |include_2|, but | 98 // equally complete with |include_1|, it will appear before |include_2|, but |
82 // after |include_1| since order is preserved amongst profiles of equal | 99 // after |include_1| since order is preserved amongst profiles of equal |
83 // completeness. | 100 // completeness. |
84 AutofillProfile include_3 = CreateProfileWithContactInfo( | 101 AutofillProfile include_3 = CreateProfileWithContactInfo( |
85 "Bart", "eatmyshorts@simpson.net", "5551234567"); | 102 "Bart", "eatmyshorts@simpson.net", "6515553226"); |
86 | 103 |
87 std::vector<AutofillProfile*> profiles = {&exclude_1, &exclude_2, &include_1, | 104 std::vector<AutofillProfile*> profiles = {&exclude_1, &exclude_2, &include_1, |
88 &exclude_3, &include_2, &include_3}; | 105 &exclude_3, &include_2, &include_3}; |
89 | 106 |
90 MockPaymentOptionsProvider provider(kRequestPayerName | kRequestPayerEmail | | 107 MockPaymentOptionsProvider provider(kRequestPayerName | kRequestPayerEmail | |
91 kRequestPayerPhone); | 108 kRequestPayerPhone); |
| 109 PaymentsProfileComparator comp("en-US", provider); |
| 110 |
92 std::vector<AutofillProfile*> filtered = | 111 std::vector<AutofillProfile*> filtered = |
93 FilterProfilesForContact(profiles, "en-US", provider); | 112 comp.FilterProfilesForContact(profiles); |
94 | 113 |
95 ASSERT_EQ(3u, filtered.size()); | 114 ASSERT_EQ(3u, filtered.size()); |
96 EXPECT_EQ(&include_1, filtered[0]); | 115 EXPECT_EQ(&include_1, filtered[0]); |
97 EXPECT_EQ(&include_3, filtered[1]); | 116 EXPECT_EQ(&include_3, filtered[1]); |
98 EXPECT_EQ(&include_2, filtered[2]); | 117 EXPECT_EQ(&include_2, filtered[2]); |
99 | 118 |
100 // Repeat the filter using a provider set to only request phone numbers. | 119 // Repeat the filter using a provider set to only request phone numbers. |
101 // Under these rules, since all profiles have the same (or no) phone number, | 120 // Under these rules, since all profiles have the same (or no) phone number, |
102 // we should only see the first profile with a phone number, |exclude_1|. | 121 // we should only see the first profile with a phone number, |exclude_1|. |
103 MockPaymentOptionsProvider phone_only_provider(kRequestPayerPhone); | 122 MockPaymentOptionsProvider phone_only_provider(kRequestPayerPhone); |
| 123 PaymentsProfileComparator phone_only_comp("en-US", phone_only_provider); |
104 std::vector<AutofillProfile*> filtered_phones = | 124 std::vector<AutofillProfile*> filtered_phones = |
105 FilterProfilesForContact(profiles, "en-US", phone_only_provider); | 125 phone_only_comp.FilterProfilesForContact(profiles); |
106 ASSERT_EQ(1u, filtered_phones.size()); | 126 ASSERT_EQ(1u, filtered_phones.size()); |
107 EXPECT_EQ(&exclude_1, filtered_phones[0]); | 127 EXPECT_EQ(&exclude_1, filtered_phones[0]); |
108 } | 128 } |
109 | 129 |
110 TEST(PaymentRequestProfileUtilTest, IsContactEqualOrSuperset) { | 130 TEST(PaymentRequestProfileUtilTest, IsContactEqualOrSuperset) { |
111 MockPaymentOptionsProvider provider(kRequestPayerName | kRequestPayerEmail | | 131 MockPaymentOptionsProvider provider(kRequestPayerName | kRequestPayerEmail | |
112 kRequestPayerPhone); | 132 kRequestPayerPhone); |
113 PaymentsProfileComparator comp("en-US", provider); | 133 PaymentsProfileComparator comp("en-US", provider); |
114 | 134 |
115 AutofillProfile p1 = | 135 AutofillProfile p1 = |
116 CreateProfileWithContactInfo("Homer", "homer@simpson.net", "5551234567"); | 136 CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226"); |
117 | 137 |
118 // Candidate subset profile is equal. | 138 // Candidate subset profile is equal. |
119 AutofillProfile p2 = | 139 AutofillProfile p2 = |
120 CreateProfileWithContactInfo("Homer", "homer@simpson.net", "5551234567"); | 140 CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226"); |
121 EXPECT_TRUE(comp.IsContactEqualOrSuperset(p1, p2)); | 141 EXPECT_TRUE(comp.IsContactEqualOrSuperset(p1, p2)); |
122 EXPECT_TRUE(comp.IsContactEqualOrSuperset(p2, p1)); | 142 EXPECT_TRUE(comp.IsContactEqualOrSuperset(p2, p1)); |
123 | 143 |
124 // Candidate subset profile has non-matching fields. | 144 // Candidate subset profile has non-matching fields. |
125 AutofillProfile p3 = CreateProfileWithContactInfo( | 145 AutofillProfile p3 = CreateProfileWithContactInfo( |
126 "Homer", "homer@springfieldnuclear.gov", "5551234567"); | 146 "Homer", "homer@springfieldnuclear.gov", "6515553226"); |
127 EXPECT_FALSE(comp.IsContactEqualOrSuperset(p1, p3)); | 147 EXPECT_FALSE(comp.IsContactEqualOrSuperset(p1, p3)); |
128 EXPECT_FALSE(comp.IsContactEqualOrSuperset(p3, p1)); | 148 EXPECT_FALSE(comp.IsContactEqualOrSuperset(p3, p1)); |
129 | 149 |
130 // Candidate subset profile is equal, except for missing fields. | 150 // Candidate subset profile is equal, except for missing fields. |
131 AutofillProfile p4 = | 151 AutofillProfile p4 = |
132 CreateProfileWithContactInfo("Homer", "homer@simpson.net", ""); | 152 CreateProfileWithContactInfo("Homer", "homer@simpson.net", ""); |
133 EXPECT_TRUE(comp.IsContactEqualOrSuperset(p1, p4)); | 153 EXPECT_TRUE(comp.IsContactEqualOrSuperset(p1, p4)); |
134 EXPECT_FALSE(comp.IsContactEqualOrSuperset(p4, p1)); | 154 EXPECT_FALSE(comp.IsContactEqualOrSuperset(p4, p1)); |
135 | 155 |
136 // One field is common, but each has a field which the other is missing. | 156 // One field is common, but each has a field which the other is missing. |
137 AutofillProfile p5 = | 157 AutofillProfile p5 = |
138 CreateProfileWithContactInfo("Homer", "homer@simpson.net", ""); | 158 CreateProfileWithContactInfo("Homer", "homer@simpson.net", ""); |
139 AutofillProfile p6 = CreateProfileWithContactInfo("Homer", "", "5551234567"); | 159 AutofillProfile p6 = CreateProfileWithContactInfo("Homer", "", "6515553226"); |
140 EXPECT_FALSE(comp.IsContactEqualOrSuperset(p5, p6)); | 160 EXPECT_FALSE(comp.IsContactEqualOrSuperset(p5, p6)); |
141 EXPECT_FALSE(comp.IsContactEqualOrSuperset(p6, p5)); | 161 EXPECT_FALSE(comp.IsContactEqualOrSuperset(p6, p5)); |
142 } | 162 } |
143 | 163 |
144 TEST(PaymentRequestProfileUtilTest, IsContactEqualOrSuperset_WithFieldIgnored) { | 164 TEST(PaymentRequestProfileUtilTest, IsContactEqualOrSuperset_WithFieldIgnored) { |
145 // Discrepancies in email should be ignored throughout this test. | 165 // Discrepancies in email should be ignored throughout this test. |
146 MockPaymentOptionsProvider provider(kRequestPayerName | kRequestPayerPhone); | 166 MockPaymentOptionsProvider provider(kRequestPayerName | kRequestPayerPhone); |
147 PaymentsProfileComparator comp("en-US", provider); | 167 PaymentsProfileComparator comp("en-US", provider); |
148 | 168 |
149 AutofillProfile p1 = | 169 AutofillProfile p1 = |
150 CreateProfileWithContactInfo("Homer", "homer@simpson.net", "5551234567"); | 170 CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226"); |
151 | 171 |
152 // Candidate subset profile is equal. | 172 // Candidate subset profile is equal. |
153 AutofillProfile p2 = | 173 AutofillProfile p2 = |
154 CreateProfileWithContactInfo("Homer", "homer@simpson.net", "5551234567"); | 174 CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226"); |
155 EXPECT_TRUE(comp.IsContactEqualOrSuperset(p1, p2)); | 175 EXPECT_TRUE(comp.IsContactEqualOrSuperset(p1, p2)); |
156 EXPECT_TRUE(comp.IsContactEqualOrSuperset(p2, p1)); | 176 EXPECT_TRUE(comp.IsContactEqualOrSuperset(p2, p1)); |
157 | 177 |
158 // Email fields don't match, but profiles are still equal. | 178 // Email fields don't match, but profiles are still equal. |
159 AutofillProfile p3 = CreateProfileWithContactInfo( | 179 AutofillProfile p3 = CreateProfileWithContactInfo( |
160 "Homer", "homer@springfieldnuclear.gov", "5551234567"); | 180 "Homer", "homer@springfieldnuclear.gov", "6515553226"); |
161 EXPECT_TRUE(comp.IsContactEqualOrSuperset(p1, p3)); | 181 EXPECT_TRUE(comp.IsContactEqualOrSuperset(p1, p3)); |
162 EXPECT_TRUE(comp.IsContactEqualOrSuperset(p3, p1)); | 182 EXPECT_TRUE(comp.IsContactEqualOrSuperset(p3, p1)); |
163 | 183 |
164 // Profile without an email is mutual subset of profile with an email. | 184 // Profile without an email is mutual subset of profile with an email. |
165 AutofillProfile p4 = CreateProfileWithContactInfo("Homer", "", "5551234567"); | 185 AutofillProfile p4 = CreateProfileWithContactInfo("Homer", "", "6515553226"); |
166 EXPECT_TRUE(comp.IsContactEqualOrSuperset(p1, p4)); | 186 EXPECT_TRUE(comp.IsContactEqualOrSuperset(p1, p4)); |
167 EXPECT_TRUE(comp.IsContactEqualOrSuperset(p4, p1)); | 187 EXPECT_TRUE(comp.IsContactEqualOrSuperset(p4, p1)); |
168 } | 188 } |
169 | 189 |
170 TEST(PaymentRequestProfileUtilTest, GetContactCompletenessScore) { | 190 TEST(PaymentRequestProfileUtilTest, GetContactCompletenessScore) { |
171 MockPaymentOptionsProvider provider(kRequestPayerName | kRequestPayerPhone); | 191 MockPaymentOptionsProvider provider(kRequestPayerName | kRequestPayerPhone); |
172 PaymentsProfileComparator comp("en-US", provider); | 192 PaymentsProfileComparator comp("en-US", provider); |
173 | 193 |
174 // Two completeness points: One each for name and phone number, but not email | 194 // Two completeness points: One each for name and phone number, but not email |
175 // as it was not requested. | 195 // as it was not requested. |
176 AutofillProfile p1 = | 196 AutofillProfile p1 = |
177 CreateProfileWithContactInfo("Homer", "homer@simpson.net", "5551234567"); | 197 CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226"); |
178 EXPECT_EQ(2, comp.GetContactCompletenessScore(&p1)); | 198 EXPECT_EQ(2, comp.GetContactCompletenessScore(&p1)); |
179 | 199 |
180 // One completeness point for name, no points for phone number (missing) or | 200 // One completeness point for name, no points for phone number (missing) or |
181 // email (not requested). | 201 // email (not requested). |
182 AutofillProfile p2 = | 202 AutofillProfile p2 = |
183 CreateProfileWithContactInfo("Homer", "homer@simpson.net", ""); | 203 CreateProfileWithContactInfo("Homer", "homer@simpson.net", ""); |
184 EXPECT_EQ(1, comp.GetContactCompletenessScore(&p2)); | 204 EXPECT_EQ(1, comp.GetContactCompletenessScore(&p2)); |
185 | 205 |
186 // No completeness points, as the only field present was not requested. | 206 // No completeness points, as the only field present was not requested. |
187 AutofillProfile p3 = | 207 AutofillProfile p3 = |
188 CreateProfileWithContactInfo("", "homer@simpson.net", ""); | 208 CreateProfileWithContactInfo("", "homer@simpson.net", ""); |
189 EXPECT_EQ(0, comp.GetContactCompletenessScore(&p3)); | 209 EXPECT_EQ(0, comp.GetContactCompletenessScore(&p3)); |
190 | 210 |
191 // Null profile returns 0. | 211 // Null profile returns 0. |
192 EXPECT_EQ(0, comp.GetContactCompletenessScore(nullptr)); | 212 EXPECT_EQ(0, comp.GetContactCompletenessScore(nullptr)); |
193 } | 213 } |
194 | 214 |
195 TEST(PaymentRequestProfileUtilTest, IsContactInfoComplete) { | 215 TEST(PaymentRequestProfileUtilTest, IsContactInfoComplete) { |
196 MockPaymentOptionsProvider provider(kRequestPayerName | kRequestPayerEmail); | 216 MockPaymentOptionsProvider provider(kRequestPayerName | kRequestPayerEmail); |
197 PaymentsProfileComparator comp("en-US", provider); | 217 PaymentsProfileComparator comp("en-US", provider); |
198 | 218 |
199 // If name and email are present, return true regardless of the (ignored) | 219 // If name and email are present, return true regardless of the (ignored) |
200 // phone value. | 220 // phone value. |
201 AutofillProfile p1 = | 221 AutofillProfile p1 = |
202 CreateProfileWithContactInfo("Homer", "homer@simpson.net", "5551234567"); | 222 CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226"); |
203 AutofillProfile p2 = | 223 AutofillProfile p2 = |
204 CreateProfileWithContactInfo("Homer", "homer@simpson.net", ""); | 224 CreateProfileWithContactInfo("Homer", "homer@simpson.net", ""); |
205 | 225 |
206 EXPECT_TRUE(comp.IsContactInfoComplete(&p1)); | 226 EXPECT_TRUE(comp.IsContactInfoComplete(&p1)); |
207 EXPECT_TRUE(comp.IsContactInfoComplete(&p2)); | 227 EXPECT_TRUE(comp.IsContactInfoComplete(&p2)); |
208 | 228 |
209 // If name is not present, return false regardless of the (ignored) | 229 // If name is not present, return false regardless of the (ignored) |
210 // phone value. | 230 // phone value. |
211 AutofillProfile p3 = | 231 AutofillProfile p3 = |
212 CreateProfileWithContactInfo("", "homer@simpson.net", "5551234567"); | 232 CreateProfileWithContactInfo("", "homer@simpson.net", "6515553226"); |
213 AutofillProfile p4 = | 233 AutofillProfile p4 = |
214 CreateProfileWithContactInfo("", "homer@simpson.net", ""); | 234 CreateProfileWithContactInfo("", "homer@simpson.net", ""); |
215 | 235 |
216 EXPECT_FALSE(comp.IsContactInfoComplete(&p3)); | 236 EXPECT_FALSE(comp.IsContactInfoComplete(&p3)); |
217 EXPECT_FALSE(comp.IsContactInfoComplete(&p4)); | 237 EXPECT_FALSE(comp.IsContactInfoComplete(&p4)); |
218 | 238 |
219 // If no fields are requested, any profile (even empty or null) is complete. | 239 // If no fields are requested, any profile (even empty or null) is complete. |
220 MockPaymentOptionsProvider empty_provider(0); | 240 MockPaymentOptionsProvider empty_provider(0); |
221 PaymentsProfileComparator empty_comp("en-US", empty_provider); | 241 PaymentsProfileComparator empty_comp("en-US", empty_provider); |
222 | 242 |
223 AutofillProfile p5 = CreateProfileWithContactInfo("", "", ""); | 243 AutofillProfile p5 = CreateProfileWithContactInfo("", "", ""); |
224 | 244 |
225 EXPECT_TRUE(empty_comp.IsContactInfoComplete(&p1)); | 245 EXPECT_TRUE(empty_comp.IsContactInfoComplete(&p1)); |
226 EXPECT_TRUE(empty_comp.IsContactInfoComplete(&p5)); | 246 EXPECT_TRUE(empty_comp.IsContactInfoComplete(&p5)); |
227 EXPECT_TRUE(empty_comp.IsContactInfoComplete(nullptr)); | 247 EXPECT_TRUE(empty_comp.IsContactInfoComplete(nullptr)); |
228 } | 248 } |
229 | 249 |
230 } // namespace profile_util | 250 TEST(PaymentRequestProfileUtilTest, IsShippingComplete) { |
| 251 MockPaymentOptionsProvider provider(kRequestShipping); |
| 252 PaymentsProfileComparator comp("en-US", provider); |
| 253 |
| 254 // True if name, phone, and address are all populated. |
| 255 AutofillProfile p1 = CreateProfileWithCompleteAddress("Homer", "6515553226"); |
| 256 EXPECT_TRUE(comp.IsShippingComplete(&p1)); |
| 257 |
| 258 // False if address is partially populated. |
| 259 AutofillProfile p2 = CreateProfileWithPartialAddress("Homer", "6515553226"); |
| 260 EXPECT_FALSE(comp.IsShippingComplete(&p2)); |
| 261 |
| 262 // False if name isn't populated. |
| 263 AutofillProfile p3 = CreateProfileWithCompleteAddress("", "6515553226"); |
| 264 EXPECT_FALSE(comp.IsShippingComplete(&p3)); |
| 265 |
| 266 // False if phone isn't populated. |
| 267 AutofillProfile p4 = CreateProfileWithCompleteAddress("Homer", ""); |
| 268 EXPECT_FALSE(comp.IsShippingComplete(&p4)); |
| 269 |
| 270 // False if only contact info (no address fields) is populated. |
| 271 AutofillProfile p5 = |
| 272 CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226"); |
| 273 EXPECT_FALSE(comp.IsShippingComplete(&p5)); |
| 274 |
| 275 MockPaymentOptionsProvider provider_no_shipping(0); |
| 276 PaymentsProfileComparator comp_no_shipping("en-US", provider_no_shipping); |
| 277 // nullptr is handled correctly: false if shipping requested, true if not. |
| 278 EXPECT_FALSE(comp.IsShippingComplete(nullptr)); |
| 279 EXPECT_TRUE(comp_no_shipping.IsShippingComplete(nullptr)); |
| 280 } |
| 281 |
| 282 TEST(PaymentRequestProfileUtilTest, GetStringForMissingContactFields) { |
| 283 MockPaymentOptionsProvider provider(kRequestPayerName | kRequestPayerPhone | |
| 284 kRequestPayerEmail | kRequestShipping); |
| 285 PaymentsProfileComparator comp("en-US", provider); |
| 286 |
| 287 // No error message for complete profile. |
| 288 AutofillProfile p1 = |
| 289 CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226"); |
| 290 EXPECT_TRUE(comp.GetStringForMissingContactFields(p1).empty()); |
| 291 |
| 292 MockPaymentOptionsProvider provider_no_email( |
| 293 kRequestPayerName | kRequestPayerPhone | kRequestShipping); |
| 294 PaymentsProfileComparator comp_no_email("en-US", provider_no_email); |
| 295 |
| 296 // No error message if missing field wasn't required. |
| 297 AutofillProfile p2 = CreateProfileWithContactInfo("Homer", "", "6515553226"); |
| 298 EXPECT_TRUE(comp_no_email.GetStringForMissingContactFields(p2).empty()); |
| 299 |
| 300 // Error message for email address if email address is missing and required. |
| 301 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_EMAIL_REQUIRED), |
| 302 comp.GetStringForMissingContactFields(p2)); |
| 303 |
| 304 // Error message for phone number if phone is missing and required. |
| 305 AutofillProfile p3 = |
| 306 CreateProfileWithContactInfo("Homer", "homer@simpson.net", ""); |
| 307 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_PHONE_NUMBER_REQUIRED), |
| 308 comp.GetStringForMissingContactFields(p3)); |
| 309 |
| 310 // Error message for name if name is missing and required. |
| 311 AutofillProfile p4 = |
| 312 CreateProfileWithContactInfo("", "homer@simpson.net", "6515553226"); |
| 313 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_NAME_REQUIRED), |
| 314 comp.GetStringForMissingContactFields(p4)); |
| 315 |
| 316 // Generic error message if multiple fields missing. |
| 317 AutofillProfile p5 = |
| 318 CreateProfileWithContactInfo("", "homer@simpson.net", ""); |
| 319 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_MORE_INFORMATION_REQUIRED), |
| 320 comp.GetStringForMissingContactFields(p5)); |
| 321 } |
| 322 |
| 323 TEST(PaymentRequestProfileUtilTest, GetStringForMissingShippingFields) { |
| 324 MockPaymentOptionsProvider provider(kRequestPayerName | kRequestPayerPhone | |
| 325 kRequestPayerEmail | kRequestShipping); |
| 326 PaymentsProfileComparator comp("en-US", provider); |
| 327 |
| 328 // No error message for complete profile. |
| 329 AutofillProfile p1 = CreateProfileWithCompleteAddress("Homer", "6515553226"); |
| 330 EXPECT_TRUE(comp.GetStringForMissingShippingFields(p1).empty()); |
| 331 |
| 332 // Error message for shipping if shipping requested and not present. |
| 333 AutofillProfile p2 = |
| 334 CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226"); |
| 335 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_INVALID_ADDRESS), |
| 336 comp.GetStringForMissingShippingFields(p2)); |
| 337 |
| 338 // Error message for shipping if shipping requested and only partially |
| 339 // complete. |
| 340 AutofillProfile p3 = CreateProfileWithPartialAddress("Homer", "6515553226"); |
| 341 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_INVALID_ADDRESS), |
| 342 comp.GetStringForMissingShippingFields(p3)); |
| 343 |
| 344 // Error message for name if name requested and missing. |
| 345 AutofillProfile p4 = CreateProfileWithCompleteAddress("", "6515553226"); |
| 346 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_NAME_REQUIRED), |
| 347 comp.GetStringForMissingShippingFields(p4)); |
| 348 |
| 349 // Error message for phone if phone requested and missing. |
| 350 AutofillProfile p5 = CreateProfileWithCompleteAddress("Homer", ""); |
| 351 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_PHONE_NUMBER_REQUIRED), |
| 352 comp.GetStringForMissingShippingFields(p5)); |
| 353 |
| 354 // Generic error message if multiple fields missing. |
| 355 AutofillProfile p6 = CreateProfileWithContactInfo("", "", ""); |
| 356 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_MORE_INFORMATION_REQUIRED), |
| 357 comp.GetStringForMissingShippingFields(p6)); |
| 358 |
| 359 MockPaymentOptionsProvider provider_no_shipping( |
| 360 kRequestPayerName | kRequestPayerPhone | kRequestPayerEmail); |
| 361 PaymentsProfileComparator comp_no_shipping("en-US", provider_no_shipping); |
| 362 |
| 363 // No error message if everything is missing but shipping wasn't requested. |
| 364 EXPECT_TRUE(comp_no_shipping.GetStringForMissingShippingFields(p6).empty()); |
| 365 } |
| 366 |
231 } // namespace payments | 367 } // namespace payments |
OLD | NEW |