File: payments_profile_comparator_unittest.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (496 lines) | stat: -rw-r--r-- 21,370 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/payments/core/payments_profile_comparator.h"

#include <memory>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "base/uuid.h"
#include "components/autofill/core/browser/data_model/addresses/autofill_profile.h"
#include "components/autofill/core/browser/test_utils/autofill_test_utils.h"
#include "components/payments/core/payment_options_provider.h"
#include "components/strings/grit/components_strings.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"

using autofill::AutofillProfile;

namespace payments {

constexpr uint32_t kRequestPayerName = 1 << 0;
constexpr uint32_t kRequestPayerEmail = 1 << 1;
constexpr uint32_t kRequestPayerPhone = 1 << 2;
constexpr uint32_t kRequestShipping = 1 << 3;

class MockPaymentOptionsProvider : public PaymentOptionsProvider {
 public:
  MockPaymentOptionsProvider(uint32_t options) : options_(options) {}

  ~MockPaymentOptionsProvider() override = default;
  bool request_payer_name() const override {
    return options_ & kRequestPayerName;
  }
  bool request_payer_email() const override {
    return options_ & kRequestPayerEmail;
  }
  bool request_payer_phone() const override {
    return options_ & kRequestPayerPhone;
  }
  bool request_shipping() const override { return options_ & kRequestShipping; }
  PaymentShippingType shipping_type() const override {
    return PaymentShippingType::SHIPPING;
  }

