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

Get chrome/test:unit_tests to build if CanonicalCookie's constructor is

private.

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

This replaces uses of the constructor with the factory
CreateUnsafeCookieForTesting. This factory is meant for test-only code
and should not be used in production.

Bug: 1102874
Change-Id: I8b9346238b476123eb8aec306f64a58bd8805ba5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2582408Reviewed-by: default avatarLily Chen <chlily@chromium.org>
Reviewed-by: default avatarJoshua Bell <jsbell@chromium.org>
Reviewed-by: default avatarMike West <mkwst@chromium.org>
Commit-Queue: Dylan Cutler <dylancutler@google.com>
Cr-Commit-Position: refs/heads/master@{#836601}
parent 62bb81a1
......@@ -22,15 +22,15 @@ TEST(CookiesHelperUnittest, CookieConversionWithInfiniteExpirationDate) {
// applicable on 32-bit machines, but we can fake it a bit for cross-platform
// testing by just setting the expiration date directly.
const base::Time kExpirationDate = base::Time::Max();
net::CanonicalCookie cookie("cookiename", "cookievalue", "example.com", "/",
base::Time::Now(), kExpirationDate, base::Time(),
false, false, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_DEFAULT, false);
auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting(
"cookiename", "cookievalue", "example.com", "/", base::Time::Now(),
kExpirationDate, base::Time(), false, false,
net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT, false);
// Serialize the cookie to JSON. We need to gracefully handle the infinite
// expiration date, which should be converted to the maximum value.
api::cookies::Cookie serialized_cookie =
cookies_helpers::CreateCookie(cookie, "1");
cookies_helpers::CreateCookie(*cookie, "1");
std::unique_ptr<base::Value> value_cookie = serialized_cookie.ToValue();
ASSERT_TRUE(value_cookie);
base::Value* expiration_time =
......
......@@ -83,11 +83,11 @@ TEST_F(ExtensionCookiesTest, StoreIdProfileConversion) {
}
TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) {
std::unique_ptr<net::CanonicalCookie> canonical_cookie1(
std::make_unique<net::CanonicalCookie>(
std::unique_ptr<net::CanonicalCookie> canonical_cookie1 =
net::CanonicalCookie::CreateUnsafeCookieForTesting(
"ABC", "DEF", "www.example.com", "/", base::Time(), base::Time(),
base::Time(), false, false, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_DEFAULT, false));
net::COOKIE_PRIORITY_DEFAULT, false);
ASSERT_NE(nullptr, canonical_cookie1.get());
Cookie cookie1 =
cookies_helpers::CreateCookie(*canonical_cookie1, "some cookie store");
......@@ -103,12 +103,12 @@ TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) {
EXPECT_FALSE(cookie1.expiration_date.get());
EXPECT_EQ("some cookie store", cookie1.store_id);
std::unique_ptr<net::CanonicalCookie> canonical_cookie2(
std::make_unique<net::CanonicalCookie>(
std::unique_ptr<net::CanonicalCookie> canonical_cookie2 =
net::CanonicalCookie::CreateUnsafeCookieForTesting(
"ABC", "DEF", ".example.com", "/", base::Time(),
base::Time::FromDoubleT(10000), base::Time(), false, false,
net::CookieSameSite::STRICT_MODE, net::COOKIE_PRIORITY_DEFAULT,
false));
false);
ASSERT_NE(nullptr, canonical_cookie2.get());
Cookie cookie2 =
cookies_helpers::CreateCookie(*canonical_cookie2, "some cookie store");
......@@ -128,20 +128,20 @@ TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) {
}
TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) {
std::unique_ptr<net::CanonicalCookie> cookie1(
std::make_unique<net::CanonicalCookie>(
std::unique_ptr<net::CanonicalCookie> cookie1 =
net::CanonicalCookie::CreateUnsafeCookieForTesting(
"ABC", "DEF", ".example.com", "/", base::Time(), base::Time(),
base::Time(), false, false, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_DEFAULT, false));
net::COOKIE_PRIORITY_DEFAULT, false);
ASSERT_NE(nullptr, cookie1.get());
EXPECT_EQ("http://example.com/",
cookies_helpers::GetURLFromCanonicalCookie(*cookie1).spec());
std::unique_ptr<net::CanonicalCookie> cookie2(
std::make_unique<net::CanonicalCookie>(
std::unique_ptr<net::CanonicalCookie> cookie2 =
net::CanonicalCookie::CreateUnsafeCookieForTesting(
"ABC", "DEF", ".helloworld.com", "/", base::Time(), base::Time(),
base::Time(), true, false, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_DEFAULT, false));
net::COOKIE_PRIORITY_DEFAULT, false);
ASSERT_NE(nullptr, cookie2.get());
EXPECT_EQ("https://helloworld.com/",
cookies_helpers::GetURLFromCanonicalCookie(*cookie2).spec());
......@@ -173,12 +173,12 @@ TEST_F(ExtensionCookiesTest, DomainMatching) {
std::unique_ptr<GetAll::Params> params(GetAll::Params::Create(args));
cookies_helpers::MatchFilter filter(&params->details);
std::unique_ptr<net::CanonicalCookie> cookie(
std::make_unique<net::CanonicalCookie>(
std::unique_ptr<net::CanonicalCookie> cookie =
net::CanonicalCookie::CreateUnsafeCookieForTesting(
"name", std::string(), tests[i].domain, "/", base::Time(),
base::Time(), base::Time(), false, false,
net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT,
false));
false);
ASSERT_NE(nullptr, cookie.get());
EXPECT_EQ(tests[i].matches, filter.MatchesCookie(*cookie)) << " test " << i;
}
......
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