chromium/third_party/blink/renderer/platform/image-decoders/image_decoder_test.cc

// Copyright 2013 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/image-decoders/image_decoder.h"

#include <memory>
#include "build/build_config.h"
#include "media/media_buildflags.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/platform/image-decoders/image_frame.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace blink {

class TestImageDecoder : public ImageDecoder {};

TEST(ImageDecoderTest, sizeCalculationMayOverflow) {}

TEST(ImageDecoderTest, requiredPreviousFrameIndex) {}

TEST(ImageDecoderTest, requiredPreviousFrameIndexDisposeOverwriteBgcolor) {}

TEST(ImageDecoderTest, requiredPreviousFrameIndexForFrame1) {}

TEST(ImageDecoderTest, requiredPreviousFrameIndexBlendAtopBgcolor) {}

TEST(ImageDecoderTest, requiredPreviousFrameIndexKnownOpaque) {}

TEST(ImageDecoderTest, clearCacheExceptFrameDoNothing) {}

TEST(ImageDecoderTest, clearCacheExceptFrameAll) {}

TEST(ImageDecoderTest, clearCacheExceptFramePreverveClearExceptFrame) {}

#if BUILDFLAG(IS_FUCHSIA)

TEST(ImageDecoderTest, decodedSizeLimitBoundary) {
  constexpr unsigned kWidth = 100;
  constexpr unsigned kHeight = 200;
  constexpr unsigned kBitDepth = 4;
  std::unique_ptr<TestImageDecoder> decoder(std::make_unique<TestImageDecoder>(
      ImageDecoder::kDefaultBitDepth, (kWidth * kHeight * kBitDepth)));

  // Smallest allowable size, should succeed.
  EXPECT_TRUE(decoder->SetSize(1, 1));
  EXPECT_TRUE(decoder->IsSizeAvailable());
  EXPECT_FALSE(decoder->Failed());

  // At the limit, should succeed.
  EXPECT_TRUE(decoder->SetSize(kWidth, kHeight));
  EXPECT_TRUE(decoder->IsSizeAvailable());
  EXPECT_FALSE(decoder->Failed());

  // Just over the limit, should fail.
  EXPECT_TRUE(decoder->SetSize(kWidth + 1, kHeight));
  EXPECT_FALSE(decoder->IsSizeAvailable());
  EXPECT_TRUE(decoder->Failed());
}

TEST(ImageDecoderTest, decodedSizeUnlimited) {
  // Very large values for width and height should be OK.
  constexpr unsigned kWidth = 10000;
  constexpr unsigned kHeight = 10000;

  std::unique_ptr<TestImageDecoder> decoder(std::make_unique<TestImageDecoder>(
      ImageDecoder::kDefaultBitDepth, ImageDecoder::kNoDecodedImageByteLimit));
  EXPECT_TRUE(decoder->SetSize(kWidth, kHeight));
  EXPECT_TRUE(decoder->IsSizeAvailable());
  EXPECT_FALSE(decoder->Failed());
}

#else

// The limit is currently ignored on non-Fuchsia platforms (except for
// JPEG, which would decode a down-sampled version).
TEST(ImageDecoderTest, decodedSizeLimitIsIgnored) {}

#endif  // BUILDFLAG(IS_FUCHSIA)

#if BUILDFLAG(ENABLE_AV1_DECODER)
TEST(ImageDecoderTest, hasSufficientDataToSniffMimeTypeAvif) {}
#endif  // BUILDFLAG(ENABLE_AV1_DECODER)

}  // namespace blink