chromium/components/prefs/pref_service_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 <stddef.h>
#include <stdint.h>

#include <string>

#include "base/functional/callback_helpers.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/prefs/json_pref_store.h"
#include "components/prefs/mock_pref_change_callback.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_notifier_impl.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service_factory.h"
#include "components/prefs/pref_value_store.h"
#include "components/prefs/testing_pref_service.h"
#include "components/prefs/testing_pref_store.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

_;
Mock;

namespace {

const char kPrefName[] =;
const char kStandaloneBrowserPref[] =;

}  // namespace

#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST(PrefServiceUtilTest, GetAllDottedPaths) {
  using pref_service_util::GetAllDottedPaths;

  base::Value::Dict dict;
  std::vector<std::string> paths;

  GetAllDottedPaths(dict, paths);
  // Expect paths to be [].
  EXPECT_EQ(paths.size(), std::size_t(0));

  dict.SetByDottedPath("one.two", base::Value(12));
  GetAllDottedPaths(dict, paths);
  EXPECT_THAT(paths, testing::UnorderedElementsAre("one.two"));

  paths.clear();
  dict.SetByDottedPath("one.three", base::Value(13));
  GetAllDottedPaths(dict, paths);
  EXPECT_THAT(paths, testing::UnorderedElementsAre("one.two", "one.three"));

  paths.clear();
  dict.SetByDottedPath("key", "value");
  GetAllDottedPaths(dict, paths);
  EXPECT_THAT(paths,
              testing::UnorderedElementsAre("one.two", "one.three", "key"));
}
#endif

TEST(PrefServiceTest, NoObserverFire) {}

TEST(PrefServiceTest, HasPrefPath) {}

TEST(PrefServiceTest, Observers) {}

// Make sure that if a preference changes type, so the wrong type is stored in
// the user pref file, it uses the correct fallback value instead.
TEST(PrefServiceTest, GetValueChangedType) {}

TEST(PrefServiceTest, GetValueAndGetRecommendedValue) {}

TEST(PrefServiceTest, SetTimeValue_RegularTime) {}

TEST(PrefServiceTest, SetTimeValue_NullTime) {}

TEST(PrefServiceTest, SetTimeDeltaValue_RegularTimeDelta) {}

TEST(PrefServiceTest, SetTimeDeltaValue_ZeroTimeDelta) {}

// A PrefStore which just stores the last write flags that were used to write
// values to it.
class WriteFlagChecker : public TestingPrefStore {};

TEST(PrefServiceTest, WriteablePrefStoreFlags) {}

class PrefServiceSetValueTest : public testing::Test {};

const char PrefServiceSetValueTest::kName[] =;
const char PrefServiceSetValueTest::kValue[] =;

TEST_F(PrefServiceSetValueTest, SetStringValue) {}

TEST_F(PrefServiceSetValueTest, SetDictionaryValue) {}

TEST_F(PrefServiceSetValueTest, SetListValue) {}

class PrefStandaloneBrowserPrefsTest : public testing::Test {};

// Check that the standalone browser pref store is correctly initialized,
// written to, read, and has correct precedence.
TEST_F(PrefStandaloneBrowserPrefsTest, CheckStandaloneBrowserPref) {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(PrefStandaloneBrowserPrefsTest, RemoveAllStandaloneBrowserPrefs) {
  const char int_pref_name[] = "int.name";
  const char str_pref_name[] = "str.pref.name";
  pref_registry_->RegisterIntegerPref(int_pref_name, 0);
  pref_registry_->RegisterStringPref(str_pref_name, "");

  pref_service_->SetStandaloneBrowserPref(int_pref_name, base::Value(4));
  pref_service_->SetStandaloneBrowserPref(str_pref_name, base::Value("value"));
  EXPECT_EQ(base::Value(4), pref_service_->GetValue(int_pref_name));
  EXPECT_EQ(base::Value("value"), pref_service_->GetValue(str_pref_name));

  pref_service_->RemoveAllStandaloneBrowserPrefs();
  EXPECT_EQ(base::Value(0), pref_service_->GetValue(int_pref_name));
  EXPECT_EQ(base::Value(""), pref_service_->GetValue(str_pref_name));
}
#endif