#include "components/content_settings/core/browser/cookie_settings.h"
#include <cstddef>
#include <memory>
#include <string>
#include <tuple>
#include "base/feature_list.h"
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/values.h"
#include "build/build_config.h"
#include "components/content_settings/core/browser/content_settings_registry.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/content_settings/core/common/content_settings_utils.h"
#include "components/content_settings/core/common/features.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/content_settings/core/test/content_settings_mock_provider.h"
#include "components/content_settings/core/test/content_settings_test_utils.h"
#include "components/prefs/testing_pref_service.h"
#include "components/privacy_sandbox/privacy_sandbox_features.h"
#include "components/privacy_sandbox/privacy_sandbox_prefs.h"
#include "components/privacy_sandbox/tracking_protection_prefs.h"
#include "components/privacy_sandbox/tracking_protection_settings.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "components/tpcd/metadata/browser/manager.h"
#include "components/tpcd/metadata/browser/parser.h"
#include "extensions/buildflags/buildflags.h"
#include "net/cookies/cookie_constants.h"
#include "net/cookies/cookie_setting_override.h"
#include "net/cookies/cookie_util.h"
#include "net/cookies/site_for_cookies.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#include "url/origin.h"
#include "url/url_constants.h"
#if BUILDFLAG(IS_IOS)
#include "components/content_settings/core/common/features.h"
#else
#include "components/privacy_sandbox/privacy_sandbox_features.h"
#endif
namespace {
ProviderType;
const bool kSupports3pcBlocking = …;
#if !BUILDFLAG(IS_IOS)
constexpr char kAllowedRequestsHistogram[] = …;
#endif
enum GrantSource { … };
class TestTpcdManagerDelegate : public tpcd::metadata::Manager::Delegate { … };
}
namespace content_settings {
class CookieSettingsObserver : public CookieSettings::Observer { … };
class CookieSettingsTestBase : public testing::Test { … };
class CookieSettingsTest : public CookieSettingsTestBase { … };
class CookieSettingsTestP : public CookieSettingsTestBase,
public testing::WithParamInterface<GrantSource> { … };
TEST_F(CookieSettingsTest, CustomExceptionsNoWildcardLessSpecificDomain) { … }
TEST_F(CookieSettingsTest, CustomExceptionsNoWildcardMatchingDomain) { … }
TEST_F(CookieSettingsTest, CustomExceptionsWildcardMatchingDomain) { … }
TEST_F(CookieSettingsTest, CustomExceptionsWildcardLessSpecificDomain) { … }
TEST_F(CookieSettingsTest, CustomExceptionsDotComWildcard) { … }
TEST_F(CookieSettingsTest, TestAllowlistedScheme) { … }
TEST_F(CookieSettingsTest, CookiesBlockSingle) { … }
TEST_P(CookieSettingsTestP, CookiesBlockThirdParty) { … }
TEST_F(CookieSettingsTest, CookiesControlsDefault) { … }
TEST_F(CookieSettingsTest, CookiesControlsDisabled) { … }
TEST_F(CookieSettingsTest, CookiesControlsEnabledForIncognito) { … }
TEST_F(CookieSettingsTest, TestThirdPartyCookiePhaseout) { … }
TEST_F(CookieSettingsTest, CookiesAllowThirdParty) { … }
TEST_F(CookieSettingsTest, CookiesExplicitBlockSingleThirdParty) { … }
TEST_F(CookieSettingsTest, CookiesExplicitSessionOnly) { … }
TEST_F(CookieSettingsTest, ThirdPartyExceptionSessionOnly) { … }
class CookieSettingsTestUserBypass : public CookieSettingsTest { … };
#if !BUILDFLAG(IS_IOS)
TEST_F(CookieSettingsTestUserBypass, UserBypassTemporaryExceptions) { … }
TEST_F(CookieSettingsTestUserBypass,
TrackingProtectionUserBypassTemporaryExceptions) { … }
#endif
TEST_F(CookieSettingsTestUserBypass,
UserBypassThirdPartyCookiesTemporaryExceptions) { … }
TEST_F(CookieSettingsTestUserBypass, ResetThirdPartyCookiesExceptions) { … }
TEST_F(CookieSettingsTestUserBypass,
UserBypassThirdPartyCookiesIncognitoExceptions) { … }
TEST_F(CookieSettingsTest, KeepBlocked) { … }
TEST_F(CookieSettingsTest, DeleteSessionOnly) { … }
TEST_F(CookieSettingsTest, DeleteSessionOnlyWithThirdPartyBlocking) { … }
TEST_F(CookieSettingsTest, DeletionWithDifferentPorts) { … }
TEST_F(CookieSettingsTest, DeletionWithSubDomains) { … }
TEST_F(CookieSettingsTest, DeleteCookiesWithThirdPartyException) { … }
TEST_F(CookieSettingsTest, CookiesThirdPartyBlockedExplicitAllow) { … }
TEST_F(CookieSettingsTest, CookiesThirdPartyBlockedAllSitesAllowed) { … }
TEST_F(CookieSettingsTest, CookiesBlockEverything) { … }
TEST_F(CookieSettingsTest, CookiesBlockEverythingExceptAllowed) { … }
#if !BUILDFLAG(IS_IOS)
TEST_F(CookieSettingsTest, GetCookieSettingAllowedTelemetry) { … }
TEST_P(CookieSettingsTestP, GetCookieSettingSAA) { … }
TEST_P(CookieSettingsTestP, GetCookieSettingSAAWebsocket) { … }
TEST_P(CookieSettingsTestP, GetCookieSettingSAAViaFedCM) { … }
TEST_P(CookieSettingsTestP, GetCookieSettingTopLevelStorageAccess) { … }
TEST_P(CookieSettingsTestP, GetCookieSettingSAAResourceWildcards) { … }
TEST_P(CookieSettingsTestP, GetCookieSettingSAATopLevelWildcards) { … }
TEST_P(CookieSettingsTestP, GetCookieSettingRespectsExplicitSettings) { … }
TEST_P(CookieSettingsTestP, GetCookieSettingSAAExpiredGrant) { … }
TEST_P(CookieSettingsTestP, GetCookieSetting3pcdTrial) { … }
TEST_P(CookieSettingsTestP, GetCookieSetting3pcdMetadataGrants) { … }
TEST_P(CookieSettingsTestP, GetCookieSetting3pcdHeuristicsGrants) { … }
TEST_F(CookieSettingsTest, SetTemporaryCookieGrantForHeuristicOverrides) { … }
TEST_F(CookieSettingsTest, SetTemporaryCookieGrantForHeuristicSchemeless) { … }
#endif
TEST_F(CookieSettingsTest, ExtensionsRegularSettings) { … }
TEST_F(CookieSettingsTest, ExtensionsOwnCookies) { … }
TEST_F(CookieSettingsTest, ExtensionsThirdParty) { … }
TEST_F(CookieSettingsTest, ThirdPartyException) { … }
#if !BUILDFLAG(IS_IOS)
TEST_F(CookieSettingsTest,
TrackingProtectionExceptionReadWhenNoCookieException) { … }
#endif
TEST_F(CookieSettingsTest, ManagedThirdPartyException) { … }
TEST_F(CookieSettingsTest, ThirdPartySettingObserver) { … }
TEST_F(CookieSettingsTest, PreservesBlockingStateFrom3pcdOnOffboarding) { … }
TEST_F(CookieSettingsTest, LegacyCookieAccessAllowAll) { … }
TEST_F(CookieSettingsTest, LegacyCookieAccessBlockAll) { … }
TEST_F(CookieSettingsTest, LegacyCookieAccessAllowDomainPattern) { … }
TEST_F(CookieSettingsTest, LegacyCookieAccessAllowDomainWildcardPattern) { … }
TEST_F(CookieSettingsTest, GetStorageAccessStatus) { … }
std::string CustomTestName(
const testing::TestParamInfo<CookieSettingsTestP::ParamType>& info) { … }
INSTANTIATE_TEST_SUITE_P(…);
#if !BUILDFLAG(IS_IOS)
class CookieSettingsTopLevelTpcdTrialTest
: public CookieSettingsTestBase,
public testing::
WithParamInterface<
bool> { … };
TEST_P(CookieSettingsTopLevelTpcdTrialTest, GetCookieSettingTopLevel3pcdTrial) { … }
INSTANTIATE_TEST_SUITE_P(…);
#endif
#if !BUILDFLAG(IS_IOS)
class CookieSettingsTopLevelTpcdOriginTrialTest
: public CookieSettingsTestBase { … };
TEST_F(CookieSettingsTopLevelTpcdOriginTrialTest,
GetCookieSetting3pcdOriginTrial) { … }
#endif
}