#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[] = …;
const char kWriteGolden[] = …;
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> { … };
}
TEST_P(JsonPrefStoreTest, NonExistentFile) { … }
TEST_P(JsonPrefStoreTest, InvalidFile) { … }
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) { … }
TEST_P(JsonPrefStoreTest, RemoveClearsEmptyParent) { … }
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) { … }
}