 private:
  uint32_t options_;
};

AutofillProfile CreateProfileWithContactInfo(const char* name,
                                             const char* email,
                                             const char* phone) {
  AutofillProfile profile(
      autofill::i18n_model_definition::kLegacyHierarchyCountryCode);
  autofill::test::SetProfileInfo(&profile, name, "", "", email, "", "", "", "",
                                 "", "", "", phone);
  return profile;
}

AutofillProfile CreateProfileWithCompleteAddress(const char* name,
                                                 const char* phone) {
  AutofillProfile profile(
      autofill::i18n_model_definition::kLegacyHierarchyCountryCode);
  autofill::test::SetProfileInfo(&profile, name, "", "", "", "", "123 Fake St.",
                                 "", "Fakesville", "MN", "54000", "US", phone);
  return profile;
}

AutofillProfile CreateProfileWithPartialAddress(const char* name,
                                                const char* phone) {
  AutofillProfile profile(
      autofill::i18n_model_definition::kLegacyHierarchyCountryCode);
  autofill::test::SetProfileInfo(&profile, name, "", "", "", "", "123 Fake St.",
                                 "", "", "", "54000", "", phone);
  return profile;
}

TEST(PaymentRequestProfileUtilTest, FilterProfilesForContact) {
  // These profiles are subset/equal, so only the first complete one is
  // included.
  AutofillProfile exclude_1 =
      CreateProfileWithContactInfo("Homer", "", "6515553226");

  AutofillProfile exclude_2 =
      CreateProfileWithContactInfo("Homer", "homer@simpson.net", "");

  AutofillProfile include_1 =
      CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226");

  AutofillProfile exclude_3 =
      CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226");

  // This profile is different, so it should also be included. Since it is
  // less complete than |include_1|, it will appear after.
  AutofillProfile include_2 =
      CreateProfileWithContactInfo("Marge", "marge@simpson.net", "");

  // This profile is different, so it should also be included. Since it is
  // equally complete with |include_1|, it will appear before |include_2|, but
  // after |include_1| since order is preserved amongst profiles of equal
  // completeness.
  AutofillProfile include_3 = CreateProfileWithContactInfo(
      "Bart", "eatmyshorts@simpson.net", "6515553226");

  std::vector<raw_ptr<AutofillProfile, VectorExperimental>> profiles = {
      &exclude_1, &exclude_2, &include_1, &exclude_3, &include_2, &include_3};

  MockPaymentOptionsProvider provider(kRequestPayerName | kRequestPayerEmail |
                                      kRequestPayerPhone);
  PaymentsProfileComparator comp("en-US", provider);

  std::vector<raw_ptr<AutofillProfile, VectorExperimental>> filtered =
      comp.FilterProfilesForContact(profiles);

  ASSERT_EQ(3u, filtered.size());
  EXPECT_EQ(&include_1, filtered[0]);
  EXPECT_EQ(&include_3, filtered[1]);
  EXPECT_EQ(&include_2, filtered[2]);

  // Repeat the filter using a provider set to only request phone numbers.
  // Under these rules, since all profiles have the same (or no) phone number,
  // we should only see the first profile with a phone number, |exclude_1|.
  MockPaymentOptionsProvider phone_only_provider(kRequestPayerPhone);
  PaymentsProfileComparator phone_only_comp("en-US", phone_only_provider);
  std::vector<raw_ptr<AutofillProfile, VectorExperimental>> filtered_phones =
      phone_only_comp.FilterProfilesForContact(profiles);
  ASSERT_EQ(1u, filtered_phones.size());
  EXPECT_EQ(&exclude_1, filtered_phones[0]);
}

TEST(PaymentRequestProfileUtilTest, IsContactEqualOrSuperset) {
  MockPaymentOptionsProvider provider(kRequestPayerName | kRequestPayerEmail |
                                      kRequestPayerPhone);
  PaymentsProfileComparator comp("en-US", provider);

  AutofillProfile p1 =
      CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226");

  // Candidate subset profile is equal.
  AutofillProfile p2 =
      CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226");
  EXPECT_TRUE(comp.IsContactEqualOrSuperset(p1, p2));
  EXPECT_TRUE(comp.IsContactEqualOrSuperset(p2, p1));

  // Candidate subset profile has non-matching fields.
  AutofillProfile p3 = CreateProfileWithContactInfo(
      "Homer", "homer@springfieldnuclear.gov", "6515553226");
  EXPECT_FALSE(comp.IsContactEqualOrSuperset(p1, p3));
  EXPECT_FALSE(comp.IsContactEqualOrSuperset(p3, p1));

  // Candidate subset profile is equal, except for missing fields.
  AutofillProfile p4 =
      CreateProfileWithContactInfo("Homer", "homer@simpson.net", "");
  EXPECT_TRUE(comp.IsContactEqualOrSuperset(p1, p4));
  EXPECT_FALSE(comp.IsContactEqualOrSuperset(p4, p1));

  // One field is common, but each has a field which the other is missing.
  AutofillProfile p5 =
      CreateProfileWithContactInfo("Homer", "homer@simpson.net", "");
  AutofillProfile p6 = CreateProfileWithContactInfo("Homer", "", "6515553226");
  EXPECT_FALSE(comp.IsContactEqualOrSuperset(p5, p6));
  EXPECT_FALSE(comp.IsContactEqualOrSuperset(p6, p5));
}

TEST(PaymentRequestProfileUtilTest, IsContactEqualOrSuperset_WithFieldIgnored) {
  // Discrepancies in email should be ignored throughout this test.
  MockPaymentOptionsProvider provider(kRequestPayerName | kRequestPayerPhone);
  PaymentsProfileComparator comp("en-US", provider);

  AutofillProfile p1 =
      CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226");

  // Candidate subset profile is equal.
  AutofillProfile p2 =
      CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226");
  EXPECT_TRUE(comp.IsContactEqualOrSuperset(p1, p2));
  EXPECT_TRUE(comp.IsContactEqualOrSuperset(p2, p1));

  // Email fields don't match, but profiles are still equal.
  AutofillProfile p3 = CreateProfileWithContactInfo(
      "Homer", "homer@springfieldnuclear.gov", "6515553226");
  EXPECT_TRUE(comp.IsContactEqualOrSuperset(p1, p3));
  EXPECT_TRUE(comp.IsContactEqualOrSuperset(p3, p1));

  // Profile without an email is mutual subset of profile with an email.
  AutofillProfile p4 = CreateProfileWithContactInfo("Homer", "", "6515553226");
  EXPECT_TRUE(comp.IsContactEqualOrSuperset(p1, p4));
  EXPECT_TRUE(comp.IsContactEqualOrSuperset(p4, p1));
}

TEST(PaymentRequestProfileUtilTest, GetContactCompletenessScore) {
  MockPaymentOptionsProvider provider(kRequestPayerName | kRequestPayerPhone);
  PaymentsProfileComparator comp("en-US", provider);

  // Two completeness points: One each for name and phone number, but not email
  // as it was not requested.
  AutofillProfile p1 =
      CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226");
  EXPECT_EQ(2, comp.GetContactCompletenessScore(&p1));

  // One completeness point for name, no points for phone number (missing) or
  // email (not requested).
  AutofillProfile p2 =
      CreateProfileWithContactInfo("Homer", "homer@simpson.net", "");
  EXPECT_EQ(1, comp.GetContactCompletenessScore(&p2));

  // No completeness points, as the only field present was not requested.
  AutofillProfile p3 =
      CreateProfileWithContactInfo("", "homer@simpson.net", "");
  EXPECT_EQ(0, comp.GetContactCompletenessScore(&p3));

  // Null profile returns 0.
  EXPECT_EQ(0, comp.GetContactCompletenessScore(nullptr));
}

TEST(PaymentRequestProfileUtilTest, IsContactInfoComplete) {
  MockPaymentOptionsProvider provider(kRequestPayerName | kRequestPayerEmail);
  PaymentsProfileComparator comp("en-US", provider);

  // If name and email are present, return true regardless of the (ignored)
  // phone value.
  AutofillProfile p1 =
      CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226");
  AutofillProfile p2 =
      CreateProfileWithContactInfo("Homer", "homer@simpson.net", "");

  EXPECT_TRUE(comp.IsContactInfoComplete(&p1));
  EXPECT_TRUE(comp.IsContactInfoComplete(&p2));

  // If name is not present, return false regardless of the (ignored)
  // phone value.
  AutofillProfile p3 =
      CreateProfileWithContactInfo("", "homer@simpson.net", "6515553226");
  AutofillProfile p4 =
      CreateProfileWithContactInfo("", "homer@simpson.net", "");

  EXPECT_FALSE(comp.IsContactInfoComplete(&p3));
  EXPECT_FALSE(comp.IsContactInfoComplete(&p4));

  // If no fields are requested, any profile (even empty or null) is complete.
  MockPaymentOptionsProvider empty_provider(0);
  PaymentsProfileComparator empty_comp("en-US", empty_provider);

  AutofillProfile p5 = CreateProfileWithContactInfo("", "", "");

  EXPECT_TRUE(empty_comp.IsContactInfoComplete(&p1));
  EXPECT_TRUE(empty_comp.IsContactInfoComplete(&p5));
  EXPECT_TRUE(empty_comp.IsContactInfoComplete(nullptr));
}

TEST(PaymentRequestProfileUtilTest, FilterProfilesForShipping) {
  MockPaymentOptionsProvider provider(kRequestShipping);
  PaymentsProfileComparator comp("en-US", provider);

  AutofillProfile address_only = CreateProfileWithCompleteAddress("", "");

  AutofillProfile no_name = CreateProfileWithCompleteAddress("", "6515553226");
  AutofillProfile no_phone = CreateProfileWithCompleteAddress("Homer", "");

  AutofillProfile empty = CreateProfileWithContactInfo("", "", "");

  AutofillProfile complete1 =
      CreateProfileWithCompleteAddress("Homer", "6515553226");

  AutofillProfile partial_address =
      CreateProfileWithPartialAddress("Homer", "6515553226");
  AutofillProfile no_address =
      CreateProfileWithContactInfo("Homer", "", "6515553226");

  AutofillProfile complete2 =
      CreateProfileWithCompleteAddress("Bart", "6515553226");

  AutofillProfile partial_no_phone =
      CreateProfileWithPartialAddress("", "6515553226");
  AutofillProfile partial_no_name =
      CreateProfileWithPartialAddress("Homer", "");

  std::vector<raw_ptr<AutofillProfile, VectorExperimental>> profiles = {
      &address_only,     &no_name,         &no_phone,   &empty,
      &complete1,        &partial_address, &no_address, &complete2,
      &partial_no_phone, &partial_no_name};

  std::vector<raw_ptr<AutofillProfile, VectorExperimental>> filtered =
      comp.FilterProfilesForShipping(profiles);

  // Current logic does not remove profiles, only reorder them.
  ASSERT_EQ(10u, filtered.size());

  // First, the complete profiles should be hoisted to the top, keeping their
  // relative order.
  EXPECT_EQ(&complete1, filtered[0]);
  EXPECT_EQ(&complete2, filtered[1]);

  // Next are profiles with a complete address but missing one other field.
  EXPECT_EQ(&no_name, filtered[2]);
  EXPECT_EQ(&no_phone, filtered[3]);

  // A profile with only a complete address should still appear before profiles
  // with partial/empty addresses.
  EXPECT_EQ(&address_only, filtered[4]);

  // Profiles with partial/no address then are sorted by whether or not they
  // have names and/or phone numbers.
  EXPECT_EQ(&partial_address, filtered[5]);
  EXPECT_EQ(&no_address, filtered[6]);

  EXPECT_EQ(&partial_no_phone, filtered[7]);
  EXPECT_EQ(&partial_no_name, filtered[8]);

  EXPECT_EQ(&empty, filtered[9]);
}

TEST(PaymentRequestProfileUtilTest, GetShippingCompletenessScore) {
  MockPaymentOptionsProvider provider(kRequestShipping);
  PaymentsProfileComparator comp("en-US", provider);

  // 12 points for a complete profile: 10 for address, 1 each for name/phone.
  AutofillProfile p1 = CreateProfileWithCompleteAddress("Homer", "6515553226");
  EXPECT_EQ(12, comp.GetShippingCompletenessScore(&p1));

  // 11 points if name or phone is missing.
  AutofillProfile p2 = CreateProfileWithCompleteAddress("", "6515553226");
  AutofillProfile p3 = CreateProfileWithCompleteAddress("Homer", "");
  EXPECT_EQ(11, comp.GetShippingCompletenessScore(&p2));
  EXPECT_EQ(11, comp.GetShippingCompletenessScore(&p3));

  // 10 points for complete address only.
  AutofillProfile p4 = CreateProfileWithCompleteAddress("", "");
  EXPECT_EQ(10, comp.GetShippingCompletenessScore(&p4));

  // 2 points for name and phone without address.
  AutofillProfile p5 = CreateProfileWithContactInfo("Homer", "", "6515553226");
  EXPECT_EQ(2, comp.GetShippingCompletenessScore(&p5));

  // 1 point for name or phone alone.
  AutofillProfile p6 = CreateProfileWithContactInfo("Homer", "", "");
  AutofillProfile p7 = CreateProfileWithContactInfo("", "", "6515553226");
  EXPECT_EQ(1, comp.GetShippingCompletenessScore(&p6));
  EXPECT_EQ(1, comp.GetShippingCompletenessScore(&p7));

  // No points for empty profile, or profile with only a partial address.
  AutofillProfile p8 = CreateProfileWithContactInfo("", "", "");
  AutofillProfile p9 = CreateProfileWithPartialAddress("", "");
  EXPECT_EQ(0, comp.GetShippingCompletenessScore(&p8));
  EXPECT_EQ(0, comp.GetShippingCompletenessScore(&p9));
}

TEST(PaymentRequestProfileUtilTest, IsShippingComplete) {
  MockPaymentOptionsProvider provider(kRequestShipping);
  PaymentsProfileComparator comp("en-US", provider);

  // True if name, phone, and address are all populated.
  AutofillProfile p1 = CreateProfileWithCompleteAddress("Homer", "6515553226");
  EXPECT_TRUE(comp.IsShippingComplete(&p1));

  // False if address is partially populated.
  AutofillProfile p2 = CreateProfileWithPartialAddress("Homer", "6515553226");
  EXPECT_FALSE(comp.IsShippingComplete(&p2));

  // False if name isn't populated.
  AutofillProfile p3 = CreateProfileWithCompleteAddress("", "6515553226");
  EXPECT_FALSE(comp.IsShippingComplete(&p3));

  // False if phone isn't populated.
  AutofillProfile p4 = CreateProfileWithCompleteAddress("Homer", "");
  EXPECT_FALSE(comp.IsShippingComplete(&p4));

  // False if only contact info (no address fields) is populated.
  AutofillProfile p5 =
      CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226");
  EXPECT_FALSE(comp.IsShippingComplete(&p5));

  MockPaymentOptionsProvider provider_no_shipping(0);
  PaymentsProfileComparator comp_no_shipping("en-US", provider_no_shipping);
  // nullptr is handled correctly: false if shipping requested, true if not.
  EXPECT_FALSE(comp.IsShippingComplete(nullptr));
  EXPECT_TRUE(comp_no_shipping.IsShippingComplete(nullptr));
}

TEST(PaymentRequestProfileUtilTest, GetStringForMissingContactFields) {
  MockPaymentOptionsProvider provider(kRequestPayerName | kRequestPayerPhone |
                                      kRequestPayerEmail | kRequestShipping);
  PaymentsProfileComparator comp("en-US", provider);

  // No error message for complete profile.
  AutofillProfile p1 =
      CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226");
  EXPECT_TRUE(comp.GetStringForMissingContactFields(p1).empty());

  MockPaymentOptionsProvider provider_no_email(
      kRequestPayerName | kRequestPayerPhone | kRequestShipping);
  PaymentsProfileComparator comp_no_email("en-US", provider_no_email);

  // No error message if missing field wasn't required.
  AutofillProfile p2 = CreateProfileWithContactInfo("Homer", "", "6515553226");
  EXPECT_TRUE(comp_no_email.GetStringForMissingContactFields(p2).empty());

  // Error message for email address if email address is missing and required.
  EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_EMAIL_REQUIRED),
            comp.GetStringForMissingContactFields(p2));

  // Error message for phone number if phone is missing and required.
  AutofillProfile p3 =
      CreateProfileWithContactInfo("Homer", "homer@simpson.net", "");
  EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_PHONE_NUMBER_REQUIRED),
            comp.GetStringForMissingContactFields(p3));

  // Error message for name if name is missing and required.
  AutofillProfile p4 =
      CreateProfileWithContactInfo("", "homer@simpson.net", "6515553226");
  EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_NAME_REQUIRED),
            comp.GetStringForMissingContactFields(p4));

  // Generic error message if multiple fields missing.
  AutofillProfile p5 =
      CreateProfileWithContactInfo("", "homer@simpson.net", "");
  EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_MORE_INFORMATION_REQUIRED),
            comp.GetStringForMissingContactFields(p5));
}

