chromium/third_party/blink/renderer/platform/bindings/parkable_string_test.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#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 =;

// Compressed size of the string returned by |MakeLargeString()|.
// Update if the assertion in the |CheckCompressedSize()| test fails.
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 {};

}  // namespace

class ParkableStringTest
    : public testing::TestWithParam<ParkableStringImpl::CompressionAlgorithm> {};

INSTANTIATE_TEST_SUITE_P();

// The main aim of this test is to check that the compressed size of a string
// doesn't change. If it does, |kCompressedSizeZlib| and/or
// |kCompressedSizeSnappy| will need to be updated.
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) {}

// Non-regression test for crbug.com/905137.
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) {}

// Flaky on a few platforms: crbug.com/1168170.
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) {}

// Same test as the previous one, with RAIL mode transitions.
TEST_P(ParkableStringTestLessAggressiveMode, NoParkingWhileLoading) {}

// Combination of background and loading.
TEST_P(ParkableStringTestLessAggressiveMode,
       NoParkingWhileLoadingOrInForeground) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace blink