autofill_profile_unittest.cc revision 21d179b334e59e9a3bfcaed4c4430bef1bc5759d
1// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "base/basictypes.h" 6#include "base/scoped_ptr.h" 7#include "base/scoped_vector.h" 8#include "base/stl_util-inl.h" 9#include "base/string16.h" 10#include "base/utf_string_conversions.h" 11#include "chrome/browser/autofill/autofill_common_test.h" 12#include "chrome/browser/autofill/autofill_profile.h" 13#include "chrome/common/guid.h" 14#include "grit/generated_resources.h" 15#include "testing/gtest/include/gtest/gtest.h" 16 17namespace { 18 19bool UpdateProfileLabel(AutoFillProfile *profile) { 20 std::vector<AutoFillProfile*> profiles; 21 profiles.push_back(profile); 22 return AutoFillProfile::AdjustInferredLabels(&profiles); 23} 24 25// Tests different possibilities for summary string generation. 26// Based on existence of first name, last name, and address line 1. 27TEST(AutoFillProfileTest, PreviewSummaryString) { 28 // Case 0/null: "" 29 AutoFillProfile profile0; 30 // Empty profile - nothing to update. 31 EXPECT_FALSE(UpdateProfileLabel(&profile0)); 32 string16 summary0 = profile0.Label(); 33 EXPECT_EQ(string16(), summary0); 34 35 // Case 0a/empty name and address, so the first two fields of the rest of the 36 // data is used: "Hollywood, CA" 37 AutoFillProfile profile00; 38 autofill_test::SetProfileInfo(&profile00, "Billing", "", "Mitchell", "", 39 "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", "91601", "US", 40 "12345678910", "01987654321"); 41 EXPECT_TRUE(UpdateProfileLabel(&profile00)); 42 string16 summary00 = profile00.Label(); 43 EXPECT_EQ(ASCIIToUTF16("Hollywood, CA"), summary00); 44 45 // Case 1: "<address>" 46 AutoFillProfile profile1; 47 autofill_test::SetProfileInfo(&profile1, "Billing", "", "Mitchell", "", 48 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", 49 "91601", "US", "12345678910", "01987654321"); 50 EXPECT_TRUE(UpdateProfileLabel(&profile1)); 51 string16 summary1 = profile1.Label(); 52 EXPECT_EQ(ASCIIToUTF16("123 Zoo St., Hollywood"), summary1); 53 54 // Case 2: "<lastname>" 55 AutoFillProfile profile2; 56 autofill_test::SetProfileInfo(&profile2, "Billing", "", "Mitchell", 57 "Morrison", "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", 58 "91601", "US", "12345678910", "01987654321"); 59 EXPECT_TRUE(UpdateProfileLabel(&profile2)); 60 string16 summary2 = profile2.Label(); 61 // Summary does include full name which is empty if the first name is empty. 62 EXPECT_EQ(ASCIIToUTF16("Hollywood, CA"), summary2); 63 64 // Case 3: "<lastname>, <address>" 65 AutoFillProfile profile3; 66 autofill_test::SetProfileInfo(&profile3, "Billing", "", "Mitchell", 67 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", 68 "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); 69 EXPECT_TRUE(UpdateProfileLabel(&profile3)); 70 string16 summary3 = profile3.Label(); 71 EXPECT_EQ(ASCIIToUTF16("123 Zoo St., Hollywood"), summary3); 72 73 // Case 4: "<firstname>" 74 AutoFillProfile profile4; 75 autofill_test::SetProfileInfo(&profile4, "Billing", "Marion", "Mitchell", "", 76 "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", "91601", "US", 77 "12345678910", "01987654321"); 78 EXPECT_TRUE(UpdateProfileLabel(&profile4)); 79 string16 summary4 = profile4.Label(); 80 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell, Hollywood"), summary4); 81 82 // Case 5: "<firstname>, <address>" 83 AutoFillProfile profile5; 84 autofill_test::SetProfileInfo(&profile5, "Billing", "Marion", "Mitchell", "", 85 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", 86 "91601", "US", "12345678910", "01987654321"); 87 EXPECT_TRUE(UpdateProfileLabel(&profile5)); 88 string16 summary5 = profile5.Label(); 89 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell, 123 Zoo St."), summary5); 90 91 // Case 6: "<firstname> <lastname>" 92 AutoFillProfile profile6; 93 autofill_test::SetProfileInfo(&profile6, "Billing", "Marion", "Mitchell", 94 "Morrison", "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", 95 "91601", "US", "12345678910", "01987654321"); 96 EXPECT_TRUE(UpdateProfileLabel(&profile6)); 97 string16 summary6 = profile6.Label(); 98 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell Morrison, Hollywood"), 99 summary6); 100 101 // Case 7: "<firstname> <lastname>, <address>" 102 AutoFillProfile profile7; 103 autofill_test::SetProfileInfo(&profile7, "Billing", "Marion", "Mitchell", 104 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", 105 "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); 106 EXPECT_TRUE(UpdateProfileLabel(&profile7)); 107 string16 summary7 = profile7.Label(); 108 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell Morrison, 123 Zoo St."), 109 summary7); 110 111 // Case 7a: "<firstname> <lastname>, <address>" - same as #7, except for 112 // e-mail. 113 AutoFillProfile profile7a; 114 autofill_test::SetProfileInfo(&profile7a, "Billing", "Marion", "Mitchell", 115 "Morrison", "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", 116 "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); 117 std::vector<AutoFillProfile*> profiles; 118 profiles.push_back(&profile7); 119 profiles.push_back(&profile7a); 120 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles)); 121 summary7 = profile7.Label(); 122 string16 summary7a = profile7a.Label(); 123 EXPECT_EQ(ASCIIToUTF16( 124 "Marion Mitchell Morrison, 123 Zoo St., johnwayne@me.xyz"), summary7); 125 EXPECT_EQ(ASCIIToUTF16( 126 "Marion Mitchell Morrison, 123 Zoo St., marion@me.xyz"), summary7a); 127} 128 129TEST(AutoFillProfileTest, AdjustInferredLabels) { 130 std::vector<AutoFillProfile*> profiles; 131 profiles.push_back(new AutoFillProfile); 132 autofill_test::SetProfileInfo( 133 profiles[0], 134 "", 135 "John", 136 "", 137 "Doe", 138 "johndoe@hades.com", 139 "Underworld", 140 "666 Erebus St.", 141 "", 142 "Elysium", "CA", 143 "91111", 144 "US", 145 "11111111111", 146 "22222222222"); 147 profiles.push_back(new AutoFillProfile); 148 autofill_test::SetProfileInfo( 149 profiles[1], 150 "", 151 "Jane", 152 "", 153 "Doe", 154 "janedoe@tertium.com", 155 "Pluto Inc.", 156 "123 Letha Shore.", 157 "", 158 "Dis", "CA", 159 "91222", 160 "US", 161 "12345678910", 162 "01987654321"); 163 // As labels are empty they are adjusted the first time. 164 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles)); 165 // No need to adjust them anymore. 166 EXPECT_FALSE(AutoFillProfile::AdjustInferredLabels(&profiles)); 167 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St."), 168 profiles[0]->Label()); 169 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), 170 profiles[1]->Label()); 171 172 profiles.push_back(new AutoFillProfile); 173 autofill_test::SetProfileInfo( 174 profiles[2], 175 "", 176 "John", 177 "", 178 "Doe", 179 "johndoe@tertium.com", 180 "Underworld", 181 "666 Erebus St.", 182 "", 183 "Elysium", "CA", 184 "91111", 185 "US", 186 "11111111111", 187 "22222222222"); 188 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles)); 189 190 // Profile 0 and 2 inferred label now includes an e-mail. 191 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@hades.com"), 192 profiles[0]->Label()); 193 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), 194 profiles[1]->Label()); 195 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@tertium.com"), 196 profiles[2]->Label()); 197 198 delete profiles[2]; 199 profiles.pop_back(); 200 201 profiles.push_back(new AutoFillProfile); 202 autofill_test::SetProfileInfo( 203 profiles[2], 204 "", 205 "John", 206 "", 207 "Doe", 208 "johndoe@hades.com", 209 "Underworld", 210 "666 Erebus St.", 211 "", 212 "Elysium", "CA", 213 "91111", 214 "US", 215 "11111111111", 216 "33333333333"); // Fax is different 217 218 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles)); 219 220 // Profile 0 and 2 inferred label now includes a fax number. 221 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., fax:#22222222222"), 222 profiles[0]->Label()); 223 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), 224 profiles[1]->Label()); 225 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., fax:#33333333333"), 226 profiles[2]->Label()); 227 228 profiles.push_back(new AutoFillProfile); 229 autofill_test::SetProfileInfo( 230 profiles[3], 231 "", 232 "John", 233 "", 234 "Doe", 235 "johndoe@hades.com", 236 "Underworld", 237 "666 Erebus St.", 238 "", 239 "Elysium", "CA", 240 "91111", 241 "US", 242 "44444444444", // Phone is different for some. 243 "33333333333"); // Fax is different for some. 244 245 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles)); 246 247 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., 11111111111," 248 " fax:#22222222222"), 249 profiles[0]->Label()); 250 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), 251 profiles[1]->Label()); 252 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., 11111111111," 253 " fax:#33333333333"), 254 profiles[2]->Label()); 255 // This one differs from other ones by unique phone, so no need for extra 256 // information. 257 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., 44444444444"), 258 profiles[3]->Label()); 259 260 profiles.push_back(new AutoFillProfile); 261 autofill_test::SetProfileInfo( 262 profiles[4], 263 "", 264 "John", 265 "", 266 "Doe", 267 "johndoe@styx.com", // E-Mail is different for some. 268 "Underworld", 269 "666 Erebus St.", 270 "", 271 "Elysium", "CA", 272 "91111", 273 "US", 274 "44444444444", // Phone is different for some. 275 "33333333333"); // Fax is different for some. 276 277 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles)); 278 279 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@hades.com," 280 " 11111111111, fax:#22222222222"), 281 profiles[0]->Label()); 282 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), 283 profiles[1]->Label()); 284 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@hades.com," 285 " 11111111111, fax:#33333333333"), 286 profiles[2]->Label()); 287 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@hades.com," 288 " 44444444444, fax:#33333333333"), 289 profiles[3]->Label()); 290 // This one differs from other ones by unique e-mail, so no need for extra 291 // information. 292 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@styx.com"), 293 profiles[4]->Label()); 294 295 EXPECT_FALSE(AutoFillProfile::AdjustInferredLabels(&profiles)); 296 297 // Clean up. 298 STLDeleteContainerPointers(profiles.begin(), profiles.end()); 299} 300 301TEST(AutoFillProfileTest, CreateInferredLabels) { 302 std::vector<AutoFillProfile*> profiles; 303 profiles.push_back(new AutoFillProfile); 304 autofill_test::SetProfileInfo(profiles[0], 305 "", 306 "John", 307 "", 308 "Doe", 309 "johndoe@hades.com", 310 "Underworld", 311 "666 Erebus St.", 312 "", 313 "Elysium", "CA", 314 "91111", 315 "US", 316 "11111111111", 317 "22222222222"); 318 profiles.push_back(new AutoFillProfile); 319 autofill_test::SetProfileInfo(profiles[1], 320 "", 321 "Jane", 322 "", 323 "Doe", 324 "janedoe@tertium.com", 325 "Pluto Inc.", 326 "123 Letha Shore.", 327 "", 328 "Dis", "CA", 329 "91222", 330 "US", 331 "12345678910", 332 "01987654321"); 333 std::vector<string16> labels; 334 // Two fields at least - no filter. 335 AutoFillProfile::CreateInferredLabels(&profiles, NULL, UNKNOWN_TYPE, 2, 336 &labels); 337 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St."), labels[0]); 338 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); 339 340 // Three fields at least - no filter. 341 AutoFillProfile::CreateInferredLabels(&profiles, NULL, UNKNOWN_TYPE, 3, 342 &labels); 343 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., Elysium"), 344 labels[0]); 345 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore., Dis"), 346 labels[1]); 347 348 std::vector<AutoFillFieldType> suggested_fields; 349 suggested_fields.push_back(ADDRESS_HOME_CITY); 350 suggested_fields.push_back(ADDRESS_HOME_STATE); 351 suggested_fields.push_back(ADDRESS_HOME_ZIP); 352 353 // Two fields at least, from suggested fields - no filter. 354 AutoFillProfile::CreateInferredLabels(&profiles, &suggested_fields, 355 UNKNOWN_TYPE, 2, &labels); 356 EXPECT_EQ(ASCIIToUTF16("Elysium, CA"), labels[0]); 357 EXPECT_EQ(ASCIIToUTF16("Dis, CA"), labels[1]); 358 359 // Three fields at least, from suggested fields - no filter. 360 AutoFillProfile::CreateInferredLabels(&profiles, &suggested_fields, 361 UNKNOWN_TYPE, 3, &labels); 362 EXPECT_EQ(ASCIIToUTF16("Elysium, CA, 91111"), labels[0]); 363 EXPECT_EQ(ASCIIToUTF16("Dis, CA, 91222"), labels[1]); 364 365 // Three fields at least, from suggested fields - but filter reduces available 366 // fields to two. 367 AutoFillProfile::CreateInferredLabels(&profiles, &suggested_fields, 368 ADDRESS_HOME_STATE, 3, &labels); 369 EXPECT_EQ(ASCIIToUTF16("Elysium, 91111"), labels[0]); 370 EXPECT_EQ(ASCIIToUTF16("Dis, 91222"), labels[1]); 371 372 suggested_fields.clear(); 373 // In our implementation we always display NAME_FULL for all NAME* fields... 374 suggested_fields.push_back(NAME_MIDDLE); 375 // One field at least, from suggested fields - no filter. 376 AutoFillProfile::CreateInferredLabels(&profiles, &suggested_fields, 377 UNKNOWN_TYPE, 1, &labels); 378 EXPECT_EQ(ASCIIToUTF16("John Doe"), labels[0]); 379 EXPECT_EQ(ASCIIToUTF16("Jane Doe"), labels[1]); 380 381 // One field at least, from suggested fields - filter the same as suggested 382 // field. 383 AutoFillProfile::CreateInferredLabels(&profiles, &suggested_fields, 384 NAME_MIDDLE, 1, &labels); 385 EXPECT_EQ(string16(), labels[0]); 386 EXPECT_EQ(string16(), labels[1]); 387 388 // One field at least, from suggested fields - filter same as the first non- 389 // unknown suggested field. 390 suggested_fields.clear(); 391 suggested_fields.push_back(UNKNOWN_TYPE); 392 suggested_fields.push_back(NAME_FULL); 393 suggested_fields.push_back(ADDRESS_HOME_LINE1); 394 AutoFillProfile::CreateInferredLabels(&profiles, &suggested_fields, NAME_FULL, 395 1, &labels); 396 EXPECT_EQ(string16(ASCIIToUTF16("666 Erebus St.")), labels[0]); 397 EXPECT_EQ(string16(ASCIIToUTF16("123 Letha Shore.")), labels[1]); 398 399 // Clean up. 400 STLDeleteContainerPointers(profiles.begin(), profiles.end()); 401} 402 403// Test that we fall back to using the full name if there are no other 404// distinguishing fields, but only if it makes sense given the suggested fields. 405TEST(AutoFillProfileTest, CreateInferredLabelsFallsBackToFullName) { 406 ScopedVector<AutoFillProfile> profiles; 407 profiles.push_back(new AutoFillProfile); 408 autofill_test::SetProfileInfo(profiles[0], 409 "", "John", "", "Doe", "doe@example.com", "", 410 "88 Nowhere Ave.", "", "", "", "", "", "", ""); 411 profiles.push_back(new AutoFillProfile); 412 autofill_test::SetProfileInfo(profiles[1], 413 "", "Johnny", "K", "Doe", "doe@example.com", "", 414 "88 Nowhere Ave.", "", "", "", "", "", "", ""); 415 416 // If the only name field in the suggested fields is the excluded field, we 417 // should not fall back to the full name as a distinguishing field. 418 std::vector<AutoFillFieldType> suggested_fields; 419 suggested_fields.push_back(NAME_LAST); 420 suggested_fields.push_back(ADDRESS_HOME_LINE1); 421 suggested_fields.push_back(EMAIL_ADDRESS); 422 std::vector<string16> labels; 423 AutoFillProfile::CreateInferredLabels(&profiles.get(), &suggested_fields, 424 NAME_LAST, 1, &labels); 425 ASSERT_EQ(2U, labels.size()); 426 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave."), labels[0]); 427 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave."), labels[1]); 428 429 // Otherwise, we should. 430 suggested_fields.push_back(NAME_FIRST); 431 AutoFillProfile::CreateInferredLabels(&profiles.get(), &suggested_fields, 432 NAME_LAST, 1, &labels); 433 ASSERT_EQ(2U, labels.size()); 434 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., John Doe"), labels[0]); 435 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., Johnny K Doe"), labels[1]); 436} 437 438// Test that we do not show duplicate fields in the labels. 439TEST(AutoFillProfileTest, CreateInferredLabelsNoDuplicatedFields) { 440 ScopedVector<AutoFillProfile> profiles; 441 profiles.push_back(new AutoFillProfile); 442 autofill_test::SetProfileInfo(profiles[0], 443 "", "John", "", "Doe", "doe@example.com", "", 444 "88 Nowhere Ave.", "", "", "", "", "", "", ""); 445 profiles.push_back(new AutoFillProfile); 446 autofill_test::SetProfileInfo(profiles[1], 447 "", "John", "", "Doe", "dojo@example.com", "", 448 "88 Nowhere Ave.", "", "", "", "", "", "", ""); 449 450 // If the only name field in the suggested fields is the excluded field, we 451 // should not fall back to the full name as a distinguishing field. 452 std::vector<AutoFillFieldType> suggested_fields; 453 suggested_fields.push_back(ADDRESS_HOME_LINE1); 454 suggested_fields.push_back(ADDRESS_BILLING_LINE1); 455 suggested_fields.push_back(EMAIL_ADDRESS); 456 std::vector<string16> labels; 457 AutoFillProfile::CreateInferredLabels(&profiles.get(), &suggested_fields, 458 UNKNOWN_TYPE, 2, &labels); 459 ASSERT_EQ(2U, labels.size()); 460 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., doe@example.com"), labels[0]); 461 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., dojo@example.com"), labels[1]); 462} 463 464// Make sure that empty fields are not treated as distinguishing fields. 465TEST(AutoFillProfileTest, CreateInferredLabelsSkipsEmptyFields) { 466 ScopedVector<AutoFillProfile> profiles; 467 profiles.push_back(new AutoFillProfile); 468 autofill_test::SetProfileInfo(profiles[0], 469 "", "John", "", "Doe", "doe@example.com", 470 "Gogole", "", "", "", "", "", "", "", ""); 471 profiles.push_back(new AutoFillProfile); 472 autofill_test::SetProfileInfo(profiles[1], 473 "", "John", "", "Doe", "doe@example.com", 474 "Ggoole", "", "", "", "", "", "", "", ""); 475 profiles.push_back(new AutoFillProfile); 476 autofill_test::SetProfileInfo(profiles[2], 477 "", "John", "", "Doe", "john.doe@example.com", 478 "Goolge", "", "", "", "", "", "", "", ""); 479 480 std::vector<string16> labels; 481 AutoFillProfile::CreateInferredLabels(&profiles.get(), NULL, UNKNOWN_TYPE, 3, 482 &labels); 483 ASSERT_EQ(3U, labels.size()); 484 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Gogole"), labels[0]); 485 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Ggoole"), labels[1]); 486 EXPECT_EQ(ASCIIToUTF16("John Doe, john.doe@example.com, Goolge"), labels[2]); 487 488 // A field must have a non-empty value for each profile to be considered a 489 // distinguishing field. 490 profiles[1]->SetInfo(AutoFillType(ADDRESS_HOME_LINE1), 491 ASCIIToUTF16("88 Nowhere Ave.")); 492 AutoFillProfile::CreateInferredLabels(&profiles.get(), NULL, UNKNOWN_TYPE, 1, 493 &labels); 494 ASSERT_EQ(3U, labels.size()); 495 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Gogole"), labels[0]); 496 EXPECT_EQ(ASCIIToUTF16("John Doe, 88 Nowhere Ave., doe@example.com, Ggoole"), 497 labels[1]) << labels[1]; 498 EXPECT_EQ(ASCIIToUTF16("John Doe, john.doe@example.com"), labels[2]); 499} 500 501TEST(AutoFillProfileTest, IsSubsetOf) { 502 scoped_ptr<AutoFillProfile> a, b; 503 504 // |a| is a subset of |b|. 505 a.reset(new AutoFillProfile); 506 b.reset(new AutoFillProfile); 507 autofill_test::SetProfileInfo(a.get(), "label1", "Thomas", NULL, "Jefferson", 508 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, 509 NULL, NULL); 510 autofill_test::SetProfileInfo(b.get(), "label2", "Thomas", NULL, "Jefferson", 511 "declaration_guy@gmail.com", "United States Government", "Monticello", 512 NULL, "Charlottesville", "Virginia", "22902", NULL, NULL, NULL); 513 EXPECT_TRUE(a->IsSubsetOf(*b)); 514 515 // |b| is not a subset of |a|. 516 EXPECT_FALSE(b->IsSubsetOf(*a)); 517 518 // |a| is a subset of |a|. 519 EXPECT_TRUE(a->IsSubsetOf(*a)); 520 521 // One field in |b| is different. 522 a.reset(new AutoFillProfile); 523 b.reset(new AutoFillProfile); 524 autofill_test::SetProfileInfo(a.get(), "label1", "Thomas", NULL, "Jefferson", 525 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, 526 NULL, NULL); 527 autofill_test::SetProfileInfo(a.get(), "label2", "Thomas", NULL, "Adams", 528 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, 529 NULL, NULL); 530 EXPECT_FALSE(a->IsSubsetOf(*b)); 531} 532 533TEST(AutoFillProfileTest, IntersectionOfTypesHasEqualValues) { 534 scoped_ptr<AutoFillProfile> a, b; 535 536 // Intersection of types contains the fields NAME_FIRST, NAME_LAST, 537 // EMAIL_ADDRESS. The values of these field types are equal between the two 538 // profiles. 539 a.reset(new AutoFillProfile); 540 b.reset(new AutoFillProfile); 541 autofill_test::SetProfileInfo(a.get(), "label1", "Thomas", NULL, "Jefferson", 542 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, 543 "12134759123", "19384284720"); 544 autofill_test::SetProfileInfo(b.get(), "label2", "Thomas", NULL, "Jefferson", 545 "declaration_guy@gmail.com", "United States Government", "Monticello", 546 NULL, "Charlottesville", "Virginia", "22902", NULL, NULL, NULL); 547 EXPECT_TRUE(a->IntersectionOfTypesHasEqualValues(*b)); 548 549 // Intersection of types contains the fields NAME_FIRST, NAME_LAST, 550 // EMAIL_ADDRESS. The value of EMAIL_ADDRESS differs between the two profiles. 551 a.reset(new AutoFillProfile); 552 b.reset(new AutoFillProfile); 553 autofill_test::SetProfileInfo(a.get(), "label1", "Thomas", NULL, "Jefferson", 554 "poser@yahoo.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, 555 "12134759123", "19384284720"); 556 autofill_test::SetProfileInfo(b.get(), "label2", "Thomas", NULL, "Jefferson",\ 557 "declaration_guy@gmail.com", "United States Government", "Monticello", 558 NULL, "Charlottesville", "Virginia", "22902", NULL, NULL, NULL); 559 EXPECT_FALSE(a->IntersectionOfTypesHasEqualValues(*b)); 560 561 // Intersection of types is empty. 562 a.reset(new AutoFillProfile); 563 b.reset(new AutoFillProfile); 564 autofill_test::SetProfileInfo(a.get(), "label1", "Thomas", NULL, "Jefferson", 565 "poser@yahoo.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, 566 "12134759123", "19384284720"); 567 autofill_test::SetProfileInfo(b.get(), "label2", NULL, NULL, NULL, NULL, 568 "United States Government", "Monticello", NULL, "Charlottesville", 569 "Virginia", "22902", NULL, NULL, NULL); 570 EXPECT_FALSE(a->IntersectionOfTypesHasEqualValues(*b)); 571} 572 573TEST(AutoFillProfileTest, MergeWith) { 574 scoped_ptr<AutoFillProfile> a, b; 575 576 // Merge |b| into |a|. 577 a.reset(new AutoFillProfile); 578 b.reset(new AutoFillProfile); 579 autofill_test::SetProfileInfo(a.get(), "label1", "Jimmy", NULL, NULL, NULL, 580 NULL, NULL, NULL, NULL, NULL, NULL, NULL, "12134759123", "19384284720"); 581 autofill_test::SetProfileInfo(b.get(), "label2", "James", NULL, "Madison", 582 "constitutionalist@gmail.com", "United States Government", "Monticello", 583 NULL, "Charlottesville", "Virginia", "22902", NULL, NULL, NULL); 584 AutoFillProfile expected_b(*b); 585 a->MergeWith(*b); 586 587 AutoFillProfile expected_a; 588 autofill_test::SetProfileInfo(&expected_a, "label1", "Jimmy", NULL, "Madison", 589 "constitutionalist@gmail.com", "United States Government", "Monticello", 590 NULL, "Charlottesville", "Virginia", "22902", NULL, "12134759123", 591 "19384284720"); 592 EXPECT_EQ(0, expected_a.Compare(*a)); 593 EXPECT_EQ(0, expected_b.Compare(*b)); 594} 595 596TEST(AutoFillProfileTest, AssignmentOperator){ 597 AutoFillProfile a, b; 598 599 // Result of assignment should be logically equal to the original profile. 600 autofill_test::SetProfileInfo(&a, "Billing", "Marion", "Mitchell", "Morrison", 601 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", 602 "Hollywood", "CA", "91601", "US", "12345678910", 603 "01987654321"); 604 b = a; 605 EXPECT_TRUE(a == b); 606 607 // Assignment to self should not change the profile value. 608 a = a; 609 EXPECT_TRUE(a == b); 610} 611 612TEST(AutoFillProfileTest, Clone) { 613 AutoFillProfile a; 614 615 // Clone should be logically equal to the original. 616 autofill_test::SetProfileInfo(&a, "Billing", "Marion", "Mitchell", "Morrison", 617 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", 618 "Hollywood", "CA", "91601", "US", "12345678910", 619 "01987654321"); 620 scoped_ptr<AutoFillProfile> b(static_cast<AutoFillProfile*>(a.Clone())); 621 EXPECT_TRUE(a == *b); 622} 623 624TEST(AutoFillProfileTest, Compare) { 625 AutoFillProfile a, b; 626 627 // Empty profiles are the same. 628 EXPECT_EQ(0, a.Compare(b)); 629 630 // GUIDs don't count. 631 a.set_guid(guid::GenerateGUID()); 632 b.set_guid(guid::GenerateGUID()); 633 EXPECT_EQ(0, a.Compare(b)); 634 635 // Different values produce non-zero results. 636 autofill_test::SetProfileInfo(&a, "label1", "Jimmy", NULL, NULL, NULL, 637 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); 638 autofill_test::SetProfileInfo(&b, "label1", "Ringo", NULL, NULL, NULL, 639 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); 640 EXPECT_GT(0, a.Compare(b)); 641 EXPECT_LT(0, b.Compare(a)); 642} 643 644} // namespace 645