chromium/components/content_settings/core/browser/content_settings_pref_unittest.cc

// Copyright 2019 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/content_settings/core/browser/content_settings_pref.h"

#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <utility>

#include "base/functional/callback_helpers.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/gtest_util.h"
#include "base/test/scoped_feature_list.h"
#include "base/values.h"
#include "components/content_settings/core/browser/content_settings_utils.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_constraints.h"
#include "components/content_settings/core/common/content_settings_metadata.h"
#include "components/content_settings/core/common/content_settings_partition_key.h"
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/content_settings/core/common/content_settings_utils.h"
#include "components/content_settings/core/common/features.h"
#include "components/content_settings/core/test/content_settings_test_utils.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "ppapi/buildflags/buildflags.h"
#include "services/preferences/public/cpp/dictionary_value_update.h"
#include "services/preferences/public/cpp/scoped_pref_update.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

namespace content_settings {
namespace {

// Test content setting pattern pairs in string format. The percent-encoded
// sequence "%61" should get canonicalized to the letter 'a'.
constexpr char kTestPatternCanonicalAlpha[] =;
constexpr char kTestPatternNonCanonicalAlpha1[] =;
constexpr char kTestPatternNonCanonicalAlpha2[] =;
constexpr char kTestPatternCanonicalBeta[] =;
constexpr char kTestPatternNonCanonicalBeta[] =;
constexpr char kTestPatternCanonicalGamma[] =;

constexpr char kTestContentSettingPrefName[] =;
constexpr char kTestContentSettingPartitionedPrefName[] =;

constexpr char kExpirationKey[] =;
constexpr char kLastModifiedKey[] =;
constexpr char kSettingKey[] =;
constexpr char kTagKey[] =;
constexpr char kSessionModelKey[] =;

// Creates a JSON dictionary representing a dummy content setting exception
// value in preferences. The setting will be marked with the |tag| like so:
//
//   value = {
//     "last_modified": "...",
//     "setting": {
//       "tag": "...",
//     }
//   }
base::Value::Dict CreateDummyContentSettingValue(
    std::string_view tag,
    bool expired,
    mojom::SessionModel session_model = mojom::SessionModel::DURABLE) {}

// Given the JSON dictionary representing the "setting" stored under a content
// setting exception value, returns the tag.
std::string GetTagFromDummyContentSetting(const base::Value::Dict& setting) {}

// Given the JSON dictionary representing a content setting exception value,
// returns the tag.
std::string GetTagFromDummyContentSettingValue(
    const base::Value::Dict& pref_value) {}

}  // namespace

class ContentSettingsPrefTest : public testing::Test {};

class ContentSettingsPrefParameterizedTest
    : public ContentSettingsPrefTest,
      public testing::WithParamInterface<std::tuple<PartitionKey, bool>> {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(ContentSettingsPrefParameterizedTest, BasicReadWrite) {}

TEST_F(ContentSettingsPrefTest,
       ReadContentSettingsFromPrefShouldRemovePartitionIfNecessary) {}

TEST_P(ContentSettingsPrefParameterizedTest,
       SetWebsiteSettingShouldRemovePartitionIfEmpty) {}

TEST_P(ContentSettingsPrefParameterizedTest, SetWebsiteSettingWhenEmpty) {}

TEST_F(ContentSettingsPrefTest, DoNotPersistInMemoryPartition) {}

TEST_F(ContentSettingsPrefTest, ClearAllContentSettingsRules) {}

TEST_F(ContentSettingsPrefTest, GetNumExceptions) {}

TEST_P(ContentSettingsPrefParameterizedTest,
       CanonicalizationWhileReadingFromPrefs) {}

// If we are reading from prefs and we have any persistend settings that have
// expired we should remove these to prevent unbounded growth and bloat.
TEST_P(ContentSettingsPrefParameterizedTest, ExpirationWhileReadingFromPrefs) {}

// Ensure that any previously set last_modified values using
// base::Time::ToInternalValue can be read correctly.
TEST_P(ContentSettingsPrefParameterizedTest, LegacyLastModifiedLoad) {}

// Ensure that decided_by_related_website_sets can be written and read.
TEST_F(ContentSettingsPrefTest, DecidedByRelatedWebsiteSetsLoad) {}

// Ensure that decided_by_related_website_sets is not written to JSON when it's
// false.
TEST_F(ContentSettingsPrefTest,
       DecidedByRelatedWebsiteSetsFalseNotWrittenToJson) {}

// Ensure that NON_RESTORABLE_USER_SESSION grants are migrated to DURABLE with a
// `decided_by_related_website_sets` value of true.
// TODO(b/344678400): Delete after NON_RESTORABLE_USER_SESSION is removed.
TEST_F(
    ContentSettingsPrefTest,
    MigrateNonRestorableStorageAccessToDurableWithDecidedByRelatedWebsiteSets) {}

}  // namespace content_settings