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/string16.h" | 7 #include "base/string16.h" |
7 #include "chrome/browser/autofill/autofill_common_unittest.h" | 8 #include "chrome/browser/autofill/autofill_common_unittest.h" |
8 #include "chrome/browser/autofill/autofill_profile.h" | 9 #include "chrome/browser/autofill/autofill_profile.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 | 11 |
11 namespace { | 12 namespace { |
12 | 13 |
13 // Tests different possibilities for summary string generation. | 14 // Tests different possibilities for summary string generation. |
14 // Based on existence of first name, last name, and address line 1. | 15 // Based on existence of first name, last name, and address line 1. |
15 TEST(AutoFillProfileTest, PreviewSummaryString) { | 16 TEST(AutoFillProfileTest, PreviewSummaryString) { |
16 // Case 0/null: "" | 17 // Case 0/null: "" |
17 AutoFillProfile profile0(string16(), 0); | 18 AutoFillProfile profile0(string16(), 0); |
18 string16 summary0 = profile0.PreviewSummary(); | 19 string16 summary0 = profile0.PreviewSummary(); |
19 EXPECT_EQ(string16(), summary0); | 20 EXPECT_EQ(string16(), summary0); |
20 | 21 |
21 // Case 0/empty: "" | 22 // Case 0/empty: "" |
22 AutoFillProfile profile00(string16(), 0); | 23 AutoFillProfile profile00(string16(), 0); |
23 autofill_unittest::SetProfileInfo( | 24 autofill_unittest::SetProfileInfo(&profile00, "Billing", "", "Mitchell", "", |
24 &profile00, | 25 "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", "91601", "US", |
25 "Billing", | 26 "12345678910", "01987654321"); |
26 "", | |
27 "Mitchell", | |
28 "", | |
29 "johnwayne@me.xyz", | |
30 "Fox", | |
31 "", | |
32 "unit 5", | |
33 "Hollywood", "CA", | |
34 "91601", | |
35 "US", | |
36 "12345678910", | |
37 "01987654321"); | |
38 string16 summary00 = profile00.PreviewSummary(); | 27 string16 summary00 = profile00.PreviewSummary(); |
39 EXPECT_EQ(string16(), summary00); | 28 EXPECT_EQ(string16(), summary00); |
40 | 29 |
41 // Case 1: "<address>" | 30 // Case 1: "<address>" |
42 AutoFillProfile profile1(string16(), 0); | 31 AutoFillProfile profile1(string16(), 0); |
43 autofill_unittest::SetProfileInfo( | 32 autofill_unittest::SetProfileInfo(&profile1, "Billing", "", "Mitchell", "", |
44 &profile1, | 33 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
45 "Billing", | 34 "91601", "US", "12345678910", "01987654321"); |
46 "", | |
47 "Mitchell", | |
48 "", | |
49 "johnwayne@me.xyz", | |
50 "Fox", | |
51 "123 Zoo St.", | |
52 "unit 5", | |
53 "Hollywood", "CA", | |
54 "91601", | |
55 "US", | |
56 "12345678910", | |
57 "01987654321"); | |
58 string16 summary1 = profile1.PreviewSummary(); | 35 string16 summary1 = profile1.PreviewSummary(); |
59 EXPECT_EQ(string16(ASCIIToUTF16("123 Zoo St.")), summary1); | 36 EXPECT_EQ(string16(ASCIIToUTF16("123 Zoo St.")), summary1); |
60 | 37 |
61 // Case 2: "<lastname>" | 38 // Case 2: "<lastname>" |
62 AutoFillProfile profile2(string16(), 0); | 39 AutoFillProfile profile2(string16(), 0); |
63 autofill_unittest::SetProfileInfo( | 40 autofill_unittest::SetProfileInfo(&profile2, "Billing", "", "Mitchell", |
64 &profile2, | 41 "Morrison", "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", |
65 "Billing", | 42 "91601", "US", "12345678910", "01987654321"); |
66 "", | |
67 "Mitchell", | |
68 "Morrison", | |
69 "johnwayne@me.xyz", | |
70 "Fox", | |
71 "", | |
72 "unit 5", | |
73 "Hollywood", "CA", | |
74 "91601", | |
75 "US", | |
76 "12345678910", | |
77 "01987654321"); | |
78 string16 summary2 = profile2.PreviewSummary(); | 43 string16 summary2 = profile2.PreviewSummary(); |
79 EXPECT_EQ(string16(ASCIIToUTF16("Morrison")), summary2); | 44 EXPECT_EQ(string16(ASCIIToUTF16("Morrison")), summary2); |
80 | 45 |
81 // Case 3: "<lastname>, <address>" | 46 // Case 3: "<lastname>, <address>" |
82 AutoFillProfile profile3(string16(), 0); | 47 AutoFillProfile profile3(string16(), 0); |
83 autofill_unittest::SetProfileInfo( | 48 autofill_unittest::SetProfileInfo(&profile3, "Billing", "", "Mitchell", |
84 &profile3, | 49 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
85 "Billing", | 50 "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); |
86 "", | |
87 "Mitchell", | |
88 "Morrison", | |
89 "johnwayne@me.xyz", | |
90 "Fox", | |
91 "123 Zoo St.", | |
92 "unit 5", | |
93 "Hollywood", "CA", | |
94 "91601", | |
95 "US", | |
96 "12345678910", | |
97 "01987654321"); | |
98 string16 summary3 = profile3.PreviewSummary(); | 51 string16 summary3 = profile3.PreviewSummary(); |
99 EXPECT_EQ(string16(ASCIIToUTF16("Morrison, 123 Zoo St.")), summary3); | 52 EXPECT_EQ(string16(ASCIIToUTF16("Morrison, 123 Zoo St.")), summary3); |
100 | 53 |
101 // Case 4: "<firstname>" | 54 // Case 4: "<firstname>" |
102 AutoFillProfile profile4(string16(), 0); | 55 AutoFillProfile profile4(string16(), 0); |
103 autofill_unittest::SetProfileInfo( | 56 autofill_unittest::SetProfileInfo(&profile4, "Billing", "Marion", "Mitchell", |
104 &profile4, | 57 "", "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", "91601", |
105 "Billing", | 58 "US", "12345678910", "01987654321"); |
106 "Marion", | |
107 "Mitchell", | |
108 "", | |
109 "johnwayne@me.xyz", | |
110 "Fox", | |
111 "", | |
112 "unit 5", | |
113 "Hollywood", "CA", | |
114 "91601", | |
115 "US", | |
116 "12345678910", | |
117 "01987654321"); | |
118 string16 summary4 = profile4.PreviewSummary(); | 59 string16 summary4 = profile4.PreviewSummary(); |
119 EXPECT_EQ(string16(ASCIIToUTF16("Marion")), summary4); | 60 EXPECT_EQ(string16(ASCIIToUTF16("Marion")), summary4); |
120 | 61 |
121 // Case 5: "<firstname>, <address>" | 62 // Case 5: "<firstname>, <address>" |
122 AutoFillProfile profile5(string16(), 0); | 63 AutoFillProfile profile5(string16(), 0); |
123 autofill_unittest::SetProfileInfo( | 64 autofill_unittest::SetProfileInfo(&profile5, "Billing", "Marion", "Mitchell", |
124 &profile5, | 65 "", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
125 "Billing", | 66 "91601", "US", "12345678910", "01987654321"); |
126 "Marion", | |
127 "Mitchell", | |
128 "", | |
129 "johnwayne@me.xyz", | |
130 "Fox", | |
131 "123 Zoo St.", | |
132 "unit 5", | |
133 "Hollywood", "CA", | |
134 "91601", | |
135 "US", | |
136 "12345678910", | |
137 "01987654321"); | |
138 string16 summary5 = profile5.PreviewSummary(); | 67 string16 summary5 = profile5.PreviewSummary(); |
139 EXPECT_EQ(string16(ASCIIToUTF16("Marion, 123 Zoo St.")), summary5); | 68 EXPECT_EQ(string16(ASCIIToUTF16("Marion, 123 Zoo St.")), summary5); |
140 | 69 |
141 // Case 6: "<firstname> <lastname>" | 70 // Case 6: "<firstname> <lastname>" |
142 AutoFillProfile profile6(string16(), 0); | 71 AutoFillProfile profile6(string16(), 0); |
143 autofill_unittest::SetProfileInfo( | 72 autofill_unittest::SetProfileInfo(&profile6, "Billing", "Marion", "Mitchell", |
144 &profile6, | 73 "Morrison", "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", |
145 "Billing", | 74 "91601", "US", "12345678910", "01987654321"); |
146 "Marion", | |
147 "Mitchell", | |
148 "Morrison", | |
149 "johnwayne@me.xyz", | |
150 "Fox", | |
151 "", | |
152 "unit 5", | |
153 "Hollywood", "CA", | |
154 "91601", | |
155 "US", | |
156 "12345678910", | |
157 "01987654321"); | |
158 string16 summary6 = profile6.PreviewSummary(); | 75 string16 summary6 = profile6.PreviewSummary(); |
159 EXPECT_EQ(string16(ASCIIToUTF16("Marion Morrison")), summary6); | 76 EXPECT_EQ(string16(ASCIIToUTF16("Marion Morrison")), summary6); |
160 | 77 |
161 // Case 7: "<firstname> <lastname>, <address>" | 78 // Case 7: "<firstname> <lastname>, <address>" |
162 AutoFillProfile profile7(string16(), 0); | 79 AutoFillProfile profile7(string16(), 0); |
163 autofill_unittest::SetProfileInfo( | 80 autofill_unittest::SetProfileInfo(&profile7, "Billing", "Marion", "Mitchell", |
164 &profile7, | 81 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
165 "Billing", | 82 "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); |
166 "Marion", | |
167 "Mitchell", | |
168 "Morrison", | |
169 "johnwayne@me.xyz", | |
170 "Fox", | |
171 "123 Zoo St.", | |
172 "unit 5", | |
173 "Hollywood", "CA", | |
174 "91601", | |
175 "US", | |
176 "12345678910", | |
177 "01987654321"); | |
178 string16 summary7 = profile7.PreviewSummary(); | 83 string16 summary7 = profile7.PreviewSummary(); |
179 EXPECT_EQ(string16(ASCIIToUTF16("Marion Morrison, 123 Zoo St.")), summary7); | 84 EXPECT_EQ(string16(ASCIIToUTF16("Marion Morrison, 123 Zoo St.")), summary7); |
180 } | 85 } |
181 | 86 |
| 87 TEST(AutoFillProfileTest, IsSubsetOf) { |
| 88 scoped_ptr<AutoFillProfile> a, b; |
| 89 |
| 90 // |a| is a subset of |b|. |
| 91 a.reset(new AutoFillProfile); |
| 92 b.reset(new AutoFillProfile); |
| 93 autofill_unittest::SetProfileInfo(a.get(), "label1", "Thomas", NULL, |
| 94 "Jefferson", "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, |
| 95 NULL, NULL, NULL, NULL); |
| 96 autofill_unittest::SetProfileInfo(b.get(), "label2", "Thomas", NULL, |
| 97 "Jefferson", "declaration_guy@gmail.com", "United States Government", |
| 98 "Monticello", NULL, "Charlottesville", "Virginia", "22902", NULL, NULL, |
| 99 NULL); |
| 100 EXPECT_TRUE(a->IsSubsetOf(*b)); |
| 101 |
| 102 // |b| is not a subset of |a|. |
| 103 EXPECT_FALSE(b->IsSubsetOf(*a)); |
| 104 |
| 105 // |a| is a subset of |a|. |
| 106 EXPECT_TRUE(a->IsSubsetOf(*a)); |
| 107 |
| 108 // One field in |b| is different. |
| 109 a.reset(new AutoFillProfile); |
| 110 b.reset(new AutoFillProfile); |
| 111 autofill_unittest::SetProfileInfo(a.get(), "label1", "Thomas", NULL, |
| 112 "Jefferson", "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, |
| 113 NULL, NULL, NULL, NULL); |
| 114 autofill_unittest::SetProfileInfo(a.get(), "label2", "Thomas", NULL, |
| 115 "Adams", "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, |
| 116 NULL, NULL, NULL, NULL); |
| 117 EXPECT_FALSE(a->IsSubsetOf(*b)); |
| 118 } |
| 119 |
| 120 TEST(AutoFillProfileTest, IntersectionOfTypesHasEqualValues) { |
| 121 scoped_ptr<AutoFillProfile> a, b; |
| 122 |
| 123 // Intersection of types contains the fields NAME_FIRST, NAME_LAST, |
| 124 // EMAIL_ADDRESS. The values of these field types are equal between the two |
| 125 // profiles. |
| 126 a.reset(new AutoFillProfile); |
| 127 b.reset(new AutoFillProfile); |
| 128 autofill_unittest::SetProfileInfo(a.get(), "label1", "Thomas", NULL, |
| 129 "Jefferson", "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, |
| 130 NULL, NULL, "12134759123", "19384284720"); |
| 131 autofill_unittest::SetProfileInfo(b.get(), "label2", "Thomas", NULL, |
| 132 "Jefferson", "declaration_guy@gmail.com", "United States Government", |
| 133 "Monticello", NULL, "Charlottesville", "Virginia", "22902", NULL, NULL, |
| 134 NULL); |
| 135 EXPECT_TRUE(a->IntersectionOfTypesHasEqualValues(*b)); |
| 136 |
| 137 // Intersection of types contains the fields NAME_FIRST, NAME_LAST, |
| 138 // EMAIL_ADDRESS. The value of EMAIL_ADDRESS differs between the two profiles. |
| 139 a.reset(new AutoFillProfile); |
| 140 b.reset(new AutoFillProfile); |
| 141 autofill_unittest::SetProfileInfo(a.get(), "label1", "Thomas", NULL, |
| 142 "Jefferson", "poser@yahoo.com", NULL, NULL, NULL, NULL, NULL, |
| 143 NULL, NULL, "12134759123", "19384284720"); |
| 144 autofill_unittest::SetProfileInfo(b.get(), "label2", "Thomas", NULL, |
| 145 "Jefferson", "declaration_guy@gmail.com", "United States Government", |
| 146 "Monticello", NULL, "Charlottesville", "Virginia", "22902", NULL, NULL, |
| 147 NULL); |
| 148 EXPECT_FALSE(a->IntersectionOfTypesHasEqualValues(*b)); |
| 149 |
| 150 // Intersection of types is empty. |
| 151 a.reset(new AutoFillProfile); |
| 152 b.reset(new AutoFillProfile); |
| 153 autofill_unittest::SetProfileInfo(a.get(), "label1", "Thomas", NULL, |
| 154 "Jefferson", "poser@yahoo.com", NULL, NULL, NULL, NULL, NULL, |
| 155 NULL, NULL, "12134759123", "19384284720"); |
| 156 autofill_unittest::SetProfileInfo(b.get(), "label2", NULL, NULL, NULL, NULL, |
| 157 "United States Government", "Monticello", NULL, "Charlottesville", |
| 158 "Virginia", "22902", NULL, NULL, NULL); |
| 159 EXPECT_FALSE(a->IntersectionOfTypesHasEqualValues(*b)); |
| 160 } |
| 161 |
| 162 TEST(AutoFillProfileTest, MergeWith) { |
| 163 scoped_ptr<AutoFillProfile> a, b; |
| 164 |
| 165 // Merge |b| into |a|. |
| 166 a.reset(new AutoFillProfile); |
| 167 b.reset(new AutoFillProfile); |
| 168 autofill_unittest::SetProfileInfo(a.get(), "label1", "Jimmy", NULL, |
| 169 NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 170 NULL, NULL, "12134759123", "19384284720"); |
| 171 autofill_unittest::SetProfileInfo(b.get(), "label2", "James", NULL, |
| 172 "Madison", "constitutionalist@gmail.com", "United States Government", |
| 173 "Monticello", NULL, "Charlottesville", "Virginia", "22902", NULL, NULL, |
| 174 NULL); |
| 175 AutoFillProfile expected_b(*b); |
| 176 a->MergeWith(*b); |
| 177 |
| 178 AutoFillProfile expected_a; |
| 179 autofill_unittest::SetProfileInfo(&expected_a, "label1", "Jimmy", NULL, |
| 180 "Madison", "constitutionalist@gmail.com", "United States Government", |
| 181 "Monticello", NULL, "Charlottesville", "Virginia", "22902", NULL, |
| 182 "12134759123", "19384284720"); |
| 183 EXPECT_EQ(expected_a, *a); |
| 184 EXPECT_EQ(expected_b, *b); |
| 185 } |
| 186 |
182 } // namespace | 187 } // namespace |
183 | 188 |
OLD | NEW |