#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "content/browser/storage_partition_impl.h"
#include <stddef.h>
#include <stdint.h>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "base/containers/contains.h"
#include "base/files/file_path.h"
#include "base/files/file_util.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/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/scoped_observation.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/test/bind.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_command_line.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_future.h"
#include "base/threading/sequence_local_storage_slot.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/services/storage/dom_storage/async_dom_storage_database.h"
#include "components/services/storage/dom_storage/dom_storage_database.h"
#include "components/services/storage/dom_storage/local_storage_database.pb.h"
#include "components/services/storage/public/cpp/constants.h"
#include "components/services/storage/public/mojom/local_storage_control.mojom.h"
#include "components/services/storage/public/mojom/partition.mojom.h"
#include "components/services/storage/public/mojom/storage_service.mojom.h"
#include "components/services/storage/public/mojom/storage_usage_info.mojom.h"
#include "components/services/storage/shared_storage/async_shared_storage_database_impl.h"
#include "components/services/storage/shared_storage/shared_storage_manager.h"
#include "components/services/storage/shared_storage/shared_storage_options.h"
#include "components/services/storage/storage_service_impl.h"
#include "content/browser/aggregation_service/aggregation_service_test_utils.h"
#include "content/browser/attribution_reporting/test/mock_attribution_manager.h"
#include "content/browser/code_cache/generated_code_cache.h"
#include "content/browser/code_cache/generated_code_cache_context.h"
#include "content/browser/gpu/gpu_disk_cache_factory.h"
#include "content/browser/interest_group/interest_group_manager_impl.h"
#include "content/browser/interest_group/interest_group_permissions_cache.h"
#include "content/browser/interest_group/interest_group_permissions_checker.h"
#include "content/browser/private_aggregation/private_aggregation_manager.h"
#include "content/browser/private_aggregation/private_aggregation_test_utils.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/browsing_data_filter_builder.h"
#include "content/public/browser/generated_code_cache_settings.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/storage_usage_info.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_utils.h"
#include "content/services/auction_worklet/public/mojom/bidder_worklet.mojom.h"
#include "net/base/network_isolation_key.h"
#include "net/base/schemeful_site.h"
#include "net/base/test_completion_callback.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_access_result.h"
#include "net/cookies/cookie_inclusion_status.h"
#include "ppapi/buildflags/buildflags.h"
#include "services/network/cookie_manager.h"
#include "services/network/public/cpp/features.h"
#include "storage/browser/quota/quota_client_type.h"
#include "storage/browser/quota/quota_manager.h"
#include "storage/browser/quota/quota_manager_proxy.h"
#include "storage/browser/test/mock_quota_client.h"
#include "storage/browser/test/mock_quota_manager.h"
#include "storage/browser/test/mock_special_storage_policy.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/interest_group/interest_group.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/interest_group/interest_group_types.mojom.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom-shared.h"
#include "third_party/leveldatabase/env_chromium.h"
#include "url/gurl.h"
#include "url/origin.h"
#if BUILDFLAG(IS_ANDROID)
#include "content/public/browser/android/java_interfaces.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#endif
CanonicalCookie;
CookieDeletionFilter;
CookieDeletionFilterPtr;
namespace content {
namespace {
const char kCacheKey[] = …;
const char kCacheValue[] = …;
const blink::mojom::StorageType kTemporary = …;
const blink::mojom::StorageType kSyncable = …;
const storage::QuotaClientType kClientFile = …;
const uint32_t kAllQuotaRemoveMask = …;
class RemoveCookieTester { … };
class RemoveInterestGroupTester { … };
class RemoveLocalStorageTester { … };
class RemoveCodeCacheTester { … };
class MockDataRemovalObserver : public StoragePartition::DataRemovalObserver { … };
bool IsWebSafeSchemeForTest(const std::string& scheme) { … }
bool DoesOriginMatchForUnprotectedWeb(
const blink::StorageKey& storage_key,
storage::SpecialStoragePolicy* special_storage_policy) { … }
bool DoesOriginMatchForBothProtectedAndUnprotectedWeb(
const blink::StorageKey& storage_key,
storage::SpecialStoragePolicy* special_storage_policy) { … }
bool DoesOriginMatchUnprotected(
const url::Origin& desired_origin,
const blink::StorageKey& storage_key,
storage::SpecialStoragePolicy* special_storage_policy) { … }
void ClearQuotaData(content::StoragePartition* partition,
base::RunLoop* loop_to_quit) { … }
void ClearQuotaDataWithOriginMatcher(
content::StoragePartition* partition,
StoragePartition::StorageKeyPolicyMatcherFunction storage_key_matcher,
const base::Time delete_begin,
base::RunLoop* loop_to_quit) { … }
void ClearQuotaDataForOrigin(content::StoragePartition* partition,
const GURL& remove_origin,
const base::Time delete_begin,
base::RunLoop* loop_to_quit) { … }
void ClearQuotaDataForTemporary(content::StoragePartition* partition,
const base::Time delete_begin,
base::RunLoop* loop_to_quit) { … }
void ClearCookies(content::StoragePartition* partition,
const base::Time delete_begin,
const base::Time delete_end,
base::RunLoop* run_loop) { … }
void ClearCookiesMatchingInfo(content::StoragePartition* partition,
CookieDeletionFilterPtr delete_filter,
base::RunLoop* run_loop) { … }
void ClearStuff(
uint32_t remove_mask,
content::StoragePartition* partition,
const base::Time delete_begin,
const base::Time delete_end,
BrowsingDataFilterBuilder* filter_builder,
StoragePartition::StorageKeyPolicyMatcherFunction storage_key_matcher,
base::RunLoop* run_loop) { … }
void ClearData(content::StoragePartition* partition, base::RunLoop* run_loop) { … }
void ClearDataForOrigin(uint32_t remove_mask,
content::StoragePartition* partition,
const GURL& origin,
base::RunLoop* run_loop) { … }
void ClearCodeCache(content::StoragePartition* partition,
base::Time begin_time,
base::Time end_time,
base::RepeatingCallback<bool(const GURL&)> url_predicate,
base::RunLoop* run_loop) { … }
bool FilterURL(const GURL& filter_url, const GURL& url) { … }
void ClearInterestGroups(content::StoragePartition* partition,
const base::Time delete_begin,
const base::Time delete_end,
base::RunLoop* run_loop) { … }
void ClearInterestGroupsAndKAnon(content::StoragePartition* partition,
const base::Time delete_begin,
const base::Time delete_end,
base::RunLoop* run_loop) { … }
void ClearInterestGroupPermissionsCache(content::StoragePartition* partition,
const base::Time delete_begin,
const base::Time delete_end,
base::RunLoop* run_loop) { … }
bool FilterMatchesCookie(const CookieDeletionFilterPtr& filter,
const net::CanonicalCookie& cookie) { … }
}
class StoragePartitionImplTest : public testing::Test { … };
class StoragePartitionShaderClearTest : public testing::Test { … };
TEST_F(StoragePartitionShaderClearTest, ClearShaderCache) { … }
TEST_F(StoragePartitionImplTest, QuotaClientTypesGeneration) { … }
storage::BucketInfo AddQuotaManagedBucket(
storage::MockQuotaManager* manager,
const blink::StorageKey& storage_key,
const std::string& bucket_name,
blink::mojom::StorageType type,
base::Time modified = base::Time::Now()) { … }
TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverBoth) { … }
TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverOnlyTemporary) { … }
TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverOnlySyncable) { … }
TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverNeither) { … }
TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverSpecificOrigin) { … }
TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForLastHour) { … }
TEST_F(StoragePartitionImplTest, RemoveQuotaManagedTemporaryDataForLastWeek) { … }
TEST_F(StoragePartitionImplTest, RemoveQuotaManagedUnprotectedOrigins) { … }
TEST_F(StoragePartitionImplTest, RemoveQuotaManagedProtectedOrigins) { … }
TEST_F(StoragePartitionImplTest, RemoveQuotaManagedIgnoreDevTools) { … }
TEST_F(StoragePartitionImplTest, RemoveCookieForever) { … }
TEST_F(StoragePartitionImplTest, RemoveCookieLastHour) { … }
TEST_F(StoragePartitionImplTest, RemoveCookieWithDeleteInfo) { … }
TEST_F(StoragePartitionImplTest, RemoveInterestGroupForever) { … }
TEST_F(StoragePartitionImplTest, RemoveInterestGroupPermissionsCacheForever) { … }
TEST_F(StoragePartitionImplTest, RemoveUnprotectedLocalStorageForever) { … }
TEST_F(StoragePartitionImplTest, RemoveProtectedLocalStorageForever) { … }
TEST_F(StoragePartitionImplTest, RemoveLocalStorageForLastWeek) { … }
TEST_F(StoragePartitionImplTest, RemoveLocalStorageForOrigins) { … }
TEST_F(StoragePartitionImplTest, RemoveLocalStorageForOneOrigin) { … }
TEST_F(StoragePartitionImplTest, ClearCodeCache) { … }
TEST_F(StoragePartitionImplTest, ClearCodeCacheSpecificURL) { … }
TEST_F(StoragePartitionImplTest, ClearCodeCacheDateRange) { … }
TEST_F(StoragePartitionImplTest, ClearWasmCodeCache) { … }
TEST_F(StoragePartitionImplTest, ClearWebUICodeCache) { … }
TEST_F(StoragePartitionImplTest, WebUICodeCacheDisabled) { … }
TEST_F(StoragePartitionImplTest, ClearCodeCacheIncognito) { … }
TEST(StoragePartitionImplStaticTest, CreatePredicateForHostCookies) { … }
TEST_F(StoragePartitionImplTest, AttributionManagerCreatedInIncognito) { … }
TEST_F(StoragePartitionImplTest, AttributionReportingClearData) { … }
TEST_F(StoragePartitionImplTest, AttributionReportingClearDataWrongMask) { … }
TEST_F(StoragePartitionImplTest, AttributionReportingClearDataForFilter) { … }
TEST_F(StoragePartitionImplTest, DataRemovalObserver) { … }
TEST_F(StoragePartitionImplTest, RemoveAggregationServiceData) { … }
TEST_F(StoragePartitionImplTest, RemovePrivateAggregationData) { … }
TEST(StorageServiceImplOnSequenceLocalStorage, ThreadDestructionDoesNotFail) { … }
class StoragePartitionImplSharedStorageTest : public StoragePartitionImplTest { … };
TEST_F(StoragePartitionImplSharedStorageTest,
RemoveUnprotectedSharedStorageForever) { … }
TEST_F(StoragePartitionImplSharedStorageTest,
RemoveProtectedSharedStorageForever) { … }
TEST_F(StoragePartitionImplSharedStorageTest, RemoveSharedStorageRecent) { … }
TEST_F(StoragePartitionImplTest, PrivateNetworkAccessPermission) { … }
}