chromium/skia/public/mojom/test/mojom_traits_unittest.cc

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <limits>
#include "mojo/public/cpp/test_support/test_utils.h"
#include "skia/ext/skcolorspace_primaries.h"
#include "skia/public/mojom/bitmap.mojom.h"
#include "skia/public/mojom/bitmap_skbitmap_mojom_traits.h"
#include "skia/public/mojom/image_info.mojom-shared.h"
#include "skia/public/mojom/image_info.mojom.h"
#include "skia/public/mojom/skcolorspace.mojom.h"
#include "skia/public/mojom/skcolorspace_mojom_traits.h"
#include "skia/public/mojom/skcolorspace_primaries.mojom.h"
#include "skia/public/mojom/skcolorspace_primaries_mojom_traits.h"
#include "skia/public/mojom/tile_mode.mojom.h"
#include "skia/public/mojom/tile_mode_mojom_traits.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkColorFilter.h"
#include "third_party/skia/include/core/SkColorSpace.h"
#include "third_party/skia/include/core/SkImageInfo.h"
#include "third_party/skia/include/core/SkString.h"
#include "third_party/skia/include/core/SkTileMode.h"
#include "third_party/skia/modules/skcms/skcms.h"
#include "ui/gfx/skia_util.h"

namespace skia {
namespace {

// A helper to construct a skia.mojom.BitmapN32 without using StructTraits
// to bypass checks on the sending/serialization side.
mojo::StructPtr<skia::mojom::BitmapN32> ConstructBitmapN32(
    SkImageInfo info,
    std::vector<unsigned char> pixels) {}

// A helper to construct a skia.mojom.BitmapWithArbitraryBpp without using
// StructTraits to bypass checks on the sending/serialization side.
mojo::StructPtr<skia::mojom::BitmapWithArbitraryBpp>
ConstructBitmapWithArbitraryBpp(SkImageInfo info,
                                int row_bytes,
                                std::vector<unsigned char> pixels) {}

// A helper to construct a skia.mojom.BitmapMappedFromTrustedProcess without
// using StructTraits to bypass checks on the sending/serialization side.
mojo::StructPtr<skia::mojom::BitmapMappedFromTrustedProcess>
ConstructBitmapMappedFromTrustedProcess(SkImageInfo info,
                                        int row_bytes,
                                        std::vector<unsigned char> pixels) {}

// A helper to construct a skia.mojom.InlineBitmap without using StructTraits
// to bypass checks on the sending/serialization side.
mojo::StructPtr<skia::mojom::InlineBitmap> ConstructInlineBitmap(
    SkImageInfo info,
    std::vector<unsigned char> pixels) {}

// A helper to construct a skia.mojom.ImageInfo without using StructTraits
// to bypass checks on the sending/serialization side.
mojo::StructPtr<skia::mojom::ImageInfo> ConstructImageInfo(
    SkColorType color_type,
    SkAlphaType alpha_type,
    uint32_t width,
    uint32_t height) {}

TEST(StructTraitsTest, ImageInfo) {}

// We catch negative integers on the sending side and crash, when struct traits
// are used.
TEST(StructTraitsDeathTest, ImageInfoOverflowSizeWithStructTrait) {}

// We must reject sizes that would cause integer overflow on the receiving side.
// The wire format is `uint32_t`, but Skia needs us to convert that to an `int`
// for the SkImageInfo type.
TEST(StructTraitsTest, ImageInfoOverflowSizeWithoutStructTrait) {}

TEST(StructTraitsTest, ImageInfoCustomColorSpace) {}

TEST(StructTraitsTest, SkColorSpace) {}

TEST(StructTraitsTest, TileMode) {}

TEST(StructTraitsTest, Bitmap) {}

// Null input produces a default-initialized SkBitmap.
TEST(StructTraitsTest, BitmapNull) {}

// Serialize to string works, we only need this verify this for InlineBitmap,
// as the other Bitmap types should not be used for this purpose.
TEST(StructTraitsTest, InlineBitmapSerializeToString) {}

// Verify that we can manually construct a valid skia.mojom object and
// deserialize it successfully.
TEST(StructTraitsTest, VerifyMojomConstruction) {}

// We only allow 64 * 1024 as the max width.
TEST(StructTraitsTest, BitmapTooWideToSerialize) {}

// We only allow 64 * 1024 as the max height.
TEST(StructTraitsTest, BitmapTooTallToSerialize) {}

template <typename MojomType>
static void BadRowBytes() {}

// We do not allow sending rowBytes() other than the minRowBytes().
TEST(StructTraitsTest, BitmapSerializeInvalidRowBytes_BitmapN32) {}
TEST(StructTraitsTest, BitmapSerializeInvalidRowBytes_BitmapWithArbitraryBpp) {}
TEST(StructTraitsTest,
     BitmapSerializeInvalidRowBytes_BitmapMappedFromTrustedProcess) {}
TEST(StructTraitsTest, BitmapSerializeInvalidRowBytes_InlineBitmap) {}

template <typename MojomType>
static void BadColor(bool expect_crash) {}

TEST(StructTraitsTest, BitmapSerializeInvalidColorType_BitmapN32) {}
TEST(StructTraitsTest, BitmapSerializeInvalidColorType_BitmapWithArbitraryBpp) {}
TEST(StructTraitsTest,
     BitmapSerializeInvalidColorType_BitmapMappedFromTrustedProcess) {}
TEST(StructTraitsTest, BitmapSerializeInvalidColorType_InlineBitmap) {}

// The row_bytes field is ignored, and the minRowBytes() is always used.
TEST(StructTraitsTest, BitmapDeserializeIgnoresRowBytes) {}

// The SkImageInfo claims 8 bytes, but the pixel vector has 4.
TEST(StructTraitsTest, InlineBitmapDeserializeTooFewBytes) {}

// The SkImageInfo claims 4 bytes, but the pixel vector has 8.
TEST(StructTraitsTest, InlineBitmapDeserializeTooManyBytes) {}

}  // namespace
}  // namespace skia