src/net/cookies/canonical_cookie_unittest.cc
// Confirm that input arguments are reflected in the output cookie.
Confirm that input arguments are reflected in the output cookie.
Confirm that input arguments are reflected in the output cookie .
TEST(CanonicalCookieTest, CreateSanitizedCookie_Inputs) {
  base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
  base::Time one_hour_ago = base::Time::Now() - base::TimeDelta::FromHours(1);
  base::Time one_hour_from_now =
      base::Time::Now() + base::TimeDelta::FromHours(1);
  std::unique_ptr<CanonicalCookie> cc;
  cc = CanonicalCookie::CreateSanitizedCookie(
      GURL("https://www.foo.com"), "A", "B", std::string(), "/foo",
      base::Time(), base::Time(), base::Time(), false ,
      false , CookieSameSite::NO_RESTRICTION,
      COOKIE_PRIORITY_DEFAULT);
  EXPECT_TRUE(cc);
  EXPECT_EQ("A", cc->Name());
  EXPECT_EQ("B", cc->Value());
  EXPECT_EQ("www.foo.com", cc->Domain());
  EXPECT_EQ("/foo", cc->Path());
  EXPECT_EQ(base::Time(), cc->CreationDate());
  EXPECT_EQ(base::Time(), cc->LastAccessDate());
  EXPECT_EQ(base::Time(), cc->ExpiryDate());
  EXPECT_FALSE(cc->IsSecure());
  EXPECT_FALSE(cc->IsHttpOnly());
  EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cc->SameSite());
  EXPECT_EQ(COOKIE_PRIORITY_MEDIUM, cc->Priority());
  EXPECT_FALSE(cc->IsDomainCookie());
  cc = CanonicalCookie::CreateSanitizedCookie(
      GURL("https://www.foo.com"), "A", "B", std::string(), "/foo",
      two_hours_ago, base::Time(), base::Time(), false ,
      false , CookieSameSite::NO_RESTRICTION,
      COOKIE_PRIORITY_DEFAULT);
  EXPECT_TRUE(cc);
  EXPECT_EQ(two_hours_ago, cc->CreationDate());
  cc = CanonicalCookie::CreateSanitizedCookie(
      GURL("https://www.foo.com"), "A", "B", std::string(), "/foo",
      two_hours_ago, base::Time(), one_hour_ago, false ,
      false , CookieSameSite::NO_RESTRICTION,
      COOKIE_PRIORITY_DEFAULT);
  EXPECT_TRUE(cc);
  EXPECT_EQ(one_hour_ago, cc->LastAccessDate());
  cc = CanonicalCookie::CreateSanitizedCookie(
      GURL("https://www.foo.com"), "A", "B", std::string(), "/foo",
      base::Time(), one_hour_from_now, base::Time(), false ,
      false , CookieSameSite::NO_RESTRICTION,
      COOKIE_PRIORITY_DEFAULT);
  EXPECT_TRUE(cc);
  EXPECT_EQ(one_hour_from_now, cc->ExpiryDate());
  cc = CanonicalCookie::CreateSanitizedCookie(
      GURL("https://www.foo.com"), "A", "B", std::string(), "/foo",
      base::Time(), base::Time(), base::Time(), true ,
      false , CookieSameSite::NO_RESTRICTION,
      COOKIE_PRIORITY_DEFAULT);
  EXPECT_TRUE(cc);
  EXPECT_TRUE(cc->IsSecure());
  cc = CanonicalCookie::CreateSanitizedCookie(
      GURL("https://www.foo.com"), "A", "B", std::string(), "/foo",
      base::Time(), base::Time(), base::Time(), false ,
      true , CookieSameSite::NO_RESTRICTION,
      COOKIE_PRIORITY_DEFAULT);
  EXPECT_TRUE(cc);
  EXPECT_TRUE(cc->IsHttpOnly());
  cc = CanonicalCookie::CreateSanitizedCookie(
      GURL("https://www.foo.com"), "A", "B", std::string(), "/foo",
      base::Time(), base::Time(), base::Time(), false ,
      false , CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT);
  EXPECT_TRUE(cc);
  EXPECT_EQ(CookieSameSite::LAX_MODE, cc->SameSite());
  cc = CanonicalCookie::CreateSanitizedCookie(
      GURL("https://www.foo.com"), "A", "B", std::string(), "/foo",
      base::Time(), base::Time(), base::Time(), false ,
      false , CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW);
  EXPECT_TRUE(cc);
  EXPECT_EQ(COOKIE_PRIORITY_LOW, cc->Priority());
  cc = CanonicalCookie::CreateSanitizedCookie(
      GURL("https://www.foo.com"), "A", "B", "www.foo.com", "/foo",
      base::Time(), base::Time(), base::Time(), false ,
      false , CookieSameSite::NO_RESTRICTION,
      COOKIE_PRIORITY_DEFAULT);
  EXPECT_TRUE(cc);
  EXPECT_TRUE(cc->IsDomainCookie());
}
TEST ( CanonicalCookieTest , CreateSanitizedCookie_Inputs ) { base :: Time two_hours_ago = base :: Time :: Now ( ) - base :: TimeDelta :: FromHours ( 2 ) ; base :: Time one_hour_ago = base :: Time :: Now ( ) - base :: TimeDelta :: FromHours ( 1 ) ; base :: Time one_hour_from_now = base :: Time :: Now ( ) + base :: TimeDelta :: FromHours ( 1 ) ; std :: unique_ptr < CanonicalCookie > cc ; cc = CanonicalCookie :: CreateSanitizedCookie ( GURL ( " " ) , " " , " " , std :: string ( ) , " " , base :: Time ( ) , base :: Time ( ) , base :: Time ( ) , false , false , CookieSameSite :: NO_RESTRICTION , COOKIE_PRIORITY_DEFAULT ) ; EXPECT_TRUE ( cc ) ; EXPECT_EQ ( " " , cc -> Name ( ) ) ; EXPECT_EQ ( " " , cc -> Value ( ) ) ; EXPECT_EQ ( " " , cc -> Domain ( ) ) ; EXPECT_EQ ( " " , cc -> Path ( ) ) ; EXPECT_EQ ( base :: Time ( ) , cc -> CreationDate ( ) ) ; EXPECT_EQ ( base :: Time ( ) , cc -> LastAccessDate ( ) ) ; EXPECT_EQ ( base :: Time ( ) , cc -> ExpiryDate ( ) ) ; EXPECT_FALSE ( cc -> IsSecure ( ) ) ; EXPECT_FALSE ( cc -> IsHttpOnly ( ) ) ; EXPECT_EQ ( CookieSameSite :: NO_RESTRICTION , cc -> SameSite ( ) ) ; EXPECT_EQ ( COOKIE_PRIORITY_MEDIUM , cc -> Priority ( ) ) ; EXPECT_FALSE ( cc -> IsDomainCookie ( ) ) ; cc = CanonicalCookie :: CreateSanitizedCookie ( GURL ( " " ) , " " , " " , std :: string ( ) , " " , two_hours_ago , base :: Time ( ) , base :: Time ( ) , false , false , CookieSameSite :: NO_RESTRICTION , COOKIE_PRIORITY_DEFAULT ) ; EXPECT_TRUE ( cc ) ; EXPECT_EQ ( two_hours_ago , cc -> CreationDate ( ) ) ; cc = CanonicalCookie :: CreateSanitizedCookie ( GURL ( " " ) , " " , " " , std :: string ( ) , " " , two_hours_ago , base :: Time ( ) , one_hour_ago , false , false , CookieSameSite :: NO_RESTRICTION , COOKIE_PRIORITY_DEFAULT ) ; EXPECT_TRUE ( cc ) ; EXPECT_EQ ( one_hour_ago , cc -> LastAccessDate ( ) ) ; cc = CanonicalCookie :: CreateSanitizedCookie ( GURL ( " " ) , " " , " " , std :: string ( ) , " " , base :: Time ( ) , one_hour_from_now , base :: Time ( ) , false , false , CookieSameSite :: NO_RESTRICTION , COOKIE_PRIORITY_DEFAULT ) ; EXPECT_TRUE ( cc ) ; EXPECT_EQ ( one_hour_from_now , cc -> ExpiryDate ( ) ) ; cc = CanonicalCookie :: CreateSanitizedCookie ( GURL ( " " ) , " " , " " , std :: string ( ) , " " , base :: Time ( ) , base :: Time ( ) , base :: Time ( ) , true , false , CookieSameSite :: NO_RESTRICTION , COOKIE_PRIORITY_DEFAULT ) ; EXPECT_TRUE ( cc ) ; EXPECT_TRUE ( cc -> IsSecure ( ) ) ; cc = CanonicalCookie :: CreateSanitizedCookie ( GURL ( " " ) , " " , " " , std :: string ( ) , " " , base :: Time ( ) , base :: Time ( ) , base :: Time ( ) , false , true , CookieSameSite :: NO_RESTRICTION , COOKIE_PRIORITY_DEFAULT ) ; EXPECT_TRUE ( cc ) ; EXPECT_TRUE ( cc -> IsHttpOnly ( ) ) ; cc = CanonicalCookie :: CreateSanitizedCookie ( GURL ( " " ) , " " , " " , std :: string ( ) , " " , base :: Time ( ) , base :: Time ( ) , base :: Time ( ) , false , false , CookieSameSite :: LAX_MODE , COOKIE_PRIORITY_DEFAULT ) ; EXPECT_TRUE ( cc ) ; EXPECT_EQ ( CookieSameSite :: LAX_MODE , cc -> SameSite ( ) ) ; cc = CanonicalCookie :: CreateSanitizedCookie ( GURL ( " " ) , " " , " " , std :: string ( ) , " " , base :: Time ( ) , base :: Time ( ) , base :: Time ( ) , false , false , CookieSameSite :: NO_RESTRICTION , COOKIE_PRIORITY_LOW ) ; EXPECT_TRUE ( cc ) ; EXPECT_EQ ( COOKIE_PRIORITY_LOW , cc -> Priority ( ) ) ; cc = CanonicalCookie :: CreateSanitizedCookie ( GURL ( " " ) , " " , " " , " " , " " , base :: Time ( ) , base :: Time ( ) , base :: Time ( ) , false , false , CookieSameSite :: NO_RESTRICTION , COOKIE_PRIORITY_DEFAULT ) ; EXPECT_TRUE ( cc ) ; EXPECT_TRUE ( cc -> IsDomainCookie ( ) ) ; }
Confirm that input arguments are reflected in the output cookie.
Confirm that input arguments are reflected in the output cookie .
/*secure*/ /*httponly*/ // Creation date /*secure*/ /*httponly*/ // Last access date /*secure*/ /*httponly*/ // Expiry /*secure*/ /*httponly*/ // Secure /*secure*/ /*httponly*/ // Httponly /*secure*/ /*httponly*/ // Same site /*secure*/ /*httponly*/ // Priority /*secure*/ /*httponly*/ // Domain cookie /*secure*/ /*httponly*/