#include "components/sync/model/data_type_store_impl.h"
#include <map>
#include <optional>
#include <string>
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/storage_type.h"
#include "components/sync/model/model_error.h"
#include "components/sync/protocol/data_type_state.pb.h"
#include "components/sync/protocol/entity_metadata.pb.h"
#include "components/sync/test/data_type_store_test_util.h"
#include "components/sync/test/test_matchers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace syncer {
namespace {
IsEmpty;
Not;
Pair;
SizeIs;
sync_pb::DataTypeState CreateDataTypeState(const std::string& value) { … }
sync_pb::EntityMetadata CreateEntityMetadata(const std::string& value) { … }
static void CaptureError(std::optional<ModelError>* dst,
const std::optional<ModelError>& error) { … }
void CaptureErrorAndRecords(
std::optional<ModelError>* dst_error,
std::unique_ptr<DataTypeStore::RecordList>* dst_records,
const std::optional<ModelError>& error,
std::unique_ptr<DataTypeStore::RecordList> records) { … }
void CaptureErrorAndMetadataBatch(std::optional<ModelError>* dst_error,
std::unique_ptr<MetadataBatch>* dst_batch,
const std::optional<ModelError>& error,
std::unique_ptr<MetadataBatch> batch) { … }
void CaptureErrorRecordsAndIdList(
std::optional<ModelError>* dst_error,
std::unique_ptr<DataTypeStore::RecordList>* dst_records,
std::unique_ptr<DataTypeStore::IdList>* dst_id_list,
const std::optional<ModelError>& error,
std::unique_ptr<DataTypeStore::RecordList> records,
std::unique_ptr<DataTypeStore::IdList> missing_id_list) { … }
void WriteData(DataTypeStore* store,
const std::string& key,
const std::string& data) { … }
void WriteMetadata(DataTypeStore* store,
const std::string& key,
const sync_pb::EntityMetadata& metadata) { … }
void WriteDataTypeState(DataTypeStore* store,
const sync_pb::DataTypeState& state) { … }
void ReadStoreContents(DataTypeStore* store,
std::unique_ptr<DataTypeStore::RecordList>* data_records,
std::unique_ptr<MetadataBatch>* metadata_batch) { … }
void VerifyMetadata(
const std::unique_ptr<MetadataBatch>& batch,
const sync_pb::DataTypeState& state,
std::map<std::string, sync_pb::EntityMetadata> expected_metadata) { … }
MATCHER_P2(RecordMatches, id, value, "") { … }
}
class DataTypeStoreImplTest : public testing::TestWithParam<StorageType> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(DataTypeStoreImplTest, ReadEmptyStore) { … }
TEST_P(DataTypeStoreImplTest, WriteThenRead) { … }
TEST_P(DataTypeStoreImplTest, WriteThenReadWithPreprocessing) { … }
TEST_P(DataTypeStoreImplTest, WriteThenReadWithPreprocessingError) { … }
TEST_P(DataTypeStoreImplTest, WriteThenDeleteAll) { … }
TEST_P(DataTypeStoreImplTest, MissingDataTypeState) { … }
TEST_P(DataTypeStoreImplTest, ReadMissingDataRecords) { … }
TEST_P(DataTypeStoreImplTest, ReadAllDataAndMetadata) { … }
TEST(DataTypeStoreImplWithTwoStoreTest, TwoStoresWithSharedBackend) { … }
TEST(DataTypeStoreImplWithTwoStoreTest, DeleteAllWithSharedBackend) { … }
TEST(DataTypeStoreImplWithTwoStoreTest,
AccountStoreDeleteAllWithSharedBackendAndSameDataType) { … }
TEST(DataTypeStoreImplWithTwoStoreTest,
UnspecifiedStoreDeleteAllWithSharedBackendAndSameDataType) { … }
}