| 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 1805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1816 TEST_F(AutofillTableTest, SetServerProfileUpdateUsageStats) { | 1816 TEST_F(AutofillTableTest, SetServerProfileUpdateUsageStats) { |
| 1817 AutofillProfile one(AutofillProfile::SERVER_PROFILE, "a123"); | 1817 AutofillProfile one(AutofillProfile::SERVER_PROFILE, "a123"); |
| 1818 std::vector<AutofillProfile> inputs; | 1818 std::vector<AutofillProfile> inputs; |
| 1819 inputs.push_back(one); | 1819 inputs.push_back(one); |
| 1820 table_->SetServerProfiles(inputs); | 1820 table_->SetServerProfiles(inputs); |
| 1821 | 1821 |
| 1822 std::vector<std::unique_ptr<AutofillProfile>> outputs; | 1822 std::vector<std::unique_ptr<AutofillProfile>> outputs; |
| 1823 table_->GetServerProfiles(&outputs); | 1823 table_->GetServerProfiles(&outputs); |
| 1824 ASSERT_EQ(1u, outputs.size()); | 1824 ASSERT_EQ(1u, outputs.size()); |
| 1825 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); | 1825 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); |
| 1826 EXPECT_EQ(0U, outputs[0]->use_count()); | 1826 EXPECT_EQ(1U, outputs[0]->use_count()); |
| 1827 EXPECT_EQ(base::Time(), outputs[0]->use_date()); | 1827 EXPECT_NE(base::Time(), outputs[0]->use_date()); |
| 1828 // 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 |
| 1829 // base::Time(). | 1829 // base::Time(). |
| 1830 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); | 1830 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1831 outputs.clear(); | 1831 outputs.clear(); |
| 1832 | 1832 |
| 1833 // Update the usage stats; make sure they're reflected in GetServerProfiles. | 1833 // Update the usage stats; make sure they're reflected in GetServerProfiles. |
| 1834 inputs.back().set_use_count(4U); | 1834 inputs.back().set_use_count(4U); |
| 1835 inputs.back().set_use_date(base::Time::Now()); | 1835 inputs.back().set_use_date(base::Time::Now()); |
| 1836 table_->UpdateServerAddressMetadata(inputs.back()); | 1836 table_->UpdateServerAddressMetadata(inputs.back()); |
| 1837 table_->GetServerProfiles(&outputs); | 1837 table_->GetServerProfiles(&outputs); |
| 1838 ASSERT_EQ(1u, outputs.size()); | 1838 ASSERT_EQ(1u, outputs.size()); |
| 1839 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); | 1839 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); |
| 1840 EXPECT_EQ(4U, outputs[0]->use_count()); | 1840 EXPECT_EQ(4U, outputs[0]->use_count()); |
| 1841 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()); | 1842 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1843 outputs.clear(); | 1843 outputs.clear(); |
| 1844 | 1844 |
| 1845 // Setting the profiles again shouldn't delete the usage stats. | 1845 // Setting the profiles again shouldn't delete the usage stats. |
| 1846 table_->SetServerProfiles(inputs); | 1846 table_->SetServerProfiles(inputs); |
| 1847 table_->GetServerProfiles(&outputs); | 1847 table_->GetServerProfiles(&outputs); |
| 1848 ASSERT_EQ(1u, outputs.size()); | 1848 ASSERT_EQ(1u, outputs.size()); |
| 1849 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); | 1849 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); |
| 1850 EXPECT_EQ(4U, outputs[0]->use_count()); | 1850 EXPECT_EQ(4U, outputs[0]->use_count()); |
| 1851 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()); | 1852 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1853 outputs.clear(); | 1853 outputs.clear(); |
| 1854 | |
| 1855 // Set a null profile list --- this should clear metadata. | |
| 1856 table_->SetServerProfiles(std::vector<AutofillProfile>()); | |
| 1857 // Reset the old profile list and see the metadata is reset. | |
| 1858 table_->SetServerProfiles(inputs); | |
| 1859 table_->GetServerProfiles(&outputs); | |
| 1860 ASSERT_EQ(1u, outputs.size()); | |
| 1861 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); | |
| 1862 EXPECT_EQ(0U, outputs[0]->use_count()); | |
| 1863 EXPECT_EQ(base::Time(), outputs[0]->use_date()); | |
| 1864 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); | |
| 1865 outputs.clear(); | |
| 1866 } | 1854 } |
| 1867 | 1855 |
| 1868 // Tests that deleting time ranges re-masks server credit cards that were | 1856 // Tests that deleting time ranges re-masks server credit cards that were |
| 1869 // unmasked in that time. | 1857 // unmasked in that time. |
| 1870 TEST_F(AutofillTableTest, DeleteUnmaskedCard) { | 1858 TEST_F(AutofillTableTest, DeleteUnmaskedCard) { |
| 1871 // This isn't the exact unmasked time, since the database will use the | 1859 // This isn't the exact unmasked time, since the database will use the |
| 1872 // current time that it is called. The code below has to be approximate. | 1860 // current time that it is called. The code below has to be approximate. |
| 1873 base::Time unmasked_time = base::Time::Now(); | 1861 base::Time unmasked_time = base::Time::Now(); |
| 1874 | 1862 |
| 1875 // Add a masked card. | 1863 // Add a masked card. |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2076 "(rowid, value) VALUES(1, ?)")); | 2064 "(rowid, value) VALUES(1, ?)")); |
| 2077 s2.BindString(0, "unparseable"); | 2065 s2.BindString(0, "unparseable"); |
| 2078 | 2066 |
| 2079 EXPECT_TRUE(s.Run()); | 2067 EXPECT_TRUE(s.Run()); |
| 2080 EXPECT_TRUE(s2.Run()); | 2068 EXPECT_TRUE(s2.Run()); |
| 2081 | 2069 |
| 2082 EXPECT_FALSE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch)); | 2070 EXPECT_FALSE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch)); |
| 2083 } | 2071 } |
| 2084 | 2072 |
| 2085 } // namespace autofill | 2073 } // namespace autofill |
| OLD | NEW |