#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "net/cookies/cookie_monster.h"
#include <stdint.h>
#include <algorithm>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "base/containers/queue.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/histogram.h"
#include "base/metrics/histogram_samples.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_tokenizer.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_future.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "cookie_partition_key.h"
#include "net/base/features.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/canonical_cookie_test_helpers.h"
#include "net/cookies/cookie_change_dispatcher.h"
#include "net/cookies/cookie_constants.h"
#include "net/cookies/cookie_inclusion_status.h"
#include "net/cookies/cookie_monster_store_test.h"
#include "net/cookies/cookie_partition_key.h"
#include "net/cookies/cookie_store.h"
#include "net/cookies/cookie_store_change_unittest.h"
#include "net/cookies/cookie_store_test_callbacks.h"
#include "net/cookies/cookie_store_test_helpers.h"
#include "net/cookies/cookie_store_unittest.h"
#include "net/cookies/cookie_util.h"
#include "net/cookies/parsed_cookie.h"
#include "net/cookies/test_cookie_access_delegate.h"
#include "net/log/net_log_with_source.h"
#include "net/log/test_net_log.h"
#include "net/log/test_net_log_util.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#include "url/third_party/mozilla/url_parse.h"
#include "url/url_constants.h"
namespace net {
Time;
CookieDeletionInfo;
namespace {
ElementsAre;
MATCHER_P(CookieEquals, expected, "") { … }
MATCHER_P2(MatchesCookieNameDomain, name, domain, "") { … }
MATCHER_P4(MatchesCookieNameValueCreationExpiry,
name,
value,
creation,
expiry,
"") { … }
const char kTopLevelDomainPlus1[] = …;
const char kTopLevelDomainPlus2[] = …;
const char kTopLevelDomainPlus2Secure[] = …;
const char kTopLevelDomainPlus3[] = …;
const char kOtherDomain[] = …;
struct CookieMonsterTestTraits { … };
INSTANTIATE_TYPED_TEST_SUITE_P(…);
INSTANTIATE_TYPED_TEST_SUITE_P(…);
INSTANTIATE_TYPED_TEST_SUITE_P(…);
INSTANTIATE_TYPED_TEST_SUITE_P(…);
template <typename T>
class CookieMonsterTestBase : public CookieStoreTest<T> { … };
CookieMonsterTest;
class CookieMonsterTestGarbageCollectionObc
: public CookieMonsterTest,
public testing::WithParamInterface<std::tuple<bool, bool>> { … };
CookieMonsterTestPriorityGarbageCollectionObc;
struct CookiesInputInfo { … };
}
class DeferredCookieTaskTest : public CookieMonsterTest { … };
TEST_F(DeferredCookieTaskTest, DeferredGetCookieList) { … }
TEST_F(DeferredCookieTaskTest, DeferredSetCookie) { … }
TEST_F(DeferredCookieTaskTest, DeferredSetAllCookies) { … }
TEST_F(DeferredCookieTaskTest, DeferredGetAllCookies) { … }
TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlCookies) { … }
TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlWithOptionsCookies) { … }
TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCookies) { … }
TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCreatedInTimeRangeCookies) { … }
TEST_F(DeferredCookieTaskTest,
DeferredDeleteAllWithPredicateCreatedInTimeRangeCookies) { … }
TEST_F(DeferredCookieTaskTest, DeferredDeleteMatchingCookies) { … }
TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) { … }
TEST_F(DeferredCookieTaskTest, DeferredDeleteSessionCookies) { … }
TEST_F(DeferredCookieTaskTest, DeferredTaskOrder) { … }
TEST_F(CookieMonsterTest, TestCookieDeleteAll) { … }
TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedInTimeRangeTimestamps) { … }
TEST_F(CookieMonsterTest,
TestCookieDeleteAllCreatedInTimeRangeTimestampsWithInfo) { … }
TEST_F(CookieMonsterTest, TestCookieDeleteMatchingCookies) { … }
static const base::TimeDelta kLastAccessThreshold = …;
static const base::TimeDelta kAccessDelay = …;
TEST_F(CookieMonsterTest, TestLastAccess) { … }
TEST_P(CookieMonsterTestPriorityGarbageCollectionObc,
TestHostGarbageCollection) { … }
TEST_P(CookieMonsterTestPriorityGarbageCollectionObc,
TestPriorityAwareGarbageCollectionNonSecure) { … }
TEST_P(CookieMonsterTestPriorityGarbageCollectionObc,
TestPriorityAwareGarbageCollectionSecure) { … }
TEST_P(CookieMonsterTestPriorityGarbageCollectionObc,
TestPriorityAwareGarbageCollectionMixed) { … }
TEST_P(CookieMonsterTestGarbageCollectionObc, DomainCookiesPreferred) { … }
TEST_P(CookieMonsterTestGarbageCollectionObc, SecureCookiesPreferred) { … }
TEST_F(CookieMonsterTest, TestPartitionedCookiesGarbageCollection_Memory) { … }
TEST_F(CookieMonsterTest, TestPartitionedCookiesGarbageCollection_MaxCookies) { … }
TEST_F(CookieMonsterTest, SetCookieableSchemes) { … }
TEST_F(CookieMonsterTest, SetCookieableSchemes_StoreInitialized) { … }
TEST_F(CookieMonsterTest, GetAllCookiesForURL) { … }
TEST_F(CookieMonsterTest, GetExcludedCookiesForURL) { … }
TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) { … }
TEST_F(CookieMonsterTest, GetExcludedCookiesForURLPathMatching) { … }
TEST_F(CookieMonsterTest, CookieSorting) { … }
TEST_F(CookieMonsterTest, InheritCreationDate) { … }
TEST_F(CookieMonsterTest, OverwriteSource) { … }
TEST_F(CookieMonsterTest, DeleteExpiredCookiesOnGet) { … }
TEST_F(CookieMonsterTest, DeleteExpiredCookiesAfterTimeElapsed) { … }
TEST_F(CookieMonsterTest, DeleteExpiredPartitionedCookiesAfterTimeElapsed) { … }
TEST_F(CookieMonsterTest, ExpireSinglePartitionedCookie) { … }
TEST_F(CookieMonsterTest, DeleteExpiredAfterTimeElapsed_GetAllCookies) { … }
TEST_F(CookieMonsterTest,
DeleteExpiredPartitionedCookiesAfterTimeElapsed_GetAllCookies) { … }
TEST_F(CookieMonsterTest, DeletePartitionedCookie) { … }
TEST_F(CookieMonsterTest, DontImportDuplicateCookies) { … }
TEST_F(CookieMonsterTest, DontImportDuplicateCookies_PartitionedCookies) { … }
TEST_F(CookieMonsterTest, ImportDuplicateCreationTimes) { … }
TEST_F(CookieMonsterTest, ImportDuplicateCreationTimes_PartitionedCookies) { … }
TEST_F(CookieMonsterTest, PredicateSeesAllCookies) { … }
TEST_F(CookieMonsterTest, GetKey) { … }
TEST_F(CookieMonsterTest, BackingStoreCommunication) { … }
TEST_F(CookieMonsterTest, RestoreDifferentCookieSameCreationTime) { … }
TEST_F(CookieMonsterTest, CookieListOrdering) { … }
TEST_F(CookieMonsterTest, GarbageCollectionKeepsRecentEphemeralCookies) { … }
TEST_F(CookieMonsterTest, GarbageCollectionKeepsRecentCookies) { … }
TEST_F(CookieMonsterTest, GarbageCollectionKeepsOnlyRecentCookies) { … }
TEST_F(CookieMonsterTest, GarbageCollectionExactlyAllOldCookiesDeleted) { … }
TEST_F(CookieMonsterTest, GarbageCollectionTriggers5) { … }
TEST_F(CookieMonsterTest, GarbageCollectWithSecureCookiesOnly) { … }
TEST_F(CookieMonsterTest, WhileLoadingLoadCompletesBeforeKeyLoadCompletes) { … }
TEST_F(CookieMonsterTest, WhileLoadingDeleteAllGetForURL) { … }
TEST_F(CookieMonsterTest, WhileLoadingGetAllSetGetAll) { … }
namespace {
void RunClosureOnAllCookiesReceived(base::OnceClosure closure,
const CookieList& cookie_list) { … }
}
TEST_F(CookieMonsterTest, CheckOrderOfCookieTaskQueueWhenLoadingCompletes) { … }
TEST_F(CookieMonsterTest, FlushStore) { … }
TEST_F(CookieMonsterTest, SetAllCookies) { … }
TEST_F(CookieMonsterTest, DeleteAll) { … }
TEST_F(CookieMonsterTest, HistogramCheck) { … }
TEST_F(CookieMonsterTest, InvalidExpiryTime) { … }
TEST_F(CookieMonsterTest, PersistSessionCookies) { … }
TEST_F(CookieMonsterTest, PersisentCookieStorageTest) { … }
TEST_F(CookieMonsterTest, ControlCharacterPurge) { … }
TEST_F(CookieMonsterTest, CookieSourceHistogram) { … }
TEST_F(CookieMonsterTest, NumKeysHistogram) { … }
TEST_F(CookieMonsterTest, CookieCount2Histogram) { … }
TEST_F(CookieMonsterTest, CookieJarSizeHistograms) { … }
TEST_F(CookieMonsterTest, PartitionedCookieHistograms) { … }
TEST_F(CookieMonsterTest, MaxSameSiteNoneCookiesPerKey) { … }
TEST_F(CookieMonsterTest, SecureCookieLocalhost) { … }
TEST_F(CookieMonsterTest, MaybeDeleteEquivalentCookieAndUpdateStatus) { … }
TEST_F(CookieMonsterTest,
MaybeDeleteEquivalentCookieAndUpdateStatus_PartitionedCookies) { … }
class CookieMonsterTest_MaybeDeleteEquivalentCookieAndUpdateStatus
: public CookieMonsterTest { … };
TEST_F(CookieMonsterTest_MaybeDeleteEquivalentCookieAndUpdateStatus,
NoSchemeNoPort) { … }
TEST_F(CookieMonsterTest_MaybeDeleteEquivalentCookieAndUpdateStatus,
YesSchemeNoPort) { … }
TEST_F(CookieMonsterTest_MaybeDeleteEquivalentCookieAndUpdateStatus,
NoSchemeYesPort) { … }
TEST_F(CookieMonsterTest_MaybeDeleteEquivalentCookieAndUpdateStatus,
YesSchemeYesPort) { … }
class CookieMonsterTest_StoreLoadedCookies : public CookieMonsterTest { … };
TEST_F(CookieMonsterTest_StoreLoadedCookies, NoSchemeNoPort) { … }
TEST_F(CookieMonsterTest_StoreLoadedCookies, YesSchemeNoPort) { … }
TEST_F(CookieMonsterTest_StoreLoadedCookies, NoSchemeYesPort) { … }
TEST_F(CookieMonsterTest_StoreLoadedCookies, YesSchemeYesPort) { … }
TEST_F(CookieMonsterTest, SkipDontOverwriteForMultipleReasons) { … }
TEST_F(CookieMonsterTest, DontDeleteEquivalentCookieIfSetIsRejected) { … }
TEST_F(CookieMonsterTest, SetSecureCookies) { … }
TEST_F(CookieMonsterTest, LeaveSecureCookiesAlone_DomainMatch) { … }
TEST_F(CookieMonsterTest, LeaveSecureCookiesAlone_PathMatch) { … }
TEST_F(CookieMonsterTest, EvictSecureCookies) { … }
TEST_F(CookieMonsterTest, EquivalentCookies) { … }
TEST_F(CookieMonsterTest, SetCanonicalCookieDoesNotBlockForLoadAll) { … }
TEST_F(CookieMonsterTest, DeleteDuplicateCTime) { … }
TEST_F(CookieMonsterTest, DeleteCookieWithInheritedTimestamps) { … }
TEST_F(CookieMonsterTest, RejectCreatedSameSiteCookieOnSet) { … }
TEST_F(CookieMonsterTest, RejectCreatedSecureCookieOnSet) { … }
TEST_F(CookieMonsterTest, RejectCreatedHttpOnlyCookieOnSet) { … }
TEST_F(CookieMonsterTest, CookiesWithoutSameSiteMustBeSecure) { … }
class CookieMonsterNotificationTest : public CookieMonsterTest { … };
void RecordCookieChanges(std::vector<CanonicalCookie>* out_cookies,
std::vector<CookieChangeCause>* out_causes,
const CookieChangeInfo& change) { … }
TEST_F(CookieMonsterNotificationTest, NoNotificationOnLoad) { … }
class CookieMonsterLegacyCookieAccessTest : public CookieMonsterTest { … };
TEST_F(CookieMonsterLegacyCookieAccessTest, SetLegacyNoSameSiteCookie) { … }
TEST_F(CookieMonsterLegacyCookieAccessTest, GetLegacyNoSameSiteCookie) { … }
TEST_F(CookieMonsterLegacyCookieAccessTest,
SetLegacySameSiteNoneInsecureCookie) { … }
TEST_F(CookieMonsterLegacyCookieAccessTest,
GetLegacySameSiteNoneInsecureCookie) { … }
TEST_F(CookieMonsterTest, IsCookieSentToSamePortThatSetIt) { … }
TEST_F(CookieMonsterTest, CookieDomainSetHistogram) { … }
TEST_F(CookieMonsterTest, CookiePortReadHistogram) { … }
TEST_F(CookieMonsterTest, CookiePortSetHistogram) { … }
TEST_F(CookieMonsterTest, CookiePortReadDiffersFromSetHistogram) { … }
TEST_F(CookieMonsterTest, CookieSourceSchemeNameHistogram) { … }
class FirstPartySetEnabledCookieMonsterTest : public CookieMonsterTest { … };
TEST_F(FirstPartySetEnabledCookieMonsterTest, RecordsPeriodicFPSSizes) { … }
TEST_F(CookieMonsterTest, GetAllCookiesForURLNonce) { … }
TEST_F(CookieMonsterTest, SiteHasCookieInOtherPartition) { … }
TEST_F(CookieMonsterTest, FilterCookiesWithOptionsExcludeShadowingDomains) { … }
TEST_F(CookieMonsterTest, FilterCookiesWithOptionsWarnShadowingDomains) { … }
TEST_F(CookieMonsterTest, FromStorageCookieCreated300DaysAgoThenUpdatedNow) { … }
TEST_F(CookieMonsterTest, FromStorageCookieCreated500DaysAgoThenUpdatedNow) { … }
TEST_F(CookieMonsterTest, SanitizedCookieCreated300DaysAgoThenUpdatedNow) { … }
TEST_F(CookieMonsterTest, SanitizedCookieCreated500DaysAgoThenUpdatedNow) { … }
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
}