#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include <utility>
#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/field_trial_param_associator.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "net/base/completion_once_callback.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/base/request_priority.h"
#include "net/base/test_completion_callback.h"
#include "net/disk_cache/blockfile/backend_impl.h"
#include "net/disk_cache/blockfile/entry_impl.h"
#include "net/disk_cache/cache_util.h"
#include "net/disk_cache/disk_cache_test_base.h"
#include "net/disk_cache/disk_cache_test_util.h"
#include "net/disk_cache/memory/mem_entry_impl.h"
#include "net/disk_cache/simple/simple_backend_impl.h"
#include "net/disk_cache/simple/simple_entry_format.h"
#include "net/disk_cache/simple/simple_entry_impl.h"
#include "net/disk_cache/simple/simple_histogram_enums.h"
#include "net/disk_cache/simple/simple_synchronous_entry.h"
#include "net/disk_cache/simple/simple_test_util.h"
#include "net/disk_cache/simple/simple_util.h"
#include "net/test/gtest_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
IsError;
IsOk;
Time;
EntryResult;
EntryResultCallback;
RangeResult;
ScopedEntryPtr;
class DiskCacheEntryTest : public DiskCacheTestWithCache { … };
void DiskCacheEntryTest::InternalSyncIOBackground(disk_cache::Entry* entry) { … }
void DiskCacheEntryTest::InternalSyncIO() { … }
TEST_F(DiskCacheEntryTest, InternalSyncIO) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyInternalSyncIO) { … }
void DiskCacheEntryTest::InternalAsyncIO() { … }
TEST_F(DiskCacheEntryTest, InternalAsyncIO) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyInternalAsyncIO) { … }
void DiskCacheEntryTest::ExternalSyncIOBackground(disk_cache::Entry* entry) { … }
void DiskCacheEntryTest::ExternalSyncIO() { … }
TEST_F(DiskCacheEntryTest, ExternalSyncIO) { … }
TEST_F(DiskCacheEntryTest, ExternalSyncIONoBuffer) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyExternalSyncIO) { … }
void DiskCacheEntryTest::ExternalAsyncIO() { … }
TEST_F(DiskCacheEntryTest, ExternalAsyncIO) { … }
#if BUILDFLAG(IS_IOS)
#define MAYBE_ExternalAsyncIONoBuffer …
#else
#define MAYBE_ExternalAsyncIONoBuffer …
#endif
TEST_F(DiskCacheEntryTest, MAYBE_ExternalAsyncIONoBuffer) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyExternalAsyncIO) { … }
void DiskCacheEntryTest::ReleaseBuffer(int stream_index) { … }
TEST_F(DiskCacheEntryTest, ReleaseBuffer) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyReleaseBuffer) { … }
void DiskCacheEntryTest::StreamAccess() { … }
TEST_F(DiskCacheEntryTest, StreamAccess) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyStreamAccess) { … }
void DiskCacheEntryTest::GetKey() { … }
TEST_F(DiskCacheEntryTest, GetKey) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyGetKey) { … }
void DiskCacheEntryTest::GetTimes(int stream_index) { … }
TEST_F(DiskCacheEntryTest, GetTimes) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyGetTimes) { … }
TEST_F(DiskCacheEntryTest, AppCacheGetTimes) { … }
TEST_F(DiskCacheEntryTest, ShaderCacheGetTimes) { … }
void DiskCacheEntryTest::GrowData(int stream_index) { … }
TEST_F(DiskCacheEntryTest, GrowData) { … }
TEST_F(DiskCacheEntryTest, GrowDataNoBuffer) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyGrowData) { … }
void DiskCacheEntryTest::TruncateData(int stream_index) { … }
TEST_F(DiskCacheEntryTest, TruncateData) { … }
TEST_F(DiskCacheEntryTest, TruncateDataNoBuffer) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyTruncateData) { … }
void DiskCacheEntryTest::ZeroLengthIO(int stream_index) { … }
TEST_F(DiskCacheEntryTest, ZeroLengthIO) { … }
TEST_F(DiskCacheEntryTest, ZeroLengthIONoBuffer) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyZeroLengthIO) { … }
void DiskCacheEntryTest::Buffering() { … }
TEST_F(DiskCacheEntryTest, Buffering) { … }
TEST_F(DiskCacheEntryTest, BufferingNoBuffer) { … }
void DiskCacheEntryTest::SizeAtCreate() { … }
TEST_F(DiskCacheEntryTest, SizeAtCreate) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlySizeAtCreate) { … }
void DiskCacheEntryTest::SizeChanges(int stream_index) { … }
TEST_F(DiskCacheEntryTest, SizeChanges) { … }
TEST_F(DiskCacheEntryTest, SizeChangesNoBuffer) { … }
void DiskCacheEntryTest::ReuseEntry(int size, int stream_index) { … }
TEST_F(DiskCacheEntryTest, ReuseExternalEntry) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyReuseExternalEntry) { … }
TEST_F(DiskCacheEntryTest, ReuseInternalEntry) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyReuseInternalEntry) { … }
void DiskCacheEntryTest::InvalidData(int stream_index) { … }
TEST_F(DiskCacheEntryTest, InvalidData) { … }
TEST_F(DiskCacheEntryTest, InvalidDataNoBuffer) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyInvalidData) { … }
void DiskCacheEntryTest::ReadWriteDestroyBuffer(int stream_index) { … }
TEST_F(DiskCacheEntryTest, ReadWriteDestroyBuffer) { … }
void DiskCacheEntryTest::DoomNormalEntry() { … }
TEST_F(DiskCacheEntryTest, DoomEntry) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyDoomEntry) { … }
void DiskCacheEntryTest::DoomEntryNextToOpenEntry() { … }
TEST_F(DiskCacheEntryTest, DoomEntryNextToOpenEntry) { … }
TEST_F(DiskCacheEntryTest, NewEvictionDoomEntryNextToOpenEntry) { … }
TEST_F(DiskCacheEntryTest, AppCacheDoomEntryNextToOpenEntry) { … }
void DiskCacheEntryTest::DoomedEntry(int stream_index) { … }
TEST_F(DiskCacheEntryTest, DoomedEntry) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyDoomedEntry) { … }
TEST_F(DiskCacheEntryTest, MissingData) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyEnumerationWithSparseEntries) { … }
void VerifySparseIO(disk_cache::Entry* entry,
int64_t offset,
net::IOBuffer* buf_1,
int size,
net::IOBuffer* buf_2) { … }
void VerifyContentSparseIO(disk_cache::Entry* entry,
int64_t offset,
char* buffer,
int size) { … }
void DiskCacheEntryTest::BasicSparseIO() { … }
TEST_F(DiskCacheEntryTest, BasicSparseIO) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyBasicSparseIO) { … }
void DiskCacheEntryTest::HugeSparseIO() { … }
TEST_F(DiskCacheEntryTest, HugeSparseIO) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyHugeSparseIO) { … }
void DiskCacheEntryTest::GetAvailableRangeTest() { … }
TEST_F(DiskCacheEntryTest, GetAvailableRange) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyGetAvailableRange) { … }
TEST_F(DiskCacheEntryTest, GetAvailableRangeBlockFileDiscontinuous) { … }
TEST_F(DiskCacheEntryTest, SparseWriteDropped) { … }
TEST_F(DiskCacheEntryTest, SparseSquentialWriteNotDropped) { … }
void DiskCacheEntryTest::CouldBeSparse() { … }
TEST_F(DiskCacheEntryTest, CouldBeSparse) { … }
TEST_F(DiskCacheEntryTest, MemoryCouldBeSparse) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyMisalignedSparseIO) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyMisalignedGetAvailableRange) { … }
void DiskCacheEntryTest::UpdateSparseEntry() { … }
TEST_F(DiskCacheEntryTest, UpdateSparseEntry) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyUpdateSparseEntry) { … }
void DiskCacheEntryTest::DoomSparseEntry() { … }
TEST_F(DiskCacheEntryTest, DoomSparseEntry) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyDoomSparseEntry) { … }
class SparseTestCompletionCallback: public net::TestCompletionCallback { … };
TEST_F(DiskCacheEntryTest, DoomSparseEntry2) { … }
void DiskCacheEntryTest::PartialSparseEntry() { … }
TEST_F(DiskCacheEntryTest, PartialSparseEntry) { … }
TEST_F(DiskCacheEntryTest, MemoryPartialSparseEntry) { … }
void DiskCacheEntryTest::SparseInvalidArg() { … }
TEST_F(DiskCacheEntryTest, SparseInvalidArg) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlySparseInvalidArg) { … }
TEST_F(DiskCacheEntryTest, SimpleSparseInvalidArg) { … }
void DiskCacheEntryTest::SparseClipEnd(int64_t max_index,
bool expect_unsupported) { … }
TEST_F(DiskCacheEntryTest, SparseClipEnd) { … }
TEST_F(DiskCacheEntryTest, SparseClipEnd2) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlySparseClipEnd) { … }
TEST_F(DiskCacheEntryTest, SimpleSparseClipEnd) { … }
TEST_F(DiskCacheEntryTest, CleanupSparseEntry) { … }
TEST_F(DiskCacheEntryTest, CancelSparseIO) { … }
TEST_F(DiskCacheEntryTest, KeySanityCheck) { … }
TEST_F(DiskCacheEntryTest, KeySanityCheck2) { … }
TEST_F(DiskCacheEntryTest, KeySanityCheck3) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheInternalAsyncIO) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheExternalAsyncIO) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheReleaseBuffer) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheStreamAccess) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheGetKey) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheGetTimes) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheGrowData) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheTruncateData) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheZeroLengthIO) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheSizeAtCreate) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheReuseExternalEntry) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheReuseInternalEntry) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheGiantEntry) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheSizeChanges) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheInvalidData) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheReadWriteDestroyBuffer) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheDoomEntry) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheDoomEntryNextToOpenEntry) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheDoomedEntry) { … }
bool DiskCacheEntryTest::SimpleCacheMakeBadChecksumEntry(const std::string& key,
int data_size) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheBadChecksum) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheErrorThenDoom) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheCreateAfterDiskLayerDoom) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheQueuedOpenOnDoomedEntry) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheDoomErrorRace) { … }
bool TruncatePath(const base::FilePath& file_path, int64_t length) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheNoEOF) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheNonOptimisticOperationsBasic) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheNonOptimisticOperationsDontBlock) { … }
TEST_F(DiskCacheEntryTest,
SimpleCacheNonOptimisticOperationsBasicsWithoutWaiting) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheOptimistic) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheOptimistic2) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheOptimistic3) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheOptimistic4) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheOptimistic5) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheOptimistic6) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheOptimisticWriteReleases) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheCreateDoomRace) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheDoomCreateRace) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheDoomCreateOptimistic) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheDoomCreateOptimisticMassDoom) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheDoomOpenOptimistic) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheDoomDoom) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheDoomCreateDoom) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheDoomCloseCreateCloseOpen) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheOptimisticCreateFailsOnOpen) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheEvictOldEntries) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheInFlightTruncate) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheInFlightRead) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheOpenCreateRaceWithNoIndex) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheMultipleReadersCheckCRC2) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheReadCombineCRC) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheNonSequentialWrite) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheStream1SizeChanges) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheCRCRewrite) { … }
bool DiskCacheEntryTest::SimpleCacheThirdStreamFileExists(const char* key) { … }
void DiskCacheEntryTest::SyncDoomEntry(const char* key) { … }
void DiskCacheEntryTest::CreateEntryWithHeaderBodyAndSideData(
const std::string& key,
int data_size) { … }
void DiskCacheEntryTest::TruncateFileFromEnd(int file_index,
const std::string& key,
int data_size,
int truncate_size) { … }
void DiskCacheEntryTest::UseAfterBackendDestruction() { … }
void DiskCacheEntryTest::CloseSparseAfterBackendDestruction() { … }
TEST_F(DiskCacheEntryTest, SimpleCacheOmittedThirdStream1) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheOmittedThirdStream2) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheOmittedThirdStream3) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheOmittedThirdStream4) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheOmittedThirdStream5) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheDoomOptimisticWritesRace) { … }
TEST_F(DiskCacheEntryTest, SimpleCachePreserveActiveEntries) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheBasicSparseIO) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheHugeSparseIO) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheGetAvailableRange) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheUpdateSparseEntry) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheDoomSparseEntry) { … }
TEST_F(DiskCacheEntryTest, SimpleCachePartialSparseEntry) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheTruncateLargeSparseFile) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheNoBodyEOF) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheNoSideDataEOF) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheReadWithoutKeySHA256) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheDoubleOpenWithoutKeySHA256) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheReadCorruptKeySHA256) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheReadCorruptLength) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheCreateRecoverFromRmdir) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheSparseErrorHandling) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheCreateCollision) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheConvertToSparseStream2LeftOver) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheLazyStream2CreateFailure) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheChecksumpScrewUp) { … }
TEST_F(DiskCacheEntryTest, SimpleUseAfterBackendDestruction) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyUseAfterBackendDestruction) { … }
TEST_F(DiskCacheEntryTest, SimpleCloseSparseAfterBackendDestruction) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyCloseSparseAfterBackendDestruction) { … }
void DiskCacheEntryTest::LastUsedTimePersists() { … }
TEST_F(DiskCacheEntryTest, LastUsedTimePersists) { … }
TEST_F(DiskCacheEntryTest, SimpleLastUsedTimePersists) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyLastUsedTimePersists) { … }
void DiskCacheEntryTest::TruncateBackwards() { … }
TEST_F(DiskCacheEntryTest, TruncateBackwards) { … }
TEST_F(DiskCacheEntryTest, SimpleTruncateBackwards) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyTruncateBackwards) { … }
void DiskCacheEntryTest::ZeroWriteBackwards() { … }
TEST_F(DiskCacheEntryTest, ZeroWriteBackwards) { … }
TEST_F(DiskCacheEntryTest, SimpleZeroWriteBackwards) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlyZeroWriteBackwards) { … }
void DiskCacheEntryTest::SparseOffset64Bit() { … }
TEST_F(DiskCacheEntryTest, SparseOffset64Bit) { … }
TEST_F(DiskCacheEntryTest, SimpleSparseOffset64Bit) { … }
TEST_F(DiskCacheEntryTest, MemoryOnlySparseOffset64Bit) { … }
TEST_F(DiskCacheEntryTest, SimpleCacheCloseResurrection) { … }
TEST_F(DiskCacheEntryTest, BlockFileSparsePendingAfterDtor) { … }
class DiskCacheSimplePrefetchTest : public DiskCacheEntryTest { … };
TEST_F(DiskCacheSimplePrefetchTest, NoPrefetch) { … }
TEST_F(DiskCacheSimplePrefetchTest, YesPrefetch) { … }
TEST_F(DiskCacheSimplePrefetchTest, YesPrefetchNoRead) { … }
TEST_F(DiskCacheSimplePrefetchTest, BadChecksumSmall) { … }
TEST_F(DiskCacheSimplePrefetchTest, ChecksumNoPrefetch) { … }
TEST_F(DiskCacheSimplePrefetchTest, NoChecksumNoPrefetch) { … }
TEST_F(DiskCacheSimplePrefetchTest, ChecksumPrefetch) { … }
TEST_F(DiskCacheSimplePrefetchTest, NoChecksumPrefetch) { … }
TEST_F(DiskCacheSimplePrefetchTest, PrefetchReadsSync) { … }
TEST_F(DiskCacheSimplePrefetchTest, NoFullNoSpeculative) { … }
TEST_F(DiskCacheSimplePrefetchTest, NoFullSmallSpeculative) { … }
TEST_F(DiskCacheSimplePrefetchTest, NoFullLargeSpeculative) { … }
TEST_F(DiskCacheSimplePrefetchTest, SmallFullNoSpeculative) { … }
TEST_F(DiskCacheSimplePrefetchTest, LargeFullNoSpeculative) { … }
TEST_F(DiskCacheSimplePrefetchTest, SmallFullSmallSpeculative) { … }
TEST_F(DiskCacheSimplePrefetchTest, LargeFullSmallSpeculative) { … }
class DiskCacheSimpleAppCachePrefetchTest : public DiskCacheSimplePrefetchTest { … };
TEST_F(DiskCacheSimpleAppCachePrefetchTest, NoFullNoSpeculative) { … }
TEST_F(DiskCacheSimpleAppCachePrefetchTest, NoFullSmallSpeculative) { … }
TEST_F(DiskCacheSimpleAppCachePrefetchTest, NoFullLargeSpeculative) { … }
TEST_F(DiskCacheSimpleAppCachePrefetchTest, SmallFullNoSpeculative) { … }
TEST_F(DiskCacheSimpleAppCachePrefetchTest, LargeFullNoSpeculative) { … }
TEST_F(DiskCacheSimpleAppCachePrefetchTest, SmallFullSmallSpeculative) { … }
TEST_F(DiskCacheSimpleAppCachePrefetchTest, LargeFullSmallSpeculative) { … }