| 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 "components/autofill/core/browser/webdata/autofill_table.h" | 5 #include "components/autofill/core/browser/webdata/autofill_table.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <tuple> | 9 #include <tuple> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 1831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1842 TEST_F(AutofillTableTest, SetServerProfileUpdateUsageStats) { | 1842 TEST_F(AutofillTableTest, SetServerProfileUpdateUsageStats) { |
| 1843 AutofillProfile one(AutofillProfile::SERVER_PROFILE, "a123"); | 1843 AutofillProfile one(AutofillProfile::SERVER_PROFILE, "a123"); |
| 1844 std::vector<AutofillProfile> inputs; | 1844 std::vector<AutofillProfile> inputs; |
| 1845 inputs.push_back(one); | 1845 inputs.push_back(one); |
| 1846 table_->SetServerProfiles(inputs); | 1846 table_->SetServerProfiles(inputs); |
| 1847 | 1847 |
| 1848 std::vector<std::unique_ptr<AutofillProfile>> outputs; | 1848 std::vector<std::unique_ptr<AutofillProfile>> outputs; |
| 1849 table_->GetServerProfiles(&outputs); | 1849 table_->GetServerProfiles(&outputs); |
| 1850 ASSERT_EQ(1u, outputs.size()); | 1850 ASSERT_EQ(1u, outputs.size()); |
| 1851 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); | 1851 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); |
| 1852 EXPECT_EQ(0U, outputs[0]->use_count()); | 1852 EXPECT_EQ(1U, outputs[0]->use_count()); |
| 1853 EXPECT_EQ(base::Time(), outputs[0]->use_date()); | 1853 EXPECT_NE(base::Time(), outputs[0]->use_date()); |
| 1854 // We don't track modification date for server profiles. It should always be | 1854 // We don't track modification date for server profiles. It should always be |
| 1855 // base::Time(). | 1855 // base::Time(). |
| 1856 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); | 1856 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1857 outputs.clear(); | 1857 outputs.clear(); |
| 1858 | 1858 |
| 1859 // Update the usage stats; make sure they're reflected in GetServerProfiles. | 1859 // Update the usage stats; make sure they're reflected in GetServerProfiles. |
| 1860 inputs.back().set_use_count(4U); | 1860 inputs.back().set_use_count(4U); |
| 1861 inputs.back().set_use_date(base::Time::Now()); | 1861 inputs.back().set_use_date(base::Time::Now()); |
| 1862 table_->UpdateServerAddressMetadata(inputs.back()); | 1862 table_->UpdateServerAddressMetadata(inputs.back()); |
| 1863 table_->GetServerProfiles(&outputs); | 1863 table_->GetServerProfiles(&outputs); |
| 1864 ASSERT_EQ(1u, outputs.size()); | 1864 ASSERT_EQ(1u, outputs.size()); |
| 1865 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); | 1865 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); |
| 1866 EXPECT_EQ(4U, outputs[0]->use_count()); | 1866 EXPECT_EQ(4U, outputs[0]->use_count()); |
| 1867 EXPECT_NE(base::Time(), outputs[0]->use_date()); | 1867 EXPECT_NE(base::Time(), outputs[0]->use_date()); |
| 1868 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); | 1868 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1869 outputs.clear(); | 1869 outputs.clear(); |
| 1870 | 1870 |
| 1871 // Setting the profiles again shouldn't delete the usage stats. | 1871 // Setting the profiles again shouldn't delete the usage stats. |
| 1872 table_->SetServerProfiles(inputs); | 1872 table_->SetServerProfiles(inputs); |
| 1873 table_->GetServerProfiles(&outputs); | 1873 table_->GetServerProfiles(&outputs); |
| 1874 ASSERT_EQ(1u, outputs.size()); | 1874 ASSERT_EQ(1u, outputs.size()); |
| 1875 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); | 1875 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); |
| 1876 EXPECT_EQ(4U, outputs[0]->use_count()); | 1876 EXPECT_EQ(4U, outputs[0]->use_count()); |
| 1877 EXPECT_NE(base::Time(), outputs[0]->use_date()); | 1877 EXPECT_NE(base::Time(), outputs[0]->use_date()); |
| 1878 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); | 1878 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); |
| 1879 outputs.clear(); | 1879 outputs.clear(); |
| 1880 | |
| 1881 // Set a null profile list --- this should clear metadata. | |
| 1882 table_->SetServerProfiles(std::vector<AutofillProfile>()); | |
| 1883 // Reset the old profile list and see the metadata is reset. | |
| 1884 table_->SetServerProfiles(inputs); | |
| 1885 table_->GetServerProfiles(&outputs); | |
| 1886 ASSERT_EQ(1u, outputs.size()); | |
| 1887 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); | |
| 1888 EXPECT_EQ(0U, outputs[0]->use_count()); | |
| 1889 EXPECT_EQ(base::Time(), outputs[0]->use_date()); | |
| 1890 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); | |
| 1891 outputs.clear(); | |
| 1892 } | 1880 } |
| 1893 | 1881 |
| 1894 // Tests that deleting time ranges re-masks server credit cards that were | 1882 // Tests that deleting time ranges re-masks server credit cards that were |
| 1895 // unmasked in that time. | 1883 // unmasked in that time. |
| 1896 TEST_F(AutofillTableTest, DeleteUnmaskedCard) { | 1884 TEST_F(AutofillTableTest, DeleteUnmaskedCard) { |
| 1897 // This isn't the exact unmasked time, since the database will use the | 1885 // This isn't the exact unmasked time, since the database will use the |
| 1898 // current time that it is called. The code below has to be approximate. | 1886 // current time that it is called. The code below has to be approximate. |
| 1899 base::Time unmasked_time = base::Time::Now(); | 1887 base::Time unmasked_time = base::Time::Now(); |
| 1900 | 1888 |
| 1901 // Add a masked card. | 1889 // Add a masked card. |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2113 sql::Statement s(db_->GetSQLConnection()->GetUniqueStatement( | 2101 sql::Statement s(db_->GetSQLConnection()->GetUniqueStatement( |
| 2114 "INSERT OR REPLACE INTO autofill_model_type_state " | 2102 "INSERT OR REPLACE INTO autofill_model_type_state " |
| 2115 "(rowid, value) VALUES(1, ?)")); | 2103 "(rowid, value) VALUES(1, ?)")); |
| 2116 s.BindString(0, "unparseable"); | 2104 s.BindString(0, "unparseable"); |
| 2117 EXPECT_TRUE(s.Run()); | 2105 EXPECT_TRUE(s.Run()); |
| 2118 | 2106 |
| 2119 EXPECT_FALSE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch)); | 2107 EXPECT_FALSE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch)); |
| 2120 } | 2108 } |
| 2121 | 2109 |
| 2122 } // namespace autofill | 2110 } // namespace autofill |
| OLD | NEW |