From 8e46adc28bf4748265973f3ee899b97a03f50bc4 Mon Sep 17 00:00:00 2001 From: Ari Chivukula Date: Tue, 26 Apr 2022 13:22:01 +0000 Subject: [PATCH] [Cookie Last Update Date] (2) Propagate and populate LastUpdateDate field This CL adds the getters/setters for LastUpdateDate and hooks it into the sqlite from the last CL for the last_update_utc column. https://docs.google.com/document/d/1x7_2wVY2gSEfMlvpS4AoQtN5x7fHG_AsQ01V4CkSELI/edit The important changes are just in a few files: (A) Adding the new cookie field net/cookies/canonical_cookie.h net/cookies/canonical_cookie.cc net/cookies/canonical_cookie_unittest.cc (B) Hooking the field into mojom services/network/public/mojom/cookie_manager.mojom services/network/public/cpp/cookie_manager_mojom_traits.h services/network/public/cpp/cookie_manager_mojom_traits.cc services/network/public/cpp/cookie_manager_mojom_traits_unittest.cc (C) Hooking the field into sqlite: net/extras/sqlite/sqlite_persistent_cookie_store.cc net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc (D) Testing creation date inheritance: net/cookies/cookie_monster_unittest.cc (E) Hooking the field into android: chrome/browser/android/cookies/cookies_fetcher_util.cc chrome/browser/profiles/android/java/src/org/chromium/chrome/browser/cookies/CookiesFetcher.java chrome/browser/profiles/android/java/src/org/chromium/chrome/browser/cookies/CanonicalCookie.java This CL is part of a series: (1) Add last_update_utc field to db (2) Propagate and populate LastUpdateDate field (3) Track cookie refresh delay Bug: 1264458 Change-Id: Id48a13e5f0512ce0406d17d3d09a04b14c1f5190 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3597954 Reviewed-by: Sylvain Defresne Reviewed-by: Steven Bingler Auto-Submit: Ari Chivukula Reviewed-by: Joshua Bell Reviewed-by: Kinuko Yasuda Reviewed-by: David Roger Reviewed-by: Mike West Reviewed-by: Josh Karlin Commit-Queue: Josh Karlin Cr-Commit-Position: refs/heads/main@{#996129} --- .../browser/cookies/CanonicalCookieTest.java | 17 +- .../android/cookies/cookies_fetcher_util.cc | 4 + .../ash/login/webview_login_browsertest.cc | 7 +- .../browsing_data_remover_browsertest_base.cc | 7 +- .../third_party_data_remover_browsertest.cc | 5 +- .../client_hints/client_hints_browsertest.cc | 2 +- .../api/browsing_data/browsing_data_test.cc | 2 +- .../api/cookies/cookies_helpers_unittest.cc | 2 +- .../api/cookies/cookies_unittest.cc | 21 +- .../api/identity/identity_apitest.cc | 4 +- .../net/chrome_network_service_browsertest.cc | 4 +- .../profile_resetter_browsertest.cc | 4 +- .../browser/cookies/CanonicalCookie.java | 13 +- .../browser/cookies/CookiesFetcher.java | 22 +- .../sync/test/integration/cookie_helper.cc | 1 + .../identity_manager_unittest.cc | 8 +- ...ttribution_cookie_checker_impl_unittest.cc | 1 + .../browsing_data_remover_impl_unittest.cc | 5 +- .../browsing_data/browsing_data_test_utils.cc | 2 +- .../same_site_data_remover_impl_unittest.cc | 12 +- .../cookie_store_manager_unittest.cc | 50 +- .../browser/network_service_browsertest.cc | 4 +- google_apis/gaia/oauth_multilogin_result.cc | 3 +- .../gaia/oauth_multilogin_result_unittest.cc | 10 +- ios/net/cookies/cookie_cache_unittest.cc | 4 +- ios/net/cookies/cookie_store_ios_test_util.mm | 1 + ios/net/cookies/system_cookie_util.mm | 3 +- .../cookies/system_cookie_util_unittest.mm | 4 + .../download_session_task_impl_unittest.mm | 1 + net/base/network_delegate_unittest.cc | 9 +- net/cookies/canonical_cookie.cc | 23 +- net/cookies/canonical_cookie.h | 9 +- net/cookies/canonical_cookie_unittest.cc | 442 +++++---- net/cookies/cookie_deletion_info_unittest.cc | 11 + net/cookies/cookie_monster.cc | 4 +- net/cookies/cookie_monster_store_test.cc | 9 +- net/cookies/cookie_monster_unittest.cc | 118 +-- net/cookies/cookie_store_unittest.h | 73 +- net/cookies/cookie_util_unittest.cc | 11 +- .../sqlite/sqlite_persistent_cookie_store.cc | 10 +- ...sqlite_persistent_cookie_store_perftest.cc | 2 +- ...sqlite_persistent_cookie_store_unittest.cc | 124 +-- services/network/cookie_manager.cc | 6 +- services/network/cookie_manager_unittest.cc | 852 +++++++++--------- services/network/cookie_settings_unittest.cc | 7 +- services/network/network_context_unittest.cc | 8 +- .../public/cpp/cookie_manager_mojom_traits.cc | 10 +- .../public/cpp/cookie_manager_mojom_traits.h | 3 + .../cookie_manager_mojom_traits_unittest.cc | 42 +- .../network/public/mojom/cookie_manager.mojom | 1 + services/network/restricted_cookie_manager.cc | 2 +- .../restricted_cookie_manager_unittest.cc | 107 +-- .../session_cleanup_cookie_store_unittest.cc | 4 +- 53 files changed, 1153 insertions(+), 957 deletions(-) diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/cookies/CanonicalCookieTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/cookies/CanonicalCookieTest.java index 7bd5ece492c236..f39e9da3c9a19c 100644 --- a/chrome/android/junit/src/org/chromium/chrome/browser/cookies/CanonicalCookieTest.java +++ b/chrome/android/junit/src/org/chromium/chrome/browser/cookies/CanonicalCookieTest.java @@ -58,6 +58,7 @@ private static void assertCookiesEqual(CanonicalCookie lhs, CanonicalCookie rhs) Assert.assertEquals(lhs.getCreationDate(), rhs.getCreationDate()); Assert.assertEquals(lhs.getExpirationDate(), rhs.getExpirationDate()); Assert.assertEquals(lhs.getLastAccessDate(), rhs.getLastAccessDate()); + Assert.assertEquals(lhs.getLastUpdateDate(), rhs.getLastUpdateDate()); Assert.assertEquals(lhs.isSecure(), rhs.isSecure()); Assert.assertEquals(lhs.isHttpOnly(), rhs.isHttpOnly()); Assert.assertEquals(lhs.getSameSite(), rhs.getSameSite()); @@ -87,16 +88,16 @@ public void testSaveRestoreEmptyList() throws Exception { public void testSaveRestore() throws Exception { ArrayList cookies = new ArrayList<>(); cookies.add(new CanonicalCookie("name", "value", "domain", "path", 0 /* creation */, - 1 /* expiration */, 0 /* lastAccess */, false /* secure */, true /* httpOnly */, - 0 /* sameSite */, 0 /* priority */, false /* same_party */, "" /* partition_key */, - 1 /* sourceScheme */, 72 /* sourcePort */)); + 1 /* expiration */, 0 /* lastAccess */, 0 /* lastUpdate */, false /* secure */, + true /* httpOnly */, 0 /* sameSite */, 0 /* priority */, false /* same_party */, + "" /* partition_key */, 1 /* sourceScheme */, 72 /* sourcePort */)); cookies.add(new CanonicalCookie("name2", "value2", ".domain2", "path2", 10 /* creation */, - 20 /* expiration */, 15 /* lastAccess */, true /* secure */, false /* httpOnly */, - 1 /* sameSite */, 1 /* priority */, true /* same_party */, "" /* partition_key */, - 2 /* sourceScheme */, 445 /* sourcePort */)); + 20 /* expiration */, 15 /* lastAccess */, 15 /* lastUpdate */, true /* secure */, + false /* httpOnly */, 1 /* sameSite */, 1 /* priority */, true /* same_party */, + "" /* partition_key */, 2 /* sourceScheme */, 445 /* sourcePort */)); cookies.add(new CanonicalCookie("name3", "value3", "domain3", "path3", 10 /* creation */, - 20 /* expiration */, 15 /* lastAccess */, true /* secure */, false /* httpOnly */, - 2 /* sameSite */, 2 /* priority */, false /* same_party */, + 20 /* expiration */, 15 /* lastAccess */, 15 /* lastUpdate */, true /* secure */, + false /* httpOnly */, 2 /* sameSite */, 2 /* priority */, false /* same_party */, "https://toplevelsite.com" /* partition_key */, 2 /* sourceScheme */, -1 /* sourcePort */)); diff --git a/chrome/browser/android/cookies/cookies_fetcher_util.cc b/chrome/browser/android/cookies/cookies_fetcher_util.cc index af238812116e70..27ed9e04822fa5 100644 --- a/chrome/browser/android/cookies/cookies_fetcher_util.cc +++ b/chrome/browser/android/cookies/cookies_fetcher_util.cc @@ -53,6 +53,7 @@ void OnCookiesFetchFinished(const net::CookieList& cookies) { i->CreationDate().ToDeltaSinceWindowsEpoch().InMicroseconds(), i->ExpiryDate().ToDeltaSinceWindowsEpoch().InMicroseconds(), i->LastAccessDate().ToDeltaSinceWindowsEpoch().InMicroseconds(), + i->LastUpdateDate().ToDeltaSinceWindowsEpoch().InMicroseconds(), i->IsSecure(), i->IsHttpOnly(), static_cast(i->SameSite()), i->Priority(), i->IsSameParty(), base::android::ConvertUTF8ToJavaString(env, pk), @@ -91,6 +92,7 @@ static void JNI_CookiesFetcher_RestoreCookies( jlong creation, jlong expiration, jlong last_access, + jlong last_update, jboolean secure, jboolean httponly, jint same_site, @@ -121,6 +123,8 @@ static void JNI_CookiesFetcher_RestoreCookies( base::Microseconds(expiration)), base::Time::FromDeltaSinceWindowsEpoch( base::Microseconds(last_access)), + base::Time::FromDeltaSinceWindowsEpoch( + base::Microseconds(last_update)), secure, httponly, static_cast(same_site), static_cast(priority), same_party, pk, static_cast(source_scheme), source_port); diff --git a/chrome/browser/ash/login/webview_login_browsertest.cc b/chrome/browser/ash/login/webview_login_browsertest.cc index 77cfcc8d44036a..c359a89af57d80 100644 --- a/chrome/browser/ash/login/webview_login_browsertest.cc +++ b/chrome/browser/ash/login/webview_login_browsertest.cc @@ -175,9 +175,10 @@ void InjectCookie(content::StoragePartition* storage_partition) { std::unique_ptr cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting( kTestCookieName, kTestCookieValue, kTestCookieHost, "/", base::Time(), - base::Time(), base::Time(), true /* secure */, false /* httponly*/, - net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, - false /* same_party */); + base::Time(), base::Time(), base::Time(), /*secure=*/true, + /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_MEDIUM, + /*same_party=*/false); base::RunLoop run_loop; cookie_manager->SetCanonicalCookie( *cookie, net::cookie_util::SimulatedCookieSource(*cookie, "https"), diff --git a/chrome/browser/browsing_data/browsing_data_remover_browsertest_base.cc b/chrome/browser/browsing_data/browsing_data_remover_browsertest_base.cc index 48cb0a960bb019..6a03db0e9094dd 100644 --- a/chrome/browser/browsing_data/browsing_data_remover_browsertest_base.cc +++ b/chrome/browser/browsing_data/browsing_data_remover_browsertest_base.cc @@ -455,9 +455,10 @@ bool BrowsingDataRemoverBrowserTestBase::SetGaiaCookieForProfile( GURL google_url = GaiaUrls::GetInstance()->secure_google_url(); 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, - false /* same_party */); + base::Time(), base::Time(), base::Time(), /*secure=*/true, + /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_DEFAULT, + /*same_party=*/false); bool success = false; base::RunLoop loop; base::OnceCallback callback = diff --git a/chrome/browser/browsing_data/third_party_data_remover_browsertest.cc b/chrome/browser/browsing_data/third_party_data_remover_browsertest.cc index ecbc32d2948206..ce9d8a11d68e86 100644 --- a/chrome/browser/browsing_data/third_party_data_remover_browsertest.cc +++ b/chrome/browser/browsing_data/third_party_data_remover_browsertest.cc @@ -86,8 +86,9 @@ class ThirdPartyDataRemoverTest : public InProcessBrowserTest { std::unique_ptr cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting( name, "foobar", host, "/", base::Time(), base::Time(), base::Time(), - /* secure= */ true, /* httponly= */ false, same_site, - net::COOKIE_PRIORITY_LOW, /* same_party= */ false); + base::Time(), + /*secure=*/true, /*httponly=*/false, same_site, + net::COOKIE_PRIORITY_LOW, /*same_party=*/false); net::CookieOptions options; options.set_same_site_cookie_context(cookie_context); bool result_out; diff --git a/chrome/browser/client_hints/client_hints_browsertest.cc b/chrome/browser/client_hints/client_hints_browsertest.cc index 5d7769c90901ce..21b2ee0f185019 100644 --- a/chrome/browser/client_hints/client_hints_browsertest.cc +++ b/chrome/browser/client_hints/client_hints_browsertest.cc @@ -5215,7 +5215,7 @@ class PartitionedCookiesOriginTrialBrowserTest : public InProcessBrowserTest { const absl::optional& partition_key) { auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting( name, value, url.host(), "/", base::Time::Now() - base::Days(1), - base::Time::Now() + base::Days(1), base::Time::Now(), + base::Time::Now() + base::Days(1), base::Time::Now(), base::Time::Now(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, net::CookiePriority::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false, diff --git a/chrome/browser/extensions/api/browsing_data/browsing_data_test.cc b/chrome/browser/extensions/api/browsing_data/browsing_data_test.cc index 26351875026564..cebc73b7fc3367 100644 --- a/chrome/browser/extensions/api/browsing_data/browsing_data_test.cc +++ b/chrome/browser/extensions/api/browsing_data/browsing_data_test.cc @@ -57,7 +57,7 @@ bool SetGaiaCookieForProfile(Profile* profile) { GURL google_url = GaiaUrls::GetInstance()->secure_google_url(); auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting( "SAPISID", std::string(), "." + google_url.host(), "/", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/true, false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT, false); diff --git a/chrome/browser/extensions/api/cookies/cookies_helpers_unittest.cc b/chrome/browser/extensions/api/cookies/cookies_helpers_unittest.cc index 54160ed48b0d50..796bacd050b192 100644 --- a/chrome/browser/extensions/api/cookies/cookies_helpers_unittest.cc +++ b/chrome/browser/extensions/api/cookies/cookies_helpers_unittest.cc @@ -24,7 +24,7 @@ TEST(CookiesHelperUnittest, CookieConversionWithInfiniteExpirationDate) { const base::Time kExpirationDate = base::Time::Max(); auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting( "cookiename", "cookievalue", "example.com", "/", base::Time::Now(), - kExpirationDate, base::Time(), false, false, + kExpirationDate, base::Time(), 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 diff --git a/chrome/browser/extensions/api/cookies/cookies_unittest.cc b/chrome/browser/extensions/api/cookies/cookies_unittest.cc index a318fb163dc56a..c2b5547b76fdb1 100644 --- a/chrome/browser/extensions/api/cookies/cookies_unittest.cc +++ b/chrome/browser/extensions/api/cookies/cookies_unittest.cc @@ -93,8 +93,9 @@ TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) { std::unique_ptr 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); + base::Time(), base::Time(), false, false, + net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT, + false); ASSERT_NE(nullptr, canonical_cookie1.get()); Cookie cookie1 = cookies_helpers::CreateCookie(*canonical_cookie1, "some cookie store"); @@ -113,8 +114,8 @@ TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) { std::unique_ptr 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, + base::Time::FromDoubleT(10000), base::Time(), base::Time(), false, + false, net::CookieSameSite::STRICT_MODE, net::COOKIE_PRIORITY_DEFAULT, false); ASSERT_NE(nullptr, canonical_cookie2.get()); Cookie cookie2 = @@ -138,8 +139,9 @@ TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { std::unique_ptr 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); + base::Time(), base::Time(), false, false, + net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT, + false); ASSERT_NE(nullptr, cookie1.get()); EXPECT_EQ("http://example.com/", cookies_helpers::GetURLFromCanonicalCookie(*cookie1).spec()); @@ -147,8 +149,9 @@ TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { std::unique_ptr 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); + base::Time(), base::Time(), true, false, + net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT, + false); ASSERT_NE(nullptr, cookie2.get()); EXPECT_EQ("https://helloworld.com/", cookies_helpers::GetURLFromCanonicalCookie(*cookie2).spec()); @@ -183,7 +186,7 @@ TEST_F(ExtensionCookiesTest, DomainMatching) { std::unique_ptr cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting( "name", std::string(), tests[i].domain, "/", base::Time(), - base::Time(), base::Time(), false, false, + base::Time(), base::Time(), base::Time(), false, false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT, false); ASSERT_NE(nullptr, cookie.get()); diff --git a/chrome/browser/extensions/api/identity/identity_apitest.cc b/chrome/browser/extensions/api/identity/identity_apitest.cc index f290c67b8c8318..469ae5a896a354 100644 --- a/chrome/browser/extensions/api/identity/identity_apitest.cc +++ b/chrome/browser/extensions/api/identity/identity_apitest.cc @@ -3464,8 +3464,8 @@ IN_PROC_BROWSER_TEST_P(ClearAllCachedAuthTokensFunctionTestWithPartitionParam, CleanWebAuthFlowCookies) { 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::Time(), base::Time(), true, false, + net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT, false); base::RunLoop set_cookie_loop; GetCookieManager()->SetCanonicalCookie( *test_cookie, diff --git a/chrome/browser/net/chrome_network_service_browsertest.cc b/chrome/browser/net/chrome_network_service_browsertest.cc index 0a378d7dc7a869..1dd85083392bbd 100644 --- a/chrome/browser/net/chrome_network_service_browsertest.cc +++ b/chrome/browser/net/chrome_network_service_browsertest.cc @@ -59,9 +59,9 @@ void SetCookie(network::mojom::CookieManager* cookie_manager) { base::Time t = base::Time::Now(); auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting( kCookieName, kCookieValue, "www.test.com", "/", t, t + base::Days(1), - base::Time(), true /* secure */, false /* http-only*/, + base::Time(), base::Time(), /*secure=*/true, /*http-only=*/false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT, - false /* same_party */); + /*same_party=*/false); base::RunLoop run_loop; cookie_manager->SetCanonicalCookie( *cookie, net::cookie_util::SimulatedCookieSource(*cookie, "https"), diff --git a/chrome/browser/profile_resetter/profile_resetter_browsertest.cc b/chrome/browser/profile_resetter/profile_resetter_browsertest.cc index f484fd3cbcd06d..2423f6d5ab2080 100644 --- a/chrome/browser/profile_resetter/profile_resetter_browsertest.cc +++ b/chrome/browser/profile_resetter/profile_resetter_browsertest.cc @@ -104,9 +104,9 @@ void RemoveCookieTester::AddCookie(const std::string& host, options.set_include_httponly(); auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting( name, value, host, "/", base::Time(), base::Time(), base::Time(), - true /* secure*/, false /* http only*/, + base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, - false /* same_party */); + /*same_party=*/false); cookie_manager_->SetCanonicalCookie( *cookie, net::cookie_util::SimulatedCookieSource(*cookie, "https"), options, diff --git a/chrome/browser/profiles/android/java/src/org/chromium/chrome/browser/cookies/CanonicalCookie.java b/chrome/browser/profiles/android/java/src/org/chromium/chrome/browser/cookies/CanonicalCookie.java index ec7fac982934f1..77beb17ae0a5f8 100644 --- a/chrome/browser/profiles/android/java/src/org/chromium/chrome/browser/cookies/CanonicalCookie.java +++ b/chrome/browser/profiles/android/java/src/org/chromium/chrome/browser/cookies/CanonicalCookie.java @@ -23,6 +23,7 @@ class CanonicalCookie { private final long mCreation; private final long mExpiration; private final long mLastAccess; + private final long mLastUpdate; private final boolean mSecure; private final boolean mHttpOnly; private final int mSameSite; @@ -34,8 +35,8 @@ class CanonicalCookie { /** Constructs a CanonicalCookie */ CanonicalCookie(String name, String value, String domain, String path, long creation, - long expiration, long lastAccess, boolean secure, boolean httpOnly, int sameSite, - int priority, boolean sameParty, String partitionKey, int sourceScheme, + long expiration, long lastAccess, long lastUpdate, boolean secure, boolean httpOnly, + int sameSite, int priority, boolean sameParty, String partitionKey, int sourceScheme, int sourcePort) { mName = name; mValue = value; @@ -44,6 +45,7 @@ class CanonicalCookie { mCreation = creation; mExpiration = expiration; mLastAccess = lastAccess; + mLastUpdate = lastUpdate; mSecure = secure; mHttpOnly = httpOnly; mSameSite = sameSite; @@ -84,6 +86,11 @@ long getLastAccessDate() { return mLastAccess; } + /** @return Last updated time. */ + long getLastUpdateDate() { + return mLastUpdate; + } + /** @return Expiration time. */ long getExpirationDate() { return mExpiration; @@ -193,6 +200,7 @@ private void saveToStream(DataOutputStream out) throws IOException { out.writeLong(mCreation); out.writeLong(mExpiration); out.writeLong(mLastAccess); + out.writeLong(mLastUpdate); out.writeBoolean(mSecure); out.writeBoolean(mHttpOnly); out.writeInt(mSameSite); @@ -211,6 +219,7 @@ private static CanonicalCookie createFromStream(DataInputStream in) throws IOExc in.readLong(), // creation in.readLong(), // expiration in.readLong(), // last access + in.readLong(), // last update in.readBoolean(), // secure in.readBoolean(), // httponly in.readInt(), // samesite diff --git a/chrome/browser/profiles/android/java/src/org/chromium/chrome/browser/cookies/CookiesFetcher.java b/chrome/browser/profiles/android/java/src/org/chromium/chrome/browser/cookies/CookiesFetcher.java index ac9ba74f673e26..1bc32ed5179b46 100644 --- a/chrome/browser/profiles/android/java/src/org/chromium/chrome/browser/cookies/CookiesFetcher.java +++ b/chrome/browser/profiles/android/java/src/org/chromium/chrome/browser/cookies/CookiesFetcher.java @@ -130,9 +130,9 @@ protected void onPostExecute(List cookies) { CookiesFetcherJni.get().restoreCookies(cookie.getName(), cookie.getValue(), cookie.getDomain(), cookie.getPath(), cookie.getCreationDate(), cookie.getExpirationDate(), cookie.getLastAccessDate(), - cookie.isSecure(), cookie.isHttpOnly(), cookie.getSameSite(), - cookie.getPriority(), cookie.isSameParty(), cookie.getPartitionKey(), - cookie.sourceScheme(), cookie.sourcePort()); + cookie.getLastUpdateDate(), cookie.isSecure(), cookie.isHttpOnly(), + cookie.getSameSite(), cookie.getPriority(), cookie.isSameParty(), + cookie.getPartitionKey(), cookie.sourceScheme(), cookie.sourcePort()); } } }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); @@ -174,12 +174,12 @@ protected Void doInBackground() { @CalledByNative private static CanonicalCookie createCookie(String name, String value, String domain, - String path, long creation, long expiration, long lastAccess, boolean secure, - boolean httpOnly, int sameSite, int priority, boolean sameParty, String partitionKey, - int sourceScheme, int sourcePort) { + String path, long creation, long expiration, long lastAccess, long lastUpdate, + boolean secure, boolean httpOnly, int sameSite, int priority, boolean sameParty, + String partitionKey, int sourceScheme, int sourcePort) { return new CanonicalCookie(name, value, domain, path, creation, expiration, lastAccess, - secure, httpOnly, sameSite, priority, sameParty, partitionKey, sourceScheme, - sourcePort); + lastUpdate, secure, httpOnly, sameSite, priority, sameParty, partitionKey, + sourceScheme, sourcePort); } @CalledByNative @@ -234,8 +234,8 @@ private static CanonicalCookie[] createCookiesArray(int size) { interface Natives { void persistCookies(); void restoreCookies(String name, String value, String domain, String path, long creation, - long expiration, long lastAccess, boolean secure, boolean httpOnly, int sameSite, - int priority, boolean sameParty, String partitionKey, int sourceScheme, - int sourcePort); + long expiration, long lastAccess, long lastUpdate, boolean secure, boolean httpOnly, + int sameSite, int priority, boolean sameParty, String partitionKey, + int sourceScheme, int sourcePort); } } diff --git a/chrome/browser/sync/test/integration/cookie_helper.cc b/chrome/browser/sync/test/integration/cookie_helper.cc index 54e2c8bbe2397a..da7948bfc5faf0 100644 --- a/chrome/browser/sync/test/integration/cookie_helper.cc +++ b/chrome/browser/sync/test/integration/cookie_helper.cc @@ -31,6 +31,7 @@ void AddSigninCookie(Profile* profile) { kSigninCookieName, std::string(), ".google.com", "/", /*creation=*/base::Time(), /*expiration=*/base::Time(), /*last_access=*/base::Time(), + /*last_update=*/base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT, diff --git a/components/signin/public/identity_manager/identity_manager_unittest.cc b/components/signin/public/identity_manager/identity_manager_unittest.cc index a71f5a107468c8..03e336d611276c 100644 --- a/components/signin/public/identity_manager/identity_manager_unittest.cc +++ b/components/signin/public/identity_manager/identity_manager_unittest.cc @@ -2118,8 +2118,8 @@ TEST_F(IdentityManagerTest, CallbackSentOnAccountsCookieDeletedByUserAction) { run_loop.QuitClosure()); auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting( "SAPISID", std::string(), ".google.com", "/", base::Time(), base::Time(), - base::Time(), /*secure=*/true, false, net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_DEFAULT, false); + base::Time(), base::Time(), /*secure=*/true, false, + net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT, false); SimulateCookieDeletedByUser(identity_manager()->GetGaiaCookieManagerService(), *cookie); run_loop.Run(); @@ -2150,8 +2150,8 @@ TEST_F(IdentityManagerTest, OnNetworkInitialized) { // through any mojo pipe. auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting( "SAPISID", std::string(), ".google.com", "/", base::Time(), base::Time(), - base::Time(), /*secure=*/true, false, net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_DEFAULT, false); + base::Time(), base::Time(), /*secure=*/true, false, + net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT, false); test_cookie_manager_ptr->DispatchCookieChange(net::CookieChangeInfo( *cookie, net::CookieAccessResult(), net::CookieChangeCause::EXPLICIT)); run_loop.Run(); diff --git a/content/browser/attribution_reporting/attribution_cookie_checker_impl_unittest.cc b/content/browser/attribution_reporting/attribution_cookie_checker_impl_unittest.cc index 32112a39d8d0c4..31fba27c48eccb 100644 --- a/content/browser/attribution_reporting/attribution_cookie_checker_impl_unittest.cc +++ b/content/browser/attribution_reporting/attribution_cookie_checker_impl_unittest.cc @@ -51,6 +51,7 @@ class AttributionCookieCheckerImplTest : public testing::Test { /*creation=*/base::Time(), /*expiration=*/base::Time(), /*last_access=*/base::Time(), + /*last_update=*/base::Time(), /*secure=*/true, /*httponly=*/params.httponly, /*same_site=*/params.same_site, diff --git a/content/browser/browsing_data/browsing_data_remover_impl_unittest.cc b/content/browser/browsing_data/browsing_data_remover_impl_unittest.cc index 3d118f8ac95862..052c0704f28b16 100644 --- a/content/browser/browsing_data/browsing_data_remover_impl_unittest.cc +++ b/content/browser/browsing_data/browsing_data_remover_impl_unittest.cc @@ -131,8 +131,9 @@ net::CanonicalCookie CreateCookieWithHost(const url::Origin& origin) { std::unique_ptr cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting( "A", "1", origin.host(), "/", base::Time::Now(), base::Time::Now(), - base::Time(), false, false, net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_MEDIUM, false); + base::Time(), base::Time(), false, false, + net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, + false); EXPECT_TRUE(cookie); return *cookie; } diff --git a/content/browser/browsing_data/browsing_data_test_utils.cc b/content/browser/browsing_data/browsing_data_test_utils.cc index 3254f62f67e874..5dd11664c02882 100644 --- a/content/browser/browsing_data/browsing_data_test_utils.cc +++ b/content/browser/browsing_data/browsing_data_test_utils.cc @@ -39,7 +39,7 @@ void CreateCookieForTest( bool result_out; auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting( cookie_name, "1", cookie_domain, "/", base::Time(), base::Time(), - base::Time(), is_cookie_secure, false, same_site, + base::Time(), base::Time(), is_cookie_secure, false, same_site, net::COOKIE_PRIORITY_LOW, false); GetCookieManager(browser_context) ->SetCanonicalCookie( diff --git a/content/browser/browsing_data/same_site_data_remover_impl_unittest.cc b/content/browser/browsing_data/same_site_data_remover_impl_unittest.cc index 52bb4059f108eb..9b02c2b2a59d98 100644 --- a/content/browser/browsing_data/same_site_data_remover_impl_unittest.cc +++ b/content/browser/browsing_data/same_site_data_remover_impl_unittest.cc @@ -237,8 +237,9 @@ TEST_F(SameSiteDataRemoverImplTest, TestCookieRemovalUnaffectedByParameters) { bool result_out = false; auto cookie1 = net::CanonicalCookie::CreateUnsafeCookieForTesting( "TestCookie1", "20", "google.com", "/", base::Time::Now(), base::Time(), - base::Time(), true, true, net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_HIGH, /*same_party=*/true); + base::Time(), base::Time(), true, true, + net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_HIGH, + /*same_party=*/true); cookie_manager->SetCanonicalCookie( *cookie1, net::cookie_util::SimulatedCookieSource(*cookie1, "https"), options, base::BindLambdaForTesting([&](net::CookieAccessResult result) { @@ -256,7 +257,7 @@ TEST_F(SameSiteDataRemoverImplTest, TestCookieRemovalUnaffectedByParameters) { result_out = false; auto cookie2 = net::CanonicalCookie::CreateUnsafeCookieForTesting( "TestCookie2", "10", "gmail.google.com", "/", base::Time(), - base::Time::Max(), base::Time(), false, true, + base::Time::Max(), base::Time(), base::Time(), false, true, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_HIGH, false); cookie_manager->SetCanonicalCookie( *cookie2, net::cookie_util::SimulatedCookieSource(*cookie2, "https"), @@ -380,8 +381,9 @@ TEST_F(SameSiteDataRemoverImplTest, TestDoesNotDeletePartitionedCookies) { bool result_out; auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-partitioned", "1", "www.partitioned.com", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, - net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_LOW, + base::Time(), base::Time(), base::Time(), /*secure=*/true, + /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_LOW, /*same_party=*/false, net::CookiePartitionKey::FromURLForTesting( GURL("https://toplevel.site"))); diff --git a/content/browser/cookie_store/cookie_store_manager_unittest.cc b/content/browser/cookie_store/cookie_store_manager_unittest.cc index 4ab8d95a552ce9..42b05b3b4f93de 100644 --- a/content/browser/cookie_store/cookie_store_manager_unittest.cc +++ b/content/browser/cookie_store/cookie_store_manager_unittest.cc @@ -307,20 +307,22 @@ class CookieStoreManagerTest return SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( name, value, domain, path, base::Time(), base::Time(), base::Time(), - /* secure = */ true, - /* httponly = */ false, net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false)); + base::Time(), + /*secure=*/true, + /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false)); } bool DeleteCookie(const char* name, const char* domain, const char* path) { return SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( - name, /* value = */ "", domain, path, /* creation = */ base::Time(), - /* expiration = */ base::Time::Min(), - /* last_access = */ base::Time(), - /* secure = */ true, /* httponly = */ false, + name, /*value=*/"", domain, path, /*creation=*/base::Time(), + /*expiration=*/base::Time::Min(), + /*last_access=*/base::Time(), + /*last_update=*/base::Time(), + /*secure=*/true, /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT, - /* same_party = */ false)); + /*same_party=*/false)); } // Designates a closure for preparing the cookie store for the current test. @@ -1562,10 +1564,10 @@ TEST_P(CookieStoreManagerTest, HttpOnlyCookieChange) { ASSERT_TRUE( SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( "cookie-name-1", "cookie-value-1", "example.com", "/", base::Time(), - base::Time(), base::Time(), - /* secure = */ true, - /* httponly = */ true, net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false))); + base::Time(), base::Time(), base::Time(), + /*secure=*/true, + /*httponly=*/true, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false))); task_environment_.RunUntilIdle(); EXPECT_EQ(0u, worker_test_helper_->changes().size()); @@ -1573,10 +1575,10 @@ TEST_P(CookieStoreManagerTest, HttpOnlyCookieChange) { ASSERT_TRUE( SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( "cookie-name-2", "cookie-value-2", "example.com", "/", base::Time(), - base::Time(), base::Time(), - /* secure = */ true, - /* httponly = */ false, net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false))); + base::Time(), base::Time(), base::Time(), + /*secure=*/true, + /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false))); task_environment_.RunUntilIdle(); ASSERT_EQ(1u, worker_test_helper_->changes().size()); @@ -1619,10 +1621,10 @@ TEST_P(CookieStoreManagerTest, HttpOnlyCookieChangeLegacy) { ASSERT_TRUE( SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( "cookie-name-1", "cookie-value-1", "legacy.com", "/", base::Time(), - base::Time(), base::Time(), - /* secure = */ false, - /* httponly = */ true, net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false))); + base::Time(), base::Time(), base::Time(), + /*secure=*/false, + /*httponly=*/true, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false))); task_environment_.RunUntilIdle(); EXPECT_EQ(0u, worker_test_helper_->changes().size()); @@ -1630,10 +1632,10 @@ TEST_P(CookieStoreManagerTest, HttpOnlyCookieChangeLegacy) { ASSERT_TRUE( SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( "cookie-name-2", "cookie-value-2", "legacy.com", "/", base::Time(), - base::Time(), base::Time(), - /* secure = */ false, - /* httponly = */ false, net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false))); + base::Time(), base::Time(), base::Time(), + /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false))); task_environment_.RunUntilIdle(); ASSERT_EQ(1u, worker_test_helper_->changes().size()); diff --git a/content/browser/network_service_browsertest.cc b/content/browser/network_service_browsertest.cc index 7c249e4434433e..5e1e56d814e589 100644 --- a/content/browser/network_service_browsertest.cc +++ b/content/browser/network_service_browsertest.cc @@ -748,9 +748,9 @@ void SetCookie( base::Time t = base::Time::Now(); auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting( kCookieName, kCookieValue, "example.test", "/", t, t + base::Days(1), - base::Time(), true /* secure */, false /* http-only*/, + base::Time(), base::Time(), /*secure=*/true, /*http-only=*/false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT, - false /* same_party */); + /*=same_party=*/false); base::RunLoop run_loop; cookie_manager->SetCanonicalCookie( *cookie, net::cookie_util::SimulatedCookieSource(*cookie, "https"), diff --git a/google_apis/gaia/oauth_multilogin_result.cc b/google_apis/gaia/oauth_multilogin_result.cc index a9d97df8aac776..424c12abc2226f 100644 --- a/google_apis/gaia/oauth_multilogin_result.cc +++ b/google_apis/gaia/oauth_multilogin_result.cc @@ -129,7 +129,8 @@ void OAuthMultiloginResult::TryParseCookiesFromValue(base::Value* json_value) { name ? *name : "", value ? *value : "", cookie_domain, path ? *path : "", /*creation=*/base::Time::Now(), base::Time::Now() + before_expiration, - /*last_access=*/base::Time::Now(), is_secure.value_or(true), + /*last_access=*/base::Time::Now(), + /*last_update=*/base::Time::Now(), is_secure.value_or(true), is_http_only.value_or(true), samesite_mode, net::StringToCookiePriority(priority ? *priority : "medium"), same_party_bool, /*partition_key=*/absl::nullopt, diff --git a/google_apis/gaia/oauth_multilogin_result_unittest.cc b/google_apis/gaia/oauth_multilogin_result_unittest.cc index 3f9a9f32de0060..45d1f7b40830e2 100644 --- a/google_apis/gaia/oauth_multilogin_result_unittest.cc +++ b/google_apis/gaia/oauth_multilogin_result_unittest.cc @@ -97,24 +97,24 @@ TEST(OAuthMultiloginResultTest, TryParseCookiesFromValue) { const std::vector cookies = { *CanonicalCookie::CreateUnsafeCookieForTesting( "SID", "vAlUe1", ".google.ru", "/", time_now, time_now, - expiration_time, /*secure=*/true, + expiration_time, time_now, /*secure=*/true, /*httponly=*/false, net::CookieSameSite::UNSPECIFIED, net::CookiePriority::COOKIE_PRIORITY_HIGH, /*same_party=*/false), *CanonicalCookie::CreateUnsafeCookieForTesting( "SAPISID", "vAlUe2", "google.com", "/", time_now, time_now, - expiration_time, /*secure=*/false, + expiration_time, time_now, /*secure=*/false, /*httponly=*/true, net::CookieSameSite::LAX_MODE, net::CookiePriority::COOKIE_PRIORITY_HIGH, /*same_party=*/false), *CanonicalCookie::CreateUnsafeCookieForTesting( - "HSID", "vAlUe4", "", "/", time_now, time_now, time_now, + "HSID", "vAlUe4", "", "/", time_now, time_now, time_now, time_now, /*secure=*/true, /*httponly=*/true, net::CookieSameSite::STRICT_MODE, net::CookiePriority::COOKIE_PRIORITY_HIGH, /*same_party=*/false), *CanonicalCookie::CreateUnsafeCookieForTesting( "__Secure-1PSID", "vAlUe4", ".google.fr", "/", time_now, time_now, - expiration_time, /*secure=*/true, /*httponly=*/true, + expiration_time, time_now, /*secure=*/true, /*httponly=*/true, net::CookieSameSite::UNSPECIFIED, net::CookiePriority::COOKIE_PRIORITY_HIGH, /*same_party=*/true)}; @@ -186,6 +186,8 @@ TEST(OAuthMultiloginResultTest, TryParseCookiesFromValue) { DoubleNear(now, 0.5)); EXPECT_THAT(result.cookies()[0].ExpiryDate().ToDoubleT(), DoubleNear(expiration, 0.5)); + EXPECT_THAT(result.cookies()[0].LastUpdateDate().ToDoubleT(), + DoubleNear(now, 0.5)); } TEST(OAuthMultiloginResultTest, CreateOAuthMultiloginResultFromString) { diff --git a/ios/net/cookies/cookie_cache_unittest.cc b/ios/net/cookies/cookie_cache_unittest.cc index deae7573483671..6faecaa6da25d9 100644 --- a/ios/net/cookies/cookie_cache_unittest.cc +++ b/ios/net/cookies/cookie_cache_unittest.cc @@ -20,8 +20,8 @@ CanonicalCookie MakeCookie(const GURL& url, const std::string& value) { return *CanonicalCookie::CreateUnsafeCookieForTesting( name, value, url.host(), url.path(), base::Time(), base::Time(), - base::Time(), false, false, net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_DEFAULT, false); + base::Time(), base::Time(), false, false, + net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT, false); } } // namespace diff --git a/ios/net/cookies/cookie_store_ios_test_util.mm b/ios/net/cookies/cookie_store_ios_test_util.mm index 907e0806b66086..79169a42967d4d 100644 --- a/ios/net/cookies/cookie_store_ios_test_util.mm +++ b/ios/net/cookies/cookie_store_ios_test_util.mm @@ -49,6 +49,7 @@ base::Time(), // creation base::Time(), // expires base::Time(), // last accessed + base::Time(), // last updated false, // secure false, // httponly net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT, diff --git a/ios/net/cookies/system_cookie_util.mm b/ios/net/cookies/system_cookie_util.mm index 60b3ca6000fe6d..ff0db985f3d3ff 100644 --- a/ios/net/cookies/system_cookie_util.mm +++ b/ios/net/cookies/system_cookie_util.mm @@ -56,7 +56,8 @@ base::SysNSStringToUTF8([cookie domain]), base::SysNSStringToUTF8([cookie path]), ceation_time, base::Time::FromDoubleT([[cookie expiresDate] timeIntervalSince1970]), - base::Time(), [cookie isSecure], [cookie isHTTPOnly], same_site, + base::Time(), base::Time(), [cookie isSecure], [cookie isHTTPOnly], + same_site, // When iOS begins to support 'Priority' and 'SameParty' attributes, pass // them through here. net::COOKIE_PRIORITY_DEFAULT, false /* SameParty */, diff --git a/ios/net/cookies/system_cookie_util_unittest.mm b/ios/net/cookies/system_cookie_util_unittest.mm index 85ce992ebb29e1..f38b1e3b20e728 100644 --- a/ios/net/cookies/system_cookie_util_unittest.mm +++ b/ios/net/cookies/system_cookie_util_unittest.mm @@ -44,6 +44,7 @@ void CheckSystemCookie(const base::Time& expires, bool secure, bool httponly) { base::Time(), // creation expires, base::Time(), // last_access + base::Time(), // last_update secure, httponly, same_site, net::COOKIE_PRIORITY_DEFAULT, false /* same_party */); // Convert it to system cookie. @@ -198,6 +199,7 @@ void VerifyGetCookiesResultHistogram( base::Time(), // creation base::Time(), // expires base::Time(), // last_access + base::Time(), // last_update false, // secure false, // httponly net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT, @@ -216,6 +218,7 @@ void VerifyGetCookiesResultHistogram( base::Time(), // creation expire_date, base::Time(), // last_access + base::Time(), // last_update false, // secure false, // httponly net::CookieSameSite::UNSPECIFIED, net::COOKIE_PRIORITY_DEFAULT, @@ -225,6 +228,7 @@ void VerifyGetCookiesResultHistogram( base::Time(), // creation expire_date, base::Time(), // last_access + base::Time(), // last_update false, // secure false, // httponly net::CookieSameSite::UNSPECIFIED, net::COOKIE_PRIORITY_DEFAULT, diff --git a/ios/web/download/download_session_task_impl_unittest.mm b/ios/web/download/download_session_task_impl_unittest.mm index 81a84b86fea47c..c300b6b3934170 100644 --- a/ios/web/download/download_session_task_impl_unittest.mm +++ b/ios/web/download/download_session_task_impl_unittest.mm @@ -515,6 +515,7 @@ void SimulateDownloadCompletion(CRWFakeNSURLSessionTask* session_task, /*creation=*/now, /*expire_date=*/now + base::Hours(2), /*last_access=*/now, + /*last_update=*/now, /*secure=*/false, /*httponly=*/false, net::CookieSameSite::UNSPECIFIED, net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false); diff --git a/net/base/network_delegate_unittest.cc b/net/base/network_delegate_unittest.cc index f9fcf8a0f0b7bb..733cff80b8bf54 100644 --- a/net/base/network_delegate_unittest.cc +++ b/net/base/network_delegate_unittest.cc @@ -22,10 +22,11 @@ constexpr char kURL[] = "example.test"; CanonicalCookie MakeCookie(const std::string& name) { return *CanonicalCookie::CreateUnsafeCookieForTesting( - name, "value", kURL, "/" /* path */, base::Time() /* creation */, - base::Time() /* expiration */, base::Time() /* last_access */, - true /* secure */, false /* httponly */, CookieSameSite::UNSPECIFIED, - CookiePriority::COOKIE_PRIORITY_DEFAULT, false /* same_party */); + name, "value", kURL, /*path=*/"/", /*creation=*/base::Time(), + /*expiration=*/base::Time(), /*last_access=*/base::Time(), + /*last_update=*/base::Time(), + /*secure=*/true, /*httponly=*/false, CookieSameSite::UNSPECIFIED, + CookiePriority::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false); } CookieAccessResult Include() { diff --git a/net/cookies/canonical_cookie.cc b/net/cookies/canonical_cookie.cc index 5b1f48dc9b107a..845c57d708055e 100644 --- a/net/cookies/canonical_cookie.cc +++ b/net/cookies/canonical_cookie.cc @@ -408,6 +408,7 @@ CanonicalCookie::CanonicalCookie( base::Time creation, base::Time expiration, base::Time last_access, + base::Time last_update, bool secure, bool httponly, CookieSameSite same_site, @@ -423,6 +424,7 @@ CanonicalCookie::CanonicalCookie( creation_date_(creation), expiry_date_(expiration), last_access_date_(last_access), + last_update_date_(last_update), secure_(secure), httponly_(httponly), same_site_(same_site), @@ -625,7 +627,8 @@ std::unique_ptr CanonicalCookie::Create( std::unique_ptr cc = base::WrapUnique(new CanonicalCookie( parsed_cookie.Name(), parsed_cookie.Value(), cookie_domain, cookie_path, - creation_time, cookie_expires, creation_time, parsed_cookie.IsSecure(), + creation_time, cookie_expires, creation_time, + /*last_update=*/base::Time::Now(), parsed_cookie.IsSecure(), parsed_cookie.IsHttpOnly(), samesite, parsed_cookie.Priority(), parsed_cookie.IsSameParty(), cookie_partition_key, source_scheme, source_port)); @@ -812,8 +815,9 @@ std::unique_ptr CanonicalCookie::CreateSanitizedCookie( std::unique_ptr cc = base::WrapUnique(new CanonicalCookie( name, value, cookie_domain, encoded_cookie_path, creation_time, - expiration_time, last_access_time, secure, http_only, same_site, priority, - same_party, partition_key, source_scheme, source_port)); + expiration_time, last_access_time, /*last_update=*/base::Time::Now(), + secure, http_only, same_site, priority, same_party, partition_key, + source_scheme, source_port)); DCHECK(cc->IsCanonical()); return cc; @@ -828,6 +832,7 @@ std::unique_ptr CanonicalCookie::FromStorage( base::Time creation, base::Time expiration, base::Time last_access, + base::Time last_update, bool secure, bool httponly, CookieSameSite same_site, @@ -846,8 +851,9 @@ std::unique_ptr CanonicalCookie::FromStorage( std::unique_ptr cc = base::WrapUnique(new CanonicalCookie( std::move(name), std::move(value), std::move(domain), std::move(path), - creation, expiration, last_access, secure, httponly, same_site, priority, - same_party, partition_key, source_scheme, validated_port)); + creation, expiration, last_access, last_update, secure, httponly, + same_site, priority, same_party, partition_key, source_scheme, + validated_port)); if (cc->IsCanonicalForFromStorage()) { // This will help capture the number of times a cookie is canonical but does @@ -871,6 +877,7 @@ std::unique_ptr CanonicalCookie::CreateUnsafeCookieForTesting( const base::Time& creation, const base::Time& expiration, const base::Time& last_access, + const base::Time& last_update, bool secure, bool httponly, CookieSameSite same_site, @@ -880,9 +887,9 @@ std::unique_ptr CanonicalCookie::CreateUnsafeCookieForTesting( CookieSourceScheme source_scheme, int source_port) { return base::WrapUnique(new CanonicalCookie( - name, value, domain, path, creation, expiration, last_access, secure, - httponly, same_site, priority, same_party, partition_key, source_scheme, - source_port)); + name, value, domain, path, creation, expiration, last_access, last_update, + secure, httponly, same_site, priority, same_party, partition_key, + source_scheme, source_port)); } std::string CanonicalCookie::DomainWithoutDot() const { diff --git a/net/cookies/canonical_cookie.h b/net/cookies/canonical_cookie.h index 19acf0a8821d72..f954be2405fbf6 100644 --- a/net/cookies/canonical_cookie.h +++ b/net/cookies/canonical_cookie.h @@ -138,6 +138,7 @@ class NET_EXPORT CanonicalCookie { base::Time creation, base::Time expiration, base::Time last_access, + base::Time last_update, bool secure, bool httponly, CookieSameSite same_site, @@ -157,6 +158,7 @@ class NET_EXPORT CanonicalCookie { const base::Time& creation, const base::Time& expiration, const base::Time& last_access, + const base::Time& last_update, bool secure, bool httponly, CookieSameSite same_site, @@ -181,9 +183,10 @@ class NET_EXPORT CanonicalCookie { const std::string& Domain() const { return domain_; } const std::string& Path() const { return path_; } const base::Time& CreationDate() const { return creation_date_; } + const base::Time& ExpiryDate() const { return expiry_date_; } const base::Time& LastAccessDate() const { return last_access_date_; } + const base::Time& LastUpdateDate() const { return last_update_date_; } bool IsPersistent() const { return !expiry_date_.is_null(); } - const base::Time& ExpiryDate() const { return expiry_date_; } bool IsSecure() const { return secure_; } bool IsHttpOnly() const { return httponly_; } CookieSameSite SameSite() const { return same_site_; } @@ -286,7 +289,7 @@ class NET_EXPORT CanonicalCookie { priority_ == other.priority_ && same_party_ == other.same_party_ && partition_key_ == other.partition_key_ && name_ == other.name_ && value_ == other.value_ && domain_ == other.domain_ && - path_ == other.path_; + path_ == other.path_ && last_update_date_ == other.last_update_date_; } void SetSourceScheme(CookieSourceScheme source_scheme) { @@ -435,6 +438,7 @@ class NET_EXPORT CanonicalCookie { base::Time creation, base::Time expiration, base::Time last_access, + base::Time last_update, bool secure, bool httponly, CookieSameSite same_site, @@ -519,6 +523,7 @@ class NET_EXPORT CanonicalCookie { base::Time creation_date_; base::Time expiry_date_; base::Time last_access_date_; + base::Time last_update_date_; bool secure_{false}; bool httponly_{false}; CookieSameSite same_site_{CookieSameSite::NO_RESTRICTION}; diff --git a/net/cookies/canonical_cookie_unittest.cc b/net/cookies/canonical_cookie_unittest.cc index 7d8a0151548811..9cef2f4ab84f13 100644 --- a/net/cookies/canonical_cookie_unittest.cc +++ b/net/cookies/canonical_cookie_unittest.cc @@ -74,7 +74,7 @@ TEST(CanonicalCookieTest, Constructor) { // CreateUnsafeCookieForTesting just forwards to the constructor. auto cookie1 = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", "www.example.com", "/test", current_time, base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, + base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false, absl::nullopt, CookieSourceScheme::kSecure, 443); EXPECT_EQ("A", cookie1->Name()); @@ -92,7 +92,7 @@ TEST(CanonicalCookieTest, Constructor) { auto cookie2 = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", ".www.example.com", "/", current_time, base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, + base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, true, CookiePartitionKey::FromURLForTesting(GURL("https://foo.com")), CookieSourceScheme::kNonSecure, 65536); @@ -115,15 +115,15 @@ TEST(CanonicalCookieTest, Constructor) { // Set Secure to true but don't specify source_scheme or port. auto cookie3 = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", ".www.example.com", "/", current_time, base::Time(), - base::Time(), true /* secure */, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_DEFAULT, false); + base::Time(), base::Time(), true /* secure */, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false); EXPECT_TRUE(cookie3->IsSecure()); EXPECT_EQ(cookie3->SourceScheme(), CookieSourceScheme::kUnset); EXPECT_EQ(cookie3->SourcePort(), url::PORT_UNSPECIFIED); auto cookie4 = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", ".www.example.com", "/test", current_time, base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, + base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false); EXPECT_EQ("A", cookie4->Name()); EXPECT_EQ("2", cookie4->Value()); @@ -140,17 +140,17 @@ TEST(CanonicalCookieTest, Constructor) { // Test some port edge cases: unspecified. auto cookie5 = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", ".www.example.com", "/", current_time, base::Time(), - base::Time(), true /* secure */, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_DEFAULT, false, absl::nullopt, CookieSourceScheme::kUnset, - url::PORT_UNSPECIFIED); + base::Time(), base::Time(), true /* secure */, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false, + absl::nullopt, CookieSourceScheme::kUnset, url::PORT_UNSPECIFIED); EXPECT_EQ(cookie5->SourcePort(), url::PORT_UNSPECIFIED); // Test some port edge cases: invalid. auto cookie6 = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", ".www.example.com", "/", current_time, base::Time(), - base::Time(), true /* secure */, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_DEFAULT, false, absl::nullopt, CookieSourceScheme::kUnset, - url::PORT_INVALID); + base::Time(), base::Time(), true /* secure */, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false, + absl::nullopt, CookieSourceScheme::kUnset, url::PORT_INVALID); EXPECT_EQ(cookie6->SourcePort(), url::PORT_INVALID); } @@ -797,18 +797,19 @@ TEST_P(CanonicalCookieWithClampingTest, CreateWithExpires) { // Expires in the far future using CreateUnsafeCookieForTesting. cookie = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "1", url.host(), url.path(), creation_time, base::Time::Max(), - base::Time(), true, false, CookieSameSite::UNSPECIFIED, + base::Time(), base::Time(), true, false, CookieSameSite::UNSPECIFIED, COOKIE_PRIORITY_HIGH, false, absl::nullopt /* cookie_partition_key */, CookieSourceScheme::kSecure, 443); EXPECT_TRUE(cookie.get()); EXPECT_TRUE(cookie->IsPersistent()); EXPECT_FALSE(cookie->IsExpired(creation_time)); EXPECT_EQ(base::Time::Max(), cookie->ExpiryDate()); + EXPECT_EQ(base::Time(), cookie->LastUpdateDate()); // Expires in the far future using FromStorage. cookie = CanonicalCookie::FromStorage( "A", "B", "www.foo.com", "/bar", creation_time, base::Time::Max(), - base::Time(), false /*secure*/, false /*httponly*/, + base::Time(), base::Time(), false /*secure*/, false /*httponly*/, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false /*same_party*/, absl::nullopt /*partition_key*/, CookieSourceScheme::kSecure, 443); @@ -816,6 +817,7 @@ TEST_P(CanonicalCookieWithClampingTest, CreateWithExpires) { EXPECT_TRUE(cookie->IsPersistent()); EXPECT_FALSE(cookie->IsExpired(creation_time)); EXPECT_EQ(base::Time::Max(), cookie->ExpiryDate()); + EXPECT_EQ(base::Time(), cookie->LastUpdateDate()); } TEST(CanonicalCookieTest, EmptyExpiry) { @@ -852,6 +854,54 @@ TEST(CanonicalCookieTest, EmptyExpiry) { EXPECT_EQ(base::Time(), cookie->ExpiryDate()); } +TEST_P(CanonicalCookieWithClampingTest, CreateWithLastUpdate) { + GURL url("http://www.example.com/test/foo.html"); + base::Time creation_time = base::Time::Now() - base::Days(1); + base::Time last_update_time = base::Time::Now() - base::Hours(1); + absl::optional server_time = absl::nullopt; + + // Creating a cookie sets the last update date as now. + std::unique_ptr cookie = + CanonicalCookie::Create(url, "A=1", creation_time, server_time, + /*cookie_partition_key=*/absl::nullopt); + ASSERT_TRUE(cookie.get()); + EXPECT_TRUE((base::Time::Now() - cookie->LastUpdateDate()).magnitude() < + base::Seconds(1)); + + // Creating a sanitized cookie sets the last update date as now. + cookie = CanonicalCookie::CreateSanitizedCookie( + url, "A", "1", url.host(), url.path(), creation_time, base::Time(), + creation_time, /*secure=*/true, + /*http_only=*/false, CookieSameSite::NO_RESTRICTION, + COOKIE_PRIORITY_DEFAULT, /*same_party=*/false, + /*partition_key=*/absl::nullopt); + ASSERT_TRUE(cookie.get()); + EXPECT_TRUE((base::Time::Now() - cookie->LastUpdateDate()).magnitude() < + base::Seconds(1)); + + // Creating an unsafe cookie allows us to set the last update date. + cookie = CanonicalCookie::CreateUnsafeCookieForTesting( + "A", "1", url.host(), url.path(), creation_time, base::Time(), + base::Time(), last_update_time, /*secure=*/true, + /*httponly=*/false, CookieSameSite::NO_RESTRICTION, + COOKIE_PRIORITY_DEFAULT, /*same_party=*/false, + /*partition_key=*/absl::nullopt, CookieSourceScheme::kSecure, + /*source_port=*/443); + ASSERT_TRUE(cookie.get()); + EXPECT_EQ(last_update_time, cookie->LastUpdateDate()); + + // Loading a cookie from storage allows us to set the last update date. + cookie = CanonicalCookie::FromStorage( + "A", "1", url.host(), url.path(), creation_time, base::Time(), + base::Time(), last_update_time, /*secure=*/true, + /*httponly=*/false, CookieSameSite::NO_RESTRICTION, + COOKIE_PRIORITY_DEFAULT, /*same_party=*/false, + /*partition_key=*/absl::nullopt, CookieSourceScheme::kSecure, + /*source_port=*/443); + ASSERT_TRUE(cookie.get()); + EXPECT_EQ(last_update_time, cookie->LastUpdateDate()); +} + TEST(CanonicalCookieTest, IsEquivalent) { GURL url("https://www.example.com/"); std::string cookie_name = "A"; @@ -860,6 +910,7 @@ TEST(CanonicalCookieTest, IsEquivalent) { std::string cookie_path = "/path"; base::Time creation_time = base::Time::Now(); base::Time expiration_time = creation_time + base::Days(2); + base::Time update_time = creation_time + base::Days(1); bool secure = false; bool httponly = false; CookieSameSite same_site = CookieSameSite::NO_RESTRICTION; @@ -868,7 +919,7 @@ TEST(CanonicalCookieTest, IsEquivalent) { // Test that a cookie is equivalent to itself. auto cookie = CanonicalCookie::CreateUnsafeCookieForTesting( cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, - expiration_time, base::Time(), secure, httponly, same_site, + expiration_time, base::Time(), update_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM, same_party); EXPECT_TRUE(cookie->IsEquivalent(*cookie)); EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*cookie)); @@ -876,7 +927,7 @@ TEST(CanonicalCookieTest, IsEquivalent) { // Test that two identical cookies are equivalent. auto other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, - expiration_time, base::Time(), secure, httponly, same_site, + expiration_time, base::Time(), update_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM, same_party); EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); @@ -885,7 +936,7 @@ TEST(CanonicalCookieTest, IsEquivalent) { // DON'T affect cookie equivalence. other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( cookie_name, "2", cookie_domain, cookie_path, creation_time, - expiration_time, base::Time(), secure, httponly, same_site, + expiration_time, base::Time(), update_time, secure, httponly, same_site, COOKIE_PRIORITY_HIGH, same_party); EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); @@ -894,7 +945,7 @@ TEST(CanonicalCookieTest, IsEquivalent) { base::Time other_creation_time = creation_time + base::Minutes(2); other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( cookie_name, "2", cookie_domain, cookie_path, other_creation_time, - expiration_time, base::Time(), secure, httponly, same_site, + expiration_time, base::Time(), update_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM, same_party); EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); @@ -902,7 +953,7 @@ TEST(CanonicalCookieTest, IsEquivalent) { other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, - expiration_time, base::Time(), true, httponly, same_site, + expiration_time, base::Time(), update_time, true, httponly, same_site, COOKIE_PRIORITY_LOW, same_party); EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); @@ -910,7 +961,7 @@ TEST(CanonicalCookieTest, IsEquivalent) { other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, - expiration_time, base::Time(), secure, true, same_site, + expiration_time, base::Time(), update_time, secure, true, same_site, COOKIE_PRIORITY_LOW, same_party); EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); @@ -918,16 +969,26 @@ TEST(CanonicalCookieTest, IsEquivalent) { other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, - expiration_time, base::Time(), secure, httponly, + expiration_time, base::Time(), update_time, secure, httponly, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_LOW, same_party); EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); + // Test the effect of a differing last_update_time on equivalency. + other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( + cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, + expiration_time, base::Time(), base::Time(), secure, httponly, same_site, + COOKIE_PRIORITY_LOW, same_party); + EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); + EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); + EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); + EXPECT_FALSE(cookie->HasEquivalentDataMembers(*other_cookie)); + // Cookies whose names mismatch are not equivalent. other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( "B", cookie_value, cookie_domain, cookie_path, creation_time, - expiration_time, base::Time(), secure, httponly, same_site, + expiration_time, base::Time(), update_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM, same_party); EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); @@ -938,7 +999,7 @@ TEST(CanonicalCookieTest, IsEquivalent) { // rules of 'IsEquivalentForSecureCookieMatching'. other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( cookie_name, cookie_value, "www.example.com", cookie_path, creation_time, - expiration_time, base::Time(), secure, httponly, same_site, + expiration_time, base::Time(), update_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM, same_party); EXPECT_TRUE(cookie->IsDomainCookie()); EXPECT_FALSE(other_cookie->IsDomainCookie()); @@ -950,7 +1011,7 @@ TEST(CanonicalCookieTest, IsEquivalent) { // 'www.example.com', but they are equivalent for secure cookie matching. other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( cookie_name, cookie_value, ".example.com", cookie_path, creation_time, - expiration_time, base::Time(), secure, httponly, same_site, + expiration_time, base::Time(), update_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM, same_party); EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); @@ -963,7 +1024,7 @@ TEST(CanonicalCookieTest, IsEquivalent) { // equivalent for secure cookie matching to |other_cookie| set on '/'. other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( cookie_name, cookie_value, cookie_domain, "/test", creation_time, - expiration_time, base::Time(), secure, httponly, same_site, + expiration_time, base::Time(), update_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM, same_party); EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); @@ -971,8 +1032,8 @@ TEST(CanonicalCookieTest, IsEquivalent) { other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( cookie_name, cookie_value, cookie_domain, cookie_path + "/subpath", - creation_time, expiration_time, base::Time(), secure, httponly, same_site, - COOKIE_PRIORITY_MEDIUM, same_party); + creation_time, expiration_time, base::Time(), update_time, secure, + httponly, same_site, COOKIE_PRIORITY_MEDIUM, same_party); EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); // The path comparison is asymmetric EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); @@ -980,7 +1041,7 @@ TEST(CanonicalCookieTest, IsEquivalent) { other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( cookie_name, cookie_value, cookie_domain, "/", creation_time, - expiration_time, base::Time(), secure, httponly, same_site, + expiration_time, base::Time(), update_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM, same_party); EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); @@ -989,7 +1050,7 @@ TEST(CanonicalCookieTest, IsEquivalent) { // Partitioned cookies are not equivalent to unpartitioned cookies. other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, - expiration_time, base::Time(), secure, httponly, same_site, + expiration_time, base::Time(), update_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM, same_party, CookiePartitionKey::FromURLForTesting(GURL("https://foo.com"))); EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); @@ -998,7 +1059,7 @@ TEST(CanonicalCookieTest, IsEquivalent) { // Partitioned cookies are equal if they have the same partition key. auto paritioned_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, - expiration_time, base::Time(), secure, httponly, same_site, + expiration_time, base::Time(), update_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM, same_party, CookiePartitionKey::FromURLForTesting(GURL("https://foo.com"))); EXPECT_TRUE(paritioned_cookie->IsEquivalent(*other_cookie)); @@ -1008,7 +1069,7 @@ TEST(CanonicalCookieTest, IsEquivalent) { // Partitioned cookies with different partition keys are not equal other_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, - expiration_time, base::Time(), secure, httponly, same_site, + expiration_time, base::Time(), update_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM, same_party, CookiePartitionKey::FromURLForTesting(GURL("https://bar.com"))); EXPECT_FALSE(paritioned_cookie->IsEquivalent(*other_cookie)); @@ -1073,14 +1134,15 @@ TEST(CanonicalCookieTest, IsEquivalentForSecureCookieMatching) { for (auto test : kTests) { auto cookie = CanonicalCookie::CreateUnsafeCookieForTesting( test.cookie.name, "value1", test.cookie.domain, test.cookie.path, - base::Time(), base::Time(), base::Time(), false /* secure */, - false /* httponly */, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_MEDIUM, - false /* sameparty */, test.cookie.cookie_partition_key); + base::Time(), base::Time(), base::Time(), base::Time(), + false /* secure */, false /* httponly */, CookieSameSite::LAX_MODE, + COOKIE_PRIORITY_MEDIUM, false /* sameparty */, + test.cookie.cookie_partition_key); auto secure_cookie = CanonicalCookie::CreateUnsafeCookieForTesting( test.secure_cookie.name, "value2", test.secure_cookie.domain, test.secure_cookie.path, base::Time(), base::Time(), base::Time(), - true /* secure */, false /* httponly */, CookieSameSite::LAX_MODE, - COOKIE_PRIORITY_MEDIUM, false /* sameparty */, + base::Time(), true /* secure */, false /* httponly */, + CookieSameSite::LAX_MODE, COOKIE_PRIORITY_MEDIUM, false /* sameparty */, test.secure_cookie.cookie_partition_key); EXPECT_EQ(test.equivalent, @@ -1194,25 +1256,25 @@ TEST(CanonicalCookieTest, GetEffectiveSameSite) { // Recent session cookie. cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", "example.test", "/", recent_creation_time, base::Time(), - base::Time(), true /* secure */, false /* httponly */, test.same_site, - COOKIE_PRIORITY_DEFAULT, false)); + base::Time(), base::Time(), true /* secure */, false /* httponly */, + test.same_site, COOKIE_PRIORITY_DEFAULT, false)); // Recent persistent cookie. cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", "example.test", "/", recent_creation_time, expiry_time, - base::Time(), true /* secure */, false /* httponly */, test.same_site, - COOKIE_PRIORITY_DEFAULT, false)); + base::Time(), base::Time(), true /* secure */, false /* httponly */, + test.same_site, COOKIE_PRIORITY_DEFAULT, false)); } if (!test.is_cookie_recent.has_value() || !(*test.is_cookie_recent)) { // Not-recent session cookie. cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", "example.test", "/", not_recent_creation_time, base::Time(), - base::Time(), true /* secure */, false /* httponly */, test.same_site, - COOKIE_PRIORITY_DEFAULT, false)); + base::Time(), base::Time(), true /* secure */, false /* httponly */, + test.same_site, COOKIE_PRIORITY_DEFAULT, false)); // Not-recent persistent cookie. cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", "example.test", "/", not_recent_creation_time, expiry_time, - base::Time(), true /* secure */, false /* httponly */, test.same_site, - COOKIE_PRIORITY_DEFAULT, false)); + base::Time(), base::Time(), true /* secure */, false /* httponly */, + test.same_site, COOKIE_PRIORITY_DEFAULT, false)); } std::vector access_semantics = { @@ -1930,7 +1992,7 @@ TEST(CanonicalCookieTest, IncludeForRequestURL_SameSiteNone_Metrics) { const auto make_cookie = [now](CookieSameSite same_site, bool same_party) { return CanonicalCookie::CreateUnsafeCookieForTesting( "A", "1", "www.example.com", "/test", now, base::Time(), base::Time(), - true /* secure */, false /*httponly*/, same_site, + base::Time(), true /* secure */, false /*httponly*/, same_site, COOKIE_PRIORITY_DEFAULT, same_party); }; GURL url("https://www.example.com/test"); @@ -2153,7 +2215,7 @@ TEST(CanonicalCookieTest, IncludeForRequestURL_RedirectDowngradeWarning) { std::unique_ptr cookie = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "1", "www.example.test", "/test", base::Time::Now(), - base::Time(), base::Time(), /*secure=*/true, + base::Time(), base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, samesite, COOKIE_PRIORITY_DEFAULT, /*same_party=*/false); @@ -2178,8 +2240,9 @@ TEST(CanonicalCookieTest, IncludeForRequestURL_RedirectDowngradeWarning) { std::unique_ptr cookie = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "1", "www.example.test", "/test", base::Time::Now(), - base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, - test.samesite, COOKIE_PRIORITY_DEFAULT, /*same_party=*/false); + base::Time(), base::Time(), base::Time(), /*secure=*/true, + /*httponly=*/false, test.samesite, COOKIE_PRIORITY_DEFAULT, + /*same_party=*/false); CookieOptions options; options.set_same_site_cookie_context( @@ -2230,7 +2293,7 @@ TEST(CanonicalCookieTest, MultipleExclusionReasons) { // would weed it out. auto cookie1 = CanonicalCookie::CreateUnsafeCookieForTesting( "name", "value", "other-domain.com", "/bar", creation_time, base::Time(), - base::Time(), true /* secure */, true /* httponly */, + base::Time(), base::Time(), true /* secure */, true /* httponly */, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT, false); EXPECT_THAT( cookie1->IncludeForRequestURL( @@ -2463,228 +2526,228 @@ TEST(CanonicalCookieTest, IsCanonical) { // Base correct template. EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "x.y", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Newline in name. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A\n", "B", "x.y", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Carriage return in name. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A\r", "B", "x.y", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Null character in name. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( std::string("A\0Z", 3), "B", "x.y", "/path", base::Time(), - base::Time(), base::Time(), false, false, + base::Time(), base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Name begins with whitespace. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( " A", "B", "x.y", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Name ends with whitespace. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A ", "B", "x.y", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Empty name. (Note this is against the spec but compatible with other // browsers.) EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( "", "B", "x.y", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Space in name EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( "A C", "B", "x.y", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Extra space suffixing name. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A ", "B", "x.y", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // '=' character in name. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A=", "B", "x.y", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Separator in name. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A;", "B", "x.y", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // '=' character in value. EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B=", "x.y", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Separator in value. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B;", "x.y", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Separator in domain. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", ";x.y", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Garbage in domain. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "@:&", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Space in domain. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "x.y ", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // 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. EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Path does not start with a "/". EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "x.y", "path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Empty path. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "x.y", "", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // "localhost" as domain. EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "localhost", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Localhost IPv4 address as domain. EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "127.0.0.1", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Simple IPv4 address as domain. EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "1.2.3.4", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // period-prefixed IPv4 address as domain. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", ".1.3.2.4", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // period-prefixed truncated IPv4 address as domain. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", ".3.2.4", "/path", base::Time(), base::Time(), - base::Time(), true, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), true, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // truncated IPv4 address as domain. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "3.2.4", "/path", base::Time(), base::Time(), - base::Time(), true, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), true, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Non-canonical IPv4 address as domain. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "01.2.03.4", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Non-canonical IPv4 address as domain. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "16843009", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Non-canonical IPv4 address as domain. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "0x1010101", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Null IPv6 address as domain. EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "[::]", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Localhost IPv6 address as domain. EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "[::1]", "/path", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Fully speced IPv6 address as domain. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "[2001:0DB8:AC10:FE01:0000:0000:0000:0000]", - "/path", base::Time(), base::Time(), base::Time(), false, - false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, - false) + "/path", base::Time(), base::Time(), base::Time(), + base::Time(), false, false, CookieSameSite::NO_RESTRICTION, + COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Zero abbreviated IPv6 address as domain. Not canonical because of leading // zeros & uppercase hex letters. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "[2001:0DB8:AC10:FE01::]", "/path", base::Time(), - base::Time(), base::Time(), false, false, + base::Time(), base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); @@ -2692,123 +2755,125 @@ TEST(CanonicalCookieTest, IsCanonical) { // uppercase hex letters. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "[2001:DB8:AC10:FE01::]", "/path", base::Time(), - base::Time(), base::Time(), false, false, + base::Time(), base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Lowercased hex IPv6 address as domain. EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "[2001:db8:ac10:fe01::]", "/path", base::Time(), - base::Time(), base::Time(), false, false, + base::Time(), base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Lowercased hex IPv6 address as domain for domain cookie. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", ".[2001:db8:ac10:fe01::]", "/path", base::Time(), - base::Time(), base::Time(), false, false, + base::Time(), base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Incomplete lowercased hex IPv6 address as domain. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "[2001:db8:ac10:fe01:]", "/path", base::Time(), - base::Time(), base::Time(), false, false, + base::Time(), base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Missing square brackets in IPv6 address as domain. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "2606:2800:220:1:248:1893:25c8:1946", "/path", - base::Time(), base::Time(), base::Time(), false, false, - CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), base::Time(), base::Time(), + false, false, CookieSameSite::NO_RESTRICTION, + COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Properly formatted host cookie. EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-A", "B", "x.y", "/", base::Time(), base::Time(), - base::Time(), true, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), true, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Insecure host cookie. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-A", "B", "x.y", "/", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Host cookie with non-null path. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-A", "B", "x.y", "/path", base::Time(), base::Time(), - base::Time(), true, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), true, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Host cookie with empty domain. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-A", "B", "", "/", base::Time(), base::Time(), - base::Time(), true, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), true, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Host cookie with period prefixed domain. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-A", "B", ".x.y", "/", base::Time(), base::Time(), - base::Time(), true, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), true, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Properly formatted secure cookie. EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( "__Secure-A", "B", "x.y", "/", base::Time(), base::Time(), - base::Time(), true, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), true, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // Insecure secure cookie. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "__Secure-A", "B", "x.y", "/", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, false) + base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false) ->IsCanonical()); // SameParty attribute used correctly (with Secure and non-Strict SameSite). EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "x.y", "/", base::Time(), base::Time(), - base::Time(), true, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_LOW, true) + base::Time(), base::Time(), true, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, true) ->IsCanonical()); EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "x.y", "/", base::Time(), base::Time(), - base::Time(), true, false, CookieSameSite::UNSPECIFIED, - COOKIE_PRIORITY_LOW, true) + base::Time(), base::Time(), true, false, + CookieSameSite::UNSPECIFIED, COOKIE_PRIORITY_LOW, true) ->IsCanonical()); EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "x.y", "/", base::Time(), base::Time(), - base::Time(), true, false, CookieSameSite::LAX_MODE, - COOKIE_PRIORITY_LOW, true) + base::Time(), base::Time(), true, false, + CookieSameSite::LAX_MODE, COOKIE_PRIORITY_LOW, true) ->IsCanonical()); // SameParty without Secure is not canonical. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "x.y", "/", base::Time(), base::Time(), - base::Time(), false, false, CookieSameSite::LAX_MODE, - COOKIE_PRIORITY_LOW, true) + base::Time(), base::Time(), false, false, + CookieSameSite::LAX_MODE, COOKIE_PRIORITY_LOW, true) ->IsCanonical()); // SameParty with SameSite=Strict is not canonical. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "x.y", "/", base::Time(), base::Time(), - base::Time(), true, false, CookieSameSite::STRICT_MODE, - COOKIE_PRIORITY_LOW, true) + base::Time(), base::Time(), true, false, + CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_LOW, true) ->IsCanonical()); // Partitioned attribute used correctly (__Host- prefix, no SameParty). EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-A", "B", "x.y", "/", base::Time(), base::Time(), - base::Time(), /*secure=*/true, /*httponly=*/false, - CookieSameSite::UNSPECIFIED, COOKIE_PRIORITY_LOW, + base::Time(), base::Time(), /*secure=*/true, + /*httponly=*/false, CookieSameSite::UNSPECIFIED, + COOKIE_PRIORITY_LOW, /*same_party=*/false, CookiePartitionKey::FromURLForTesting( GURL("https://toplevelsite.com"))) @@ -2818,8 +2883,9 @@ TEST(CanonicalCookieTest, IsCanonical) { // Secure, Path=/, and no Domain. EXPECT_TRUE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "x.y", "/", base::Time(), base::Time(), - base::Time(), /*secure=*/true, /*httponly=*/false, - CookieSameSite::UNSPECIFIED, COOKIE_PRIORITY_LOW, + base::Time(), base::Time(), /*secure=*/true, + /*httponly=*/false, CookieSameSite::UNSPECIFIED, + COOKIE_PRIORITY_LOW, /*same_party=*/false, CookiePartitionKey::FromURLForTesting( GURL("https://toplevelsite.com"))) @@ -2828,8 +2894,9 @@ TEST(CanonicalCookieTest, IsCanonical) { // Partitioned attribute invalid, not Secure. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "x.y", "/", base::Time(), base::Time(), - base::Time(), /*secure=*/false, /*httponly=*/false, - CookieSameSite::UNSPECIFIED, COOKIE_PRIORITY_LOW, + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, CookieSameSite::UNSPECIFIED, + COOKIE_PRIORITY_LOW, /*same_party=*/false, CookiePartitionKey::FromURLForTesting( GURL("https://toplevelsite.com"))) @@ -2838,8 +2905,9 @@ TEST(CanonicalCookieTest, IsCanonical) { // Partitioned attribute invalid, no Path. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "x.y", "", base::Time(), base::Time(), - base::Time(), /*secure=*/true, /*httponly=*/false, - CookieSameSite::UNSPECIFIED, COOKIE_PRIORITY_LOW, + base::Time(), base::Time(), /*secure=*/true, + /*httponly=*/false, CookieSameSite::UNSPECIFIED, + COOKIE_PRIORITY_LOW, /*same_party=*/false, CookiePartitionKey::FromURLForTesting( GURL("https://toplevelsite.com"))) @@ -2848,8 +2916,9 @@ TEST(CanonicalCookieTest, IsCanonical) { // Partitioned attribute invalid, invalid Path. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "x.y", "/foobar", base::Time(), base::Time(), - base::Time(), /*secure=*/true, /*httponly=*/false, - CookieSameSite::UNSPECIFIED, COOKIE_PRIORITY_LOW, + base::Time(), base::Time(), /*secure=*/true, + /*httponly=*/false, CookieSameSite::UNSPECIFIED, + COOKIE_PRIORITY_LOW, /*same_party=*/false, CookiePartitionKey::FromURLForTesting( GURL("https://toplevelsite.com"))) @@ -2858,8 +2927,9 @@ TEST(CanonicalCookieTest, IsCanonical) { // Partitioned attribute invalid, Domain attribute also included. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", ".x.y", "/", base::Time(), base::Time(), - base::Time(), /*secure=*/true, /*httponly=*/false, - CookieSameSite::UNSPECIFIED, COOKIE_PRIORITY_LOW, + base::Time(), base::Time(), /*secure=*/true, + /*httponly=*/false, CookieSameSite::UNSPECIFIED, + COOKIE_PRIORITY_LOW, /*same_party=*/false, CookiePartitionKey::FromURLForTesting( GURL("https://toplevelsite.com"))) @@ -2868,8 +2938,9 @@ TEST(CanonicalCookieTest, IsCanonical) { // Partitioned attribute invalid, SameParty attribute also included. EXPECT_FALSE(CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-A", "B", "x.y", "/", base::Time(), base::Time(), - base::Time(), /*secure=*/true, /*httponly=*/false, - CookieSameSite::UNSPECIFIED, COOKIE_PRIORITY_LOW, + base::Time(), base::Time(), /*secure=*/true, + /*httponly=*/false, CookieSameSite::UNSPECIFIED, + COOKIE_PRIORITY_LOW, /*same_party=*/true, CookiePartitionKey::FromURLForTesting( GURL("https://toplevelsite.com"))) @@ -2878,8 +2949,9 @@ TEST(CanonicalCookieTest, IsCanonical) { TEST(CanonicalCookieTest, TestSetCreationDate) { auto cookie = CanonicalCookie::CreateUnsafeCookieForTesting( - "A", "B", "x.y", "/path", base::Time(), base::Time(), base::Time(), false, - false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false); + "A", "B", "x.y", "/path", base::Time(), base::Time(), base::Time(), + base::Time(), false, false, CookieSameSite::NO_RESTRICTION, + COOKIE_PRIORITY_LOW, false); EXPECT_TRUE(cookie->CreationDate().is_null()); base::Time now(base::Time::Now()); @@ -3889,7 +3961,7 @@ TEST(CanonicalCookieTest, FromStorage) { std::unique_ptr cc = CanonicalCookie::FromStorage( "A", "B", "www.foo.com", "/bar", two_hours_ago, one_hour_from_now, - one_hour_ago, false /*secure*/, false /*httponly*/, + one_hour_ago, one_hour_ago, false /*secure*/, false /*httponly*/, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false /*same_party*/, absl::nullopt /*partition_key*/, CookieSourceScheme::kSecure, 87); @@ -3901,6 +3973,7 @@ TEST(CanonicalCookieTest, FromStorage) { EXPECT_EQ(two_hours_ago, cc->CreationDate()); EXPECT_EQ(one_hour_ago, cc->LastAccessDate()); EXPECT_EQ(one_hour_from_now, cc->ExpiryDate()); + EXPECT_EQ(one_hour_ago, cc->LastUpdateDate()); EXPECT_FALSE(cc->IsSecure()); EXPECT_FALSE(cc->IsHttpOnly()); EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cc->SameSite()); @@ -3914,7 +3987,7 @@ TEST(CanonicalCookieTest, FromStorage) { // contains a newline character. EXPECT_FALSE(CanonicalCookie::FromStorage( "A\n", "B", "www.foo.com", "/bar", two_hours_ago, one_hour_from_now, - one_hour_ago, false /*secure*/, false /*httponly*/, + one_hour_ago, one_hour_ago, false /*secure*/, false /*httponly*/, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false /*same_party*/, absl::nullopt /*partition_key*/, CookieSourceScheme::kSecure, 80)); @@ -3923,7 +3996,7 @@ TEST(CanonicalCookieTest, FromStorage) { // FromStorage() should result in a PORT_INVALID. std::unique_ptr cc2 = CanonicalCookie::FromStorage( "A", "B", "www.foo.com", "/bar", two_hours_ago, one_hour_from_now, - one_hour_ago, false /*secure*/, false /*httponly*/, + one_hour_ago, one_hour_ago, false /*secure*/, false /*httponly*/, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false /*same_party*/, absl::nullopt /*partition_key*/, CookieSourceScheme::kSecure, 80000); @@ -3933,7 +4006,7 @@ TEST(CanonicalCookieTest, FromStorage) { // Test port edge cases: unspecified. std::unique_ptr cc3 = CanonicalCookie::FromStorage( "A", "B", "www.foo.com", "/bar", two_hours_ago, one_hour_from_now, - one_hour_ago, false /*secure*/, false /*httponly*/, + one_hour_ago, one_hour_ago, false /*secure*/, false /*httponly*/, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false /*same_party*/, absl::nullopt /*partition_key*/, CookieSourceScheme::kSecure, url::PORT_UNSPECIFIED); @@ -3942,7 +4015,7 @@ TEST(CanonicalCookieTest, FromStorage) { // Test port edge cases: invalid. std::unique_ptr cc4 = CanonicalCookie::FromStorage( "A", "B", "www.foo.com", "/bar", two_hours_ago, one_hour_from_now, - one_hour_ago, false /*secure*/, false /*httponly*/, + one_hour_ago, one_hour_ago, false /*secure*/, false /*httponly*/, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false /*same_party*/, absl::nullopt /*partition_key*/, CookieSourceScheme::kSecure, url::PORT_INVALID); @@ -3956,11 +4029,11 @@ TEST(CanonicalCookieTest, IsSetPermittedInContext) { auto cookie_scriptable = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", "www.example.com", "/test", current_time, base::Time(), - base::Time(), true /*secure*/, false /*httponly*/, + base::Time(), base::Time(), true /*secure*/, false /*httponly*/, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false); auto cookie_httponly = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", "www.example.com", "/test", current_time, base::Time(), - base::Time(), true /*secure*/, true /*httponly*/, + base::Time(), base::Time(), true /*secure*/, true /*httponly*/, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false); CookieOptions context_script; @@ -4061,7 +4134,7 @@ TEST(CanonicalCookieTest, IsSetPermittedInContext) { auto cookie_same_site_unrestricted = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", "www.example.com", "/test", current_time, base::Time(), - base::Time(), true /*secure*/, false /*httponly*/, + base::Time(), base::Time(), true /*secure*/, false /*httponly*/, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false); EXPECT_THAT( @@ -4166,7 +4239,7 @@ TEST(CanonicalCookieTest, IsSetPermittedInContext) { { auto cookie_same_site_lax = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", "www.example.com", "/test", current_time, base::Time(), - base::Time(), true /*secure*/, false /*httponly*/, + base::Time(), base::Time(), true /*secure*/, false /*httponly*/, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, false); EXPECT_THAT( @@ -4291,7 +4364,7 @@ TEST(CanonicalCookieTest, IsSetPermittedInContext) { auto cookie_same_site_strict = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", "www.example.com", "/test", current_time, base::Time(), - base::Time(), true /*secure*/, false /*httponly*/, + base::Time(), base::Time(), true /*secure*/, false /*httponly*/, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT, false); // TODO(morlovich): Do compatibility testing on whether set of strict in lax @@ -4455,7 +4528,7 @@ TEST(CanonicalCookieTest, IsSetPermittedInContext) { auto cookie_same_site_unspecified = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", "www.example.com", "/test", current_time, base::Time(), - base::Time(), true /*secure*/, false /*httponly*/, + base::Time(), base::Time(), true /*secure*/, false /*httponly*/, CookieSameSite::UNSPECIFIED, COOKIE_PRIORITY_DEFAULT, false); EXPECT_THAT( @@ -4574,7 +4647,7 @@ TEST(CanonicalCookieTest, IsSetPermittedEffectiveSameSite) { // CanonicalCookie with CookieSameSite::NO_RESTRICTION. auto cookie_no_restriction = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", "www.example.com", "/test", current_time, base::Time(), - base::Time(), true /*secure*/, false /*httponly*/, + base::Time(), base::Time(), true /*secure*/, false /*httponly*/, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false); EXPECT_THAT( @@ -4591,7 +4664,7 @@ TEST(CanonicalCookieTest, IsSetPermittedEffectiveSameSite) { // CanonicalCookie with CookieSameSite::LAX_MODE. auto cookie_lax = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", "www.example.com", "/test", current_time, base::Time(), - base::Time(), true /*secure*/, false /*httponly*/, + base::Time(), base::Time(), true /*secure*/, false /*httponly*/, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, false); EXPECT_THAT( @@ -4608,7 +4681,7 @@ TEST(CanonicalCookieTest, IsSetPermittedEffectiveSameSite) { // CanonicalCookie with CookieSameSite::STRICT_MODE. auto cookie_strict = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", "www.example.com", "/test", current_time, base::Time(), - base::Time(), true /*secure*/, false /*httponly*/, + base::Time(), base::Time(), true /*secure*/, false /*httponly*/, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT, false); EXPECT_THAT( @@ -4626,11 +4699,11 @@ TEST(CanonicalCookieTest, IsSetPermittedEffectiveSameSite) { base::Time creation_time = base::Time::Now() - (kLaxAllowUnsafeMaxAge * 4); auto cookie_old_unspecified = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", "www.example.com", "/test", creation_time, base::Time(), - base::Time(), true /*secure*/, false /*httponly*/, + base::Time(), base::Time(), true /*secure*/, false /*httponly*/, CookieSameSite::UNSPECIFIED, COOKIE_PRIORITY_DEFAULT, false); auto cookie_unspecified = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", "www.example.com", "/test", current_time, base::Time(), - base::Time(), true /*secure*/, false /*httponly*/, + base::Time(), base::Time(), true /*secure*/, false /*httponly*/, CookieSameSite::UNSPECIFIED, COOKIE_PRIORITY_DEFAULT, false); EXPECT_THAT( @@ -4694,7 +4767,7 @@ TEST(CanonicalCookieTest, IsSetPermitted_AllowedToAccessSecureCookies) { continue; auto cookie = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", "www.example.com", "/test", current_time, base::Time(), - base::Time(), secure, false /*httponly*/, same_site, + base::Time(), base::Time(), secure, false /*httponly*/, same_site, COOKIE_PRIORITY_DEFAULT, same_party); for (bool delegate_treats_url_as_trustworthy : {false, true}) { @@ -4757,7 +4830,7 @@ TEST(CanonicalCookieTest, IsSetPermitted_SameSiteNone_Metrics) { const auto make_cookie = [now](CookieSameSite same_site, bool same_party) { return CanonicalCookie::CreateUnsafeCookieForTesting( "A", "1", "www.example.com", "/test", now, base::Time(), base::Time(), - true /* secure */, false /*httponly*/, same_site, + base::Time(), true /* secure */, false /*httponly*/, same_site, COOKIE_PRIORITY_DEFAULT, same_party); }; GURL url("https://www.example.com/test"); @@ -4911,7 +4984,7 @@ TEST(CanonicalCookieTest, IsSetPermitted_SameParty) { bool delegate_treats_url_as_trustworthy = false; auto cookie = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", "www.example.com", "/test", current_time, base::Time(), - base::Time(), true /* secure */, false /*httponly*/, + base::Time(), base::Time(), true /* secure */, false /*httponly*/, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, true /* same_party */); @@ -4938,8 +5011,8 @@ TEST(CanonicalCookieTest, IsSetPermitted_SameParty) { }) { auto cookie = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "2", "www.example.com", "/test", current_time, base::Time(), - base::Time(), true /* secure */, false /*httponly*/, same_site, - COOKIE_PRIORITY_DEFAULT, true /* same_party */); + base::Time(), base::Time(), true /* secure */, false /*httponly*/, + same_site, COOKIE_PRIORITY_DEFAULT, true /* same_party */); for (bool delegate_treats_url_as_trustworthy : {false, true}) { for (CookieAccessSemantics access_semantics : { @@ -5000,7 +5073,7 @@ TEST(CanonicalCookieTest, IsSetPermittedInContext_RedirectDowngradeWarning) { std::unique_ptr cookie = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "1", "www.example.test", "/test", base::Time::Now(), - base::Time(), base::Time(), /*secure=*/true, + base::Time(), base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, samesite, COOKIE_PRIORITY_DEFAULT, /*same_party=*/false); @@ -5026,8 +5099,9 @@ TEST(CanonicalCookieTest, IsSetPermittedInContext_RedirectDowngradeWarning) { std::unique_ptr cookie = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "1", "www.example.test", "/test", base::Time::Now(), - base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, - test.samesite, COOKIE_PRIORITY_DEFAULT, /*same_party=*/false); + base::Time(), base::Time(), base::Time(), /*secure=*/true, + /*httponly=*/false, test.samesite, COOKIE_PRIORITY_DEFAULT, + /*same_party=*/false); Context::ContextMetadata lax_cross_downgrade_metadata; lax_cross_downgrade_metadata.cross_site_redirect_downgrade = @@ -5084,7 +5158,7 @@ TEST(CanonicalCookieTest, TestIsCanonicalWithInvalidSizeHistograms) { // Test a cookie that is canonical and valid size EXPECT_TRUE(CanonicalCookie::FromStorage( "A", "B", "www.foo.com", "/bar", two_hours_ago, one_hour_from_now, - one_hour_ago, false /*secure*/, false /*httponly*/, + one_hour_ago, one_hour_ago, false /*secure*/, false /*httponly*/, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false /*same_party*/, absl::nullopt /*partition_key*/, CookieSourceScheme::kSecure, 87)); @@ -5098,13 +5172,13 @@ TEST(CanonicalCookieTest, TestIsCanonicalWithInvalidSizeHistograms) { const std::string kCookieBig(4096, 'a'); EXPECT_TRUE(CanonicalCookie::FromStorage( kCookieBig, "B", "www.foo.com", "/bar", two_hours_ago, one_hour_from_now, - one_hour_ago, false /*secure*/, false /*httponly*/, + one_hour_ago, one_hour_ago, false /*secure*/, false /*httponly*/, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false /*same_party*/, absl::nullopt /*partition_key*/, CookieSourceScheme::kSecure, 87)); EXPECT_TRUE(CanonicalCookie::FromStorage( "A", kCookieBig, "www.foo.com", "/bar", two_hours_ago, one_hour_from_now, - one_hour_ago, false /*secure*/, false /*httponly*/, + one_hour_ago, one_hour_ago, false /*secure*/, false /*httponly*/, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false /*same_party*/, absl::nullopt /*partition_key*/, CookieSourceScheme::kSecure, 87)); diff --git a/net/cookies/cookie_deletion_info_unittest.cc b/net/cookies/cookie_deletion_info_unittest.cc index f316103f89177e..a21021e7cf54ea 100644 --- a/net/cookies/cookie_deletion_info_unittest.cc +++ b/net/cookies/cookie_deletion_info_unittest.cc @@ -88,6 +88,7 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoMatchSessionControl) { /*creation=*/base::Time::Now(), /*expiration=*/base::Time::Max(), /*last_access=*/base::Time::Now(), + /*last_update=*/base::Time::Now(), /*secure=*/true, /*httponly=*/false, CookieSameSite::NO_RESTRICTION, CookiePriority::COOKIE_PRIORITY_DEFAULT, @@ -98,6 +99,7 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoMatchSessionControl) { /*creation=*/base::Time::Now(), /*expiration=*/base::Time(), /*last_access=*/base::Time::Now(), + /*last_update=*/base::Time::Now(), /*secure=*/true, /*httponly=*/false, CookieSameSite::NO_RESTRICTION, CookiePriority::COOKIE_PRIORITY_DEFAULT, @@ -149,6 +151,7 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoMatchHost) { /*creation=*/base::Time::Now(), /*expiration=*/base::Time::Max(), /*last_access=*/base::Time::Now(), + /*last_update=*/base::Time::Now(), /*secure=*/true, /*httponly=*/false, CookieSameSite::NO_RESTRICTION, CookiePriority::COOKIE_PRIORITY_DEFAULT, @@ -160,6 +163,7 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoMatchHost) { /*creation=*/base::Time::Now(), /*expiration=*/base::Time::Max(), /*last_access=*/base::Time::Now(), + /*last_update=*/base::Time::Now(), /*secure=*/true, /*httponly=*/false, CookieSameSite::NO_RESTRICTION, CookiePriority::COOKIE_PRIORITY_DEFAULT, @@ -224,6 +228,7 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoMatchName) { /*creation=*/base::Time::Now(), /*expiration=*/base::Time::Max(), /*last_access=*/base::Time::Now(), + /*last_update=*/base::Time::Now(), /*secure=*/true, /*httponly=*/false, CookieSameSite::NO_RESTRICTION, CookiePriority::COOKIE_PRIORITY_DEFAULT, @@ -234,6 +239,7 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoMatchName) { /*creation=*/base::Time::Now(), /*expiration=*/base::Time::Max(), /*last_access=*/base::Time::Now(), + /*last_update=*/base::Time::Now(), /*secure=*/true, /*httponly=*/false, CookieSameSite::NO_RESTRICTION, CookiePriority::COOKIE_PRIORITY_DEFAULT, @@ -260,6 +266,7 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoMatchValue) { /*creation=*/base::Time::Now(), /*expiration=*/base::Time::Max(), /*last_access=*/base::Time::Now(), + /*last_update=*/base::Time::Now(), /*secure=*/true, /*httponly=*/false, CookieSameSite::NO_RESTRICTION, CookiePriority::COOKIE_PRIORITY_DEFAULT, @@ -270,6 +277,7 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoMatchValue) { /*creation=*/base::Time::Now(), /*expiration=*/base::Time::Max(), /*last_access=*/base::Time::Now(), + /*last_update=*/base::Time::Now(), /*secure=*/true, /*httponly=*/false, CookieSameSite::NO_RESTRICTION, CookiePriority::COOKIE_PRIORITY_DEFAULT, @@ -296,6 +304,7 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoMatchUrl) { /*creation=*/base::Time::Now(), /*expiration=*/base::Time::Max(), /*last_access=*/base::Time::Now(), + /*last_update=*/base::Time::Now(), /*secure=*/true, /*httponly=*/false, CookieSameSite::NO_RESTRICTION, CookiePriority::COOKIE_PRIORITY_DEFAULT, @@ -349,6 +358,7 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoDomainMatchesDomain) { /*creation=*/base::Time::FromDoubleT(kTestMinEpoch + 1), /*expiration=*/base::Time::Max(), /*last_access=*/base::Time::FromDoubleT(kTestMinEpoch + 1), + /*last_update=*/base::Time::Now(), /*secure=*/true, /*httponly=*/false, /*same_site=*/CookieSameSite::NO_RESTRICTION, @@ -417,6 +427,7 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoMatchesDomainList) { /*creation=*/base::Time::Now(), /*expiration=*/base::Time::Max(), /*last_access=*/base::Time::Now(), + /*last_update=*/base::Time::Now(), /*secure=*/false, /*httponly=*/false, /*same_site=*/CookieSameSite::NO_RESTRICTION, diff --git a/net/cookies/cookie_monster.cc b/net/cookies/cookie_monster.cc index 73172c5c884630..5f54517f7a6905 100644 --- a/net/cookies/cookie_monster.cc +++ b/net/cookies/cookie_monster.cc @@ -2497,8 +2497,8 @@ void CookieMonster::ConvertPartitionedCookie(const net::CanonicalCookie& cookie, auto new_cookie = net::CanonicalCookie::FromStorage( cookie.Name(), cookie.Value(), cookie.Domain(), cookie.Path(), cookie.CreationDate(), cookie.ExpiryDate(), base::Time::Now(), - cookie.IsSecure(), cookie.IsHttpOnly(), cookie.SameSite(), - cookie.Priority(), cookie.IsSameParty(), absl::nullopt, + cookie.LastUpdateDate(), cookie.IsSecure(), cookie.IsHttpOnly(), + cookie.SameSite(), cookie.Priority(), cookie.IsSameParty(), absl::nullopt, cookie.SourceScheme(), cookie.SourcePort()); DCHECK(new_cookie); diff --git a/net/cookies/cookie_monster_store_test.cc b/net/cookies/cookie_monster_store_test.cc index 4170ea3a381418..e64f70b65e690d 100644 --- a/net/cookies/cookie_monster_store_test.cc +++ b/net/cookies/cookie_monster_store_test.cc @@ -121,8 +121,8 @@ std::unique_ptr BuildCanonicalCookie( return CanonicalCookie::CreateUnsafeCookieForTesting( pc.Name(), pc.Value(), "." + url.host(), cookie_path, creation_time, - cookie_expires, base::Time(), pc.IsSecure(), pc.IsHttpOnly(), - pc.SameSite(), pc.Priority(), pc.IsSameParty()); + cookie_expires, base::Time(), base::Time(), pc.IsSecure(), + pc.IsHttpOnly(), pc.SameSite(), pc.Priority(), pc.IsSameParty()); } void AddCookieToList(const GURL& url, @@ -234,8 +234,9 @@ std::unique_ptr CreateMonsterFromStoreForGC( std::unique_ptr cc = CanonicalCookie::CreateUnsafeCookieForTesting( "a", "1", base::StringPrintf("h%05d.izzle", i), "/path", - creation_time, expiration_time, base::Time(), secure, false, - CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false); + creation_time, expiration_time, base::Time(), base::Time(), secure, + false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, + false); cc->SetLastAccessDate(last_access_time); store->AddCookie(*cc); } diff --git a/net/cookies/cookie_monster_unittest.cc b/net/cookies/cookie_monster_unittest.cc index e626e078cab6e9..b3c78f318cd9f1 100644 --- a/net/cookies/cookie_monster_unittest.cc +++ b/net/cookies/cookie_monster_unittest.cc @@ -248,89 +248,89 @@ class CookieMonsterTestBase : public CookieStoreTest { // Domain cookies cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "dom_1", "A", ".harvard.edu", "/", now, base::Time(), base::Time(), - false, false, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, - false)); + base::Time(), false, false, CookieSameSite::LAX_MODE, + COOKIE_PRIORITY_DEFAULT, false)); cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "dom_2", "B", ".math.harvard.edu", "/", now, base::Time(), base::Time(), - false, false, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, - false)); + base::Time(), false, false, CookieSameSite::LAX_MODE, + COOKIE_PRIORITY_DEFAULT, false)); cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "dom_3", "C", ".bourbaki.math.harvard.edu", "/", now, base::Time(), - base::Time(), false, false, CookieSameSite::LAX_MODE, + base::Time(), base::Time(), false, false, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, false)); // Host cookies cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "host_1", "A", url_top_level_domain_plus_1, "/", now, base::Time(), - base::Time(), false, false, CookieSameSite::LAX_MODE, + base::Time(), base::Time(), false, false, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, false)); cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "host_2", "B", url_top_level_domain_plus_2, "/", now, base::Time(), - base::Time(), false, false, CookieSameSite::LAX_MODE, + base::Time(), base::Time(), false, false, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, false)); cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "host_3", "C", url_top_level_domain_plus_3, "/", now, base::Time(), - base::Time(), false, false, CookieSameSite::LAX_MODE, + base::Time(), base::Time(), false, false, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, false)); // http_only cookie cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "httpo_check", "A", url_top_level_domain_plus_2, "/", now, base::Time(), - base::Time(), false, true, CookieSameSite::LAX_MODE, + base::Time(), base::Time(), false, true, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, false)); // same-site cookie cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "same_site_check", "A", url_top_level_domain_plus_2, "/", now, - base::Time(), base::Time(), false, false, CookieSameSite::STRICT_MODE, - COOKIE_PRIORITY_DEFAULT, false)); + base::Time(), base::Time(), base::Time(), false, false, + CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT, false)); // same-party cookie cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "same_party_check", "A", url_top_level_domain_plus_2, "/", now, - base::Time(), base::Time(), true /* secure */, false, + base::Time(), base::Time(), base::Time(), true /* secure */, false, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, true /* same_party */)); // Secure cookies cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "sec_dom", "A", ".math.harvard.edu", "/", now, base::Time(), - base::Time(), true, false, CookieSameSite::NO_RESTRICTION, + base::Time(), base::Time(), true, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false)); cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "sec_host", "B", url_top_level_domain_plus_2, "/", now, base::Time(), - base::Time(), true, false, CookieSameSite::NO_RESTRICTION, + base::Time(), base::Time(), true, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false)); // Domain path cookies cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "dom_path_1", "A", ".math.harvard.edu", "/dir1", now, base::Time(), - base::Time(), false, false, CookieSameSite::LAX_MODE, + base::Time(), base::Time(), false, false, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, false)); cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "dom_path_2", "B", ".math.harvard.edu", "/dir1/dir2", now, base::Time(), - base::Time(), false, false, CookieSameSite::LAX_MODE, + base::Time(), base::Time(), false, false, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, false)); // Host path cookies cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "host_path_1", "A", url_top_level_domain_plus_2, "/dir1", now, - base::Time(), base::Time(), false, false, CookieSameSite::LAX_MODE, - COOKIE_PRIORITY_DEFAULT, false)); + base::Time(), base::Time(), base::Time(), false, false, + CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, false)); cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "host_path_2", "B", url_top_level_domain_plus_2, "/dir1/dir2", now, - base::Time(), base::Time(), false, false, CookieSameSite::LAX_MODE, - COOKIE_PRIORITY_DEFAULT, false)); + base::Time(), base::Time(), base::Time(), false, false, + CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, false)); // Partitioned cookies cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-pc_1", "A", url_top_level_domain_secure, "/", now, base::Time(), - base::Time(), true, false, CookieSameSite::NO_RESTRICTION, + base::Time(), base::Time(), true, false, CookieSameSite::NO_RESTRICTION, CookiePriority::COOKIE_PRIORITY_DEFAULT, false, CookiePartitionKey::FromURLForTesting(GURL(kTopLevelDomainPlus1)))); cookies.push_back(CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-pc_2", "B", url_top_level_domain_secure, "/", now, base::Time(), - base::Time(), true, false, CookieSameSite::NO_RESTRICTION, + base::Time(), base::Time(), true, false, CookieSameSite::NO_RESTRICTION, CookiePriority::COOKIE_PRIORITY_DEFAULT, false, CookiePartitionKey::FromURLForTesting(GURL(kTopLevelDomainPlus1)))); @@ -942,10 +942,11 @@ class CookieMonsterTestBase : public CookieStoreTest { for (int i = 0; i < num_cookies; i++) { std::unique_ptr cc( CanonicalCookie::CreateUnsafeCookieForTesting( - "a", "1", base::StringPrintf("h%05d.izzle", i), "/" /* path */, - creation_time, base::Time() /* expiration_time */, - creation_time /* last_access */, true /* secure */, - false /* http_only */, CookieSameSite::NO_RESTRICTION, + "a", "1", base::StringPrintf("h%05d.izzle", i), /*path=*/"/", + creation_time, /*=expiration_time=*/base::Time(), + /*last_access=*/creation_time, /*last_update=*/creation_time, + /*secure=*/true, + /*httponly=*/false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false /* same_party */)); GURL source_url = cookie_util::SimulatedCookieSource(*cc, "https"); cm->SetCanonicalCookieAsync(std::move(cc), source_url, @@ -962,6 +963,7 @@ class CookieMonsterTestBase : public CookieStoreTest { it->CreationDate() == cookie.CreationDate() && it->ExpiryDate() == cookie.ExpiryDate() && it->LastAccessDate() == cookie.LastAccessDate() && + it->LastUpdateDate() == cookie.LastUpdateDate() && it->IsSecure() == cookie.IsSecure() && it->IsHttpOnly() == cookie.IsHttpOnly() && it->Priority() == cookie.Priority()) { @@ -1124,12 +1126,12 @@ TEST_F(DeferredCookieTaskTest, DeferredSetAllCookies) { CookieList list; list.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "." + http_www_foo_.domain(), "/", base::Time::Now(), - base::Time(), base::Time(), false, true, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_DEFAULT, false)); + base::Time(), base::Time(), base::Time(), false, true, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false)); list.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( "C", "D", "." + http_www_foo_.domain(), "/", base::Time::Now(), - base::Time(), base::Time(), false, true, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_DEFAULT, false)); + base::Time(), base::Time(), base::Time(), false, true, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false)); ResultSavingCookieCallback call1; cookie_monster_->SetAllCookiesAsync(list, call1.MakeCallback()); @@ -2153,14 +2155,18 @@ TEST_F(CookieMonsterTest, InheritCreationDate) { CookieList cookies = GetAllCookies(cm.get()); ASSERT_EQ(1u, cookies.size()); EXPECT_EQ(the_not_so_distant_past, cookies[0].CreationDate()); + base::Time last_update = cookies[0].LastUpdateDate(); // Overwrite the cookie with the same value, and verify that the creation date - // is inherited. + // is inherited. The update date isn't inherited though. EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "Name=Value; path=/")); cookies = GetAllCookies(cm.get()); ASSERT_EQ(1u, cookies.size()); EXPECT_EQ(the_not_so_distant_past, cookies[0].CreationDate()); + // If this is flakey you many need to manually set the last update time. + EXPECT_LT(last_update, cookies[0].LastUpdateDate()); + last_update = cookies[0].LastUpdateDate(); // New value => new creation date. EXPECT_TRUE( @@ -2169,6 +2175,8 @@ TEST_F(CookieMonsterTest, InheritCreationDate) { cookies = GetAllCookies(cm.get()); ASSERT_EQ(1u, cookies.size()); EXPECT_NE(the_not_so_distant_past, cookies[0].CreationDate()); + // If this is flakey you many need to manually set the last update time. + EXPECT_LT(last_update, cookies[0].LastUpdateDate()); } // Check that GetAllCookiesForURL() does not return expired cookies and deletes @@ -2528,9 +2536,9 @@ TEST_F(CookieMonsterTest, BackingStoreCommunication) { cmout.get(), CanonicalCookie::CreateUnsafeCookieForTesting( cookie.name, cookie.value, cookie.domain, cookie.path, - base::Time(), cookie.expiration_time, base::Time(), cookie.secure, - cookie.http_only, cookie.same_site, cookie.priority, - cookie.same_party), + base::Time(), cookie.expiration_time, base::Time(), base::Time(), + cookie.secure, cookie.http_only, cookie.same_site, + cookie.priority, cookie.same_party), cookie.url, true /*modify_httponly*/)); } @@ -2998,20 +3006,21 @@ TEST_F(CookieMonsterTest, SetAllCookies) { CookieList list; list.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "." + http_www_foo_.url().host(), "/", base::Time::Now(), - base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_DEFAULT, false)); + base::Time(), base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false)); list.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( "C", "D", "." + http_www_foo_.url().host(), "/bar", base::Time::Now(), - base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_DEFAULT, false)); + base::Time(), base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false)); list.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( "W", "X", "." + http_www_foo_.url().host(), "/", base::Time::Now(), - base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_DEFAULT, false)); + base::Time(), base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false)); list.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-Y", "Z", https_www_foo_.url().host(), "/", base::Time::Now(), - base::Time(), base::Time(), true, false, CookieSameSite::NO_RESTRICTION, - CookiePriority::COOKIE_PRIORITY_DEFAULT, false, + base::Time(), base::Time(), base::Time(), true, false, + CookieSameSite::NO_RESTRICTION, CookiePriority::COOKIE_PRIORITY_DEFAULT, + false, CookiePartitionKey::FromURLForTesting(GURL("https://toplevelsite.com")))); // SetAllCookies must not flush. @@ -3100,8 +3109,8 @@ TEST_F(CookieMonsterTest, HistogramCheck) { expired_histogram->SnapshotSamples()); auto cookie = CanonicalCookie::CreateUnsafeCookieForTesting( "a", "b", "a.url", "/", base::Time(), - base::Time::Now() + base::Minutes(59), base::Time(), true, false, - CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false); + base::Time::Now() + base::Minutes(59), base::Time(), base::Time(), true, + false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false); GURL source_url = cookie_util::SimulatedCookieSource(*cookie, "https"); ASSERT_TRUE(SetCanonicalCookie(cm.get(), std::move(cookie), source_url, true /*modify_httponly*/)); @@ -3233,9 +3242,10 @@ TEST_F(CookieMonsterTest, ControlCharacterPurge) { "baz", "\x05" "boo", - "." + domain, path, now2, later, base::Time(), true /* secure */, - false /* httponly */, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_DEFAULT, false /* sameparty */); + "." + domain, path, now2, later, base::Time(), base::Time(), + true /* secure */, false /* httponly */, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, + false /* sameparty */); initial_cookies.push_back(std::move(cc)); std::unique_ptr cc2 = @@ -3243,9 +3253,10 @@ TEST_F(CookieMonsterTest, ControlCharacterPurge) { "baz", "\x7F" "boo", - "." + domain, path, now3, later, base::Time(), true /* secure */, - false /* httponly */, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_DEFAULT, false /* sameparty */); + "." + domain, path, now3, later, base::Time(), base::Time(), + true /* secure */, false /* httponly */, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, + false /* sameparty */); initial_cookies.push_back(std::move(cc2)); // Partitioned cookies with control characters should not be loaded. @@ -3256,9 +3267,10 @@ TEST_F(CookieMonsterTest, ControlCharacterPurge) { "__Host-baz", "\x7F" "boo", - domain, "/", now3, later, base::Time(), true /* secure */, - false /* httponly */, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_DEFAULT, false /* sameparty */, cookie_partition_key); + domain, "/", now3, later, base::Time(), base::Time(), + true /* secure */, false /* httponly */, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, + false /* sameparty */, cookie_partition_key); initial_cookies.push_back(std::move(cc3)); AddCookieToList(url, "hello=world; path=" + path, now4, &initial_cookies); diff --git a/net/cookies/cookie_store_unittest.h b/net/cookies/cookie_store_unittest.h index 5e004ee3fa660b..f131f4f10cdd33 100644 --- a/net/cookies/cookie_store_unittest.h +++ b/net/cookies/cookie_store_unittest.h @@ -605,28 +605,28 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) { cs, CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", foo_foo_host, "/foo", one_hour_ago, one_hour_from_now, - base::Time(), false /* secure */, false /* httponly */, + base::Time(), base::Time(), false /* secure */, false /* httponly */, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, false), this->www_foo_foo_.url(), true)); EXPECT_TRUE(this->SetCanonicalCookie( cs, CanonicalCookie::CreateUnsafeCookieForTesting( "C", "D", "." + foo_bar_domain, "/bar", two_hours_ago, base::Time(), - one_hour_ago, false, true, CookieSameSite::LAX_MODE, + one_hour_ago, one_hour_ago, false, true, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, false), this->www_foo_bar_.url(), true)); // A secure source is required for setting secure cookies. - EXPECT_TRUE( - this->SetCanonicalCookieReturnAccessResult( - cs, - CanonicalCookie::CreateUnsafeCookieForTesting( - "E", "F", http_foo_host, "/", base::Time(), base::Time(), - base::Time(), true, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_DEFAULT, false), - this->http_www_foo_.url(), true) - .status.HasExclusionReason( - CookieInclusionStatus::EXCLUDE_SECURE_ONLY)); + EXPECT_TRUE(this->SetCanonicalCookieReturnAccessResult( + cs, + CanonicalCookie::CreateUnsafeCookieForTesting( + "E", "F", http_foo_host, "/", base::Time(), + base::Time(), base::Time(), base::Time(), true, false, + CookieSameSite::NO_RESTRICTION, + COOKIE_PRIORITY_DEFAULT, false), + this->http_www_foo_.url(), true) + .status.HasExclusionReason( + CookieInclusionStatus::EXCLUDE_SECURE_ONLY)); // A Secure cookie can be created from an insecure URL, but is rejected upon // setting. @@ -648,21 +648,22 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) { cs, CanonicalCookie::CreateUnsafeCookieForTesting( "E", "F", https_foo_host, "/", base::Time(), base::Time(), - base::Time(), true /* secure */, false /* httponly */, + base::Time(), base::Time(), true /* secure */, false /* httponly */, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false /* same_party */), this->https_www_foo_.url(), true /* modify_http_only */)); - EXPECT_TRUE(this->SetCanonicalCookieReturnAccessResult( - cs, - CanonicalCookie::CreateUnsafeCookieForTesting( - "E", "F", http_foo_host, "/", base::Time(), - base::Time(), base::Time(), true /* secure */, - false /* httponly */, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_DEFAULT, false /* same_party */), - this->http_www_foo_.url(), true /* modify_http_only */) - .status.HasExclusionReason( - CookieInclusionStatus::EXCLUDE_SECURE_ONLY)); + EXPECT_TRUE( + this->SetCanonicalCookieReturnAccessResult( + cs, + CanonicalCookie::CreateUnsafeCookieForTesting( + "E", "F", http_foo_host, "/", base::Time(), base::Time(), + base::Time(), base::Time(), true /* secure */, + false /* httponly */, CookieSameSite::NO_RESTRICTION, + COOKIE_PRIORITY_DEFAULT, false /* same_party */), + this->http_www_foo_.url(), true /* modify_http_only */) + .status.HasExclusionReason( + CookieInclusionStatus::EXCLUDE_SECURE_ONLY)); if (TypeParam::supports_http_only) { // Permission to modify http only cookies is required to set an @@ -671,9 +672,10 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) { cs, CanonicalCookie::CreateUnsafeCookieForTesting( "G", "H", http_foo_host, "/unique", base::Time(), - base::Time(), base::Time(), false /* secure */, - true /* httponly */, CookieSameSite::LAX_MODE, - COOKIE_PRIORITY_DEFAULT, false /* same_party */), + base::Time(), base::Time(), base::Time(), + false /* secure */, true /* httponly */, + CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, + false /* same_party */), this->http_www_foo_.url(), false /* modify_http_only */) .status.HasExclusionReason( CookieInclusionStatus::EXCLUDE_HTTP_ONLY)); @@ -699,7 +701,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) { cs, CanonicalCookie::CreateUnsafeCookieForTesting( "G", "H", http_foo_host, "/unique", base::Time(), base::Time(), - base::Time(), false /* secure */, true /* httponly */, + base::Time(), base::Time(), false /* secure */, true /* httponly */, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, false /* same_party */), this->http_www_foo_.url(), true /* modify_http_only */)); @@ -708,9 +710,10 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) { cs, CanonicalCookie::CreateUnsafeCookieForTesting( "G", "H", http_foo_host, "/unique", base::Time(), - base::Time(), base::Time(), false /* secure */, - true /* httponly */, CookieSameSite::LAX_MODE, - COOKIE_PRIORITY_DEFAULT, false /* same_party */), + base::Time(), base::Time(), base::Time(), + false /* secure */, true /* httponly */, + CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, + false /* same_party */), this->http_www_foo_.url(), false /* modify_http_only */) .status.HasExclusionReason( CookieInclusionStatus::EXCLUDE_HTTP_ONLY)); @@ -720,7 +723,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) { cs, CanonicalCookie::CreateUnsafeCookieForTesting( "G", "H", http_foo_host, "/unique", base::Time(), base::Time(), - base::Time(), false /* secure */, true /* httponly */, + base::Time(), base::Time(), false /* secure */, true /* httponly */, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, false /* same_party */), this->http_www_foo_.url(), true /* modify_http_only */)); @@ -799,28 +802,28 @@ TYPED_TEST_P(CookieStoreTest, SecureEnforcement) { cs, CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", http_domain, "/", base::Time::Now(), base::Time(), - base::Time(), true, false, CookieSameSite::STRICT_MODE, + base::Time(), base::Time(), true, false, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT, false /* same_party */), http_url, true /*modify_httponly*/)); EXPECT_TRUE(this->SetCanonicalCookie( cs, CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", http_domain, "/", base::Time::Now(), base::Time(), - base::Time(), true, false, CookieSameSite::STRICT_MODE, + base::Time(), base::Time(), true, false, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT, false /* same_party */), https_url, true /*modify_httponly*/)); EXPECT_TRUE(this->SetCanonicalCookie( cs, CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", http_domain, "/", base::Time::Now(), base::Time(), - base::Time(), false, false, CookieSameSite::STRICT_MODE, + base::Time(), base::Time(), false, false, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT, false /* same_party */), https_url, true /*modify_httponly*/)); EXPECT_TRUE(this->SetCanonicalCookie( cs, CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", http_domain, "/", base::Time::Now(), base::Time(), - base::Time(), false, false, CookieSameSite::STRICT_MODE, + base::Time(), base::Time(), false, false, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT, false /* same_party */), http_url, true /*modify_httponly*/)); } diff --git a/net/cookies/cookie_util_unittest.cc b/net/cookies/cookie_util_unittest.cc index 6020776afeae5a..6ab824e266631b 100644 --- a/net/cookies/cookie_util_unittest.cc +++ b/net/cookies/cookie_util_unittest.cc @@ -1538,7 +1538,7 @@ TEST(CookieUtilTest, GetSamePartyStatus_NotInSet) { base::Time now = base::Time::Now(); std::unique_ptr cookie = CanonicalCookie::CreateUnsafeCookieForTesting( - "cookie", "tasty", "example.test", "/", now, now, now, + "cookie", "tasty", "example.test", "/", now, now, now, now, secure, httponly, same_site, CookiePriority::COOKIE_PRIORITY_DEFAULT, same_party); @@ -1575,7 +1575,7 @@ TEST(CookieUtilTest, GetSamePartyStatus_FeatureDisabled) { base::Time now = base::Time::Now(); std::unique_ptr cookie = CanonicalCookie::CreateUnsafeCookieForTesting( - "cookie", "tasty", "example.test", "/", now, now, now, + "cookie", "tasty", "example.test", "/", now, now, now, now, secure, httponly, same_site, CookiePriority::COOKIE_PRIORITY_DEFAULT, same_party); @@ -1611,8 +1611,9 @@ TEST(CookieUtilTest, GetSamePartyStatus_NotSameParty) { base::Time now = base::Time::Now(); std::unique_ptr cookie = CanonicalCookie::CreateUnsafeCookieForTesting( - "cookie", "tasty", "example.test", "/", now, now, now, secure, - httponly, same_site, CookiePriority::COOKIE_PRIORITY_DEFAULT, + "cookie", "tasty", "example.test", "/", now, now, now, now, + secure, httponly, same_site, + CookiePriority::COOKIE_PRIORITY_DEFAULT, false /* same_party */); options.set_same_party_context(SamePartyContext(party_context_type)); @@ -1667,7 +1668,7 @@ TEST(CookieUtilTest, GetSamePartyStatus_SamePartySemantics) { base::Time now = base::Time::Now(); std::unique_ptr cookie = CanonicalCookie::CreateUnsafeCookieForTesting( - "cookie", "tasty", "example.test", "/", now, now, now, + "cookie", "tasty", "example.test", "/", now, now, now, now, true /* secure */, httponly, same_site, CookiePriority::COOKIE_PRIORITY_DEFAULT, true /* same_party */); diff --git a/net/extras/sqlite/sqlite_persistent_cookie_store.cc b/net/extras/sqlite/sqlite_persistent_cookie_store.cc index 97fe7ece9bb651..f7ef5fa51205b8 100644 --- a/net/extras/sqlite/sqlite_persistent_cookie_store.cc +++ b/net/extras/sqlite/sqlite_persistent_cookie_store.cc @@ -1082,6 +1082,7 @@ bool SQLitePersistentCookieStore::Backend::MakeCookiesFromSQLStatement( statement.ColumnTime(0), // creation_utc statement.ColumnTime(6), // expires_utc statement.ColumnTime(9), // last_access_utc + statement.ColumnTime(18), // last_update_utc statement.ColumnBool(7), // secure statement.ColumnBool(8), // http_only DBCookieSameSiteToCookieSameSite(static_cast( @@ -1092,11 +1093,13 @@ bool SQLitePersistentCookieStore::Backend::MakeCookiesFromSQLStatement( std::move(cookie_partition_key), // top_frame_site_key DBToCookieSourceScheme(statement.ColumnInt(15)), // source_scheme statement.ColumnInt(16)); // source_port - // TODO(crbug.com/1264458): Propagate/populate last_update_utc. - DCHECK_EQ(statement.ColumnInt(18), 0); if (cc) { DLOG_IF(WARNING, cc->CreationDate() > Time::Now()) << L"CreationDate too recent"; + if (!cc->LastUpdateDate().is_null()) { + DLOG_IF(WARNING, cc->LastUpdateDate() > Time::Now()) + << L"LastUpdateDate too recent"; + } cookies.push_back(std::move(cc)); } else { RecordCookieLoadProblem(COOKIE_LOAD_PROBLEM_NON_CANONICAL); @@ -1622,8 +1625,7 @@ void SQLitePersistentCookieStore::Backend::DoCommit() { add_statement.BindInt(15, static_cast(po->cc().SourceScheme())); add_statement.BindInt(16, po->cc().SourcePort()); add_statement.BindBool(17, po->cc().IsSameParty()); - // TODO(crbug.com/1264458): Propagate/populate last_update_utc. - add_statement.BindInt(18, 0); + add_statement.BindTime(18, po->cc().LastUpdateDate()); if (!add_statement.Run()) { DLOG(WARNING) << "Could not add a cookie to the DB."; RecordCookieCommitProblem(COOKIE_COMMIT_PROBLEM_ADD); diff --git a/net/extras/sqlite/sqlite_persistent_cookie_store_perftest.cc b/net/extras/sqlite/sqlite_persistent_cookie_store_perftest.cc index d2ace12683d0b6..e48be618b05ce3 100644 --- a/net/extras/sqlite/sqlite_persistent_cookie_store_perftest.cc +++ b/net/extras/sqlite/sqlite_persistent_cookie_store_perftest.cc @@ -89,7 +89,7 @@ class SQLitePersistentCookieStorePerfTest : public testing::Test { std::string domain_name(base::StringPrintf(".domain_%d.com", domain_num)); return *CanonicalCookie::CreateUnsafeCookieForTesting( base::StringPrintf("Cookie_%d", cookie_num), "1", domain_name, "/", t, - t, t, false, false, CookieSameSite::NO_RESTRICTION, + t, t, t, false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false); } diff --git a/net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc b/net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc index acff4dbc3e5620..bfe43d4d2d2395 100644 --- a/net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc +++ b/net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc @@ -184,8 +184,9 @@ class SQLitePersistentCookieStoreTest : public TestWithTaskEnvironment { const std::string& path, const base::Time& creation) { store_->AddCookie(*CanonicalCookie::CreateUnsafeCookieForTesting( - name, value, domain, path, creation, creation, base::Time(), false, - false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false)); + name, value, domain, path, creation, creation, base::Time(), + base::Time(), false, false, CookieSameSite::NO_RESTRICTION, + COOKIE_PRIORITY_DEFAULT, false)); } void AddCookieWithExpiration(const std::string& name, @@ -195,8 +196,9 @@ class SQLitePersistentCookieStoreTest : public TestWithTaskEnvironment { const base::Time& creation, const base::Time& expiration) { store_->AddCookie(*CanonicalCookie::CreateUnsafeCookieForTesting( - name, value, domain, path, creation, expiration, base::Time(), false, - false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false)); + name, value, domain, path, creation, expiration, base::Time(), + base::Time(), false, false, CookieSameSite::NO_RESTRICTION, + COOKIE_PRIORITY_DEFAULT, false)); } std::string ReadRawDBContents() { @@ -533,7 +535,7 @@ TEST_F(SQLitePersistentCookieStoreTest, TestLoadOldSessionCookies) { // Add a session cookie. store_->AddCookie(*CanonicalCookie::CreateUnsafeCookieForTesting( "C", "D", "sessioncookie.com", "/", base::Time::Now(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, + base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false)); // Force the store to write its data to the disk. @@ -560,7 +562,7 @@ TEST_F(SQLitePersistentCookieStoreTest, TestDontLoadOldSessionCookies) { // Add a session cookie. store_->AddCookie(*CanonicalCookie::CreateUnsafeCookieForTesting( "C", "D", "sessioncookie.com", "/", base::Time::Now(), base::Time(), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, + base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false)); // Force the store to write its data to the disk. @@ -598,7 +600,7 @@ TEST_F(SQLitePersistentCookieStoreTest, FilterBadCookiesAndFixupDb) { "value, encrypted_value, path, expires_utc, is_secure, is_httponly, " "samesite, last_access_utc, has_expires, is_persistent, priority, " "source_scheme, source_port, is_same_party, last_update_utc) " - "VALUES (?,?,?,?,?,'',?,0,0,0,0,0,1,1,0,?,?,0,0)")); + "VALUES (?,?,?,?,?,'',?,0,0,0,0,0,1,1,0,?,?,0,?)")); ASSERT_TRUE(stmt.is_valid()); struct CookieInfo { @@ -619,6 +621,7 @@ TEST_F(SQLitePersistentCookieStoreTest, FilterBadCookiesAndFixupDb) { {"chromium.org", "G", "H", "/dir"}}; int64_t creation_time = 1; + base::Time last_update(base::Time::Now()); for (auto& cookie_info : cookies_info) { stmt.Reset(true); @@ -632,6 +635,7 @@ TEST_F(SQLitePersistentCookieStoreTest, FilterBadCookiesAndFixupDb) { stmt.BindString(5, cookie_info.path); stmt.BindInt(6, static_cast(CookieSourceScheme::kUnset)); stmt.BindInt(7, SQLitePersistentCookieStore::kDefaultUnknownPort); + stmt.BindTime(8, last_update); ASSERT_TRUE(stmt.Run()); } stmt.Clear(); @@ -646,6 +650,7 @@ TEST_F(SQLitePersistentCookieStoreTest, FilterBadCookiesAndFixupDb) { EXPECT_STREQ("G", cookies[0]->Name().c_str()); EXPECT_STREQ("H", cookies[0]->Value().c_str()); EXPECT_STREQ("/dir", cookies[0]->Path().c_str()); + EXPECT_EQ(last_update, cookies[0]->LastUpdateDate()); DestroyStore(); // Make sure that we only have one row left. @@ -669,13 +674,13 @@ TEST_F(SQLitePersistentCookieStoreTest, PersistIsPersistent) { // Add a session cookie. store_->AddCookie(*CanonicalCookie::CreateUnsafeCookieForTesting( kSessionName, "val", "sessioncookie.com", "/", base::Time::Now(), - base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, - COOKIE_PRIORITY_DEFAULT, false)); + base::Time(), base::Time(), base::Time(), false, false, + CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false)); // Add a persistent cookie. store_->AddCookie(*CanonicalCookie::CreateUnsafeCookieForTesting( kPersistentName, "val", "sessioncookie.com", "/", base::Time::Now() - base::Days(1), base::Time::Now() + base::Days(1), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, + base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false)); // Force the store to write its data to the disk. @@ -716,21 +721,21 @@ TEST_F(SQLitePersistentCookieStoreTest, PriorityIsPersistent) { store_->AddCookie(*CanonicalCookie::CreateUnsafeCookieForTesting( kLowName, kCookieValue, kDomain, kCookiePath, base::Time::Now() - base::Minutes(1), base::Time::Now() + base::Days(1), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, + base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW, false)); // Add a medium-priority persistent cookie. store_->AddCookie(*CanonicalCookie::CreateUnsafeCookieForTesting( kMediumName, kCookieValue, kDomain, kCookiePath, base::Time::Now() - base::Minutes(2), base::Time::Now() + base::Days(1), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, + base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_MEDIUM, false)); // Add a high-priority persistent cookie. store_->AddCookie(*CanonicalCookie::CreateUnsafeCookieForTesting( kHighName, kCookieValue, kDomain, kCookiePath, base::Time::Now() - base::Minutes(3), base::Time::Now() + base::Days(1), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, + base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_HIGH, false)); // Force the store to write its data to the disk. @@ -777,21 +782,21 @@ TEST_F(SQLitePersistentCookieStoreTest, SameSiteIsPersistent) { store_->AddCookie(*CanonicalCookie::CreateUnsafeCookieForTesting( kNoneName, kCookieValue, kDomain, kCookiePath, base::Time::Now() - base::Minutes(1), base::Time::Now() + base::Days(1), - base::Time(), false, false, CookieSameSite::NO_RESTRICTION, + base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false)); // Add a lax-samesite persistent cookie. store_->AddCookie(*CanonicalCookie::CreateUnsafeCookieForTesting( kLaxName, kCookieValue, kDomain, kCookiePath, base::Time::Now() - base::Minutes(2), base::Time::Now() + base::Days(1), - base::Time(), false, false, CookieSameSite::LAX_MODE, + base::Time(), base::Time(), false, false, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, false)); // Add a strict-samesite persistent cookie. store_->AddCookie(*CanonicalCookie::CreateUnsafeCookieForTesting( kStrictName, kCookieValue, kDomain, kCookiePath, base::Time::Now() - base::Minutes(3), base::Time::Now() + base::Days(1), - base::Time(), false, false, CookieSameSite::STRICT_MODE, + base::Time(), base::Time(), false, false, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT, false)); // Force the store to write its data to the disk. @@ -833,7 +838,7 @@ TEST_F(SQLitePersistentCookieStoreTest, SameSiteExtendedTreatedAsUnspecified) { store_->AddCookie(*CanonicalCookie::CreateUnsafeCookieForTesting( kExtendedName, kCookieValue, kDomain, kCookiePath, base::Time::Now() - base::Minutes(1), base::Time::Now() + base::Days(1), - base::Time(), false, false, CookieSameSite::STRICT_MODE, + base::Time(), base::Time(), false, false, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT, false)); // Force the store to write its data to the disk. @@ -873,7 +878,7 @@ TEST_F(SQLitePersistentCookieStoreTest, SamePartyIsPersistent) { store_->AddCookie(*CanonicalCookie::CreateUnsafeCookieForTesting( kNonSamePartyCookieName, kCookieValue, kDomain, kCookiePath, base::Time::Now() - base::Minutes(1), base::Time::Now() + base::Days(1), - base::Time(), + base::Time(), base::Time(), /*secure=*/true, false, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, /*same_party=*/false)); @@ -881,7 +886,7 @@ TEST_F(SQLitePersistentCookieStoreTest, SamePartyIsPersistent) { store_->AddCookie(*CanonicalCookie::CreateUnsafeCookieForTesting( kSamePartyCookieName, kCookieValue, kDomain, kCookiePath, base::Time::Now() - base::Minutes(1), base::Time::Now() + base::Days(1), - base::Time(), + base::Time(), base::Time(), /*secure=*/true, false, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, /*same_party=*/true)); @@ -931,7 +936,7 @@ TEST_F(SQLitePersistentCookieStoreTest, SourcePortIsPersistent) { store_->AddCookie(*CanonicalCookie::CreateUnsafeCookieForTesting( input.name, kCookieValue, kDomain, kCookiePath, base::Time::Now() - base::Minutes(1), base::Time::Now() + base::Days(1), - base::Time(), + base::Time(), base::Time(), /*secure=*/true, false, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, /*same_party=*/false, @@ -1131,33 +1136,33 @@ bool AddV9CookiesToDB(sql::Database* db) { std::vector cookies; cookies.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "example.com", "/", cookie_time, cookie_time, cookie_time, - false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, - false)); + cookie_time, false, false, CookieSameSite::NO_RESTRICTION, + COOKIE_PRIORITY_DEFAULT, false)); cookie_time += base::Microseconds(1); cookies.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( "C", "B", "example.com", "/", cookie_time, cookie_time, cookie_time, - false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, - false)); + cookie_time, false, false, CookieSameSite::NO_RESTRICTION, + COOKIE_PRIORITY_DEFAULT, false)); cookie_time += base::Microseconds(1); cookies.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "example2.com", "/", cookie_time, cookie_time, cookie_time, - false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, - false)); + cookie_time, false, false, CookieSameSite::NO_RESTRICTION, + COOKIE_PRIORITY_DEFAULT, false)); cookie_time += base::Microseconds(1); cookies.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( "C", "B", "example2.com", "/", cookie_time, cookie_time, cookie_time, - false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, - false)); + cookie_time, false, false, CookieSameSite::NO_RESTRICTION, + COOKIE_PRIORITY_DEFAULT, false)); cookie_time += base::Microseconds(1); cookies.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "example.com", "/path", cookie_time, cookie_time, cookie_time, - false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, - false)); + cookie_time, false, false, CookieSameSite::NO_RESTRICTION, + COOKIE_PRIORITY_DEFAULT, false)); cookie_time += base::Microseconds(1); cookies.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( "C", "B", "example.com", "/path", cookie_time, cookie_time, cookie_time, - false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, - false)); + cookie_time, false, false, CookieSameSite::NO_RESTRICTION, + COOKIE_PRIORITY_DEFAULT, false)); cookie_time += base::Microseconds(1); return AddV9CookiesToDBImpl(db, cookies); } @@ -1280,8 +1285,9 @@ TEST_F(SQLitePersistentCookieStoreTest, UpgradeToSchemaVersion10Corrupted) { base::Time old_time = base::Time::Now() - base::Minutes(90); base::Time old_time2 = base::Time::Now() - base::Minutes(91); auto old_cookie1 = CanonicalCookie::CreateUnsafeCookieForTesting( - "A", "old_value", "example.com", "/", old_time, old_time, old_time, false, - false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false); + "A", "old_value", "example.com", "/", old_time, old_time, old_time, + old_time, false, false, CookieSameSite::NO_RESTRICTION, + COOKIE_PRIORITY_DEFAULT, false); AddV9CookiesToDBImpl(&connection, {*old_cookie1}); // Add the same set of cookies twice to create duplicates. @@ -1291,8 +1297,8 @@ TEST_F(SQLitePersistentCookieStoreTest, UpgradeToSchemaVersion10Corrupted) { // Add some others as well. auto old_cookie2 = CanonicalCookie::CreateUnsafeCookieForTesting( "A", "old_value", "example.com", "/path", old_time2, old_time2, old_time2, - false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, - false); + old_time2, false, false, CookieSameSite::NO_RESTRICTION, + COOKIE_PRIORITY_DEFAULT, false); AddV9CookiesToDBImpl(&connection, {*old_cookie2}); connection.Close(); @@ -1618,22 +1624,22 @@ bool AddV10CookiesToDB(sql::Database* db) { std::vector cookies; cookies.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( - "A", "B", "example.com", "/", time, time, time, false, false, + "A", "B", "example.com", "/", time, time, time, time, false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false)); cookies.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( - "C", "B", "example.com", "/", time, time, time, false, false, + "C", "B", "example.com", "/", time, time, time, time, false, false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT, false)); cookies.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( - "A", "B", "example2.com", "/", time, time, time, false, false, + "A", "B", "example2.com", "/", time, time, time, time, false, false, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, false)); cookies.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( - "C", "B", "example2.com", "/", time, time, time, false, false, + "C", "B", "example2.com", "/", time, time, time, time, false, false, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT, false)); cookies.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( - "A", "B", "example.com", "/path", time, time, time, false, false, + "A", "B", "example.com", "/path", time, time, time, time, false, false, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT, false)); cookies.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( - "C", "B", "example.com", "/path", time, time, time, false, false, + "C", "B", "example.com", "/path", time, time, time, time, false, false, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT, false)); return AddV10CookiesToDBImpl(db, cookies); } @@ -1988,27 +1994,27 @@ std::vector CookiesForMigrationTest() { // Some of these are constructed with SameParty set to true, to test that in // the DB migration, the is_same_party values are all defaulted to false. cookies.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( - "A", "B", "example.com", "/", now, now, now, true /* secure */, + "A", "B", "example.com", "/", now, now, now, now, true /* secure */, false /* httponly */, CookieSameSite::UNSPECIFIED, COOKIE_PRIORITY_DEFAULT, false /* same_party */)); cookies.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( - "C", "B", "example.com", "/", now, now, now, true /* secure */, + "C", "B", "example.com", "/", now, now, now, now, true /* secure */, false /* httponly */, CookieSameSite::UNSPECIFIED, COOKIE_PRIORITY_DEFAULT, true /* same_party */)); cookies.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( - "A", "B", "example2.com", "/", now, now, now, true /* secure */, + "A", "B", "example2.com", "/", now, now, now, now, true /* secure */, false /* httponly */, CookieSameSite::UNSPECIFIED, COOKIE_PRIORITY_DEFAULT, true /* same_party */)); cookies.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( - "C", "B", "example2.com", "/", now, now, now, false /* secure */, + "C", "B", "example2.com", "/", now, now, now, now, false /* secure */, false /* httponly */, CookieSameSite::UNSPECIFIED, COOKIE_PRIORITY_DEFAULT, false /* same_party */)); cookies.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( - "A", "B", "example.com", "/path", now, now, now, false /* secure */, + "A", "B", "example.com", "/path", now, now, now, now, false /* secure */, false /* httponly */, CookieSameSite::UNSPECIFIED, COOKIE_PRIORITY_DEFAULT, false /* same_party */)); cookies.push_back(*CanonicalCookie::CreateUnsafeCookieForTesting( - "C", "B", "example.com", "/path", now, now, now, false /* secure */, + "C", "B", "example.com", "/path", now, now, now, now, false /* secure */, false /* httponly */, CookieSameSite::UNSPECIFIED, COOKIE_PRIORITY_DEFAULT, false /* same_party */)); return cookies; @@ -2237,7 +2243,7 @@ void ConfirmCookiesAfterMigrationTest( EXPECT_TRUE(read_in_cookies[i]->IsSecure()); EXPECT_EQ(CookieSourceScheme::kUnset, read_in_cookies[i]->SourceScheme()); EXPECT_FALSE(read_in_cookies[i]->IsSameParty()); - // TODO(crbug.com/1264458): Propagate/populate last_update_utc. + EXPECT_TRUE(read_in_cookies[i]->LastUpdateDate().is_null()); i++; EXPECT_EQ("A", read_in_cookies[i]->Name()); @@ -2247,7 +2253,7 @@ void ConfirmCookiesAfterMigrationTest( EXPECT_FALSE(read_in_cookies[i]->IsSecure()); EXPECT_EQ(CookieSourceScheme::kUnset, read_in_cookies[i]->SourceScheme()); EXPECT_FALSE(read_in_cookies[i]->IsSameParty()); - // TODO(crbug.com/1264458): Propagate/populate last_update_utc. + EXPECT_TRUE(read_in_cookies[i]->LastUpdateDate().is_null()); i++; EXPECT_EQ("A", read_in_cookies[i]->Name()); @@ -2257,7 +2263,7 @@ void ConfirmCookiesAfterMigrationTest( EXPECT_TRUE(read_in_cookies[i]->IsSecure()); EXPECT_EQ(CookieSourceScheme::kUnset, read_in_cookies[i]->SourceScheme()); EXPECT_EQ(expect_same_party_cookies, read_in_cookies[i]->IsSameParty()); - // TODO(crbug.com/1264458): Propagate/populate last_update_utc. + EXPECT_TRUE(read_in_cookies[i]->LastUpdateDate().is_null()); i++; EXPECT_EQ("C", read_in_cookies[i]->Name()); @@ -2267,7 +2273,7 @@ void ConfirmCookiesAfterMigrationTest( EXPECT_TRUE(read_in_cookies[i]->IsSecure()); EXPECT_EQ(CookieSourceScheme::kUnset, read_in_cookies[i]->SourceScheme()); EXPECT_EQ(expect_same_party_cookies, read_in_cookies[i]->IsSameParty()); - // TODO(crbug.com/1264458): Propagate/populate last_update_utc. + EXPECT_TRUE(read_in_cookies[i]->LastUpdateDate().is_null()); i++; EXPECT_EQ("C", read_in_cookies[i]->Name()); @@ -2277,7 +2283,7 @@ void ConfirmCookiesAfterMigrationTest( EXPECT_FALSE(read_in_cookies[i]->IsSecure()); EXPECT_EQ(CookieSourceScheme::kUnset, read_in_cookies[i]->SourceScheme()); EXPECT_FALSE(read_in_cookies[i]->IsSameParty()); - // TODO(crbug.com/1264458): Propagate/populate last_update_utc. + EXPECT_TRUE(read_in_cookies[i]->LastUpdateDate().is_null()); i++; EXPECT_EQ("C", read_in_cookies[i]->Name()); @@ -2287,7 +2293,7 @@ void ConfirmCookiesAfterMigrationTest( EXPECT_FALSE(read_in_cookies[i]->IsSecure()); EXPECT_EQ(CookieSourceScheme::kUnset, read_in_cookies[i]->SourceScheme()); EXPECT_FALSE(read_in_cookies[i]->IsSameParty()); - // TODO(crbug.com/1264458): Propagate/populate last_update_utc. + EXPECT_TRUE(read_in_cookies[i]->LastUpdateDate().is_null()); } // Confirm that source_scheme gets added and is set to "Unset". @@ -2418,8 +2424,9 @@ TEST_P(PartitionedCookiesSQLitePersistentCookieStoreTest, store_->AddCookie(*CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-foo", "bar", GURL("https://example.com/").host(), "/", base::Time::Now(), base::Time::Now() + base::Days(1), base::Time::Now(), - true /* secure */, false /* httponly */, CookieSameSite::UNSPECIFIED, - COOKIE_PRIORITY_DEFAULT, false /* sameparty */, + base::Time::Now(), true /* secure */, false /* httponly */, + CookieSameSite::UNSPECIFIED, COOKIE_PRIORITY_DEFAULT, + false /* sameparty */, CookiePartitionKey::FromURLForTesting(GURL("https://toplevelsite.com")))); Flush(); @@ -2445,12 +2452,13 @@ TEST_P(PartitionedCookiesSQLitePersistentCookieStoreTest, "value, encrypted_value, path, expires_utc, is_secure, is_httponly, " "samesite, last_access_utc, has_expires, is_persistent, priority, " "source_scheme, source_port, is_same_party, last_update_utc) " - "VALUES (?,?,?,?,?,'',?,?,1,0,0,?,1,1,0,?,?,0,0)")); + "VALUES (?,?,?,?,?,'',?,?,1,0,0,?,1,1,0,?,?,0,?)")); ASSERT_TRUE(stmt.is_valid()); base::Time creation(base::Time::Now()); base::Time expiration(creation + base::Days(1)); base::Time last_access(base::Time::Now()); + base::Time last_update(base::Time::Now()); stmt.BindTime(0, creation); stmt.BindString(1, GURL("https://www.example.com/").host()); @@ -2462,6 +2470,7 @@ TEST_P(PartitionedCookiesSQLitePersistentCookieStoreTest, stmt.BindTime(7, last_access); stmt.BindInt(8, static_cast(CookieSourceScheme::kUnset)); stmt.BindInt(9, SQLitePersistentCookieStore::kDefaultUnknownPort); + stmt.BindTime(10, last_update); ASSERT_TRUE(stmt.Run()); stmt.Clear(); @@ -2478,6 +2487,7 @@ TEST_P(PartitionedCookiesSQLitePersistentCookieStoreTest, EXPECT_EQ( CookiePartitionKey::FromURLForTesting(GURL("https://toplevelsite.com")), cc->PartitionKey()); + EXPECT_EQ(last_update, cc->LastUpdateDate()); } else { EXPECT_EQ(0u, cookies.size()); // If Partitioned cookies are disabled, then we should delete any diff --git a/services/network/cookie_manager.cc b/services/network/cookie_manager.cc index c47a0482919499..07c1fb882adc8c 100644 --- a/services/network/cookie_manager.cc +++ b/services/network/cookie_manager.cc @@ -176,9 +176,9 @@ void CookieManager::OnGotFirstPartySetPartitionKeyForSet( cookie = net::CanonicalCookie::FromStorage( cookie->Name(), cookie->Value(), cookie->Domain(), cookie->Path(), cookie->CreationDate(), cookie->ExpiryDate(), cookie->LastAccessDate(), - cookie->IsSecure(), cookie->IsHttpOnly(), cookie->SameSite(), - cookie->Priority(), cookie->IsSameParty(), fps_cookie_partition_key, - cookie->SourceScheme(), cookie->SourcePort()); + cookie->LastUpdateDate(), cookie->IsSecure(), cookie->IsHttpOnly(), + cookie->SameSite(), cookie->Priority(), cookie->IsSameParty(), + fps_cookie_partition_key, cookie->SourceScheme(), cookie->SourcePort()); if (!cookie) { std::move(callback).Run( net::CookieAccessResult(net::CookieInclusionStatus( diff --git a/services/network/cookie_manager_unittest.cc b/services/network/cookie_manager_unittest.cc index b39d785ccb708d..9f3f6cbef86102 100644 --- a/services/network/cookie_manager_unittest.cc +++ b/services/network/cookie_manager_unittest.cc @@ -458,36 +458,36 @@ TEST_F(CookieManagerTest, GetAllCookies) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", kCookieDomain, "/", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "C", "D", "foo_host2", "/with/path", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "C", "D", "foo_host2", "/with/path", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "Secure", "E", kCookieDomain, "/with/path", base::Time(), - base::Time(), base::Time(), /*secure=*/true, + base::Time(), base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "HttpOnly", "F", kCookieDomain, "/with/path", - base::Time(), base::Time(), base::Time(), - /*secure=*/false, - /*httponly=*/true, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "HttpOnly", "F", kCookieDomain, "/with/path", base::Time(), + base::Time(), base::Time(), base::Time(), + /*secure=*/false, + /*httponly=*/true, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "SecureSameParty", "G", kCookieDomain, "/with/path", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/true), @@ -596,29 +596,29 @@ TEST_F(CookieManagerTest, GetAllCookiesWithAccessSemantics) { // starts sorting the cookies differently. // UNKNOWN - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A", "B", "domain1.test", - "/this/path/is/the/longest/for/sorting/purposes", - base::Time(), base::Time(), base::Time(), - /*secure=*/true, /*httponly=*/false, - net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A", "B", "domain1.test", + "/this/path/is/the/longest/for/sorting/purposes", base::Time(), + base::Time(), base::Time(), base::Time(), + /*secure=*/true, /*httponly=*/false, + net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, + /*same_party=*/false), + "https", true)); // LEGACY - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "C", "D", "domain2.test", "/with/longer/path", - base::Time(), base::Time(), base::Time(), - /*secure=*/true, /*httponly=*/false, - net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "C", "D", "domain2.test", "/with/longer/path", base::Time(), + base::Time(), base::Time(), base::Time(), + /*secure=*/true, /*httponly=*/false, + net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, + /*same_party=*/false), + "https", true)); // not set (UNKNOWN) EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "HttpOnly", "F", "domain3.test", "/with/path", base::Time(), - base::Time(), base::Time(), /*secure=*/true, + base::Time(), base::Time(), base::Time(), /*secure=*/true, /*httponly=*/true, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -626,7 +626,7 @@ TEST_F(CookieManagerTest, GetAllCookiesWithAccessSemantics) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "Secure", "E", ".domainwithdot.test", "/", base::Time(), base::Time(), - base::Time(), /*secure=*/true, + base::Time(), base::Time(), /*secure=*/true, /*httponly=*/true, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -654,33 +654,33 @@ TEST_F(CookieManagerTest, GetCookieList) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", kCookieDomain, "/", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "C", "D", "foo_host2", "/with/path", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "Secure", "E", kCookieDomain, "/with/path", - base::Time(), base::Time(), base::Time(), - /*secure=*/true, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "HttpOnly", "F", kCookieDomain, "/with/path", - base::Time(), base::Time(), base::Time(), - /*secure=*/false, - /*httponly=*/true, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "C", "D", "foo_host2", "/with/path", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "Secure", "E", kCookieDomain, "/with/path", base::Time(), + base::Time(), base::Time(), base::Time(), + /*secure=*/true, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "HttpOnly", "F", kCookieDomain, "/with/path", base::Time(), + base::Time(), base::Time(), base::Time(), + /*secure=*/false, + /*httponly=*/true, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); // Want the SameSite=lax cookies, but not httponly ones. net::CookieOptions options; @@ -720,7 +720,7 @@ TEST_F(CookieManagerTest, GetCookieListHttpOnly) { result = SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", kCookieDomain, "/", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/true, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true); @@ -728,7 +728,7 @@ TEST_F(CookieManagerTest, GetCookieListHttpOnly) { result = SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "C", "D", kCookieDomain, "/", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true); @@ -772,24 +772,24 @@ TEST_F(CookieManagerTest, GetCookieListSameSite) { result = SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", kCookieDomain, "/", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true); ASSERT_TRUE(result); - result = - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "C", "D", kCookieDomain, "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true); + result = SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "C", "D", kCookieDomain, "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true); ASSERT_TRUE(result); result = SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "E", "F", kCookieDomain, "/", base::Time(), base::Time(), - base::Time(), /*secure=*/false, + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::STRICT_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true); @@ -854,30 +854,30 @@ TEST_F(CookieManagerTest, GetCookieListSameParty) { ASSERT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "nonSameParty-Unspecified", "A", kCookieDomain, "/", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::UNSPECIFIED, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); ASSERT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "SameParty-Unspecified", "B", kCookieDomain, "/", base::Time(), - base::Time(), base::Time(), /*secure=*/true, + base::Time(), base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::UNSPECIFIED, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/true), "https", true)); // None: - ASSERT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "nonSameParty-None", "C", kCookieDomain, "/", - base::Time(), base::Time(), base::Time(), - /*secure=*/true, /*httponly=*/false, - net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + ASSERT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "nonSameParty-None", "C", kCookieDomain, "/", base::Time(), + base::Time(), base::Time(), base::Time(), + /*secure=*/true, /*httponly=*/false, + net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, + /*same_party=*/false), + "https", true)); ASSERT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "SameParty-None", "D", kCookieDomain, "/", base::Time(), base::Time(), - base::Time(), /*secure=*/true, + base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/true), "https", true)); @@ -885,14 +885,14 @@ TEST_F(CookieManagerTest, GetCookieListSameParty) { ASSERT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "nonSameParty-Lax", "E", kCookieDomain, "/", base::Time(), - base::Time(), base::Time(), /*secure=*/true, + base::Time(), base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); ASSERT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "SameParty-Lax", "F", kCookieDomain, "/", base::Time(), base::Time(), - base::Time(), /*secure=*/true, + base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/true), "https", true)); @@ -1028,7 +1028,7 @@ TEST_F(CookieManagerTest, GetCookieListCookiePartitionKeyCollection) { ASSERT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-A", "1", kCookieDomain, "/", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false, /*partition_key=*/absl::nullopt), @@ -1037,7 +1037,7 @@ TEST_F(CookieManagerTest, GetCookieListCookiePartitionKeyCollection) { ASSERT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-B", "2", kCookieDomain, "/", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false, absl::make_optional( @@ -1047,7 +1047,7 @@ TEST_F(CookieManagerTest, GetCookieListCookiePartitionKeyCollection) { ASSERT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-C", "3", kCookieDomain, "/", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false, absl::make_optional( @@ -1057,7 +1057,7 @@ TEST_F(CookieManagerTest, GetCookieListCookiePartitionKeyCollection) { ASSERT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-D", "4", kCookieDomain, "/", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false, absl::make_optional( @@ -1115,7 +1115,7 @@ TEST_F(CookieManagerTest, GetCookieListAccessTime) { bool result = SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", kCookieDomain, "/", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true); @@ -1153,6 +1153,7 @@ TEST_F(CookieManagerTest, DeleteCanonicalCookie) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "foo_host", "/", base::Time(), base::Time(), base::Time(), + base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -1168,38 +1169,39 @@ TEST_F(CookieManagerTest, DeleteThroughSet) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", kCookieDomain, "/", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "C", "D", "foo_host2", "/with/path", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "Secure", "E", kCookieDomain, "/with/path", - base::Time(), base::Time(), base::Time(), - /*secure=*/true, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "HttpOnly", "F", kCookieDomain, "/with/path", - base::Time(), base::Time(), base::Time(), - /*secure=*/false, - /*httponly=*/true, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "C", "D", "foo_host2", "/with/path", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "Secure", "E", kCookieDomain, "/with/path", base::Time(), + base::Time(), base::Time(), base::Time(), + /*secure=*/true, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "HttpOnly", "F", kCookieDomain, "/with/path", base::Time(), + base::Time(), base::Time(), base::Time(), + /*secure=*/false, + /*httponly=*/true, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); base::Time yesterday = base::Time::Now() - base::Days(1); EXPECT_TRUE(service_wrapper()->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A", "E", kCookieDomain, "/", base::Time(), yesterday, base::Time(), + base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "http", false)); @@ -1225,7 +1227,7 @@ TEST_F(CookieManagerTest, ConfirmSecureSetFails) { service_wrapper()->SetCanonicalCookieWithAccessResult( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "N", "O", kCookieDomain, "/", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), @@ -1316,7 +1318,7 @@ TEST_F(CookieManagerTest, ConfirmHttpOnlySetFails) { service_wrapper()->SetCanonicalCookieWithAccessResult( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "N", "O", kCookieDomain, "/", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/true, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), @@ -1333,20 +1335,20 @@ TEST_F(CookieManagerTest, ConfirmHttpOnlySetFails) { } TEST_F(CookieManagerTest, ConfirmSecureOverwriteFails) { - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "Secure", "F", kCookieDomain, "/with/path", - base::Time(), base::Time(), base::Time(), - /*secure=*/true, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "Secure", "F", kCookieDomain, "/with/path", base::Time(), + base::Time(), base::Time(), base::Time(), + /*secure=*/true, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); net::CookieAccessResult access_result = service_wrapper()->SetCanonicalCookieWithAccessResult( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "Secure", "Nope", kCookieDomain, "/with/path", base::Time(), - base::Time(), base::Time(), /*secure=*/false, + base::Time(), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "http", false); @@ -1365,20 +1367,20 @@ TEST_F(CookieManagerTest, ConfirmSecureOverwriteFails) { } TEST_F(CookieManagerTest, ConfirmHttpOnlyOverwriteFails) { - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "HttpOnly", "F", kCookieDomain, "/with/path", - base::Time(), base::Time(), base::Time(), - /*secure=*/false, - /*httponly=*/true, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "http", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "HttpOnly", "F", kCookieDomain, "/with/path", base::Time(), + base::Time(), base::Time(), base::Time(), + /*secure=*/false, + /*httponly=*/true, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "http", true)); net::CookieAccessResult access_result = service_wrapper()->SetCanonicalCookieWithAccessResult( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "HttpOnly", "Nope", kCookieDomain, "/with/path", base::Time(), - base::Time(), base::Time(), /*secure=*/false, + base::Time(), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", false); @@ -1401,32 +1403,32 @@ TEST_F(CookieManagerTest, DeleteEverything) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", kCookieDomain, "/", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "C", "D", "foo_host2", "/with/path", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "C", "D", "foo_host2", "/with/path", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "Secure", "E", kCookieDomain, "/with/path", base::Time(), - base::Time(), base::Time(), /*secure=*/true, + base::Time(), base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "HttpOnly", "F", kCookieDomain, "/with/path", - base::Time(), base::Time(), base::Time(), - /*secure=*/false, - /*httponly=*/true, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "HttpOnly", "F", kCookieDomain, "/with/path", base::Time(), + base::Time(), base::Time(), base::Time(), + /*secure=*/false, + /*httponly=*/true, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); mojom::CookieDeletionFilter filter; EXPECT_EQ(4u, service_wrapper()->DeleteCookies(filter)); @@ -1443,7 +1445,7 @@ TEST_F(CookieManagerTest, DeleteByTime) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A1", "val", kCookieDomain, "/", now - base::Minutes(60), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -1451,7 +1453,7 @@ TEST_F(CookieManagerTest, DeleteByTime) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A2", "val", kCookieDomain, "/", now - base::Minutes(120), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -1459,7 +1461,7 @@ TEST_F(CookieManagerTest, DeleteByTime) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A3", "val", kCookieDomain, "/", now - base::Minutes(180), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -1478,29 +1480,29 @@ TEST_F(CookieManagerTest, DeleteByTime) { TEST_F(CookieManagerTest, DeleteByExcludingDomains) { // Create three cookies and delete the middle one. - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A1", "val", "foo_host1", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A1", "val", "foo_host1", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A2", "val", "foo_host2", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A2", "val", "foo_host2", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A3", "val", "foo_host3", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A3", "val", "foo_host3", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); mojom::CookieDeletionFilter filter; filter.excluding_domains = std::vector(); @@ -1514,29 +1516,29 @@ TEST_F(CookieManagerTest, DeleteByExcludingDomains) { TEST_F(CookieManagerTest, DeleteByIncludingDomains) { // Create three cookies and delete the middle one. - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A1", "val", "foo_host1", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A1", "val", "foo_host1", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A2", "val", "foo_host2", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A2", "val", "foo_host2", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A3", "val", "foo_host3", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A3", "val", "foo_host3", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); mojom::CookieDeletionFilter filter; filter.including_domains = std::vector(); @@ -1551,25 +1553,25 @@ TEST_F(CookieManagerTest, DeleteByIncludingDomains) { // Confirm deletion is based on eTLD+1 TEST_F(CookieManagerTest, DeleteDetails_eTLD) { - // Two domains on diferent levels of the same eTLD both get deleted. - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A1", "val", "example.com", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A2", "val", "www.example.com", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + // Two domains on different levels of the same eTLD both get deleted. + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A1", "val", "example.com", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A2", "val", "www.example.com", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A3", "val", "www.nonexample.com", "/", base::Time(), base::Time(), - base::Time(), /*secure=*/false, + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -1586,24 +1588,24 @@ TEST_F(CookieManagerTest, DeleteDetails_eTLD) { EXPECT_EQ(1u, service_wrapper()->DeleteCookies(filter)); // Same thing happens on an eTLD+1 which isn't a TLD+1. - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A1", "val", "example.co.uk", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A1", "val", "example.co.uk", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A2", "val", "www.example.co.uk", "/", base::Time(), base::Time(), - base::Time(), /*secure=*/false, + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A3", "val", "www.nonexample.co.uk", "/", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -1618,24 +1620,24 @@ TEST_F(CookieManagerTest, DeleteDetails_eTLD) { // Deletion of a second level domain that's an eTLD doesn't delete any // subdomains. - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A1", "val", "example.co.uk", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A1", "val", "example.co.uk", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A2", "val", "www.example.co.uk", "/", base::Time(), base::Time(), - base::Time(), /*secure=*/false, + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A3", "val", "www.nonexample.co.uk", "/", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -1654,34 +1656,34 @@ TEST_F(CookieManagerTest, DeleteDetails_HostDomain) { // Create four cookies: A host (no leading .) and domain cookie // (leading .) for each of two separate domains. Confirm that the // filter deletes both of one domain and leaves the other alone. - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A1", "val", "foo_host.com", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A2", "val", ".foo_host.com", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A3", "val", "bar.host.com", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A4", "val", ".bar.host.com", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A1", "val", "foo_host.com", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A2", "val", ".foo_host.com", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A3", "val", "bar.host.com", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A4", "val", ".bar.host.com", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); mojom::CookieDeletionFilter filter; filter.including_domains = std::vector(); @@ -1696,40 +1698,41 @@ TEST_F(CookieManagerTest, DeleteDetails_HostDomain) { } TEST_F(CookieManagerTest, DeleteDetails_eTLDvsPrivateRegistry) { - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A1", "val", "random.co.uk", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A1", "val", "random.co.uk", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A2", "val", "sub.domain.random.co.uk", "/", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A3", "val", "random.com", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A3", "val", "random.com", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A4", "val", "random", "/", base::Time(), base::Time(), base::Time(), + base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A5", "val", "normal.co.uk", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A5", "val", "normal.co.uk", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); mojom::CookieDeletionFilter filter; filter.including_domains = std::vector(); @@ -1745,20 +1748,20 @@ TEST_F(CookieManagerTest, DeleteDetails_eTLDvsPrivateRegistry) { } TEST_F(CookieManagerTest, DeleteDetails_PrivateRegistry) { - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A1", "val", "privatedomain", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A1", "val", "privatedomain", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( // Will not actually be treated as a private domain as it's under // .com. "A2", "val", "privatedomain.com", "/", base::Time(), base::Time(), - base::Time(), /*secure=*/false, /*httponly=*/false, + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -1768,8 +1771,9 @@ TEST_F(CookieManagerTest, DeleteDetails_PrivateRegistry) { // Will not actually be treated as a private domain as it's two // level "A3", "val", "subdomain.privatedomain", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, - net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, + base::Time(), base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -1803,14 +1807,14 @@ TEST_F(CookieManagerTest, DeleteDetails_IgnoredFields) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A01", "RandomValue", "example.com", "/", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A02", "RandomValue", "canonical.com", "/", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -1819,15 +1823,16 @@ TEST_F(CookieManagerTest, DeleteDetails_IgnoredFields) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A03", "val", "example.com", "/this/is/a/long/path", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A04", "val", "canonical.com", "/this/is/a/long/path", base::Time(), - base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, - net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, + base::Time(), base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -1835,14 +1840,16 @@ TEST_F(CookieManagerTest, DeleteDetails_IgnoredFields) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A05", "val", "example.com", "/", base::Time::Now() - base::Days(3), - base::Time(), base::Time::Now() - base::Days(3), /*secure=*/false, + base::Time(), base::Time::Now() - base::Days(3), base::Time(), + /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A06", "val", "canonical.com", "/", base::Time::Now() - base::Days(3), - base::Time(), base::Time::Now() - base::Days(3), /*secure=*/false, + base::Time(), base::Time::Now() - base::Days(3), base::Time(), + /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -1851,33 +1858,33 @@ TEST_F(CookieManagerTest, DeleteDetails_IgnoredFields) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A07", "val", "example.com", "/", base::Time(), base::Time(), - base::Time(), /*secure=*/false, + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::STRICT_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A08", "val", "canonical.com", "/", base::Time(), base::Time(), - base::Time(), /*secure=*/false, + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::STRICT_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); // Priority - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A09", "val", "example.com", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_HIGH, /*same_party=*/false), - "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A10", "val", "canonical.com", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_HIGH, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A09", "val", "example.com", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_HIGH, /*same_party=*/false), + "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A10", "val", "canonical.com", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_HIGH, /*same_party=*/false), + "https", true)); // Use the filter and make sure the result is the expected set. EXPECT_EQ(5u, service_wrapper()->DeleteCookies(filter)); @@ -1969,8 +1976,9 @@ TEST_F(CookieManagerTest, DeleteDetails_Consumer) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A1", "val", test_cases[i].domain, test_cases[i].path, base::Time(), - base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, - net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, + base::Time(), base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -1979,7 +1987,8 @@ TEST_F(CookieManagerTest, DeleteDetails_Consumer) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A2", "val", "." + test_cases[i].domain, test_cases[i].path, - base::Time(), base::Time(), base::Time(), /*secure=*/false, + base::Time(), base::Time(), base::Time(), base::Time(), + /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -1989,8 +1998,9 @@ TEST_F(CookieManagerTest, DeleteDetails_Consumer) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A3", "val", test_cases[i].domain, test_cases[i].path, base::Time(), - base::Time(), base::Time(), /*secure=*/false, /*httponly=*/true, - net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, + base::Time(), base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/true, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -1998,8 +2008,9 @@ TEST_F(CookieManagerTest, DeleteDetails_Consumer) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A4", "val", test_cases[i].domain, test_cases[i].path, base::Time(), - base::Time(), base::Time(), /*secure=*/false, /*httponly=*/true, - net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, + base::Time(), base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/true, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -2017,37 +2028,37 @@ TEST_F(CookieManagerTest, DeleteDetails_Consumer) { TEST_F(CookieManagerTest, DeleteByName) { // Create cookies with varying (name, host) - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A1", "val", kCookieDomain, "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true /*modify_httponly*/)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A1", "val", kCookieDomain, "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true /*modify_httponly*/)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A1", "val", "bar_host", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true /*modify_httponly*/)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A1", "val", "bar_host", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true /*modify_httponly*/)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A2", "val", kCookieDomain, "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true /*modify_httponly*/)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A2", "val", kCookieDomain, "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true /*modify_httponly*/)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A3", "val", "bar_host", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true /*modify_httponly*/)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A3", "val", "bar_host", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true /*modify_httponly*/)); mojom::CookieDeletionFilter filter; filter.cookie_name = std::string("A1"); @@ -2065,21 +2076,21 @@ TEST_F(CookieManagerTest, DeleteByURL) { GURL filter_url("http://www.example.com/path"); // Cookie that shouldn't be deleted because it's secure. - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A01", "val", "www.example.com", "/path", - base::Time(), base::Time(), base::Time(), - /*secure=*/true, /*httponly=*/false, - net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true /*modify_httponly*/)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A01", "val", "www.example.com", "/path", base::Time(), base::Time(), + base::Time(), base::Time(), + /*secure=*/true, /*httponly=*/false, + net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, + /*same_party=*/false), + "https", true /*modify_httponly*/)); // Cookie that should not be deleted because it's a host cookie in a // subdomain that doesn't exactly match the passed URL. EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A02", "val", "sub.www.example.com", "/path", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true /*modify_httponly*/)); @@ -2088,7 +2099,7 @@ TEST_F(CookieManagerTest, DeleteByURL) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A03", "val", "www.example.com", "/otherpath", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true /*modify_httponly*/)); @@ -2098,27 +2109,27 @@ TEST_F(CookieManagerTest, DeleteByURL) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A04", "val", "www.example.com", "/path/path2", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true /*modify_httponly*/)); // Cookie that shouldn't be deleted because it's at a host cookie domain that // doesn't exactly match the url's host. - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A05", "val", "example.com", "/path", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true /*modify_httponly*/)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A05", "val", "example.com", "/path", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true /*modify_httponly*/)); // Cookie that should not be deleted because it's not a host cookie and // has a domain that's more specific than the URL EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A06", "val", ".sub.www.example.com", "/path", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true /*modify_httponly*/)); @@ -2128,7 +2139,7 @@ TEST_F(CookieManagerTest, DeleteByURL) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A07", "val", ".www.example.com", "/path", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true /*modify_httponly*/)); @@ -2138,7 +2149,7 @@ TEST_F(CookieManagerTest, DeleteByURL) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A08", "val", ".example.com", "/path", base::Time(), base::Time(), - base::Time(), /*secure=*/false, + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true /*modify_httponly*/)); @@ -2147,20 +2158,20 @@ TEST_F(CookieManagerTest, DeleteByURL) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A09", "val", "www.example.com", "/path", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true /*modify_httponly*/)); // Cookie that should be deleted because it applies to a larger set // of paths than the URL path. - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A10", "val", "www.example.com", "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true /*modify_httponly*/)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A10", "val", "www.example.com", "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true /*modify_httponly*/)); mojom::CookieDeletionFilter filter; filter.url = filter_url; @@ -2182,29 +2193,29 @@ TEST_F(CookieManagerTest, DeleteBySessionStatus) { base::Time now(base::Time::Now()); // Create three cookies and delete the middle one. - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A1", "val", kCookieDomain, "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A1", "val", kCookieDomain, "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A2", "val", kCookieDomain, "/", base::Time(), now + base::Days(1), - base::Time(), + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); - EXPECT_TRUE( - SetCanonicalCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A3", "val", kCookieDomain, "/", base::Time(), - base::Time(), base::Time(), /*secure=*/false, - /*httponly=*/false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), - "https", true)); + EXPECT_TRUE(SetCanonicalCookie( + *net::CanonicalCookie::CreateUnsafeCookieForTesting( + "A3", "val", kCookieDomain, "/", base::Time(), base::Time(), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), + "https", true)); mojom::CookieDeletionFilter filter; filter.session_control = @@ -2254,7 +2265,7 @@ TEST_F(CookieManagerTest, DeleteByAll) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A1", "val0", "nope.com", "/path", now - base::Days(3), - now + base::Days(3), base::Time(), /*secure=*/false, + now + base::Days(3), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -2263,7 +2274,7 @@ TEST_F(CookieManagerTest, DeleteByAll) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A2", "val1", "nope.com", "/path", now - base::Days(5), - now + base::Days(3), base::Time(), /*secure=*/false, + now + base::Days(3), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -2272,7 +2283,7 @@ TEST_F(CookieManagerTest, DeleteByAll) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A3", "val2", "nope.com", "/path", now - base::Days(1), - now + base::Days(3), base::Time(), /*secure=*/false, + now + base::Days(3), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -2281,7 +2292,7 @@ TEST_F(CookieManagerTest, DeleteByAll) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A4", "val3", "other.com", "/path", now - base::Days(3), - now + base::Days(3), base::Time(), + now + base::Days(3), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), @@ -2291,7 +2302,7 @@ TEST_F(CookieManagerTest, DeleteByAll) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A5", "val4", "no.com", "/path", now - base::Days(3), - now + base::Days(3), base::Time(), /*secure=*/false, + now + base::Days(3), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -2300,7 +2311,7 @@ TEST_F(CookieManagerTest, DeleteByAll) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A6", "val6", "nope.com", "/otherpath", now - base::Days(3), - now + base::Days(3), base::Time(), + now + base::Days(3), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), @@ -2310,7 +2321,7 @@ TEST_F(CookieManagerTest, DeleteByAll) { EXPECT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "A7", "val7", "nope.com", "/path", now - base::Days(3), base::Time(), - base::Time(), /*secure=*/false, /*httponly=*/false, + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -2388,7 +2399,7 @@ TEST_F(CookieManagerTest, AddCookieChangeListener) { service_wrapper()->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "DifferentName", "val", listener_url_host, "/", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), @@ -2401,7 +2412,7 @@ TEST_F(CookieManagerTest, AddCookieChangeListener) { service_wrapper()->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( listener_cookie_name, "val", "www.other.host", "/", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), @@ -2414,7 +2425,7 @@ TEST_F(CookieManagerTest, AddCookieChangeListener) { service_wrapper()->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( listener_cookie_name, "val", listener_url_host, "/", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), @@ -2470,7 +2481,7 @@ TEST_F(CookieManagerTest, AddGlobalChangeListener) { service_wrapper()->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "Thing1", "val", kExampleHost, "/", base::Time(), base::Time(), - base::Time(), /*secure=*/false, + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true); @@ -2494,14 +2505,14 @@ TEST_F(CookieManagerTest, AddGlobalChangeListener) { service_wrapper()->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "Thing1", "val", kThisHost, "/", base::Time(), base::Time(), - base::Time(), /*secure=*/false, + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true); service_wrapper()->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "Thing2", "val", kThatHost, "/", base::Time(), base::Time(), - base::Time(), /*secure=*/false, + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true); @@ -2557,7 +2568,7 @@ TEST_F(CookieManagerTest, ListenerDestroyed) { service_wrapper()->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( listener_cookie_name, "val", listener_url_host, "/", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), @@ -2612,7 +2623,7 @@ TEST_F(CookieManagerTest, CloningAndClientDestructVisible) { EXPECT_TRUE(new_wrapper.SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "X", "Y", "www.other.host", "/", base::Time(), base::Time(), - base::Time(), /*secure=*/false, + base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false), "https", true)); @@ -2787,7 +2798,7 @@ class SessionCleanupCookieManagerTest : public CookieManagerTest { net::CanonicalCookie CreateCookie(const std::string& domain) { base::Time t = base::Time::Now(); return *net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A", "B", domain, "/", t, t + base::Days(1), base::Time(), + "A", "B", domain, "/", t, t + base::Days(1), base::Time(), base::Time(), /*secure=*/false, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false); } @@ -2975,7 +2986,7 @@ TEST_F(FPSPartitionedCookiesCookieManagerTest, GetCookieList) { ASSERT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-unpartitioned", "1", kCookieDomain, "/", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false, /*partition_key=*/absl::nullopt), @@ -2985,7 +2996,7 @@ TEST_F(FPSPartitionedCookiesCookieManagerTest, GetCookieList) { ASSERT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-intheset", "2", kCookieDomain, "/", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false, absl::make_optional(owner_partition_key_)), @@ -2993,7 +3004,7 @@ TEST_F(FPSPartitionedCookiesCookieManagerTest, GetCookieList) { ASSERT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-nonmember", "4", kCookieDomain, "/", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false, absl::make_optional( @@ -3018,7 +3029,7 @@ TEST_F(FPSPartitionedCookiesCookieManagerTest, SetCanonicalCookie) { ASSERT_TRUE(service_wrapper()->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-unpartitioned", "1", kCookieDomain, "/", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false, /*partition_key=*/absl::nullopt), @@ -3029,7 +3040,7 @@ TEST_F(FPSPartitionedCookiesCookieManagerTest, SetCanonicalCookie) { ASSERT_TRUE(service_wrapper()->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-intheset", "2", kCookieDomain, "/", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false, absl::make_optional(member_partition_key_)), @@ -3037,7 +3048,7 @@ TEST_F(FPSPartitionedCookiesCookieManagerTest, SetCanonicalCookie) { ASSERT_TRUE(service_wrapper()->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-nonmember", "4", kCookieDomain, "/", base::Time(), - base::Time(), base::Time(), + base::Time(), base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false, absl::make_optional( @@ -3062,7 +3073,7 @@ TEST_F(CookieManagerTest, ConvertPartitionedCookiesToUnpartitioned) { *net::CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-A", "0", kCookieDomain, "/", base::Time::Now() - base::Days(1), base::Time::Now() + base::Days(1), - base::Time::Now(), + base::Time::Now(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false, @@ -3074,6 +3085,7 @@ TEST_F(CookieManagerTest, ConvertPartitionedCookiesToUnpartitioned) { *net::CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-B", "0", kCookieDomain, "/", base::Time::Now() - base::Days(1), base::Time(), base::Time::Now(), + base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false, @@ -3101,7 +3113,7 @@ TEST_F(CookieManagerTest, ConvertPartitionedCookiesToUnpartitioned) { ASSERT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-A", "1", kCookieDomain, "/", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false, net::CookiePartitionKey::FromURLForTesting( @@ -3129,7 +3141,7 @@ TEST_F(CookieManagerTest, ConvertPartitionedCookiesToUnpartitioned) { *net::CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-C", "0", kCookieDomain, "/", base::Time::Now() - base::Days(1), base::Time::Now() + base::Days(1), - base::Time::Now(), + base::Time::Now(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false, @@ -3140,7 +3152,7 @@ TEST_F(CookieManagerTest, ConvertPartitionedCookiesToUnpartitioned) { *net::CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-C", "1", kCookieDomain, "/", base::Time::Now() - base::Days(1), base::Time::Now() + base::Days(1), - base::Time::Now() + base::Minutes(5), + base::Time::Now() + base::Minutes(5), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false, @@ -3165,7 +3177,7 @@ TEST_F(CookieManagerTest, ConvertPartitionedCookiesToUnpartitioned) { ASSERT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-D", "0", kCookieDomain, "/", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false, @@ -3193,7 +3205,7 @@ TEST_F(CookieManagerTest, ConvertPartitionedCookiesToUnpartitioned) { ASSERT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-E", "0", kCookieDomain, "/", base::Time(), base::Time(), - base::Time(), + base::Time(), base::Time(), /*secure=*/true, /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_MEDIUM, /*same_party=*/false, diff --git a/services/network/cookie_settings_unittest.cc b/services/network/cookie_settings_unittest.cc index bede44eee1d4ed..7b61fe1aecd127 100644 --- a/services/network/cookie_settings_unittest.cc +++ b/services/network/cookie_settings_unittest.cc @@ -49,9 +49,10 @@ std::unique_ptr MakeCanonicalCookie( absl::optional cookie_partition_key = absl::nullopt) { return net::CanonicalCookie::CreateUnsafeCookieForTesting( - name, "1", domain, "/" /* path */, base::Time() /* creation */, - base::Time() /* expiration */, base::Time() /* last_access */, - true /* secure */, false /* httponly */, net::CookieSameSite::UNSPECIFIED, + name, "1", domain, /*path=*/"/", /*creation=*/base::Time(), + /*expiration=*/base::Time(), /*last_access=*/base::Time(), + /*last_update=*/base::Time(), + /*secure=*/true, /*httponly=*/false, net::CookieSameSite::UNSPECIFIED, net::CookiePriority::COOKIE_PRIORITY_DEFAULT, sameparty, cookie_partition_key); } diff --git a/services/network/network_context_unittest.cc b/services/network/network_context_unittest.cc index 908b5927078a69..4efa2914722d78 100644 --- a/services/network/network_context_unittest.cc +++ b/services/network/network_context_unittest.cc @@ -2624,7 +2624,7 @@ bool SetCookieHelper(NetworkContext* network_context, cookie_manager->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( key, value, url.host(), "/", base::Time(), base::Time(), base::Time(), - true, false, net::CookieSameSite::NO_RESTRICTION, + base::Time(), true, false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_LOW, false), url, net::CookieOptions::MakeAllInclusive(), base::BindOnce(&SetCookieCallback, &run_loop, &result)); @@ -2645,7 +2645,7 @@ TEST_F(NetworkContextTest, CookieManager) { bool result = false; auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting( "TestCookie", "1", "www.test.com", "/", base::Time(), base::Time(), - base::Time(), false, false, net::CookieSameSite::LAX_MODE, + base::Time(), base::Time(), false, false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_LOW, false); cookie_manager_remote->SetCanonicalCookie( *cookie, net::cookie_util::SimulatedCookieSource(*cookie, "https"), @@ -4166,7 +4166,7 @@ TEST_F(NetworkContextTest, CanSetCookieFalseIfCookiesBlocked) { nullptr, TRAFFIC_ANNOTATION_FOR_TESTS); auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting( "TestCookie", "1", "www.test.com", "/", base::Time(), base::Time(), - base::Time(), false, false, net::CookieSameSite::LAX_MODE, + base::Time(), base::Time(), false, false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_LOW, false); EXPECT_TRUE( network_context->url_request_context()->network_delegate()->CanSetCookie( @@ -4186,7 +4186,7 @@ TEST_F(NetworkContextTest, CanSetCookieTrueIfCookiesAllowed) { nullptr, TRAFFIC_ANNOTATION_FOR_TESTS); auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting( "TestCookie", "1", "www.test.com", "/", base::Time(), base::Time(), - base::Time(), false, false, net::CookieSameSite::LAX_MODE, + base::Time(), base::Time(), false, false, net::CookieSameSite::LAX_MODE, net::COOKIE_PRIORITY_LOW, false); SetDefaultContentSetting(CONTENT_SETTING_ALLOW, network_context.get()); diff --git a/services/network/public/cpp/cookie_manager_mojom_traits.cc b/services/network/public/cpp/cookie_manager_mojom_traits.cc index 8353bc50069a05..bc0e51d3a3a901 100644 --- a/services/network/public/cpp/cookie_manager_mojom_traits.cc +++ b/services/network/public/cpp/cookie_manager_mojom_traits.cc @@ -597,6 +597,7 @@ bool StructTraits< base::Time creation_time; base::Time expiry_time; base::Time last_access_time; + base::Time last_update_time; if (!cookie.ReadCreation(&creation_time)) return false; @@ -606,6 +607,9 @@ bool StructTraits< if (!cookie.ReadLastAccess(&last_access_time)) return false; + if (!cookie.ReadLastUpdate(&last_update_time)) + return false; + net::CookieSameSite site_restrictions; if (!cookie.ReadSiteRestrictions(&site_restrictions)) return false; @@ -625,9 +629,9 @@ bool StructTraits< auto cc = net::CanonicalCookie::FromStorage( std::move(name), std::move(value), std::move(domain), std::move(path), std::move(creation_time), std::move(expiry_time), - std::move(last_access_time), cookie.secure(), cookie.httponly(), - site_restrictions, priority, cookie.same_party(), partition_key, - source_scheme, cookie.source_port()); + std::move(last_access_time), std::move(last_update_time), cookie.secure(), + cookie.httponly(), site_restrictions, priority, cookie.same_party(), + partition_key, source_scheme, cookie.source_port()); if (!cc) return false; *out = *cc; diff --git a/services/network/public/cpp/cookie_manager_mojom_traits.h b/services/network/public/cpp/cookie_manager_mojom_traits.h index d059ce00816f4f..69eb32ad09ae28 100644 --- a/services/network/public/cpp/cookie_manager_mojom_traits.h +++ b/services/network/public/cpp/cookie_manager_mojom_traits.h @@ -259,6 +259,9 @@ struct StructTraitsCreationDate(), copied.CreationDate()); EXPECT_EQ(original->LastAccessDate(), copied.LastAccessDate()); EXPECT_EQ(original->ExpiryDate(), copied.ExpiryDate()); + EXPECT_EQ(original->LastUpdateDate(), copied.LastUpdateDate()); EXPECT_EQ(original->IsSecure(), copied.IsSecure()); EXPECT_EQ(original->IsHttpOnly(), copied.IsHttpOnly()); EXPECT_EQ(original->SameSite(), copied.SameSite()); @@ -52,7 +54,7 @@ TEST(CookieManagerTraitsTest, Roundtrips_CanonicalCookie) { auto original_unspecified = net::CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "x.y", "/path", base::Time(), base::Time(), base::Time(), - false, false, net::CookieSameSite::NO_RESTRICTION, + base::Time(), false, false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_LOW, false, absl::nullopt, net::CookieSourceScheme::kSecure, url::PORT_UNSPECIFIED); net::CanonicalCookie copied_unspecified; @@ -65,10 +67,10 @@ TEST(CookieManagerTraitsTest, Roundtrips_CanonicalCookie) { // Test port edge cases: invalid. auto original_invalid = net::CanonicalCookie::CreateUnsafeCookieForTesting( - "A", "B", "x.y", "/path", base::Time(), base::Time(), base::Time(), false, - false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_LOW, - false, absl::nullopt, net::CookieSourceScheme::kSecure, - url::PORT_INVALID); + "A", "B", "x.y", "/path", base::Time(), base::Time(), base::Time(), + base::Time(), false, false, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_LOW, false, absl::nullopt, + net::CookieSourceScheme::kSecure, url::PORT_INVALID); net::CanonicalCookie copied_invalid; EXPECT_TRUE(mojo::test::SerializeAndDeserialize( @@ -81,7 +83,7 @@ TEST(CookieManagerTraitsTest, Roundtrips_CanonicalCookie) { original = net::CanonicalCookie::CreateUnsafeCookieForTesting( "A\n", "B", "x.y", "/path", base::Time(), base::Time(), base::Time(), - false, false, net::CookieSameSite::NO_RESTRICTION, + base::Time(), false, false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_LOW, false); EXPECT_FALSE(mojo::test::SerializeAndDeserialize( @@ -117,8 +119,9 @@ TEST(CookieManagerTraitsTest, Roundtrips_CookieAccessResult) { TEST(CookieManagerTraitsTest, Rountrips_CookieWithAccessResult) { auto original_cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "x.y", "/path", base::Time(), base::Time(), base::Time(), - /* secure = */ true, /* httponly = */ false, - net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_LOW, false); + base::Time(), + /*secure=*/true, /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_LOW, false); net::CookieWithAccessResult original = {*original_cookie, net::CookieAccessResult()}; @@ -135,6 +138,7 @@ TEST(CookieManagerTraitsTest, Rountrips_CookieWithAccessResult) { EXPECT_EQ(original.cookie.CreationDate(), copied.cookie.CreationDate()); EXPECT_EQ(original.cookie.LastAccessDate(), copied.cookie.LastAccessDate()); EXPECT_EQ(original.cookie.ExpiryDate(), copied.cookie.ExpiryDate()); + EXPECT_EQ(original.cookie.LastUpdateDate(), copied.cookie.LastUpdateDate()); EXPECT_EQ(original.cookie.IsSecure(), copied.cookie.IsSecure()); EXPECT_EQ(original.cookie.IsHttpOnly(), copied.cookie.IsHttpOnly()); EXPECT_EQ(original.cookie.SameSite(), copied.cookie.SameSite()); @@ -148,8 +152,9 @@ TEST(CookieManagerTraitsTest, Rountrips_CookieWithAccessResult) { TEST(CookieManagerTraitsTest, Roundtrips_CookieAndLineWithAccessResult) { auto original_cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "x.y", "/path", base::Time(), base::Time(), base::Time(), - /* secure = */ true, /* httponly = */ false, - net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_LOW, false); + base::Time(), + /*secure=*/true, /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_LOW, false); net::CookieAndLineWithAccessResult original(*original_cookie, "cookie-string", net::CookieAccessResult()); @@ -166,6 +171,7 @@ TEST(CookieManagerTraitsTest, Roundtrips_CookieAndLineWithAccessResult) { EXPECT_EQ(original.cookie->CreationDate(), copied.cookie->CreationDate()); EXPECT_EQ(original.cookie->LastAccessDate(), copied.cookie->LastAccessDate()); EXPECT_EQ(original.cookie->ExpiryDate(), copied.cookie->ExpiryDate()); + EXPECT_EQ(original.cookie->LastUpdateDate(), copied.cookie->LastUpdateDate()); EXPECT_EQ(original.cookie->IsSecure(), copied.cookie->IsSecure()); EXPECT_EQ(original.cookie->IsHttpOnly(), copied.cookie->IsHttpOnly()); EXPECT_EQ(original.cookie->SameSite(), copied.cookie->SameSite()); @@ -374,7 +380,7 @@ TEST(CookieManagerTraitsTest, Roundtrips_SamePartyCookieContextType) { TEST(CookieManagerTraitsTest, Roundtrips_PartitionKey) { auto original = net::CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-A", "B", "x.y", "/", base::Time(), base::Time(), base::Time(), - true, false, net::CookieSameSite::NO_RESTRICTION, + base::Time(), true, false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_LOW, false, net::CookiePartitionKey::FromURLForTesting( GURL("https://toplevelsite.com")), @@ -389,7 +395,7 @@ TEST(CookieManagerTraitsTest, Roundtrips_PartitionKey) { original = net::CanonicalCookie::CreateUnsafeCookieForTesting( "__Host-A", "B", "x.y", "/", base::Time(), base::Time(), base::Time(), - true, false, net::CookieSameSite::NO_RESTRICTION, + base::Time(), true, false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_LOW, false, net::CookiePartitionKey::FromScript(), net::CookieSourceScheme::kSecure, 8433); EXPECT_TRUE(mojo::test::SerializeAndDeserialize( @@ -537,8 +543,9 @@ TEST(CookieManagerTraitsTest, Roundtrips_CookieOptions) { TEST(CookieManagerTraitsTest, Roundtrips_CookieChangeInfo) { auto original_cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting( "A", "B", "x.y", "/path", base::Time(), base::Time(), base::Time(), - /* secure = */ false, /* httponly = */ false, - net::CookieSameSite::UNSPECIFIED, net::COOKIE_PRIORITY_LOW, false); + base::Time(), + /*secure=*/false, /*httponly =*/false, net::CookieSameSite::UNSPECIFIED, + net::COOKIE_PRIORITY_LOW, false); net::CookieChangeInfo original( *original_cookie, @@ -560,6 +567,7 @@ TEST(CookieManagerTraitsTest, Roundtrips_CookieChangeInfo) { EXPECT_EQ(original.cookie.CreationDate(), copied.cookie.CreationDate()); EXPECT_EQ(original.cookie.LastAccessDate(), copied.cookie.LastAccessDate()); EXPECT_EQ(original.cookie.ExpiryDate(), copied.cookie.ExpiryDate()); + EXPECT_EQ(original.cookie.LastUpdateDate(), copied.cookie.LastUpdateDate()); EXPECT_EQ(original.cookie.IsSecure(), copied.cookie.IsSecure()); EXPECT_EQ(original.cookie.IsHttpOnly(), copied.cookie.IsHttpOnly()); EXPECT_EQ(original.cookie.SameSite(), copied.cookie.SameSite()); diff --git a/services/network/public/mojom/cookie_manager.mojom b/services/network/public/mojom/cookie_manager.mojom index 4cb20ad348ea02..ddab6be2c6a901 100644 --- a/services/network/public/mojom/cookie_manager.mojom +++ b/services/network/public/mojom/cookie_manager.mojom @@ -168,6 +168,7 @@ struct CanonicalCookie { mojo_base.mojom.Time creation; mojo_base.mojom.Time expiry; mojo_base.mojom.Time last_access; + mojo_base.mojom.Time last_update; bool secure = false; bool httponly = false; CookieSameSite site_restrictions = NO_RESTRICTION; diff --git a/services/network/restricted_cookie_manager.cc b/services/network/restricted_cookie_manager.cc index faa351f1f7b1e9..5b0677e1d2b063 100644 --- a/services/network/restricted_cookie_manager.cc +++ b/services/network/restricted_cookie_manager.cc @@ -690,7 +690,7 @@ void RestrictedCookieManager::SetCanonicalCookie( std::unique_ptr sanitized_cookie = net::CanonicalCookie::FromStorage( cookie.Name(), cookie.Value(), cookie.Domain(), cookie.Path(), now, - cookie.ExpiryDate(), now, cookie.IsSecure(), cookie.IsHttpOnly(), + cookie.ExpiryDate(), now, now, cookie.IsSecure(), cookie.IsHttpOnly(), cookie.SameSite(), cookie.Priority(), cookie.IsSameParty(), cookie_partition_key, source_scheme, origin_.port()); DCHECK(sanitized_cookie); diff --git a/services/network/restricted_cookie_manager_unittest.cc b/services/network/restricted_cookie_manager_unittest.cc index c961d00c3acc19..aefc211f4efbe1 100644 --- a/services/network/restricted_cookie_manager_unittest.cc +++ b/services/network/restricted_cookie_manager_unittest.cc @@ -350,10 +350,11 @@ class RestrictedCookieManagerTest ASSERT_TRUE(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( name, value, domain, path, base::Time(), base::Time(), base::Time(), - /* secure = */ secure, - /* httponly = */ false, net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false), - "https", /* can_modify_httponly = */ true)); + base::Time(), + /*secure=*/secure, + /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false), + "https", /*can_modify_httponly=*/true)); } // Like above, but makes an http-only cookie. @@ -364,10 +365,11 @@ class RestrictedCookieManagerTest CHECK(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( name, value, domain, path, base::Time(), base::Time(), base::Time(), - /* secure = */ true, - /* httponly = */ true, net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false), - "https", /* can_modify_httponly = */ true)); + base::Time(), + /*secure=*/true, + /*httponly=*/true, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false), + "https", /*can_modify_httponly=*/true)); } std::unique_ptr CreateCookieChangeListener( @@ -461,10 +463,11 @@ class SamePartyEnabledRestrictedCookieManagerTest CHECK(SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( name, value, domain, path, base::Time(), base::Time(), base::Time(), - /* secure = */ secure, - /* httponly = */ false, net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ true), - "https", /* can_modify_httponly = */ true, + base::Time(), + /*secure=*/secure, + /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/true), + "https", /*can_modify_httponly=*/true, net::CookieOptions::SameSiteCookieContext::ContextType::SAME_SITE_LAX, net::SamePartyContext::Type::kSameParty)); } @@ -907,7 +910,7 @@ TEST_P(RestrictedCookieManagerTest, GetAllForUrlPolicyWarnActual) { cookie_monster_.SetCookieAccessDelegate(std::move(cookie_access_delegate)); SetSessionCookie("cookie-name", "cookie-value", "example.com", "/", - /* secure = */ false); + /*secure=*/false); // Now test get using (default) nonlegacy semantics. cookie_monster_.SetCookieAccessDelegate(nullptr); @@ -1053,9 +1056,9 @@ TEST_P(RestrictedCookieManagerTest, SetCanonicalCookie) { EXPECT_TRUE(sync_service_->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "new-name", "new-value", "example.com", "/", base::Time(), - base::Time(), base::Time(), /* secure = */ true, - /* httponly = */ false, net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false), + base::Time(), base::Time(), base::Time(), /*secure=*/true, + /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false), kDefaultUrlWithPath, kDefaultSiteForCookies, kDefaultOrigin)); auto options = mojom::CookieManagerGetOptions::New(); @@ -1074,9 +1077,9 @@ TEST_P(RestrictedCookieManagerTest, SetCanonicalCookieHttpOnly) { sync_service_->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "new-name", "new-value", "example.com", "/", base::Time(), - base::Time(), base::Time(), /* secure = */ true, - /* httponly = */ true, net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false), + base::Time(), base::Time(), base::Time(), /*secure=*/true, + /*httponly=*/true, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false), kDefaultUrlWithPath, kDefaultSiteForCookies, kDefaultOrigin)); auto options = mojom::CookieManagerGetOptions::New(); @@ -1116,9 +1119,9 @@ TEST_P(RestrictedCookieManagerTest, SetCanonicalCookieFromWrongOrigin) { EXPECT_FALSE(sync_service_->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "new-name", "new-value", "not-example.com", "/", base::Time(), - base::Time(), base::Time(), /* secure = */ true, - /* httponly = */ false, net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false), + base::Time(), base::Time(), base::Time(), /*secure=*/true, + /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false), kOtherUrlWithPath, kDefaultSiteForCookies, kDefaultOrigin)); ASSERT_TRUE(received_bad_message()); } @@ -1132,9 +1135,9 @@ TEST_P(RestrictedCookieManagerTest, SetCanonicalCookieFromOpaqueOrigin) { EXPECT_FALSE(sync_service_->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "new-name", "new-value", "not-example.com", "/", base::Time(), - base::Time(), base::Time(), /* secure = */ true, - /* httponly = */ false, net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false), + base::Time(), base::Time(), base::Time(), /*secure=*/true, + /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false), kDefaultUrlWithPath, kDefaultSiteForCookies, kDefaultOrigin)); ASSERT_TRUE(received_bad_message()); } @@ -1144,9 +1147,9 @@ TEST_P(RestrictedCookieManagerTest, SetCanonicalCookieWithMismatchingDomain) { EXPECT_FALSE(sync_service_->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "new-name", "new-value", "not-example.com", "/", base::Time(), - base::Time(), base::Time(), /* secure = */ true, - /* httponly = */ false, net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false), + base::Time(), base::Time(), base::Time(), /*secure=*/true, + /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false), kDefaultUrlWithPath, kDefaultSiteForCookies, kDefaultOrigin)); ASSERT_TRUE(received_bad_message()); } @@ -1296,9 +1299,9 @@ TEST_P(SamePartyEnabledRestrictedCookieManagerTest, EXPECT_TRUE(sync_service_->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "new-name", "new-value", "member1.com", "/", base::Time(), - base::Time(), base::Time(), /* secure = */ true, - /* httponly = */ false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ true), + base::Time(), base::Time(), base::Time(), /*secure=*/true, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/true), GURL("https://member1.com/test/"), net::SiteForCookies(), kDefaultOrigin)); @@ -1327,9 +1330,9 @@ TEST_P(SamePartyEnabledRestrictedCookieManagerTest, EXPECT_FALSE(sync_service_->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "new-name", "new-value", "example.com", "/", base::Time(), - base::Time(), base::Time(), /* secure = */ true, - /* httponly = */ false, net::CookieSameSite::NO_RESTRICTION, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ true), + base::Time(), base::Time(), base::Time(), /*secure=*/true, + /*httponly=*/false, net::CookieSameSite::NO_RESTRICTION, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/true), kDefaultUrlWithPath, net::SiteForCookies(), kDefaultOrigin)); EXPECT_THAT( @@ -1358,9 +1361,9 @@ TEST_P(RestrictedCookieManagerTest, SetCanonicalCookieWithInclusionStatus) { EXPECT_FALSE(sync_service_->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "new-name", "new-value", "example.com", "/", base::Time(), - base::Time(), base::Time(), /* secure = */ true, - /* httponly = */ false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false), + base::Time(), base::Time(), base::Time(), /*secure=*/true, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false), kDefaultUrlWithPath, kDefaultSiteForCookies, kDefaultOrigin, status_exclude)); ASSERT_TRUE(received_bad_message()); @@ -1372,9 +1375,9 @@ TEST_P(RestrictedCookieManagerTest, SetCanonicalCookieWithInclusionStatus) { EXPECT_TRUE(sync_service_->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "new-name", "new-value", "example.com", "/", base::Time(), - base::Time(), base::Time(), /* secure = */ true, - /* httponly = */ false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false), + base::Time(), base::Time(), base::Time(), /*secure=*/true, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false), kDefaultUrlWithPath, kDefaultSiteForCookies, kDefaultOrigin, status_warning)); @@ -1437,16 +1440,16 @@ TEST_P(RestrictedCookieManagerTest, SameSiteCookiesSpecialScheme) { EXPECT_TRUE(sync_service_->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "strict-cookie", "1", "example.com", "/", base::Time(), base::Time(), - base::Time(), /* secure = */ false, - /* httponly = */ false, net::CookieSameSite::STRICT_MODE, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::STRICT_MODE, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false), https_url, chrome_site_for_cookies, chrome_origin)); EXPECT_TRUE(sync_service_->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "lax-cookie", "1", "example.com", "/", base::Time(), base::Time(), - base::Time(), /* secure = */ false, - /* httponly = */ false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false), https_url, chrome_site_for_cookies, chrome_origin)); auto options = mojom::CookieManagerGetOptions::New(); @@ -1467,16 +1470,16 @@ TEST_P(RestrictedCookieManagerTest, SameSiteCookiesSpecialScheme) { EXPECT_FALSE(sync_service_->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "strict-cookie", "2", "example.com", "/", base::Time(), base::Time(), - base::Time(), /* secure = */ false, - /* httponly = */ false, net::CookieSameSite::STRICT_MODE, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::STRICT_MODE, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false), http_url, chrome_site_for_cookies, chrome_origin)); EXPECT_FALSE(sync_service_->SetCanonicalCookie( *net::CanonicalCookie::CreateUnsafeCookieForTesting( "lax-cookie", "2", "example.com", "/", base::Time(), base::Time(), - base::Time(), /* secure = */ false, - /* httponly = */ false, net::CookieSameSite::LAX_MODE, - net::COOKIE_PRIORITY_DEFAULT, /* same_party = */ false), + base::Time(), base::Time(), /*secure=*/false, + /*httponly=*/false, net::CookieSameSite::LAX_MODE, + net::COOKIE_PRIORITY_DEFAULT, /*same_party=*/false), http_url, chrome_site_for_cookies, chrome_origin)); options = mojom::CookieManagerGetOptions::New(); diff --git a/services/network/session_cleanup_cookie_store_unittest.cc b/services/network/session_cleanup_cookie_store_unittest.cc index c9c4afe9880763..0cce7c61097bbd 100644 --- a/services/network/session_cleanup_cookie_store_unittest.cc +++ b/services/network/session_cleanup_cookie_store_unittest.cc @@ -68,8 +68,8 @@ class SessionCleanupCookieStoreTest : public testing::Test { const std::string& path, base::Time creation) { store_->AddCookie(*net::CanonicalCookie::CreateUnsafeCookieForTesting( - name, value, domain, path, creation, creation, base::Time(), false, - false, net::CookieSameSite::NO_RESTRICTION, + name, value, domain, path, creation, creation, base::Time(), + base::Time(), false, false, net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT, false)); }