OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 <list> | 5 #include <list> |
6 #include <map> | 6 #include <map> |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 1617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1628 ASSERT_TRUE(db.GetCreditCardForGUID(guid_creditcard.guid(), &db_creditcard)); | 1628 ASSERT_TRUE(db.GetCreditCardForGUID(guid_creditcard.guid(), &db_creditcard)); |
1629 EXPECT_EQ(guid_creditcard, *db_creditcard); | 1629 EXPECT_EQ(guid_creditcard, *db_creditcard); |
1630 delete db_creditcard; | 1630 delete db_creditcard; |
1631 | 1631 |
1632 // Remove the 'GUID' profile. | 1632 // Remove the 'GUID' profile. |
1633 EXPECT_TRUE(db.RemoveCreditCard(guid_creditcard.guid())); | 1633 EXPECT_TRUE(db.RemoveCreditCard(guid_creditcard.guid())); |
1634 EXPECT_FALSE(db.GetCreditCardForGUID(guid_creditcard.guid(), | 1634 EXPECT_FALSE(db.GetCreditCardForGUID(guid_creditcard.guid(), |
1635 &db_creditcard)); | 1635 &db_creditcard)); |
1636 } | 1636 } |
1637 | 1637 |
| 1638 TEST_F(WebDatabaseTest, UpdateAutoFillProfile) { |
| 1639 WebDatabase db; |
| 1640 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
| 1641 |
| 1642 // Add a profile to the db. |
| 1643 AutoFillProfile profile; |
| 1644 profile.set_label(ASCIIToUTF16("Test Profile")); |
| 1645 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("John")); |
| 1646 profile.SetInfo(AutoFillType(NAME_MIDDLE), ASCIIToUTF16("Q.")); |
| 1647 profile.SetInfo(AutoFillType(NAME_LAST), ASCIIToUTF16("Smith")); |
| 1648 profile.SetInfo(AutoFillType(EMAIL_ADDRESS), ASCIIToUTF16("js@example.com")); |
| 1649 profile.SetInfo(AutoFillType(COMPANY_NAME), ASCIIToUTF16("Google")); |
| 1650 profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE1), |
| 1651 ASCIIToUTF16("1234 Apple Way")); |
| 1652 profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE2), ASCIIToUTF16("unit 5")); |
| 1653 profile.SetInfo(AutoFillType(ADDRESS_HOME_CITY), ASCIIToUTF16("Los Angeles")); |
| 1654 profile.SetInfo(AutoFillType(ADDRESS_HOME_STATE), ASCIIToUTF16("CA")); |
| 1655 profile.SetInfo(AutoFillType(ADDRESS_HOME_ZIP), ASCIIToUTF16("90025")); |
| 1656 profile.SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("US")); |
| 1657 profile.SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), |
| 1658 ASCIIToUTF16("18181234567")); |
| 1659 profile.SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), |
| 1660 ASCIIToUTF16("1915243678")); |
| 1661 db.AddAutoFillProfile(profile); |
| 1662 |
| 1663 // Set a mocked value for the profile's creation time. |
| 1664 const time_t mock_creation_date = Time::Now().ToTimeT() - 13; |
| 1665 sql::Statement s_mock_creation_date(db.db_.GetUniqueStatement( |
| 1666 "UPDATE autofill_profiles SET date_modified = ?")); |
| 1667 ASSERT_TRUE(s_mock_creation_date); |
| 1668 s_mock_creation_date.BindInt64(0, mock_creation_date); |
| 1669 ASSERT_TRUE(s_mock_creation_date.Run()); |
| 1670 |
| 1671 // Get the profile. |
| 1672 AutoFillProfile* tmp_profile; |
| 1673 ASSERT_TRUE(db.GetAutoFillProfileForGUID(profile.guid(), &tmp_profile)); |
| 1674 scoped_ptr<AutoFillProfile> db_profile(tmp_profile); |
| 1675 EXPECT_EQ(profile, *db_profile); |
| 1676 sql::Statement s_original(db.db_.GetUniqueStatement( |
| 1677 "SELECT date_modified FROM autofill_profiles")); |
| 1678 ASSERT_TRUE(s_original); |
| 1679 ASSERT_TRUE(s_original.Step()); |
| 1680 EXPECT_EQ(mock_creation_date, s_original.ColumnInt64(0)); |
| 1681 EXPECT_FALSE(s_original.Step()); |
| 1682 |
| 1683 // Now, update the profile and save the update to the database. |
| 1684 // The modification date should change to reflect the update. |
| 1685 profile.SetInfo(AutoFillType(EMAIL_ADDRESS), ASCIIToUTF16("js@smith.xyz")); |
| 1686 db.UpdateAutoFillProfile(profile); |
| 1687 |
| 1688 // Get the profile. |
| 1689 ASSERT_TRUE(db.GetAutoFillProfileForGUID(profile.guid(), &tmp_profile)); |
| 1690 db_profile.reset(tmp_profile); |
| 1691 EXPECT_EQ(profile, *db_profile); |
| 1692 sql::Statement s_updated(db.db_.GetUniqueStatement( |
| 1693 "SELECT date_modified FROM autofill_profiles")); |
| 1694 ASSERT_TRUE(s_updated); |
| 1695 ASSERT_TRUE(s_updated.Step()); |
| 1696 EXPECT_LT(mock_creation_date, s_updated.ColumnInt64(0)); |
| 1697 EXPECT_FALSE(s_updated.Step()); |
| 1698 |
| 1699 // Set a mocked value for the profile's modification time. |
| 1700 const time_t mock_modification_date = Time::Now().ToTimeT() - 7; |
| 1701 sql::Statement s_mock_modification_date(db.db_.GetUniqueStatement( |
| 1702 "UPDATE autofill_profiles SET date_modified = ?")); |
| 1703 ASSERT_TRUE(s_mock_modification_date); |
| 1704 s_mock_modification_date.BindInt64(0, mock_modification_date); |
| 1705 ASSERT_TRUE(s_mock_modification_date.Run()); |
| 1706 |
| 1707 // Finally, call into |UpdateAutoFillProfile()| without changing the profile. |
| 1708 // The modification date should not change. |
| 1709 db.UpdateAutoFillProfile(profile); |
| 1710 |
| 1711 // Get the profile. |
| 1712 ASSERT_TRUE(db.GetAutoFillProfileForGUID(profile.guid(), &tmp_profile)); |
| 1713 db_profile.reset(tmp_profile); |
| 1714 EXPECT_EQ(profile, *db_profile); |
| 1715 sql::Statement s_unchanged(db.db_.GetUniqueStatement( |
| 1716 "SELECT date_modified FROM autofill_profiles")); |
| 1717 ASSERT_TRUE(s_unchanged); |
| 1718 ASSERT_TRUE(s_unchanged.Step()); |
| 1719 EXPECT_EQ(mock_modification_date, s_unchanged.ColumnInt64(0)); |
| 1720 EXPECT_FALSE(s_unchanged.Step()); |
| 1721 } |
| 1722 |
| 1723 TEST_F(WebDatabaseTest, UpdateCreditCard) { |
| 1724 WebDatabase db; |
| 1725 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
| 1726 |
| 1727 // Add a credit card to the db. |
| 1728 CreditCard credit_card; |
| 1729 credit_card.set_label(ASCIIToUTF16("Test Credit Card")); |
| 1730 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), |
| 1731 ASCIIToUTF16("Jack Torrance")); |
| 1732 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NUMBER), |
| 1733 ASCIIToUTF16("1234567890123456")); |
| 1734 credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), |
| 1735 ASCIIToUTF16("04")); |
| 1736 credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), |
| 1737 ASCIIToUTF16("2013")); |
| 1738 db.AddCreditCard(credit_card); |
| 1739 |
| 1740 // Set a mocked value for the credit card's creation time. |
| 1741 const time_t mock_creation_date = Time::Now().ToTimeT() - 13; |
| 1742 sql::Statement s_mock_creation_date(db.db_.GetUniqueStatement( |
| 1743 "UPDATE credit_cards SET date_modified = ?")); |
| 1744 ASSERT_TRUE(s_mock_creation_date); |
| 1745 s_mock_creation_date.BindInt64(0, mock_creation_date); |
| 1746 ASSERT_TRUE(s_mock_creation_date.Run()); |
| 1747 |
| 1748 // Get the credit card. |
| 1749 CreditCard* tmp_credit_card; |
| 1750 ASSERT_TRUE(db.GetCreditCardForGUID(credit_card.guid(), &tmp_credit_card)); |
| 1751 scoped_ptr<CreditCard> db_credit_card(tmp_credit_card); |
| 1752 EXPECT_EQ(credit_card, *db_credit_card); |
| 1753 sql::Statement s_original(db.db_.GetUniqueStatement( |
| 1754 "SELECT date_modified FROM credit_cards")); |
| 1755 ASSERT_TRUE(s_original); |
| 1756 ASSERT_TRUE(s_original.Step()); |
| 1757 EXPECT_EQ(mock_creation_date, s_original.ColumnInt64(0)); |
| 1758 EXPECT_FALSE(s_original.Step()); |
| 1759 |
| 1760 // Now, update the credit card and save the update to the database. |
| 1761 // The modification date should change to reflect the update. |
| 1762 credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), ASCIIToUTF16("01")); |
| 1763 db.UpdateCreditCard(credit_card); |
| 1764 |
| 1765 // Get the credit card. |
| 1766 ASSERT_TRUE(db.GetCreditCardForGUID(credit_card.guid(), &tmp_credit_card)); |
| 1767 db_credit_card.reset(tmp_credit_card); |
| 1768 EXPECT_EQ(credit_card, *db_credit_card); |
| 1769 sql::Statement s_updated(db.db_.GetUniqueStatement( |
| 1770 "SELECT date_modified FROM credit_cards")); |
| 1771 ASSERT_TRUE(s_updated); |
| 1772 ASSERT_TRUE(s_updated.Step()); |
| 1773 EXPECT_LT(mock_creation_date, s_updated.ColumnInt64(0)); |
| 1774 EXPECT_FALSE(s_updated.Step()); |
| 1775 |
| 1776 // Set a mocked value for the credit card's modification time. |
| 1777 const time_t mock_modification_date = Time::Now().ToTimeT() - 7; |
| 1778 sql::Statement s_mock_modification_date(db.db_.GetUniqueStatement( |
| 1779 "UPDATE credit_cards SET date_modified = ?")); |
| 1780 ASSERT_TRUE(s_mock_modification_date); |
| 1781 s_mock_modification_date.BindInt64(0, mock_modification_date); |
| 1782 ASSERT_TRUE(s_mock_modification_date.Run()); |
| 1783 |
| 1784 // Finally, call into |UpdateCreditCard()| without changing the credit card. |
| 1785 // The modification date should not change. |
| 1786 db.UpdateCreditCard(credit_card); |
| 1787 |
| 1788 // Get the profile. |
| 1789 ASSERT_TRUE(db.GetCreditCardForGUID(credit_card.guid(), &tmp_credit_card)); |
| 1790 db_credit_card.reset(tmp_credit_card); |
| 1791 EXPECT_EQ(credit_card, *db_credit_card); |
| 1792 sql::Statement s_unchanged(db.db_.GetUniqueStatement( |
| 1793 "SELECT date_modified FROM credit_cards")); |
| 1794 ASSERT_TRUE(s_unchanged); |
| 1795 ASSERT_TRUE(s_unchanged.Step()); |
| 1796 EXPECT_EQ(mock_modification_date, s_unchanged.ColumnInt64(0)); |
| 1797 EXPECT_FALSE(s_unchanged.Step()); |
| 1798 } |
| 1799 |
1638 TEST_F(WebDatabaseTest, RemoveAutoFillProfilesAndCreditCardsModifiedBetween) { | 1800 TEST_F(WebDatabaseTest, RemoveAutoFillProfilesAndCreditCardsModifiedBetween) { |
1639 WebDatabase db; | 1801 WebDatabase db; |
1640 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); | 1802 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
1641 | 1803 |
1642 // Populate the autofill_profiles and credit_cards tables. | 1804 // Populate the autofill_profiles and credit_cards tables. |
1643 ASSERT_TRUE(db.db_.Execute( | 1805 ASSERT_TRUE(db.db_.Execute( |
1644 "INSERT INTO autofill_profiles (guid, date_modified) " | 1806 "INSERT INTO autofill_profiles (guid, date_modified) " |
1645 "VALUES('00000000-0000-0000-0000-000000000000', 11);" | 1807 "VALUES('00000000-0000-0000-0000-000000000000', 11);" |
1646 "INSERT INTO autofill_profiles (guid, date_modified) " | 1808 "INSERT INTO autofill_profiles (guid, date_modified) " |
1647 "VALUES('00000000-0000-0000-0000-000000000001', 21);" | 1809 "VALUES('00000000-0000-0000-0000-000000000001', 21);" |
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2671 &credit_card_a, | 2833 &credit_card_a, |
2672 &cc_label_a, | 2834 &cc_label_a, |
2673 &cc_number_encrypted_a, | 2835 &cc_number_encrypted_a, |
2674 &cc_date_modified_a)); | 2836 &cc_date_modified_a)); |
2675 EXPECT_EQ(credit_card, credit_card_a); | 2837 EXPECT_EQ(credit_card, credit_card_a); |
2676 EXPECT_EQ(cc_label, cc_label_a); | 2838 EXPECT_EQ(cc_label, cc_label_a); |
2677 EXPECT_EQ(cc_number_encrypted, cc_number_encrypted_a); | 2839 EXPECT_EQ(cc_number_encrypted, cc_number_encrypted_a); |
2678 EXPECT_EQ(cc_date_modified, cc_date_modified_a); | 2840 EXPECT_EQ(cc_date_modified, cc_date_modified_a); |
2679 } | 2841 } |
2680 } | 2842 } |
OLD | NEW |