#include "services/network/cookie_settings.h"
#include <optional>
#include <tuple>
#include <utility>
#include "base/functional/callback_helpers.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_metadata.h"
#include "components/content_settings/core/common/features.h"
#include "components/privacy_sandbox/privacy_sandbox_features.h"
#include "net/base/features.h"
#include "net/base/network_delegate.h"
#include "net/base/schemeful_site.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/canonical_cookie_test_helpers.h"
#include "net/cookies/cookie_constants.h"
#include "net/cookies/cookie_inclusion_status.h"
#include "net/cookies/cookie_setting_override.h"
#include "net/cookies/cookie_util.h"
#include "net/cookies/site_for_cookies.h"
#include "net/cookies/static_cookie_policy.h"
#include "net/first_party_sets/first_party_set_metadata.h"
#include "services/network/tpcd/metadata/manager.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/origin.h"
namespace network {
namespace {
_;
AllOf;
ElementsAre;
IsEmpty;
Not;
UnorderedElementsAre;
constexpr char kAllowedRequestsHistogram[] = …;
constexpr char kDomainURL[] = …;
constexpr char kURL[] = …;
constexpr char kOtherURL[] = …;
constexpr char kSubDomainURL[] = …;
constexpr char kDomain[] = …;
constexpr char kDotDomain[] = …;
constexpr char kSubDomain[] = …;
constexpr char kOtherDomain[] = …;
constexpr char kDomainWildcardPattern[] = …;
constexpr char kFPSOwnerURL[] = …;
constexpr char kFPSMemberURL[] = …;
constexpr char kUnrelatedURL[] = …;
std::unique_ptr<net::CanonicalCookie> MakeCanonicalCookie(
const std::string& name,
const std::string& domain,
std::optional<net::CookiePartitionKey> cookie_partition_key =
std::nullopt) { … }
std::unique_ptr<net::CanonicalCookie> MakeCanonicalSameSiteNoneCookie(
const std::string& name,
const std::string& domain,
std::optional<net::CookiePartitionKey> cookie_partition_key =
std::nullopt) { … }
enum GrantSource { … };
enum BlockSource { … };
enum TestVariables { … };
class CookieSettingsTestBase : public testing::Test { … };
class CookieSettingsTest : public CookieSettingsTestBase { … };
class CookieSettingsTestP : public CookieSettingsTestBase,
public testing::WithParamInterface<
std::tuple< GrantSource,
BlockSource>> { … };
TEST_F(CookieSettingsTest, GetCookieSettingDefault) { … }
TEST_F(CookieSettingsTest, GetCookieSetting) { … }
class CookieSettingsTrackingProtectionTest : public CookieSettingsTestBase { … };
#if !BUILDFLAG(IS_IOS)
TEST_F(CookieSettingsTrackingProtectionTest,
GetCookieSettingUsesTrackingProtectionSetting) { … }
#endif
TEST_F(CookieSettingsTest, GetCookieSettingMultipleProviders) { … }
TEST_F(CookieSettingsTest, GetCookieSettingOtrProviders) { … }
TEST_P(CookieSettingsTestP, GetCookieSettingMustMatchBothPatterns) { … }
TEST_F(CookieSettingsTest, GetCookieSettingGetsFirstSetting) { … }
TEST_F(CookieSettingsTest, GetCookieSettingDontBlockThirdParty) { … }
TEST_F(CookieSettingsTest, GetCookieSettingBlockThirdParty) { … }
TEST_P(CookieSettingsTestP,
GetCookieSettingOverridePreservesSessionOnlySetting) { … }
TEST_F(CookieSettingsTest, GetCookieSettingDontBlockThirdPartyWithException) { … }
TEST_P(CookieSettingsTestP, GetCookieSettingSAAUnblocks) { … }
TEST_P(CookieSettingsTestP, GetCookieSettingSAAUnblocksViaFedCM) { … }
TEST_P(CookieSettingsTestP, GetCookieSettingTopLevelStorageAccessUnblocks) { … }
TEST_P(CookieSettingsTestP, GetCookieSettingSAAResourceWildcards) { … }
TEST_P(CookieSettingsTestP, GetCookieSettingSAATopLevelWildcards) { … }
TEST_P(CookieSettingsTestP, GetCookieSettingSAARespectsSettings) { … }
TEST_P(CookieSettingsTestP, GetCookieSettingSAAExpiredGrant) { … }
TEST_F(CookieSettingsTest, CreateDeleteCookieOnExitPredicateNoSettings) { … }
TEST_F(CookieSettingsTest, CreateDeleteCookieOnExitPredicateNoSessionOnly) { … }
TEST_F(CookieSettingsTest, CreateDeleteCookieOnExitPredicateSessionOnly) { … }
TEST_F(CookieSettingsTest, CreateDeleteCookieOnExitPredicateExceptionOnly) { … }
TEST_F(CookieSettingsTest, CreateDeleteCookieOnExitPredicateAllow) { … }
TEST_F(CookieSettingsTest, GetCookieSettingSecureOriginCookiesAllowed) { … }
TEST_F(CookieSettingsTest, GetCookieSettingWithThirdPartyCookiesAllowedScheme) { … }
TEST_F(CookieSettingsTest, GetCookieSettingMatchingSchemeCookiesAllowed) { … }
TEST_F(CookieSettingsTest, LegacyCookieAccessDefault) { … }
TEST_F(CookieSettingsTest, CookieAccessSemanticsForDomain) { … }
TEST_F(CookieSettingsTest, CookieAccessSemanticsForDomainWithWildcard) { … }
TEST_P(CookieSettingsTestP, IsPrivacyModeEnabled) { … }
TEST_P(CookieSettingsTestP, IsCookieAccessible_SameSiteNoneCookie) { … }
TEST_P(CookieSettingsTestP, IsCookieAccessible_SameSiteLaxCookie) { … }
TEST_P(CookieSettingsTestP, IsCookieAccessible_PartitionedCookies) { … }
TEST_P(CookieSettingsTestP, IsCookieAccessible_NoneExemptionReason) { … }
TEST_P(CookieSettingsTestP, IsCookieAccessible_SitesInFirstPartySets) { … }
TEST_P(CookieSettingsTestP, AnnotateAndMoveUserBlockedCookies_CrossSiteEmbed) { … }
TEST_F(CookieSettingsTest,
AnnotateAndMoveUserBlockedCookies_CrossSiteEmbed_3PCAllowed) { … }
TEST_F(CookieSettingsTest,
AnnotateAndMoveUserBlockedCookies_SameSiteEmbed_3PCAllowed) { … }
TEST_P(CookieSettingsTestP,
AnnotateAndMoveUserBlockedCookies_SameSiteEmbed_FirstPartyContext) { … }
TEST_P(CookieSettingsTestP,
AnnotateAndMoveUserBlockedCookies_SameSiteEmbed_ThirdPartyContext) { … }
TEST_P(CookieSettingsTestP,
AnnotateAndMoveUserBlockedCookies_SitesInFirstPartySet) { … }
TEST_P(
CookieSettingsTestP,
AnnotateAndMoveUserBlockedCookies_SitesInFirstPartySet_FirstPartyURLBlocked) { … }
namespace {
net::CookieAccessResultList MakePartitionedCookie() { … }
}
TEST_F(CookieSettingsTest,
AnnotateAndMoveUserBlockedCookies_PartitionedCookies) { … }
TEST_F(CookieSettingsTest, GetStorageAccessStatus) { … }
std::string CustomTestName(
const testing::TestParamInfo<CookieSettingsTestP::ParamType>& info) { … }
INSTANTIATE_TEST_SUITE_P(…);
class CookieSettingsTpcdMetadataGrantsTest
: public CookieSettingsTestBase,
public testing::WithParamInterface<
bool> { … };
TEST_P(CookieSettingsTpcdMetadataGrantsTest, Grants) { … }
TEST_P(CookieSettingsTpcdMetadataGrantsTest, IsCookieAccessible) { … }
TEST_P(CookieSettingsTpcdMetadataGrantsTest,
AnnotateAndMoveUserBlockedCookies) { … }
TEST_P(CookieSettingsTpcdMetadataGrantsTest, ExplicitSettingPreserved) { … }
INSTANTIATE_TEST_SUITE_P(…);
class CookieSettingsTpcdTrialTest
: public CookieSettingsTestBase,
public testing::WithParamInterface<
bool> { … };
TEST_P(CookieSettingsTpcdTrialTest, OverrideDefaultBlock3pcSetting) { … }
TEST_P(CookieSettingsTpcdTrialTest, IsCookieAccessible) { … }
TEST_P(CookieSettingsTpcdTrialTest, AnnotateAndMoveUserBlockedCookies) { … }
TEST_P(CookieSettingsTpcdTrialTest, PreserveBlockAllCookiesSetting) { … }
TEST_P(CookieSettingsTpcdTrialTest, PreserveExplicitBlock3pcSetting) { … }
INSTANTIATE_TEST_SUITE_P(…);
class CookieSettingsTopLevelTpcdTrialTest
: public CookieSettingsTestBase,
public testing::
WithParamInterface<
bool> { … };
TEST_P(CookieSettingsTopLevelTpcdTrialTest, OverrideDefaultBlock3pcSetting) { … }
TEST_P(CookieSettingsTopLevelTpcdTrialTest, IsCookieAccessible) { … }
TEST_P(CookieSettingsTopLevelTpcdTrialTest, AnnotateAndMoveUserBlockedCookies) { … }
TEST_P(CookieSettingsTopLevelTpcdTrialTest, PreserveBlockAllCookiesSetting) { … }
TEST_P(CookieSettingsTopLevelTpcdTrialTest, PreserveExplicitBlock3pcSetting) { … }
INSTANTIATE_TEST_SUITE_P(…);
#if !BUILDFLAG(IS_IOS)
class CookieSettingsTopLevelTpcdOriginTrialTest
: public CookieSettingsTestBase,
public testing::
WithParamInterface<
bool> { … };
TEST_P(CookieSettingsTopLevelTpcdOriginTrialTest, AllowByDefault) { … }
TEST_P(CookieSettingsTopLevelTpcdOriginTrialTest, IsCookieAccessible) { … }
TEST_P(CookieSettingsTopLevelTpcdOriginTrialTest, UnblockedByMitigations) { … }
TEST_P(CookieSettingsTopLevelTpcdOriginTrialTest,
BypassDefaultAllowAllCookiesSetting) { … }
TEST_P(CookieSettingsTopLevelTpcdOriginTrialTest,
PreserveExplicitAllow3pcSetting) { … }
TEST_P(CookieSettingsTopLevelTpcdOriginTrialTest,
PreserveExplicitBlock3pcSetting) { … }
TEST_P(CookieSettingsTopLevelTpcdOriginTrialTest,
PreserveBlockAll3PCookiesSetting) { … }
TEST_P(CookieSettingsTopLevelTpcdOriginTrialTest,
PreserveBlockAllCookiesSetting) { … }
TEST_P(CookieSettingsTopLevelTpcdOriginTrialTest,
AnnotateAndMoveUserBlockedCookies) { … }
INSTANTIATE_TEST_SUITE_P(…);
#endif
}
}