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

Side by Side Diff: components/payments/core/payments_profile_comparator_unittest.cc

Issue 2884393002: [WebPayments] Adding FilterProfilesForShipping to profile comparator (Closed)
Patch Set: rebase Created 3 years, 7 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 unified diff | Download patch
OLDNEW
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
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
250 TEST(PaymentRequestProfileUtilTest, IsShippingComplete) { 347 TEST(PaymentRequestProfileUtilTest, IsShippingComplete) {
251 MockPaymentOptionsProvider provider(kRequestShipping); 348 MockPaymentOptionsProvider provider(kRequestShipping);
252 PaymentsProfileComparator comp("en-US", provider); 349 PaymentsProfileComparator comp("en-US", provider);
253 350
254 // True if name, phone, and address are all populated. 351 // True if name, phone, and address are all populated.
255 AutofillProfile p1 = CreateProfileWithCompleteAddress("Homer", "6515553226"); 352 AutofillProfile p1 = CreateProfileWithCompleteAddress("Homer", "6515553226");
256 EXPECT_TRUE(comp.IsShippingComplete(&p1)); 353 EXPECT_TRUE(comp.IsShippingComplete(&p1));
257 354
258 // False if address is partially populated. 355 // False if address is partially populated.
259 AutofillProfile p2 = CreateProfileWithPartialAddress("Homer", "6515553226"); 356 AutofillProfile p2 = CreateProfileWithPartialAddress("Homer", "6515553226");
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 455
359 MockPaymentOptionsProvider provider_no_shipping( 456 MockPaymentOptionsProvider provider_no_shipping(
360 kRequestPayerName | kRequestPayerPhone | kRequestPayerEmail); 457 kRequestPayerName | kRequestPayerPhone | kRequestPayerEmail);
361 PaymentsProfileComparator comp_no_shipping("en-US", provider_no_shipping); 458 PaymentsProfileComparator comp_no_shipping("en-US", provider_no_shipping);
362 459
363 // No error message if everything is missing but shipping wasn't requested. 460 // No error message if everything is missing but shipping wasn't requested.
364 EXPECT_TRUE(comp_no_shipping.GetStringForMissingShippingFields(p6).empty()); 461 EXPECT_TRUE(comp_no_shipping.GetStringForMissingShippingFields(p6).empty());
365 } 462 }
366 463
367 } // namespace payments 464 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/core/payments_profile_comparator.cc ('k') | ios/chrome/browser/payments/payment_request.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698