TEST(PaymentRequestProfileUtilTest, GetTitleForMissingContactFields) {
  MockPaymentOptionsProvider provider(kRequestPayerName | kRequestPayerPhone |
                                      kRequestPayerEmail | kRequestShipping);
  PaymentsProfileComparator comp("en-US", provider);

  // Error message for email address if email address is missing and required.
  AutofillProfile p1 = CreateProfileWithContactInfo("Homer", "", "6515553226");
  EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_ADD_EMAIL),
            comp.GetTitleForMissingContactFields(p1));

  // Error message for phone number if phone is missing and required.
  AutofillProfile p2 =
      CreateProfileWithContactInfo("Homer", "homer@simpson.net", "");
  EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_ADD_PHONE_NUMBER),
            comp.GetTitleForMissingContactFields(p2));

  // Error message for name if name is missing and required.
  AutofillProfile p3 =
      CreateProfileWithContactInfo("", "homer@simpson.net", "6515553226");
  EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_ADD_NAME),
            comp.GetTitleForMissingContactFields(p3));

  // Generic error message if multiple fields missing.
  AutofillProfile p4 =
      CreateProfileWithContactInfo("", "homer@simpson.net", "");
  EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_ADD_MORE_INFORMATION),
            comp.GetTitleForMissingContactFields(p4));
}

