chromium/components/sync/model/data_type_store_impl_unittest.cc

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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) {}

// Following functions capture parameters passed to callbacks into variables
// provided by test. They can be passed as callbacks to DataTypeStore
// functions.
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 to verify contents of returned RecordList .
MATCHER_P2(RecordMatches, id, value, "") {}

}  // namespace

class DataTypeStoreImplTest : public testing::TestWithParam<StorageType> {};

INSTANTIATE_TEST_SUITE_P();

// Test read functions on empty store.
TEST_P(DataTypeStoreImplTest, ReadEmptyStore) {}

// Test that records that are written to store later can be read from it.
TEST_P(DataTypeStoreImplTest, WriteThenRead) {}

TEST_P(DataTypeStoreImplTest, WriteThenReadWithPreprocessing) {}

TEST_P(DataTypeStoreImplTest, WriteThenReadWithPreprocessingError) {}

// Test that records that DeleteAllDataAndMetadata() deletes everything.
TEST_P(DataTypeStoreImplTest, WriteThenDeleteAll) {}

// Test that if DataTypeState is not set then ReadAllMetadata still succeeds
// and returns entry metadata records.
TEST_P(DataTypeStoreImplTest, MissingDataTypeState) {}

// Test that when reading data records by id, if one of the ids is missing
// operation still succeeds and missing id is returned in missing_id_list.
TEST_P(DataTypeStoreImplTest, ReadMissingDataRecords) {}

TEST_P(DataTypeStoreImplTest, ReadAllDataAndMetadata) {}

// Test that stores for different types that share the same backend don't
// interfere with each other's records.
TEST(DataTypeStoreImplWithTwoStoreTest, TwoStoresWithSharedBackend) {}

// Test that records that DeleteAllDataAndMetadata() does not delete data from
// another store when the backend is shared.
TEST(DataTypeStoreImplWithTwoStoreTest, DeleteAllWithSharedBackend) {}

TEST(DataTypeStoreImplWithTwoStoreTest,
     AccountStoreDeleteAllWithSharedBackendAndSameDataType) {}

TEST(DataTypeStoreImplWithTwoStoreTest,
     UnspecifiedStoreDeleteAllWithSharedBackendAndSameDataType) {}

}  // namespace syncer