1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "base/format_macros.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/scoped_vector.h"
10 #include "base/stl_util.h"
11 #include "base/strings/string16.h"
12 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "components/autofill/core/browser/autofill_profile.h"
15 #include "components/autofill/core/browser/autofill_test_utils.h"
16 #include "components/autofill/core/browser/autofill_type.h"
17 #include "components/autofill/core/browser/field_types.h"
18 #include "components/autofill/core/common/form_field_data.h"
19 #include "testing/gtest/include/gtest/gtest.h"
21 using base::ASCIIToUTF16
;
22 using base::UTF8ToUTF16
;
28 base::string16
GetLabel(AutofillProfile
* profile
) {
29 std::vector
<AutofillProfile
*> profiles
;
30 profiles
.push_back(profile
);
31 std::vector
<base::string16
> labels
;
32 AutofillProfile::CreateDifferentiatingLabels(profiles
, "en-US", &labels
);
36 // Holds the autofill profile |first|, |middle| and |last| names.
38 NameParts(const std::string
& first
,
39 const std::string
& middle
,
40 const std::string
& last
)
41 : first(first
), middle(middle
), last(last
) {}
48 // Test case to be executed to validate OverwriteOrAppendNames.
50 TestCase(const NameParts
& starting_name
,
51 const NameParts
& additional_name
,
52 const NameParts
& expected_result
)
53 : starting_names(std::vector
<NameParts
>(1, starting_name
)),
54 additional_names(std::vector
<NameParts
>(1, additional_name
)),
55 expected_result(std::vector
<NameParts
>(1, expected_result
)) {}
57 TestCase(const std::vector
<NameParts
>& starting_names
,
58 const std::vector
<NameParts
>& additional_names
,
59 const std::vector
<NameParts
>& expected_result
)
60 : starting_names(starting_names
),
61 additional_names(additional_names
),
62 expected_result(expected_result
) {}
64 std::vector
<NameParts
> starting_names
;
65 std::vector
<NameParts
> additional_names
;
66 std::vector
<NameParts
> expected_result
;
71 // Tests different possibilities for summary string generation.
72 // Based on existence of first name, last name, and address line 1.
73 TEST(AutofillProfileTest
, PreviewSummaryString
) {
75 AutofillProfile
profile0(base::GenerateGUID(), "https://www.example.com/");
76 // Empty profile - nothing to update.
77 base::string16 summary0
= GetLabel(&profile0
);
78 EXPECT_EQ(base::string16(), summary0
);
80 // Case 0a/empty name and address, so the first two fields of the rest of the
81 // data is used: "Hollywood, CA"
82 AutofillProfile
profile00(base::GenerateGUID(), "https://www.example.com/");
83 test::SetProfileInfo(&profile00
, "", "", "",
84 "johnwayne@me.xyz", "Fox", "", "", "Hollywood", "CA", "91601", "US",
86 base::string16 summary00
= GetLabel(&profile00
);
87 EXPECT_EQ(ASCIIToUTF16("Hollywood, CA"), summary00
);
89 // Case 1: "<address>" without line 2.
90 AutofillProfile
profile1(base::GenerateGUID(), "https://www.example.com/");
91 test::SetProfileInfo(&profile1
, "", "", "",
92 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "", "Hollywood", "CA",
93 "91601", "US", "16505678910");
94 base::string16 summary1
= GetLabel(&profile1
);
95 EXPECT_EQ(ASCIIToUTF16("123 Zoo St., Hollywood"), summary1
);
97 // Case 1a: "<address>" with line 2.
98 AutofillProfile
profile1a(base::GenerateGUID(), "https://www.example.com/");
99 test::SetProfileInfo(&profile1a
, "", "", "",
100 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
101 "91601", "US", "16505678910");
102 base::string16 summary1a
= GetLabel(&profile1a
);
103 EXPECT_EQ(ASCIIToUTF16("123 Zoo St., unit 5"), summary1a
);
105 // Case 2: "<lastname>"
106 AutofillProfile
profile2(base::GenerateGUID(), "https://www.example.com/");
107 test::SetProfileInfo(&profile2
, "", "Mitchell",
108 "Morrison", "johnwayne@me.xyz", "Fox", "", "", "Hollywood", "CA",
109 "91601", "US", "16505678910");
110 base::string16 summary2
= GetLabel(&profile2
);
111 // Summary includes full name, to the maximal extent available.
112 EXPECT_EQ(ASCIIToUTF16("Mitchell Morrison, Hollywood"), summary2
);
114 // Case 3: "<lastname>, <address>"
115 AutofillProfile
profile3(base::GenerateGUID(), "https://www.example.com/");
116 test::SetProfileInfo(&profile3
, "", "Mitchell",
117 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "",
118 "Hollywood", "CA", "91601", "US", "16505678910");
119 base::string16 summary3
= GetLabel(&profile3
);
120 EXPECT_EQ(ASCIIToUTF16("Mitchell Morrison, 123 Zoo St."), summary3
);
122 // Case 4: "<firstname>"
123 AutofillProfile
profile4(base::GenerateGUID(), "https://www.example.com/");
124 test::SetProfileInfo(&profile4
, "Marion", "Mitchell", "",
125 "johnwayne@me.xyz", "Fox", "", "", "Hollywood", "CA", "91601", "US",
127 base::string16 summary4
= GetLabel(&profile4
);
128 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell, Hollywood"), summary4
);
130 // Case 5: "<firstname>, <address>"
131 AutofillProfile
profile5(base::GenerateGUID(), "https://www.example.com/");
132 test::SetProfileInfo(&profile5
, "Marion", "Mitchell", "",
133 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
134 "91601", "US", "16505678910");
135 base::string16 summary5
= GetLabel(&profile5
);
136 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell, 123 Zoo St."), summary5
);
138 // Case 6: "<firstname> <lastname>"
139 AutofillProfile
profile6(base::GenerateGUID(), "https://www.example.com/");
140 test::SetProfileInfo(&profile6
, "Marion", "Mitchell",
141 "Morrison", "johnwayne@me.xyz", "Fox", "", "", "Hollywood", "CA",
142 "91601", "US", "16505678910");
143 base::string16 summary6
= GetLabel(&profile6
);
144 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell Morrison, Hollywood"),
147 // Case 7: "<firstname> <lastname>, <address>"
148 AutofillProfile
profile7(base::GenerateGUID(), "https://www.example.com/");
149 test::SetProfileInfo(&profile7
, "Marion", "Mitchell",
150 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5",
151 "Hollywood", "CA", "91601", "US", "16505678910");
152 base::string16 summary7
= GetLabel(&profile7
);
153 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell Morrison, 123 Zoo St."), summary7
);
155 // Case 7a: "<firstname> <lastname>, <address>" - same as #7, except for
157 AutofillProfile
profile7a(base::GenerateGUID(), "https://www.example.com/");
158 test::SetProfileInfo(&profile7a
, "Marion", "Mitchell",
159 "Morrison", "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5",
160 "Hollywood", "CA", "91601", "US", "16505678910");
161 std::vector
<AutofillProfile
*> profiles
;
162 profiles
.push_back(&profile7
);
163 profiles
.push_back(&profile7a
);
164 std::vector
<base::string16
> labels
;
165 AutofillProfile::CreateDifferentiatingLabels(profiles
, "en-US", &labels
);
166 ASSERT_EQ(profiles
.size(), labels
.size());
167 summary7
= labels
[0];
168 base::string16 summary7a
= labels
[1];
169 EXPECT_EQ(ASCIIToUTF16(
170 "Marion Mitchell Morrison, 123 Zoo St., johnwayne@me.xyz"), summary7
);
171 EXPECT_EQ(ASCIIToUTF16(
172 "Marion Mitchell Morrison, 123 Zoo St., marion@me.xyz"), summary7a
);
175 TEST(AutofillProfileTest
, AdjustInferredLabels
) {
176 ScopedVector
<AutofillProfile
> profiles
;
178 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
179 test::SetProfileInfo(
193 new AutofillProfile(base::GenerateGUID(), "http://www.example.com/"));
194 test::SetProfileInfo(
199 "janedoe@tertium.com",
207 std::vector
<base::string16
> labels
;
208 AutofillProfile::CreateDifferentiatingLabels(
209 profiles
.get(), "en-US", &labels
);
210 ASSERT_EQ(2U, labels
.size());
211 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St."), labels
[0]);
212 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels
[1]);
215 new AutofillProfile(base::GenerateGUID(), "Chrome settings"));
216 test::SetProfileInfo(
221 "johndoe@tertium.com",
230 AutofillProfile::CreateDifferentiatingLabels(
231 profiles
.get(), "en-US", &labels
);
233 // Profile 0 and 2 inferred label now includes an e-mail.
234 ASSERT_EQ(3U, labels
.size());
235 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@hades.com"),
237 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels
[1]);
238 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@tertium.com"),
244 new AutofillProfile(base::GenerateGUID(), std::string()));
245 test::SetProfileInfo(
254 "Elysium", "CO", // State is different
260 AutofillProfile::CreateDifferentiatingLabels(
261 profiles
.get(), "en-US", &labels
);
263 // Profile 0 and 2 inferred label now includes a state.
264 ASSERT_EQ(3U, labels
.size());
265 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CA"), labels
[0]);
266 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels
[1]);
267 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO"), labels
[2]);
270 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
271 test::SetProfileInfo(
280 "Elysium", "CO", // State is different for some.
283 "16504444444"); // Phone is different for some.
286 AutofillProfile::CreateDifferentiatingLabels(
287 profiles
.get(), "en-US", &labels
);
288 ASSERT_EQ(4U, labels
.size());
289 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CA"), labels
[0]);
290 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels
[1]);
291 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, 16502111111"),
293 // This one differs from other ones by unique phone, so no need for extra
295 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, 16504444444"),
299 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
300 test::SetProfileInfo(
305 "johndoe@styx.com", // E-Mail is different for some.
309 "Elysium", "CO", // State is different for some.
312 "16504444444"); // Phone is different for some.
315 AutofillProfile::CreateDifferentiatingLabels(
316 profiles
.get(), "en-US", &labels
);
317 ASSERT_EQ(5U, labels
.size());
318 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CA"), labels
[0]);
319 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels
[1]);
320 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, johndoe@hades.com,"
321 " 16502111111"), labels
[2]);
322 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, johndoe@hades.com,"
323 " 16504444444"), labels
[3]);
324 // This one differs from other ones by unique e-mail, so no need for extra
326 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, johndoe@styx.com"),
330 TEST(AutofillProfileTest
, CreateInferredLabelsI18n_CH
) {
331 ScopedVector
<AutofillProfile
> profiles
;
333 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
334 test::SetProfileInfo(profiles
.back(),
338 "hrgiger@beispiel.com",
340 "Brandschenkestrasse 110",
346 profiles
.back()->set_language_code("de_CH");
347 static const char* kExpectedLabels
[] = {
350 "H. R. Giger, Brandschenkestrasse 110",
351 "H. R. Giger, Brandschenkestrasse 110, Zurich",
352 "H. R. Giger, Brandschenkestrasse 110, CH-8002 Zurich",
353 "Beispiel Inc, H. R. Giger, Brandschenkestrasse 110, CH-8002 Zurich",
354 "Beispiel Inc, H. R. Giger, Brandschenkestrasse 110, CH-8002 Zurich, "
356 "Beispiel Inc, H. R. Giger, Brandschenkestrasse 110, CH-8002 Zurich, "
357 "Switzerland, hrgiger@beispiel.com",
358 "Beispiel Inc, H. R. Giger, Brandschenkestrasse 110, CH-8002 Zurich, "
359 "Switzerland, hrgiger@beispiel.com, +41446681800",
362 std::vector
<base::string16
> labels
;
363 for (size_t i
= 0; i
< arraysize(kExpectedLabels
); ++i
) {
364 AutofillProfile::CreateInferredLabels(
365 profiles
.get(), NULL
, UNKNOWN_TYPE
, i
, "en-US", &labels
);
366 ASSERT_FALSE(labels
.empty());
367 EXPECT_EQ(UTF8ToUTF16(kExpectedLabels
[i
]), labels
.back());
372 TEST(AutofillProfileTest
, CreateInferredLabelsI18n_FR
) {
373 ScopedVector
<AutofillProfile
> profiles
;
375 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
376 test::SetProfileInfo(profiles
.back(),
380 "antoine@exemple.com",
387 "+33 (0) 1 42 68 53 00");
388 profiles
.back()->set_language_code("fr_FR");
389 profiles
.back()->SetInfo(
390 AutofillType(ADDRESS_HOME_SORTING_CODE
), UTF8ToUTF16("CEDEX"), "en-US");
391 static const char* kExpectedLabels
[] = {
393 "Antoine de Saint-Exupéry",
394 "Antoine de Saint-Exupéry, 8 Rue de Londres",
395 "Antoine de Saint-Exupéry, 8 Rue de Londres, Paris",
396 "Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris",
397 "Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris CEDEX",
398 "Exemple Inc, Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris "
400 "Exemple Inc, Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris "
402 "Exemple Inc, Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris "
403 "CEDEX, France, antoine@exemple.com",
404 "Exemple Inc, Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris "
405 "CEDEX, France, antoine@exemple.com, +33142685300",
406 "Exemple Inc, Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris "
407 "CEDEX, France, antoine@exemple.com, +33142685300",
410 std::vector
<base::string16
> labels
;
411 for (size_t i
= 0; i
< arraysize(kExpectedLabels
); ++i
) {
412 AutofillProfile::CreateInferredLabels(
413 profiles
.get(), NULL
, UNKNOWN_TYPE
, i
, "en-US", &labels
);
414 ASSERT_FALSE(labels
.empty());
415 EXPECT_EQ(UTF8ToUTF16(kExpectedLabels
[i
]), labels
.back());
419 TEST(AutofillProfileTest
, CreateInferredLabelsI18n_KR
) {
420 ScopedVector
<AutofillProfile
> profiles
;
422 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
423 test::SetProfileInfo(profiles
.back(),
429 "Gangnam Finance Center",
431 "Gangnam-Gu", "Seoul",
435 profiles
.back()->set_language_code("ko_Latn");
436 profiles
.back()->SetInfo(AutofillType(ADDRESS_HOME_DEPENDENT_LOCALITY
),
437 UTF8ToUTF16("Yeoksam-Dong"),
439 static const char* kExpectedLabels
[] = {
442 "Park Jae-sang, Gangnam Finance Center",
443 "Park Jae-sang, Gangnam Finance Center, 152 Teheran-ro",
444 "Park Jae-sang, Gangnam Finance Center, 152 Teheran-ro, Yeoksam-Dong",
445 "Park Jae-sang, Gangnam Finance Center, 152 Teheran-ro, Yeoksam-Dong, "
447 "Park Jae-sang, Gangnam Finance Center, 152 Teheran-ro, Yeoksam-Dong, "
449 "Park Jae-sang, Gangnam Finance Center, 152 Teheran-ro, Yeoksam-Dong, "
450 "Gangnam-Gu, Seoul, 135-984",
451 "Park Jae-sang, Yeleul Inc, Gangnam Finance Center, 152 Teheran-ro, "
452 "Yeoksam-Dong, Gangnam-Gu, Seoul, 135-984",
453 "Park Jae-sang, Yeleul Inc, Gangnam Finance Center, 152 Teheran-ro, "
454 "Yeoksam-Dong, Gangnam-Gu, Seoul, 135-984, South Korea",
455 "Park Jae-sang, Yeleul Inc, Gangnam Finance Center, 152 Teheran-ro, "
456 "Yeoksam-Dong, Gangnam-Gu, Seoul, 135-984, South Korea, "
458 "Park Jae-sang, Yeleul Inc, Gangnam Finance Center, 152 Teheran-ro, "
459 "Yeoksam-Dong, Gangnam-Gu, Seoul, 135-984, South Korea, "
460 "park@yeleul.com, +8225319000",
463 std::vector
<base::string16
> labels
;
464 for (size_t i
= 0; i
< arraysize(kExpectedLabels
); ++i
) {
465 AutofillProfile::CreateInferredLabels(
466 profiles
.get(), NULL
, UNKNOWN_TYPE
, i
, "en-US", &labels
);
467 ASSERT_FALSE(labels
.empty());
468 EXPECT_EQ(UTF8ToUTF16(kExpectedLabels
[i
]), labels
.back());
472 TEST(AutofillProfileTest
, CreateInferredLabelsI18n_JP_Latn
) {
473 ScopedVector
<AutofillProfile
> profiles
;
475 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
476 test::SetProfileInfo(profiles
.back(),
482 "Roppongi Hills Mori Tower",
484 "Minato-ku", "Tokyo",
488 profiles
.back()->set_language_code("ja_Latn");
489 static const char* kExpectedLabels
[] = {
492 "Miku Hatsune, Roppongi Hills Mori Tower",
493 "Miku Hatsune, Roppongi Hills Mori Tower, 6-10-1 Roppongi",
494 "Miku Hatsune, Roppongi Hills Mori Tower, 6-10-1 Roppongi, Minato-ku",
495 "Miku Hatsune, Roppongi Hills Mori Tower, 6-10-1 Roppongi, Minato-ku, "
497 "Miku Hatsune, Roppongi Hills Mori Tower, 6-10-1 Roppongi, Minato-ku, "
499 "Miku Hatsune, Rei Inc, Roppongi Hills Mori Tower, 6-10-1 Roppongi, "
500 "Minato-ku, Tokyo, 106-6126",
501 "Miku Hatsune, Rei Inc, Roppongi Hills Mori Tower, 6-10-1 Roppongi, "
502 "Minato-ku, Tokyo, 106-6126, Japan",
503 "Miku Hatsune, Rei Inc, Roppongi Hills Mori Tower, 6-10-1 Roppongi, "
504 "Minato-ku, Tokyo, 106-6126, Japan, miku@rei.com",
505 "Miku Hatsune, Rei Inc, Roppongi Hills Mori Tower, 6-10-1 Roppongi, "
506 "Minato-ku, Tokyo, 106-6126, Japan, miku@rei.com, +81363849000",
509 std::vector
<base::string16
> labels
;
510 for (size_t i
= 0; i
< arraysize(kExpectedLabels
); ++i
) {
511 AutofillProfile::CreateInferredLabels(
512 profiles
.get(), NULL
, UNKNOWN_TYPE
, i
, "en-US", &labels
);
513 ASSERT_FALSE(labels
.empty());
514 EXPECT_EQ(UTF8ToUTF16(kExpectedLabels
[i
]), labels
.back());
518 TEST(AutofillProfileTest
, CreateInferredLabelsI18n_JP_ja
) {
519 ScopedVector
<AutofillProfile
> profiles
;
521 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
522 test::SetProfileInfo(profiles
.back(),
534 profiles
.back()->set_language_code("ja_JP");
535 static const char* kExpectedLabels
[] = {
539 "六本木ヒルズ森タワー六本木 6-10-1ミク 初音",
540 "港区六本木ヒルズ森タワー六本木 6-10-1ミク 初音",
541 "東京都港区六本木ヒルズ森タワー六本木 6-10-1ミク 初音",
542 "〒106-6126東京都港区六本木ヒルズ森タワー六本木 6-10-1ミク 初音",
543 "〒106-6126東京都港区六本木ヒルズ森タワー六本木 6-10-1例ミク 初音",
544 "〒106-6126東京都港区六本木ヒルズ森タワー六本木 6-10-1例ミク 初音, Japan",
545 "〒106-6126東京都港区六本木ヒルズ森タワー六本木 6-10-1例ミク 初音, Japan, "
547 "〒106-6126東京都港区六本木ヒルズ森タワー六本木 6-10-1例ミク 初音, Japan, "
548 "miku@rei.com, 0363849000",
551 std::vector
<base::string16
> labels
;
552 for (size_t i
= 0; i
< arraysize(kExpectedLabels
); ++i
) {
553 AutofillProfile::CreateInferredLabels(
554 profiles
.get(), NULL
, UNKNOWN_TYPE
, i
, "en-US", &labels
);
555 ASSERT_FALSE(labels
.empty());
556 EXPECT_EQ(UTF8ToUTF16(kExpectedLabels
[i
]), labels
.back());
560 TEST(AutofillProfileTest
, CreateInferredLabels
) {
561 ScopedVector
<AutofillProfile
> profiles
;
563 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
564 test::SetProfileInfo(profiles
[0],
577 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
578 test::SetProfileInfo(profiles
[1],
582 "janedoe@tertium.com",
590 std::vector
<base::string16
> labels
;
591 // Two fields at least - no filter.
592 AutofillProfile::CreateInferredLabels(profiles
.get(), NULL
, UNKNOWN_TYPE
, 2,
594 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St."), labels
[0]);
595 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels
[1]);
597 // Three fields at least - no filter.
598 AutofillProfile::CreateInferredLabels(profiles
.get(), NULL
, UNKNOWN_TYPE
, 3,
600 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., Elysium"),
602 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore., Dis"),
605 std::vector
<ServerFieldType
> suggested_fields
;
606 suggested_fields
.push_back(ADDRESS_HOME_CITY
);
607 suggested_fields
.push_back(ADDRESS_HOME_STATE
);
608 suggested_fields
.push_back(ADDRESS_HOME_ZIP
);
610 // Two fields at least, from suggested fields - no filter.
611 AutofillProfile::CreateInferredLabels(profiles
.get(), &suggested_fields
,
612 UNKNOWN_TYPE
, 2, "en-US", &labels
);
613 EXPECT_EQ(ASCIIToUTF16("Elysium 91111"), labels
[0]);
614 EXPECT_EQ(ASCIIToUTF16("Dis 91222"), labels
[1]);
616 // Three fields at least, from suggested fields - no filter.
617 AutofillProfile::CreateInferredLabels(profiles
.get(), &suggested_fields
,
618 UNKNOWN_TYPE
, 3, "en-US", &labels
);
619 EXPECT_EQ(ASCIIToUTF16("Elysium, CA 91111"), labels
[0]);
620 EXPECT_EQ(ASCIIToUTF16("Dis, CA 91222"), labels
[1]);
622 // Three fields at least, from suggested fields - but filter reduces available
624 AutofillProfile::CreateInferredLabels(profiles
.get(), &suggested_fields
,
625 ADDRESS_HOME_ZIP
, 3, "en-US", &labels
);
626 EXPECT_EQ(ASCIIToUTF16("Elysium, CA"), labels
[0]);
627 EXPECT_EQ(ASCIIToUTF16("Dis, CA"), labels
[1]);
629 suggested_fields
.clear();
630 // In our implementation we always display NAME_FULL for all NAME* fields...
631 suggested_fields
.push_back(NAME_MIDDLE
);
632 // One field at least, from suggested fields - no filter.
633 AutofillProfile::CreateInferredLabels(profiles
.get(), &suggested_fields
,
634 UNKNOWN_TYPE
, 1, "en-US", &labels
);
635 EXPECT_EQ(ASCIIToUTF16("John Doe"), labels
[0]);
636 EXPECT_EQ(ASCIIToUTF16("Jane Doe"), labels
[1]);
638 // One field at least, from suggested fields - filter the same as suggested
640 AutofillProfile::CreateInferredLabels(profiles
.get(), &suggested_fields
,
641 NAME_MIDDLE
, 1, "en-US", &labels
);
642 EXPECT_EQ(base::string16(), labels
[0]);
643 EXPECT_EQ(base::string16(), labels
[1]);
645 suggested_fields
.clear();
646 // In our implementation we always display NAME_FULL for NAME_MIDDLE_INITIAL
647 suggested_fields
.push_back(NAME_MIDDLE_INITIAL
);
648 // One field at least, from suggested fields - no filter.
649 AutofillProfile::CreateInferredLabels(profiles
.get(), &suggested_fields
,
650 UNKNOWN_TYPE
, 1, "en-US", &labels
);
651 EXPECT_EQ(ASCIIToUTF16("John Doe"), labels
[0]);
652 EXPECT_EQ(ASCIIToUTF16("Jane Doe"), labels
[1]);
654 // One field at least, from suggested fields - filter same as the first non-
655 // unknown suggested field.
656 suggested_fields
.clear();
657 suggested_fields
.push_back(UNKNOWN_TYPE
);
658 suggested_fields
.push_back(NAME_FULL
);
659 suggested_fields
.push_back(ADDRESS_HOME_LINE1
);
660 AutofillProfile::CreateInferredLabels(profiles
.get(), &suggested_fields
,
661 NAME_FULL
, 1, "en-US", &labels
);
662 EXPECT_EQ(base::string16(ASCIIToUTF16("666 Erebus St.")), labels
[0]);
663 EXPECT_EQ(base::string16(ASCIIToUTF16("123 Letha Shore.")), labels
[1]);
665 // No suggested fields, but non-unknown excluded field.
666 AutofillProfile::CreateInferredLabels(profiles
.get(), NULL
,
667 NAME_FULL
, 1, "en-US", &labels
);
668 EXPECT_EQ(base::string16(ASCIIToUTF16("666 Erebus St.")), labels
[0]);
669 EXPECT_EQ(base::string16(ASCIIToUTF16("123 Letha Shore.")), labels
[1]);
672 // Test that we fall back to using the full name if there are no other
673 // distinguishing fields, but only if it makes sense given the suggested fields.
674 TEST(AutofillProfileTest
, CreateInferredLabelsFallsBackToFullName
) {
675 ScopedVector
<AutofillProfile
> profiles
;
677 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
678 test::SetProfileInfo(profiles
[0],
679 "John", "", "Doe", "doe@example.com", "",
680 "88 Nowhere Ave.", "", "", "", "", "", "");
682 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
683 test::SetProfileInfo(profiles
[1],
684 "Johnny", "K", "Doe", "doe@example.com", "",
685 "88 Nowhere Ave.", "", "", "", "", "", "");
687 // If the only name field in the suggested fields is the excluded field, we
688 // should not fall back to the full name as a distinguishing field.
689 std::vector
<ServerFieldType
> suggested_fields
;
690 suggested_fields
.push_back(NAME_LAST
);
691 suggested_fields
.push_back(ADDRESS_HOME_LINE1
);
692 suggested_fields
.push_back(EMAIL_ADDRESS
);
693 std::vector
<base::string16
> labels
;
694 AutofillProfile::CreateInferredLabels(profiles
.get(), &suggested_fields
,
695 NAME_LAST
, 1, "en-US", &labels
);
696 ASSERT_EQ(2U, labels
.size());
697 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave."), labels
[0]);
698 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave."), labels
[1]);
700 // Otherwise, we should.
701 suggested_fields
.push_back(NAME_FIRST
);
702 AutofillProfile::CreateInferredLabels(profiles
.get(), &suggested_fields
,
703 NAME_LAST
, 1, "en-US", &labels
);
704 ASSERT_EQ(2U, labels
.size());
705 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., John Doe"), labels
[0]);
706 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., Johnny K Doe"), labels
[1]);
709 // Test that we do not show duplicate fields in the labels.
710 TEST(AutofillProfileTest
, CreateInferredLabelsNoDuplicatedFields
) {
711 ScopedVector
<AutofillProfile
> profiles
;
713 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
714 test::SetProfileInfo(profiles
[0],
715 "John", "", "Doe", "doe@example.com", "",
716 "88 Nowhere Ave.", "", "", "", "", "", "");
718 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
719 test::SetProfileInfo(profiles
[1],
720 "John", "", "Doe", "dojo@example.com", "",
721 "88 Nowhere Ave.", "", "", "", "", "", "");
723 // If the only name field in the suggested fields is the excluded field, we
724 // should not fall back to the full name as a distinguishing field.
725 std::vector
<ServerFieldType
> suggested_fields
;
726 suggested_fields
.push_back(ADDRESS_HOME_LINE1
);
727 suggested_fields
.push_back(ADDRESS_BILLING_LINE1
);
728 suggested_fields
.push_back(EMAIL_ADDRESS
);
729 std::vector
<base::string16
> labels
;
730 AutofillProfile::CreateInferredLabels(profiles
.get(), &suggested_fields
,
731 UNKNOWN_TYPE
, 2, "en-US", &labels
);
732 ASSERT_EQ(2U, labels
.size());
733 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., doe@example.com"), labels
[0]);
734 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., dojo@example.com"), labels
[1]);
737 // Make sure that empty fields are not treated as distinguishing fields.
738 TEST(AutofillProfileTest
, CreateInferredLabelsSkipsEmptyFields
) {
739 ScopedVector
<AutofillProfile
> profiles
;
741 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
742 test::SetProfileInfo(profiles
[0],
743 "John", "", "Doe", "doe@example.com",
744 "Gogole", "", "", "", "", "", "", "");
746 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
747 test::SetProfileInfo(profiles
[1],
748 "John", "", "Doe", "doe@example.com",
749 "Ggoole", "", "", "", "", "", "", "");
751 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
752 test::SetProfileInfo(profiles
[2],
753 "John", "", "Doe", "john.doe@example.com",
754 "Goolge", "", "", "", "", "", "", "");
756 std::vector
<base::string16
> labels
;
757 AutofillProfile::CreateInferredLabels(profiles
.get(), NULL
, UNKNOWN_TYPE
, 3,
759 ASSERT_EQ(3U, labels
.size());
760 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Gogole"), labels
[0]);
761 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Ggoole"), labels
[1]);
762 EXPECT_EQ(ASCIIToUTF16("John Doe, john.doe@example.com, Goolge"), labels
[2]);
764 // A field must have a non-empty value for each profile to be considered a
765 // distinguishing field.
766 profiles
[1]->SetRawInfo(ADDRESS_HOME_LINE1
, ASCIIToUTF16("88 Nowhere Ave."));
767 AutofillProfile::CreateInferredLabels(profiles
.get(), NULL
, UNKNOWN_TYPE
, 1,
769 ASSERT_EQ(3U, labels
.size());
770 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Gogole"), labels
[0]);
771 EXPECT_EQ(ASCIIToUTF16("John Doe, 88 Nowhere Ave., doe@example.com, Ggoole"),
772 labels
[1]) << labels
[1];
773 EXPECT_EQ(ASCIIToUTF16("John Doe, john.doe@example.com"), labels
[2]);
776 // Test that labels that would otherwise have multiline values are flattened.
777 TEST(AutofillProfileTest
, CreateInferredLabelsFlattensMultiLineValues
) {
778 ScopedVector
<AutofillProfile
> profiles
;
780 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
781 test::SetProfileInfo(profiles
[0],
782 "John", "", "Doe", "doe@example.com", "",
783 "88 Nowhere Ave.", "Apt. 42", "", "", "", "", "");
785 // If the only name field in the suggested fields is the excluded field, we
786 // should not fall back to the full name as a distinguishing field.
787 std::vector
<ServerFieldType
> suggested_fields
;
788 suggested_fields
.push_back(NAME_FULL
);
789 suggested_fields
.push_back(ADDRESS_HOME_STREET_ADDRESS
);
790 std::vector
<base::string16
> labels
;
791 AutofillProfile::CreateInferredLabels(profiles
.get(), &suggested_fields
,
792 NAME_FULL
, 1, "en-US", &labels
);
793 ASSERT_EQ(1U, labels
.size());
794 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., Apt. 42"), labels
[0]);
797 TEST(AutofillProfileTest
, IsSubsetOf
) {
798 scoped_ptr
<AutofillProfile
> a
, b
;
800 // |a| is a subset of |b|.
802 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
804 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
805 test::SetProfileInfo(a
.get(), "Thomas", NULL
, "Jefferson",
806 "declaration_guy@gmail.com", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
808 test::SetProfileInfo(b
.get(), "Thomas", NULL
, "Jefferson",
809 "declaration_guy@gmail.com", "United States Government", "Monticello",
810 NULL
, "Charlottesville", "Virginia", "22902", NULL
, NULL
);
811 EXPECT_TRUE(a
->IsSubsetOf(*b
, "en-US"));
813 // |b| is not a subset of |a|.
814 EXPECT_FALSE(b
->IsSubsetOf(*a
, "en-US"));
816 // |a| is a subset of |a|.
817 EXPECT_TRUE(a
->IsSubsetOf(*a
, "en-US"));
819 // One field in |b| is different.
821 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
823 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
824 test::SetProfileInfo(a
.get(), "Thomas", NULL
, "Jefferson",
825 "declaration_guy@gmail.com", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
827 test::SetProfileInfo(a
.get(), "Thomas", NULL
, "Adams",
828 "declaration_guy@gmail.com", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
830 EXPECT_FALSE(a
->IsSubsetOf(*b
, "en-US"));
833 TEST(AutofillProfileTest
, OverwriteWith
) {
834 AutofillProfile
a(base::GenerateGUID(), "https://www.example.com");
835 test::SetProfileInfo(&a
, "Marion", "Mitchell", "Morrison",
836 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5",
837 "Hollywood", "CA", "91601", "US",
840 // Create an identical profile except that the new profile:
841 // (1) Has a different origin,
842 // (2) Has a different address line 2,
843 // (3) Lacks a company name,
844 // (4) Has a different full name, and
845 // (5) Has a language code.
846 AutofillProfile b
= a
;
847 b
.set_guid(base::GenerateGUID());
848 b
.set_origin("Chrome settings");
849 b
.SetRawInfo(ADDRESS_HOME_LINE2
, ASCIIToUTF16("area 51"));
850 b
.SetRawInfo(COMPANY_NAME
, base::string16());
852 b
.SetRawInfo(NAME_FULL
, ASCIIToUTF16("Marion M. Morrison"));
853 b
.set_language_code("en");
855 a
.OverwriteWith(b
, "en-US");
856 EXPECT_EQ("Chrome settings", a
.origin());
857 EXPECT_EQ(ASCIIToUTF16("area 51"), a
.GetRawInfo(ADDRESS_HOME_LINE2
));
858 EXPECT_EQ(ASCIIToUTF16("Fox"), a
.GetRawInfo(COMPANY_NAME
));
859 base::string16 name
= a
.GetInfo(AutofillType(NAME_FULL
), "en-US");
860 EXPECT_EQ(ASCIIToUTF16("Marion M. Morrison"), name
);
861 EXPECT_EQ("en", a
.language_code());
864 TEST(AutofillProfileTest
, AssignmentOperator
) {
865 AutofillProfile
a(base::GenerateGUID(), "https://www.example.com/");
866 test::SetProfileInfo(&a
, "Marion", "Mitchell", "Morrison",
867 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5",
868 "Hollywood", "CA", "91601", "US",
871 // Result of assignment should be logically equal to the original profile.
872 AutofillProfile
b(base::GenerateGUID(), "http://www.example.com/");
876 // Assignment to self should not change the profile value.
881 TEST(AutofillProfileTest
, Copy
) {
882 AutofillProfile
a(base::GenerateGUID(), "https://www.example.com/");
883 test::SetProfileInfo(&a
, "Marion", "Mitchell", "Morrison",
884 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5",
885 "Hollywood", "CA", "91601", "US",
888 // Clone should be logically equal to the original.
889 AutofillProfile
b(a
);
893 TEST(AutofillProfileTest
, Compare
) {
894 AutofillProfile
a(base::GenerateGUID(), std::string());
895 AutofillProfile
b(base::GenerateGUID(), std::string());
897 // Empty profiles are the same.
898 EXPECT_EQ(0, a
.Compare(b
));
900 // GUIDs don't count.
901 a
.set_guid(base::GenerateGUID());
902 b
.set_guid(base::GenerateGUID());
903 EXPECT_EQ(0, a
.Compare(b
));
905 // Origins don't count.
906 a
.set_origin("apple");
907 b
.set_origin("banana");
908 EXPECT_EQ(0, a
.Compare(b
));
910 // Different values produce non-zero results.
911 test::SetProfileInfo(&a
, "Jimmy", NULL
, NULL
, NULL
,
912 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
913 test::SetProfileInfo(&b
, "Ringo", NULL
, NULL
, NULL
,
914 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
915 EXPECT_GT(0, a
.Compare(b
));
916 EXPECT_LT(0, b
.Compare(a
));
918 // Phone numbers are compared by the full number, including the area code.
919 // This is a regression test for http://crbug.com/163024
920 test::SetProfileInfo(&a
, NULL
, NULL
, NULL
, NULL
,
921 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "650.555.4321");
922 test::SetProfileInfo(&b
, NULL
, NULL
, NULL
, NULL
,
923 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "408.555.4321");
924 EXPECT_GT(0, a
.Compare(b
));
925 EXPECT_LT(0, b
.Compare(a
));
927 // Addresses are compared in full. Regression test for http://crbug.com/375545
928 test::SetProfileInfo(&a
, "John", NULL
, NULL
, NULL
,
929 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
930 a
.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS
,
931 ASCIIToUTF16("line one\nline two"));
932 test::SetProfileInfo(&b
, "John", NULL
, NULL
, NULL
,
933 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
934 b
.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS
,
935 ASCIIToUTF16("line one\nline two\nline three"));
936 EXPECT_GT(0, a
.Compare(b
));
937 EXPECT_LT(0, b
.Compare(a
));
940 TEST(AutofillProfileTest
, IsPresentButInvalid
) {
941 AutofillProfile
profile(base::GenerateGUID(), "https://www.example.com/");
942 EXPECT_FALSE(profile
.IsPresentButInvalid(ADDRESS_HOME_STATE
));
943 EXPECT_FALSE(profile
.IsPresentButInvalid(ADDRESS_HOME_ZIP
));
944 EXPECT_FALSE(profile
.IsPresentButInvalid(PHONE_HOME_WHOLE_NUMBER
));
946 profile
.SetRawInfo(ADDRESS_HOME_COUNTRY
, ASCIIToUTF16("US"));
947 EXPECT_FALSE(profile
.IsPresentButInvalid(ADDRESS_HOME_STATE
));
948 EXPECT_FALSE(profile
.IsPresentButInvalid(ADDRESS_HOME_ZIP
));
949 EXPECT_FALSE(profile
.IsPresentButInvalid(PHONE_HOME_WHOLE_NUMBER
));
951 profile
.SetRawInfo(ADDRESS_HOME_STATE
, ASCIIToUTF16("C"));
952 EXPECT_TRUE(profile
.IsPresentButInvalid(ADDRESS_HOME_STATE
));
954 profile
.SetRawInfo(ADDRESS_HOME_STATE
, ASCIIToUTF16("CA"));
955 EXPECT_FALSE(profile
.IsPresentButInvalid(ADDRESS_HOME_STATE
));
957 profile
.SetRawInfo(ADDRESS_HOME_ZIP
, ASCIIToUTF16("90"));
958 EXPECT_TRUE(profile
.IsPresentButInvalid(ADDRESS_HOME_ZIP
));
960 profile
.SetRawInfo(ADDRESS_HOME_ZIP
, ASCIIToUTF16("90210"));
961 EXPECT_FALSE(profile
.IsPresentButInvalid(ADDRESS_HOME_ZIP
));
963 profile
.SetRawInfo(PHONE_HOME_WHOLE_NUMBER
, ASCIIToUTF16("310"));
964 EXPECT_TRUE(profile
.IsPresentButInvalid(PHONE_HOME_WHOLE_NUMBER
));
966 profile
.SetRawInfo(PHONE_HOME_WHOLE_NUMBER
, ASCIIToUTF16("(310) 310-6000"));
967 EXPECT_FALSE(profile
.IsPresentButInvalid(PHONE_HOME_WHOLE_NUMBER
));
970 TEST(AutofillProfileTest
, SetRawInfoPreservesLineBreaks
) {
971 AutofillProfile
profile(base::GenerateGUID(), "https://www.example.com/");
973 profile
.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS
,
974 ASCIIToUTF16("123 Super St.\n"
976 EXPECT_EQ(ASCIIToUTF16("123 Super St.\n"
978 profile
.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS
));
981 TEST(AutofillProfileTest
, SetInfoPreservesLineBreaks
) {
982 AutofillProfile
profile(base::GenerateGUID(), "https://www.example.com/");
984 profile
.SetInfo(AutofillType(ADDRESS_HOME_STREET_ADDRESS
),
985 ASCIIToUTF16("123 Super St.\n"
988 EXPECT_EQ(ASCIIToUTF16("123 Super St.\n"
990 profile
.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS
));
993 TEST(AutofillProfileTest
, SetRawInfoDoesntTrimWhitespace
) {
994 AutofillProfile
profile(base::GenerateGUID(), "https://www.example.com/");
996 profile
.SetRawInfo(EMAIL_ADDRESS
, ASCIIToUTF16("\tuser@example.com "));
997 EXPECT_EQ(ASCIIToUTF16("\tuser@example.com "),
998 profile
.GetRawInfo(EMAIL_ADDRESS
));
1001 TEST(AutofillProfileTest
, SetInfoTrimsWhitespace
) {
1002 AutofillProfile
profile(base::GenerateGUID(), "https://www.example.com/");
1004 profile
.SetInfo(AutofillType(EMAIL_ADDRESS
),
1005 ASCIIToUTF16("\tuser@example.com "),
1007 EXPECT_EQ(ASCIIToUTF16("user@example.com"),
1008 profile
.GetRawInfo(EMAIL_ADDRESS
));
1011 TEST(AutofillProfileTest
, FullAddress
) {
1012 AutofillProfile
profile(base::GenerateGUID(), "https://www.example.com/");
1013 test::SetProfileInfo(&profile
, "Marion", "Mitchell", "Morrison",
1014 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5",
1015 "Hollywood", "CA", "91601", "US",
1018 AutofillType
full_address(HTML_TYPE_FULL_ADDRESS
, HTML_MODE_NONE
);
1019 base::string16
formatted_address(ASCIIToUTF16(
1020 "Marion Mitchell Morrison\n"
1024 "Hollywood, CA 91601"));
1025 EXPECT_EQ(formatted_address
, profile
.GetInfo(full_address
, "en-US"));
1026 // This should fail and leave the profile unchanged.
1027 EXPECT_FALSE(profile
.SetInfo(full_address
, ASCIIToUTF16("foobar"), "en-US"));
1028 EXPECT_EQ(formatted_address
, profile
.GetInfo(full_address
, "en-US"));
1030 // Some things can be missing...
1031 profile
.SetInfo(AutofillType(ADDRESS_HOME_LINE2
),
1034 profile
.SetInfo(AutofillType(EMAIL_ADDRESS
),
1037 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell Morrison\n"
1040 "Hollywood, CA 91601"),
1041 profile
.GetInfo(full_address
, "en-US"));
1043 // ...but nothing comes out if a required field is missing.
1044 profile
.SetInfo(AutofillType(ADDRESS_HOME_STATE
), base::string16(), "en-US");
1045 EXPECT_TRUE(profile
.GetInfo(full_address
, "en-US").empty());
1047 // Restore the state but remove country. This should also fail.
1048 profile
.SetInfo(AutofillType(ADDRESS_HOME_STATE
),
1051 EXPECT_FALSE(profile
.GetInfo(full_address
, "en-US").empty());
1052 profile
.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY
),
1055 EXPECT_TRUE(profile
.GetInfo(full_address
, "en-US").empty());
1058 TEST(AutofillProfileTest
, CanonicalizeProfileString
) {
1060 EXPECT_EQ(base::string16(),
1061 AutofillProfile::CanonicalizeProfileString(base::string16()));
1063 // Simple punctuation removed.
1064 EXPECT_EQ(ASCIIToUTF16("1600 amphitheatre pkwy"),
1065 AutofillProfile::CanonicalizeProfileString(ASCIIToUTF16(
1066 "1600 Amphitheatre, Pkwy.")));
1068 // Unicode punctuation (hyphen and space), multiple spaces collapsed.
1069 EXPECT_EQ(ASCIIToUTF16("mid island plaza"),
1070 AutofillProfile::CanonicalizeProfileString(base::WideToUTF16(
1071 L
"Mid\x2013Island\x2003 Plaza")));
1074 } // namespace autofill