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/payments_profile_comparator.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" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 MockPaymentOptionsProvider empty_provider(0); | 240 MockPaymentOptionsProvider empty_provider(0); |
241 PaymentsProfileComparator empty_comp("en-US", empty_provider); | 241 PaymentsProfileComparator empty_comp("en-US", empty_provider); |
242 | 242 |
243 AutofillProfile p5 = CreateProfileWithContactInfo("", "", ""); | 243 AutofillProfile p5 = CreateProfileWithContactInfo("", "", ""); |
244 | 244 |
245 EXPECT_TRUE(empty_comp.IsContactInfoComplete(&p1)); | 245 EXPECT_TRUE(empty_comp.IsContactInfoComplete(&p1)); |
246 EXPECT_TRUE(empty_comp.IsContactInfoComplete(&p5)); | 246 EXPECT_TRUE(empty_comp.IsContactInfoComplete(&p5)); |
247 EXPECT_TRUE(empty_comp.IsContactInfoComplete(nullptr)); | 247 EXPECT_TRUE(empty_comp.IsContactInfoComplete(nullptr)); |
248 } | 248 } |
249 | 249 |
250 TEST(PaymentRequestProfileUtilTest, FilterProfilesForShipping) { | |
251 MockPaymentOptionsProvider provider(kRequestShipping); | |
252 PaymentsProfileComparator comp("en-US", provider); | |
253 | |
254 AutofillProfile address_only = CreateProfileWithCompleteAddress("", ""); | |
255 | |
256 AutofillProfile no_name = CreateProfileWithCompleteAddress("", "6515553226"); | |
257 AutofillProfile no_phone = CreateProfileWithCompleteAddress("Homer", ""); | |
258 | |
259 AutofillProfile empty = CreateProfileWithContactInfo("", "", ""); | |
260 | |
261 AutofillProfile complete1 = | |
262 CreateProfileWithCompleteAddress("Homer", "6515553226"); | |
263 | |
264 AutofillProfile partial_address = | |
265 CreateProfileWithPartialAddress("Homer", "6515553226"); | |
266 AutofillProfile no_address = | |
267 CreateProfileWithContactInfo("Homer", "", "6515553226"); | |
268 | |
269 AutofillProfile complete2 = | |
270 CreateProfileWithCompleteAddress("Bart", "6515553226"); | |
271 | |
272 AutofillProfile partial_no_phone = | |
273 CreateProfileWithPartialAddress("", "6515553226"); | |
274 AutofillProfile partial_no_name = | |
275 CreateProfileWithPartialAddress("Homer", ""); | |
276 | |
277 std::vector<AutofillProfile*> profiles = { | |
278 &address_only, &no_name, &no_phone, &empty, | |
279 &complete1, &partial_address, &no_address, &complete2, | |
280 &partial_no_phone, &partial_no_name}; | |
281 | |
282 std::vector<AutofillProfile*> filtered = | |
283 comp.FilterProfilesForShipping(profiles); | |
284 | |
285 // Current logic does not remove profiles, only reorder them. | |
286 ASSERT_EQ(10u, filtered.size()); | |
287 | |
288 // First, the complete profiles should be hoisted to the top, keeping their | |
289 // relative order. | |
290 EXPECT_EQ(&complete1, filtered[0]); | |
291 EXPECT_EQ(&complete2, filtered[1]); | |
292 | |
293 // Next are profiles with a complete address but missing one other field. | |
294 EXPECT_EQ(&no_name, filtered[2]); | |
295 EXPECT_EQ(&no_phone, filtered[3]); | |
296 | |
297 // A profile with only a complete address should still appear before profiles | |
298 // with partial/empty addresses. | |
299 EXPECT_EQ(&address_only, filtered[4]); | |
300 | |
301 // Profiles with partial/no address then are sorted by whether or not they | |
302 // have names and/or phone numbers. | |
303 EXPECT_EQ(&partial_address, filtered[5]); | |
304 EXPECT_EQ(&no_address, filtered[6]); | |
305 | |
306 EXPECT_EQ(&partial_no_phone, filtered[7]); | |
307 EXPECT_EQ(&partial_no_name, filtered[8]); | |
308 | |
309 EXPECT_EQ(&empty, filtered[9]); | |
310 } | |
311 | |
312 TEST(PaymentRequestProfileUtilTest, GetShippingCompletenessScore) { | |
313 MockPaymentOptionsProvider provider(kRequestShipping); | |
314 PaymentsProfileComparator comp("en-US", provider); | |
315 | |
316 // 12 points for a complete profile: 10 for address, 1 each for name/phone. | |
317 AutofillProfile p1 = CreateProfileWithCompleteAddress("Homer", "6515553226"); | |
318 EXPECT_EQ(12, comp.GetShippingCompletenessScore(&p1)); | |
319 | |
320 // 11 points if name or phone is missing. | |
321 AutofillProfile p2 = CreateProfileWithCompleteAddress("", "6515553226"); | |
322 AutofillProfile p3 = CreateProfileWithCompleteAddress("Homer", ""); | |
323 EXPECT_EQ(11, comp.GetShippingCompletenessScore(&p2)); | |
324 EXPECT_EQ(11, comp.GetShippingCompletenessScore(&p3)); | |
325 | |
326 // 10 points for complete address only. | |
327 AutofillProfile p4 = CreateProfileWithCompleteAddress("", ""); | |
328 EXPECT_EQ(10, comp.GetShippingCompletenessScore(&p4)); | |
329 | |
330 // 2 points for name and phone without address. | |
331 AutofillProfile p5 = CreateProfileWithContactInfo("Homer", "", "6515553226"); | |
332 EXPECT_EQ(2, comp.GetShippingCompletenessScore(&p5)); | |
333 | |
334 // 1 point for name or phone alone. | |
335 AutofillProfile p6 = CreateProfileWithContactInfo("Homer", "", ""); | |
336 AutofillProfile p7 = CreateProfileWithContactInfo("", "", "6515553226"); | |
337 EXPECT_EQ(1, comp.GetShippingCompletenessScore(&p6)); | |
338 EXPECT_EQ(1, comp.GetShippingCompletenessScore(&p7)); | |
339 | |
340 // No points for empty profile, or profile with only a partial address. | |
341 AutofillProfile p8 = CreateProfileWithContactInfo("", "", ""); | |
342 AutofillProfile p9 = CreateProfileWithPartialAddress("", ""); | |
343 EXPECT_EQ(0, comp.GetShippingCompletenessScore(&p8)); | |
344 EXPECT_EQ(0, comp.GetShippingCompletenessScore(&p9)); | |
345 } | |
346 | |
347 TEST(PaymentRequestProfileUtilTest, IsShippingComplete) { | 250 TEST(PaymentRequestProfileUtilTest, IsShippingComplete) { |
348 MockPaymentOptionsProvider provider(kRequestShipping); | 251 MockPaymentOptionsProvider provider(kRequestShipping); |
349 PaymentsProfileComparator comp("en-US", provider); | 252 PaymentsProfileComparator comp("en-US", provider); |
350 | 253 |
351 // True if name, phone, and address are all populated. | 254 // True if name, phone, and address are all populated. |
352 AutofillProfile p1 = CreateProfileWithCompleteAddress("Homer", "6515553226"); | 255 AutofillProfile p1 = CreateProfileWithCompleteAddress("Homer", "6515553226"); |
353 EXPECT_TRUE(comp.IsShippingComplete(&p1)); | 256 EXPECT_TRUE(comp.IsShippingComplete(&p1)); |
354 | 257 |
355 // False if address is partially populated. | 258 // False if address is partially populated. |
356 AutofillProfile p2 = CreateProfileWithPartialAddress("Homer", "6515553226"); | 259 AutofillProfile p2 = CreateProfileWithPartialAddress("Homer", "6515553226"); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 | 358 |
456 MockPaymentOptionsProvider provider_no_shipping( | 359 MockPaymentOptionsProvider provider_no_shipping( |
457 kRequestPayerName | kRequestPayerPhone | kRequestPayerEmail); | 360 kRequestPayerName | kRequestPayerPhone | kRequestPayerEmail); |
458 PaymentsProfileComparator comp_no_shipping("en-US", provider_no_shipping); | 361 PaymentsProfileComparator comp_no_shipping("en-US", provider_no_shipping); |
459 | 362 |
460 // No error message if everything is missing but shipping wasn't requested. | 363 // No error message if everything is missing but shipping wasn't requested. |
461 EXPECT_TRUE(comp_no_shipping.GetStringForMissingShippingFields(p6).empty()); | 364 EXPECT_TRUE(comp_no_shipping.GetStringForMissingShippingFields(p6).empty()); |
462 } | 365 } |
463 | 366 |
464 } // namespace payments | 367 } // namespace payments |
OLD | NEW |