| 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   sync_pb::ModelTypeState model_type_state; | 
|  | 2031   model_type_state.set_initial_sync_done(true); | 
|  | 2032 | 
|  | 2033   EXPECT_TRUE(table_->UpdateModelTypeState(syncer::AUTOFILL, model_type_state)); | 
|  | 2034 | 
|  | 2035   metadata.set_sequence_number(2); | 
|  | 2036   EXPECT_TRUE( | 
|  | 2037       table_->UpdateSyncMetadata(syncer::AUTOFILL, storage_key2, metadata)); | 
|  | 2038 | 
|  | 2039   syncer::MetadataBatch metadata_batch; | 
|  | 2040   EXPECT_TRUE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch)); | 
|  | 2041 | 
|  | 2042   EXPECT_TRUE(metadata_batch.GetModelTypeState().initial_sync_done()); | 
|  | 2043 | 
|  | 2044   syncer::EntityMetadataMap metadata_records = metadata_batch.TakeAllMetadata(); | 
|  | 2045 | 
|  | 2046   EXPECT_EQ(metadata_records.size(), 2u); | 
|  | 2047   EXPECT_EQ(metadata_records[storage_key].sequence_number(), 1); | 
|  | 2048   EXPECT_EQ(metadata_records[storage_key2].sequence_number(), 2); | 
|  | 2049 | 
|  | 2050   // Now check that a model type state update replaces the old value | 
|  | 2051   model_type_state.set_initial_sync_done(false); | 
|  | 2052   EXPECT_TRUE(table_->UpdateModelTypeState(syncer::AUTOFILL, model_type_state)); | 
|  | 2053 | 
|  | 2054   EXPECT_TRUE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch)); | 
|  | 2055   EXPECT_FALSE(metadata_batch.GetModelTypeState().initial_sync_done()); | 
|  | 2056 } | 
|  | 2057 | 
|  | 2058 TEST_F(AutofillTableTest, WriteThenDeleteSyncMetadata) { | 
|  | 2059   sync_pb::EntityMetadata metadata; | 
|  | 2060   syncer::MetadataBatch metadata_batch; | 
|  | 2061   std::string storage_key = "storage_key"; | 
|  | 2062   sync_pb::ModelTypeState model_type_state; | 
|  | 2063 | 
|  | 2064   model_type_state.set_initial_sync_done(true); | 
|  | 2065 | 
|  | 2066   metadata.set_client_tag_hash("client_hash"); | 
|  | 2067 | 
|  | 2068   // Write the data into the store. | 
|  | 2069   EXPECT_TRUE( | 
|  | 2070       table_->UpdateSyncMetadata(syncer::AUTOFILL, storage_key, metadata)); | 
|  | 2071   EXPECT_TRUE(table_->UpdateModelTypeState(syncer::AUTOFILL, model_type_state)); | 
|  | 2072   // Delete the data we just wrote. | 
|  | 2073   EXPECT_TRUE(table_->ClearSyncMetadata(syncer::AUTOFILL, storage_key)); | 
|  | 2074   // It shouldn't be there any more. | 
|  | 2075   EXPECT_TRUE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch)); | 
|  | 2076 | 
|  | 2077   syncer::EntityMetadataMap metadata_records = metadata_batch.TakeAllMetadata(); | 
|  | 2078   EXPECT_EQ(metadata_records.size(), 0u); | 
|  | 2079 | 
|  | 2080   // Now delete the model type state. | 
|  | 2081   EXPECT_TRUE(table_->ClearModelTypeState(syncer::AUTOFILL)); | 
|  | 2082   EXPECT_FALSE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch)); | 
|  | 2083 } | 
|  | 2084 | 
|  | 2085 TEST_F(AutofillTableTest, CorruptSyncMetadata) { | 
|  | 2086   syncer::MetadataBatch metadata_batch; | 
|  | 2087   sync_pb::ModelTypeState state; | 
|  | 2088   std::string storage_key = "storage_key"; | 
|  | 2089 | 
|  | 2090   sql::Statement s(db_->GetSQLConnection()->GetUniqueStatement( | 
|  | 2091       "INSERT OR REPLACE INTO autofill_sync_metadata " | 
|  | 2092       "(storage_key, value) VALUES(?, ?)")); | 
|  | 2093   s.BindString(0, storage_key); | 
|  | 2094   s.BindString(1, "unparseable"); | 
|  | 2095 | 
|  | 2096   sql::Statement s2(db_->GetSQLConnection()->GetUniqueStatement( | 
|  | 2097       "INSERT OR REPLACE INTO autofill_model_type_state " | 
|  | 2098       "(rowid, value) VALUES(1, ?)")); | 
|  | 2099   s2.BindString(0, "unparseable"); | 
|  | 2100 | 
|  | 2101   EXPECT_TRUE(s.Run()); | 
|  | 2102   EXPECT_TRUE(s2.Run()); | 
|  | 2103 | 
|  | 2104   EXPECT_FALSE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch)); | 
|  | 2105 } | 
|  | 2106 | 
| 2019 }  // namespace autofill | 2107 }  // namespace autofill | 
| OLD | NEW | 
|---|