| 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, SetServerCardUpdateUsageStatsAndBillingAddress) { | 1721 TEST_F(AutofillTableTest, SetServerCardUpdateUsageStats) { |
| 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"); | |
| 1730 masked_card.SetTypeForMaskedCard(kVisaCard); | 1729 masked_card.SetTypeForMaskedCard(kVisaCard); |
| 1731 | 1730 |
| 1732 std::vector<CreditCard> inputs; | 1731 std::vector<CreditCard> inputs; |
| 1733 inputs.push_back(masked_card); | 1732 inputs.push_back(masked_card); |
| 1734 test::SetServerCreditCards(table_.get(), inputs); | 1733 test::SetServerCreditCards(table_.get(), inputs); |
| 1735 | 1734 |
| 1736 std::vector<std::unique_ptr<CreditCard>> outputs; | 1735 std::vector<std::unique_ptr<CreditCard>> outputs; |
| 1737 table_->GetServerCreditCards(&outputs); | 1736 table_->GetServerCreditCards(&outputs); |
| 1738 ASSERT_EQ(1u, outputs.size()); | 1737 ASSERT_EQ(1u, outputs.size()); |
| 1739 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); | 1738 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); |
| 1740 EXPECT_EQ(1U, outputs[0]->use_count()); | 1739 EXPECT_EQ(1U, outputs[0]->use_count()); |
| 1741 EXPECT_NE(base::Time(), outputs[0]->use_date()); | 1740 EXPECT_NE(base::Time(), outputs[0]->use_date()); |
| 1742 // We don't track modification date for server cards. It should always be | 1741 // We don't track modification date for server cards. It should always be |
| 1743 // base::Time(). | 1742 // base::Time(). |
| 1744 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); | 1743 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1745 outputs.clear(); | 1744 outputs.clear(); |
| 1746 | 1745 |
| 1747 // Update the usage stats; make sure they're reflected in GetServerProfiles. | 1746 // Update the usage stats; make sure they're reflected in GetServerProfiles. |
| 1748 inputs.back().set_use_count(4U); | 1747 inputs.back().set_use_count(4U); |
| 1749 inputs.back().set_use_date(base::Time()); | 1748 inputs.back().set_use_date(base::Time()); |
| 1750 inputs.back().set_billing_address_id("2"); | 1749 table_->UpdateServerCardUsageStats(inputs.back()); |
| 1751 table_->UpdateServerCardMetadata(inputs.back()); | |
| 1752 table_->GetServerCreditCards(&outputs); | 1750 table_->GetServerCreditCards(&outputs); |
| 1753 ASSERT_EQ(1u, outputs.size()); | 1751 ASSERT_EQ(1u, outputs.size()); |
| 1754 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); | 1752 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); |
| 1755 EXPECT_EQ(4U, outputs[0]->use_count()); | 1753 EXPECT_EQ(4U, outputs[0]->use_count()); |
| 1756 EXPECT_EQ(base::Time(), outputs[0]->use_date()); | 1754 EXPECT_EQ(base::Time(), outputs[0]->use_date()); |
| 1757 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); | 1755 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1758 EXPECT_EQ("2", outputs[0]->billing_address_id()); | |
| 1759 outputs.clear(); | 1756 outputs.clear(); |
| 1760 | 1757 |
| 1761 // Setting the cards again shouldn't delete the usage stats. | 1758 // Setting the cards again shouldn't delete the usage stats. |
| 1762 table_->SetServerCreditCards(inputs); | 1759 table_->SetServerCreditCards(inputs); |
| 1763 table_->GetServerCreditCards(&outputs); | 1760 table_->GetServerCreditCards(&outputs); |
| 1764 ASSERT_EQ(1u, outputs.size()); | 1761 ASSERT_EQ(1u, outputs.size()); |
| 1765 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); | 1762 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); |
| 1766 EXPECT_EQ(4U, outputs[0]->use_count()); | 1763 EXPECT_EQ(4U, outputs[0]->use_count()); |
| 1767 EXPECT_EQ(base::Time(), outputs[0]->use_date()); | 1764 EXPECT_EQ(base::Time(), outputs[0]->use_date()); |
| 1768 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); | 1765 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1769 EXPECT_EQ("2", outputs[0]->billing_address_id()); | |
| 1770 outputs.clear(); | 1766 outputs.clear(); |
| 1771 | 1767 |
| 1772 // Set a card list where the card is missing --- this should clear metadata. | 1768 // Set a card list where the card is missing --- this should clear metadata. |
| 1773 CreditCard masked_card2(CreditCard::MASKED_SERVER_CARD, "b456"); | 1769 CreditCard masked_card2(CreditCard::MASKED_SERVER_CARD, "b456"); |
| 1774 inputs.back() = masked_card2; | 1770 inputs.back() = masked_card2; |
| 1775 table_->SetServerCreditCards(inputs); | 1771 table_->SetServerCreditCards(inputs); |
| 1776 | 1772 |
| 1777 // Back to the original card list. | 1773 // Back to the original card list. |
| 1778 inputs.back() = masked_card; | 1774 inputs.back() = masked_card; |
| 1779 table_->SetServerCreditCards(inputs); | 1775 table_->SetServerCreditCards(inputs); |
| 1780 table_->GetServerCreditCards(&outputs); | 1776 table_->GetServerCreditCards(&outputs); |
| 1781 ASSERT_EQ(1u, outputs.size()); | 1777 ASSERT_EQ(1u, outputs.size()); |
| 1782 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); | 1778 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); |
| 1783 EXPECT_EQ(1U, outputs[0]->use_count()); | 1779 EXPECT_EQ(1U, outputs[0]->use_count()); |
| 1784 EXPECT_NE(base::Time(), outputs[0]->use_date()); | 1780 EXPECT_NE(base::Time(), outputs[0]->use_date()); |
| 1785 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); | 1781 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1786 EXPECT_EQ("1", outputs[0]->billing_address_id()); | |
| 1787 outputs.clear(); | 1782 outputs.clear(); |
| 1788 } | 1783 } |
| 1789 | 1784 |
| 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 |
| 1790 TEST_F(AutofillTableTest, SetServerProfile) { | 1812 TEST_F(AutofillTableTest, SetServerProfile) { |
| 1791 AutofillProfile one(AutofillProfile::SERVER_PROFILE, "a123"); | 1813 AutofillProfile one(AutofillProfile::SERVER_PROFILE, "a123"); |
| 1792 std::vector<AutofillProfile> inputs; | 1814 std::vector<AutofillProfile> inputs; |
| 1793 inputs.push_back(one); | 1815 inputs.push_back(one); |
| 1794 table_->SetServerProfiles(inputs); | 1816 table_->SetServerProfiles(inputs); |
| 1795 | 1817 |
| 1796 std::vector<std::unique_ptr<AutofillProfile>> outputs; | 1818 std::vector<std::unique_ptr<AutofillProfile>> outputs; |
| 1797 table_->GetServerProfiles(&outputs); | 1819 table_->GetServerProfiles(&outputs); |
| 1798 ASSERT_EQ(1u, outputs.size()); | 1820 ASSERT_EQ(1u, outputs.size()); |
| 1799 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); | 1821 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1826 EXPECT_EQ(0U, outputs[0]->use_count()); | 1848 EXPECT_EQ(0U, outputs[0]->use_count()); |
| 1827 EXPECT_EQ(base::Time(), outputs[0]->use_date()); | 1849 EXPECT_EQ(base::Time(), outputs[0]->use_date()); |
| 1828 // We don't track modification date for server profiles. It should always be | 1850 // We don't track modification date for server profiles. It should always be |
| 1829 // base::Time(). | 1851 // base::Time(). |
| 1830 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); | 1852 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1831 outputs.clear(); | 1853 outputs.clear(); |
| 1832 | 1854 |
| 1833 // Update the usage stats; make sure they're reflected in GetServerProfiles. | 1855 // Update the usage stats; make sure they're reflected in GetServerProfiles. |
| 1834 inputs.back().set_use_count(4U); | 1856 inputs.back().set_use_count(4U); |
| 1835 inputs.back().set_use_date(base::Time::Now()); | 1857 inputs.back().set_use_date(base::Time::Now()); |
| 1836 table_->UpdateServerAddressMetadata(inputs.back()); | 1858 table_->UpdateServerAddressUsageStats(inputs.back()); |
| 1837 table_->GetServerProfiles(&outputs); | 1859 table_->GetServerProfiles(&outputs); |
| 1838 ASSERT_EQ(1u, outputs.size()); | 1860 ASSERT_EQ(1u, outputs.size()); |
| 1839 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); | 1861 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); |
| 1840 EXPECT_EQ(4U, outputs[0]->use_count()); | 1862 EXPECT_EQ(4U, outputs[0]->use_count()); |
| 1841 EXPECT_NE(base::Time(), outputs[0]->use_date()); | 1863 EXPECT_NE(base::Time(), outputs[0]->use_date()); |
| 1842 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); | 1864 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1843 outputs.clear(); | 1865 outputs.clear(); |
| 1844 | 1866 |
| 1845 // Setting the profiles again shouldn't delete the usage stats. | 1867 // Setting the profiles again shouldn't delete the usage stats. |
| 1846 table_->SetServerProfiles(inputs); | 1868 table_->SetServerProfiles(inputs); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2076 "(rowid, value) VALUES(1, ?)")); | 2098 "(rowid, value) VALUES(1, ?)")); |
| 2077 s2.BindString(0, "unparseable"); | 2099 s2.BindString(0, "unparseable"); |
| 2078 | 2100 |
| 2079 EXPECT_TRUE(s.Run()); | 2101 EXPECT_TRUE(s.Run()); |
| 2080 EXPECT_TRUE(s2.Run()); | 2102 EXPECT_TRUE(s2.Run()); |
| 2081 | 2103 |
| 2082 EXPECT_FALSE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch)); | 2104 EXPECT_FALSE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch)); |
| 2083 } | 2105 } |
| 2084 | 2106 |
| 2085 } // namespace autofill | 2107 } // namespace autofill |
| OLD | NEW |