OLD | NEW |
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" |
11 #include "chrome/browser/autofill/autofill_common_test.h" | 11 #include "chrome/browser/autofill/autofill_common_test.h" |
12 #include "chrome/browser/autofill/autofill_profile.h" | 12 #include "chrome/browser/autofill/autofill_profile.h" |
13 #include "chrome/common/guid.h" | 13 #include "chrome/common/guid.h" |
| 14 #include "chrome/test/testing_browser_process_test.h" |
14 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 bool UpdateProfileLabel(AutofillProfile *profile) { | 20 bool UpdateProfileLabel(AutofillProfile *profile) { |
20 std::vector<AutofillProfile*> profiles; | 21 std::vector<AutofillProfile*> profiles; |
21 profiles.push_back(profile); | 22 profiles.push_back(profile); |
22 return AutofillProfile::AdjustInferredLabels(&profiles); | 23 return AutofillProfile::AdjustInferredLabels(&profiles); |
23 } | 24 } |
24 | 25 |
25 } // namespace | 26 } // namespace |
26 | 27 |
| 28 typedef TestingBrowserProcessTest AutofillProfileTest; |
| 29 |
27 // Tests different possibilities for summary string generation. | 30 // Tests different possibilities for summary string generation. |
28 // Based on existence of first name, last name, and address line 1. | 31 // Based on existence of first name, last name, and address line 1. |
29 TEST(AutofillProfileTest, PreviewSummaryString) { | 32 TEST_F(AutofillProfileTest, PreviewSummaryString) { |
30 // Case 0/null: "" | 33 // Case 0/null: "" |
31 AutofillProfile profile0; | 34 AutofillProfile profile0; |
32 // Empty profile - nothing to update. | 35 // Empty profile - nothing to update. |
33 EXPECT_FALSE(UpdateProfileLabel(&profile0)); | 36 EXPECT_FALSE(UpdateProfileLabel(&profile0)); |
34 string16 summary0 = profile0.Label(); | 37 string16 summary0 = profile0.Label(); |
35 EXPECT_EQ(string16(), summary0); | 38 EXPECT_EQ(string16(), summary0); |
36 | 39 |
37 // Case 0a/empty name and address, so the first two fields of the rest of the | 40 // Case 0a/empty name and address, so the first two fields of the rest of the |
38 // data is used: "Hollywood, CA" | 41 // data is used: "Hollywood, CA" |
39 AutofillProfile profile00; | 42 AutofillProfile profile00; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 profiles.push_back(&profile7a); | 124 profiles.push_back(&profile7a); |
122 EXPECT_TRUE(AutofillProfile::AdjustInferredLabels(&profiles)); | 125 EXPECT_TRUE(AutofillProfile::AdjustInferredLabels(&profiles)); |
123 summary7 = profile7.Label(); | 126 summary7 = profile7.Label(); |
124 string16 summary7a = profile7a.Label(); | 127 string16 summary7a = profile7a.Label(); |
125 EXPECT_EQ(ASCIIToUTF16( | 128 EXPECT_EQ(ASCIIToUTF16( |
126 "Marion Mitchell Morrison, 123 Zoo St., johnwayne@me.xyz"), summary7); | 129 "Marion Mitchell Morrison, 123 Zoo St., johnwayne@me.xyz"), summary7); |
127 EXPECT_EQ(ASCIIToUTF16( | 130 EXPECT_EQ(ASCIIToUTF16( |
128 "Marion Mitchell Morrison, 123 Zoo St., marion@me.xyz"), summary7a); | 131 "Marion Mitchell Morrison, 123 Zoo St., marion@me.xyz"), summary7a); |
129 } | 132 } |
130 | 133 |
131 TEST(AutofillProfileTest, AdjustInferredLabels) { | 134 TEST_F(AutofillProfileTest, AdjustInferredLabels) { |
132 std::vector<AutofillProfile*> profiles; | 135 std::vector<AutofillProfile*> profiles; |
133 profiles.push_back(new AutofillProfile); | 136 profiles.push_back(new AutofillProfile); |
134 autofill_test::SetProfileInfo( | 137 autofill_test::SetProfileInfo( |
135 profiles[0], | 138 profiles[0], |
136 "John", | 139 "John", |
137 "", | 140 "", |
138 "Doe", | 141 "Doe", |
139 "johndoe@hades.com", | 142 "johndoe@hades.com", |
140 "Underworld", | 143 "Underworld", |
141 "666 Erebus St.", | 144 "666 Erebus St.", |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 // information. | 290 // information. |
288 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@styx.com"), | 291 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@styx.com"), |
289 profiles[4]->Label()); | 292 profiles[4]->Label()); |
290 | 293 |
291 EXPECT_FALSE(AutofillProfile::AdjustInferredLabels(&profiles)); | 294 EXPECT_FALSE(AutofillProfile::AdjustInferredLabels(&profiles)); |
292 | 295 |
293 // Clean up. | 296 // Clean up. |
294 STLDeleteContainerPointers(profiles.begin(), profiles.end()); | 297 STLDeleteContainerPointers(profiles.begin(), profiles.end()); |
295 } | 298 } |
296 | 299 |
297 TEST(AutofillProfileTest, CreateInferredLabels) { | 300 TEST_F(AutofillProfileTest, CreateInferredLabels) { |
298 std::vector<AutofillProfile*> profiles; | 301 std::vector<AutofillProfile*> profiles; |
299 profiles.push_back(new AutofillProfile); | 302 profiles.push_back(new AutofillProfile); |
300 autofill_test::SetProfileInfo(profiles[0], | 303 autofill_test::SetProfileInfo(profiles[0], |
301 "John", | 304 "John", |
302 "", | 305 "", |
303 "Doe", | 306 "Doe", |
304 "johndoe@hades.com", | 307 "johndoe@hades.com", |
305 "Underworld", | 308 "Underworld", |
306 "666 Erebus St.", | 309 "666 Erebus St.", |
307 "", | 310 "", |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 1, &labels); | 392 1, &labels); |
390 EXPECT_EQ(string16(ASCIIToUTF16("666 Erebus St.")), labels[0]); | 393 EXPECT_EQ(string16(ASCIIToUTF16("666 Erebus St.")), labels[0]); |
391 EXPECT_EQ(string16(ASCIIToUTF16("123 Letha Shore.")), labels[1]); | 394 EXPECT_EQ(string16(ASCIIToUTF16("123 Letha Shore.")), labels[1]); |
392 | 395 |
393 // Clean up. | 396 // Clean up. |
394 STLDeleteContainerPointers(profiles.begin(), profiles.end()); | 397 STLDeleteContainerPointers(profiles.begin(), profiles.end()); |
395 } | 398 } |
396 | 399 |
397 // Test that we fall back to using the full name if there are no other | 400 // Test that we fall back to using the full name if there are no other |
398 // distinguishing fields, but only if it makes sense given the suggested fields. | 401 // distinguishing fields, but only if it makes sense given the suggested fields. |
399 TEST(AutofillProfileTest, CreateInferredLabelsFallsBackToFullName) { | 402 TEST_F(AutofillProfileTest, CreateInferredLabelsFallsBackToFullName) { |
400 ScopedVector<AutofillProfile> profiles; | 403 ScopedVector<AutofillProfile> profiles; |
401 profiles.push_back(new AutofillProfile); | 404 profiles.push_back(new AutofillProfile); |
402 autofill_test::SetProfileInfo(profiles[0], | 405 autofill_test::SetProfileInfo(profiles[0], |
403 "John", "", "Doe", "doe@example.com", "", | 406 "John", "", "Doe", "doe@example.com", "", |
404 "88 Nowhere Ave.", "", "", "", "", "", "", ""); | 407 "88 Nowhere Ave.", "", "", "", "", "", "", ""); |
405 profiles.push_back(new AutofillProfile); | 408 profiles.push_back(new AutofillProfile); |
406 autofill_test::SetProfileInfo(profiles[1], | 409 autofill_test::SetProfileInfo(profiles[1], |
407 "Johnny", "K", "Doe", "doe@example.com", "", | 410 "Johnny", "K", "Doe", "doe@example.com", "", |
408 "88 Nowhere Ave.", "", "", "", "", "", "", ""); | 411 "88 Nowhere Ave.", "", "", "", "", "", "", ""); |
409 | 412 |
(...skipping 13 matching lines...) Expand all Loading... |
423 // Otherwise, we should. | 426 // Otherwise, we should. |
424 suggested_fields.push_back(NAME_FIRST); | 427 suggested_fields.push_back(NAME_FIRST); |
425 AutofillProfile::CreateInferredLabels(&profiles.get(), &suggested_fields, | 428 AutofillProfile::CreateInferredLabels(&profiles.get(), &suggested_fields, |
426 NAME_LAST, 1, &labels); | 429 NAME_LAST, 1, &labels); |
427 ASSERT_EQ(2U, labels.size()); | 430 ASSERT_EQ(2U, labels.size()); |
428 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., John Doe"), labels[0]); | 431 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., John Doe"), labels[0]); |
429 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., Johnny K Doe"), labels[1]); | 432 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., Johnny K Doe"), labels[1]); |
430 } | 433 } |
431 | 434 |
432 // Test that we do not show duplicate fields in the labels. | 435 // Test that we do not show duplicate fields in the labels. |
433 TEST(AutofillProfileTest, CreateInferredLabelsNoDuplicatedFields) { | 436 TEST_F(AutofillProfileTest, CreateInferredLabelsNoDuplicatedFields) { |
434 ScopedVector<AutofillProfile> profiles; | 437 ScopedVector<AutofillProfile> profiles; |
435 profiles.push_back(new AutofillProfile); | 438 profiles.push_back(new AutofillProfile); |
436 autofill_test::SetProfileInfo(profiles[0], | 439 autofill_test::SetProfileInfo(profiles[0], |
437 "John", "", "Doe", "doe@example.com", "", | 440 "John", "", "Doe", "doe@example.com", "", |
438 "88 Nowhere Ave.", "", "", "", "", "", "", ""); | 441 "88 Nowhere Ave.", "", "", "", "", "", "", ""); |
439 profiles.push_back(new AutofillProfile); | 442 profiles.push_back(new AutofillProfile); |
440 autofill_test::SetProfileInfo(profiles[1], | 443 autofill_test::SetProfileInfo(profiles[1], |
441 "John", "", "Doe", "dojo@example.com", "", | 444 "John", "", "Doe", "dojo@example.com", "", |
442 "88 Nowhere Ave.", "", "", "", "", "", "", ""); | 445 "88 Nowhere Ave.", "", "", "", "", "", "", ""); |
443 | 446 |
444 // If the only name field in the suggested fields is the excluded field, we | 447 // If the only name field in the suggested fields is the excluded field, we |
445 // should not fall back to the full name as a distinguishing field. | 448 // should not fall back to the full name as a distinguishing field. |
446 std::vector<AutofillFieldType> suggested_fields; | 449 std::vector<AutofillFieldType> suggested_fields; |
447 suggested_fields.push_back(ADDRESS_HOME_LINE1); | 450 suggested_fields.push_back(ADDRESS_HOME_LINE1); |
448 suggested_fields.push_back(ADDRESS_BILLING_LINE1); | 451 suggested_fields.push_back(ADDRESS_BILLING_LINE1); |
449 suggested_fields.push_back(EMAIL_ADDRESS); | 452 suggested_fields.push_back(EMAIL_ADDRESS); |
450 std::vector<string16> labels; | 453 std::vector<string16> labels; |
451 AutofillProfile::CreateInferredLabels(&profiles.get(), &suggested_fields, | 454 AutofillProfile::CreateInferredLabels(&profiles.get(), &suggested_fields, |
452 UNKNOWN_TYPE, 2, &labels); | 455 UNKNOWN_TYPE, 2, &labels); |
453 ASSERT_EQ(2U, labels.size()); | 456 ASSERT_EQ(2U, labels.size()); |
454 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., doe@example.com"), labels[0]); | 457 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., doe@example.com"), labels[0]); |
455 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., dojo@example.com"), labels[1]); | 458 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., dojo@example.com"), labels[1]); |
456 } | 459 } |
457 | 460 |
458 // Make sure that empty fields are not treated as distinguishing fields. | 461 // Make sure that empty fields are not treated as distinguishing fields. |
459 TEST(AutofillProfileTest, CreateInferredLabelsSkipsEmptyFields) { | 462 TEST_F(AutofillProfileTest, CreateInferredLabelsSkipsEmptyFields) { |
460 ScopedVector<AutofillProfile> profiles; | 463 ScopedVector<AutofillProfile> profiles; |
461 profiles.push_back(new AutofillProfile); | 464 profiles.push_back(new AutofillProfile); |
462 autofill_test::SetProfileInfo(profiles[0], | 465 autofill_test::SetProfileInfo(profiles[0], |
463 "John", "", "Doe", "doe@example.com", | 466 "John", "", "Doe", "doe@example.com", |
464 "Gogole", "", "", "", "", "", "", "", ""); | 467 "Gogole", "", "", "", "", "", "", "", ""); |
465 profiles.push_back(new AutofillProfile); | 468 profiles.push_back(new AutofillProfile); |
466 autofill_test::SetProfileInfo(profiles[1], | 469 autofill_test::SetProfileInfo(profiles[1], |
467 "John", "", "Doe", "doe@example.com", | 470 "John", "", "Doe", "doe@example.com", |
468 "Ggoole", "", "", "", "", "", "", "", ""); | 471 "Ggoole", "", "", "", "", "", "", "", ""); |
469 profiles.push_back(new AutofillProfile); | 472 profiles.push_back(new AutofillProfile); |
(...skipping 14 matching lines...) Expand all Loading... |
484 profiles[1]->SetInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("88 Nowhere Ave.")); | 487 profiles[1]->SetInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("88 Nowhere Ave.")); |
485 AutofillProfile::CreateInferredLabels(&profiles.get(), NULL, UNKNOWN_TYPE, 1, | 488 AutofillProfile::CreateInferredLabels(&profiles.get(), NULL, UNKNOWN_TYPE, 1, |
486 &labels); | 489 &labels); |
487 ASSERT_EQ(3U, labels.size()); | 490 ASSERT_EQ(3U, labels.size()); |
488 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Gogole"), labels[0]); | 491 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Gogole"), labels[0]); |
489 EXPECT_EQ(ASCIIToUTF16("John Doe, 88 Nowhere Ave., doe@example.com, Ggoole"), | 492 EXPECT_EQ(ASCIIToUTF16("John Doe, 88 Nowhere Ave., doe@example.com, Ggoole"), |
490 labels[1]) << labels[1]; | 493 labels[1]) << labels[1]; |
491 EXPECT_EQ(ASCIIToUTF16("John Doe, john.doe@example.com"), labels[2]); | 494 EXPECT_EQ(ASCIIToUTF16("John Doe, john.doe@example.com"), labels[2]); |
492 } | 495 } |
493 | 496 |
494 TEST(AutofillProfileTest, IsSubsetOf) { | 497 TEST_F(AutofillProfileTest, IsSubsetOf) { |
495 scoped_ptr<AutofillProfile> a, b; | 498 scoped_ptr<AutofillProfile> a, b; |
496 | 499 |
497 // |a| is a subset of |b|. | 500 // |a| is a subset of |b|. |
498 a.reset(new AutofillProfile); | 501 a.reset(new AutofillProfile); |
499 b.reset(new AutofillProfile); | 502 b.reset(new AutofillProfile); |
500 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson", | 503 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson", |
501 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, | 504 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
502 NULL, NULL); | 505 NULL, NULL); |
503 autofill_test::SetProfileInfo(b.get(), "Thomas", NULL, "Jefferson", | 506 autofill_test::SetProfileInfo(b.get(), "Thomas", NULL, "Jefferson", |
504 "declaration_guy@gmail.com", "United States Government", "Monticello", | 507 "declaration_guy@gmail.com", "United States Government", "Monticello", |
(...skipping 11 matching lines...) Expand all Loading... |
516 b.reset(new AutofillProfile); | 519 b.reset(new AutofillProfile); |
517 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson", | 520 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson", |
518 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, | 521 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
519 NULL, NULL); | 522 NULL, NULL); |
520 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Adams", | 523 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Adams", |
521 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, | 524 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
522 NULL, NULL); | 525 NULL, NULL); |
523 EXPECT_FALSE(a->IsSubsetOf(*b)); | 526 EXPECT_FALSE(a->IsSubsetOf(*b)); |
524 } | 527 } |
525 | 528 |
526 TEST(AutofillProfileTest, IntersectionOfTypesHasEqualValues) { | 529 TEST_F(AutofillProfileTest, IntersectionOfTypesHasEqualValues) { |
527 scoped_ptr<AutofillProfile> a, b; | 530 scoped_ptr<AutofillProfile> a, b; |
528 | 531 |
529 // Intersection of types contains the fields NAME_FIRST, NAME_LAST, | 532 // Intersection of types contains the fields NAME_FIRST, NAME_LAST, |
530 // EMAIL_ADDRESS. The values of these field types are equal between the two | 533 // EMAIL_ADDRESS. The values of these field types are equal between the two |
531 // profiles. | 534 // profiles. |
532 a.reset(new AutofillProfile); | 535 a.reset(new AutofillProfile); |
533 b.reset(new AutofillProfile); | 536 b.reset(new AutofillProfile); |
534 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson", | 537 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson", |
535 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, | 538 "declaration_guy@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
536 "12134759123", "19384284720"); | 539 "12134759123", "19384284720"); |
(...skipping 19 matching lines...) Expand all Loading... |
556 b.reset(new AutofillProfile); | 559 b.reset(new AutofillProfile); |
557 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson", | 560 autofill_test::SetProfileInfo(a.get(), "Thomas", NULL, "Jefferson", |
558 "poser@yahoo.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, | 561 "poser@yahoo.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
559 "12134759123", "19384284720"); | 562 "12134759123", "19384284720"); |
560 autofill_test::SetProfileInfo(b.get(), NULL, NULL, NULL, NULL, | 563 autofill_test::SetProfileInfo(b.get(), NULL, NULL, NULL, NULL, |
561 "United States Government", "Monticello", NULL, "Charlottesville", | 564 "United States Government", "Monticello", NULL, "Charlottesville", |
562 "Virginia", "22902", NULL, NULL, NULL); | 565 "Virginia", "22902", NULL, NULL, NULL); |
563 EXPECT_FALSE(a->IntersectionOfTypesHasEqualValues(*b)); | 566 EXPECT_FALSE(a->IntersectionOfTypesHasEqualValues(*b)); |
564 } | 567 } |
565 | 568 |
566 TEST(AutofillProfileTest, MergeWith) { | 569 TEST_F(AutofillProfileTest, MergeWith) { |
567 scoped_ptr<AutofillProfile> a, b; | 570 scoped_ptr<AutofillProfile> a, b; |
568 | 571 |
569 // Merge |b| into |a|. | 572 // Merge |b| into |a|. |
570 a.reset(new AutofillProfile); | 573 a.reset(new AutofillProfile); |
571 b.reset(new AutofillProfile); | 574 b.reset(new AutofillProfile); |
572 autofill_test::SetProfileInfo(a.get(), "Jimmy", NULL, NULL, NULL, | 575 autofill_test::SetProfileInfo(a.get(), "Jimmy", NULL, NULL, NULL, |
573 NULL, NULL, NULL, NULL, NULL, NULL, NULL, "12134759123", "19384284720"); | 576 NULL, NULL, NULL, NULL, NULL, NULL, NULL, "12134759123", "19384284720"); |
574 autofill_test::SetProfileInfo(b.get(), "James", NULL, "Madison", | 577 autofill_test::SetProfileInfo(b.get(), "James", NULL, "Madison", |
575 "constitutionalist@gmail.com", "United States Government", "Monticello", | 578 "constitutionalist@gmail.com", "United States Government", "Monticello", |
576 NULL, "Charlottesville", "Virginia", "22902", NULL, NULL, NULL); | 579 NULL, "Charlottesville", "Virginia", "22902", NULL, NULL, NULL); |
577 AutofillProfile expected_b(*b); | 580 AutofillProfile expected_b(*b); |
578 a->MergeWith(*b); | 581 a->MergeWith(*b); |
579 | 582 |
580 AutofillProfile expected_a; | 583 AutofillProfile expected_a; |
581 autofill_test::SetProfileInfo(&expected_a, "Jimmy", NULL, "Madison", | 584 autofill_test::SetProfileInfo(&expected_a, "Jimmy", NULL, "Madison", |
582 "constitutionalist@gmail.com", "United States Government", "Monticello", | 585 "constitutionalist@gmail.com", "United States Government", "Monticello", |
583 NULL, "Charlottesville", "Virginia", "22902", NULL, "12134759123", | 586 NULL, "Charlottesville", "Virginia", "22902", NULL, "12134759123", |
584 "19384284720"); | 587 "19384284720"); |
585 EXPECT_EQ(0, expected_a.Compare(*a)); | 588 EXPECT_EQ(0, expected_a.Compare(*a)); |
586 EXPECT_EQ(0, expected_b.Compare(*b)); | 589 EXPECT_EQ(0, expected_b.Compare(*b)); |
587 } | 590 } |
588 | 591 |
589 TEST(AutofillProfileTest, AssignmentOperator){ | 592 TEST_F(AutofillProfileTest, AssignmentOperator){ |
590 AutofillProfile a, b; | 593 AutofillProfile a, b; |
591 | 594 |
592 // Result of assignment should be logically equal to the original profile. | 595 // Result of assignment should be logically equal to the original profile. |
593 autofill_test::SetProfileInfo(&a, "Marion", "Mitchell", "Morrison", | 596 autofill_test::SetProfileInfo(&a, "Marion", "Mitchell", "Morrison", |
594 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", | 597 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
595 "Hollywood", "CA", "91601", "US", "12345678910", | 598 "Hollywood", "CA", "91601", "US", "12345678910", |
596 "01987654321"); | 599 "01987654321"); |
597 b = a; | 600 b = a; |
598 EXPECT_TRUE(a == b); | 601 EXPECT_TRUE(a == b); |
599 | 602 |
600 // Assignment to self should not change the profile value. | 603 // Assignment to self should not change the profile value. |
601 a = a; | 604 a = a; |
602 EXPECT_TRUE(a == b); | 605 EXPECT_TRUE(a == b); |
603 } | 606 } |
604 | 607 |
605 TEST(AutofillProfileTest, Copy) { | 608 TEST_F(AutofillProfileTest, Copy) { |
606 AutofillProfile a; | 609 AutofillProfile a; |
607 | 610 |
608 // Clone should be logically equal to the original. | 611 // Clone should be logically equal to the original. |
609 autofill_test::SetProfileInfo(&a, "Marion", "Mitchell", "Morrison", | 612 autofill_test::SetProfileInfo(&a, "Marion", "Mitchell", "Morrison", |
610 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", | 613 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
611 "Hollywood", "CA", "91601", "US", "12345678910", | 614 "Hollywood", "CA", "91601", "US", "12345678910", |
612 "01987654321"); | 615 "01987654321"); |
613 AutofillProfile b(a); | 616 AutofillProfile b(a); |
614 EXPECT_TRUE(a == b); | 617 EXPECT_TRUE(a == b); |
615 } | 618 } |
616 | 619 |
617 TEST(AutofillProfileTest, Compare) { | 620 TEST_F(AutofillProfileTest, Compare) { |
618 AutofillProfile a, b; | 621 AutofillProfile a, b; |
619 | 622 |
620 // Empty profiles are the same. | 623 // Empty profiles are the same. |
621 EXPECT_EQ(0, a.Compare(b)); | 624 EXPECT_EQ(0, a.Compare(b)); |
622 | 625 |
623 // GUIDs don't count. | 626 // GUIDs don't count. |
624 a.set_guid(guid::GenerateGUID()); | 627 a.set_guid(guid::GenerateGUID()); |
625 b.set_guid(guid::GenerateGUID()); | 628 b.set_guid(guid::GenerateGUID()); |
626 EXPECT_EQ(0, a.Compare(b)); | 629 EXPECT_EQ(0, a.Compare(b)); |
627 | 630 |
628 // Different values produce non-zero results. | 631 // Different values produce non-zero results. |
629 autofill_test::SetProfileInfo(&a, "Jimmy", NULL, NULL, NULL, | 632 autofill_test::SetProfileInfo(&a, "Jimmy", NULL, NULL, NULL, |
630 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); | 633 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
631 autofill_test::SetProfileInfo(&b, "Ringo", NULL, NULL, NULL, | 634 autofill_test::SetProfileInfo(&b, "Ringo", NULL, NULL, NULL, |
632 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); | 635 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
633 EXPECT_GT(0, a.Compare(b)); | 636 EXPECT_GT(0, a.Compare(b)); |
634 EXPECT_LT(0, b.Compare(a)); | 637 EXPECT_LT(0, b.Compare(a)); |
635 } | 638 } |
636 | 639 |
637 TEST(AutofillProfileTest, CountryCode) { | 640 TEST_F(AutofillProfileTest, CountryCode) { |
638 AutofillProfile profile; | 641 AutofillProfile profile; |
639 EXPECT_EQ(std::string(), profile.CountryCode()); | 642 EXPECT_EQ(std::string(), profile.CountryCode()); |
640 | 643 |
641 profile.SetCountryCode("US"); | 644 profile.SetCountryCode("US"); |
642 EXPECT_EQ("US", profile.CountryCode()); | 645 EXPECT_EQ("US", profile.CountryCode()); |
643 } | 646 } |
644 | 647 |
645 TEST(AutofillProfileTest, MultiValueNames) { | 648 TEST_F(AutofillProfileTest, MultiValueNames) { |
646 AutofillProfile p; | 649 AutofillProfile p; |
647 const string16 kJohnDoe(ASCIIToUTF16("John Doe")); | 650 const string16 kJohnDoe(ASCIIToUTF16("John Doe")); |
648 const string16 kJohnPDoe(ASCIIToUTF16("John P. Doe")); | 651 const string16 kJohnPDoe(ASCIIToUTF16("John P. Doe")); |
649 std::vector<string16> set_values; | 652 std::vector<string16> set_values; |
650 set_values.push_back(kJohnDoe); | 653 set_values.push_back(kJohnDoe); |
651 set_values.push_back(kJohnPDoe); | 654 set_values.push_back(kJohnPDoe); |
652 p.SetMultiInfo(NAME_FULL, set_values); | 655 p.SetMultiInfo(NAME_FULL, set_values); |
653 | 656 |
654 // Expect regular |GetInfo| returns the first element. | 657 // Expect regular |GetInfo| returns the first element. |
655 EXPECT_EQ(kJohnDoe, p.GetInfo(NAME_FULL)); | 658 EXPECT_EQ(kJohnDoe, p.GetInfo(NAME_FULL)); |
(...skipping 23 matching lines...) Expand all Loading... |
679 set_values.clear(); | 682 set_values.clear(); |
680 p.SetMultiInfo(NAME_FULL, set_values); | 683 p.SetMultiInfo(NAME_FULL, set_values); |
681 p.GetMultiInfo(NAME_FULL, &get_values); | 684 p.GetMultiInfo(NAME_FULL, &get_values); |
682 ASSERT_EQ(1UL, get_values.size()); | 685 ASSERT_EQ(1UL, get_values.size()); |
683 EXPECT_EQ(string16(), get_values[0]); | 686 EXPECT_EQ(string16(), get_values[0]); |
684 | 687 |
685 // Expect regular |GetInfo| returns empty value. | 688 // Expect regular |GetInfo| returns empty value. |
686 EXPECT_EQ(string16(), p.GetInfo(NAME_FULL)); | 689 EXPECT_EQ(string16(), p.GetInfo(NAME_FULL)); |
687 } | 690 } |
688 | 691 |
689 TEST(AutofillProfileTest, MultiValueEmails) { | 692 TEST_F(AutofillProfileTest, MultiValueEmails) { |
690 AutofillProfile p; | 693 AutofillProfile p; |
691 const string16 kJohnDoe(ASCIIToUTF16("john@doe.com")); | 694 const string16 kJohnDoe(ASCIIToUTF16("john@doe.com")); |
692 const string16 kJohnPDoe(ASCIIToUTF16("john_p@doe.com")); | 695 const string16 kJohnPDoe(ASCIIToUTF16("john_p@doe.com")); |
693 std::vector<string16> set_values; | 696 std::vector<string16> set_values; |
694 set_values.push_back(kJohnDoe); | 697 set_values.push_back(kJohnDoe); |
695 set_values.push_back(kJohnPDoe); | 698 set_values.push_back(kJohnPDoe); |
696 p.SetMultiInfo(EMAIL_ADDRESS, set_values); | 699 p.SetMultiInfo(EMAIL_ADDRESS, set_values); |
697 | 700 |
698 // Expect regular |GetInfo| returns the first element. | 701 // Expect regular |GetInfo| returns the first element. |
699 EXPECT_EQ(kJohnDoe, p.GetInfo(EMAIL_ADDRESS)); | 702 EXPECT_EQ(kJohnDoe, p.GetInfo(EMAIL_ADDRESS)); |
(...skipping 23 matching lines...) Expand all Loading... |
723 set_values.clear(); | 726 set_values.clear(); |
724 p.SetMultiInfo(EMAIL_ADDRESS, set_values); | 727 p.SetMultiInfo(EMAIL_ADDRESS, set_values); |
725 p.GetMultiInfo(EMAIL_ADDRESS, &get_values); | 728 p.GetMultiInfo(EMAIL_ADDRESS, &get_values); |
726 ASSERT_EQ(1UL, get_values.size()); | 729 ASSERT_EQ(1UL, get_values.size()); |
727 EXPECT_EQ(string16(), get_values[0]); | 730 EXPECT_EQ(string16(), get_values[0]); |
728 | 731 |
729 // Expect regular |GetInfo| returns empty value. | 732 // Expect regular |GetInfo| returns empty value. |
730 EXPECT_EQ(string16(), p.GetInfo(EMAIL_ADDRESS)); | 733 EXPECT_EQ(string16(), p.GetInfo(EMAIL_ADDRESS)); |
731 } | 734 } |
732 | 735 |
733 TEST(AutofillProfileTest, MultiValuePhone) { | 736 TEST_F(AutofillProfileTest, MultiValuePhone) { |
734 AutofillProfile p; | 737 AutofillProfile p; |
735 const string16 kJohnDoe(ASCIIToUTF16("4151112222")); | 738 const string16 kJohnDoe(ASCIIToUTF16("4151112222")); |
736 const string16 kJohnPDoe(ASCIIToUTF16("4151113333")); | 739 const string16 kJohnPDoe(ASCIIToUTF16("4151113333")); |
737 std::vector<string16> set_values; | 740 std::vector<string16> set_values; |
738 set_values.push_back(kJohnDoe); | 741 set_values.push_back(kJohnDoe); |
739 set_values.push_back(kJohnPDoe); | 742 set_values.push_back(kJohnPDoe); |
740 p.SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values); | 743 p.SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values); |
741 | 744 |
742 // Expect regular |GetInfo| returns the first element. | 745 // Expect regular |GetInfo| returns the first element. |
743 EXPECT_EQ(kJohnDoe, p.GetInfo(PHONE_HOME_WHOLE_NUMBER)); | 746 EXPECT_EQ(kJohnDoe, p.GetInfo(PHONE_HOME_WHOLE_NUMBER)); |
(...skipping 23 matching lines...) Expand all Loading... |
767 set_values.clear(); | 770 set_values.clear(); |
768 p.SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values); | 771 p.SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values); |
769 p.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &get_values); | 772 p.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &get_values); |
770 ASSERT_EQ(1UL, get_values.size()); | 773 ASSERT_EQ(1UL, get_values.size()); |
771 EXPECT_EQ(string16(), get_values[0]); | 774 EXPECT_EQ(string16(), get_values[0]); |
772 | 775 |
773 // Expect regular |GetInfo| returns empty value. | 776 // Expect regular |GetInfo| returns empty value. |
774 EXPECT_EQ(string16(), p.GetInfo(PHONE_HOME_WHOLE_NUMBER)); | 777 EXPECT_EQ(string16(), p.GetInfo(PHONE_HOME_WHOLE_NUMBER)); |
775 } | 778 } |
776 | 779 |
777 TEST(AutofillProfileTest, MultiValueFax) { | 780 TEST_F(AutofillProfileTest, MultiValueFax) { |
778 AutofillProfile p; | 781 AutofillProfile p; |
779 const string16 kJohnDoe(ASCIIToUTF16("4152112222")); | 782 const string16 kJohnDoe(ASCIIToUTF16("4152112222")); |
780 const string16 kJohnPDoe(ASCIIToUTF16("4153113333")); | 783 const string16 kJohnPDoe(ASCIIToUTF16("4153113333")); |
781 std::vector<string16> set_values; | 784 std::vector<string16> set_values; |
782 set_values.push_back(kJohnDoe); | 785 set_values.push_back(kJohnDoe); |
783 set_values.push_back(kJohnPDoe); | 786 set_values.push_back(kJohnPDoe); |
784 p.SetMultiInfo(PHONE_FAX_WHOLE_NUMBER, set_values); | 787 p.SetMultiInfo(PHONE_FAX_WHOLE_NUMBER, set_values); |
785 | 788 |
786 // Expect regular |GetInfo| returns the first element. | 789 // Expect regular |GetInfo| returns the first element. |
787 EXPECT_EQ(kJohnDoe, p.GetInfo(PHONE_FAX_WHOLE_NUMBER)); | 790 EXPECT_EQ(kJohnDoe, p.GetInfo(PHONE_FAX_WHOLE_NUMBER)); |
(...skipping 22 matching lines...) Expand all Loading... |
810 // Delete values. | 813 // Delete values. |
811 set_values.clear(); | 814 set_values.clear(); |
812 p.SetMultiInfo(PHONE_FAX_WHOLE_NUMBER, set_values); | 815 p.SetMultiInfo(PHONE_FAX_WHOLE_NUMBER, set_values); |
813 p.GetMultiInfo(PHONE_FAX_WHOLE_NUMBER, &get_values); | 816 p.GetMultiInfo(PHONE_FAX_WHOLE_NUMBER, &get_values); |
814 ASSERT_EQ(1UL, get_values.size()); | 817 ASSERT_EQ(1UL, get_values.size()); |
815 EXPECT_EQ(string16(), get_values[0]); | 818 EXPECT_EQ(string16(), get_values[0]); |
816 | 819 |
817 // Expect regular |GetInfo| returns empty value. | 820 // Expect regular |GetInfo| returns empty value. |
818 EXPECT_EQ(string16(), p.GetInfo(PHONE_FAX_WHOLE_NUMBER)); | 821 EXPECT_EQ(string16(), p.GetInfo(PHONE_FAX_WHOLE_NUMBER)); |
819 } | 822 } |
OLD | NEW |