OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/scoped_ptr.h" | 6 #include "base/scoped_ptr.h" |
7 #include "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
8 #include "base/string16.h" | 8 #include "base/string16.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/autofill/autofill_common_test.h" | 10 #include "chrome/browser/autofill/autofill_common_test.h" |
11 #include "chrome/browser/autofill/autofill_profile.h" | 11 #include "chrome/browser/autofill/autofill_profile.h" |
12 #include "chrome/browser/guid.h" | 12 #include "chrome/browser/guid.h" |
13 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
| 18 bool UpdateProfileLabel(AutoFillProfile *profile) { |
| 19 std::vector<AutoFillProfile*> profiles; |
| 20 profiles.push_back(profile); |
| 21 return AutoFillProfile::AdjustInferredLabels(&profiles); |
| 22 } |
| 23 |
18 // Tests different possibilities for summary string generation. | 24 // Tests different possibilities for summary string generation. |
19 // Based on existence of first name, last name, and address line 1. | 25 // Based on existence of first name, last name, and address line 1. |
20 TEST(AutoFillProfileTest, PreviewSummaryString) { | 26 TEST(AutoFillProfileTest, PreviewSummaryString) { |
21 // Case 0/null: "" | 27 // Case 0/null: "" |
22 AutoFillProfile profile0(string16(), 0); | 28 AutoFillProfile profile0(string16(), 0); |
23 string16 summary0 = profile0.PreviewSummary(); | 29 // Empty profile - nothing to update. |
| 30 EXPECT_FALSE(UpdateProfileLabel(&profile0)); |
| 31 string16 summary0 = profile0.Label(); |
24 EXPECT_EQ(string16(), summary0); | 32 EXPECT_EQ(string16(), summary0); |
25 | 33 |
26 // Case 0/empty: "" | 34 // Case 0a/empty name and address, so the first two fields of the rest of the |
| 35 // data is used: "Hollywood, CA" |
27 AutoFillProfile profile00(string16(), 0); | 36 AutoFillProfile profile00(string16(), 0); |
28 autofill_test::SetProfileInfo(&profile00, "Billing", "", "Mitchell", "", | 37 autofill_test::SetProfileInfo(&profile00, "Billing", "", "Mitchell", "", |
29 "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", "91601", "US", | 38 "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", "91601", "US", |
30 "12345678910", "01987654321"); | 39 "12345678910", "01987654321"); |
31 string16 summary00 = profile00.PreviewSummary(); | 40 EXPECT_TRUE(UpdateProfileLabel(&profile00)); |
32 EXPECT_EQ(string16(), summary00); | 41 string16 summary00 = profile00.Label(); |
| 42 EXPECT_EQ(string16(ASCIIToUTF16("Hollywood, CA")), summary00); |
33 | 43 |
34 // Case 1: "<address>" | 44 // Case 1: "<address>" |
35 AutoFillProfile profile1(string16(), 0); | 45 AutoFillProfile profile1(string16(), 0); |
36 autofill_test::SetProfileInfo(&profile1, "Billing", "", "Mitchell", "", | 46 autofill_test::SetProfileInfo(&profile1, "Billing", "", "Mitchell", "", |
37 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 47 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
38 "91601", "US", "12345678910", "01987654321"); | 48 "91601", "US", "12345678910", "01987654321"); |
39 string16 summary1 = profile1.PreviewSummary(); | 49 EXPECT_TRUE(UpdateProfileLabel(&profile1)); |
40 EXPECT_EQ(string16(ASCIIToUTF16("123 Zoo St.")), summary1); | 50 string16 summary1 = profile1.Label(); |
| 51 EXPECT_EQ(string16(ASCIIToUTF16("123 Zoo St., Hollywood")), summary1); |
41 | 52 |
42 // Case 2: "<lastname>" | 53 // Case 2: "<lastname>" |
43 AutoFillProfile profile2(string16(), 0); | 54 AutoFillProfile profile2(string16(), 0); |
44 autofill_test::SetProfileInfo(&profile2, "Billing", "", "Mitchell", | 55 autofill_test::SetProfileInfo(&profile2, "Billing", "", "Mitchell", |
45 "Morrison", "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", | 56 "Morrison", "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", |
46 "91601", "US", "12345678910", "01987654321"); | 57 "91601", "US", "12345678910", "01987654321"); |
47 string16 summary2 = profile2.PreviewSummary(); | 58 EXPECT_TRUE(UpdateProfileLabel(&profile2)); |
48 EXPECT_EQ(string16(ASCIIToUTF16("Morrison")), summary2); | 59 string16 summary2 = profile2.Label(); |
| 60 // Summary does include full name which is empty if the first name is empty. |
| 61 EXPECT_EQ(string16(ASCIIToUTF16("Hollywood, CA")), summary2); |
49 | 62 |
50 // Case 3: "<lastname>, <address>" | 63 // Case 3: "<lastname>, <address>" |
51 AutoFillProfile profile3(string16(), 0); | 64 AutoFillProfile profile3(string16(), 0); |
52 autofill_test::SetProfileInfo(&profile3, "Billing", "", "Mitchell", | 65 autofill_test::SetProfileInfo(&profile3, "Billing", "", "Mitchell", |
53 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", | 66 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
54 "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); | 67 "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); |
55 string16 summary3 = profile3.PreviewSummary(); | 68 EXPECT_TRUE(UpdateProfileLabel(&profile3)); |
56 EXPECT_EQ(string16(ASCIIToUTF16("Morrison, 123 Zoo St.")), summary3); | 69 string16 summary3 = profile3.Label(); |
| 70 EXPECT_EQ(string16(ASCIIToUTF16("123 Zoo St., Hollywood")), summary3); |
57 | 71 |
58 // Case 4: "<firstname>" | 72 // Case 4: "<firstname>" |
59 AutoFillProfile profile4(string16(), 0); | 73 AutoFillProfile profile4(string16(), 0); |
60 autofill_test::SetProfileInfo(&profile4, "Billing", "Marion", "Mitchell", "", | 74 autofill_test::SetProfileInfo(&profile4, "Billing", "Marion", "Mitchell", "", |
61 "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", "91601", "US", | 75 "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", "91601", "US", |
62 "12345678910", "01987654321"); | 76 "12345678910", "01987654321"); |
63 string16 summary4 = profile4.PreviewSummary(); | 77 EXPECT_TRUE(UpdateProfileLabel(&profile4)); |
64 EXPECT_EQ(string16(ASCIIToUTF16("Marion")), summary4); | 78 string16 summary4 = profile4.Label(); |
| 79 EXPECT_EQ(string16(ASCIIToUTF16("Marion Mitchell, Hollywood")), summary4); |
65 | 80 |
66 // Case 5: "<firstname>, <address>" | 81 // Case 5: "<firstname>, <address>" |
67 AutoFillProfile profile5(string16(), 0); | 82 AutoFillProfile profile5(string16(), 0); |
68 autofill_test::SetProfileInfo(&profile5, "Billing", "Marion", "Mitchell", "", | 83 autofill_test::SetProfileInfo(&profile5, "Billing", "Marion", "Mitchell", "", |
69 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 84 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
70 "91601", "US", "12345678910", "01987654321"); | 85 "91601", "US", "12345678910", "01987654321"); |
71 string16 summary5 = profile5.PreviewSummary(); | 86 EXPECT_TRUE(UpdateProfileLabel(&profile5)); |
72 EXPECT_EQ(string16(ASCIIToUTF16("Marion, 123 Zoo St.")), summary5); | 87 string16 summary5 = profile5.Label(); |
| 88 EXPECT_EQ(string16(ASCIIToUTF16("Marion Mitchell, 123 Zoo St.")), summary5); |
73 | 89 |
74 // Case 6: "<firstname> <lastname>" | 90 // Case 6: "<firstname> <lastname>" |
75 AutoFillProfile profile6(string16(), 0); | 91 AutoFillProfile profile6(string16(), 0); |
76 autofill_test::SetProfileInfo(&profile6, "Billing", "Marion", "Mitchell", | 92 autofill_test::SetProfileInfo(&profile6, "Billing", "Marion", "Mitchell", |
77 "Morrison", "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", | 93 "Morrison", "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", |
78 "91601", "US", "12345678910", "01987654321"); | 94 "91601", "US", "12345678910", "01987654321"); |
79 string16 summary6 = profile6.PreviewSummary(); | 95 EXPECT_TRUE(UpdateProfileLabel(&profile6)); |
80 EXPECT_EQ(string16(ASCIIToUTF16("Marion Morrison")), summary6); | 96 string16 summary6 = profile6.Label(); |
| 97 EXPECT_EQ(string16(ASCIIToUTF16("Marion Mitchell Morrison, Hollywood")), |
| 98 summary6); |
81 | 99 |
82 // Case 7: "<firstname> <lastname>, <address>" | 100 // Case 7: "<firstname> <lastname>, <address>" |
83 AutoFillProfile profile7(string16(), 0); | 101 AutoFillProfile profile7(string16(), 0); |
84 autofill_test::SetProfileInfo(&profile7, "Billing", "Marion", "Mitchell", | 102 autofill_test::SetProfileInfo(&profile7, "Billing", "Marion", "Mitchell", |
85 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", | 103 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
86 "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); | 104 "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); |
87 string16 summary7 = profile7.PreviewSummary(); | 105 EXPECT_TRUE(UpdateProfileLabel(&profile7)); |
88 EXPECT_EQ(string16(ASCIIToUTF16("Marion Morrison, 123 Zoo St.")), summary7); | 106 string16 summary7 = profile7.Label(); |
| 107 EXPECT_EQ(string16(ASCIIToUTF16("Marion Mitchell Morrison, 123 Zoo St.")), |
| 108 summary7); |
| 109 |
| 110 // Case 7a: "<firstname> <lastname>, <address>" - same as #7, except for |
| 111 // e-mail. |
| 112 AutoFillProfile profile7a(string16(), 0); |
| 113 autofill_test::SetProfileInfo(&profile7a, "Billing", "Marion", "Mitchell", |
| 114 "Morrison", "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
| 115 "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); |
| 116 std::vector<AutoFillProfile*> profiles; |
| 117 profiles.push_back(&profile7); |
| 118 profiles.push_back(&profile7a); |
| 119 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles)); |
| 120 summary7 = profile7.Label(); |
| 121 string16 summary7a = profile7a.Label(); |
| 122 EXPECT_EQ(string16(ASCIIToUTF16( |
| 123 "Marion Mitchell Morrison, 123 Zoo St., johnwayne@me.xyz")), summary7); |
| 124 EXPECT_EQ(string16(ASCIIToUTF16( |
| 125 "Marion Mitchell Morrison, 123 Zoo St., marion@me.xyz")), summary7a); |
89 } | 126 } |
90 | 127 |
91 TEST(AutoFillProfileTest, AdjustInferredLabels) { | 128 TEST(AutoFillProfileTest, AdjustInferredLabels) { |
92 std::vector<AutoFillProfile*> profiles; | 129 std::vector<AutoFillProfile*> profiles; |
93 profiles.push_back(new AutoFillProfile(string16(), 0)); | 130 profiles.push_back(new AutoFillProfile(string16(), 0)); |
94 autofill_test::SetProfileInfo( | 131 autofill_test::SetProfileInfo( |
95 profiles[0], | 132 profiles[0], |
96 "", | 133 "", |
97 "John", | 134 "John", |
98 "", | 135 "", |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 // Different values produce non-zero results. | 414 // Different values produce non-zero results. |
378 autofill_test::SetProfileInfo(&a, "label1", "Jimmy", NULL, NULL, NULL, | 415 autofill_test::SetProfileInfo(&a, "label1", "Jimmy", NULL, NULL, NULL, |
379 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); | 416 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
380 autofill_test::SetProfileInfo(&b, "label1", "Ringo", NULL, NULL, NULL, | 417 autofill_test::SetProfileInfo(&b, "label1", "Ringo", NULL, NULL, NULL, |
381 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); | 418 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
382 EXPECT_GT(0, a.Compare(b)); | 419 EXPECT_GT(0, a.Compare(b)); |
383 EXPECT_LT(0, b.Compare(a)); | 420 EXPECT_LT(0, b.Compare(a)); |
384 } | 421 } |
385 | 422 |
386 } // namespace | 423 } // namespace |
OLD | NEW |