TEST(PaymentRequestProfileUtilTest, GetStringForMissingShippingFields) {
  MockPaymentOptionsProvider provider(kRequestPayerName | kRequestPayerPhone |
                                      kRequestPayerEmail | kRequestShipping);
  PaymentsProfileComparator comp("en-US", provider);

  // No error message for complete profile.
  AutofillProfile p1 = CreateProfileWithCompleteAddress("Homer", "6515553226");
  EXPECT_TRUE(comp.GetStringForMissingShippingFields(p1).empty());

  // Error message for shipping if shipping requested and not present.
  AutofillProfile p2 =
      CreateProfileWithContactInfo("Homer", "homer@simpson.net", "6515553226");
  EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_INVALID_ADDRESS),
            comp.GetStringForMissingShippingFields(p2));

  // Error message for shipping if shipping requested and only partially
  // complete.
  AutofillProfile p3 = CreateProfileWithPartialAddress("Homer", "6515553226");
  EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_INVALID_ADDRESS),
            comp.GetStringForMissingShippingFields(p3));

  // Error message for name if name requested and missing.
  AutofillProfile p4 = CreateProfileWithCompleteAddress("", "6515553226");
  EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_NAME_REQUIRED),
            comp.GetStringForMissingShippingFields(p4));

  // Error message for phone if phone requested and missing.
  AutofillProfile p5 = CreateProfileWithCompleteAddress("Homer", "");
  EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_PHONE_NUMBER_REQUIRED),
            comp.GetStringForMissingShippingFields(p5));

  // Generic error message if multiple fields missing.
  AutofillProfile p6 = CreateProfileWithContactInfo("", "", "");
  EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_MORE_INFORMATION_REQUIRED),
            comp.GetStringForMissingShippingFields(p6));

  MockPaymentOptionsProvider provider_no_shipping(
      kRequestPayerName | kRequestPayerPhone | kRequestPayerEmail);
  PaymentsProfileComparator comp_no_shipping("en-US", provider_no_shipping);

  // No error message if everything is missing but shipping wasn't requested.
  EXPECT_TRUE(comp_no_shipping.GetStringForMissingShippingFields(p6).empty());
}

}  // namespace payments