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

Side by Side Diff: chrome/browser/webdata/autofill_table_unittest.cc

Issue 11360055: [Autofill] Rename GetInfo and SetInfo to GetRawInfo and SetRawInfo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase harder Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <vector> 5 #include <vector>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/guid.h" 8 #include "base/guid.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 ASSERT_EQ(2U, all_entries.size()); 538 ASSERT_EQ(2U, all_entries.size());
539 } 539 }
540 540
541 TEST_F(AutofillTableTest, AutofillProfile) { 541 TEST_F(AutofillTableTest, AutofillProfile) {
542 WebDatabase db; 542 WebDatabase db;
543 543
544 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); 544 ASSERT_EQ(sql::INIT_OK, db.Init(file_));
545 545
546 // Add a 'Home' profile. 546 // Add a 'Home' profile.
547 AutofillProfile home_profile; 547 AutofillProfile home_profile;
548 home_profile.SetInfo(NAME_FIRST, ASCIIToUTF16("John")); 548 home_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
549 home_profile.SetInfo(NAME_MIDDLE, ASCIIToUTF16("Q.")); 549 home_profile.SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("Q."));
550 home_profile.SetInfo(NAME_LAST, ASCIIToUTF16("Smith")); 550 home_profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Smith"));
551 home_profile.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16("js@smith.xyz")); 551 home_profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("js@smith.xyz"));
552 home_profile.SetInfo(COMPANY_NAME, ASCIIToUTF16("Google")); 552 home_profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Google"));
553 home_profile.SetInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1234 Apple Way")); 553 home_profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1234 Apple Way"));
554 home_profile.SetInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("unit 5")); 554 home_profile.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("unit 5"));
555 home_profile.SetInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Los Angeles")); 555 home_profile.SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Los Angeles"));
556 home_profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); 556 home_profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA"));
557 home_profile.SetInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90025")); 557 home_profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90025"));
558 home_profile.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); 558 home_profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
559 home_profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("18181234567")); 559 home_profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("18181234567"));
560 560
561 Time pre_creation_time = Time::Now(); 561 Time pre_creation_time = Time::Now();
562 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(home_profile)); 562 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(home_profile));
563 Time post_creation_time = Time::Now(); 563 Time post_creation_time = Time::Now();
564 564
565 // Get the 'Home' profile. 565 // Get the 'Home' profile.
566 AutofillProfile* db_profile; 566 AutofillProfile* db_profile;
567 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile( 567 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(
568 home_profile.guid(), &db_profile)); 568 home_profile.guid(), &db_profile));
569 EXPECT_EQ(home_profile, *db_profile); 569 EXPECT_EQ(home_profile, *db_profile);
570 sql::Statement s_home(db.GetSQLConnection()->GetUniqueStatement( 570 sql::Statement s_home(db.GetSQLConnection()->GetUniqueStatement(
571 "SELECT date_modified " 571 "SELECT date_modified "
572 "FROM autofill_profiles WHERE guid=?")); 572 "FROM autofill_profiles WHERE guid=?"));
573 s_home.BindString(0, home_profile.guid()); 573 s_home.BindString(0, home_profile.guid());
574 ASSERT_TRUE(s_home.is_valid()); 574 ASSERT_TRUE(s_home.is_valid());
575 ASSERT_TRUE(s_home.Step()); 575 ASSERT_TRUE(s_home.Step());
576 EXPECT_GE(s_home.ColumnInt64(0), pre_creation_time.ToTimeT()); 576 EXPECT_GE(s_home.ColumnInt64(0), pre_creation_time.ToTimeT());
577 EXPECT_LE(s_home.ColumnInt64(0), post_creation_time.ToTimeT()); 577 EXPECT_LE(s_home.ColumnInt64(0), post_creation_time.ToTimeT());
578 EXPECT_FALSE(s_home.Step()); 578 EXPECT_FALSE(s_home.Step());
579 delete db_profile; 579 delete db_profile;
580 580
581 // Add a 'Billing' profile. 581 // Add a 'Billing' profile.
582 AutofillProfile billing_profile = home_profile; 582 AutofillProfile billing_profile = home_profile;
583 billing_profile.set_guid(base::GenerateGUID()); 583 billing_profile.set_guid(base::GenerateGUID());
584 billing_profile.SetInfo(ADDRESS_HOME_LINE1, 584 billing_profile.SetRawInfo(ADDRESS_HOME_LINE1,
585 ASCIIToUTF16("5678 Bottom Street")); 585 ASCIIToUTF16("5678 Bottom Street"));
586 billing_profile.SetInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("suite 3")); 586 billing_profile.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("suite 3"));
587 587
588 pre_creation_time = Time::Now(); 588 pre_creation_time = Time::Now();
589 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(billing_profile)); 589 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(billing_profile));
590 post_creation_time = Time::Now(); 590 post_creation_time = Time::Now();
591 591
592 // Get the 'Billing' profile. 592 // Get the 'Billing' profile.
593 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile( 593 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(
594 billing_profile.guid(), &db_profile)); 594 billing_profile.guid(), &db_profile));
595 EXPECT_EQ(billing_profile, *db_profile); 595 EXPECT_EQ(billing_profile, *db_profile);
596 sql::Statement s_billing(db.GetSQLConnection()->GetUniqueStatement( 596 sql::Statement s_billing(db.GetSQLConnection()->GetUniqueStatement(
597 "SELECT date_modified FROM autofill_profiles WHERE guid=?")); 597 "SELECT date_modified FROM autofill_profiles WHERE guid=?"));
598 s_billing.BindString(0, billing_profile.guid()); 598 s_billing.BindString(0, billing_profile.guid());
599 ASSERT_TRUE(s_billing.is_valid()); 599 ASSERT_TRUE(s_billing.is_valid());
600 ASSERT_TRUE(s_billing.Step()); 600 ASSERT_TRUE(s_billing.Step());
601 EXPECT_GE(s_billing.ColumnInt64(0), pre_creation_time.ToTimeT()); 601 EXPECT_GE(s_billing.ColumnInt64(0), pre_creation_time.ToTimeT());
602 EXPECT_LE(s_billing.ColumnInt64(0), post_creation_time.ToTimeT()); 602 EXPECT_LE(s_billing.ColumnInt64(0), post_creation_time.ToTimeT());
603 EXPECT_FALSE(s_billing.Step()); 603 EXPECT_FALSE(s_billing.Step());
604 delete db_profile; 604 delete db_profile;
605 605
606 // Update the 'Billing' profile, name only. 606 // Update the 'Billing' profile, name only.
607 billing_profile.SetInfo(NAME_FIRST, ASCIIToUTF16("Jane")); 607 billing_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jane"));
608 Time pre_modification_time = Time::Now(); 608 Time pre_modification_time = Time::Now();
609 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti( 609 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(
610 billing_profile)); 610 billing_profile));
611 Time post_modification_time = Time::Now(); 611 Time post_modification_time = Time::Now();
612 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile( 612 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(
613 billing_profile.guid(), &db_profile)); 613 billing_profile.guid(), &db_profile));
614 EXPECT_EQ(billing_profile, *db_profile); 614 EXPECT_EQ(billing_profile, *db_profile);
615 sql::Statement s_billing_updated(db.GetSQLConnection()->GetUniqueStatement( 615 sql::Statement s_billing_updated(db.GetSQLConnection()->GetUniqueStatement(
616 "SELECT date_modified FROM autofill_profiles WHERE guid=?")); 616 "SELECT date_modified FROM autofill_profiles WHERE guid=?"));
617 s_billing_updated.BindString(0, billing_profile.guid()); 617 s_billing_updated.BindString(0, billing_profile.guid());
618 ASSERT_TRUE(s_billing_updated.is_valid()); 618 ASSERT_TRUE(s_billing_updated.is_valid());
619 ASSERT_TRUE(s_billing_updated.Step()); 619 ASSERT_TRUE(s_billing_updated.Step());
620 EXPECT_GE(s_billing_updated.ColumnInt64(0), 620 EXPECT_GE(s_billing_updated.ColumnInt64(0),
621 pre_modification_time.ToTimeT()); 621 pre_modification_time.ToTimeT());
622 EXPECT_LE(s_billing_updated.ColumnInt64(0), 622 EXPECT_LE(s_billing_updated.ColumnInt64(0),
623 post_modification_time.ToTimeT()); 623 post_modification_time.ToTimeT());
624 EXPECT_FALSE(s_billing_updated.Step()); 624 EXPECT_FALSE(s_billing_updated.Step());
625 delete db_profile; 625 delete db_profile;
626 626
627 // Update the 'Billing' profile. 627 // Update the 'Billing' profile.
628 billing_profile.SetInfo(NAME_FIRST, ASCIIToUTF16("Janice")); 628 billing_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Janice"));
629 billing_profile.SetInfo(NAME_MIDDLE, ASCIIToUTF16("C.")); 629 billing_profile.SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("C."));
630 billing_profile.SetInfo(NAME_FIRST, ASCIIToUTF16("Joplin")); 630 billing_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Joplin"));
631 billing_profile.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16("jane@singer.com")); 631 billing_profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("jane@singer.com"));
632 billing_profile.SetInfo(COMPANY_NAME, ASCIIToUTF16("Indy")); 632 billing_profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Indy"));
633 billing_profile.SetInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("Open Road")); 633 billing_profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("Open Road"));
634 billing_profile.SetInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Route 66")); 634 billing_profile.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Route 66"));
635 billing_profile.SetInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("NFA")); 635 billing_profile.SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("NFA"));
636 billing_profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("NY")); 636 billing_profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("NY"));
637 billing_profile.SetInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("10011")); 637 billing_profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("10011"));
638 billing_profile.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("United States")); 638 billing_profile.SetRawInfo(ADDRESS_HOME_COUNTRY,
639 billing_profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("18181230000")); 639 ASCIIToUTF16("United States"));
640 billing_profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER,
641 ASCIIToUTF16("18181230000"));
640 Time pre_modification_time_2 = Time::Now(); 642 Time pre_modification_time_2 = Time::Now();
641 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti( 643 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(
642 billing_profile)); 644 billing_profile));
643 Time post_modification_time_2 = Time::Now(); 645 Time post_modification_time_2 = Time::Now();
644 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile( 646 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(
645 billing_profile.guid(), &db_profile)); 647 billing_profile.guid(), &db_profile));
646 EXPECT_EQ(billing_profile, *db_profile); 648 EXPECT_EQ(billing_profile, *db_profile);
647 sql::Statement s_billing_updated_2(db.GetSQLConnection()->GetUniqueStatement( 649 sql::Statement s_billing_updated_2(db.GetSQLConnection()->GetUniqueStatement(
648 "SELECT date_modified FROM autofill_profiles WHERE guid=?")); 650 "SELECT date_modified FROM autofill_profiles WHERE guid=?"));
649 s_billing_updated_2.BindString(0, billing_profile.guid()); 651 s_billing_updated_2.BindString(0, billing_profile.guid());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 EXPECT_EQ(0, p.Compare(*db_profile)); 695 EXPECT_EQ(0, p.Compare(*db_profile));
694 delete db_profile; 696 delete db_profile;
695 697
696 // Delete values. 698 // Delete values.
697 set_values.clear(); 699 set_values.clear();
698 p.SetMultiInfo(NAME_FULL, set_values); 700 p.SetMultiInfo(NAME_FULL, set_values);
699 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(p)); 701 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(p));
700 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile)); 702 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile));
701 EXPECT_EQ(p, *db_profile); 703 EXPECT_EQ(p, *db_profile);
702 EXPECT_EQ(0, p.Compare(*db_profile)); 704 EXPECT_EQ(0, p.Compare(*db_profile));
703 EXPECT_EQ(string16(), db_profile->GetInfo(NAME_FULL)); 705 EXPECT_EQ(string16(), db_profile->GetRawInfo(NAME_FULL));
704 delete db_profile; 706 delete db_profile;
705 } 707 }
706 708
707 TEST_F(AutofillTableTest, AutofillProfileSingleValue) { 709 TEST_F(AutofillTableTest, AutofillProfileSingleValue) {
708 WebDatabase db; 710 WebDatabase db;
709 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); 711 ASSERT_EQ(sql::INIT_OK, db.Init(file_));
710 712
711 AutofillProfile p; 713 AutofillProfile p;
712 const string16 kJohnDoe(ASCIIToUTF16("John Doe")); 714 const string16 kJohnDoe(ASCIIToUTF16("John Doe"));
713 const string16 kJohnPDoe(ASCIIToUTF16("John P. Doe")); 715 const string16 kJohnPDoe(ASCIIToUTF16("John P. Doe"));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 EXPECT_EQ(0, p.Compare(*db_profile)); 772 EXPECT_EQ(0, p.Compare(*db_profile));
771 delete db_profile; 773 delete db_profile;
772 774
773 // Delete values. 775 // Delete values.
774 set_values.clear(); 776 set_values.clear();
775 p.SetMultiInfo(EMAIL_ADDRESS, set_values); 777 p.SetMultiInfo(EMAIL_ADDRESS, set_values);
776 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(p)); 778 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(p));
777 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile)); 779 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile));
778 EXPECT_EQ(p, *db_profile); 780 EXPECT_EQ(p, *db_profile);
779 EXPECT_EQ(0, p.Compare(*db_profile)); 781 EXPECT_EQ(0, p.Compare(*db_profile));
780 EXPECT_EQ(string16(), db_profile->GetInfo(EMAIL_ADDRESS)); 782 EXPECT_EQ(string16(), db_profile->GetRawInfo(EMAIL_ADDRESS));
781 delete db_profile; 783 delete db_profile;
782 } 784 }
783 785
784 TEST_F(AutofillTableTest, AutofillProfileMultiValuePhone) { 786 TEST_F(AutofillTableTest, AutofillProfileMultiValuePhone) {
785 WebDatabase db; 787 WebDatabase db;
786 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); 788 ASSERT_EQ(sql::INIT_OK, db.Init(file_));
787 789
788 AutofillProfile p; 790 AutofillProfile p;
789 const string16 kJohnDoe(ASCIIToUTF16("4151112222")); 791 const string16 kJohnDoe(ASCIIToUTF16("4151112222"));
790 const string16 kJohnPDoe(ASCIIToUTF16("4151113333")); 792 const string16 kJohnPDoe(ASCIIToUTF16("4151113333"));
(...skipping 20 matching lines...) Expand all
811 EXPECT_EQ(0, p.Compare(*db_profile)); 813 EXPECT_EQ(0, p.Compare(*db_profile));
812 delete db_profile; 814 delete db_profile;
813 815
814 // Delete values. 816 // Delete values.
815 set_values.clear(); 817 set_values.clear();
816 p.SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values); 818 p.SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values);
817 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(p)); 819 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(p));
818 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile)); 820 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(p.guid(), &db_profile));
819 EXPECT_EQ(p, *db_profile); 821 EXPECT_EQ(p, *db_profile);
820 EXPECT_EQ(0, p.Compare(*db_profile)); 822 EXPECT_EQ(0, p.Compare(*db_profile));
821 EXPECT_EQ(string16(), db_profile->GetInfo(EMAIL_ADDRESS)); 823 EXPECT_EQ(string16(), db_profile->GetRawInfo(EMAIL_ADDRESS));
822 delete db_profile; 824 delete db_profile;
823 } 825 }
824 826
825 TEST_F(AutofillTableTest, AutofillProfileTrash) { 827 TEST_F(AutofillTableTest, AutofillProfileTrash) {
826 WebDatabase db; 828 WebDatabase db;
827 829
828 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); 830 ASSERT_EQ(sql::INIT_OK, db.Init(file_));
829 831
830 std::vector<std::string> guids; 832 std::vector<std::string> guids;
831 db.GetAutofillTable()->GetAutofillProfilesInTrash(&guids); 833 db.GetAutofillTable()->GetAutofillProfilesInTrash(&guids);
(...skipping 16 matching lines...) Expand all
848 TEST_F(AutofillTableTest, AutofillProfileTrashInteraction) { 850 TEST_F(AutofillTableTest, AutofillProfileTrashInteraction) {
849 WebDatabase db; 851 WebDatabase db;
850 852
851 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); 853 ASSERT_EQ(sql::INIT_OK, db.Init(file_));
852 854
853 std::vector<std::string> guids; 855 std::vector<std::string> guids;
854 db.GetAutofillTable()->GetAutofillProfilesInTrash(&guids); 856 db.GetAutofillTable()->GetAutofillProfilesInTrash(&guids);
855 EXPECT_TRUE(guids.empty()); 857 EXPECT_TRUE(guids.empty());
856 858
857 AutofillProfile profile; 859 AutofillProfile profile;
858 profile.SetInfo(NAME_FIRST, ASCIIToUTF16("John")); 860 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
859 profile.SetInfo(NAME_MIDDLE, ASCIIToUTF16("Q.")); 861 profile.SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("Q."));
860 profile.SetInfo(NAME_LAST, ASCIIToUTF16("Smith")); 862 profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Smith"));
861 profile.SetInfo(EMAIL_ADDRESS,ASCIIToUTF16("js@smith.xyz")); 863 profile.SetRawInfo(EMAIL_ADDRESS,ASCIIToUTF16("js@smith.xyz"));
862 profile.SetInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1 Main St")); 864 profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1 Main St"));
863 profile.SetInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Los Angeles")); 865 profile.SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Los Angeles"));
864 profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); 866 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA"));
865 profile.SetInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90025")); 867 profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90025"));
866 profile.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); 868 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
867 869
868 // Mark this profile as in the trash. This stops |AddAutofillProfile| from 870 // Mark this profile as in the trash. This stops |AddAutofillProfile| from
869 // adding it. 871 // adding it.
870 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillGUIDToTrash(profile.guid())); 872 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillGUIDToTrash(profile.guid()));
871 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(profile)); 873 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(profile));
872 AutofillProfile* added_profile = NULL; 874 AutofillProfile* added_profile = NULL;
873 EXPECT_FALSE(db.GetAutofillTable()->GetAutofillProfile( 875 EXPECT_FALSE(db.GetAutofillTable()->GetAutofillProfile(
874 profile.guid(), &added_profile)); 876 profile.guid(), &added_profile));
875 EXPECT_EQ(static_cast<AutofillProfile*>(NULL), added_profile); 877 EXPECT_EQ(static_cast<AutofillProfile*>(NULL), added_profile);
876 878
877 // Add the profile for real this time. 879 // Add the profile for real this time.
878 EXPECT_TRUE(db.GetAutofillTable()->EmptyAutofillProfilesTrash()); 880 EXPECT_TRUE(db.GetAutofillTable()->EmptyAutofillProfilesTrash());
879 EXPECT_TRUE(db.GetAutofillTable()->GetAutofillProfilesInTrash(&guids)); 881 EXPECT_TRUE(db.GetAutofillTable()->GetAutofillProfilesInTrash(&guids));
880 EXPECT_TRUE(guids.empty()); 882 EXPECT_TRUE(guids.empty());
881 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(profile)); 883 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillProfile(profile));
882 EXPECT_TRUE(db.GetAutofillTable()->GetAutofillProfile(profile.guid(), 884 EXPECT_TRUE(db.GetAutofillTable()->GetAutofillProfile(profile.guid(),
883 &added_profile)); 885 &added_profile));
884 ASSERT_NE(static_cast<AutofillProfile*>(NULL), added_profile); 886 ASSERT_NE(static_cast<AutofillProfile*>(NULL), added_profile);
885 delete added_profile; 887 delete added_profile;
886 888
887 // Mark this profile as in the trash. This stops |UpdateAutofillProfileMulti| 889 // Mark this profile as in the trash. This stops |UpdateAutofillProfileMulti|
888 // from updating it. In normal operation a profile should not be both in the 890 // from updating it. In normal operation a profile should not be both in the
889 // trash and in the profiles table simultaneously. 891 // trash and in the profiles table simultaneously.
890 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillGUIDToTrash(profile.guid())); 892 EXPECT_TRUE(db.GetAutofillTable()->AddAutofillGUIDToTrash(profile.guid()));
891 profile.SetInfo(NAME_FIRST, ASCIIToUTF16("Jane")); 893 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jane"));
892 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(profile)); 894 EXPECT_TRUE(db.GetAutofillTable()->UpdateAutofillProfileMulti(profile));
893 AutofillProfile* updated_profile = NULL; 895 AutofillProfile* updated_profile = NULL;
894 EXPECT_TRUE(db.GetAutofillTable()->GetAutofillProfile( 896 EXPECT_TRUE(db.GetAutofillTable()->GetAutofillProfile(
895 profile.guid(), &updated_profile)); 897 profile.guid(), &updated_profile));
896 ASSERT_NE(static_cast<AutofillProfile*>(NULL), added_profile); 898 ASSERT_NE(static_cast<AutofillProfile*>(NULL), added_profile);
897 EXPECT_EQ(ASCIIToUTF16("John"), updated_profile->GetInfo(NAME_FIRST)); 899 EXPECT_EQ(ASCIIToUTF16("John"), updated_profile->GetRawInfo(NAME_FIRST));
898 delete updated_profile; 900 delete updated_profile;
899 901
900 // Try to delete the trashed profile. This stops |RemoveAutofillProfile| from 902 // Try to delete the trashed profile. This stops |RemoveAutofillProfile| from
901 // deleting it. In normal operation deletion is done by migration step, and 903 // deleting it. In normal operation deletion is done by migration step, and
902 // removal from trash is done by |WebDataService|. |RemoveAutofillProfile| 904 // removal from trash is done by |WebDataService|. |RemoveAutofillProfile|
903 // does remove the item from the trash if it is found however, so that if 905 // does remove the item from the trash if it is found however, so that if
904 // other clients remove it (via Sync say) then it is gone and doesn't need to 906 // other clients remove it (via Sync say) then it is gone and doesn't need to
905 // be processed further by |WebDataService|. 907 // be processed further by |WebDataService|.
906 EXPECT_TRUE(db.GetAutofillTable()->RemoveAutofillProfile(profile.guid())); 908 EXPECT_TRUE(db.GetAutofillTable()->RemoveAutofillProfile(profile.guid()));
907 AutofillProfile* removed_profile = NULL; 909 AutofillProfile* removed_profile = NULL;
(...skipping 12 matching lines...) Expand all
920 EXPECT_EQ(static_cast<AutofillProfile*>(NULL), removed_profile); 922 EXPECT_EQ(static_cast<AutofillProfile*>(NULL), removed_profile);
921 } 923 }
922 924
923 TEST_F(AutofillTableTest, CreditCard) { 925 TEST_F(AutofillTableTest, CreditCard) {
924 WebDatabase db; 926 WebDatabase db;
925 927
926 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); 928 ASSERT_EQ(sql::INIT_OK, db.Init(file_));
927 929
928 // Add a 'Work' credit card. 930 // Add a 'Work' credit card.
929 CreditCard work_creditcard; 931 CreditCard work_creditcard;
930 work_creditcard.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Jack Torrance")); 932 work_creditcard.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Jack Torrance"));
931 work_creditcard.SetInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("1234567890123456")); 933 work_creditcard.SetRawInfo(CREDIT_CARD_NUMBER,
932 work_creditcard.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("04")); 934 ASCIIToUTF16("1234567890123456"));
933 work_creditcard.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2013")); 935 work_creditcard.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("04"));
936 work_creditcard.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR,
937 ASCIIToUTF16("2013"));
934 938
935 Time pre_creation_time = Time::Now(); 939 Time pre_creation_time = Time::Now();
936 EXPECT_TRUE(db.GetAutofillTable()->AddCreditCard(work_creditcard)); 940 EXPECT_TRUE(db.GetAutofillTable()->AddCreditCard(work_creditcard));
937 Time post_creation_time = Time::Now(); 941 Time post_creation_time = Time::Now();
938 942
939 // Get the 'Work' credit card. 943 // Get the 'Work' credit card.
940 CreditCard* db_creditcard; 944 CreditCard* db_creditcard;
941 ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(work_creditcard.guid(), 945 ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(work_creditcard.guid(),
942 &db_creditcard)); 946 &db_creditcard));
943 EXPECT_EQ(work_creditcard, *db_creditcard); 947 EXPECT_EQ(work_creditcard, *db_creditcard);
944 sql::Statement s_work(db.GetSQLConnection()->GetUniqueStatement( 948 sql::Statement s_work(db.GetSQLConnection()->GetUniqueStatement(
945 "SELECT guid, name_on_card, expiration_month, expiration_year, " 949 "SELECT guid, name_on_card, expiration_month, expiration_year, "
946 "card_number_encrypted, date_modified " 950 "card_number_encrypted, date_modified "
947 "FROM credit_cards WHERE guid=?")); 951 "FROM credit_cards WHERE guid=?"));
948 s_work.BindString(0, work_creditcard.guid()); 952 s_work.BindString(0, work_creditcard.guid());
949 ASSERT_TRUE(s_work.is_valid()); 953 ASSERT_TRUE(s_work.is_valid());
950 ASSERT_TRUE(s_work.Step()); 954 ASSERT_TRUE(s_work.Step());
951 EXPECT_GE(s_work.ColumnInt64(5), pre_creation_time.ToTimeT()); 955 EXPECT_GE(s_work.ColumnInt64(5), pre_creation_time.ToTimeT());
952 EXPECT_LE(s_work.ColumnInt64(5), post_creation_time.ToTimeT()); 956 EXPECT_LE(s_work.ColumnInt64(5), post_creation_time.ToTimeT());
953 EXPECT_FALSE(s_work.Step()); 957 EXPECT_FALSE(s_work.Step());
954 delete db_creditcard; 958 delete db_creditcard;
955 959
956 // Add a 'Target' credit card. 960 // Add a 'Target' credit card.
957 CreditCard target_creditcard; 961 CreditCard target_creditcard;
958 target_creditcard.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Jack Torrance")); 962 target_creditcard.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Jack Torrance"));
959 target_creditcard.SetInfo(CREDIT_CARD_NUMBER, 963 target_creditcard.SetRawInfo(CREDIT_CARD_NUMBER,
960 ASCIIToUTF16("1111222233334444")); 964 ASCIIToUTF16("1111222233334444"));
961 target_creditcard.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("06")); 965 target_creditcard.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("06"));
962 target_creditcard.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2012")); 966 target_creditcard.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR,
967 ASCIIToUTF16("2012"));
963 968
964 pre_creation_time = Time::Now(); 969 pre_creation_time = Time::Now();
965 EXPECT_TRUE(db.GetAutofillTable()->AddCreditCard(target_creditcard)); 970 EXPECT_TRUE(db.GetAutofillTable()->AddCreditCard(target_creditcard));
966 post_creation_time = Time::Now(); 971 post_creation_time = Time::Now();
967 ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(target_creditcard.guid(), 972 ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(target_creditcard.guid(),
968 &db_creditcard)); 973 &db_creditcard));
969 EXPECT_EQ(target_creditcard, *db_creditcard); 974 EXPECT_EQ(target_creditcard, *db_creditcard);
970 sql::Statement s_target(db.GetSQLConnection()->GetUniqueStatement( 975 sql::Statement s_target(db.GetSQLConnection()->GetUniqueStatement(
971 "SELECT guid, name_on_card, expiration_month, expiration_year, " 976 "SELECT guid, name_on_card, expiration_month, expiration_year, "
972 "card_number_encrypted, date_modified " 977 "card_number_encrypted, date_modified "
973 "FROM credit_cards WHERE guid=?")); 978 "FROM credit_cards WHERE guid=?"));
974 s_target.BindString(0, target_creditcard.guid()); 979 s_target.BindString(0, target_creditcard.guid());
975 ASSERT_TRUE(s_target.is_valid()); 980 ASSERT_TRUE(s_target.is_valid());
976 ASSERT_TRUE(s_target.Step()); 981 ASSERT_TRUE(s_target.Step());
977 EXPECT_GE(s_target.ColumnInt64(5), pre_creation_time.ToTimeT()); 982 EXPECT_GE(s_target.ColumnInt64(5), pre_creation_time.ToTimeT());
978 EXPECT_LE(s_target.ColumnInt64(5), post_creation_time.ToTimeT()); 983 EXPECT_LE(s_target.ColumnInt64(5), post_creation_time.ToTimeT());
979 EXPECT_FALSE(s_target.Step()); 984 EXPECT_FALSE(s_target.Step());
980 delete db_creditcard; 985 delete db_creditcard;
981 986
982 // Update the 'Target' credit card. 987 // Update the 'Target' credit card.
983 target_creditcard.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Charles Grady")); 988 target_creditcard.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Charles Grady"));
984 Time pre_modification_time = Time::Now(); 989 Time pre_modification_time = Time::Now();
985 EXPECT_TRUE(db.GetAutofillTable()->UpdateCreditCard(target_creditcard)); 990 EXPECT_TRUE(db.GetAutofillTable()->UpdateCreditCard(target_creditcard));
986 Time post_modification_time = Time::Now(); 991 Time post_modification_time = Time::Now();
987 ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(target_creditcard.guid(), 992 ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(target_creditcard.guid(),
988 &db_creditcard)); 993 &db_creditcard));
989 EXPECT_EQ(target_creditcard, *db_creditcard); 994 EXPECT_EQ(target_creditcard, *db_creditcard);
990 sql::Statement s_target_updated(db.GetSQLConnection()->GetUniqueStatement( 995 sql::Statement s_target_updated(db.GetSQLConnection()->GetUniqueStatement(
991 "SELECT guid, name_on_card, expiration_month, expiration_year, " 996 "SELECT guid, name_on_card, expiration_month, expiration_year, "
992 "card_number_encrypted, date_modified " 997 "card_number_encrypted, date_modified "
993 "FROM credit_cards WHERE guid=?")); 998 "FROM credit_cards WHERE guid=?"));
(...skipping 11 matching lines...) Expand all
1005 EXPECT_FALSE(db.GetAutofillTable()->GetCreditCard(target_creditcard.guid(), 1010 EXPECT_FALSE(db.GetAutofillTable()->GetCreditCard(target_creditcard.guid(),
1006 &db_creditcard)); 1011 &db_creditcard));
1007 } 1012 }
1008 1013
1009 TEST_F(AutofillTableTest, UpdateAutofillProfile) { 1014 TEST_F(AutofillTableTest, UpdateAutofillProfile) {
1010 WebDatabase db; 1015 WebDatabase db;
1011 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); 1016 ASSERT_EQ(sql::INIT_OK, db.Init(file_));
1012 1017
1013 // Add a profile to the db. 1018 // Add a profile to the db.
1014 AutofillProfile profile; 1019 AutofillProfile profile;
1015 profile.SetInfo(NAME_FIRST, ASCIIToUTF16("John")); 1020 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
1016 profile.SetInfo(NAME_MIDDLE, ASCIIToUTF16("Q.")); 1021 profile.SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("Q."));
1017 profile.SetInfo(NAME_LAST, ASCIIToUTF16("Smith")); 1022 profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Smith"));
1018 profile.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16("js@example.com")); 1023 profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("js@example.com"));
1019 profile.SetInfo(COMPANY_NAME, ASCIIToUTF16("Google")); 1024 profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Google"));
1020 profile.SetInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1234 Apple Way")); 1025 profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1234 Apple Way"));
1021 profile.SetInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("unit 5")); 1026 profile.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("unit 5"));
1022 profile.SetInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Los Angeles")); 1027 profile.SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Los Angeles"));
1023 profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); 1028 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA"));
1024 profile.SetInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90025")); 1029 profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90025"));
1025 profile.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); 1030 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
1026 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("18181234567")); 1031 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("18181234567"));
1027 db.GetAutofillTable()->AddAutofillProfile(profile); 1032 db.GetAutofillTable()->AddAutofillProfile(profile);
1028 1033
1029 // Set a mocked value for the profile's creation time. 1034 // Set a mocked value for the profile's creation time.
1030 const time_t mock_creation_date = Time::Now().ToTimeT() - 13; 1035 const time_t mock_creation_date = Time::Now().ToTimeT() - 13;
1031 sql::Statement s_mock_creation_date(db.GetSQLConnection()->GetUniqueStatement( 1036 sql::Statement s_mock_creation_date(db.GetSQLConnection()->GetUniqueStatement(
1032 "UPDATE autofill_profiles SET date_modified = ?")); 1037 "UPDATE autofill_profiles SET date_modified = ?"));
1033 ASSERT_TRUE(s_mock_creation_date.is_valid()); 1038 ASSERT_TRUE(s_mock_creation_date.is_valid());
1034 s_mock_creation_date.BindInt64(0, mock_creation_date); 1039 s_mock_creation_date.BindInt64(0, mock_creation_date);
1035 ASSERT_TRUE(s_mock_creation_date.Run()); 1040 ASSERT_TRUE(s_mock_creation_date.Run());
1036 1041
1037 // Get the profile. 1042 // Get the profile.
1038 AutofillProfile* tmp_profile; 1043 AutofillProfile* tmp_profile;
1039 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(profile.guid(), 1044 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(profile.guid(),
1040 &tmp_profile)); 1045 &tmp_profile));
1041 scoped_ptr<AutofillProfile> db_profile(tmp_profile); 1046 scoped_ptr<AutofillProfile> db_profile(tmp_profile);
1042 EXPECT_EQ(profile, *db_profile); 1047 EXPECT_EQ(profile, *db_profile);
1043 sql::Statement s_original(db.GetSQLConnection()->GetUniqueStatement( 1048 sql::Statement s_original(db.GetSQLConnection()->GetUniqueStatement(
1044 "SELECT date_modified FROM autofill_profiles")); 1049 "SELECT date_modified FROM autofill_profiles"));
1045 ASSERT_TRUE(s_original.is_valid()); 1050 ASSERT_TRUE(s_original.is_valid());
1046 ASSERT_TRUE(s_original.Step()); 1051 ASSERT_TRUE(s_original.Step());
1047 EXPECT_EQ(mock_creation_date, s_original.ColumnInt64(0)); 1052 EXPECT_EQ(mock_creation_date, s_original.ColumnInt64(0));
1048 EXPECT_FALSE(s_original.Step()); 1053 EXPECT_FALSE(s_original.Step());
1049 1054
1050 // Now, update the profile and save the update to the database. 1055 // Now, update the profile and save the update to the database.
1051 // The modification date should change to reflect the update. 1056 // The modification date should change to reflect the update.
1052 profile.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16("js@smith.xyz")); 1057 profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("js@smith.xyz"));
1053 db.GetAutofillTable()->UpdateAutofillProfileMulti(profile); 1058 db.GetAutofillTable()->UpdateAutofillProfileMulti(profile);
1054 1059
1055 // Get the profile. 1060 // Get the profile.
1056 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(profile.guid(), 1061 ASSERT_TRUE(db.GetAutofillTable()->GetAutofillProfile(profile.guid(),
1057 &tmp_profile)); 1062 &tmp_profile));
1058 db_profile.reset(tmp_profile); 1063 db_profile.reset(tmp_profile);
1059 EXPECT_EQ(profile, *db_profile); 1064 EXPECT_EQ(profile, *db_profile);
1060 sql::Statement s_updated(db.GetSQLConnection()->GetUniqueStatement( 1065 sql::Statement s_updated(db.GetSQLConnection()->GetUniqueStatement(
1061 "SELECT date_modified FROM autofill_profiles")); 1066 "SELECT date_modified FROM autofill_profiles"));
1062 ASSERT_TRUE(s_updated.is_valid()); 1067 ASSERT_TRUE(s_updated.is_valid());
(...skipping 26 matching lines...) Expand all
1089 EXPECT_EQ(mock_modification_date, s_unchanged.ColumnInt64(0)); 1094 EXPECT_EQ(mock_modification_date, s_unchanged.ColumnInt64(0));
1090 EXPECT_FALSE(s_unchanged.Step()); 1095 EXPECT_FALSE(s_unchanged.Step());
1091 } 1096 }
1092 1097
1093 TEST_F(AutofillTableTest, UpdateCreditCard) { 1098 TEST_F(AutofillTableTest, UpdateCreditCard) {
1094 WebDatabase db; 1099 WebDatabase db;
1095 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); 1100 ASSERT_EQ(sql::INIT_OK, db.Init(file_));
1096 1101
1097 // Add a credit card to the db. 1102 // Add a credit card to the db.
1098 CreditCard credit_card; 1103 CreditCard credit_card;
1099 credit_card.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Jack Torrance")); 1104 credit_card.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Jack Torrance"));
1100 credit_card.SetInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("1234567890123456")); 1105 credit_card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("1234567890123456"));
1101 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("04")); 1106 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("04"));
1102 credit_card.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2013")); 1107 credit_card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2013"));
1103 db.GetAutofillTable()->AddCreditCard(credit_card); 1108 db.GetAutofillTable()->AddCreditCard(credit_card);
1104 1109
1105 // Set a mocked value for the credit card's creation time. 1110 // Set a mocked value for the credit card's creation time.
1106 const time_t mock_creation_date = Time::Now().ToTimeT() - 13; 1111 const time_t mock_creation_date = Time::Now().ToTimeT() - 13;
1107 sql::Statement s_mock_creation_date(db.GetSQLConnection()->GetUniqueStatement( 1112 sql::Statement s_mock_creation_date(db.GetSQLConnection()->GetUniqueStatement(
1108 "UPDATE credit_cards SET date_modified = ?")); 1113 "UPDATE credit_cards SET date_modified = ?"));
1109 ASSERT_TRUE(s_mock_creation_date.is_valid()); 1114 ASSERT_TRUE(s_mock_creation_date.is_valid());
1110 s_mock_creation_date.BindInt64(0, mock_creation_date); 1115 s_mock_creation_date.BindInt64(0, mock_creation_date);
1111 ASSERT_TRUE(s_mock_creation_date.Run()); 1116 ASSERT_TRUE(s_mock_creation_date.Run());
1112 1117
1113 // Get the credit card. 1118 // Get the credit card.
1114 CreditCard* tmp_credit_card; 1119 CreditCard* tmp_credit_card;
1115 ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(credit_card.guid(), 1120 ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(credit_card.guid(),
1116 &tmp_credit_card)); 1121 &tmp_credit_card));
1117 scoped_ptr<CreditCard> db_credit_card(tmp_credit_card); 1122 scoped_ptr<CreditCard> db_credit_card(tmp_credit_card);
1118 EXPECT_EQ(credit_card, *db_credit_card); 1123 EXPECT_EQ(credit_card, *db_credit_card);
1119 sql::Statement s_original(db.GetSQLConnection()->GetUniqueStatement( 1124 sql::Statement s_original(db.GetSQLConnection()->GetUniqueStatement(
1120 "SELECT date_modified FROM credit_cards")); 1125 "SELECT date_modified FROM credit_cards"));
1121 ASSERT_TRUE(s_original.is_valid()); 1126 ASSERT_TRUE(s_original.is_valid());
1122 ASSERT_TRUE(s_original.Step()); 1127 ASSERT_TRUE(s_original.Step());
1123 EXPECT_EQ(mock_creation_date, s_original.ColumnInt64(0)); 1128 EXPECT_EQ(mock_creation_date, s_original.ColumnInt64(0));
1124 EXPECT_FALSE(s_original.Step()); 1129 EXPECT_FALSE(s_original.Step());
1125 1130
1126 // Now, update the credit card and save the update to the database. 1131 // Now, update the credit card and save the update to the database.
1127 // The modification date should change to reflect the update. 1132 // The modification date should change to reflect the update.
1128 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); 1133 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01"));
1129 db.GetAutofillTable()->UpdateCreditCard(credit_card); 1134 db.GetAutofillTable()->UpdateCreditCard(credit_card);
1130 1135
1131 // Get the credit card. 1136 // Get the credit card.
1132 ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(credit_card.guid(), 1137 ASSERT_TRUE(db.GetAutofillTable()->GetCreditCard(credit_card.guid(),
1133 &tmp_credit_card)); 1138 &tmp_credit_card));
1134 db_credit_card.reset(tmp_credit_card); 1139 db_credit_card.reset(tmp_credit_card);
1135 EXPECT_EQ(credit_card, *db_credit_card); 1140 EXPECT_EQ(credit_card, *db_credit_card);
1136 sql::Statement s_updated(db.GetSQLConnection()->GetUniqueStatement( 1141 sql::Statement s_updated(db.GetSQLConnection()->GetUniqueStatement(
1137 "SELECT date_modified FROM credit_cards")); 1142 "SELECT date_modified FROM credit_cards"));
1138 ASSERT_TRUE(s_updated.is_valid()); 1143 ASSERT_TRUE(s_updated.is_valid());
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 1436
1432 // make sure the lists of entries match 1437 // make sure the lists of entries match
1433 ASSERT_EQ(expected_entries.size(), entry_set.size()); 1438 ASSERT_EQ(expected_entries.size(), entry_set.size());
1434 AutofillEntrySetIterator it; 1439 AutofillEntrySetIterator it;
1435 for (it = entry_set.begin(); it != entry_set.end(); it++) { 1440 for (it = entry_set.begin(); it != entry_set.end(); it++) {
1436 expected_entries.erase(*it); 1441 expected_entries.erase(*it);
1437 } 1442 }
1438 1443
1439 EXPECT_EQ(0U, expected_entries.size()); 1444 EXPECT_EQ(0U, expected_entries.size());
1440 } 1445 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/autofill_table.cc ('k') | chrome/browser/webdata/web_data_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698