#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/core/loader/resource/image_resource.h"
#include <memory>
#include <string_view>
#include "base/task/single_thread_task_runner.h"
#include "base/test/metrics/histogram_tester.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/loader/referrer_utils.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-blink.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_url.h"
#include "third_party/blink/public/platform/web_url_response.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/loader/empty_clients.h"
#include "third_party/blink/renderer/core/loader/resource/mock_image_resource_observer.h"
#include "third_party/blink/renderer/core/svg/graphics/svg_image.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
#include "third_party/blink/renderer/core/testing/scoped_mock_overlay_scrollbars.h"
#include "third_party/blink/renderer/platform/exported/wrapped_resource_response.h"
#include "third_party/blink/renderer/platform/graphics/bitmap_image.h"
#include "third_party/blink/renderer/platform/graphics/image.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/thread_state.h"
#include "third_party/blink/renderer/platform/instrumentation/instance_counters.h"
#include "third_party/blink/renderer/platform/loader/fetch/console_logger.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_initiator_info.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_initiator_type_names.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_parameters.h"
#include "third_party/blink/renderer/platform/loader/fetch/memory_cache.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_finish_observer.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_loader.h"
#include "third_party/blink/renderer/platform/loader/fetch/unique_identifier.h"
#include "third_party/blink/renderer/platform/loader/testing/mock_fetch_context.h"
#include "third_party/blink/renderer/platform/loader/testing/mock_resource_client.h"
#include "third_party/blink/renderer/platform/loader/testing/test_loader_factory.h"
#include "third_party/blink/renderer/platform/loader/testing/test_resource_fetcher_properties.h"
#include "third_party/blink/renderer/platform/network/http_names.h"
#include "third_party/blink/renderer/platform/scheduler/test/fake_frame_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/test/fake_task_runner.h"
#include "third_party/blink/renderer/platform/testing/mock_context_lifecycle_notifier.h"
#include "third_party/blink/renderer/platform/testing/scoped_mocked_url.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support_with_mock_scheduler.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/url_loader_mock_factory.h"
#include "third_party/blink/renderer/platform/wtf/shared_buffer.h"
#include "third_party/blink/renderer/platform/wtf/text/base64.h"
namespace blink {
ScopedMockedURLLoad;
namespace {
constexpr unsigned char kJpegImage[] = …;
constexpr int kJpegImageWidth = …;
constexpr int kJpegImageHeight = …;
constexpr size_t kJpegImageSubrangeWithDimensionsLength = …;
constexpr size_t kJpegImageSubrangeWithoutDimensionsLength = …;
class ImageResourceTest : public testing::Test,
private ScopedMockOverlayScrollbars { … };
TEST_F(ImageResourceTest, DimensionsDecodableFromPartialTestImage) { … }
constexpr unsigned char kJpegImage2[] = …;
constexpr std::string_view kSvgImage = …;
constexpr std::string_view kSvgImage2 = …;
constexpr char kTestURL[] = …;
String GetTestFilePath() { … }
constexpr std::string_view kSvgImageWithSubresource = …;
void ReceiveResponse(ImageResource* image_resource,
const KURL& url,
const char* mime_type,
base::span<const char> data) { … }
AtomicString BuildContentRange(size_t range_length, size_t total_length) { … }
ResourceFetcher* CreateFetcher() { … }
TEST_F(ImageResourceTest, MultipartImage) { … }
TEST_F(ImageResourceTest, BitmapMultipartImage) { … }
TEST_F(ImageResourceTest, CancelOnRemoveObserver) { … }
class MockFinishObserver : public ResourceFinishObserver { … };
TEST_F(ImageResourceTest, CancelWithImageAndFinishObserver) { … }
TEST_F(ImageResourceTest, DecodedDataRemainsWhileHasClients) { … }
TEST_F(ImageResourceTest, UpdateBitmapImages) { … }
TEST_F(ImageResourceTest, SVGImage) { … }
TEST_F(ImageResourceTest, SVGImageWithSubresource) { … }
TEST_F(ImageResourceTest, SuccessfulRevalidationJpeg) { … }
TEST_F(ImageResourceTest, SuccessfulRevalidationSvg) { … }
TEST_F(ImageResourceTest, FailedRevalidationJpegToJpeg) { … }
TEST_F(ImageResourceTest, FailedRevalidationJpegToSvg) { … }
TEST_F(ImageResourceTest, FailedRevalidationSvgToJpeg) { … }
TEST_F(ImageResourceTest, FailedRevalidationSvgToSvg) { … }
TEST_F(ImageResourceTest, Prune) { … }
TEST_F(ImageResourceTest, CancelOnDecodeError) { … }
TEST_F(ImageResourceTest, DecodeErrorWithEmptyBody) { … }
TEST_F(ImageResourceTest, PartialContentWithoutDimensions) { … }
TEST_F(ImageResourceTest, PeriodicFlushTest) { … }
TEST_F(ImageResourceTest, DeferredInvalidation) { … }
constexpr unsigned char kLossyWebPImage[] = …;
constexpr unsigned char kLosslessWebPImage[] = …;
constexpr unsigned char kExtendedWebPImage[] = …;
TEST_F(ImageResourceTest, WebPSniffing) { … }
}
class ImageResourceCounterTest : public testing::Test { … };
TEST_F(ImageResourceCounterTest, InstanceCounters) { … }
TEST_F(ImageResourceCounterTest, InstanceCounters_UserAgent) { … }
TEST_F(ImageResourceCounterTest, RevalidationPolicyMetrics) { … }
}