| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <tuple> | 10 #include <tuple> |
| (...skipping 1700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1711 test::SetServerCreditCards(table_.get(), inputs); | 1711 test::SetServerCreditCards(table_.get(), inputs); |
| 1712 table_->GetServerCreditCards(&outputs); | 1712 table_->GetServerCreditCards(&outputs); |
| 1713 ASSERT_EQ(1u, outputs.size()); | 1713 ASSERT_EQ(1u, outputs.size()); |
| 1714 EXPECT_TRUE(outputs[0]->record_type() == CreditCard::MASKED_SERVER_CARD); | 1714 EXPECT_TRUE(outputs[0]->record_type() == CreditCard::MASKED_SERVER_CARD); |
| 1715 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); | 1715 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); |
| 1716 EXPECT_EQ(ASCIIToUTF16("1111"), outputs[0]->GetRawInfo(CREDIT_CARD_NUMBER)); | 1716 EXPECT_EQ(ASCIIToUTF16("1111"), outputs[0]->GetRawInfo(CREDIT_CARD_NUMBER)); |
| 1717 | 1717 |
| 1718 outputs.clear(); | 1718 outputs.clear(); |
| 1719 } | 1719 } |
| 1720 | 1720 |
| 1721 TEST_F(AutofillTableTest, SetServerCardUpdateUsageStats) { | 1721 TEST_F(AutofillTableTest, SetServerCardUpdateUsageStatsAndBillingAddress) { |
| 1722 // Add a masked card. | 1722 // Add a masked card. |
| 1723 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); | 1723 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); |
| 1724 masked_card.SetRawInfo(CREDIT_CARD_NAME_FULL, | 1724 masked_card.SetRawInfo(CREDIT_CARD_NAME_FULL, |
| 1725 ASCIIToUTF16("Paul F. Tompkins")); | 1725 ASCIIToUTF16("Paul F. Tompkins")); |
| 1726 masked_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("1")); | 1726 masked_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("1")); |
| 1727 masked_card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2020")); | 1727 masked_card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2020")); |
| 1728 masked_card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("1111")); | 1728 masked_card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("1111")); |
| 1729 masked_card.set_billing_address_id("1"); |
| 1729 masked_card.SetTypeForMaskedCard(kVisaCard); | 1730 masked_card.SetTypeForMaskedCard(kVisaCard); |
| 1730 | 1731 |
| 1731 std::vector<CreditCard> inputs; | 1732 std::vector<CreditCard> inputs; |
| 1732 inputs.push_back(masked_card); | 1733 inputs.push_back(masked_card); |
| 1733 test::SetServerCreditCards(table_.get(), inputs); | 1734 test::SetServerCreditCards(table_.get(), inputs); |
| 1734 | 1735 |
| 1735 std::vector<std::unique_ptr<CreditCard>> outputs; | 1736 std::vector<std::unique_ptr<CreditCard>> outputs; |
| 1736 table_->GetServerCreditCards(&outputs); | 1737 table_->GetServerCreditCards(&outputs); |
| 1737 ASSERT_EQ(1u, outputs.size()); | 1738 ASSERT_EQ(1u, outputs.size()); |
| 1738 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); | 1739 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); |
| 1739 EXPECT_EQ(1U, outputs[0]->use_count()); | 1740 EXPECT_EQ(1U, outputs[0]->use_count()); |
| 1740 EXPECT_NE(base::Time(), outputs[0]->use_date()); | 1741 EXPECT_NE(base::Time(), outputs[0]->use_date()); |
| 1741 // We don't track modification date for server cards. It should always be | 1742 // We don't track modification date for server cards. It should always be |
| 1742 // base::Time(). | 1743 // base::Time(). |
| 1743 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); | 1744 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1744 outputs.clear(); | 1745 outputs.clear(); |
| 1745 | 1746 |
| 1746 // Update the usage stats; make sure they're reflected in GetServerProfiles. | 1747 // Update the usage stats; make sure they're reflected in GetServerProfiles. |
| 1747 inputs.back().set_use_count(4U); | 1748 inputs.back().set_use_count(4U); |
| 1748 inputs.back().set_use_date(base::Time()); | 1749 inputs.back().set_use_date(base::Time()); |
| 1749 table_->UpdateServerCardUsageStats(inputs.back()); | 1750 inputs.back().set_billing_address_id("2"); |
| 1751 table_->UpdateServerCardMetadata(inputs.back()); |
| 1750 table_->GetServerCreditCards(&outputs); | 1752 table_->GetServerCreditCards(&outputs); |
| 1751 ASSERT_EQ(1u, outputs.size()); | 1753 ASSERT_EQ(1u, outputs.size()); |
| 1752 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); | 1754 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); |
| 1753 EXPECT_EQ(4U, outputs[0]->use_count()); | 1755 EXPECT_EQ(4U, outputs[0]->use_count()); |
| 1754 EXPECT_EQ(base::Time(), outputs[0]->use_date()); | 1756 EXPECT_EQ(base::Time(), outputs[0]->use_date()); |
| 1755 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); | 1757 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1758 EXPECT_EQ("2", outputs[0]->billing_address_id()); |
| 1756 outputs.clear(); | 1759 outputs.clear(); |
| 1757 | 1760 |
| 1758 // Setting the cards again shouldn't delete the usage stats. | 1761 // Setting the cards again shouldn't delete the usage stats. |
| 1759 table_->SetServerCreditCards(inputs); | 1762 table_->SetServerCreditCards(inputs); |
| 1760 table_->GetServerCreditCards(&outputs); | 1763 table_->GetServerCreditCards(&outputs); |
| 1761 ASSERT_EQ(1u, outputs.size()); | 1764 ASSERT_EQ(1u, outputs.size()); |
| 1762 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); | 1765 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); |
| 1763 EXPECT_EQ(4U, outputs[0]->use_count()); | 1766 EXPECT_EQ(4U, outputs[0]->use_count()); |
| 1764 EXPECT_EQ(base::Time(), outputs[0]->use_date()); | 1767 EXPECT_EQ(base::Time(), outputs[0]->use_date()); |
| 1765 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); | 1768 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1769 EXPECT_EQ("2", outputs[0]->billing_address_id()); |
| 1766 outputs.clear(); | 1770 outputs.clear(); |
| 1767 | 1771 |
| 1768 // Set a card list where the card is missing --- this should clear metadata. | 1772 // Set a card list where the card is missing --- this should clear metadata. |
| 1769 CreditCard masked_card2(CreditCard::MASKED_SERVER_CARD, "b456"); | 1773 CreditCard masked_card2(CreditCard::MASKED_SERVER_CARD, "b456"); |
| 1770 inputs.back() = masked_card2; | 1774 inputs.back() = masked_card2; |
| 1771 table_->SetServerCreditCards(inputs); | 1775 table_->SetServerCreditCards(inputs); |
| 1772 | 1776 |
| 1773 // Back to the original card list. | 1777 // Back to the original card list. |
| 1774 inputs.back() = masked_card; | 1778 inputs.back() = masked_card; |
| 1775 table_->SetServerCreditCards(inputs); | 1779 table_->SetServerCreditCards(inputs); |
| 1776 table_->GetServerCreditCards(&outputs); | 1780 table_->GetServerCreditCards(&outputs); |
| 1777 ASSERT_EQ(1u, outputs.size()); | 1781 ASSERT_EQ(1u, outputs.size()); |
| 1778 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); | 1782 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); |
| 1779 EXPECT_EQ(1U, outputs[0]->use_count()); | 1783 EXPECT_EQ(1U, outputs[0]->use_count()); |
| 1780 EXPECT_NE(base::Time(), outputs[0]->use_date()); | 1784 EXPECT_NE(base::Time(), outputs[0]->use_date()); |
| 1781 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); | 1785 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1786 EXPECT_EQ("1", outputs[0]->billing_address_id()); |
| 1782 outputs.clear(); | 1787 outputs.clear(); |
| 1783 } | 1788 } |
| 1784 | 1789 |
| 1785 TEST_F(AutofillTableTest, UpdateServerCardBillingAddress) { | |
| 1786 // Add a masked card. | |
| 1787 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); | |
| 1788 masked_card.SetRawInfo(CREDIT_CARD_NAME_FULL, | |
| 1789 ASCIIToUTF16("Paul F. Tompkins")); | |
| 1790 masked_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("1")); | |
| 1791 masked_card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2020")); | |
| 1792 masked_card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("1111")); | |
| 1793 masked_card.set_billing_address_id("billing-address-id-1"); | |
| 1794 masked_card.SetTypeForMaskedCard(kVisaCard); | |
| 1795 test::SetServerCreditCards(table_.get(), | |
| 1796 std::vector<CreditCard>(1, masked_card)); | |
| 1797 std::vector<std::unique_ptr<CreditCard>> outputs; | |
| 1798 table_->GetServerCreditCards(&outputs); | |
| 1799 ASSERT_EQ(1u, outputs.size()); | |
| 1800 | |
| 1801 EXPECT_EQ("billing-address-id-1", outputs[0]->billing_address_id()); | |
| 1802 | |
| 1803 masked_card.set_billing_address_id("billing-address-id-2"); | |
| 1804 table_->UpdateServerCardBillingAddress(masked_card); | |
| 1805 outputs.clear(); | |
| 1806 table_->GetServerCreditCards(&outputs); | |
| 1807 ASSERT_EQ(1u, outputs.size()); | |
| 1808 | |
| 1809 EXPECT_EQ("billing-address-id-2", outputs[0]->billing_address_id()); | |
| 1810 } | |
| 1811 | |
| 1812 TEST_F(AutofillTableTest, SetServerProfile) { | 1790 TEST_F(AutofillTableTest, SetServerProfile) { |
| 1813 AutofillProfile one(AutofillProfile::SERVER_PROFILE, "a123"); | 1791 AutofillProfile one(AutofillProfile::SERVER_PROFILE, "a123"); |
| 1814 std::vector<AutofillProfile> inputs; | 1792 std::vector<AutofillProfile> inputs; |
| 1815 inputs.push_back(one); | 1793 inputs.push_back(one); |
| 1816 table_->SetServerProfiles(inputs); | 1794 table_->SetServerProfiles(inputs); |
| 1817 | 1795 |
| 1818 std::vector<std::unique_ptr<AutofillProfile>> outputs; | 1796 std::vector<std::unique_ptr<AutofillProfile>> outputs; |
| 1819 table_->GetServerProfiles(&outputs); | 1797 table_->GetServerProfiles(&outputs); |
| 1820 ASSERT_EQ(1u, outputs.size()); | 1798 ASSERT_EQ(1u, outputs.size()); |
| 1821 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); | 1799 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1848 EXPECT_EQ(0U, outputs[0]->use_count()); | 1826 EXPECT_EQ(0U, outputs[0]->use_count()); |
| 1849 EXPECT_EQ(base::Time(), outputs[0]->use_date()); | 1827 EXPECT_EQ(base::Time(), outputs[0]->use_date()); |
| 1850 // We don't track modification date for server profiles. It should always be | 1828 // We don't track modification date for server profiles. It should always be |
| 1851 // base::Time(). | 1829 // base::Time(). |
| 1852 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); | 1830 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1853 outputs.clear(); | 1831 outputs.clear(); |
| 1854 | 1832 |
| 1855 // Update the usage stats; make sure they're reflected in GetServerProfiles. | 1833 // Update the usage stats; make sure they're reflected in GetServerProfiles. |
| 1856 inputs.back().set_use_count(4U); | 1834 inputs.back().set_use_count(4U); |
| 1857 inputs.back().set_use_date(base::Time::Now()); | 1835 inputs.back().set_use_date(base::Time::Now()); |
| 1858 table_->UpdateServerAddressUsageStats(inputs.back()); | 1836 table_->UpdateServerAddressMetadata(inputs.back()); |
| 1859 table_->GetServerProfiles(&outputs); | 1837 table_->GetServerProfiles(&outputs); |
| 1860 ASSERT_EQ(1u, outputs.size()); | 1838 ASSERT_EQ(1u, outputs.size()); |
| 1861 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); | 1839 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); |
| 1862 EXPECT_EQ(4U, outputs[0]->use_count()); | 1840 EXPECT_EQ(4U, outputs[0]->use_count()); |
| 1863 EXPECT_NE(base::Time(), outputs[0]->use_date()); | 1841 EXPECT_NE(base::Time(), outputs[0]->use_date()); |
| 1864 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); | 1842 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1865 outputs.clear(); | 1843 outputs.clear(); |
| 1866 | 1844 |
| 1867 // Setting the profiles again shouldn't delete the usage stats. | 1845 // Setting the profiles again shouldn't delete the usage stats. |
| 1868 table_->SetServerProfiles(inputs); | 1846 table_->SetServerProfiles(inputs); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2098 "(rowid, value) VALUES(1, ?)")); | 2076 "(rowid, value) VALUES(1, ?)")); |
| 2099 s2.BindString(0, "unparseable"); | 2077 s2.BindString(0, "unparseable"); |
| 2100 | 2078 |
| 2101 EXPECT_TRUE(s.Run()); | 2079 EXPECT_TRUE(s.Run()); |
| 2102 EXPECT_TRUE(s2.Run()); | 2080 EXPECT_TRUE(s2.Run()); |
| 2103 | 2081 |
| 2104 EXPECT_FALSE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch)); | 2082 EXPECT_FALSE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch)); |
| 2105 } | 2083 } |
| 2106 | 2084 |
| 2107 } // namespace autofill | 2085 } // namespace autofill |
| OLD | NEW |