chromium/components/paint_preview/common/serial_utils_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.

#include "components/paint_preview/common/serial_utils.h"

#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "build/build_config.h"
#include "components/paint_preview/common/file_stream.h"
#include "skia/ext/font_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/codec/SkBmpDecoder.h"
#include "third_party/skia/include/codec/SkGifDecoder.h"
#include "third_party/skia/include/codec/SkJpegDecoder.h"
#include "third_party/skia/include/codec/SkPngDecoder.h"
#include "third_party/skia/include/codec/SkWebpDecoder.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkData.h"
#include "third_party/skia/include/core/SkFontStyle.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
#include "third_party/skia/include/core/SkRect.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/core/SkSerialProcs.h"
#include "third_party/skia/include/core/SkStream.h"
#include "third_party/skia/include/core/SkTypeface.h"

namespace paint_preview {

TEST(PaintPreviewSerialUtils, TestMakeEmptyPicture) {}

TEST(PaintPreviewSerialUtils, TestTransformedPictureProcs) {}

TEST(PaintPreviewSerialUtils, TestSerialPictureNotInMap) {}

// Skip this on Android as we only have system fonts in this test and Android
// doesn't serialize those.
#if !BUILDFLAG(IS_ANDROID)
TEST(PaintPreviewSerialUtils, TestSerialTypeface) {}
#endif

#if BUILDFLAG(IS_ANDROID)
TEST(PaintPreviewSerialUtils, TestSerialAndroidSystemTypeface) {
  PictureSerializationContext picture_ctx;

  // This is a system font serialization of the data will be skipped.
  auto typeface = skia::MakeTypefaceFromName("sans-serif", SkFontStyle::Bold());
  TypefaceUsageMap usage_map;
  std::unique_ptr<GlyphUsage> usage =
      std::make_unique<SparseGlyphUsage>(typeface->countGlyphs());
  usage->Set(0);
  usage->Set('a');
  usage->Set('b');
  EXPECT_TRUE(
      usage_map.insert(std::make_pair(typeface->uniqueID(), std::move(usage)))
          .second);
  TypefaceSerializationContext typeface_ctx(&usage_map);
  ImageSerializationContext ictx;

  SkSerialProcs serial_procs =
      MakeSerialProcs(&picture_ctx, &typeface_ctx, &ictx);
  EXPECT_EQ(serial_procs.fPictureCtx, &picture_ctx);
  EXPECT_EQ(serial_procs.fTypefaceCtx, &typeface_ctx);
  EXPECT_EQ(serial_procs.fImageCtx, &ictx);

  auto final_data =
      serial_procs.fTypefaceProc(typeface.get(), serial_procs.fTypefaceCtx);
  ASSERT_TRUE(final_data);
  EXPECT_GT(typeface_ctx.finished.count(typeface->uniqueID()), 0U);
  auto original_data = typeface->serialize();
  ASSERT_EQ(original_data->size(), final_data->size());
  ASSERT_EQ(
      0, memcmp(original_data->data(), final_data->data(), final_data->size()));
}
#endif

TEST(PaintPreviewSerialUtils, TestSerialNoTypefaceInMap) {}

TEST(PaintPreviewSerialUtils, TestImageContextLimitBudget) {}

TEST(PaintPreviewSerialUtils, TestImageContextLimitSize) {}

namespace {

struct DeserialImageContext {};

static void TrySerialAndDeserial(sk_sp<SkData> image_data) {}

}  // namespace

TEST(PaintPreviewSerialUtils, TestImageContextEncodeAndDecodePng) {}

TEST(PaintPreviewSerialUtils, TestImageContextEncodeAndDecodeJpeg) {}

TEST(PaintPreviewSerialUtils, TestImageContextEncodeAndDecodeWebp) {}

TEST(PaintPreviewSerialUtils, TestImageContextEncodeAndDecodeGif) {}

TEST(PaintPreviewSerialUtils, TestImageContextEncodeAndDecodeBmp) {}

}  // namespace paint_preview