| 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 <tuple> | 7 #include <tuple> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 1723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1734 std::vector<CreditCard> inputs; | 1734 std::vector<CreditCard> inputs; |
| 1735 inputs.push_back(masked_card); | 1735 inputs.push_back(masked_card); |
| 1736 test::SetServerCreditCards(table_.get(), inputs); | 1736 test::SetServerCreditCards(table_.get(), inputs); |
| 1737 | 1737 |
| 1738 ScopedVector<CreditCard> outputs; | 1738 ScopedVector<CreditCard> outputs; |
| 1739 table_->GetServerCreditCards(&outputs.get()); | 1739 table_->GetServerCreditCards(&outputs.get()); |
| 1740 ASSERT_EQ(1u, outputs.size()); | 1740 ASSERT_EQ(1u, outputs.size()); |
| 1741 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); | 1741 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); |
| 1742 EXPECT_EQ(1U, outputs[0]->use_count()); | 1742 EXPECT_EQ(1U, outputs[0]->use_count()); |
| 1743 EXPECT_NE(base::Time(), outputs[0]->use_date()); | 1743 EXPECT_NE(base::Time(), outputs[0]->use_date()); |
| 1744 // We don't track modification date for server cards. It should always be |
| 1745 // base::Time(). |
| 1746 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1744 outputs.clear(); | 1747 outputs.clear(); |
| 1745 | 1748 |
| 1746 // Update the usage stats; make sure they're reflected in GetServerProfiles. | 1749 // Update the usage stats; make sure they're reflected in GetServerProfiles. |
| 1747 inputs.back().set_use_count(4U); | 1750 inputs.back().set_use_count(4U); |
| 1748 inputs.back().set_use_date(base::Time()); | 1751 inputs.back().set_use_date(base::Time()); |
| 1749 table_->UpdateServerCardUsageStats(inputs.back()); | 1752 table_->UpdateServerCardUsageStats(inputs.back()); |
| 1750 table_->GetServerCreditCards(&outputs.get()); | 1753 table_->GetServerCreditCards(&outputs.get()); |
| 1751 ASSERT_EQ(1u, outputs.size()); | 1754 ASSERT_EQ(1u, outputs.size()); |
| 1752 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); | 1755 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); |
| 1753 EXPECT_EQ(4U, outputs[0]->use_count()); | 1756 EXPECT_EQ(4U, outputs[0]->use_count()); |
| 1754 EXPECT_EQ(base::Time(), outputs[0]->use_date()); | 1757 EXPECT_EQ(base::Time(), outputs[0]->use_date()); |
| 1758 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1755 outputs.clear(); | 1759 outputs.clear(); |
| 1756 | 1760 |
| 1757 // Setting the cards again shouldn't delete the usage stats. | 1761 // Setting the cards again shouldn't delete the usage stats. |
| 1758 table_->SetServerCreditCards(inputs); | 1762 table_->SetServerCreditCards(inputs); |
| 1759 table_->GetServerCreditCards(&outputs.get()); | 1763 table_->GetServerCreditCards(&outputs.get()); |
| 1760 ASSERT_EQ(1u, outputs.size()); | 1764 ASSERT_EQ(1u, outputs.size()); |
| 1761 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); | 1765 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); |
| 1762 EXPECT_EQ(4U, outputs[0]->use_count()); | 1766 EXPECT_EQ(4U, outputs[0]->use_count()); |
| 1763 EXPECT_EQ(base::Time(), outputs[0]->use_date()); | 1767 EXPECT_EQ(base::Time(), outputs[0]->use_date()); |
| 1768 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1764 outputs.clear(); | 1769 outputs.clear(); |
| 1765 | 1770 |
| 1766 // Set a card list where the card is missing --- this should clear metadata. | 1771 // Set a card list where the card is missing --- this should clear metadata. |
| 1767 CreditCard masked_card2(CreditCard::MASKED_SERVER_CARD, "b456"); | 1772 CreditCard masked_card2(CreditCard::MASKED_SERVER_CARD, "b456"); |
| 1768 inputs.back() = masked_card2; | 1773 inputs.back() = masked_card2; |
| 1769 table_->SetServerCreditCards(inputs); | 1774 table_->SetServerCreditCards(inputs); |
| 1770 | 1775 |
| 1771 // Back to the original card list. | 1776 // Back to the original card list. |
| 1772 inputs.back() = masked_card; | 1777 inputs.back() = masked_card; |
| 1773 table_->SetServerCreditCards(inputs); | 1778 table_->SetServerCreditCards(inputs); |
| 1774 table_->GetServerCreditCards(&outputs.get()); | 1779 table_->GetServerCreditCards(&outputs.get()); |
| 1775 ASSERT_EQ(1u, outputs.size()); | 1780 ASSERT_EQ(1u, outputs.size()); |
| 1776 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); | 1781 EXPECT_EQ(masked_card.server_id(), outputs[0]->server_id()); |
| 1777 EXPECT_EQ(1U, outputs[0]->use_count()); | 1782 EXPECT_EQ(1U, outputs[0]->use_count()); |
| 1778 EXPECT_NE(base::Time(), outputs[0]->use_date()); | 1783 EXPECT_NE(base::Time(), outputs[0]->use_date()); |
| 1784 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1779 outputs.clear(); | 1785 outputs.clear(); |
| 1780 } | 1786 } |
| 1781 | 1787 |
| 1782 TEST_F(AutofillTableTest, SetServerProfile) { | 1788 TEST_F(AutofillTableTest, SetServerProfile) { |
| 1783 AutofillProfile one(AutofillProfile::SERVER_PROFILE, "a123"); | 1789 AutofillProfile one(AutofillProfile::SERVER_PROFILE, "a123"); |
| 1784 std::vector<AutofillProfile> inputs; | 1790 std::vector<AutofillProfile> inputs; |
| 1785 inputs.push_back(one); | 1791 inputs.push_back(one); |
| 1786 table_->SetServerProfiles(inputs); | 1792 table_->SetServerProfiles(inputs); |
| 1787 | 1793 |
| 1788 std::vector<AutofillProfile*> outputs; | 1794 std::vector<AutofillProfile*> outputs; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1812 std::vector<AutofillProfile> inputs; | 1818 std::vector<AutofillProfile> inputs; |
| 1813 inputs.push_back(one); | 1819 inputs.push_back(one); |
| 1814 table_->SetServerProfiles(inputs); | 1820 table_->SetServerProfiles(inputs); |
| 1815 | 1821 |
| 1816 ScopedVector<AutofillProfile> outputs; | 1822 ScopedVector<AutofillProfile> outputs; |
| 1817 table_->GetServerProfiles(&outputs.get()); | 1823 table_->GetServerProfiles(&outputs.get()); |
| 1818 ASSERT_EQ(1u, outputs.size()); | 1824 ASSERT_EQ(1u, outputs.size()); |
| 1819 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); | 1825 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); |
| 1820 EXPECT_EQ(0U, outputs[0]->use_count()); | 1826 EXPECT_EQ(0U, outputs[0]->use_count()); |
| 1821 EXPECT_EQ(base::Time(), outputs[0]->use_date()); | 1827 EXPECT_EQ(base::Time(), outputs[0]->use_date()); |
| 1828 // We don't track modification date for server profiles. It should always be |
| 1829 // base::Time(). |
| 1830 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1822 outputs.clear(); | 1831 outputs.clear(); |
| 1823 | 1832 |
| 1824 // Update the usage stats; make sure they're reflected in GetServerProfiles. | 1833 // Update the usage stats; make sure they're reflected in GetServerProfiles. |
| 1825 inputs.back().set_use_count(4U); | 1834 inputs.back().set_use_count(4U); |
| 1826 inputs.back().set_use_date(base::Time::Now()); | 1835 inputs.back().set_use_date(base::Time::Now()); |
| 1827 table_->UpdateServerAddressUsageStats(inputs.back()); | 1836 table_->UpdateServerAddressUsageStats(inputs.back()); |
| 1828 table_->GetServerProfiles(&outputs.get()); | 1837 table_->GetServerProfiles(&outputs.get()); |
| 1829 ASSERT_EQ(1u, outputs.size()); | 1838 ASSERT_EQ(1u, outputs.size()); |
| 1830 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); | 1839 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); |
| 1831 EXPECT_EQ(4U, outputs[0]->use_count()); | 1840 EXPECT_EQ(4U, outputs[0]->use_count()); |
| 1832 EXPECT_NE(base::Time(), outputs[0]->use_date()); | 1841 EXPECT_NE(base::Time(), outputs[0]->use_date()); |
| 1842 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1833 outputs.clear(); | 1843 outputs.clear(); |
| 1834 | 1844 |
| 1835 // Setting the profiles again shouldn't delete the usage stats. | 1845 // Setting the profiles again shouldn't delete the usage stats. |
| 1836 table_->SetServerProfiles(inputs); | 1846 table_->SetServerProfiles(inputs); |
| 1837 table_->GetServerProfiles(&outputs.get()); | 1847 table_->GetServerProfiles(&outputs.get()); |
| 1838 ASSERT_EQ(1u, outputs.size()); | 1848 ASSERT_EQ(1u, outputs.size()); |
| 1839 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); | 1849 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); |
| 1840 EXPECT_EQ(4U, outputs[0]->use_count()); | 1850 EXPECT_EQ(4U, outputs[0]->use_count()); |
| 1841 EXPECT_NE(base::Time(), outputs[0]->use_date()); | 1851 EXPECT_NE(base::Time(), outputs[0]->use_date()); |
| 1852 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1842 outputs.clear(); | 1853 outputs.clear(); |
| 1843 | 1854 |
| 1844 // Set a null profile list --- this should clear metadata. | 1855 // Set a null profile list --- this should clear metadata. |
| 1845 table_->SetServerProfiles(std::vector<AutofillProfile>()); | 1856 table_->SetServerProfiles(std::vector<AutofillProfile>()); |
| 1846 // Reset the old profile list and see the metadata is reset. | 1857 // Reset the old profile list and see the metadata is reset. |
| 1847 table_->SetServerProfiles(inputs); | 1858 table_->SetServerProfiles(inputs); |
| 1848 table_->GetServerProfiles(&outputs.get()); | 1859 table_->GetServerProfiles(&outputs.get()); |
| 1849 ASSERT_EQ(1u, outputs.size()); | 1860 ASSERT_EQ(1u, outputs.size()); |
| 1850 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); | 1861 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); |
| 1851 EXPECT_EQ(0U, outputs[0]->use_count()); | 1862 EXPECT_EQ(0U, outputs[0]->use_count()); |
| 1852 EXPECT_EQ(base::Time(), outputs[0]->use_date()); | 1863 EXPECT_EQ(base::Time(), outputs[0]->use_date()); |
| 1864 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1853 outputs.clear(); | 1865 outputs.clear(); |
| 1854 } | 1866 } |
| 1855 | 1867 |
| 1856 // Tests that deleting time ranges re-masks server credit cards that were | 1868 // Tests that deleting time ranges re-masks server credit cards that were |
| 1857 // unmasked in that time. | 1869 // unmasked in that time. |
| 1858 TEST_F(AutofillTableTest, DeleteUnmaskedCard) { | 1870 TEST_F(AutofillTableTest, DeleteUnmaskedCard) { |
| 1859 // This isn't the exact unmasked time, since the database will use the | 1871 // This isn't the exact unmasked time, since the database will use the |
| 1860 // current time that it is called. The code below has to be approximate. | 1872 // current time that it is called. The code below has to be approximate. |
| 1861 base::Time unmasked_time = base::Time::Now(); | 1873 base::Time unmasked_time = base::Time::Now(); |
| 1862 | 1874 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1979 for (size_t j = 0; j < kTestCases[i].expected_suggestion_count; ++j) { | 1991 for (size_t j = 0; j < kTestCases[i].expected_suggestion_count; ++j) { |
| 1980 EXPECT_EQ(ASCIIToUTF16(kTestCases[i].expected_suggestion[j]), v[j]); | 1992 EXPECT_EQ(ASCIIToUTF16(kTestCases[i].expected_suggestion[j]), v[j]); |
| 1981 } | 1993 } |
| 1982 | 1994 |
| 1983 changes.clear(); | 1995 changes.clear(); |
| 1984 table_->RemoveFormElementsAddedBetween(t1, Time(), &changes); | 1996 table_->RemoveFormElementsAddedBetween(t1, Time(), &changes); |
| 1985 } | 1997 } |
| 1986 } | 1998 } |
| 1987 | 1999 |
| 1988 } // namespace autofill | 2000 } // namespace autofill |
| OLD | NEW |