| 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, WriteThenReadSyncMetadata) { |
| 2022 sync_pb::EntityMetadata metadata; |
| 2023 sync_pb::EntityMetadata returned_metadata; |
| 2024 std::string storage_key = "storage_key"; |
| 2025 |
| 2026 sync_pb::ModelTypeState model_type_state; |
| 2027 sync_pb::ModelTypeState returned_state; |
| 2028 |
| 2029 EXPECT_FALSE(table_->GetModelTypeState(syncer::AUTOFILL, &returned_state)); |
| 2030 EXPECT_FALSE(table_->GetSyncMetadata(syncer::AUTOFILL, storage_key, |
| 2031 &returned_metadata)); |
| 2032 |
| 2033 metadata.set_client_tag_hash("client_hash"); |
| 2034 metadata.set_server_id("server_id"); |
| 2035 metadata.set_sequence_number(4); |
| 2036 |
| 2037 model_type_state.set_initial_sync_done(true); |
| 2038 |
| 2039 EXPECT_TRUE( |
| 2040 table_->UpdateSyncMetadata(syncer::AUTOFILL, storage_key, metadata)); |
| 2041 EXPECT_TRUE(table_->UpdateModelTypeState(syncer::AUTOFILL, model_type_state)); |
| 2042 |
| 2043 EXPECT_TRUE(table_->GetSyncMetadata(syncer::AUTOFILL, storage_key, |
| 2044 &returned_metadata)); |
| 2045 EXPECT_TRUE(table_->GetModelTypeState(syncer::AUTOFILL, &returned_state)); |
| 2046 |
| 2047 EXPECT_EQ(returned_metadata.client_tag_hash(), "client_hash"); |
| 2048 EXPECT_EQ(returned_metadata.server_id(), "server_id"); |
| 2049 EXPECT_EQ(returned_metadata.sequence_number(), 4); |
| 2050 |
| 2051 EXPECT_TRUE(returned_state.initial_sync_done()); |
| 2052 |
| 2053 // Test that updates replace the existing row. |
| 2054 model_type_state.set_initial_sync_done(false); |
| 2055 table_->UpdateModelTypeState(syncer::AUTOFILL, model_type_state); |
| 2056 |
| 2057 EXPECT_TRUE(table_->GetModelTypeState(syncer::AUTOFILL, &returned_state)); |
| 2058 EXPECT_FALSE(returned_state.initial_sync_done()); |
| 2059 } |
| 2060 |
| 2061 TEST_F(AutofillTableTest, WriteThenDeleteSyncMetadata) { |
| 2062 sync_pb::EntityMetadata metadata; |
| 2063 std::string storage_key = "storage_key"; |
| 2064 sync_pb::ModelTypeState model_type_state; |
| 2065 |
| 2066 model_type_state.set_initial_sync_done(true); |
| 2067 |
| 2068 metadata.set_client_tag_hash("client_hash"); |
| 2069 |
| 2070 // Write the data into the store. |
| 2071 EXPECT_TRUE( |
| 2072 table_->UpdateSyncMetadata(syncer::AUTOFILL, storage_key, metadata)); |
| 2073 EXPECT_TRUE(table_->UpdateModelTypeState(syncer::AUTOFILL, model_type_state)); |
| 2074 // Delete the data we just wrote. |
| 2075 EXPECT_TRUE(table_->ClearSyncMetadata(syncer::AUTOFILL, storage_key)); |
| 2076 EXPECT_TRUE(table_->ClearModelTypeState(syncer::AUTOFILL)); |
| 2077 // It shouldn't be there any more. |
| 2078 EXPECT_FALSE( |
| 2079 table_->GetSyncMetadata(syncer::AUTOFILL, storage_key, &metadata)); |
| 2080 EXPECT_FALSE(table_->GetModelTypeState(syncer::AUTOFILL, &model_type_state)); |
| 2081 } |
| 2082 |
| 2083 TEST_F(AutofillTableTest, ReadEmptySyncMetadata) { |
| 2084 sync_pb::EntityMetadata returned_metadata; |
| 2085 sync_pb::ModelTypeState state; |
| 2086 std::string storage_key = "storage_key"; |
| 2087 |
| 2088 EXPECT_FALSE(table_->GetSyncMetadata(syncer::AUTOFILL, storage_key, |
| 2089 &returned_metadata)); |
| 2090 EXPECT_FALSE(table_->GetModelTypeState(syncer::AUTOFILL, &state)); |
| 2091 } |
| 2092 |
| 2093 TEST_F(AutofillTableTest, CorruptSyncMetadata) { |
| 2094 sync_pb::EntityMetadata metadata; |
| 2095 sync_pb::ModelTypeState state; |
| 2096 std::string storage_key = "storage_key"; |
| 2097 |
| 2098 sql::Statement s(db_->GetSQLConnection()->GetUniqueStatement( |
| 2099 "INSERT OR REPLACE INTO autofill_sync_metadata " |
| 2100 "(storage_key, value) VALUES(?, ?)")); |
| 2101 s.BindString(0, storage_key); |
| 2102 s.BindString(1, "unparseable"); |
| 2103 |
| 2104 sql::Statement s2(db_->GetSQLConnection()->GetUniqueStatement( |
| 2105 "INSERT OR REPLACE INTO autofill_model_type_state " |
| 2106 "(rowid, value) VALUES(1, ?)")); |
| 2107 s2.BindString(0, "unparseable"); |
| 2108 |
| 2109 EXPECT_TRUE(s.Run()); |
| 2110 EXPECT_TRUE(s2.Run()); |
| 2111 |
| 2112 EXPECT_FALSE( |
| 2113 table_->GetSyncMetadata(syncer::AUTOFILL, storage_key, &metadata)); |
| 2114 EXPECT_FALSE(table_->GetModelTypeState(syncer::AUTOFILL, &state)); |
| 2115 } |
| 2116 |
| 2117 TEST_F(AutofillTableTest, GetAllSyncMetadata) { |
| 2118 sync_pb::EntityMetadata metadata; |
| 2119 std::string storage_key = "storage_key"; |
| 2120 std::string storage_key2 = "storage_key2"; |
| 2121 metadata.set_sequence_number(1); |
| 2122 |
| 2123 EXPECT_TRUE( |
| 2124 table_->UpdateSyncMetadata(syncer::AUTOFILL, storage_key, metadata)); |
| 2125 |
| 2126 metadata.set_sequence_number(2); |
| 2127 EXPECT_TRUE( |
| 2128 table_->UpdateSyncMetadata(syncer::AUTOFILL, storage_key2, metadata)); |
| 2129 |
| 2130 std::vector<sync_pb::EntityMetadata> metadata_records; |
| 2131 EXPECT_TRUE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_records)); |
| 2132 |
| 2133 EXPECT_EQ(metadata_records.size(), 2u); |
| 2134 EXPECT_EQ(metadata_records[0].sequence_number(), 1); |
| 2135 EXPECT_EQ(metadata_records[1].sequence_number(), 2); |
| 2136 } |
| 2137 |
| 2019 } // namespace autofill | 2138 } // namespace autofill |
| OLD | NEW |