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

Side by Side Diff: chrome/browser/autofill/autofill_profile_unittest.cc

Issue 7892048: Autofill: Remove fax number completely. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment fix. Created 9 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/autofill/autofill_profile.cc ('k') | chrome/browser/autofill/autofill_type.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/memory/scoped_vector.h" 7 #include "base/memory/scoped_vector.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 23 matching lines...) Expand all
34 // Empty profile - nothing to update. 34 // Empty profile - nothing to update.
35 EXPECT_FALSE(UpdateProfileLabel(&profile0)); 35 EXPECT_FALSE(UpdateProfileLabel(&profile0));
36 string16 summary0 = profile0.Label(); 36 string16 summary0 = profile0.Label();
37 EXPECT_EQ(string16(), summary0); 37 EXPECT_EQ(string16(), summary0);
38 38
39 // Case 0a/empty name and address, so the first two fields of the rest of the 39 // Case 0a/empty name and address, so the first two fields of the rest of the
40 // data is used: "Hollywood, CA" 40 // data is used: "Hollywood, CA"
41 AutofillProfile profile00; 41 AutofillProfile profile00;
42 autofill_test::SetProfileInfo(&profile00, "", "Mitchell", "", 42 autofill_test::SetProfileInfo(&profile00, "", "Mitchell", "",
43 "johnwayne@me.xyz", "Fox", "", "", "Hollywood", "CA", "91601", "US", 43 "johnwayne@me.xyz", "Fox", "", "", "Hollywood", "CA", "91601", "US",
44 "16505678910", "78127654321"); 44 "16505678910");
45 EXPECT_TRUE(UpdateProfileLabel(&profile00)); 45 EXPECT_TRUE(UpdateProfileLabel(&profile00));
46 string16 summary00 = profile00.Label(); 46 string16 summary00 = profile00.Label();
47 EXPECT_EQ(ASCIIToUTF16("Hollywood, CA"), summary00); 47 EXPECT_EQ(ASCIIToUTF16("Hollywood, CA"), summary00);
48 48
49 // Case 1: "<address>" without line 2. 49 // Case 1: "<address>" without line 2.
50 AutofillProfile profile1; 50 AutofillProfile profile1;
51 autofill_test::SetProfileInfo(&profile1, "", "Mitchell", "", 51 autofill_test::SetProfileInfo(&profile1, "", "Mitchell", "",
52 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "", "Hollywood", "CA", 52 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "", "Hollywood", "CA",
53 "91601", "US", "16505678910", "78127654321"); 53 "91601", "US", "16505678910");
54 EXPECT_TRUE(UpdateProfileLabel(&profile1)); 54 EXPECT_TRUE(UpdateProfileLabel(&profile1));
55 string16 summary1 = profile1.Label(); 55 string16 summary1 = profile1.Label();
56 EXPECT_EQ(ASCIIToUTF16("123 Zoo St., Hollywood"), summary1); 56 EXPECT_EQ(ASCIIToUTF16("123 Zoo St., Hollywood"), summary1);
57 57
58 // Case 1a: "<address>" with line 2. 58 // Case 1a: "<address>" with line 2.
59 AutofillProfile profile1a; 59 AutofillProfile profile1a;
60 autofill_test::SetProfileInfo(&profile1a, "", "Mitchell", "", 60 autofill_test::SetProfileInfo(&profile1a, "", "Mitchell", "",
61 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", 61 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
62 "91601", "US", "16505678910", "78127654321"); 62 "91601", "US", "16505678910");
63 EXPECT_TRUE(UpdateProfileLabel(&profile1a)); 63 EXPECT_TRUE(UpdateProfileLabel(&profile1a));
64 string16 summary1a = profile1a.Label(); 64 string16 summary1a = profile1a.Label();
65 EXPECT_EQ(ASCIIToUTF16("123 Zoo St., unit 5"), summary1a); 65 EXPECT_EQ(ASCIIToUTF16("123 Zoo St., unit 5"), summary1a);
66 66
67 // Case 2: "<lastname>" 67 // Case 2: "<lastname>"
68 AutofillProfile profile2; 68 AutofillProfile profile2;
69 autofill_test::SetProfileInfo(&profile2, "", "Mitchell", 69 autofill_test::SetProfileInfo(&profile2, "", "Mitchell",
70 "Morrison", "johnwayne@me.xyz", "Fox", "", "", "Hollywood", "CA", 70 "Morrison", "johnwayne@me.xyz", "Fox", "", "", "Hollywood", "CA",
71 "91601", "US", "16505678910", "78127654321"); 71 "91601", "US", "16505678910");
72 EXPECT_TRUE(UpdateProfileLabel(&profile2)); 72 EXPECT_TRUE(UpdateProfileLabel(&profile2));
73 string16 summary2 = profile2.Label(); 73 string16 summary2 = profile2.Label();
74 // Summary does include full name which is empty if the first name is empty. 74 // Summary does include full name which is empty if the first name is empty.
75 EXPECT_EQ(ASCIIToUTF16("Hollywood, CA"), summary2); 75 EXPECT_EQ(ASCIIToUTF16("Hollywood, CA"), summary2);
76 76
77 // Case 3: "<lastname>, <address>" 77 // Case 3: "<lastname>, <address>"
78 AutofillProfile profile3; 78 AutofillProfile profile3;
79 autofill_test::SetProfileInfo(&profile3, "", "Mitchell", 79 autofill_test::SetProfileInfo(&profile3, "", "Mitchell",
80 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "", 80 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "",
81 "Hollywood", "CA", "91601", "US", "16505678910", "78127654321"); 81 "Hollywood", "CA", "91601", "US", "16505678910");
82 EXPECT_TRUE(UpdateProfileLabel(&profile3)); 82 EXPECT_TRUE(UpdateProfileLabel(&profile3));
83 string16 summary3 = profile3.Label(); 83 string16 summary3 = profile3.Label();
84 EXPECT_EQ(ASCIIToUTF16("123 Zoo St., Hollywood"), summary3); 84 EXPECT_EQ(ASCIIToUTF16("123 Zoo St., Hollywood"), summary3);
85 85
86 // Case 4: "<firstname>" 86 // Case 4: "<firstname>"
87 AutofillProfile profile4; 87 AutofillProfile profile4;
88 autofill_test::SetProfileInfo(&profile4, "Marion", "Mitchell", "", 88 autofill_test::SetProfileInfo(&profile4, "Marion", "Mitchell", "",
89 "johnwayne@me.xyz", "Fox", "", "", "Hollywood", "CA", "91601", "US", 89 "johnwayne@me.xyz", "Fox", "", "", "Hollywood", "CA", "91601", "US",
90 "16505678910", "01987654321"); 90 "16505678910");
91 EXPECT_TRUE(UpdateProfileLabel(&profile4)); 91 EXPECT_TRUE(UpdateProfileLabel(&profile4));
92 string16 summary4 = profile4.Label(); 92 string16 summary4 = profile4.Label();
93 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell, Hollywood"), summary4); 93 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell, Hollywood"), summary4);
94 94
95 // Case 5: "<firstname>, <address>" 95 // Case 5: "<firstname>, <address>"
96 AutofillProfile profile5; 96 AutofillProfile profile5;
97 autofill_test::SetProfileInfo(&profile5, "Marion", "Mitchell", "", 97 autofill_test::SetProfileInfo(&profile5, "Marion", "Mitchell", "",
98 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", 98 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
99 "91601", "US", "16505678910", "78127654321"); 99 "91601", "US", "16505678910");
100 EXPECT_TRUE(UpdateProfileLabel(&profile5)); 100 EXPECT_TRUE(UpdateProfileLabel(&profile5));
101 string16 summary5 = profile5.Label(); 101 string16 summary5 = profile5.Label();
102 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell, 123 Zoo St."), summary5); 102 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell, 123 Zoo St."), summary5);
103 103
104 // Case 6: "<firstname> <lastname>" 104 // Case 6: "<firstname> <lastname>"
105 AutofillProfile profile6; 105 AutofillProfile profile6;
106 autofill_test::SetProfileInfo(&profile6, "Marion", "Mitchell", 106 autofill_test::SetProfileInfo(&profile6, "Marion", "Mitchell",
107 "Morrison", "johnwayne@me.xyz", "Fox", "", "", "Hollywood", "CA", 107 "Morrison", "johnwayne@me.xyz", "Fox", "", "", "Hollywood", "CA",
108 "91601", "US", "16505678910", "78127654321"); 108 "91601", "US", "16505678910");
109 EXPECT_TRUE(UpdateProfileLabel(&profile6)); 109 EXPECT_TRUE(UpdateProfileLabel(&profile6));
110 string16 summary6 = profile6.Label(); 110 string16 summary6 = profile6.Label();
111 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell Morrison, Hollywood"), 111 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell Morrison, Hollywood"),
112 summary6); 112 summary6);
113 113
114 // Case 7: "<firstname> <lastname>, <address>" 114 // Case 7: "<firstname> <lastname>, <address>"
115 AutofillProfile profile7; 115 AutofillProfile profile7;
116 autofill_test::SetProfileInfo(&profile7, "Marion", "Mitchell", 116 autofill_test::SetProfileInfo(&profile7, "Marion", "Mitchell",
117 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", 117 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5",
118 "Hollywood", "CA", "91601", "US", "16505678910", "78127654321"); 118 "Hollywood", "CA", "91601", "US", "16505678910");
119 EXPECT_TRUE(UpdateProfileLabel(&profile7)); 119 EXPECT_TRUE(UpdateProfileLabel(&profile7));
120 string16 summary7 = profile7.Label(); 120 string16 summary7 = profile7.Label();
121 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell Morrison, 123 Zoo St."), 121 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell Morrison, 123 Zoo St."),
122 summary7); 122 summary7);
123 123
124 // Case 7a: "<firstname> <lastname>, <address>" - same as #7, except for 124 // Case 7a: "<firstname> <lastname>, <address>" - same as #7, except for
125 // e-mail. 125 // e-mail.
126 AutofillProfile profile7a; 126 AutofillProfile profile7a;
127 autofill_test::SetProfileInfo(&profile7a, "Marion", "Mitchell", 127 autofill_test::SetProfileInfo(&profile7a, "Marion", "Mitchell",
128 "Morrison", "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", 128 "Morrison", "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5",
129 "Hollywood", "CA", "91601", "US", "16505678910", "78127654321"); 129 "Hollywood", "CA", "91601", "US", "16505678910");
130 std::vector<AutofillProfile*> profiles; 130 std::vector<AutofillProfile*> profiles;
131 profiles.push_back(&profile7); 131 profiles.push_back(&profile7);
132 profiles.push_back(&profile7a); 132 profiles.push_back(&profile7a);
133 EXPECT_TRUE(AutofillProfile::AdjustInferredLabels(&profiles)); 133 EXPECT_TRUE(AutofillProfile::AdjustInferredLabels(&profiles));
134 summary7 = profile7.Label(); 134 summary7 = profile7.Label();
135 string16 summary7a = profile7a.Label(); 135 string16 summary7a = profile7a.Label();
136 EXPECT_EQ(ASCIIToUTF16( 136 EXPECT_EQ(ASCIIToUTF16(
137 "Marion Mitchell Morrison, 123 Zoo St., johnwayne@me.xyz"), summary7); 137 "Marion Mitchell Morrison, 123 Zoo St., johnwayne@me.xyz"), summary7);
138 EXPECT_EQ(ASCIIToUTF16( 138 EXPECT_EQ(ASCIIToUTF16(
139 "Marion Mitchell Morrison, 123 Zoo St., marion@me.xyz"), summary7a); 139 "Marion Mitchell Morrison, 123 Zoo St., marion@me.xyz"), summary7a);
140 } 140 }
141 141
142 TEST_F(AutofillProfileTest, AdjustInferredLabels) { 142 TEST_F(AutofillProfileTest, AdjustInferredLabels) {
143 std::vector<AutofillProfile*> profiles; 143 std::vector<AutofillProfile*> profiles;
144 profiles.push_back(new AutofillProfile); 144 profiles.push_back(new AutofillProfile);
145 autofill_test::SetProfileInfo( 145 autofill_test::SetProfileInfo(
146 profiles[0], 146 profiles[0],
147 "John", 147 "John",
148 "", 148 "",
149 "Doe", 149 "Doe",
150 "johndoe@hades.com", 150 "johndoe@hades.com",
151 "Underworld", 151 "Underworld",
152 "666 Erebus St.", 152 "666 Erebus St.",
153 "", 153 "",
154 "Elysium", "CA", 154 "Elysium", "CA",
155 "91111", 155 "91111",
156 "US", 156 "US",
157 "16502111111", 157 "16502111111");
158 "16502222222");
159 profiles.push_back(new AutofillProfile); 158 profiles.push_back(new AutofillProfile);
160 autofill_test::SetProfileInfo( 159 autofill_test::SetProfileInfo(
161 profiles[1], 160 profiles[1],
162 "Jane", 161 "Jane",
163 "", 162 "",
164 "Doe", 163 "Doe",
165 "janedoe@tertium.com", 164 "janedoe@tertium.com",
166 "Pluto Inc.", 165 "Pluto Inc.",
167 "123 Letha Shore.", 166 "123 Letha Shore.",
168 "", 167 "",
169 "Dis", "CA", 168 "Dis", "CA",
170 "91222", 169 "91222",
171 "US", 170 "US",
172 "12345678910", 171 "12345678910");
173 "01987654321");
174 // As labels are empty they are adjusted the first time. 172 // As labels are empty they are adjusted the first time.
175 EXPECT_TRUE(AutofillProfile::AdjustInferredLabels(&profiles)); 173 EXPECT_TRUE(AutofillProfile::AdjustInferredLabels(&profiles));
176 // No need to adjust them anymore. 174 // No need to adjust them anymore.
177 EXPECT_FALSE(AutofillProfile::AdjustInferredLabels(&profiles)); 175 EXPECT_FALSE(AutofillProfile::AdjustInferredLabels(&profiles));
178 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St."), 176 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St."),
179 profiles[0]->Label()); 177 profiles[0]->Label());
180 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), 178 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."),
181 profiles[1]->Label()); 179 profiles[1]->Label());
182 180
183 profiles.push_back(new AutofillProfile); 181 profiles.push_back(new AutofillProfile);
184 autofill_test::SetProfileInfo( 182 autofill_test::SetProfileInfo(
185 profiles[2], 183 profiles[2],
186 "John", 184 "John",
187 "", 185 "",
188 "Doe", 186 "Doe",
189 "johndoe@tertium.com", 187 "johndoe@tertium.com",
190 "Underworld", 188 "Underworld",
191 "666 Erebus St.", 189 "666 Erebus St.",
192 "", 190 "",
193 "Elysium", "CA", 191 "Elysium", "CA",
194 "91111", 192 "91111",
195 "US", 193 "US",
196 "16502111111", 194 "16502111111");
197 "16502222222");
198 EXPECT_TRUE(AutofillProfile::AdjustInferredLabels(&profiles)); 195 EXPECT_TRUE(AutofillProfile::AdjustInferredLabels(&profiles));
199 196
200 // Profile 0 and 2 inferred label now includes an e-mail. 197 // Profile 0 and 2 inferred label now includes an e-mail.
201 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@hades.com"), 198 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@hades.com"),
202 profiles[0]->Label()); 199 profiles[0]->Label());
203 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), 200 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."),
204 profiles[1]->Label()); 201 profiles[1]->Label());
205 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@tertium.com"), 202 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@tertium.com"),
206 profiles[2]->Label()); 203 profiles[2]->Label());
207 204
208 delete profiles[2]; 205 delete profiles[2];
209 profiles.pop_back(); 206 profiles.pop_back();
210 207
211 profiles.push_back(new AutofillProfile); 208 profiles.push_back(new AutofillProfile);
212 autofill_test::SetProfileInfo( 209 autofill_test::SetProfileInfo(
213 profiles[2], 210 profiles[2],
214 "John", 211 "John",
215 "", 212 "",
216 "Doe", 213 "Doe",
217 "johndoe@hades.com", 214 "johndoe@hades.com",
218 "Underworld", 215 "Underworld",
219 "666 Erebus St.", 216 "666 Erebus St.",
220 "", 217 "",
221 "Elysium", "CA", 218 "Elysium", "CO", // State is different
222 "91111", 219 "91111",
223 "US", 220 "US",
224 "16502111111", 221 "16502111111");
225 "16503333333"); // Fax is different
226 222
227 EXPECT_TRUE(AutofillProfile::AdjustInferredLabels(&profiles)); 223 EXPECT_TRUE(AutofillProfile::AdjustInferredLabels(&profiles));
228 224
229 // Profile 0 and 2 inferred label now includes a fax number. 225 // Profile 0 and 2 inferred label now includes a state.
230 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., fax:#16502222222"), 226 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CA"),
231 profiles[0]->Label()); 227 profiles[0]->Label());
232 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), 228 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."),
233 profiles[1]->Label()); 229 profiles[1]->Label());
234 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., fax:#16503333333"), 230 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO"),
235 profiles[2]->Label()); 231 profiles[2]->Label());
236 232
237 profiles.push_back(new AutofillProfile); 233 profiles.push_back(new AutofillProfile);
238 autofill_test::SetProfileInfo( 234 autofill_test::SetProfileInfo(
239 profiles[3], 235 profiles[3],
240 "John", 236 "John",
241 "", 237 "",
242 "Doe", 238 "Doe",
243 "johndoe@hades.com", 239 "johndoe@hades.com",
244 "Underworld", 240 "Underworld",
245 "666 Erebus St.", 241 "666 Erebus St.",
246 "", 242 "",
247 "Elysium", "CA", 243 "Elysium", "CO", // State is different for some.
248 "91111", 244 "91111",
249 "US", 245 "US",
250 "16504444444", // Phone is different for some. 246 "16504444444"); // Phone is different for some.
251 "16503333333"); // Fax is different for some.
252 247
253 EXPECT_TRUE(AutofillProfile::AdjustInferredLabels(&profiles)); 248 EXPECT_TRUE(AutofillProfile::AdjustInferredLabels(&profiles));
254 249
255 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., 16502111111," 250 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CA"),
256 " fax:#16502222222"),
257 profiles[0]->Label()); 251 profiles[0]->Label());
258 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), 252 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."),
259 profiles[1]->Label()); 253 profiles[1]->Label());
260 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., 16502111111," 254 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, 16502111111"),
261 " fax:#16503333333"),
262 profiles[2]->Label()); 255 profiles[2]->Label());
263 // This one differs from other ones by unique phone, so no need for extra 256 // This one differs from other ones by unique phone, so no need for extra
264 // information. 257 // information.
265 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., 16504444444"), 258 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, 16504444444"),
266 profiles[3]->Label()); 259 profiles[3]->Label());
267 260
268 profiles.push_back(new AutofillProfile); 261 profiles.push_back(new AutofillProfile);
269 autofill_test::SetProfileInfo( 262 autofill_test::SetProfileInfo(
270 profiles[4], 263 profiles[4],
271 "John", 264 "John",
272 "", 265 "",
273 "Doe", 266 "Doe",
274 "johndoe@styx.com", // E-Mail is different for some. 267 "johndoe@styx.com", // E-Mail is different for some.
275 "Underworld", 268 "Underworld",
276 "666 Erebus St.", 269 "666 Erebus St.",
277 "", 270 "",
278 "Elysium", "CA", 271 "Elysium", "CO", // State is different for some.
279 "91111", 272 "91111",
280 "US", 273 "US",
281 "16504444444", // Phone is different for some. 274 "16504444444"); // Phone is different for some.
282 "16503333333"); // Fax is different for some.
283 275
284 EXPECT_TRUE(AutofillProfile::AdjustInferredLabels(&profiles)); 276 EXPECT_TRUE(AutofillProfile::AdjustInferredLabels(&profiles));
285 277
286 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@hades.com," 278 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CA"),
287 " 16502111111, fax:#16502222222"),
288 profiles[0]->Label()); 279 profiles[0]->Label());
289 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), 280 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."),
290 profiles[1]->Label()); 281 profiles[1]->Label());
291 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@hades.com," 282 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, johndoe@hades.com,"
292 " 16502111111, fax:#16503333333"), 283 " 16502111111"),
293 profiles[2]->Label()); 284 profiles[2]->Label());
294 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@hades.com," 285 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, johndoe@hades.com,"
295 " 16504444444, fax:#16503333333"), 286 " 16504444444"),
296 profiles[3]->Label()); 287 profiles[3]->Label());
297 // This one differs from other ones by unique e-mail, so no need for extra 288 // This one differs from other ones by unique e-mail, so no need for extra
298 // information. 289 // information.
299 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@styx.com"), 290 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, johndoe@styx.com"),
300 profiles[4]->Label()); 291 profiles[4]->Label());
301 292
302 EXPECT_FALSE(AutofillProfile::AdjustInferredLabels(&profiles)); 293 EXPECT_FALSE(AutofillProfile::AdjustInferredLabels(&profiles));
303 294
304 // Clean up. 295 // Clean up.
305 STLDeleteContainerPointers(profiles.begin(), profiles.end()); 296 STLDeleteContainerPointers(profiles.begin(), profiles.end());
306 } 297 }
307 298
308 TEST_F(AutofillProfileTest, CreateInferredLabels) { 299 TEST_F(AutofillProfileTest, CreateInferredLabels) {
309 std::vector<AutofillProfile*> profiles; 300 std::vector<AutofillProfile*> profiles;
310 profiles.push_back(new AutofillProfile); 301 profiles.push_back(new AutofillProfile);
311 autofill_test::SetProfileInfo(profiles[0], 302 autofill_test::SetProfileInfo(profiles[0],
312 "John", 303 "John",
313 "", 304 "",
314 "Doe", 305 "Doe",
315 "johndoe@hades.com", 306 "johndoe@hades.com",
316 "Underworld", 307 "Underworld",
317 "666 Erebus St.", 308 "666 Erebus St.",
318 "", 309 "",
319 "Elysium", "CA", 310 "Elysium", "CA",
320 "91111", 311 "91111",
321 "US", 312 "US",
322 "16502111111", 313 "16502111111");
323 "16502222222");
324 profiles.push_back(new AutofillProfile); 314 profiles.push_back(new AutofillProfile);
325 autofill_test::SetProfileInfo(profiles[1], 315 autofill_test::SetProfileInfo(profiles[1],
326 "Jane", 316 "Jane",
327 "", 317 "",
328 "Doe", 318 "Doe",
329 "janedoe@tertium.com", 319 "janedoe@tertium.com",
330 "Pluto Inc.", 320 "Pluto Inc.",
331 "123 Letha Shore.", 321 "123 Letha Shore.",
332 "", 322 "",
333 "Dis", "CA", 323 "Dis", "CA",
334 "91222", 324 "91222",
335 "US", 325 "US",
336 "12345678910", 326 "12345678910");
337 "01987654321");
338 std::vector<string16> labels; 327 std::vector<string16> labels;
339 // Two fields at least - no filter. 328 // Two fields at least - no filter.
340 AutofillProfile::CreateInferredLabels(&profiles, NULL, UNKNOWN_TYPE, 2, 329 AutofillProfile::CreateInferredLabels(&profiles, NULL, UNKNOWN_TYPE, 2,
341 &labels); 330 &labels);
342 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St."), labels[0]); 331 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St."), labels[0]);
343 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); 332 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]);
344 333
345 // Three fields at least - no filter. 334 // Three fields at least - no filter.
346 AutofillProfile::CreateInferredLabels(&profiles, NULL, UNKNOWN_TYPE, 3, 335 AutofillProfile::CreateInferredLabels(&profiles, NULL, UNKNOWN_TYPE, 3,
347 &labels); 336 &labels);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 STLDeleteContainerPointers(profiles.begin(), profiles.end()); 403 STLDeleteContainerPointers(profiles.begin(), profiles.end());
415 } 404 }
416 405
417 // Test that we fall back to using the full name if there are no other 406 // Test that we fall back to using the full name if there are no other
418 // distinguishing fields, but only if it makes sense given the suggested fields. 407 // distinguishing fields, but only if it makes sense given the suggested fields.
419 TEST_F(AutofillProfileTest, CreateInferredLabelsFallsBackToFullName) { 408 TEST_F(AutofillProfileTest, CreateInferredLabelsFallsBackToFullName) {
420 ScopedVector<AutofillProfile> profiles; 409 ScopedVector<AutofillProfile> profiles;
421 profiles.push_back(new AutofillProfile); 410 profiles.push_back(new AutofillProfile);
422 autofill_test::SetProfileInfo(profiles[0], 411 autofill_test::SetProfileInfo(profiles[0],
423 "John", "", "Doe", "doe@example.com", "", 412 "John", "", "Doe", "doe@example.com", "",
424 "88 Nowhere Ave.", "", "", "", "", "", "", ""); 413 "88 Nowhere Ave.", "", "", "", "", "", "");
425 profiles.push_back(new AutofillProfile); 414 profiles.push_back(new AutofillProfile);
426 autofill_test::SetProfileInfo(profiles[1], 415 autofill_test::SetProfileInfo(profiles[1],
427 "Johnny", "K", "Doe", "doe@example.com", "", 416 "Johnny", "K", "Doe", "doe@example.com", "",
428 "88 Nowhere Ave.", "", "", "", "", "", "", ""); 417 "88 Nowhere Ave.", "", "", "", "", "", "");
429 418
430 // If the only name field in the suggested fields is the excluded field, we 419 // If the only name field in the suggested fields is the excluded field, we
431 // should not fall back to the full name as a distinguishing field. 420 // should not fall back to the full name as a distinguishing field.
432 std::vector<AutofillFieldType> suggested_fields; 421 std::vector<AutofillFieldType> suggested_fields;
433 suggested_fields.push_back(NAME_LAST); 422 suggested_fields.push_back(NAME_LAST);
434 suggested_fields.push_back(ADDRESS_HOME_LINE1); 423 suggested_fields.push_back(ADDRESS_HOME_LINE1);
435 suggested_fields.push_back(EMAIL_ADDRESS); 424 suggested_fields.push_back(EMAIL_ADDRESS);
436 std::vector<string16> labels; 425 std::vector<string16> labels;
437 AutofillProfile::CreateInferredLabels(&profiles.get(), &suggested_fields, 426 AutofillProfile::CreateInferredLabels(&profiles.get(), &suggested_fields,
438 NAME_LAST, 1, &labels); 427 NAME_LAST, 1, &labels);
439 ASSERT_EQ(2U, labels.size()); 428 ASSERT_EQ(2U, labels.size());
440 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave."), labels[0]); 429 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave."), labels[0]);
441 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave."), labels[1]); 430 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave."), labels[1]);
442 431
443 // Otherwise, we should. 432 // Otherwise, we should.
444 suggested_fields.push_back(NAME_FIRST); 433 suggested_fields.push_back(NAME_FIRST);
445 AutofillProfile::CreateInferredLabels(&profiles.get(), &suggested_fields, 434 AutofillProfile::CreateInferredLabels(&profiles.get(), &suggested_fields,
446 NAME_LAST, 1, &labels); 435 NAME_LAST, 1, &labels);
447 ASSERT_EQ(2U, labels.size()); 436 ASSERT_EQ(2U, labels.size());
448 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., John Doe"), labels[0]); 437 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., John Doe"), labels[0]);
449 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., Johnny K Doe"), labels[1]); 438 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., Johnny K Doe"), labels[1]);
450 } 439 }
451 440
452 // Test that we do not show duplicate fields in the labels. 441 // Test that we do not show duplicate fields in the labels.
453 TEST_F(AutofillProfileTest, CreateInferredLabelsNoDuplicatedFields) { 442 TEST_F(AutofillProfileTest, CreateInferredLabelsNoDuplicatedFields) {
454 ScopedVector<AutofillProfile> profiles; 443 ScopedVector<AutofillProfile> profiles;
455 profiles.push_back(new AutofillProfile); 444 profiles.push_back(new AutofillProfile);
456 autofill_test::SetProfileInfo(profiles[0], 445 autofill_test::SetProfileInfo(profiles[0],
457 "John", "", "Doe", "doe@example.com", "", 446 "John", "", "Doe", "doe@example.com", "",
458 "88 Nowhere Ave.", "", "", "", "", "", "", ""); 447 "88 Nowhere Ave.", "", "", "", "", "", "");
459 profiles.push_back(new AutofillProfile); 448 profiles.push_back(new AutofillProfile);
460 autofill_test::SetProfileInfo(profiles[1], 449 autofill_test::SetProfileInfo(profiles[1],
461 "John", "", "Doe", "dojo@example.com", "", 450 "John", "", "Doe", "dojo@example.com", "",
462 "88 Nowhere Ave.", "", "", "", "", "", "", ""); 451 "88 Nowhere Ave.", "", "", "", "", "", "");
463 452
464 // If the only name field in the suggested fields is the excluded field, we 453 // If the only name field in the suggested fields is the excluded field, we
465 // should not fall back to the full name as a distinguishing field. 454 // should not fall back to the full name as a distinguishing field.
466 std::vector<AutofillFieldType> suggested_fields; 455 std::vector<AutofillFieldType> suggested_fields;
467 suggested_fields.push_back(ADDRESS_HOME_LINE1); 456 suggested_fields.push_back(ADDRESS_HOME_LINE1);
468 suggested_fields.push_back(ADDRESS_BILLING_LINE1); 457 suggested_fields.push_back(ADDRESS_BILLING_LINE1);
469 suggested_fields.push_back(EMAIL_ADDRESS); 458 suggested_fields.push_back(EMAIL_ADDRESS);
470 std::vector<string16> labels; 459 std::vector<string16> labels;
471 AutofillProfile::CreateInferredLabels(&profiles.get(), &suggested_fields, 460 AutofillProfile::CreateInferredLabels(&profiles.get(), &suggested_fields,
472 UNKNOWN_TYPE, 2, &labels); 461 UNKNOWN_TYPE, 2, &labels);
473 ASSERT_EQ(2U, labels.size()); 462 ASSERT_EQ(2U, labels.size());
474 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., doe@example.com"), labels[0]); 463 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., doe@example.com"), labels[0]);
475 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., dojo@example.com"), labels[1]); 464 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., dojo@example.com"), labels[1]);
476 } 465 }
477 466
478 // Make sure that empty fields are not treated as distinguishing fields. 467 // Make sure that empty fields are not treated as distinguishing fields.
479 TEST_F(AutofillProfileTest, CreateInferredLabelsSkipsEmptyFields) { 468 TEST_F(AutofillProfileTest, CreateInferredLabelsSkipsEmptyFields) {
480 ScopedVector<AutofillProfile> profiles; 469 ScopedVector<AutofillProfile> profiles;
481 profiles.push_back(new AutofillProfile); 470 profiles.push_back(new AutofillProfile);
482 autofill_test::SetProfileInfo(profiles[0], 471 autofill_test::SetProfileInfo(profiles[0],
483 "John", "", "Doe", "doe@example.com", 472 "John", "", "Doe", "doe@example.com",
484 "Gogole", "", "", "", "", "", "", "", ""); 473 "Gogole", "", "", "", "", "", "", "");
485 profiles.push_back(new AutofillProfile); 474 profiles.push_back(new AutofillProfile);
486 autofill_test::SetProfileInfo(profiles[1], 475 autofill_test::SetProfileInfo(profiles[1],
487 "John", "", "Doe", "doe@example.com", 476 "John", "", "Doe", "doe@example.com",
488 "Ggoole", "", "", "", "", "", "", "", ""); 477 "Ggoole", "", "", "", "", "", "", "");
489 profiles.push_back(new AutofillProfile); 478 profiles.push_back(new AutofillProfile);
490 autofill_test::SetProfileInfo(profiles[2], 479 autofill_test::SetProfileInfo(profiles[2],
491 "John", "", "Doe", "john.doe@example.com", 480 "John", "", "Doe", "john.doe@example.com",
492 "Goolge", "", "", "", "", "", "", "", ""); 481 "Goolge", "", "", "", "", "", "", "");
493 482
494 std::vector<string16> labels; 483 std::vector<string16> labels;
495 AutofillProfile::CreateInferredLabels(&profiles.get(), NULL, UNKNOWN_TYPE, 3, 484 AutofillProfile::CreateInferredLabels(&profiles.get(), NULL, UNKNOWN_TYPE, 3,
496 &labels); 485 &labels);
497 ASSERT_EQ(3U, labels.size()); 486 ASSERT_EQ(3U, labels.size());
498 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Gogole"), labels[0]); 487 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Gogole"), labels[0]);
499 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Ggoole"), labels[1]); 488 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Ggoole"), labels[1]);
500 EXPECT_EQ(ASCIIToUTF16("John Doe, john.doe@example.com, Goolge"), labels[2]); 489 EXPECT_EQ(ASCIIToUTF16("John Doe, john.doe@example.com, Goolge"), labels[2]);
501 490
502 // A field must have a non-empty value for each profile to be considered a 491 // A field must have a non-empty value for each profile to be considered a
503 // distinguishing field. 492 // distinguishing field.
504 profiles[1]->SetInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("88 Nowhere Ave.")); 493 profiles[1]->SetInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("88 Nowhere Ave."));
505 AutofillProfile::CreateInferredLabels(&profiles.get(), NULL, UNKNOWN_TYPE, 1, 494 AutofillProfile::CreateInferredLabels(&profiles.get(), NULL, UNKNOWN_TYPE, 1,
506 &labels); 495 &labels);
507 ASSERT_EQ(3U, labels.size()); 496 ASSERT_EQ(3U, labels.size());
508 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Gogole"), labels[0]); 497 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Gogole"), labels[0]);
509 EXPECT_EQ(ASCIIToUTF16("John Doe, 88 Nowhere Ave., doe@example.com, Ggoole"), 498 EXPECT_EQ(ASCIIToUTF16("John Doe, 88 Nowhere Ave., doe@example.com, Ggoole"),
510 labels[1]) << labels[1]; 499 labels[1]) << labels[1];
511 EXPECT_EQ(ASCIIToUTF16("John Doe, john.doe@example.com"), labels[2]); 500 EXPECT_EQ(ASCIIToUTF16("John Doe, john.doe@example.com"), labels[2]);
512 } 501 }
513 502
514 TEST_F(AutofillProfileTest, IsSubsetOf) { 503 TEST_F(AutofillProfileTest, IsSubsetOf) {
515 scoped_ptr<AutofillProfile> a, b; 504 scoped_ptr<AutofillProfile> a, b;
516 505
517 // |a| is a subset of |b|. 506 // |a| is a subset of |b|.
518 a.reset(new AutofillProfile); 507 a.reset(new AutofillProfile);
519 b.reset(new AutofillProfile); 508 b.reset(new AutofillProfile);
520 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson", 509 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson",
521 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, 510 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
522 NULL, NULL); 511 NULL);
523 autofill_test::SetProfileInfo(b.get(), "Thomas", NULL, "Jefferson", 512 autofill_test::SetProfileInfo(b.get(), "Thomas", NULL, "Jefferson",
524 "declaration_guy@gmail.com", "United States Government", "Monticello", 513 "declaration_guy@gmail.com", "United States Government", "Monticello",
525 NULL, "Charlottesville", "Virginia", "22902", NULL, NULL, NULL); 514 NULL, "Charlottesville", "Virginia", "22902", NULL, NULL);
526 EXPECT_TRUE(a->IsSubsetOf(*b)); 515 EXPECT_TRUE(a->IsSubsetOf(*b));
527 516
528 // |b| is not a subset of |a|. 517 // |b| is not a subset of |a|.
529 EXPECT_FALSE(b->IsSubsetOf(*a)); 518 EXPECT_FALSE(b->IsSubsetOf(*a));
530 519
531 // |a| is a subset of |a|. 520 // |a| is a subset of |a|.
532 EXPECT_TRUE(a->IsSubsetOf(*a)); 521 EXPECT_TRUE(a->IsSubsetOf(*a));
533 522
534 // One field in |b| is different. 523 // One field in |b| is different.
535 a.reset(new AutofillProfile); 524 a.reset(new AutofillProfile);
536 b.reset(new AutofillProfile); 525 b.reset(new AutofillProfile);
537 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson", 526 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson",
538 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, 527 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
539 NULL, NULL); 528 NULL);
540 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Adams", 529 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Adams",
541 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, 530 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
542 NULL, NULL); 531 NULL);
543 EXPECT_FALSE(a->IsSubsetOf(*b)); 532 EXPECT_FALSE(a->IsSubsetOf(*b));
544 } 533 }
545 534
546 TEST_F(AutofillProfileTest, IntersectionOfTypesHasEqualValues) { 535 TEST_F(AutofillProfileTest, IntersectionOfTypesHasEqualValues) {
547 scoped_ptr<AutofillProfile> a, b; 536 scoped_ptr<AutofillProfile> a, b;
548 537
549 // Intersection of types contains the fields NAME_FIRST, NAME_LAST, 538 // Intersection of types contains the fields NAME_FIRST, NAME_LAST,
550 // EMAIL_ADDRESS. The values of these field types are equal between the two 539 // EMAIL_ADDRESS. The values of these field types are equal between the two
551 // profiles. 540 // profiles.
552 a.reset(new AutofillProfile); 541 a.reset(new AutofillProfile);
553 b.reset(new AutofillProfile); 542 b.reset(new AutofillProfile);
554 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson", 543 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson",
555 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, 544 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
556 "12134759123", "19384284720"); 545 "12134759123");
557 autofill_test::SetProfileInfo(b.get(), "Thomas", NULL, "Jefferson", 546 autofill_test::SetProfileInfo(b.get(), "Thomas", NULL, "Jefferson",
558 "declaration_guy@gmail.com", "United States Government", "Monticello", 547 "declaration_guy@gmail.com", "United States Government", "Monticello",
559 NULL, "Charlottesville", "Virginia", "22902", NULL, NULL, NULL); 548 NULL, "Charlottesville", "Virginia", "22902", NULL, NULL);
560 EXPECT_TRUE(a->IntersectionOfTypesHasEqualValues(*b)); 549 EXPECT_TRUE(a->IntersectionOfTypesHasEqualValues(*b));
561 550
562 // Intersection of types contains the fields NAME_FIRST, NAME_LAST, 551 // Intersection of types contains the fields NAME_FIRST, NAME_LAST,
563 // EMAIL_ADDRESS. The value of EMAIL_ADDRESS differs between the two profiles. 552 // EMAIL_ADDRESS. The value of EMAIL_ADDRESS differs between the two profiles.
564 a.reset(new AutofillProfile); 553 a.reset(new AutofillProfile);
565 b.reset(new AutofillProfile); 554 b.reset(new AutofillProfile);
566 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson", 555 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson",
567 "poser@yahoo.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, 556 "poser@yahoo.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
568 "12134759123", "19384284720"); 557 "12134759123");
569 autofill_test::SetProfileInfo(b.get(), "Thomas", NULL, "Jefferson",\ 558 autofill_test::SetProfileInfo(b.get(), "Thomas", NULL, "Jefferson",\
570 "declaration_guy@gmail.com", "United States Government", "Monticello", 559 "declaration_guy@gmail.com", "United States Government", "Monticello",
571 NULL, "Charlottesville", "Virginia", "22902", NULL, NULL, NULL); 560 NULL, "Charlottesville", "Virginia", "22902", NULL, NULL);
572 EXPECT_FALSE(a->IntersectionOfTypesHasEqualValues(*b)); 561 EXPECT_FALSE(a->IntersectionOfTypesHasEqualValues(*b));
573 562
574 // Intersection of types is empty. 563 // Intersection of types is empty.
575 a.reset(new AutofillProfile); 564 a.reset(new AutofillProfile);
576 b.reset(new AutofillProfile); 565 b.reset(new AutofillProfile);
577 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson", 566 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson",
578 "poser@yahoo.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, 567 "poser@yahoo.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
579 "12134759123", "19384284720"); 568 "12134759123");
580 autofill_test::SetProfileInfo(b.get(), NULL, NULL, NULL, NULL, 569 autofill_test::SetProfileInfo(b.get(), NULL, NULL, NULL, NULL,
581 "United States Government", "Monticello", NULL, "Charlottesville", 570 "United States Government", "Monticello", NULL, "Charlottesville",
582 "Virginia", "22902", NULL, NULL, NULL); 571 "Virginia", "22902", NULL, NULL);
583 EXPECT_FALSE(a->IntersectionOfTypesHasEqualValues(*b)); 572 EXPECT_FALSE(a->IntersectionOfTypesHasEqualValues(*b));
584 } 573 }
585 574
586 TEST_F(AutofillProfileTest, MergeWith) { 575 TEST_F(AutofillProfileTest, MergeWith) {
587 scoped_ptr<AutofillProfile> a, b; 576 scoped_ptr<AutofillProfile> a, b;
588 577
589 // Merge |b| into |a|. 578 // Merge |b| into |a|.
590 a.reset(new AutofillProfile); 579 a.reset(new AutofillProfile);
591 b.reset(new AutofillProfile); 580 b.reset(new AutofillProfile);
592 autofill_test::SetProfileInfo(a.get(), "Jimmy", NULL, NULL, NULL, 581 autofill_test::SetProfileInfo(a.get(), "Jimmy", NULL, NULL, NULL,
593 NULL, NULL, NULL, NULL, NULL, NULL, NULL, "12134759123", "19384284720"); 582 NULL, NULL, NULL, NULL, NULL, NULL, NULL, "12134759123");
594 autofill_test::SetProfileInfo(b.get(), "James", NULL, "Madison", 583 autofill_test::SetProfileInfo(b.get(), "James", NULL, "Madison",
595 "constitutionalist@gmail.com", "United States Government", "Monticello", 584 "constitutionalist@gmail.com", "United States Government", "Monticello",
596 NULL, "Charlottesville", "Virginia", "22902", NULL, NULL, NULL); 585 NULL, "Charlottesville", "Virginia", "22902", NULL, NULL);
597 AutofillProfile expected_b(*b); 586 AutofillProfile expected_b(*b);
598 a->MergeWith(*b); 587 a->MergeWith(*b);
599 588
600 AutofillProfile expected_a; 589 AutofillProfile expected_a;
601 autofill_test::SetProfileInfo(&expected_a, "Jimmy", NULL, "Madison", 590 autofill_test::SetProfileInfo(&expected_a, "Jimmy", NULL, "Madison",
602 "constitutionalist@gmail.com", "United States Government", "Monticello", 591 "constitutionalist@gmail.com", "United States Government", "Monticello",
603 NULL, "Charlottesville", "Virginia", "22902", NULL, "12134759123", 592 NULL, "Charlottesville", "Virginia", "22902", NULL, "12134759123");
604 "19384284720");
605 EXPECT_EQ(0, expected_a.Compare(*a)); 593 EXPECT_EQ(0, expected_a.Compare(*a));
606 EXPECT_EQ(0, expected_b.Compare(*b)); 594 EXPECT_EQ(0, expected_b.Compare(*b));
607 } 595 }
608 596
609 TEST_F(AutofillProfileTest, AssignmentOperator){ 597 TEST_F(AutofillProfileTest, AssignmentOperator){
610 AutofillProfile a, b; 598 AutofillProfile a, b;
611 599
612 // Result of assignment should be logically equal to the original profile. 600 // Result of assignment should be logically equal to the original profile.
613 autofill_test::SetProfileInfo(&a, "Marion", "Mitchell", "Morrison", 601 autofill_test::SetProfileInfo(&a, "Marion", "Mitchell", "Morrison",
614 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", 602 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5",
615 "Hollywood", "CA", "91601", "US", "12345678910", 603 "Hollywood", "CA", "91601", "US",
616 "01987654321"); 604 "12345678910");
617 b = a; 605 b = a;
618 EXPECT_TRUE(a == b); 606 EXPECT_TRUE(a == b);
619 607
620 // Assignment to self should not change the profile value. 608 // Assignment to self should not change the profile value.
621 a = a; 609 a = a;
622 EXPECT_TRUE(a == b); 610 EXPECT_TRUE(a == b);
623 } 611 }
624 612
625 TEST_F(AutofillProfileTest, Copy) { 613 TEST_F(AutofillProfileTest, Copy) {
626 AutofillProfile a; 614 AutofillProfile a;
627 615
628 // Clone should be logically equal to the original. 616 // Clone should be logically equal to the original.
629 autofill_test::SetProfileInfo(&a, "Marion", "Mitchell", "Morrison", 617 autofill_test::SetProfileInfo(&a, "Marion", "Mitchell", "Morrison",
630 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", 618 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5",
631 "Hollywood", "CA", "91601", "US", "12345678910", 619 "Hollywood", "CA", "91601", "US",
632 "01987654321"); 620 "12345678910");
633 AutofillProfile b(a); 621 AutofillProfile b(a);
634 EXPECT_TRUE(a == b); 622 EXPECT_TRUE(a == b);
635 } 623 }
636 624
637 TEST_F(AutofillProfileTest, Compare) { 625 TEST_F(AutofillProfileTest, Compare) {
638 AutofillProfile a, b; 626 AutofillProfile a, b;
639 627
640 // Empty profiles are the same. 628 // Empty profiles are the same.
641 EXPECT_EQ(0, a.Compare(b)); 629 EXPECT_EQ(0, a.Compare(b));
642 630
643 // GUIDs don't count. 631 // GUIDs don't count.
644 a.set_guid(guid::GenerateGUID()); 632 a.set_guid(guid::GenerateGUID());
645 b.set_guid(guid::GenerateGUID()); 633 b.set_guid(guid::GenerateGUID());
646 EXPECT_EQ(0, a.Compare(b)); 634 EXPECT_EQ(0, a.Compare(b));
647 635
648 // Different values produce non-zero results. 636 // Different values produce non-zero results.
649 autofill_test::SetProfileInfo(&a, "Jimmy", NULL, NULL, NULL, 637 autofill_test::SetProfileInfo(&a, "Jimmy", NULL, NULL, NULL,
650 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); 638 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
651 autofill_test::SetProfileInfo(&b, "Ringo", NULL, NULL, NULL, 639 autofill_test::SetProfileInfo(&b, "Ringo", NULL, NULL, NULL,
652 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); 640 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
653 EXPECT_GT(0, a.Compare(b)); 641 EXPECT_GT(0, a.Compare(b));
654 EXPECT_LT(0, b.Compare(a)); 642 EXPECT_LT(0, b.Compare(a));
655 } 643 }
656 644
657 TEST_F(AutofillProfileTest, CountryCode) { 645 TEST_F(AutofillProfileTest, CountryCode) {
658 AutofillProfile profile; 646 AutofillProfile profile;
659 EXPECT_EQ(std::string(), profile.CountryCode()); 647 EXPECT_EQ(std::string(), profile.CountryCode());
660 648
661 profile.SetCountryCode("US"); 649 profile.SetCountryCode("US");
662 EXPECT_EQ("US", profile.CountryCode()); 650 EXPECT_EQ("US", profile.CountryCode());
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 // Delete values. 774 // Delete values.
787 set_values.clear(); 775 set_values.clear();
788 p.SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values); 776 p.SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values);
789 p.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &get_values); 777 p.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &get_values);
790 ASSERT_EQ(1UL, get_values.size()); 778 ASSERT_EQ(1UL, get_values.size());
791 EXPECT_EQ(string16(), get_values[0]); 779 EXPECT_EQ(string16(), get_values[0]);
792 780
793 // Expect regular |GetInfo| returns empty value. 781 // Expect regular |GetInfo| returns empty value.
794 EXPECT_EQ(string16(), p.GetInfo(PHONE_HOME_WHOLE_NUMBER)); 782 EXPECT_EQ(string16(), p.GetInfo(PHONE_HOME_WHOLE_NUMBER));
795 } 783 }
796
797 TEST_F(AutofillProfileTest, MultiValueFax) {
798 AutofillProfile p;
799 const string16 kJohnDoe(ASCIIToUTF16("4152112222"));
800 const string16 kJohnPDoe(ASCIIToUTF16("4153113333"));
801 std::vector<string16> set_values;
802 set_values.push_back(kJohnDoe);
803 set_values.push_back(kJohnPDoe);
804 p.SetMultiInfo(PHONE_FAX_WHOLE_NUMBER, set_values);
805
806 // Expect regular |GetInfo| returns the first element.
807 EXPECT_EQ(kJohnDoe, p.GetInfo(PHONE_FAX_WHOLE_NUMBER));
808
809 // Ensure that we get out what we put in.
810 std::vector<string16> get_values;
811 p.GetMultiInfo(PHONE_FAX_WHOLE_NUMBER, &get_values);
812 ASSERT_EQ(2UL, get_values.size());
813 EXPECT_EQ(kJohnDoe, get_values[0]);
814 EXPECT_EQ(kJohnPDoe, get_values[1]);
815
816 // Update the values.
817 AutofillProfile p2 = p;
818 EXPECT_EQ(0, p.Compare(p2));
819 EXPECT_EQ(0, p.CompareMulti(p2));
820 const string16 kNoOne(ASCIIToUTF16("4151110000"));
821 set_values[1] = kNoOne;
822 p.SetMultiInfo(PHONE_FAX_WHOLE_NUMBER, set_values);
823 p.GetMultiInfo(PHONE_FAX_WHOLE_NUMBER, &get_values);
824 ASSERT_EQ(2UL, get_values.size());
825 EXPECT_EQ(kJohnDoe, get_values[0]);
826 EXPECT_EQ(kNoOne, get_values[1]);
827 EXPECT_EQ(0, p.Compare(p2));
828 EXPECT_NE(0, p.CompareMulti(p2));
829
830 // Delete values.
831 set_values.clear();
832 p.SetMultiInfo(PHONE_FAX_WHOLE_NUMBER, set_values);
833 p.GetMultiInfo(PHONE_FAX_WHOLE_NUMBER, &get_values);
834 ASSERT_EQ(1UL, get_values.size());
835 EXPECT_EQ(string16(), get_values[0]);
836
837 // Expect regular |GetInfo| returns empty value.
838 EXPECT_EQ(string16(), p.GetInfo(PHONE_FAX_WHOLE_NUMBER));
839 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_profile.cc ('k') | chrome/browser/autofill/autofill_type.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698