Commit 77288150 authored by Dylan Cutler's avatar Dylan Cutler Committed by Chromium LUCI CQ

Get //content/tests:content_unittests to pass if CanonicalCookie's

constructor is private.

This is part of a larger cleanup effort to make CanonicalCookie's
constructor private.

This CL was verified by building/running the unit test suite when
CanonicalCookie's constructor was locally changed to have a private
constructor.

Bug: 1102874
Change-Id: I1faa1b63e96091642c1a92ac8142b9de22c7d310
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2569941Reviewed-by: default avatarMaksim Orlovich <morlovich@chromium.org>
Reviewed-by: default avatarJoshua Bell <jsbell@chromium.org>
Reviewed-by: default avatarLily Chen <chlily@chromium.org>
Commit-Queue: Dylan Cutler <dylancutler@google.com>
Cr-Commit-Position: refs/heads/master@{#835697}
parent 67bd6cdd
...@@ -137,11 +137,11 @@ struct StoragePartitionRemovalData { ...@@ -137,11 +137,11 @@ struct StoragePartitionRemovalData {
}; };
net::CanonicalCookie CreateCookieWithHost(const url::Origin& origin) { net::CanonicalCookie CreateCookieWithHost(const url::Origin& origin) {
std::unique_ptr<net::CanonicalCookie> cookie( std::unique_ptr<net::CanonicalCookie> cookie =
std::make_unique<net::CanonicalCookie>( net::CanonicalCookie::CreateUnsafeCookieForTesting(
"A", "1", origin.host(), "/", base::Time::Now(), base::Time::Now(), "A", "1", origin.host(), "/", base::Time::Now(), base::Time::Now(),
base::Time(), false, false, net::CookieSameSite::NO_RESTRICTION, base::Time(), false, false, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_MEDIUM, false)); net::COOKIE_PRIORITY_MEDIUM, false);
EXPECT_TRUE(cookie); EXPECT_TRUE(cookie);
return *cookie; return *cookie;
} }
......
...@@ -37,13 +37,13 @@ void CreateCookieForTest( ...@@ -37,13 +37,13 @@ void CreateCookieForTest(
net::CookieOptions options; net::CookieOptions options;
options.set_same_site_cookie_context(cookie_context); options.set_same_site_cookie_context(cookie_context);
bool result_out; bool result_out;
net::CanonicalCookie cookie(cookie_name, "1", cookie_domain, "/", auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting(
base::Time(), base::Time(), base::Time(), cookie_name, "1", cookie_domain, "/", base::Time(), base::Time(),
is_cookie_secure, false, same_site, base::Time(), is_cookie_secure, false, same_site,
net::COOKIE_PRIORITY_LOW, false); net::COOKIE_PRIORITY_LOW, false);
GetCookieManager(browser_context) GetCookieManager(browser_context)
->SetCanonicalCookie( ->SetCanonicalCookie(
cookie, net::cookie_util::SimulatedCookieSource(cookie, "https"), *cookie, net::cookie_util::SimulatedCookieSource(*cookie, "https"),
options, options,
base::BindLambdaForTesting([&](net::CookieAccessResult result) { base::BindLambdaForTesting([&](net::CookieAccessResult result) {
result_out = result.status.IsInclude(); result_out = result.status.IsInclude();
......
...@@ -217,12 +217,12 @@ TEST_F(SameSiteDataRemoverImplTest, TestCookieRemovalUnaffectedByParameters) { ...@@ -217,12 +217,12 @@ TEST_F(SameSiteDataRemoverImplTest, TestCookieRemovalUnaffectedByParameters) {
net::CookieOptions options; net::CookieOptions options;
options.set_include_httponly(); options.set_include_httponly();
bool result_out = false; bool result_out = false;
net::CanonicalCookie cookie1("TestCookie1", "20", "google.com", "/", auto cookie1 = net::CanonicalCookie::CreateUnsafeCookieForTesting(
base::Time::Now(), base::Time(), base::Time(), "TestCookie1", "20", "google.com", "/", base::Time::Now(), base::Time(),
true, true, net::CookieSameSite::NO_RESTRICTION, base::Time(), true, true, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_HIGH, /*same_party=*/true); net::COOKIE_PRIORITY_HIGH, /*same_party=*/true);
cookie_manager->SetCanonicalCookie( cookie_manager->SetCanonicalCookie(
cookie1, net::cookie_util::SimulatedCookieSource(cookie1, "https"), *cookie1, net::cookie_util::SimulatedCookieSource(*cookie1, "https"),
options, base::BindLambdaForTesting([&](net::CookieAccessResult result) { options, base::BindLambdaForTesting([&](net::CookieAccessResult result) {
result_out = result.status.IsInclude(); result_out = result.status.IsInclude();
run_loop1.Quit(); run_loop1.Quit();
...@@ -236,12 +236,12 @@ TEST_F(SameSiteDataRemoverImplTest, TestCookieRemovalUnaffectedByParameters) { ...@@ -236,12 +236,12 @@ TEST_F(SameSiteDataRemoverImplTest, TestCookieRemovalUnaffectedByParameters) {
net::CookieOptions::SameSiteCookieContext::ContextType:: net::CookieOptions::SameSiteCookieContext::ContextType::
SAME_SITE_LAX)); SAME_SITE_LAX));
result_out = false; result_out = false;
net::CanonicalCookie cookie2("TestCookie2", "10", "gmail.google.com", "/", auto cookie2 = net::CanonicalCookie::CreateUnsafeCookieForTesting(
base::Time(), base::Time::Max(), base::Time(), "TestCookie2", "10", "gmail.google.com", "/", base::Time(),
false, true, net::CookieSameSite::LAX_MODE, base::Time::Max(), base::Time(), false, true,
net::COOKIE_PRIORITY_HIGH, false); net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_HIGH, false);
cookie_manager->SetCanonicalCookie( cookie_manager->SetCanonicalCookie(
cookie2, net::cookie_util::SimulatedCookieSource(cookie2, "https"), *cookie2, net::cookie_util::SimulatedCookieSource(*cookie2, "https"),
options, base::BindLambdaForTesting([&](net::CookieAccessResult result) { options, base::BindLambdaForTesting([&](net::CookieAccessResult result) {
result_out = result.status.IsInclude(); result_out = result.status.IsInclude();
run_loop2.Quit(); run_loop2.Quit();
......
...@@ -303,20 +303,23 @@ class CookieStoreManagerTest ...@@ -303,20 +303,23 @@ class CookieStoreManagerTest
const char* value, const char* value,
const char* domain, const char* domain,
const char* path) { const char* path) {
return SetCanonicalCookie(net::CanonicalCookie( return SetCanonicalCookie(
name, value, domain, path, base::Time(), base::Time(), base::Time(), *net::CanonicalCookie::CreateUnsafeCookieForTesting(
/* secure = */ true, name, value, domain, path, base::Time(), base::Time(), base::Time(),
/* httponly = */ false, net::CookieSameSite::NO_RESTRICTION, /* secure = */ true,
net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false)); /* httponly = */ false, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false));
} }
bool DeleteCookie(const char* name, const char* domain, const char* path) { bool DeleteCookie(const char* name, const char* domain, const char* path) {
return SetCanonicalCookie(net::CanonicalCookie( return SetCanonicalCookie(
name, /* value = */ "", domain, path, /* creation = */ base::Time(), *net::CanonicalCookie::CreateUnsafeCookieForTesting(
/* expiration = */ base::Time::Min(), /* last_access = */ base::Time(), name, /* value = */ "", domain, path, /* creation = */ base::Time(),
/* secure = */ true, /* httponly = */ false, /* expiration = */ base::Time::Min(),
net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT, /* last_access = */ base::Time(),
/* same_party = */ false)); /* secure = */ true, /* httponly = */ false,
net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT,
/* same_party = */ false));
} }
// Designates a closure for preparing the cookie store for the current test. // Designates a closure for preparing the cookie store for the current test.
...@@ -1557,22 +1560,24 @@ TEST_P(CookieStoreManagerTest, HttpOnlyCookieChange) { ...@@ -1557,22 +1560,24 @@ TEST_P(CookieStoreManagerTest, HttpOnlyCookieChange) {
if (reset_context_during_test()) if (reset_context_during_test())
ResetServiceWorkerContext(); ResetServiceWorkerContext();
ASSERT_TRUE(SetCanonicalCookie(net::CanonicalCookie( ASSERT_TRUE(
"cookie-name-1", "cookie-value-1", "example.com", "/", base::Time(), SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting(
base::Time(), base::Time(), "cookie-name-1", "cookie-value-1", "example.com", "/", base::Time(),
/* secure = */ true, base::Time(), base::Time(),
/* httponly = */ true, net::CookieSameSite::NO_RESTRICTION, /* secure = */ true,
net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false))); /* httponly = */ true, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false)));
task_environment_.RunUntilIdle(); task_environment_.RunUntilIdle();
EXPECT_EQ(0u, worker_test_helper_->changes().size()); EXPECT_EQ(0u, worker_test_helper_->changes().size());
worker_test_helper_->changes().clear(); worker_test_helper_->changes().clear();
ASSERT_TRUE(SetCanonicalCookie(net::CanonicalCookie( ASSERT_TRUE(
"cookie-name-2", "cookie-value-2", "example.com", "/", base::Time(), SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting(
base::Time(), base::Time(), "cookie-name-2", "cookie-value-2", "example.com", "/", base::Time(),
/* secure = */ true, base::Time(), base::Time(),
/* httponly = */ false, net::CookieSameSite::NO_RESTRICTION, /* secure = */ true,
net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false))); /* httponly = */ false, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false)));
task_environment_.RunUntilIdle(); task_environment_.RunUntilIdle();
ASSERT_EQ(1u, worker_test_helper_->changes().size()); ASSERT_EQ(1u, worker_test_helper_->changes().size());
...@@ -1612,22 +1617,24 @@ TEST_P(CookieStoreManagerTest, HttpOnlyCookieChangeLegacy) { ...@@ -1612,22 +1617,24 @@ TEST_P(CookieStoreManagerTest, HttpOnlyCookieChangeLegacy) {
if (reset_context_during_test()) if (reset_context_during_test())
ResetServiceWorkerContext(); ResetServiceWorkerContext();
ASSERT_TRUE(SetCanonicalCookie(net::CanonicalCookie( ASSERT_TRUE(
"cookie-name-1", "cookie-value-1", "legacy.com", "/", base::Time(), SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting(
base::Time(), base::Time(), "cookie-name-1", "cookie-value-1", "legacy.com", "/", base::Time(),
/* secure = */ false, base::Time(), base::Time(),
/* httponly = */ true, net::CookieSameSite::NO_RESTRICTION, /* secure = */ false,
net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false))); /* httponly = */ true, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false)));
task_environment_.RunUntilIdle(); task_environment_.RunUntilIdle();
EXPECT_EQ(0u, worker_test_helper_->changes().size()); EXPECT_EQ(0u, worker_test_helper_->changes().size());
worker_test_helper_->changes().clear(); worker_test_helper_->changes().clear();
ASSERT_TRUE(SetCanonicalCookie(net::CanonicalCookie( ASSERT_TRUE(
"cookie-name-2", "cookie-value-2", "legacy.com", "/", base::Time(), SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting(
base::Time(), base::Time(), "cookie-name-2", "cookie-value-2", "legacy.com", "/", base::Time(),
/* secure = */ false, base::Time(), base::Time(),
/* httponly = */ false, net::CookieSameSite::NO_RESTRICTION, /* secure = */ false,
net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false))); /* httponly = */ false, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false)));
task_environment_.RunUntilIdle(); task_environment_.RunUntilIdle();
ASSERT_EQ(1u, worker_test_helper_->changes().size()); ASSERT_EQ(1u, worker_test_helper_->changes().size());
......
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