Commit 25087abf authored by Dylan Cutler's avatar Dylan Cutler Committed by Commit Bot

Make CreateUnsafeCookieForTesting return a unique_ptr.

This will make it easier to use this factory when testing code that uses
SetCanonicalCookie() and other methods that take unique_ptrs to
CanonicalCookies.

The factory method uses base::WrapUnique to create the unique_ptr so
that the constructor can be made private. I plan on updating the other
factory methods to use base::WrapUnique instead of make_unique in a
follow-up CL.

Bug: 1102874
Change-Id: I3e84fbc68ce95438a5adfdac46573df9efe4e38d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2559311Reviewed-by: default avatarMaksim Orlovich <morlovich@chromium.org>
Commit-Queue: Dylan Cutler <dylancutler@google.com>
Cr-Commit-Position: refs/heads/master@{#831072}
parent 3bad00bf
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
...@@ -553,7 +554,7 @@ std::unique_ptr<CanonicalCookie> CanonicalCookie::FromStorage( ...@@ -553,7 +554,7 @@ std::unique_ptr<CanonicalCookie> CanonicalCookie::FromStorage(
} }
// static // static
CanonicalCookie CanonicalCookie::CreateUnsafeCookieForTesting( std::unique_ptr<CanonicalCookie> CanonicalCookie::CreateUnsafeCookieForTesting(
const std::string& name, const std::string& name,
const std::string& value, const std::string& value,
const std::string& domain, const std::string& domain,
...@@ -568,9 +569,9 @@ CanonicalCookie CanonicalCookie::CreateUnsafeCookieForTesting( ...@@ -568,9 +569,9 @@ CanonicalCookie CanonicalCookie::CreateUnsafeCookieForTesting(
bool same_party, bool same_party,
CookieSourceScheme source_scheme, CookieSourceScheme source_scheme,
int source_port) { int source_port) {
return CanonicalCookie(name, value, domain, path, creation, expiration, return base::WrapUnique(new CanonicalCookie(
last_access, secure, httponly, same_site, priority, name, value, domain, path, creation, expiration, last_access, secure,
same_party, source_scheme, source_port); httponly, same_site, priority, same_party, source_scheme, source_port));
} }
std::string CanonicalCookie::DomainWithoutDot() const { std::string CanonicalCookie::DomainWithoutDot() const {
......
...@@ -147,7 +147,7 @@ class NET_EXPORT CanonicalCookie { ...@@ -147,7 +147,7 @@ class NET_EXPORT CanonicalCookie {
// Create a CanonicalCookie that is not guaranteed to actually be Canonical // Create a CanonicalCookie that is not guaranteed to actually be Canonical
// for tests. This factory should NOT be used in production. // for tests. This factory should NOT be used in production.
static CanonicalCookie CreateUnsafeCookieForTesting( static std::unique_ptr<CanonicalCookie> CreateUnsafeCookieForTesting(
const std::string& name, const std::string& name,
const std::string& value, const std::string& value,
const std::string& domain, const std::string& domain,
......
...@@ -39,60 +39,60 @@ TEST(CanonicalCookieTest, Constructor) { ...@@ -39,60 +39,60 @@ TEST(CanonicalCookieTest, Constructor) {
"A", "2", "www.example.com", "/test", current_time, base::Time(), "A", "2", "www.example.com", "/test", current_time, base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT, false, CookieSourceScheme::kSecure, 443); COOKIE_PRIORITY_DEFAULT, false, CookieSourceScheme::kSecure, 443);
EXPECT_EQ("A", cookie1.Name()); EXPECT_EQ("A", cookie1->Name());
EXPECT_EQ("2", cookie1.Value()); EXPECT_EQ("2", cookie1->Value());
EXPECT_EQ("www.example.com", cookie1.Domain()); EXPECT_EQ("www.example.com", cookie1->Domain());
EXPECT_EQ("/test", cookie1.Path()); EXPECT_EQ("/test", cookie1->Path());
EXPECT_FALSE(cookie1.IsSecure()); EXPECT_FALSE(cookie1->IsSecure());
EXPECT_FALSE(cookie1.IsHttpOnly()); EXPECT_FALSE(cookie1->IsHttpOnly());
EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie1.SameSite()); EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie1->SameSite());
EXPECT_EQ(CookiePriority::COOKIE_PRIORITY_DEFAULT, cookie1.Priority()); EXPECT_EQ(CookiePriority::COOKIE_PRIORITY_DEFAULT, cookie1->Priority());
EXPECT_FALSE(cookie1.IsSameParty()); EXPECT_FALSE(cookie1->IsSameParty());
EXPECT_EQ(cookie1.SourceScheme(), CookieSourceScheme::kSecure); EXPECT_EQ(cookie1->SourceScheme(), CookieSourceScheme::kSecure);
EXPECT_EQ(cookie1.SourcePort(), 443); EXPECT_EQ(cookie1->SourcePort(), 443);
auto cookie2 = CanonicalCookie::CreateUnsafeCookieForTesting( auto cookie2 = CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "2", ".www.example.com", "/", current_time, base::Time(), "A", "2", ".www.example.com", "/", current_time, base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT, true, CookieSourceScheme::kNonSecure, 65536); COOKIE_PRIORITY_DEFAULT, true, CookieSourceScheme::kNonSecure, 65536);
EXPECT_EQ("A", cookie2.Name()); EXPECT_EQ("A", cookie2->Name());
EXPECT_EQ("2", cookie2.Value()); EXPECT_EQ("2", cookie2->Value());
EXPECT_EQ(".www.example.com", cookie2.Domain()); EXPECT_EQ(".www.example.com", cookie2->Domain());
EXPECT_EQ("/", cookie2.Path()); EXPECT_EQ("/", cookie2->Path());
EXPECT_FALSE(cookie2.IsSecure()); EXPECT_FALSE(cookie2->IsSecure());
EXPECT_FALSE(cookie2.IsHttpOnly()); EXPECT_FALSE(cookie2->IsHttpOnly());
EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie2.SameSite()); EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie2->SameSite());
EXPECT_EQ(CookiePriority::COOKIE_PRIORITY_DEFAULT, cookie2.Priority()); EXPECT_EQ(CookiePriority::COOKIE_PRIORITY_DEFAULT, cookie2->Priority());
EXPECT_TRUE(cookie2.IsSameParty()); EXPECT_TRUE(cookie2->IsSameParty());
EXPECT_EQ(cookie2.SourceScheme(), CookieSourceScheme::kNonSecure); EXPECT_EQ(cookie2->SourceScheme(), CookieSourceScheme::kNonSecure);
// Because the port can be set explicitly in the constructor its value can be // Because the port can be set explicitly in the constructor its value can be
// independent of the other parameters. In this case, test that an invalid // independent of the other parameters. In this case, test that an invalid
// port value is interpreted as such. // port value is interpreted as such.
EXPECT_EQ(cookie2.SourcePort(), url::PORT_INVALID); EXPECT_EQ(cookie2->SourcePort(), url::PORT_INVALID);
// Set Secure to true but don't specify source_scheme or port. // Set Secure to true but don't specify source_scheme or port.
auto cookie3 = CanonicalCookie::CreateUnsafeCookieForTesting( auto cookie3 = CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "2", ".www.example.com", "/", current_time, base::Time(), "A", "2", ".www.example.com", "/", current_time, base::Time(),
base::Time(), true /* secure */, false, CookieSameSite::NO_RESTRICTION, base::Time(), true /* secure */, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT, false); COOKIE_PRIORITY_DEFAULT, false);
EXPECT_TRUE(cookie3.IsSecure()); EXPECT_TRUE(cookie3->IsSecure());
EXPECT_EQ(cookie3.SourceScheme(), CookieSourceScheme::kUnset); EXPECT_EQ(cookie3->SourceScheme(), CookieSourceScheme::kUnset);
EXPECT_EQ(cookie3.SourcePort(), url::PORT_UNSPECIFIED); EXPECT_EQ(cookie3->SourcePort(), url::PORT_UNSPECIFIED);
auto cookie4 = CanonicalCookie::CreateUnsafeCookieForTesting( auto cookie4 = CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "2", ".www.example.com", "/test", current_time, base::Time(), "A", "2", ".www.example.com", "/test", current_time, base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT, false); COOKIE_PRIORITY_DEFAULT, false);
EXPECT_EQ("A", cookie4.Name()); EXPECT_EQ("A", cookie4->Name());
EXPECT_EQ("2", cookie4.Value()); EXPECT_EQ("2", cookie4->Value());
EXPECT_EQ(".www.example.com", cookie4.Domain()); EXPECT_EQ(".www.example.com", cookie4->Domain());
EXPECT_EQ("/test", cookie4.Path()); EXPECT_EQ("/test", cookie4->Path());
EXPECT_FALSE(cookie4.IsSecure()); EXPECT_FALSE(cookie4->IsSecure());
EXPECT_FALSE(cookie4.IsHttpOnly()); EXPECT_FALSE(cookie4->IsHttpOnly());
EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie4.SameSite()); EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie4->SameSite());
EXPECT_FALSE(cookie4.IsSameParty()); EXPECT_FALSE(cookie4->IsSameParty());
EXPECT_EQ(cookie4.SourceScheme(), CookieSourceScheme::kUnset); EXPECT_EQ(cookie4->SourceScheme(), CookieSourceScheme::kUnset);
EXPECT_EQ(cookie4.SourcePort(), url::PORT_UNSPECIFIED); EXPECT_EQ(cookie4->SourcePort(), url::PORT_UNSPECIFIED);
// Test some port edge cases: unspecified. // Test some port edge cases: unspecified.
auto cookie5 = CanonicalCookie::CreateUnsafeCookieForTesting( auto cookie5 = CanonicalCookie::CreateUnsafeCookieForTesting(
...@@ -100,7 +100,7 @@ TEST(CanonicalCookieTest, Constructor) { ...@@ -100,7 +100,7 @@ TEST(CanonicalCookieTest, Constructor) {
base::Time(), true /* secure */, false, CookieSameSite::NO_RESTRICTION, base::Time(), true /* secure */, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT, false, CookieSourceScheme::kUnset, COOKIE_PRIORITY_DEFAULT, false, CookieSourceScheme::kUnset,
url::PORT_UNSPECIFIED); url::PORT_UNSPECIFIED);
EXPECT_EQ(cookie5.SourcePort(), url::PORT_UNSPECIFIED); EXPECT_EQ(cookie5->SourcePort(), url::PORT_UNSPECIFIED);
// Test some port edge cases: invalid. // Test some port edge cases: invalid.
auto cookie6 = CanonicalCookie::CreateUnsafeCookieForTesting( auto cookie6 = CanonicalCookie::CreateUnsafeCookieForTesting(
...@@ -108,7 +108,7 @@ TEST(CanonicalCookieTest, Constructor) { ...@@ -108,7 +108,7 @@ TEST(CanonicalCookieTest, Constructor) {
base::Time(), true /* secure */, false, CookieSameSite::NO_RESTRICTION, base::Time(), true /* secure */, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT, false, CookieSourceScheme::kUnset, COOKIE_PRIORITY_DEFAULT, false, CookieSourceScheme::kUnset,
url::PORT_INVALID); url::PORT_INVALID);
EXPECT_EQ(cookie6.SourcePort(), url::PORT_INVALID); EXPECT_EQ(cookie6->SourcePort(), url::PORT_INVALID);
} }
TEST(CanonicalCookie, CreationCornerCases) { TEST(CanonicalCookie, CreationCornerCases) {
...@@ -420,16 +420,16 @@ TEST(CanonicalCookieTest, IsEquivalent) { ...@@ -420,16 +420,16 @@ TEST(CanonicalCookieTest, IsEquivalent) {
cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time,
expiration_time, base::Time(), secure, httponly, same_site, expiration_time, base::Time(), secure, httponly, same_site,
COOKIE_PRIORITY_MEDIUM, same_party); COOKIE_PRIORITY_MEDIUM, same_party);
EXPECT_TRUE(cookie.IsEquivalent(cookie)); EXPECT_TRUE(cookie->IsEquivalent(*cookie));
EXPECT_TRUE(cookie.IsEquivalentForSecureCookieMatching(cookie)); EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*cookie));
// Test that two identical cookies are equivalent. // Test that two identical cookies are equivalent.
auto other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( auto other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting(
cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time,
expiration_time, base::Time(), secure, httponly, same_site, expiration_time, base::Time(), secure, httponly, same_site,
COOKIE_PRIORITY_MEDIUM, same_party); COOKIE_PRIORITY_MEDIUM, same_party);
EXPECT_TRUE(cookie.IsEquivalent(other_cookie)); EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
EXPECT_TRUE(other_cookie.IsEquivalentForSecureCookieMatching(cookie)); EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie));
// Tests that use different variations of attribute values that // Tests that use different variations of attribute values that
// DON'T affect cookie equivalence. // DON'T affect cookie equivalence.
...@@ -437,9 +437,9 @@ TEST(CanonicalCookieTest, IsEquivalent) { ...@@ -437,9 +437,9 @@ TEST(CanonicalCookieTest, IsEquivalent) {
cookie_name, "2", cookie_domain, cookie_path, creation_time, cookie_name, "2", cookie_domain, cookie_path, creation_time,
expiration_time, base::Time(), secure, httponly, same_site, expiration_time, base::Time(), secure, httponly, same_site,
COOKIE_PRIORITY_HIGH, same_party); COOKIE_PRIORITY_HIGH, same_party);
EXPECT_TRUE(cookie.IsEquivalent(other_cookie)); EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
EXPECT_TRUE(cookie.IsEquivalentForSecureCookieMatching(other_cookie)); EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
EXPECT_TRUE(other_cookie.IsEquivalentForSecureCookieMatching(cookie)); EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie));
base::Time other_creation_time = base::Time other_creation_time =
creation_time + base::TimeDelta::FromMinutes(2); creation_time + base::TimeDelta::FromMinutes(2);
...@@ -447,42 +447,42 @@ TEST(CanonicalCookieTest, IsEquivalent) { ...@@ -447,42 +447,42 @@ TEST(CanonicalCookieTest, IsEquivalent) {
cookie_name, "2", cookie_domain, cookie_path, other_creation_time, cookie_name, "2", cookie_domain, cookie_path, other_creation_time,
expiration_time, base::Time(), secure, httponly, same_site, expiration_time, base::Time(), secure, httponly, same_site,
COOKIE_PRIORITY_MEDIUM, same_party); COOKIE_PRIORITY_MEDIUM, same_party);
EXPECT_TRUE(cookie.IsEquivalent(other_cookie)); EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
EXPECT_TRUE(cookie.IsEquivalentForSecureCookieMatching(other_cookie)); EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
EXPECT_TRUE(other_cookie.IsEquivalentForSecureCookieMatching(cookie)); EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie));
other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting(
cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time,
expiration_time, base::Time(), true, httponly, same_site, expiration_time, base::Time(), true, httponly, same_site,
COOKIE_PRIORITY_LOW, same_party); COOKIE_PRIORITY_LOW, same_party);
EXPECT_TRUE(cookie.IsEquivalent(other_cookie)); EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
EXPECT_TRUE(cookie.IsEquivalentForSecureCookieMatching(other_cookie)); EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
EXPECT_TRUE(other_cookie.IsEquivalentForSecureCookieMatching(cookie)); EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie));
other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting(
cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time,
expiration_time, base::Time(), secure, true, same_site, expiration_time, base::Time(), secure, true, same_site,
COOKIE_PRIORITY_LOW, same_party); COOKIE_PRIORITY_LOW, same_party);
EXPECT_TRUE(cookie.IsEquivalent(other_cookie)); EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
EXPECT_TRUE(cookie.IsEquivalentForSecureCookieMatching(other_cookie)); EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
EXPECT_TRUE(other_cookie.IsEquivalentForSecureCookieMatching(cookie)); EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie));
other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting(
cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time,
expiration_time, base::Time(), secure, httponly, expiration_time, base::Time(), secure, httponly,
CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_LOW, same_party); CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_LOW, same_party);
EXPECT_TRUE(cookie.IsEquivalent(other_cookie)); EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
EXPECT_TRUE(cookie.IsEquivalentForSecureCookieMatching(other_cookie)); EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
EXPECT_TRUE(other_cookie.IsEquivalentForSecureCookieMatching(cookie)); EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie));
// Cookies whose names mismatch are not equivalent. // Cookies whose names mismatch are not equivalent.
other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting(
"B", cookie_value, cookie_domain, cookie_path, creation_time, "B", cookie_value, cookie_domain, cookie_path, creation_time,
expiration_time, base::Time(), secure, httponly, same_site, expiration_time, base::Time(), secure, httponly, same_site,
COOKIE_PRIORITY_MEDIUM, same_party); COOKIE_PRIORITY_MEDIUM, same_party);
EXPECT_FALSE(cookie.IsEquivalent(other_cookie)); EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
EXPECT_FALSE(cookie.IsEquivalentForSecureCookieMatching(other_cookie)); EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
EXPECT_FALSE(other_cookie.IsEquivalentForSecureCookieMatching(cookie)); EXPECT_FALSE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie));
// A domain cookie at 'www.example.com' is not equivalent to a host cookie // A domain cookie at 'www.example.com' is not equivalent to a host cookie
// at the same domain. These are, however, equivalent according to the laxer // at the same domain. These are, however, equivalent according to the laxer
...@@ -491,11 +491,11 @@ TEST(CanonicalCookieTest, IsEquivalent) { ...@@ -491,11 +491,11 @@ TEST(CanonicalCookieTest, IsEquivalent) {
cookie_name, cookie_value, "www.example.com", cookie_path, creation_time, cookie_name, cookie_value, "www.example.com", cookie_path, creation_time,
expiration_time, base::Time(), secure, httponly, same_site, expiration_time, base::Time(), secure, httponly, same_site,
COOKIE_PRIORITY_MEDIUM, same_party); COOKIE_PRIORITY_MEDIUM, same_party);
EXPECT_TRUE(cookie.IsDomainCookie()); EXPECT_TRUE(cookie->IsDomainCookie());
EXPECT_FALSE(other_cookie.IsDomainCookie()); EXPECT_FALSE(other_cookie->IsDomainCookie());
EXPECT_FALSE(cookie.IsEquivalent(other_cookie)); EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
EXPECT_TRUE(cookie.IsEquivalentForSecureCookieMatching(other_cookie)); EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
EXPECT_TRUE(other_cookie.IsEquivalentForSecureCookieMatching(cookie)); EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie));
// Likewise, a cookie on 'example.com' is not equivalent to a cookie on // Likewise, a cookie on 'example.com' is not equivalent to a cookie on
// 'www.example.com', but they are equivalent for secure cookie matching. // 'www.example.com', but they are equivalent for secure cookie matching.
...@@ -503,9 +503,9 @@ TEST(CanonicalCookieTest, IsEquivalent) { ...@@ -503,9 +503,9 @@ TEST(CanonicalCookieTest, IsEquivalent) {
cookie_name, cookie_value, ".example.com", cookie_path, creation_time, cookie_name, cookie_value, ".example.com", cookie_path, creation_time,
expiration_time, base::Time(), secure, httponly, same_site, expiration_time, base::Time(), secure, httponly, same_site,
COOKIE_PRIORITY_MEDIUM, same_party); COOKIE_PRIORITY_MEDIUM, same_party);
EXPECT_FALSE(cookie.IsEquivalent(other_cookie)); EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
EXPECT_TRUE(cookie.IsEquivalentForSecureCookieMatching(other_cookie)); EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
EXPECT_TRUE(other_cookie.IsEquivalentForSecureCookieMatching(cookie)); EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie));
// Paths are a bit more complicated. 'IsEquivalent' requires an exact path // Paths are a bit more complicated. 'IsEquivalent' requires an exact path
// match, while secure cookie matching uses a more relaxed 'IsOnPath' check. // match, while secure cookie matching uses a more relaxed 'IsOnPath' check.
...@@ -516,26 +516,26 @@ TEST(CanonicalCookieTest, IsEquivalent) { ...@@ -516,26 +516,26 @@ TEST(CanonicalCookieTest, IsEquivalent) {
cookie_name, cookie_value, cookie_domain, "/test", creation_time, cookie_name, cookie_value, cookie_domain, "/test", creation_time,
expiration_time, base::Time(), secure, httponly, same_site, expiration_time, base::Time(), secure, httponly, same_site,
COOKIE_PRIORITY_MEDIUM, same_party); COOKIE_PRIORITY_MEDIUM, same_party);
EXPECT_FALSE(cookie.IsEquivalent(other_cookie)); EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
EXPECT_FALSE(cookie.IsEquivalentForSecureCookieMatching(other_cookie)); EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
EXPECT_FALSE(other_cookie.IsEquivalentForSecureCookieMatching(cookie)); EXPECT_FALSE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie));
other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting(
cookie_name, cookie_value, cookie_domain, cookie_path + "/subpath", cookie_name, cookie_value, cookie_domain, cookie_path + "/subpath",
creation_time, expiration_time, base::Time(), secure, httponly, same_site, creation_time, expiration_time, base::Time(), secure, httponly, same_site,
COOKIE_PRIORITY_MEDIUM, same_party); COOKIE_PRIORITY_MEDIUM, same_party);
EXPECT_FALSE(cookie.IsEquivalent(other_cookie)); EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
// The path comparison is asymmetric // The path comparison is asymmetric
EXPECT_FALSE(cookie.IsEquivalentForSecureCookieMatching(other_cookie)); EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
EXPECT_TRUE(other_cookie.IsEquivalentForSecureCookieMatching(cookie)); EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie));
other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting(
cookie_name, cookie_value, cookie_domain, "/", creation_time, cookie_name, cookie_value, cookie_domain, "/", creation_time,
expiration_time, base::Time(), secure, httponly, same_site, expiration_time, base::Time(), secure, httponly, same_site,
COOKIE_PRIORITY_MEDIUM, same_party); COOKIE_PRIORITY_MEDIUM, same_party);
EXPECT_FALSE(cookie.IsEquivalent(other_cookie)); EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
EXPECT_TRUE(cookie.IsEquivalentForSecureCookieMatching(other_cookie)); EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
EXPECT_FALSE(other_cookie.IsEquivalentForSecureCookieMatching(cookie)); EXPECT_FALSE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie));
} }
TEST(CanonicalCookieTest, IsEquivalentForSecureCookieMatching) { TEST(CanonicalCookieTest, IsEquivalentForSecureCookieMatching) {
...@@ -582,9 +582,9 @@ TEST(CanonicalCookieTest, IsEquivalentForSecureCookieMatching) { ...@@ -582,9 +582,9 @@ TEST(CanonicalCookieTest, IsEquivalentForSecureCookieMatching) {
COOKIE_PRIORITY_MEDIUM, false); COOKIE_PRIORITY_MEDIUM, false);
EXPECT_EQ(test.equivalent, EXPECT_EQ(test.equivalent,
cookie.IsEquivalentForSecureCookieMatching(secure_cookie)); cookie->IsEquivalentForSecureCookieMatching(*secure_cookie));
EXPECT_EQ(test.equivalent == test.is_symmetric, EXPECT_EQ(test.equivalent == test.is_symmetric,
secure_cookie.IsEquivalentForSecureCookieMatching(cookie)); secure_cookie->IsEquivalentForSecureCookieMatching(*cookie));
} }
} }
...@@ -1433,13 +1433,13 @@ TEST(CanonicalCookieTest, MultipleExclusionReasons) { ...@@ -1433,13 +1433,13 @@ TEST(CanonicalCookieTest, MultipleExclusionReasons) {
// Test IncludeForRequestURL() // Test IncludeForRequestURL()
// Note: This is a cookie that should never exist normally, because Create() // Note: This is a cookie that should never exist normally, because Create()
// would weed it out. // would weed it out.
CanonicalCookie cookie1 = CanonicalCookie::CreateUnsafeCookieForTesting( auto cookie1 = CanonicalCookie::CreateUnsafeCookieForTesting(
"name", "value", "other-domain.com", "/bar", creation_time, base::Time(), "name", "value", "other-domain.com", "/bar", creation_time, base::Time(),
base::Time(), true /* secure */, true /* httponly */, base::Time(), true /* secure */, true /* httponly */,
CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT, false); CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT, false);
EXPECT_TRUE( EXPECT_TRUE(
cookie1 cookie1
.IncludeForRequestURL( ->IncludeForRequestURL(
url, options, url, options,
CookieAccessParams{CookieAccessSemantics::UNKNOWN, CookieAccessParams{CookieAccessSemantics::UNKNOWN,
/*delegate_treats_url_as_trustworthy=*/false}) /*delegate_treats_url_as_trustworthy=*/false})
...@@ -1636,42 +1636,42 @@ TEST(CanonicalCookieTest, IsCanonical) { ...@@ -1636,42 +1636,42 @@ TEST(CanonicalCookieTest, IsCanonical) {
"A", "B", "x.y", "/path", base::Time(), base::Time(), "A", "B", "x.y", "/path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Newline in name. // Newline in name.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A\n", "B", "x.y", "/path", base::Time(), base::Time(), "A\n", "B", "x.y", "/path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Carriage return in name. // Carriage return in name.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A\r", "B", "x.y", "/path", base::Time(), base::Time(), "A\r", "B", "x.y", "/path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Null character in name. // Null character in name.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
std::string("A\0Z", 3), "B", "x.y", "/path", base::Time(), std::string("A\0Z", 3), "B", "x.y", "/path", base::Time(),
base::Time(), base::Time(), false, false, base::Time(), base::Time(), false, false,
CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Name begins with whitespace. // Name begins with whitespace.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
" A", "B", "x.y", "/path", base::Time(), base::Time(), " A", "B", "x.y", "/path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Name ends with whitespace. // Name ends with whitespace.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A ", "B", "x.y", "/path", base::Time(), base::Time(), "A ", "B", "x.y", "/path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Empty name. (Note this is against the spec but compatible with other // Empty name. (Note this is against the spec but compatible with other
// browsers.) // browsers.)
...@@ -1679,70 +1679,70 @@ TEST(CanonicalCookieTest, IsCanonical) { ...@@ -1679,70 +1679,70 @@ TEST(CanonicalCookieTest, IsCanonical) {
"", "B", "x.y", "/path", base::Time(), base::Time(), "", "B", "x.y", "/path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Space in name // Space in name
EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A C", "B", "x.y", "/path", base::Time(), base::Time(), "A C", "B", "x.y", "/path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Extra space suffixing name. // Extra space suffixing name.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A ", "B", "x.y", "/path", base::Time(), base::Time(), "A ", "B", "x.y", "/path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// '=' character in name. // '=' character in name.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A=", "B", "x.y", "/path", base::Time(), base::Time(), "A=", "B", "x.y", "/path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Separator in name. // Separator in name.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A;", "B", "x.y", "/path", base::Time(), base::Time(), "A;", "B", "x.y", "/path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// '=' character in value. // '=' character in value.
EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "B=", "x.y", "/path", base::Time(), base::Time(), "A", "B=", "x.y", "/path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Separator in value. // Separator in value.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "B;", "x.y", "/path", base::Time(), base::Time(), "A", "B;", "x.y", "/path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Separator in domain. // Separator in domain.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "B", ";x.y", "/path", base::Time(), base::Time(), "A", "B", ";x.y", "/path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Garbage in domain. // Garbage in domain.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "B", "@:&", "/path", base::Time(), base::Time(), "A", "B", "@:&", "/path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Space in domain. // Space in domain.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "B", "x.y ", "/path", base::Time(), base::Time(), "A", "B", "x.y ", "/path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Empty domain. (This is against cookie spec, but needed for Chrome's // Empty domain. (This is against cookie spec, but needed for Chrome's
// out-of-spec use of cookies for extensions; see http://crbug.com/730633. // out-of-spec use of cookies for extensions; see http://crbug.com/730633.
...@@ -1750,49 +1750,49 @@ TEST(CanonicalCookieTest, IsCanonical) { ...@@ -1750,49 +1750,49 @@ TEST(CanonicalCookieTest, IsCanonical) {
"A", "B", "", "/path", base::Time(), base::Time(), "A", "B", "", "/path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Path does not start with a "/". // Path does not start with a "/".
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "B", "x.y", "path", base::Time(), base::Time(), "A", "B", "x.y", "path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Empty path. // Empty path.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "B", "x.y", "", base::Time(), base::Time(), "A", "B", "x.y", "", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Simple IPv4 address as domain. // Simple IPv4 address as domain.
EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "B", "1.2.3.4", "/path", base::Time(), base::Time(), "A", "B", "1.2.3.4", "/path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// NOn-canonical IPv4 address as domain. // NOn-canonical IPv4 address as domain.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "B", "01.2.03.4", "/path", base::Time(), base::Time(), "A", "B", "01.2.03.4", "/path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Null IPv6 address as domain. // Null IPv6 address as domain.
EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "B", "[::]", "/path", base::Time(), base::Time(), "A", "B", "[::]", "/path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Localhost IPv6 address as domain. // Localhost IPv6 address as domain.
EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "B", "[::1]", "/path", base::Time(), base::Time(), "A", "B", "[::1]", "/path", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Fully speced IPv6 address as domain. // Fully speced IPv6 address as domain.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
...@@ -1800,7 +1800,7 @@ TEST(CanonicalCookieTest, IsCanonical) { ...@@ -1800,7 +1800,7 @@ TEST(CanonicalCookieTest, IsCanonical) {
"/path", base::Time(), base::Time(), base::Time(), false, "/path", base::Time(), base::Time(), base::Time(), false,
false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW,
false) false)
.IsCanonical()); ->IsCanonical());
// Zero abbreviated IPv6 address as domain. Not canonical because of leading // Zero abbreviated IPv6 address as domain. Not canonical because of leading
// zeros & uppercase hex letters. // zeros & uppercase hex letters.
...@@ -1808,7 +1808,7 @@ TEST(CanonicalCookieTest, IsCanonical) { ...@@ -1808,7 +1808,7 @@ TEST(CanonicalCookieTest, IsCanonical) {
"A", "B", "[2001:0DB8:AC10:FE01::]", "/path", base::Time(), "A", "B", "[2001:0DB8:AC10:FE01::]", "/path", base::Time(),
base::Time(), base::Time(), false, false, base::Time(), base::Time(), false, false,
CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Zero prefixes removed IPv6 address as domain. Not canoncial because of // Zero prefixes removed IPv6 address as domain. Not canoncial because of
// uppercase hex letters. // uppercase hex letters.
...@@ -1816,94 +1816,94 @@ TEST(CanonicalCookieTest, IsCanonical) { ...@@ -1816,94 +1816,94 @@ TEST(CanonicalCookieTest, IsCanonical) {
"A", "B", "[2001:DB8:AC10:FE01::]", "/path", base::Time(), "A", "B", "[2001:DB8:AC10:FE01::]", "/path", base::Time(),
base::Time(), base::Time(), false, false, base::Time(), base::Time(), false, false,
CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Lowercased hex IPv6 address as domain. // Lowercased hex IPv6 address as domain.
EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "B", "[2001:db8:ac10:fe01::]", "/path", base::Time(), "A", "B", "[2001:db8:ac10:fe01::]", "/path", base::Time(),
base::Time(), base::Time(), false, false, base::Time(), base::Time(), false, false,
CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Properly formatted host cookie. // Properly formatted host cookie.
EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting(
"__Host-A", "B", "x.y", "/", base::Time(), base::Time(), "__Host-A", "B", "x.y", "/", base::Time(), base::Time(),
base::Time(), true, false, CookieSameSite::NO_RESTRICTION, base::Time(), true, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Insecure host cookie. // Insecure host cookie.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
"__Host-A", "B", "x.y", "/", base::Time(), base::Time(), "__Host-A", "B", "x.y", "/", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Host cookie with non-null path. // Host cookie with non-null path.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
"__Host-A", "B", "x.y", "/path", base::Time(), base::Time(), "__Host-A", "B", "x.y", "/path", base::Time(), base::Time(),
base::Time(), true, false, CookieSameSite::NO_RESTRICTION, base::Time(), true, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Host cookie with empty domain. // Host cookie with empty domain.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
"__Host-A", "B", "", "/", base::Time(), base::Time(), "__Host-A", "B", "", "/", base::Time(), base::Time(),
base::Time(), true, false, CookieSameSite::NO_RESTRICTION, base::Time(), true, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Host cookie with period prefixed domain. // Host cookie with period prefixed domain.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
"__Host-A", "B", ".x.y", "/", base::Time(), base::Time(), "__Host-A", "B", ".x.y", "/", base::Time(), base::Time(),
base::Time(), true, false, CookieSameSite::NO_RESTRICTION, base::Time(), true, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Properly formatted secure cookie. // Properly formatted secure cookie.
EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting(
"__Secure-A", "B", "x.y", "/", base::Time(), base::Time(), "__Secure-A", "B", "x.y", "/", base::Time(), base::Time(),
base::Time(), true, false, CookieSameSite::NO_RESTRICTION, base::Time(), true, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// Insecure secure cookie. // Insecure secure cookie.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
"__Secure-A", "B", "x.y", "/", base::Time(), base::Time(), "__Secure-A", "B", "x.y", "/", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, false) COOKIE_PRIORITY_LOW, false)
.IsCanonical()); ->IsCanonical());
// SameParty attribute used correctly (with Secure and non-Strict SameSite). // SameParty attribute used correctly (with Secure and non-Strict SameSite).
EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "B", "x.y", "/", base::Time(), base::Time(), "A", "B", "x.y", "/", base::Time(), base::Time(),
base::Time(), true, false, CookieSameSite::NO_RESTRICTION, base::Time(), true, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_LOW, true) COOKIE_PRIORITY_LOW, true)
.IsCanonical()); ->IsCanonical());
EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "B", "x.y", "/", base::Time(), base::Time(), "A", "B", "x.y", "/", base::Time(), base::Time(),
base::Time(), true, false, CookieSameSite::UNSPECIFIED, base::Time(), true, false, CookieSameSite::UNSPECIFIED,
COOKIE_PRIORITY_LOW, true) COOKIE_PRIORITY_LOW, true)
.IsCanonical()); ->IsCanonical());
EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "B", "x.y", "/", base::Time(), base::Time(), "A", "B", "x.y", "/", base::Time(), base::Time(),
base::Time(), true, false, CookieSameSite::LAX_MODE, base::Time(), true, false, CookieSameSite::LAX_MODE,
COOKIE_PRIORITY_LOW, true) COOKIE_PRIORITY_LOW, true)
.IsCanonical()); ->IsCanonical());
// SameParty without Secure is not canonical. // SameParty without Secure is not canonical.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "B", "x.y", "/", base::Time(), base::Time(), "A", "B", "x.y", "/", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::LAX_MODE, base::Time(), false, false, CookieSameSite::LAX_MODE,
COOKIE_PRIORITY_LOW, true) COOKIE_PRIORITY_LOW, true)
.IsCanonical()); ->IsCanonical());
// SameParty with SameSite=Strict is not canonical. // SameParty with SameSite=Strict is not canonical.
EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "B", "x.y", "/", base::Time(), base::Time(), "A", "B", "x.y", "/", base::Time(), base::Time(),
base::Time(), true, false, CookieSameSite::STRICT_MODE, base::Time(), true, false, CookieSameSite::STRICT_MODE,
COOKIE_PRIORITY_LOW, true) COOKIE_PRIORITY_LOW, true)
.IsCanonical()); ->IsCanonical());
} }
TEST(CanonicalCookieTest, TestSetCreationDate) { TEST(CanonicalCookieTest, TestSetCreationDate) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment