chromium/media/parsers/webp_parser_unittest.cc

// Copyright 2019 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/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include <stddef.h>
#include <stdint.h>

#include <memory>

#include "base/base_paths.h"
#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "base/files/memory_mapped_file.h"
#include "base/path_service.h"
#include "media/parsers/vp8_parser.h"
#include "media/parsers/webp_parser.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace media {

namespace {

constexpr size_t kWebPFileAndVp8ChunkHeaderSizeInBytes =;
// clang-format off
constexpr uint8_t kLossyWebPFileHeader[] =;
constexpr base::span<const uint8_t> kLossyWebPEncodedData(
    kLossyWebPFileHeader,
    kWebPFileAndVp8ChunkHeaderSizeInBytes);
constexpr base::span<const uint8_t> kInvalidWebPEncodedDataSize(
    kLossyWebPFileHeader,
    kWebPFileAndVp8ChunkHeaderSizeInBytes - 5u);

constexpr uint8_t kLosslessWebPFileHeader[] =;
constexpr base::span<const uint8_t> kLosslessWebPEncodedData(
    kLosslessWebPFileHeader,
    kWebPFileAndVp8ChunkHeaderSizeInBytes);

constexpr uint8_t kExtendedWebPFileHeader[] =;
constexpr base::span<const uint8_t> kExtendedWebPEncodedData(
    kExtendedWebPFileHeader,
    kWebPFileAndVp8ChunkHeaderSizeInBytes);

constexpr uint8_t kUnknownWebPFileHeader[] =;
constexpr base::span<const uint8_t> kUnknownWebPEncodedData(
    kUnknownWebPFileHeader,
    kWebPFileAndVp8ChunkHeaderSizeInBytes);

constexpr uint8_t kInvalidRiffWebPFileHeader[] =;
constexpr base::span<const uint8_t> kInvalidRiffWebPEncodedData(
    kInvalidRiffWebPFileHeader,
    kWebPFileAndVp8ChunkHeaderSizeInBytes);

constexpr uint8_t kInvalidOddFileSizeInWebPFileHeader[] =;
constexpr base::span<const uint8_t> kInvalidOddFileSizeInHeaderWebPEncodedData(
    kInvalidOddFileSizeInWebPFileHeader,
    kWebPFileAndVp8ChunkHeaderSizeInBytes + 1u);  // Match the reported size

constexpr uint8_t kInvalidLargerThanLimitFileSizeInWebPFileHeader[] =;
constexpr base::span<const uint8_t>
kInvalidLargerThanLimitFileSizeInHeaderWebPEncodedData(
    kInvalidLargerThanLimitFileSizeInWebPFileHeader,
    kWebPFileAndVp8ChunkHeaderSizeInBytes);

constexpr uint8_t kInvalidLargerFileSizeInWebPFileHeader[] =;
constexpr base::span<const uint8_t>
kInvalidLargerFileSizeInHeaderWebPEncodedData(
    kInvalidLargerFileSizeInWebPFileHeader,
    kWebPFileAndVp8ChunkHeaderSizeInBytes);

constexpr uint8_t kInvalidKeyFrameSizeInWebPFileHeader[] =;
constexpr base::span<const uint8_t> kInvalidKeyFrameSizeInWebPEncodedData(
    kInvalidKeyFrameSizeInWebPFileHeader,
    kWebPFileAndVp8ChunkHeaderSizeInBytes);

constexpr uint8_t kMismatchingOddVp8FrameSizeAndDataSize[] =;
constexpr base::span<const uint8_t>
kMismatchingOddVp8FrameSizeAndDataSizeEncodedData(
    kMismatchingOddVp8FrameSizeAndDataSize,
    kWebPFileAndVp8ChunkHeaderSizeInBytes + 6u);

constexpr uint8_t kMismatchingEvenVp8FrameSizeAndDataSize[] =;
constexpr base::span<const uint8_t>
kMismatchingEvenVp8FrameSizeAndDataSizeEncodedData(
    kMismatchingEvenVp8FrameSizeAndDataSize,
    kWebPFileAndVp8ChunkHeaderSizeInBytes + 6u);

constexpr uint8_t kInvalidPaddingByteInVp8DataChunk[] =;
constexpr base::span<const uint8_t>
kInvalidPaddingByteInVp8DataChunkEncodedData(
    kInvalidPaddingByteInVp8DataChunk,
    kWebPFileAndVp8ChunkHeaderSizeInBytes + 4u);
// clang-format on

}  // namespace

TEST(WebPParserTest, WebPImageFileValidator) {}

TEST(WebPParserTest, ParseLossyWebP) {}

TEST(WebPParserTest, ParseLosslessWebP) {}

TEST(WebPParserTest, ParseExtendedWebP) {}

TEST(WebPParserTest, ParseWebPWithUnknownFormat) {}

TEST(WebPParserTest, ParseWebPWithInvalidHeaders) {}

TEST(WebPParserTest, ParseWebPWithInvalidOddSizeInHeader) {}

TEST(WebPParserTest, ParseWebPWithInvalidLargerThanLimitSizeInHeader) {}

TEST(WebPParserTest, ParseWebPWithInvalidFileSizeInHeader) {}

TEST(WebPParserTest, ParseWebPWithEmptyVp8KeyFrameAndIncorrectKeyFrameSize) {}

TEST(WebPParserTest, ParseWebPWithMismatchingVp8FrameAndDataSize) {}

TEST(WebPParserTest, ParseWebPWithInvalidPaddingByteInVp8DataChunk) {}

TEST(WebPParserTest, ParseWebPWithEmptyVp8KeyFrame) {}

}  // namespace media