chromium/third_party/blink/renderer/core/loader/resource/image_resource_test.cc

/*
 * Copyright (c) 2013, Google Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the
 * distribution.
 *     * Neither the name of Google Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#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/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 {

// An image of size 1x1.
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 {};

// Ensure that the image decoder can determine the dimensions of kJpegImage from
// just the first kJpegImageSubrangeWithDimensionsLength bytes. If this test
// fails, then the test data here probably needs to be updated.
TEST_F(ImageResourceTest, DimensionsDecodableFromPartialTestImage) {}

// An image of size 50x50.
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) {}

// Tests for pruning.

TEST_F(ImageResourceTest, Prune) {}

TEST_F(ImageResourceTest, CancelOnDecodeError) {}

TEST_F(ImageResourceTest, DecodeErrorWithEmptyBody) {}

// Testing DecodeError that occurs in didFinishLoading().
// This is similar to DecodeErrorWithEmptyBody, but with non-empty body.
TEST_F(ImageResourceTest, PartialContentWithoutDimensions) {}

TEST_F(ImageResourceTest, PeriodicFlushTest) {}

TEST_F(ImageResourceTest, DeferredInvalidation) {}

// A lossy 2x2 WebP image.
constexpr unsigned char kLossyWebPImage[] =;

// A lossless 2x2 WebP image.
constexpr unsigned char kLosslessWebPImage[] =;

// An extended lossy 2x2 WebP image.
constexpr unsigned char kExtendedWebPImage[] =;

TEST_F(ImageResourceTest, WebPSniffing) {}

}  // namespace

class ImageResourceCounterTest : public testing::Test {};

TEST_F(ImageResourceCounterTest, InstanceCounters) {}

TEST_F(ImageResourceCounterTest, InstanceCounters_UserAgent) {}

TEST_F(ImageResourceCounterTest, RevalidationPolicyMetrics) {}

}  // namespace blink