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

Side by Side Diff: components/autofill/core/browser/autofill_profile_unittest.cc

Issue 2609703002: Remove ScopedVector from autofill. (Closed)
Patch Set: drop the using Created 3 years, 11 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 "components/autofill/core/browser/autofill_profile.h" 5 #include "components/autofill/core/browser/autofill_profile.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector>
10 11
11 #include "base/format_macros.h" 12 #include "base/format_macros.h"
12 #include "base/guid.h" 13 #include "base/guid.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/memory/scoped_vector.h" 15 #include "base/memory/ptr_util.h"
15 #include "base/stl_util.h" 16 #include "base/stl_util.h"
16 #include "base/strings/string16.h" 17 #include "base/strings/string16.h"
17 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
19 #include "components/autofill/core/browser/autofill_test_utils.h" 20 #include "components/autofill/core/browser/autofill_test_utils.h"
20 #include "components/autofill/core/browser/autofill_type.h" 21 #include "components/autofill/core/browser/autofill_type.h"
21 #include "components/autofill/core/browser/field_types.h" 22 #include "components/autofill/core/browser/field_types.h"
22 #include "components/autofill/core/common/autofill_constants.h" 23 #include "components/autofill/core/common/autofill_constants.h"
23 #include "components/autofill/core/common/form_field_data.h" 24 #include "components/autofill/core/common/form_field_data.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 }; 73 };
73 74
74 void SetupTestProfile(AutofillProfile& profile) { 75 void SetupTestProfile(AutofillProfile& profile) {
75 profile.set_guid(base::GenerateGUID()); 76 profile.set_guid(base::GenerateGUID());
76 profile.set_origin(kSettingsOrigin); 77 profile.set_origin(kSettingsOrigin);
77 test::SetProfileInfo(&profile, "Marion", "Mitchell", "Morrison", 78 test::SetProfileInfo(&profile, "Marion", "Mitchell", "Morrison",
78 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", 79 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5",
79 "Hollywood", "CA", "91601", "US", "12345678910"); 80 "Hollywood", "CA", "91601", "US", "12345678910");
80 } 81 }
81 82
83 std::vector<AutofillProfile*> ToRawPointerVector(
84 const std::vector<std::unique_ptr<AutofillProfile>>& list) {
85 std::vector<AutofillProfile*> result;
86 for (const auto& item : list)
87 result.push_back(item.get());
88 return result;
89 }
90
82 } // namespace 91 } // namespace
83 92
84 // Tests different possibilities for summary string generation. 93 // Tests different possibilities for summary string generation.
85 // Based on existence of first name, last name, and address line 1. 94 // Based on existence of first name, last name, and address line 1.
86 TEST(AutofillProfileTest, PreviewSummaryString) { 95 TEST(AutofillProfileTest, PreviewSummaryString) {
87 // Case 0/null: "" 96 // Case 0/null: ""
88 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com/"); 97 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com/");
89 // Empty profile - nothing to update. 98 // Empty profile - nothing to update.
90 base::string16 summary0 = GetLabel(&profile0); 99 base::string16 summary0 = GetLabel(&profile0);
91 EXPECT_EQ(base::string16(), summary0); 100 EXPECT_EQ(base::string16(), summary0);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 ASSERT_EQ(profiles.size(), labels.size()); 188 ASSERT_EQ(profiles.size(), labels.size());
180 summary7 = labels[0]; 189 summary7 = labels[0];
181 base::string16 summary7a = labels[1]; 190 base::string16 summary7a = labels[1];
182 EXPECT_EQ(ASCIIToUTF16( 191 EXPECT_EQ(ASCIIToUTF16(
183 "Marion Mitchell Morrison, 123 Zoo St., johnwayne@me.xyz"), summary7); 192 "Marion Mitchell Morrison, 123 Zoo St., johnwayne@me.xyz"), summary7);
184 EXPECT_EQ(ASCIIToUTF16( 193 EXPECT_EQ(ASCIIToUTF16(
185 "Marion Mitchell Morrison, 123 Zoo St., marion@me.xyz"), summary7a); 194 "Marion Mitchell Morrison, 123 Zoo St., marion@me.xyz"), summary7a);
186 } 195 }
187 196
188 TEST(AutofillProfileTest, AdjustInferredLabels) { 197 TEST(AutofillProfileTest, AdjustInferredLabels) {
189 ScopedVector<AutofillProfile> profiles; 198 std::vector<std::unique_ptr<AutofillProfile>> profiles;
190 profiles.push_back( 199 profiles.push_back(base::MakeUnique<AutofillProfile>(
191 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); 200 base::GenerateGUID(), "https://www.example.com/"));
192 test::SetProfileInfo( 201 test::SetProfileInfo(profiles[0].get(), "John", "", "Doe",
193 profiles[0], 202 "johndoe@hades.com", "Underworld", "666 Erebus St.", "",
194 "John", 203 "Elysium", "CA", "91111", "US", "16502111111");
195 "", 204 profiles.push_back(base::MakeUnique<AutofillProfile>(
196 "Doe", 205 base::GenerateGUID(), "http://www.example.com/"));
197 "johndoe@hades.com", 206 test::SetProfileInfo(profiles[1].get(), "Jane", "", "Doe",
198 "Underworld", 207 "janedoe@tertium.com", "Pluto Inc.", "123 Letha Shore.",
199 "666 Erebus St.", 208 "", "Dis", "CA", "91222", "US", "12345678910");
200 "",
201 "Elysium", "CA",
202 "91111",
203 "US",
204 "16502111111");
205 profiles.push_back(
206 new AutofillProfile(base::GenerateGUID(), "http://www.example.com/"));
207 test::SetProfileInfo(
208 profiles[1],
209 "Jane",
210 "",
211 "Doe",
212 "janedoe@tertium.com",
213 "Pluto Inc.",
214 "123 Letha Shore.",
215 "",
216 "Dis", "CA",
217 "91222",
218 "US",
219 "12345678910");
220 std::vector<base::string16> labels; 209 std::vector<base::string16> labels;
221 AutofillProfile::CreateDifferentiatingLabels( 210 AutofillProfile::CreateDifferentiatingLabels(ToRawPointerVector(profiles),
222 profiles.get(), "en-US", &labels); 211 "en-US", &labels);
223 ASSERT_EQ(2U, labels.size()); 212 ASSERT_EQ(2U, labels.size());
224 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St."), labels[0]); 213 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St."), labels[0]);
225 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); 214 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]);
226 215
227 profiles.push_back( 216 profiles.push_back(
228 new AutofillProfile(base::GenerateGUID(), kSettingsOrigin)); 217 base::MakeUnique<AutofillProfile>(base::GenerateGUID(), kSettingsOrigin));
229 test::SetProfileInfo( 218 test::SetProfileInfo(profiles[2].get(), "John", "", "Doe",
230 profiles[2], 219 "johndoe@tertium.com", "Underworld", "666 Erebus St.",
231 "John", 220 "", "Elysium", "CA", "91111", "US", "16502111111");
232 "",
233 "Doe",
234 "johndoe@tertium.com",
235 "Underworld",
236 "666 Erebus St.",
237 "",
238 "Elysium", "CA",
239 "91111",
240 "US",
241 "16502111111");
242 labels.clear(); 221 labels.clear();
243 AutofillProfile::CreateDifferentiatingLabels( 222 AutofillProfile::CreateDifferentiatingLabels(ToRawPointerVector(profiles),
244 profiles.get(), "en-US", &labels); 223 "en-US", &labels);
245 224
246 // Profile 0 and 2 inferred label now includes an e-mail. 225 // Profile 0 and 2 inferred label now includes an e-mail.
247 ASSERT_EQ(3U, labels.size()); 226 ASSERT_EQ(3U, labels.size());
248 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@hades.com"), 227 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@hades.com"),
249 labels[0]); 228 labels[0]);
250 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); 229 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]);
251 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@tertium.com"), 230 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@tertium.com"),
252 labels[2]); 231 labels[2]);
253 232
254 profiles.resize(2); 233 profiles.resize(2);
255 234
256 profiles.push_back( 235 profiles.push_back(
257 new AutofillProfile(base::GenerateGUID(), std::string())); 236 base::MakeUnique<AutofillProfile>(base::GenerateGUID(), std::string()));
258 test::SetProfileInfo( 237 test::SetProfileInfo(profiles[2].get(), "John", "", "Doe",
259 profiles[2], 238 "johndoe@hades.com", "Underworld", "666 Erebus St.", "",
260 "John", 239 "Elysium", "CO", // State is different
261 "", 240 "91111", "US", "16502111111");
262 "Doe",
263 "johndoe@hades.com",
264 "Underworld",
265 "666 Erebus St.",
266 "",
267 "Elysium", "CO", // State is different
268 "91111",
269 "US",
270 "16502111111");
271 241
272 labels.clear(); 242 labels.clear();
273 AutofillProfile::CreateDifferentiatingLabels( 243 AutofillProfile::CreateDifferentiatingLabels(ToRawPointerVector(profiles),
274 profiles.get(), "en-US", &labels); 244 "en-US", &labels);
275 245
276 // Profile 0 and 2 inferred label now includes a state. 246 // Profile 0 and 2 inferred label now includes a state.
277 ASSERT_EQ(3U, labels.size()); 247 ASSERT_EQ(3U, labels.size());
278 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CA"), labels[0]); 248 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CA"), labels[0]);
279 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); 249 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]);
280 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO"), labels[2]); 250 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO"), labels[2]);
281 251
282 profiles.push_back( 252 profiles.push_back(base::MakeUnique<AutofillProfile>(
283 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); 253 base::GenerateGUID(), "https://www.example.com/"));
284 test::SetProfileInfo( 254 test::SetProfileInfo(profiles[3].get(), "John", "", "Doe",
285 profiles[3], 255 "johndoe@hades.com", "Underworld", "666 Erebus St.", "",
286 "John", 256 "Elysium", "CO", // State is different for some.
287 "", 257 "91111", "US",
288 "Doe", 258 "16504444444"); // Phone is different for some.
289 "johndoe@hades.com",
290 "Underworld",
291 "666 Erebus St.",
292 "",
293 "Elysium", "CO", // State is different for some.
294 "91111",
295 "US",
296 "16504444444"); // Phone is different for some.
297 259
298 labels.clear(); 260 labels.clear();
299 AutofillProfile::CreateDifferentiatingLabels( 261 AutofillProfile::CreateDifferentiatingLabels(ToRawPointerVector(profiles),
300 profiles.get(), "en-US", &labels); 262 "en-US", &labels);
301 ASSERT_EQ(4U, labels.size()); 263 ASSERT_EQ(4U, labels.size());
302 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CA"), labels[0]); 264 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CA"), labels[0]);
303 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); 265 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]);
304 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, 16502111111"), 266 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, 16502111111"),
305 labels[2]); 267 labels[2]);
306 // This one differs from other ones by unique phone, so no need for extra 268 // This one differs from other ones by unique phone, so no need for extra
307 // information. 269 // information.
308 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, 16504444444"), 270 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, 16504444444"),
309 labels[3]); 271 labels[3]);
310 272
311 profiles.push_back( 273 profiles.push_back(base::MakeUnique<AutofillProfile>(
312 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); 274 base::GenerateGUID(), "https://www.example.com/"));
313 test::SetProfileInfo( 275 test::SetProfileInfo(profiles[4].get(), "John", "", "Doe",
314 profiles[4], 276 "johndoe@styx.com", // E-Mail is different for some.
315 "John", 277 "Underworld", "666 Erebus St.", "", "Elysium",
316 "", 278 "CO", // State is different for some.
317 "Doe", 279 "91111", "US",
318 "johndoe@styx.com", // E-Mail is different for some. 280 "16504444444"); // Phone is different for some.
319 "Underworld",
320 "666 Erebus St.",
321 "",
322 "Elysium", "CO", // State is different for some.
323 "91111",
324 "US",
325 "16504444444"); // Phone is different for some.
326 281
327 labels.clear(); 282 labels.clear();
328 AutofillProfile::CreateDifferentiatingLabels( 283 AutofillProfile::CreateDifferentiatingLabels(ToRawPointerVector(profiles),
329 profiles.get(), "en-US", &labels); 284 "en-US", &labels);
330 ASSERT_EQ(5U, labels.size()); 285 ASSERT_EQ(5U, labels.size());
331 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CA"), labels[0]); 286 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CA"), labels[0]);
332 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); 287 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]);
333 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, johndoe@hades.com," 288 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, johndoe@hades.com,"
334 " 16502111111"), labels[2]); 289 " 16502111111"), labels[2]);
335 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, johndoe@hades.com," 290 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, johndoe@hades.com,"
336 " 16504444444"), labels[3]); 291 " 16504444444"), labels[3]);
337 // This one differs from other ones by unique e-mail, so no need for extra 292 // This one differs from other ones by unique e-mail, so no need for extra
338 // information. 293 // information.
339 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, johndoe@styx.com"), 294 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, johndoe@styx.com"),
340 labels[4]); 295 labels[4]);
341 } 296 }
342 297
343 TEST(AutofillProfileTest, CreateInferredLabelsI18n_CH) { 298 TEST(AutofillProfileTest, CreateInferredLabelsI18n_CH) {
344 ScopedVector<AutofillProfile> profiles; 299 std::vector<std::unique_ptr<AutofillProfile>> profiles;
345 profiles.push_back( 300 profiles.push_back(base::MakeUnique<AutofillProfile>(
346 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); 301 base::GenerateGUID(), "https://www.example.com/"));
347 test::SetProfileInfo(profiles.back(), 302 test::SetProfileInfo(profiles.back().get(), "H.", "R.", "Giger",
348 "H.", 303 "hrgiger@beispiel.com", "Beispiel Inc",
349 "R.", 304 "Brandschenkestrasse 110", "", "Zurich", "", "8002",
350 "Giger", 305 "CH", "+41 44-668-1800");
351 "hrgiger@beispiel.com",
352 "Beispiel Inc",
353 "Brandschenkestrasse 110",
354 "",
355 "Zurich", "",
356 "8002",
357 "CH",
358 "+41 44-668-1800");
359 profiles.back()->set_language_code("de_CH"); 306 profiles.back()->set_language_code("de_CH");
360 static const char* kExpectedLabels[] = { 307 static const char* kExpectedLabels[] = {
361 "", 308 "",
362 "H. R. Giger", 309 "H. R. Giger",
363 "H. R. Giger, Brandschenkestrasse 110", 310 "H. R. Giger, Brandschenkestrasse 110",
364 "H. R. Giger, Brandschenkestrasse 110, Zurich", 311 "H. R. Giger, Brandschenkestrasse 110, Zurich",
365 "H. R. Giger, Brandschenkestrasse 110, CH-8002 Zurich", 312 "H. R. Giger, Brandschenkestrasse 110, CH-8002 Zurich",
366 "Beispiel Inc, H. R. Giger, Brandschenkestrasse 110, CH-8002 Zurich", 313 "Beispiel Inc, H. R. Giger, Brandschenkestrasse 110, CH-8002 Zurich",
367 "Beispiel Inc, H. R. Giger, Brandschenkestrasse 110, CH-8002 Zurich, " 314 "Beispiel Inc, H. R. Giger, Brandschenkestrasse 110, CH-8002 Zurich, "
368 "Switzerland", 315 "Switzerland",
369 "Beispiel Inc, H. R. Giger, Brandschenkestrasse 110, CH-8002 Zurich, " 316 "Beispiel Inc, H. R. Giger, Brandschenkestrasse 110, CH-8002 Zurich, "
370 "Switzerland, hrgiger@beispiel.com", 317 "Switzerland, hrgiger@beispiel.com",
371 "Beispiel Inc, H. R. Giger, Brandschenkestrasse 110, CH-8002 Zurich, " 318 "Beispiel Inc, H. R. Giger, Brandschenkestrasse 110, CH-8002 Zurich, "
372 "Switzerland, hrgiger@beispiel.com, +41 44-668-1800", 319 "Switzerland, hrgiger@beispiel.com, +41 44-668-1800",
373 }; 320 };
374 321
375 std::vector<base::string16> labels; 322 std::vector<base::string16> labels;
376 for (size_t i = 0; i < arraysize(kExpectedLabels); ++i) { 323 for (size_t i = 0; i < arraysize(kExpectedLabels); ++i) {
377 AutofillProfile::CreateInferredLabels( 324 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles), NULL,
378 profiles.get(), NULL, UNKNOWN_TYPE, i, "en-US", &labels); 325 UNKNOWN_TYPE, i, "en-US", &labels);
379 ASSERT_FALSE(labels.empty()); 326 ASSERT_FALSE(labels.empty());
380 EXPECT_EQ(UTF8ToUTF16(kExpectedLabels[i]), labels.back()); 327 EXPECT_EQ(UTF8ToUTF16(kExpectedLabels[i]), labels.back());
381 } 328 }
382 } 329 }
383 330
384 331
385 TEST(AutofillProfileTest, CreateInferredLabelsI18n_FR) { 332 TEST(AutofillProfileTest, CreateInferredLabelsI18n_FR) {
386 ScopedVector<AutofillProfile> profiles; 333 std::vector<std::unique_ptr<AutofillProfile>> profiles;
387 profiles.push_back( 334 profiles.push_back(base::MakeUnique<AutofillProfile>(
388 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); 335 base::GenerateGUID(), "https://www.example.com/"));
389 test::SetProfileInfo(profiles.back(), 336 test::SetProfileInfo(profiles.back().get(), "Antoine", "", "de Saint-Exupéry",
390 "Antoine", 337 "antoine@exemple.com", "Exemple Inc", "8 Rue de Londres",
391 "", 338 "", "Paris", "", "75009", "FR", "+33 (0) 1 42 68 53 00");
392 "de Saint-Exupéry",
393 "antoine@exemple.com",
394 "Exemple Inc",
395 "8 Rue de Londres",
396 "",
397 "Paris", "",
398 "75009",
399 "FR",
400 "+33 (0) 1 42 68 53 00");
401 profiles.back()->set_language_code("fr_FR"); 339 profiles.back()->set_language_code("fr_FR");
402 profiles.back()->SetInfo( 340 profiles.back()->SetInfo(
403 AutofillType(ADDRESS_HOME_SORTING_CODE), UTF8ToUTF16("CEDEX"), "en-US"); 341 AutofillType(ADDRESS_HOME_SORTING_CODE), UTF8ToUTF16("CEDEX"), "en-US");
404 static const char* kExpectedLabels[] = { 342 static const char* kExpectedLabels[] = {
405 "", 343 "",
406 "Antoine de Saint-Exupéry", 344 "Antoine de Saint-Exupéry",
407 "Antoine de Saint-Exupéry, 8 Rue de Londres", 345 "Antoine de Saint-Exupéry, 8 Rue de Londres",
408 "Antoine de Saint-Exupéry, 8 Rue de Londres, Paris", 346 "Antoine de Saint-Exupéry, 8 Rue de Londres, Paris",
409 "Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris", 347 "Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris",
410 "Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris CEDEX", 348 "Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris CEDEX",
411 "Exemple Inc, Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris " 349 "Exemple Inc, Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris "
412 "CEDEX", 350 "CEDEX",
413 "Exemple Inc, Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris " 351 "Exemple Inc, Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris "
414 "CEDEX, France", 352 "CEDEX, France",
415 "Exemple Inc, Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris " 353 "Exemple Inc, Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris "
416 "CEDEX, France, antoine@exemple.com", 354 "CEDEX, France, antoine@exemple.com",
417 "Exemple Inc, Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris " 355 "Exemple Inc, Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris "
418 "CEDEX, France, antoine@exemple.com, +33 (0) 1 42 68 53 00", 356 "CEDEX, France, antoine@exemple.com, +33 (0) 1 42 68 53 00",
419 "Exemple Inc, Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris " 357 "Exemple Inc, Antoine de Saint-Exupéry, 8 Rue de Londres, 75009 Paris "
420 "CEDEX, France, antoine@exemple.com, +33 (0) 1 42 68 53 00", 358 "CEDEX, France, antoine@exemple.com, +33 (0) 1 42 68 53 00",
421 }; 359 };
422 360
423 std::vector<base::string16> labels; 361 std::vector<base::string16> labels;
424 for (size_t i = 0; i < arraysize(kExpectedLabels); ++i) { 362 for (size_t i = 0; i < arraysize(kExpectedLabels); ++i) {
425 AutofillProfile::CreateInferredLabels( 363 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles), NULL,
426 profiles.get(), NULL, UNKNOWN_TYPE, i, "en-US", &labels); 364 UNKNOWN_TYPE, i, "en-US", &labels);
427 ASSERT_FALSE(labels.empty()); 365 ASSERT_FALSE(labels.empty());
428 EXPECT_EQ(UTF8ToUTF16(kExpectedLabels[i]), labels.back()); 366 EXPECT_EQ(UTF8ToUTF16(kExpectedLabels[i]), labels.back());
429 } 367 }
430 } 368 }
431 369
432 TEST(AutofillProfileTest, CreateInferredLabelsI18n_KR) { 370 TEST(AutofillProfileTest, CreateInferredLabelsI18n_KR) {
433 ScopedVector<AutofillProfile> profiles; 371 std::vector<std::unique_ptr<AutofillProfile>> profiles;
434 profiles.push_back( 372 profiles.push_back(base::MakeUnique<AutofillProfile>(
435 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); 373 base::GenerateGUID(), "https://www.example.com/"));
436 test::SetProfileInfo(profiles.back(), 374 test::SetProfileInfo(profiles.back().get(), "Park", "", "Jae-sang",
437 "Park", 375 "park@yeleul.com", "Yeleul Inc",
438 "", 376 "Gangnam Finance Center", "152 Teheran-ro", "Gangnam-Gu",
439 "Jae-sang", 377 "Seoul", "135-984", "KR", "+82-2-531-9000");
440 "park@yeleul.com",
441 "Yeleul Inc",
442 "Gangnam Finance Center",
443 "152 Teheran-ro",
444 "Gangnam-Gu", "Seoul",
445 "135-984",
446 "KR",
447 "+82-2-531-9000");
448 profiles.back()->set_language_code("ko_Latn"); 378 profiles.back()->set_language_code("ko_Latn");
449 profiles.back()->SetInfo(AutofillType(ADDRESS_HOME_DEPENDENT_LOCALITY), 379 profiles.back()->SetInfo(AutofillType(ADDRESS_HOME_DEPENDENT_LOCALITY),
450 UTF8ToUTF16("Yeoksam-Dong"), 380 UTF8ToUTF16("Yeoksam-Dong"),
451 "en-US"); 381 "en-US");
452 static const char* kExpectedLabels[] = { 382 static const char* kExpectedLabels[] = {
453 "", 383 "",
454 "Park Jae-sang", 384 "Park Jae-sang",
455 "Park Jae-sang, Gangnam Finance Center", 385 "Park Jae-sang, Gangnam Finance Center",
456 "Park Jae-sang, Gangnam Finance Center, 152 Teheran-ro", 386 "Park Jae-sang, Gangnam Finance Center, 152 Teheran-ro",
457 "Park Jae-sang, Gangnam Finance Center, 152 Teheran-ro, Yeoksam-Dong", 387 "Park Jae-sang, Gangnam Finance Center, 152 Teheran-ro, Yeoksam-Dong",
(...skipping 10 matching lines...) Expand all
468 "Park Jae-sang, Yeleul Inc, Gangnam Finance Center, 152 Teheran-ro, " 398 "Park Jae-sang, Yeleul Inc, Gangnam Finance Center, 152 Teheran-ro, "
469 "Yeoksam-Dong, Gangnam-Gu, Seoul, 135-984, South Korea, " 399 "Yeoksam-Dong, Gangnam-Gu, Seoul, 135-984, South Korea, "
470 "park@yeleul.com", 400 "park@yeleul.com",
471 "Park Jae-sang, Yeleul Inc, Gangnam Finance Center, 152 Teheran-ro, " 401 "Park Jae-sang, Yeleul Inc, Gangnam Finance Center, 152 Teheran-ro, "
472 "Yeoksam-Dong, Gangnam-Gu, Seoul, 135-984, South Korea, " 402 "Yeoksam-Dong, Gangnam-Gu, Seoul, 135-984, South Korea, "
473 "park@yeleul.com, +82-2-531-9000", 403 "park@yeleul.com, +82-2-531-9000",
474 }; 404 };
475 405
476 std::vector<base::string16> labels; 406 std::vector<base::string16> labels;
477 for (size_t i = 0; i < arraysize(kExpectedLabels); ++i) { 407 for (size_t i = 0; i < arraysize(kExpectedLabels); ++i) {
478 AutofillProfile::CreateInferredLabels( 408 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles), NULL,
479 profiles.get(), NULL, UNKNOWN_TYPE, i, "en-US", &labels); 409 UNKNOWN_TYPE, i, "en-US", &labels);
480 ASSERT_FALSE(labels.empty()); 410 ASSERT_FALSE(labels.empty());
481 EXPECT_EQ(UTF8ToUTF16(kExpectedLabels[i]), labels.back()); 411 EXPECT_EQ(UTF8ToUTF16(kExpectedLabels[i]), labels.back());
482 } 412 }
483 } 413 }
484 414
485 TEST(AutofillProfileTest, CreateInferredLabelsI18n_JP_Latn) { 415 TEST(AutofillProfileTest, CreateInferredLabelsI18n_JP_Latn) {
486 ScopedVector<AutofillProfile> profiles; 416 std::vector<std::unique_ptr<AutofillProfile>> profiles;
487 profiles.push_back( 417 profiles.push_back(base::MakeUnique<AutofillProfile>(
488 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); 418 base::GenerateGUID(), "https://www.example.com/"));
489 test::SetProfileInfo(profiles.back(), 419 test::SetProfileInfo(profiles.back().get(), "Miku", "", "Hatsune",
490 "Miku", 420 "miku@rei.com", "Rei Inc", "Roppongi Hills Mori Tower",
491 "", 421 "6-10-1 Roppongi", "Minato-ku", "Tokyo", "106-6126",
492 "Hatsune", 422 "JP", "+81-3-6384-9000");
493 "miku@rei.com",
494 "Rei Inc",
495 "Roppongi Hills Mori Tower",
496 "6-10-1 Roppongi",
497 "Minato-ku", "Tokyo",
498 "106-6126",
499 "JP",
500 "+81-3-6384-9000");
501 profiles.back()->set_language_code("ja_Latn"); 423 profiles.back()->set_language_code("ja_Latn");
502 static const char* kExpectedLabels[] = { 424 static const char* kExpectedLabels[] = {
503 "", 425 "",
504 "Miku Hatsune", 426 "Miku Hatsune",
505 "Miku Hatsune, Roppongi Hills Mori Tower", 427 "Miku Hatsune, Roppongi Hills Mori Tower",
506 "Miku Hatsune, Roppongi Hills Mori Tower, 6-10-1 Roppongi", 428 "Miku Hatsune, Roppongi Hills Mori Tower, 6-10-1 Roppongi",
507 "Miku Hatsune, Roppongi Hills Mori Tower, 6-10-1 Roppongi, Minato-ku", 429 "Miku Hatsune, Roppongi Hills Mori Tower, 6-10-1 Roppongi, Minato-ku",
508 "Miku Hatsune, Roppongi Hills Mori Tower, 6-10-1 Roppongi, Minato-ku, " 430 "Miku Hatsune, Roppongi Hills Mori Tower, 6-10-1 Roppongi, Minato-ku, "
509 "Tokyo", 431 "Tokyo",
510 "Miku Hatsune, Roppongi Hills Mori Tower, 6-10-1 Roppongi, Minato-ku, " 432 "Miku Hatsune, Roppongi Hills Mori Tower, 6-10-1 Roppongi, Minato-ku, "
511 "Tokyo, 106-6126", 433 "Tokyo, 106-6126",
512 "Miku Hatsune, Rei Inc, Roppongi Hills Mori Tower, 6-10-1 Roppongi, " 434 "Miku Hatsune, Rei Inc, Roppongi Hills Mori Tower, 6-10-1 Roppongi, "
513 "Minato-ku, Tokyo, 106-6126", 435 "Minato-ku, Tokyo, 106-6126",
514 "Miku Hatsune, Rei Inc, Roppongi Hills Mori Tower, 6-10-1 Roppongi, " 436 "Miku Hatsune, Rei Inc, Roppongi Hills Mori Tower, 6-10-1 Roppongi, "
515 "Minato-ku, Tokyo, 106-6126, Japan", 437 "Minato-ku, Tokyo, 106-6126, Japan",
516 "Miku Hatsune, Rei Inc, Roppongi Hills Mori Tower, 6-10-1 Roppongi, " 438 "Miku Hatsune, Rei Inc, Roppongi Hills Mori Tower, 6-10-1 Roppongi, "
517 "Minato-ku, Tokyo, 106-6126, Japan, miku@rei.com", 439 "Minato-ku, Tokyo, 106-6126, Japan, miku@rei.com",
518 "Miku Hatsune, Rei Inc, Roppongi Hills Mori Tower, 6-10-1 Roppongi, " 440 "Miku Hatsune, Rei Inc, Roppongi Hills Mori Tower, 6-10-1 Roppongi, "
519 "Minato-ku, Tokyo, 106-6126, Japan, miku@rei.com, +81-3-6384-9000", 441 "Minato-ku, Tokyo, 106-6126, Japan, miku@rei.com, +81-3-6384-9000",
520 }; 442 };
521 443
522 std::vector<base::string16> labels; 444 std::vector<base::string16> labels;
523 for (size_t i = 0; i < arraysize(kExpectedLabels); ++i) { 445 for (size_t i = 0; i < arraysize(kExpectedLabels); ++i) {
524 AutofillProfile::CreateInferredLabels( 446 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles), NULL,
525 profiles.get(), NULL, UNKNOWN_TYPE, i, "en-US", &labels); 447 UNKNOWN_TYPE, i, "en-US", &labels);
526 ASSERT_FALSE(labels.empty()); 448 ASSERT_FALSE(labels.empty());
527 EXPECT_EQ(UTF8ToUTF16(kExpectedLabels[i]), labels.back()); 449 EXPECT_EQ(UTF8ToUTF16(kExpectedLabels[i]), labels.back());
528 } 450 }
529 } 451 }
530 452
531 TEST(AutofillProfileTest, CreateInferredLabelsI18n_JP_ja) { 453 TEST(AutofillProfileTest, CreateInferredLabelsI18n_JP_ja) {
532 ScopedVector<AutofillProfile> profiles; 454 std::vector<std::unique_ptr<AutofillProfile>> profiles;
533 profiles.push_back( 455 profiles.push_back(base::MakeUnique<AutofillProfile>(
534 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); 456 base::GenerateGUID(), "https://www.example.com/"));
535 test::SetProfileInfo(profiles.back(), 457 test::SetProfileInfo(profiles.back().get(), "ミク", "", "初音",
536 "ミク", 458 "miku@rei.com", "例", "六本木ヒルズ森タワー",
537 "", 459 "六本木 6-10-1", "港区", "東京都", "106-6126", "JP",
538 "初音",
539 "miku@rei.com",
540 "例",
541 "六本木ヒルズ森タワー",
542 "六本木 6-10-1",
543 "港区", "東京都",
544 "106-6126",
545 "JP",
546 "03-6384-9000"); 460 "03-6384-9000");
547 profiles.back()->set_language_code("ja_JP"); 461 profiles.back()->set_language_code("ja_JP");
548 static const char* kExpectedLabels[] = { 462 static const char* kExpectedLabels[] = {
549 "", 463 "",
550 "初音ミク", 464 "初音ミク",
551 "六本木ヒルズ森タワー初音ミク", 465 "六本木ヒルズ森タワー初音ミク",
552 "六本木ヒルズ森タワー六本木 6-10-1初音ミク", 466 "六本木ヒルズ森タワー六本木 6-10-1初音ミク",
553 "港区六本木ヒルズ森タワー六本木 6-10-1初音ミク", 467 "港区六本木ヒルズ森タワー六本木 6-10-1初音ミク",
554 "東京都港区六本木ヒルズ森タワー六本木 6-10-1初音ミク", 468 "東京都港区六本木ヒルズ森タワー六本木 6-10-1初音ミク",
555 "〒106-6126東京都港区六本木ヒルズ森タワー六本木 6-10-1初音ミク", 469 "〒106-6126東京都港区六本木ヒルズ森タワー六本木 6-10-1初音ミク",
556 "〒106-6126東京都港区六本木ヒルズ森タワー六本木 6-10-1例初音ミク", 470 "〒106-6126東京都港区六本木ヒルズ森タワー六本木 6-10-1例初音ミク",
557 "〒106-6126東京都港区六本木ヒルズ森タワー六本木 6-10-1例初音ミク, Japan", 471 "〒106-6126東京都港区六本木ヒルズ森タワー六本木 6-10-1例初音ミク, Japan",
558 "〒106-6126東京都港区六本木ヒルズ森タワー六本木 6-10-1例初音ミク, Japan, " 472 "〒106-6126東京都港区六本木ヒルズ森タワー六本木 6-10-1例初音ミク, Japan, "
559 "miku@rei.com", 473 "miku@rei.com",
560 "〒106-6126東京都港区六本木ヒルズ森タワー六本木 6-10-1例初音ミク, Japan, " 474 "〒106-6126東京都港区六本木ヒルズ森タワー六本木 6-10-1例初音ミク, Japan, "
561 "miku@rei.com, 03-6384-9000", 475 "miku@rei.com, 03-6384-9000",
562 }; 476 };
563 477
564 std::vector<base::string16> labels; 478 std::vector<base::string16> labels;
565 for (size_t i = 0; i < arraysize(kExpectedLabels); ++i) { 479 for (size_t i = 0; i < arraysize(kExpectedLabels); ++i) {
566 AutofillProfile::CreateInferredLabels( 480 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles), NULL,
567 profiles.get(), NULL, UNKNOWN_TYPE, i, "en-US", &labels); 481 UNKNOWN_TYPE, i, "en-US", &labels);
568 ASSERT_FALSE(labels.empty()); 482 ASSERT_FALSE(labels.empty());
569 EXPECT_EQ(UTF8ToUTF16(kExpectedLabels[i]), labels.back()); 483 EXPECT_EQ(UTF8ToUTF16(kExpectedLabels[i]), labels.back());
570 } 484 }
571 } 485 }
572 486
573 TEST(AutofillProfileTest, CreateInferredLabels) { 487 TEST(AutofillProfileTest, CreateInferredLabels) {
574 ScopedVector<AutofillProfile> profiles; 488 std::vector<std::unique_ptr<AutofillProfile>> profiles;
575 profiles.push_back( 489 profiles.push_back(base::MakeUnique<AutofillProfile>(
576 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); 490 base::GenerateGUID(), "https://www.example.com/"));
577 test::SetProfileInfo(profiles[0], 491 test::SetProfileInfo(profiles[0].get(), "John", "", "Doe",
578 "John", 492 "johndoe@hades.com", "Underworld", "666 Erebus St.", "",
579 "", 493 "Elysium", "CA", "91111", "US", "16502111111");
580 "Doe", 494 profiles.push_back(base::MakeUnique<AutofillProfile>(
581 "johndoe@hades.com", 495 base::GenerateGUID(), "https://www.example.com/"));
582 "Underworld", 496 test::SetProfileInfo(profiles[1].get(), "Jane", "", "Doe",
583 "666 Erebus St.", 497 "janedoe@tertium.com", "Pluto Inc.", "123 Letha Shore.",
584 "", 498 "", "Dis", "CA", "91222", "US", "12345678910");
585 "Elysium", "CA",
586 "91111",
587 "US",
588 "16502111111");
589 profiles.push_back(
590 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
591 test::SetProfileInfo(profiles[1],
592 "Jane",
593 "",
594 "Doe",
595 "janedoe@tertium.com",
596 "Pluto Inc.",
597 "123 Letha Shore.",
598 "",
599 "Dis", "CA",
600 "91222",
601 "US",
602 "12345678910");
603 std::vector<base::string16> labels; 499 std::vector<base::string16> labels;
604 // Two fields at least - no filter. 500 // Two fields at least - no filter.
605 AutofillProfile::CreateInferredLabels(profiles.get(), NULL, UNKNOWN_TYPE, 2, 501 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles), NULL,
606 "en-US", &labels); 502 UNKNOWN_TYPE, 2, "en-US", &labels);
607 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St."), labels[0]); 503 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St."), labels[0]);
608 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); 504 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]);
609 505
610 // Three fields at least - no filter. 506 // Three fields at least - no filter.
611 AutofillProfile::CreateInferredLabels(profiles.get(), NULL, UNKNOWN_TYPE, 3, 507 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles), NULL,
612 "en-US", &labels); 508 UNKNOWN_TYPE, 3, "en-US", &labels);
613 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., Elysium"), 509 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., Elysium"),
614 labels[0]); 510 labels[0]);
615 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore., Dis"), 511 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore., Dis"),
616 labels[1]); 512 labels[1]);
617 513
618 std::vector<ServerFieldType> suggested_fields; 514 std::vector<ServerFieldType> suggested_fields;
619 suggested_fields.push_back(ADDRESS_HOME_CITY); 515 suggested_fields.push_back(ADDRESS_HOME_CITY);
620 suggested_fields.push_back(ADDRESS_HOME_STATE); 516 suggested_fields.push_back(ADDRESS_HOME_STATE);
621 suggested_fields.push_back(ADDRESS_HOME_ZIP); 517 suggested_fields.push_back(ADDRESS_HOME_ZIP);
622 518
623 // Two fields at least, from suggested fields - no filter. 519 // Two fields at least, from suggested fields - no filter.
624 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, 520 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles),
625 UNKNOWN_TYPE, 2, "en-US", &labels); 521 &suggested_fields, UNKNOWN_TYPE, 2,
522 "en-US", &labels);
626 EXPECT_EQ(ASCIIToUTF16("Elysium 91111"), labels[0]); 523 EXPECT_EQ(ASCIIToUTF16("Elysium 91111"), labels[0]);
627 EXPECT_EQ(ASCIIToUTF16("Dis 91222"), labels[1]); 524 EXPECT_EQ(ASCIIToUTF16("Dis 91222"), labels[1]);
628 525
629 // Three fields at least, from suggested fields - no filter. 526 // Three fields at least, from suggested fields - no filter.
630 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, 527 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles),
631 UNKNOWN_TYPE, 3, "en-US", &labels); 528 &suggested_fields, UNKNOWN_TYPE, 3,
529 "en-US", &labels);
632 EXPECT_EQ(ASCIIToUTF16("Elysium, CA 91111"), labels[0]); 530 EXPECT_EQ(ASCIIToUTF16("Elysium, CA 91111"), labels[0]);
633 EXPECT_EQ(ASCIIToUTF16("Dis, CA 91222"), labels[1]); 531 EXPECT_EQ(ASCIIToUTF16("Dis, CA 91222"), labels[1]);
634 532
635 // Three fields at least, from suggested fields - but filter reduces available 533 // Three fields at least, from suggested fields - but filter reduces available
636 // fields to two. 534 // fields to two.
637 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, 535 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles),
638 ADDRESS_HOME_ZIP, 3, "en-US", &labels); 536 &suggested_fields, ADDRESS_HOME_ZIP, 3,
537 "en-US", &labels);
639 EXPECT_EQ(ASCIIToUTF16("Elysium, CA"), labels[0]); 538 EXPECT_EQ(ASCIIToUTF16("Elysium, CA"), labels[0]);
640 EXPECT_EQ(ASCIIToUTF16("Dis, CA"), labels[1]); 539 EXPECT_EQ(ASCIIToUTF16("Dis, CA"), labels[1]);
641 540
642 suggested_fields.clear(); 541 suggested_fields.clear();
643 // In our implementation we always display NAME_FULL for all NAME* fields... 542 // In our implementation we always display NAME_FULL for all NAME* fields...
644 suggested_fields.push_back(NAME_MIDDLE); 543 suggested_fields.push_back(NAME_MIDDLE);
645 // One field at least, from suggested fields - no filter. 544 // One field at least, from suggested fields - no filter.
646 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, 545 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles),
647 UNKNOWN_TYPE, 1, "en-US", &labels); 546 &suggested_fields, UNKNOWN_TYPE, 1,
547 "en-US", &labels);
648 EXPECT_EQ(ASCIIToUTF16("John Doe"), labels[0]); 548 EXPECT_EQ(ASCIIToUTF16("John Doe"), labels[0]);
649 EXPECT_EQ(ASCIIToUTF16("Jane Doe"), labels[1]); 549 EXPECT_EQ(ASCIIToUTF16("Jane Doe"), labels[1]);
650 550
651 // One field at least, from suggested fields - filter the same as suggested 551 // One field at least, from suggested fields - filter the same as suggested
652 // field. 552 // field.
653 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, 553 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles),
654 NAME_MIDDLE, 1, "en-US", &labels); 554 &suggested_fields, NAME_MIDDLE, 1,
555 "en-US", &labels);
655 EXPECT_EQ(base::string16(), labels[0]); 556 EXPECT_EQ(base::string16(), labels[0]);
656 EXPECT_EQ(base::string16(), labels[1]); 557 EXPECT_EQ(base::string16(), labels[1]);
657 558
658 suggested_fields.clear(); 559 suggested_fields.clear();
659 // In our implementation we always display NAME_FULL for NAME_MIDDLE_INITIAL 560 // In our implementation we always display NAME_FULL for NAME_MIDDLE_INITIAL
660 suggested_fields.push_back(NAME_MIDDLE_INITIAL); 561 suggested_fields.push_back(NAME_MIDDLE_INITIAL);
661 // One field at least, from suggested fields - no filter. 562 // One field at least, from suggested fields - no filter.
662 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, 563 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles),
663 UNKNOWN_TYPE, 1, "en-US", &labels); 564 &suggested_fields, UNKNOWN_TYPE, 1,
565 "en-US", &labels);
664 EXPECT_EQ(ASCIIToUTF16("John Doe"), labels[0]); 566 EXPECT_EQ(ASCIIToUTF16("John Doe"), labels[0]);
665 EXPECT_EQ(ASCIIToUTF16("Jane Doe"), labels[1]); 567 EXPECT_EQ(ASCIIToUTF16("Jane Doe"), labels[1]);
666 568
667 // One field at least, from suggested fields - filter same as the first non- 569 // One field at least, from suggested fields - filter same as the first non-
668 // unknown suggested field. 570 // unknown suggested field.
669 suggested_fields.clear(); 571 suggested_fields.clear();
670 suggested_fields.push_back(UNKNOWN_TYPE); 572 suggested_fields.push_back(UNKNOWN_TYPE);
671 suggested_fields.push_back(NAME_FULL); 573 suggested_fields.push_back(NAME_FULL);
672 suggested_fields.push_back(ADDRESS_HOME_LINE1); 574 suggested_fields.push_back(ADDRESS_HOME_LINE1);
673 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, 575 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles),
674 NAME_FULL, 1, "en-US", &labels); 576 &suggested_fields, NAME_FULL, 1,
577 "en-US", &labels);
675 EXPECT_EQ(base::string16(ASCIIToUTF16("666 Erebus St.")), labels[0]); 578 EXPECT_EQ(base::string16(ASCIIToUTF16("666 Erebus St.")), labels[0]);
676 EXPECT_EQ(base::string16(ASCIIToUTF16("123 Letha Shore.")), labels[1]); 579 EXPECT_EQ(base::string16(ASCIIToUTF16("123 Letha Shore.")), labels[1]);
677 580
678 // No suggested fields, but non-unknown excluded field. 581 // No suggested fields, but non-unknown excluded field.
679 AutofillProfile::CreateInferredLabels(profiles.get(), NULL, 582 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles), NULL,
680 NAME_FULL, 1, "en-US", &labels); 583 NAME_FULL, 1, "en-US", &labels);
681 EXPECT_EQ(base::string16(ASCIIToUTF16("666 Erebus St.")), labels[0]); 584 EXPECT_EQ(base::string16(ASCIIToUTF16("666 Erebus St.")), labels[0]);
682 EXPECT_EQ(base::string16(ASCIIToUTF16("123 Letha Shore.")), labels[1]); 585 EXPECT_EQ(base::string16(ASCIIToUTF16("123 Letha Shore.")), labels[1]);
683 } 586 }
684 587
685 // Test that we fall back to using the full name if there are no other 588 // Test that we fall back to using the full name if there are no other
686 // distinguishing fields, but only if it makes sense given the suggested fields. 589 // distinguishing fields, but only if it makes sense given the suggested fields.
687 TEST(AutofillProfileTest, CreateInferredLabelsFallsBackToFullName) { 590 TEST(AutofillProfileTest, CreateInferredLabelsFallsBackToFullName) {
688 ScopedVector<AutofillProfile> profiles; 591 std::vector<std::unique_ptr<AutofillProfile>> profiles;
689 profiles.push_back( 592 profiles.push_back(base::MakeUnique<AutofillProfile>(
690 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); 593 base::GenerateGUID(), "https://www.example.com/"));
691 test::SetProfileInfo(profiles[0], 594 test::SetProfileInfo(profiles[0].get(), "John", "", "Doe", "doe@example.com",
692 "John", "", "Doe", "doe@example.com", "", 595 "", "88 Nowhere Ave.", "", "", "", "", "", "");
693 "88 Nowhere Ave.", "", "", "", "", "", ""); 596 profiles.push_back(base::MakeUnique<AutofillProfile>(
694 profiles.push_back( 597 base::GenerateGUID(), "https://www.example.com/"));
695 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); 598 test::SetProfileInfo(profiles[1].get(), "Johnny", "K", "Doe",
696 test::SetProfileInfo(profiles[1], 599 "doe@example.com", "", "88 Nowhere Ave.", "", "", "", "",
697 "Johnny", "K", "Doe", "doe@example.com", "", 600 "", "");
698 "88 Nowhere Ave.", "", "", "", "", "", "");
699 601
700 // If the only name field in the suggested fields is the excluded field, we 602 // If the only name field in the suggested fields is the excluded field, we
701 // should not fall back to the full name as a distinguishing field. 603 // should not fall back to the full name as a distinguishing field.
702 std::vector<ServerFieldType> suggested_fields; 604 std::vector<ServerFieldType> suggested_fields;
703 suggested_fields.push_back(NAME_LAST); 605 suggested_fields.push_back(NAME_LAST);
704 suggested_fields.push_back(ADDRESS_HOME_LINE1); 606 suggested_fields.push_back(ADDRESS_HOME_LINE1);
705 suggested_fields.push_back(EMAIL_ADDRESS); 607 suggested_fields.push_back(EMAIL_ADDRESS);
706 std::vector<base::string16> labels; 608 std::vector<base::string16> labels;
707 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, 609 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles),
708 NAME_LAST, 1, "en-US", &labels); 610 &suggested_fields, NAME_LAST, 1,
611 "en-US", &labels);
709 ASSERT_EQ(2U, labels.size()); 612 ASSERT_EQ(2U, labels.size());
710 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave."), labels[0]); 613 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave."), labels[0]);
711 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave."), labels[1]); 614 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave."), labels[1]);
712 615
713 // Otherwise, we should. 616 // Otherwise, we should.
714 suggested_fields.push_back(NAME_FIRST); 617 suggested_fields.push_back(NAME_FIRST);
715 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, 618 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles),
716 NAME_LAST, 1, "en-US", &labels); 619 &suggested_fields, NAME_LAST, 1,
620 "en-US", &labels);
717 ASSERT_EQ(2U, labels.size()); 621 ASSERT_EQ(2U, labels.size());
718 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., John Doe"), labels[0]); 622 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., John Doe"), labels[0]);
719 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., Johnny K Doe"), labels[1]); 623 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., Johnny K Doe"), labels[1]);
720 } 624 }
721 625
722 // Test that we do not show duplicate fields in the labels. 626 // Test that we do not show duplicate fields in the labels.
723 TEST(AutofillProfileTest, CreateInferredLabelsNoDuplicatedFields) { 627 TEST(AutofillProfileTest, CreateInferredLabelsNoDuplicatedFields) {
724 ScopedVector<AutofillProfile> profiles; 628 std::vector<std::unique_ptr<AutofillProfile>> profiles;
725 profiles.push_back( 629 profiles.push_back(base::MakeUnique<AutofillProfile>(
726 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); 630 base::GenerateGUID(), "https://www.example.com/"));
727 test::SetProfileInfo(profiles[0], 631 test::SetProfileInfo(profiles[0].get(), "John", "", "Doe", "doe@example.com",
728 "John", "", "Doe", "doe@example.com", "", 632 "", "88 Nowhere Ave.", "", "", "", "", "", "");
729 "88 Nowhere Ave.", "", "", "", "", "", ""); 633 profiles.push_back(base::MakeUnique<AutofillProfile>(
730 profiles.push_back( 634 base::GenerateGUID(), "https://www.example.com/"));
731 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); 635 test::SetProfileInfo(profiles[1].get(), "John", "", "Doe", "dojo@example.com",
732 test::SetProfileInfo(profiles[1], 636 "", "88 Nowhere Ave.", "", "", "", "", "", "");
733 "John", "", "Doe", "dojo@example.com", "",
734 "88 Nowhere Ave.", "", "", "", "", "", "");
735 637
736 // If the only name field in the suggested fields is the excluded field, we 638 // If the only name field in the suggested fields is the excluded field, we
737 // should not fall back to the full name as a distinguishing field. 639 // should not fall back to the full name as a distinguishing field.
738 std::vector<ServerFieldType> suggested_fields; 640 std::vector<ServerFieldType> suggested_fields;
739 suggested_fields.push_back(ADDRESS_HOME_LINE1); 641 suggested_fields.push_back(ADDRESS_HOME_LINE1);
740 suggested_fields.push_back(ADDRESS_BILLING_LINE1); 642 suggested_fields.push_back(ADDRESS_BILLING_LINE1);
741 suggested_fields.push_back(EMAIL_ADDRESS); 643 suggested_fields.push_back(EMAIL_ADDRESS);
742 std::vector<base::string16> labels; 644 std::vector<base::string16> labels;
743 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, 645 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles),
744 UNKNOWN_TYPE, 2, "en-US", &labels); 646 &suggested_fields, UNKNOWN_TYPE, 2,
647 "en-US", &labels);
745 ASSERT_EQ(2U, labels.size()); 648 ASSERT_EQ(2U, labels.size());
746 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., doe@example.com"), labels[0]); 649 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., doe@example.com"), labels[0]);
747 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., dojo@example.com"), labels[1]); 650 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., dojo@example.com"), labels[1]);
748 } 651 }
749 652
750 // Make sure that empty fields are not treated as distinguishing fields. 653 // Make sure that empty fields are not treated as distinguishing fields.
751 TEST(AutofillProfileTest, CreateInferredLabelsSkipsEmptyFields) { 654 TEST(AutofillProfileTest, CreateInferredLabelsSkipsEmptyFields) {
752 ScopedVector<AutofillProfile> profiles; 655 std::vector<std::unique_ptr<AutofillProfile>> profiles;
753 profiles.push_back( 656 profiles.push_back(base::MakeUnique<AutofillProfile>(
754 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); 657 base::GenerateGUID(), "https://www.example.com/"));
755 test::SetProfileInfo(profiles[0], 658 test::SetProfileInfo(profiles[0].get(), "John", "", "Doe", "doe@example.com",
756 "John", "", "Doe", "doe@example.com",
757 "Gogole", "", "", "", "", "", "", ""); 659 "Gogole", "", "", "", "", "", "", "");
758 profiles.push_back( 660 profiles.push_back(base::MakeUnique<AutofillProfile>(
759 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); 661 base::GenerateGUID(), "https://www.example.com/"));
760 test::SetProfileInfo(profiles[1], 662 test::SetProfileInfo(profiles[1].get(), "John", "", "Doe", "doe@example.com",
761 "John", "", "Doe", "doe@example.com",
762 "Ggoole", "", "", "", "", "", "", ""); 663 "Ggoole", "", "", "", "", "", "", "");
763 profiles.push_back( 664 profiles.push_back(base::MakeUnique<AutofillProfile>(
764 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); 665 base::GenerateGUID(), "https://www.example.com/"));
765 test::SetProfileInfo(profiles[2], 666 test::SetProfileInfo(profiles[2].get(), "John", "", "Doe",
766 "John", "", "Doe", "john.doe@example.com", 667 "john.doe@example.com", "Goolge", "", "", "", "", "", "",
767 "Goolge", "", "", "", "", "", "", ""); 668 "");
768 669
769 std::vector<base::string16> labels; 670 std::vector<base::string16> labels;
770 AutofillProfile::CreateInferredLabels(profiles.get(), NULL, UNKNOWN_TYPE, 3, 671 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles), NULL,
771 "en-US", &labels); 672 UNKNOWN_TYPE, 3, "en-US", &labels);
772 ASSERT_EQ(3U, labels.size()); 673 ASSERT_EQ(3U, labels.size());
773 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Gogole"), labels[0]); 674 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Gogole"), labels[0]);
774 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Ggoole"), labels[1]); 675 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Ggoole"), labels[1]);
775 EXPECT_EQ(ASCIIToUTF16("John Doe, john.doe@example.com, Goolge"), labels[2]); 676 EXPECT_EQ(ASCIIToUTF16("John Doe, john.doe@example.com, Goolge"), labels[2]);
776 677
777 // A field must have a non-empty value for each profile to be considered a 678 // A field must have a non-empty value for each profile to be considered a
778 // distinguishing field. 679 // distinguishing field.
779 profiles[1]->SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("88 Nowhere Ave.")); 680 profiles[1]->SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("88 Nowhere Ave."));
780 AutofillProfile::CreateInferredLabels(profiles.get(), NULL, UNKNOWN_TYPE, 1, 681 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles), NULL,
781 "en-US", &labels); 682 UNKNOWN_TYPE, 1, "en-US", &labels);
782 ASSERT_EQ(3U, labels.size()); 683 ASSERT_EQ(3U, labels.size());
783 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Gogole"), labels[0]); 684 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Gogole"), labels[0]);
784 EXPECT_EQ(ASCIIToUTF16("John Doe, 88 Nowhere Ave., doe@example.com, Ggoole"), 685 EXPECT_EQ(ASCIIToUTF16("John Doe, 88 Nowhere Ave., doe@example.com, Ggoole"),
785 labels[1]) << labels[1]; 686 labels[1]) << labels[1];
786 EXPECT_EQ(ASCIIToUTF16("John Doe, john.doe@example.com"), labels[2]); 687 EXPECT_EQ(ASCIIToUTF16("John Doe, john.doe@example.com"), labels[2]);
787 } 688 }
788 689
789 // Test that labels that would otherwise have multiline values are flattened. 690 // Test that labels that would otherwise have multiline values are flattened.
790 TEST(AutofillProfileTest, CreateInferredLabelsFlattensMultiLineValues) { 691 TEST(AutofillProfileTest, CreateInferredLabelsFlattensMultiLineValues) {
791 ScopedVector<AutofillProfile> profiles; 692 std::vector<std::unique_ptr<AutofillProfile>> profiles;
792 profiles.push_back( 693 profiles.push_back(base::MakeUnique<AutofillProfile>(
793 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); 694 base::GenerateGUID(), "https://www.example.com/"));
794 test::SetProfileInfo(profiles[0], 695 test::SetProfileInfo(profiles[0].get(), "John", "", "Doe", "doe@example.com",
795 "John", "", "Doe", "doe@example.com", "", 696 "", "88 Nowhere Ave.", "Apt. 42", "", "", "", "", "");
796 "88 Nowhere Ave.", "Apt. 42", "", "", "", "", "");
797 697
798 // If the only name field in the suggested fields is the excluded field, we 698 // If the only name field in the suggested fields is the excluded field, we
799 // should not fall back to the full name as a distinguishing field. 699 // should not fall back to the full name as a distinguishing field.
800 std::vector<ServerFieldType> suggested_fields; 700 std::vector<ServerFieldType> suggested_fields;
801 suggested_fields.push_back(NAME_FULL); 701 suggested_fields.push_back(NAME_FULL);
802 suggested_fields.push_back(ADDRESS_HOME_STREET_ADDRESS); 702 suggested_fields.push_back(ADDRESS_HOME_STREET_ADDRESS);
803 std::vector<base::string16> labels; 703 std::vector<base::string16> labels;
804 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, 704 AutofillProfile::CreateInferredLabels(ToRawPointerVector(profiles),
805 NAME_FULL, 1, "en-US", &labels); 705 &suggested_fields, NAME_FULL, 1,
706 "en-US", &labels);
806 ASSERT_EQ(1U, labels.size()); 707 ASSERT_EQ(1U, labels.size());
807 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., Apt. 42"), labels[0]); 708 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., Apt. 42"), labels[0]);
808 } 709 }
809 710
810 TEST(AutofillProfileTest, IsSubsetOf) { 711 TEST(AutofillProfileTest, IsSubsetOf) {
811 std::unique_ptr<AutofillProfile> a, b; 712 std::unique_ptr<AutofillProfile> a, b;
812 713
813 // |a| is a subset of |b|. 714 // |a| is a subset of |b|.
814 a.reset( 715 a.reset(
815 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); 716 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 // The first, middle and last names should be kept and name full should be 1127 // The first, middle and last names should be kept and name full should be
1227 // added. 1128 // added.
1228 EXPECT_EQ(base::ASCIIToUTF16("Marion"), a.GetRawInfo(NAME_FIRST)); 1129 EXPECT_EQ(base::ASCIIToUTF16("Marion"), a.GetRawInfo(NAME_FIRST));
1229 EXPECT_EQ(base::ASCIIToUTF16("Mitchell"), a.GetRawInfo(NAME_MIDDLE)); 1130 EXPECT_EQ(base::ASCIIToUTF16("Mitchell"), a.GetRawInfo(NAME_MIDDLE));
1230 EXPECT_EQ(base::ASCIIToUTF16("Morrison"), a.GetRawInfo(NAME_LAST)); 1131 EXPECT_EQ(base::ASCIIToUTF16("Morrison"), a.GetRawInfo(NAME_LAST));
1231 EXPECT_EQ(base::ASCIIToUTF16("Marion Mitchell Morrison"), 1132 EXPECT_EQ(base::ASCIIToUTF16("Marion Mitchell Morrison"),
1232 a.GetRawInfo(NAME_FULL)); 1133 a.GetRawInfo(NAME_FULL));
1233 } 1134 }
1234 1135
1235 } // namespace autofill 1136 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | components/autofill/core/browser/autofill_scanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698