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) {
// Sets the APISID Gaia cookie, which is monitored by the AccountReconcilor.
bool SetGaiaCookieForProfile(Profile* profile) {
GURL google_url = GaiaUrls::GetInstance()->secure_google_url();
net::CanonicalCookie cookie(
auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting(
"SAPISID", std::string(), "." + google_url.host(), "/", base::Time(),
base::Time(), base::Time(), true /* secure */, false /* httponly */,
net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT,
......@@ -289,7 +289,7 @@ bool SetGaiaCookieForProfile(Profile* profile) {
network::mojom::CookieManager* cookie_manager =
content::BrowserContext::GetDefaultStoragePartition(profile)
->GetCookieManagerForBrowserProcess();
cookie_manager->SetCanonicalCookie(cookie, google_url,
cookie_manager->SetCanonicalCookie(*cookie, google_url,
net::CookieOptions::MakeAllInclusive(),
std::move(callback));
loop.Run();
......
......@@ -53,10 +53,10 @@ const char kRemoveEverythingArguments[] =
// Sets the SAPISID Gaia cookie, which is monitored by the AccountReconcilor.
bool SetGaiaCookieForProfile(Profile* profile) {
GURL google_url = GaiaUrls::GetInstance()->secure_google_url();
net::CanonicalCookie cookie("SAPISID", std::string(), "." + google_url.host(),
"/", base::Time(), base::Time(), base::Time(),
/*secure=*/true, false,
net::CookieSameSite::NO_RESTRICTION,
auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting(
"SAPISID", std::string(), "." + google_url.host(), "/", base::Time(),
base::Time(), base::Time(),
/*secure=*/true, false, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_DEFAULT, false);
bool success = false;
......@@ -72,7 +72,7 @@ bool SetGaiaCookieForProfile(Profile* profile) {
content::BrowserContext::GetDefaultStoragePartition(profile)
->GetCookieManagerForBrowserProcess();
cookie_manager->SetCanonicalCookie(
cookie, google_url, net::CookieOptions::MakeAllInclusive(),
*cookie, google_url, net::CookieOptions::MakeAllInclusive(),
mojo::WrapCallbackWithDefaultInvokeIfNotRun(
std::move(callback),
net::CookieAccessResult(net::CookieInclusionStatus(
......
......@@ -3661,14 +3661,14 @@ class ClearAllCachedAuthTokensFunctionTestWithPartitionParam
IN_PROC_BROWSER_TEST_P(ClearAllCachedAuthTokensFunctionTestWithPartitionParam,
CleanWebAuthFlowCookies) {
net::CanonicalCookie test_cookie(
auto test_cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting(
"test_name", "test_value", "test.com", "/", base::Time(), base::Time(),
base::Time(), true, false, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_DEFAULT, false);
base::RunLoop set_cookie_loop;
GetCookieManager()->SetCanonicalCookie(
test_cookie,
net::cookie_util::SimulatedCookieSource(test_cookie, url::kHttpsScheme),
*test_cookie,
net::cookie_util::SimulatedCookieSource(*test_cookie, url::kHttpsScheme),
net::CookieOptions(),
net::cookie_util::AdaptCookieAccessResultToBool(
base::BindLambdaForTesting([&](bool include) {
......
......@@ -44,14 +44,14 @@ net::CookieList GetCookies(
void SetCookie(
const mojo::Remote<network::mojom::CookieManager>& cookie_manager) {
base::Time t = base::Time::Now();
net::CanonicalCookie cookie(
auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting(
kCookieName, kCookieValue, "www.test.com", "/", t,
t + base::TimeDelta::FromDays(1), base::Time(), true /* secure */,
false /* http-only*/, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_DEFAULT, false /* same_party */);
base::RunLoop run_loop;
cookie_manager->SetCanonicalCookie(
cookie, net::cookie_util::SimulatedCookieSource(cookie, "https"),
*cookie, net::cookie_util::SimulatedCookieSource(*cookie, "https"),
net::CookieOptions(),
base::BindLambdaForTesting(
[&](net::CookieAccessResult result) { run_loop.Quit(); }));
......
......@@ -97,13 +97,14 @@ void RemoveCookieTester::AddCookie(const std::string& host,
waiting_callback_ = true;
net::CookieOptions options;
options.set_include_httponly();
net::CanonicalCookie cookie(
auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting(
name, value, host, "/", base::Time(), base::Time(), base::Time(),
true /* secure*/, false /* http only*/,
net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM,
false /* same_party */);
cookie_manager_->SetCanonicalCookie(
cookie, net::cookie_util::SimulatedCookieSource(cookie, "https"), options,
*cookie, net::cookie_util::SimulatedCookieSource(*cookie, "https"),
options,
base::BindOnce(&RemoveCookieTester::SetCanonicalCookieCallback,
base::Unretained(this)));
BlockUntilNotified();
......
......@@ -26,7 +26,7 @@ const char kSigninCookieName[] = "SAPISID";
void AddSigninCookie(Profile* profile) {
DCHECK(profile);
net::CanonicalCookie cookie(
auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting(
kSigninCookieName, std::string(), ".google.com", "/",
/*creation=*/base::Time(),
/*expires=*/base::Time(), /*last_access=*/base::Time(), /*secure=*/true,
......@@ -41,7 +41,7 @@ void AddSigninCookie(Profile* profile) {
base::RunLoop run_loop;
cookie_manager->SetCanonicalCookie(
cookie, net::cookie_util::SimulatedCookieSource(cookie, "https"),
*cookie, net::cookie_util::SimulatedCookieSource(*cookie, "https"),
net::CookieOptions(),
base::BindLambdaForTesting(
[&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