chromium/third_party/blink/renderer/platform/graphics/parkable_image_test.cc

// Copyright 2021 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/graphics/parkable_image.h"

#include "base/containers/heap_array.h"
#include "base/memory/raw_ptr.h"
#include "base/synchronization/lock.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 "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/platform/disk_data_allocator_test_utils.h"
#include "third_party/blink/renderer/platform/graphics/parkable_image_manager.h"
#include "third_party/blink/renderer/platform/image-decoders/image_decoder_test_helpers.h"
#include "third_party/blink/renderer/platform/wtf/shared_buffer.h"

ThreadPoolExecutionMode;

namespace blink {

namespace {
class LambdaThreadDelegate : public base::PlatformThread::Delegate {};
}  // namespace

// Parent for ParkableImageTest and ParkableImageNoParkingTest. The only
// difference between those two is whether parking is enabled or not.
class ParkableImageBaseTest : public ::testing::Test {};

// Parking is enabled for these tests.
class ParkableImageTest : public ParkableImageBaseTest {};

// Parking is delayed but enabled for these tests.
class ParkableImageDelayedTest : public ParkableImageBaseTest {};

// Parking is disabled for these tests.
class ParkableImageNoParkingTest : public ParkableImageBaseTest {};

class ParkableImageWithLimitedDiskCapacityTest : public ParkableImageBaseTest {};

// Tests that ParkableImages are constructed with the correct size.
TEST_F(ParkableImageTest, Size) {}

// Tests that |Freeze|ing a ParkableImage correctly updates its state.
TEST_F(ParkableImageTest, Frozen) {}

TEST_F(ParkableImageTest, LockAndUnlock) {}

// Tests that |Append|ing to a ParkableImage correctly adds data to it.
TEST_F(ParkableImageTest, Append) {}

// Tests that multiple |Append|s correctly add data to the end of ParkableImage.
TEST_F(ParkableImageTest, AppendMultiple) {}

// Tests that we can read/write to disk correctly, preserving the data.
TEST_F(ParkableImageTest, ParkAndUnpark) {}

// Tests that trying to park multiple times doesn't add any extra tasks.
TEST_F(ParkableImageTest, ParkTwiceAndUnpark) {}

// Tests that we can park to disk synchronously after the data is stored on
// disk the first time.
TEST_F(ParkableImageTest, ParkAndUnparkSync) {}

// Tests that creating a snapshot partway through writing correctly aborts
// discarding the data.
TEST_F(ParkableImageTest, ParkAndUnparkAborted) {}

// Tests that a frozen image will be written to disk by the manager.
TEST_F(ParkableImageTest, ManagerSimple) {}

// Tests that a small image is not kept in the manager.
TEST_F(ParkableImageTest, ManagerSmall) {}

// Tests that the manager can correctly handle multiple parking tasks being
// created at once.
TEST_F(ParkableImageTest, ManagerTwo) {}

// Test that a non-frozen image will not be written to disk.
TEST_F(ParkableImageTest, ManagerNonFrozen) {}

// Check that trying to unpark a ParkableImage when parking is disabled has no
// effect.
TEST_F(ParkableImageNoParkingTest, Unpark) {}

// Tests that the ParkableImageManager is correctly recording statistics after 5
// minutes.
TEST_F(ParkableImageTest, ManagerStatistics5min) {}

// Tests that the ParkableImageManager is correctly recording statistics after 5
// minutes, even when parking is disabled. Only bookkeeping metrics should be
// recorded in this case, since no reads/writes will happen.
TEST_F(ParkableImageNoParkingTest, ManagerStatistics5min) {}

// Tests that the manager doesn't try to park any images when parking is
// disabled.
TEST_F(ParkableImageNoParkingTest, ManagerSimple) {}

// Test a locked image will not be written to disk.
TEST_F(ParkableImageTest, ManagerNotUnlocked) {}

// Tests that the manager only reschedules the parking task  when there are
// unfrozen ParkableImages.
TEST_F(ParkableImageTest, ManagerRescheduleUnfrozen) {}

// We want to test that trying to delete an image while we try to park it works
// correctly. The expected behaviour is we park it, then delete. Slightly
// inefficient, but the safest way to do it.
TEST_F(ParkableImageTest, DestroyOnSeparateThread) {}

TEST_F(ParkableImageTest, FailedWrite) {}

// Test that we park only after 30 seconds, not immediately after freezing.
TEST_F(ParkableImageDelayedTest, Simple) {}

// Test that we park only after 30 seconds or once we have read the data, not
// immediately after freezing.
TEST_F(ParkableImageDelayedTest, Read) {}

// 30 seconds should be counted from when we freeze, and not be affected by
// parking/unparking.
TEST_F(ParkableImageDelayedTest, ParkAndUnpark) {}

TEST_F(ParkableImageWithLimitedDiskCapacityTest, ParkWithLimitedDiskCapacity) {}

}  // namespace blink