#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 {
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[] = …;
base::Value::Dict CreateDummyContentSettingValue(
std::string_view tag,
bool expired,
mojom::SessionModel session_model = mojom::SessionModel::DURABLE) { … }
std::string GetTagFromDummyContentSetting(const base::Value::Dict& setting) { … }
std::string GetTagFromDummyContentSettingValue(
const base::Value::Dict& pref_value) { … }
}
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) { … }
TEST_P(ContentSettingsPrefParameterizedTest, ExpirationWhileReadingFromPrefs) { … }
TEST_P(ContentSettingsPrefParameterizedTest, LegacyLastModifiedLoad) { … }
TEST_F(ContentSettingsPrefTest, DecidedByRelatedWebsiteSetsLoad) { … }
TEST_F(ContentSettingsPrefTest,
DecidedByRelatedWebsiteSetsFalseNotWrittenToJson) { … }
TEST_F(
ContentSettingsPrefTest,
MigrateNonRestorableStorageAccessToDurableWithDecidedByRelatedWebsiteSets) { … }
}