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

Get //chrome/test:browser_tests to build if CanonicalCookie's

constructor is private.

This is part of a larger effort to make the generic constructor of
CanonicalCookie private.

CreateUnsafeCookieForTesting is a factory method that creates a
test-only cookie which is not guaranteed to be canonical and should not
be used in production.

Bug: 1102874
Change-Id: I70bd75b14fa7ca5559a760905b459823b4f0d947
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2584644Reviewed-by: default avatarMaksim Orlovich <morlovich@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Commit-Queue: Dylan Cutler <dylancutler@google.com>
Cr-Commit-Position: refs/heads/master@{#836100}
parent bbceec86
...@@ -274,7 +274,7 @@ std::string GetCookiesTreeModelInfo(const CookieTreeNode* root) { ...@@ -274,7 +274,7 @@ std::string GetCookiesTreeModelInfo(const CookieTreeNode* root) {
// Sets the APISID Gaia cookie, which is monitored by the AccountReconcilor. // Sets the APISID Gaia cookie, which is monitored by the AccountReconcilor.
bool SetGaiaCookieForProfile(Profile* profile) { bool SetGaiaCookieForProfile(Profile* profile) {
GURL google_url = GaiaUrls::GetInstance()->secure_google_url(); GURL google_url = GaiaUrls::GetInstance()->secure_google_url();
net::CanonicalCookie cookie( auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting(
"SAPISID", std::string(), "." + google_url.host(), "/", base::Time(), "SAPISID", std::string(), "." + google_url.host(), "/", base::Time(),
base::Time(), base::Time(), true /* secure */, false /* httponly */, base::Time(), base::Time(), true /* secure */, false /* httponly */,
net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT,
...@@ -289,7 +289,7 @@ bool SetGaiaCookieForProfile(Profile* profile) { ...@@ -289,7 +289,7 @@ bool SetGaiaCookieForProfile(Profile* profile) {
network::mojom::CookieManager* cookie_manager = network::mojom::CookieManager* cookie_manager =
content::BrowserContext::GetDefaultStoragePartition(profile) content::BrowserContext::GetDefaultStoragePartition(profile)
->GetCookieManagerForBrowserProcess(); ->GetCookieManagerForBrowserProcess();
cookie_manager->SetCanonicalCookie(cookie, google_url, cookie_manager->SetCanonicalCookie(*cookie, google_url,
net::CookieOptions::MakeAllInclusive(), net::CookieOptions::MakeAllInclusive(),
std::move(callback)); std::move(callback));
loop.Run(); loop.Run();
......
...@@ -53,11 +53,11 @@ const char kRemoveEverythingArguments[] = ...@@ -53,11 +53,11 @@ const char kRemoveEverythingArguments[] =
// Sets the SAPISID Gaia cookie, which is monitored by the AccountReconcilor. // Sets the SAPISID Gaia cookie, which is monitored by the AccountReconcilor.
bool SetGaiaCookieForProfile(Profile* profile) { bool SetGaiaCookieForProfile(Profile* profile) {
GURL google_url = GaiaUrls::GetInstance()->secure_google_url(); GURL google_url = GaiaUrls::GetInstance()->secure_google_url();
net::CanonicalCookie cookie("SAPISID", std::string(), "." + google_url.host(), auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting(
"/", base::Time(), base::Time(), base::Time(), "SAPISID", std::string(), "." + google_url.host(), "/", base::Time(),
/*secure=*/true, false, base::Time(), base::Time(),
net::CookieSameSite::NO_RESTRICTION, /*secure=*/true, false, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_DEFAULT, false); net::COOKIE_PRIORITY_DEFAULT, false);
bool success = false; bool success = false;
base::RunLoop loop; base::RunLoop loop;
...@@ -72,7 +72,7 @@ bool SetGaiaCookieForProfile(Profile* profile) { ...@@ -72,7 +72,7 @@ bool SetGaiaCookieForProfile(Profile* profile) {
content::BrowserContext::GetDefaultStoragePartition(profile) content::BrowserContext::GetDefaultStoragePartition(profile)
->GetCookieManagerForBrowserProcess(); ->GetCookieManagerForBrowserProcess();
cookie_manager->SetCanonicalCookie( cookie_manager->SetCanonicalCookie(
cookie, google_url, net::CookieOptions::MakeAllInclusive(), *cookie, google_url, net::CookieOptions::MakeAllInclusive(),
mojo::WrapCallbackWithDefaultInvokeIfNotRun( mojo::WrapCallbackWithDefaultInvokeIfNotRun(
std::move(callback), std::move(callback),
net::CookieAccessResult(net::CookieInclusionStatus( net::CookieAccessResult(net::CookieInclusionStatus(
......
...@@ -3661,14 +3661,14 @@ class ClearAllCachedAuthTokensFunctionTestWithPartitionParam ...@@ -3661,14 +3661,14 @@ class ClearAllCachedAuthTokensFunctionTestWithPartitionParam
IN_PROC_BROWSER_TEST_P(ClearAllCachedAuthTokensFunctionTestWithPartitionParam, IN_PROC_BROWSER_TEST_P(ClearAllCachedAuthTokensFunctionTestWithPartitionParam,
CleanWebAuthFlowCookies) { CleanWebAuthFlowCookies) {
net::CanonicalCookie test_cookie( auto test_cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting(
"test_name", "test_value", "test.com", "/", base::Time(), base::Time(), "test_name", "test_value", "test.com", "/", base::Time(), base::Time(),
base::Time(), true, false, net::CookieSameSite::NO_RESTRICTION, base::Time(), true, false, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_DEFAULT, false); net::COOKIE_PRIORITY_DEFAULT, false);
base::RunLoop set_cookie_loop; base::RunLoop set_cookie_loop;
GetCookieManager()->SetCanonicalCookie( GetCookieManager()->SetCanonicalCookie(
test_cookie, *test_cookie,
net::cookie_util::SimulatedCookieSource(test_cookie, url::kHttpsScheme), net::cookie_util::SimulatedCookieSource(*test_cookie, url::kHttpsScheme),
net::CookieOptions(), net::CookieOptions(),
net::cookie_util::AdaptCookieAccessResultToBool( net::cookie_util::AdaptCookieAccessResultToBool(
base::BindLambdaForTesting([&](bool include) { base::BindLambdaForTesting([&](bool include) {
......
...@@ -44,14 +44,14 @@ net::CookieList GetCookies( ...@@ -44,14 +44,14 @@ net::CookieList GetCookies(
void SetCookie( void SetCookie(
const mojo::Remote<network::mojom::CookieManager>& cookie_manager) { const mojo::Remote<network::mojom::CookieManager>& cookie_manager) {
base::Time t = base::Time::Now(); base::Time t = base::Time::Now();
net::CanonicalCookie cookie( auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting(
kCookieName, kCookieValue, "www.test.com", "/", t, kCookieName, kCookieValue, "www.test.com", "/", t,
t + base::TimeDelta::FromDays(1), base::Time(), true /* secure */, t + base::TimeDelta::FromDays(1), base::Time(), true /* secure */,
false /* http-only*/, net::CookieSameSite::NO_RESTRICTION, false /* http-only*/, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_DEFAULT, false /* same_party */); net::COOKIE_PRIORITY_DEFAULT, false /* same_party */);
base::RunLoop run_loop; base::RunLoop run_loop;
cookie_manager->SetCanonicalCookie( cookie_manager->SetCanonicalCookie(
cookie, net::cookie_util::SimulatedCookieSource(cookie, "https"), *cookie, net::cookie_util::SimulatedCookieSource(*cookie, "https"),
net::CookieOptions(), net::CookieOptions(),
base::BindLambdaForTesting( base::BindLambdaForTesting(
[&](net::CookieAccessResult result) { run_loop.Quit(); })); [&](net::CookieAccessResult result) { run_loop.Quit(); }));
......
...@@ -97,13 +97,14 @@ void RemoveCookieTester::AddCookie(const std::string& host, ...@@ -97,13 +97,14 @@ void RemoveCookieTester::AddCookie(const std::string& host,
waiting_callback_ = true; waiting_callback_ = true;
net::CookieOptions options; net::CookieOptions options;
options.set_include_httponly(); options.set_include_httponly();
net::CanonicalCookie cookie( auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting(
name, value, host, "/", base::Time(), base::Time(), base::Time(), name, value, host, "/", base::Time(), base::Time(), base::Time(),
true /* secure*/, false /* http only*/, true /* secure*/, false /* http only*/,
net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM,
false /* same_party */); false /* same_party */);
cookie_manager_->SetCanonicalCookie( cookie_manager_->SetCanonicalCookie(
cookie, net::cookie_util::SimulatedCookieSource(cookie, "https"), options, *cookie, net::cookie_util::SimulatedCookieSource(*cookie, "https"),
options,
base::BindOnce(&RemoveCookieTester::SetCanonicalCookieCallback, base::BindOnce(&RemoveCookieTester::SetCanonicalCookieCallback,
base::Unretained(this))); base::Unretained(this)));
BlockUntilNotified(); BlockUntilNotified();
......
...@@ -26,7 +26,7 @@ const char kSigninCookieName[] = "SAPISID"; ...@@ -26,7 +26,7 @@ const char kSigninCookieName[] = "SAPISID";
void AddSigninCookie(Profile* profile) { void AddSigninCookie(Profile* profile) {
DCHECK(profile); DCHECK(profile);
net::CanonicalCookie cookie( auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting(
kSigninCookieName, std::string(), ".google.com", "/", kSigninCookieName, std::string(), ".google.com", "/",
/*creation=*/base::Time(), /*creation=*/base::Time(),
/*expires=*/base::Time(), /*last_access=*/base::Time(), /*secure=*/true, /*expires=*/base::Time(), /*last_access=*/base::Time(), /*secure=*/true,
...@@ -41,7 +41,7 @@ void AddSigninCookie(Profile* profile) { ...@@ -41,7 +41,7 @@ void AddSigninCookie(Profile* profile) {
base::RunLoop run_loop; base::RunLoop run_loop;
cookie_manager->SetCanonicalCookie( cookie_manager->SetCanonicalCookie(
cookie, net::cookie_util::SimulatedCookieSource(cookie, "https"), *cookie, net::cookie_util::SimulatedCookieSource(*cookie, "https"),
net::CookieOptions(), net::CookieOptions(),
base::BindLambdaForTesting( base::BindLambdaForTesting(
[&run_loop](net::CookieAccessResult) { run_loop.Quit(); })); [&run_loop](net::CookieAccessResult) { run_loop.Quit(); }));
......
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