src/net/cookies/canonical_cookie_unittest.cc
// Test that non-SameSite, insecure cookies are excluded if both
// SameSiteByDefaultCookies and CookiesWithoutSameSiteMustBeSecure are enabled.
Test that non-SameSite, insecure cookies are excluded if both
SameSiteByDefaultCookies and CookiesWithoutSameSiteMustBeSecure are enabled.
Test that non - SameSite insecure cookies are excluded if both SameSiteByDefaultCookies and CookiesWithoutSameSiteMustBeSecure are enabled .
TEST(CanonicalCookieTest, IncludeCookiesWithoutSameSiteMustBeSecure) {
  GURL url("https://www.example.com");
  base::Time creation_time = base::Time::Now();
  base::Optional<base::Time> server_time = base::nullopt;
  CookieOptions options;
  std::unique_ptr<CanonicalCookie> cookie;
  cookie = CanonicalCookie::Create(url, "A=2; SameSite=None", creation_time,
                                   server_time);
  ASSERT_TRUE(cookie.get());
  EXPECT_FALSE(cookie->IsSecure());
  EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite());
  EXPECT_EQ(CookieEffectiveSameSite::NO_RESTRICTION,
            cookie->GetEffectiveSameSiteForTesting());
  {
    base::test::ScopedFeatureList feature_list;
    feature_list.InitWithFeatures(
        {features::kSameSiteByDefaultCookies,
         features::kCookiesWithoutSameSiteMustBeSecure} ,
        {} );
    EXPECT_TRUE(
        cookie
            ->IncludeForRequestURL(url, options, CookieAccessSemantics::UNKNOWN)
            .HasExactlyExclusionReasonsForTesting(
                {CanonicalCookie::CookieInclusionStatus::
                     EXCLUDE_SAMESITE_NONE_INSECURE}));
    EXPECT_TRUE(
        cookie
            ->IncludeForRequestURL(url, options, CookieAccessSemantics::LEGACY)
            .IsInclude());
    EXPECT_TRUE(cookie
                    ->IncludeForRequestURL(url, options,
                                           CookieAccessSemantics::NONLEGACY)
                    .HasExactlyExclusionReasonsForTesting(
                        {CanonicalCookie::CookieInclusionStatus::
                             EXCLUDE_SAMESITE_NONE_INSECURE}));
  }
  {
    base::test::ScopedFeatureList feature_list;
    feature_list.InitWithFeatures(
        {} ,
        {features::kSameSiteByDefaultCookies,
         features::
             kCookiesWithoutSameSiteMustBeSecure} );
    EXPECT_TRUE(
        cookie
            ->IncludeForRequestURL(url, options, CookieAccessSemantics::UNKNOWN)
            .IsInclude());
    EXPECT_TRUE(
        cookie
            ->IncludeForRequestURL(url, options, CookieAccessSemantics::LEGACY)
            .IsInclude());
    EXPECT_TRUE(cookie
                    ->IncludeForRequestURL(url, options,
                                           CookieAccessSemantics::NONLEGACY)
                    .IsInclude());
  }
}
TEST ( CanonicalCookieTest , IncludeCookiesWithoutSameSiteMustBeSecure ) { GURL url ( " " ) ; base :: Time creation_time = base :: Time :: Now ( ) ; base :: Optional < base :: Time > server_time = base :: nullopt ; CookieOptions options ; std :: unique_ptr < CanonicalCookie > cookie ; cookie = CanonicalCookie :: Create ( url , " " , creation_time , server_time ) ; ASSERT_TRUE ( cookie . get ( ) ) ; EXPECT_FALSE ( cookie -> IsSecure ( ) ) ; EXPECT_EQ ( CookieSameSite :: NO_RESTRICTION , cookie -> SameSite ( ) ) ; EXPECT_EQ ( CookieEffectiveSameSite :: NO_RESTRICTION , cookie -> GetEffectiveSameSiteForTesting ( ) ) ; { base :: test :: ScopedFeatureList feature_list ; feature_list . InitWithFeatures ( { features :: kSameSiteByDefaultCookies , features :: kCookiesWithoutSameSiteMustBeSecure } , { } ) ; EXPECT_TRUE ( cookie -> IncludeForRequestURL ( url , options , CookieAccessSemantics :: UNKNOWN ) . HasExactlyExclusionReasonsForTesting ( { CanonicalCookie :: CookieInclusionStatus :: EXCLUDE_SAMESITE_NONE_INSECURE } ) ) ; EXPECT_TRUE ( cookie -> IncludeForRequestURL ( url , options , CookieAccessSemantics :: LEGACY ) . IsInclude ( ) ) ; EXPECT_TRUE ( cookie -> IncludeForRequestURL ( url , options , CookieAccessSemantics :: NONLEGACY ) . HasExactlyExclusionReasonsForTesting ( { CanonicalCookie :: CookieInclusionStatus :: EXCLUDE_SAMESITE_NONE_INSECURE } ) ) ; } { base :: test :: ScopedFeatureList feature_list ; feature_list . InitWithFeatures ( { } , { features :: kSameSiteByDefaultCookies , features :: kCookiesWithoutSameSiteMustBeSecure } ) ; EXPECT_TRUE ( cookie -> IncludeForRequestURL ( url , options , CookieAccessSemantics :: UNKNOWN ) . IsInclude ( ) ) ; EXPECT_TRUE ( cookie -> IncludeForRequestURL ( url , options , CookieAccessSemantics :: LEGACY ) . IsInclude ( ) ) ; EXPECT_TRUE ( cookie -> IncludeForRequestURL ( url , options , CookieAccessSemantics :: NONLEGACY ) . IsInclude ( ) ) ; } }
Test that non-SameSite, insecure cookies are excluded if both
SameSiteByDefaultCookies and CookiesWithoutSameSiteMustBeSecure are enabled.
Test that non - SameSite insecure cookies are excluded if both SameSiteByDefaultCookies and CookiesWithoutSameSiteMustBeSecure are enabled .
// Create the cookie without the experimental options enabled. // Test SameSite=None must be Secure. // Features on: /* enabled_features */ /* disabled_features */ // Features off: /* enabled_features */ /* disabled_features */ // If the semantics is Nonlegacy, only reject the cookie if the // SameSite=None-must-be-Secure feature is enabled.