#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/platform/bindings/parkable_string.h"
#include <algorithm>
#include <cstring>
#include <limits>
#include "base/functional/bind.h"
#include "base/rand_util.h"
#include "base/run_loop.h"
#include "base/task/thread_pool.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "base/timer/elapsed_timer.h"
#include "base/trace_event/memory_allocator_dump.h"
#include "base/trace_event/memory_dump_provider.h"
#include "base/trace_event/process_memory_dump.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/platform/scheduler/test/renderer_scheduler_test_support.h"
#include "third_party/blink/renderer/platform/bindings/parkable_string_manager.h"
#include "third_party/blink/renderer/platform/disk_data_allocator_test_utils.h"
#include "third_party/blink/renderer/platform/instrumentation/memory_pressure_listener.h"
#include "third_party/blink/renderer/platform/scheduler/public/rail_mode_observer.h"
#include "third_party/blink/renderer/platform/wtf/allocator/partitions.h"
ThreadPoolExecutionMode;
namespace blink {
namespace {
constexpr size_t kSizeKb = …;
constexpr size_t kCompressedSizeZlib = …;
constexpr size_t kCompressedSizeSnappy = …;
#if BUILDFLAG(HAS_ZSTD_COMPRESSION)
constexpr size_t kCompressedSizeZstd = …;
#endif
String MakeLargeString(char c = 'a') { … }
String MakeComplexString(size_t size) { … }
class LambdaThreadDelegate : public base::PlatformThread::Delegate { … };
}
class ParkableStringTest
: public testing::TestWithParam<ParkableStringImpl::CompressionAlgorithm> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(ParkableStringTest, CheckCompressedSize) { … }
TEST_P(ParkableStringTest, DontCompressRandomString) { … }
TEST_P(ParkableStringTest, ParkUnparkIdenticalContent) { … }
TEST_P(ParkableStringTest, DecompressUtf16String) { … }
TEST_P(ParkableStringTest, Simple) { … }
TEST_P(ParkableStringTest, Park) { … }
TEST_P(ParkableStringTest, EqualityNoUnparking) { … }
TEST_P(ParkableStringTest, AbortParking) { … }
TEST_P(ParkableStringTest, AbortedParkingRetainsCompressedData) { … }
TEST_P(ParkableStringTest, Unpark) { … }
TEST_P(ParkableStringTest, BackgroundUnparkFromMemory) { … }
TEST_P(ParkableStringTest, BackgroundUnparkFromDisk) { … }
struct ParkableStringWrapper { … };
TEST_P(ParkableStringTest, BackgroundDestruct) { … }
TEST_P(ParkableStringTest, LockUnlock) { … }
TEST_P(ParkableStringTest, LockParkedString) { … }
TEST_P(ParkableStringTest, DelayFirstParkingOfString) { … }
TEST_P(ParkableStringTest, ManagerSimple) { … }
TEST_P(ParkableStringTest, ManagerMultipleStrings) { … }
TEST_P(ParkableStringTest, ShouldPark) { … }
#if defined(ADDRESS_SANITIZER)
#define EXPECT_ASAN_DEATH …
#else
#define EXPECT_ASAN_DEATH(statement, regex) …
#endif
TEST_P(ParkableStringTest, AsanPoisoningTest) { … }
TEST_P(ParkableStringTest, CorrectAsanPoisoning) { … }
TEST_P(ParkableStringTest, Compression) { … }
TEST_P(ParkableStringTest, SynchronousCompression) { … }
TEST_P(ParkableStringTest, CompressionFailed) { … }
TEST_P(ParkableStringTest, ToAndFromDisk) { … }
TEST_P(ParkableStringTest, UnparkWhileWritingToDisk) { … }
TEST_P(ParkableStringTest, NoCompetingWritingToDisk) { … }
TEST_P(ParkableStringTest, SynchronousToDisk) { … }
TEST_P(ParkableStringTest, OnPurgeMemory) { … }
TEST_P(ParkableStringTest, ReportMemoryDump) { … }
TEST_P(ParkableStringTest, MemoryFootprintForDump) { … }
TEST_P(ParkableStringTest, CompressionDisabled) { … }
TEST_P(ParkableStringTest, CompressionDisabledDisablesDisk) { … }
TEST_P(ParkableStringTest, Aging) { … }
TEST_P(ParkableStringTest, NoPrematureAging) { … }
TEST_P(ParkableStringTest, OldStringsAreParked) { … }
TEST_P(ParkableStringTest, AgingTicksStopsAndRestarts) { … }
TEST_P(ParkableStringTest, AgingTicksStopsWithNoProgress) { … }
TEST_P(ParkableStringTest, DISABLED_OnlyOneAgingTask) { … }
TEST_P(ParkableStringTest, ReportTotalUnparkingTime) { … }
TEST_P(ParkableStringTest, ReportTotalDiskTime) { … }
TEST_P(ParkableStringTest, EncodingAndDeduplication) { … }
class ParkableStringTestWithQueuedThreadPool : public ParkableStringTest { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(ParkableStringTestWithQueuedThreadPool, AgingParkingInProgress) { … }
class ParkableStringTestWithLimitedDiskCapacity : public ParkableStringTest { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(ParkableStringTestWithLimitedDiskCapacity, ParkWithLimitedDiskCapacity) { … }
class ParkableStringTestLessAggressiveMode : public ParkableStringTest { … };
TEST_P(ParkableStringTestLessAggressiveMode, NoParkingInForeground) { … }
TEST_P(ParkableStringTestLessAggressiveMode, NoParkingWhileLoading) { … }
TEST_P(ParkableStringTestLessAggressiveMode,
NoParkingWhileLoadingOrInForeground) { … }
INSTANTIATE_TEST_SUITE_P(…);
}