chromium/components/prefs/json_pref_store_unittest.cc

// Copyright 2012 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/prefs/json_pref_store.h"

#include <stdint.h>

#include <memory>
#include <utility>

#include "base/compiler_specific.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/location.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/histogram_samples.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/threading/thread.h"
#include "base/values.h"
#include "components/prefs/persistent_pref_store_unittest.h"
#include "components/prefs/pref_filter.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace base {
namespace {

const char kHomePage[] =;

const char kReadJson[] =;

const char kInvalidJson[] =;

// Expected output for tests using RunBasicJsonPrefStoreTest().
const char kWriteGolden[] =;

// A PrefFilter that will intercept all calls to FilterOnLoad() and hold on
// to the |prefs| until explicitly asked to release them.
class InterceptingPrefFilter : public PrefFilter {};

InterceptingPrefFilter::InterceptingPrefFilter() {}

InterceptingPrefFilter::InterceptingPrefFilter(
    OnWriteCallbackPair callback_pair) {}

InterceptingPrefFilter::~InterceptingPrefFilter() {}

void InterceptingPrefFilter::FilterOnLoad(
    PostFilterOnLoadCallback post_filter_on_load_callback,
    base::Value::Dict pref_store_contents) {}

void InterceptingPrefFilter::ReleasePrefs() {}

class MockPrefStoreObserver : public PrefStore::Observer {};

class MockReadErrorDelegate : public PersistentPrefStore::ReadErrorDelegate {};

enum class CommitPendingWriteMode {};

base::test::TaskEnvironment::ThreadPoolExecutionMode GetExecutionMode(
    CommitPendingWriteMode commit_mode) {}

void CommitPendingWrite(JsonPrefStore* pref_store,
                        CommitPendingWriteMode commit_pending_write_mode,
                        base::test::TaskEnvironment* task_environment) {}

class JsonPrefStoreTest
    : public testing::TestWithParam<CommitPendingWriteMode> {};

}  // namespace

// Test fallback behavior for a nonexistent file.
TEST_P(JsonPrefStoreTest, NonExistentFile) {}

// Test fallback behavior for an invalid file.
TEST_P(JsonPrefStoreTest, InvalidFile) {}

// This function is used to avoid code duplication while testing synchronous
// and asynchronous version of the JsonPrefStore loading. It validates that the
// given output file's contents matches kWriteGolden.
void RunBasicJsonPrefStoreTest(JsonPrefStore* pref_store,
                               const base::FilePath& output_file,
                               CommitPendingWriteMode commit_pending_write_mode,
                               base::test::TaskEnvironment* task_environment) {}

TEST_P(JsonPrefStoreTest, Basic) {}

TEST_P(JsonPrefStoreTest, BasicAsync) {}

TEST_P(JsonPrefStoreTest, PreserveEmptyValues) {}

// This test is just documenting some potentially non-obvious behavior. It
// shouldn't be taken as normative.
TEST_P(JsonPrefStoreTest, RemoveClearsEmptyParent) {}

// Tests asynchronous reading of the file when there is no file.
TEST_P(JsonPrefStoreTest, AsyncNonExistingFile) {}

TEST_P(JsonPrefStoreTest, ReadWithInterceptor) {}

TEST_P(JsonPrefStoreTest, ReadAsyncWithInterceptor) {}

TEST_P(JsonPrefStoreTest, RemoveValuesByPrefix) {}

TEST_P(JsonPrefStoreTest, HasReadErrorDelegate) {}

TEST_P(JsonPrefStoreTest, HasReadErrorDelegateWithNullDelegate) {}

INSTANTIATE_TEST_SUITE_P();

class JsonPrefStoreLossyWriteTest : public JsonPrefStoreTest {};

TEST_P(JsonPrefStoreLossyWriteTest, LossyWriteBasic) {}

TEST_P(JsonPrefStoreLossyWriteTest, LossyWriteMixedLossyFirst) {}

TEST_P(JsonPrefStoreLossyWriteTest, LossyWriteMixedLossySecond) {}

TEST_P(JsonPrefStoreLossyWriteTest, ScheduleLossyWrite) {}

INSTANTIATE_TEST_SUITE_P();

class SuccessfulWriteReplyObserver {};

void SuccessfulWriteReplyObserver::ObserveNextWriteCallback(
    JsonPrefStore* json_pref_store) {}

enum WriteCallbackObservationState {};

class WriteCallbacksObserver {};

void WriteCallbacksObserver::ObserveNextWriteCallback(JsonPrefStore* writer) {}

bool WriteCallbacksObserver::GetAndResetPreWriteObservationState() {}

WriteCallbackObservationState
WriteCallbacksObserver::GetAndResetPostWriteObservationState() {}

class JsonPrefStoreCallbackTest : public testing::Test {};

TEST_F(JsonPrefStoreCallbackTest, TestSerializeDataCallbacks) {}

TEST_F(JsonPrefStoreCallbackTest, TestPostWriteCallbacks) {}

TEST_F(JsonPrefStoreCallbackTest, TestPostWriteCallbacksWithFakeFailure) {}

TEST_F(JsonPrefStoreCallbackTest, TestPostWriteCallbacksDuringProfileDeath) {}

}  // namespace base