| 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 17 matching lines...) Expand all Loading... |
| 28 #include "components/autofill/core/browser/autofill_type.h" | 28 #include "components/autofill/core/browser/autofill_type.h" |
| 29 #include "components/autofill/core/browser/credit_card.h" | 29 #include "components/autofill/core/browser/credit_card.h" |
| 30 #include "components/autofill/core/browser/webdata/autofill_change.h" | 30 #include "components/autofill/core/browser/webdata/autofill_change.h" |
| 31 #include "components/autofill/core/browser/webdata/autofill_entry.h" | 31 #include "components/autofill/core/browser/webdata/autofill_entry.h" |
| 32 #include "components/autofill/core/browser/webdata/autofill_table.h" | 32 #include "components/autofill/core/browser/webdata/autofill_table.h" |
| 33 #include "components/autofill/core/common/autofill_constants.h" | 33 #include "components/autofill/core/common/autofill_constants.h" |
| 34 #include "components/autofill/core/common/autofill_switches.h" | 34 #include "components/autofill/core/common/autofill_switches.h" |
| 35 #include "components/autofill/core/common/autofill_util.h" | 35 #include "components/autofill/core/common/autofill_util.h" |
| 36 #include "components/autofill/core/common/form_field_data.h" | 36 #include "components/autofill/core/common/form_field_data.h" |
| 37 #include "components/os_crypt/os_crypt_mocker.h" | 37 #include "components/os_crypt/os_crypt_mocker.h" |
| 38 #include "components/sync/protocol/entity_metadata.pb.h" |
| 39 #include "components/sync/protocol/model_type_state.pb.h" |
| 38 #include "components/webdata/common/web_database.h" | 40 #include "components/webdata/common/web_database.h" |
| 39 #include "sql/statement.h" | 41 #include "sql/statement.h" |
| 40 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
| 41 | 43 |
| 42 using base::ASCIIToUTF16; | 44 using base::ASCIIToUTF16; |
| 43 using base::Time; | 45 using base::Time; |
| 44 using base::TimeDelta; | 46 using base::TimeDelta; |
| 45 | 47 |
| 46 namespace autofill { | 48 namespace autofill { |
| 47 | 49 |
| (...skipping 1961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2009 EXPECT_EQ(test_case.expected_suggestion_count, v.size()); | 2011 EXPECT_EQ(test_case.expected_suggestion_count, v.size()); |
| 2010 for (size_t j = 0; j < test_case.expected_suggestion_count; ++j) { | 2012 for (size_t j = 0; j < test_case.expected_suggestion_count; ++j) { |
| 2011 EXPECT_EQ(ASCIIToUTF16(test_case.expected_suggestion[j]), v[j]); | 2013 EXPECT_EQ(ASCIIToUTF16(test_case.expected_suggestion[j]), v[j]); |
| 2012 } | 2014 } |
| 2013 | 2015 |
| 2014 changes.clear(); | 2016 changes.clear(); |
| 2015 table_->RemoveFormElementsAddedBetween(t1, Time(), &changes); | 2017 table_->RemoveFormElementsAddedBetween(t1, Time(), &changes); |
| 2016 } | 2018 } |
| 2017 } | 2019 } |
| 2018 | 2020 |
| 2021 TEST_F(AutofillTableTest, GetAllSyncMetadata) { |
| 2022 sync_pb::EntityMetadata metadata; |
| 2023 std::string storage_key = "storage_key"; |
| 2024 std::string storage_key2 = "storage_key2"; |
| 2025 metadata.set_sequence_number(1); |
| 2026 |
| 2027 EXPECT_TRUE( |
| 2028 table_->UpdateSyncMetadata(syncer::AUTOFILL, storage_key, metadata)); |
| 2029 |
| 2030 metadata.set_sequence_number(2); |
| 2031 EXPECT_TRUE( |
| 2032 table_->UpdateSyncMetadata(syncer::AUTOFILL, storage_key2, metadata)); |
| 2033 |
| 2034 syncer::EntityMetadataMap metadata_records; |
| 2035 EXPECT_TRUE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_records)); |
| 2036 |
| 2037 EXPECT_EQ(metadata_records.size(), 2u); |
| 2038 EXPECT_EQ(metadata_records[storage_key].sequence_number(), 1); |
| 2039 EXPECT_EQ(metadata_records[storage_key2].sequence_number(), 2); |
| 2040 } |
| 2041 |
| 2042 TEST_F(AutofillTableTest, WriteThenReadModelTypeState) { |
| 2043 sync_pb::ModelTypeState model_type_state; |
| 2044 sync_pb::ModelTypeState returned_state; |
| 2045 |
| 2046 EXPECT_FALSE(table_->GetModelTypeState(syncer::AUTOFILL, &returned_state)); |
| 2047 |
| 2048 model_type_state.set_initial_sync_done(true); |
| 2049 |
| 2050 EXPECT_TRUE(table_->UpdateModelTypeState(syncer::AUTOFILL, model_type_state)); |
| 2051 EXPECT_TRUE(table_->GetModelTypeState(syncer::AUTOFILL, &returned_state)); |
| 2052 |
| 2053 EXPECT_TRUE(returned_state.initial_sync_done()); |
| 2054 |
| 2055 // Test that updates replace the existing row. |
| 2056 model_type_state.set_initial_sync_done(false); |
| 2057 table_->UpdateModelTypeState(syncer::AUTOFILL, model_type_state); |
| 2058 |
| 2059 EXPECT_TRUE(table_->GetModelTypeState(syncer::AUTOFILL, &returned_state)); |
| 2060 EXPECT_FALSE(returned_state.initial_sync_done()); |
| 2061 } |
| 2062 |
| 2063 TEST_F(AutofillTableTest, WriteThenDeleteSyncMetadata) { |
| 2064 sync_pb::EntityMetadata metadata; |
| 2065 syncer::EntityMetadataMap returned_metadata; |
| 2066 std::string storage_key = "storage_key"; |
| 2067 sync_pb::ModelTypeState model_type_state; |
| 2068 |
| 2069 model_type_state.set_initial_sync_done(true); |
| 2070 |
| 2071 metadata.set_client_tag_hash("client_hash"); |
| 2072 |
| 2073 // Write the data into the store. |
| 2074 EXPECT_TRUE( |
| 2075 table_->UpdateSyncMetadata(syncer::AUTOFILL, storage_key, metadata)); |
| 2076 EXPECT_TRUE(table_->UpdateModelTypeState(syncer::AUTOFILL, model_type_state)); |
| 2077 // Delete the data we just wrote. |
| 2078 EXPECT_TRUE(table_->ClearSyncMetadata(syncer::AUTOFILL, storage_key)); |
| 2079 EXPECT_TRUE(table_->ClearModelTypeState(syncer::AUTOFILL)); |
| 2080 // It shouldn't be there any more. |
| 2081 EXPECT_TRUE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &returned_metadata)); |
| 2082 EXPECT_EQ(returned_metadata.size(), 0u); |
| 2083 EXPECT_FALSE(table_->GetModelTypeState(syncer::AUTOFILL, &model_type_state)); |
| 2084 } |
| 2085 |
| 2086 TEST_F(AutofillTableTest, ReadEmptySyncMetadata) { |
| 2087 syncer::EntityMetadataMap returned_metadata; |
| 2088 sync_pb::ModelTypeState state; |
| 2089 std::string storage_key = "storage_key"; |
| 2090 |
| 2091 EXPECT_TRUE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &returned_metadata)); |
| 2092 EXPECT_EQ(returned_metadata.size(), 0u); |
| 2093 } |
| 2094 |
| 2095 TEST_F(AutofillTableTest, CorruptSyncMetadata) { |
| 2096 syncer::EntityMetadataMap metadata; |
| 2097 sync_pb::ModelTypeState state; |
| 2098 std::string storage_key = "storage_key"; |
| 2099 |
| 2100 sql::Statement s(db_->GetSQLConnection()->GetUniqueStatement( |
| 2101 "INSERT OR REPLACE INTO autofill_sync_metadata " |
| 2102 "(storage_key, value) VALUES(?, ?)")); |
| 2103 s.BindString(0, storage_key); |
| 2104 s.BindString(1, "unparseable"); |
| 2105 |
| 2106 sql::Statement s2(db_->GetSQLConnection()->GetUniqueStatement( |
| 2107 "INSERT OR REPLACE INTO autofill_model_type_state " |
| 2108 "(rowid, value) VALUES(1, ?)")); |
| 2109 s2.BindString(0, "unparseable"); |
| 2110 |
| 2111 EXPECT_TRUE(s.Run()); |
| 2112 EXPECT_TRUE(s2.Run()); |
| 2113 |
| 2114 EXPECT_FALSE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata)); |
| 2115 EXPECT_FALSE(table_->GetModelTypeState(syncer::AUTOFILL, &state)); |
| 2116 } |
| 2117 |
| 2019 } // namespace autofill | 2118 } // namespace autofill |
| OLD | NEW |