Add chrome_pdf::MatchesPngFile() utility
Adds a MatchesPngFile() utility wrapper around cc::MatchesPNGFile() that tests if an SkImage matches a PNG file within //pdf/test/data. Bug: 1317832 Change-Id: I0ae8322e2530736378c3fb54e855b5d467fb196d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3597663 Reviewed-by: Sunny Sachanandani <sunnyps@chromium.org> Reviewed-by: Nigi <nigi@chromium.org> Commit-Queue: K. Moon <kmoon@chromium.org> Cr-Commit-Position: refs/heads/main@{#994456}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
9164d056da
commit
d7fda8135e
@ -331,6 +331,7 @@ if (enable_pdf) {
|
||||
":internal",
|
||||
":ppapi_migration",
|
||||
"//base",
|
||||
"//cc:test_support",
|
||||
"//testing/gmock",
|
||||
"//testing/gtest",
|
||||
"//third_party/blink/public/common:headers",
|
||||
|
@ -12,8 +12,6 @@
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/test/scoped_feature_list.h"
|
||||
#include "cc/test/pixel_comparator.h"
|
||||
#include "cc/test/pixel_test_utils.h"
|
||||
#include "pdf/accessibility_structs.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "pdf/pdfium/pdfium_test_base.h"
|
||||
@ -23,7 +21,10 @@
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "third_party/pdfium/public/fpdf_formfill.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "third_party/skia/include/core/SkImage.h"
|
||||
#include "third_party/skia/include/core/SkImageInfo.h"
|
||||
#include "third_party/skia/include/core/SkPixmap.h"
|
||||
#include "third_party/skia/include/core/SkRefCnt.h"
|
||||
#include "ui/accessibility/accessibility_features.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
#include "ui/gfx/geometry/rect_f.h"
|
||||
@ -776,17 +777,14 @@ class PDFiumPageThumbnailTest : public PDFiumTestBase {
|
||||
ASSERT_GT(stride, 0);
|
||||
ASSERT_EQ(image_info.minRowBytes(), static_cast<size_t>(stride));
|
||||
std::vector<uint8_t> data = thumbnail.TakeData();
|
||||
SkBitmap bitmap;
|
||||
EXPECT_TRUE(bitmap.installPixels(image_info, data.data(),
|
||||
image_info.minRowBytes()));
|
||||
sk_sp<SkImage> image = SkImage::MakeRasterCopy(
|
||||
SkPixmap(image_info, data.data(), image_info.minRowBytes()));
|
||||
ASSERT_TRUE(image);
|
||||
|
||||
base::FilePath expectation_png_file_path = GetThumbnailTestData(
|
||||
expectation_file_prefix, page_index, device_pixel_ratio);
|
||||
|
||||
EXPECT_TRUE(cc::MatchesPNGFile(
|
||||
bitmap, GetTestDataFilePath(expectation_png_file_path),
|
||||
cc::ExactPixelComparator(/*discard_alpha=*/false)))
|
||||
<< "Reference: " << expectation_png_file_path;
|
||||
EXPECT_TRUE(MatchesPngFile(image.get(), expectation_png_file_path));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "cc/test/pixel_test_utils.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "pdf/pdfium/pdfium_engine_exports.h"
|
||||
#include "pdf/pdfium/pdfium_test_base.h"
|
||||
@ -20,7 +19,9 @@
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "third_party/blink/public/web/web_print_params.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "third_party/skia/include/core/SkImage.h"
|
||||
#include "third_party/skia/include/core/SkImageInfo.h"
|
||||
#include "third_party/skia/include/core/SkRefCnt.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
#include "ui/gfx/geometry/size_f.h"
|
||||
#include "ui/gfx/geometry/skia_conversions.h"
|
||||
@ -39,8 +40,8 @@ constexpr gfx::Rect kPrintableAreaRect = {{18, 18}, {576, 733}};
|
||||
using ExpectedDimensions = std::vector<gfx::SizeF>;
|
||||
|
||||
base::FilePath GetReferenceFilePath(base::StringPiece test_filename) {
|
||||
return GetTestDataFilePath(base::FilePath(FILE_PATH_LITERAL("pdfium_print"))
|
||||
.AppendASCII(test_filename));
|
||||
return base::FilePath(FILE_PATH_LITERAL("pdfium_print"))
|
||||
.AppendASCII(test_filename);
|
||||
}
|
||||
|
||||
blink::WebPrintParams GetDefaultPrintParams() {
|
||||
@ -97,10 +98,8 @@ void CheckPdfRendering(const std::vector<uint8_t>& pdf_data,
|
||||
ASSERT_TRUE(exports.RenderPDFPageToBitmap(pdf_data, page_number, settings,
|
||||
page_bitmap.getPixels()));
|
||||
|
||||
EXPECT_TRUE(cc::MatchesPNGFile(
|
||||
page_bitmap, GetReferenceFilePath(expected_png_filename),
|
||||
cc::ExactPixelComparator(/*discard_alpha=*/false)))
|
||||
<< "Reference: " << expected_png_filename;
|
||||
EXPECT_TRUE(MatchesPngFile(page_bitmap.asImage().get(),
|
||||
GetReferenceFilePath(expected_png_filename)));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
3
pdf/test/DEPS
Normal file
3
pdf/test/DEPS
Normal file
@ -0,0 +1,3 @@
|
||||
include_rules = [
|
||||
"+cc/test",
|
||||
]
|
@ -7,9 +7,13 @@
|
||||
#include "base/base_paths.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/path_service.h"
|
||||
#include "cc/test/pixel_comparator.h"
|
||||
#include "cc/test/pixel_test_utils.h"
|
||||
#include "pdf/ppapi_migration/bitmap.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "third_party/skia/include/core/SkImage.h"
|
||||
#include "ui/gfx/geometry/skia_conversions.h"
|
||||
|
||||
namespace chrome_pdf {
|
||||
@ -25,6 +29,21 @@ base::FilePath GetTestDataFilePath(const base::FilePath& path) {
|
||||
.Append(path);
|
||||
}
|
||||
|
||||
testing::AssertionResult MatchesPngFile(
|
||||
const SkImage* actual_image,
|
||||
const base::FilePath& expected_png_file) {
|
||||
SkBitmap actual_bitmap;
|
||||
if (!actual_image->asLegacyBitmap(&actual_bitmap))
|
||||
return testing::AssertionFailure() << "Reference: " << expected_png_file;
|
||||
|
||||
if (!cc::MatchesPNGFile(actual_bitmap, GetTestDataFilePath(expected_png_file),
|
||||
cc::ExactPixelComparator(/*discard_alpha=*/false))) {
|
||||
return testing::AssertionFailure() << "Reference: " << expected_png_file;
|
||||
}
|
||||
|
||||
return testing::AssertionSuccess();
|
||||
}
|
||||
|
||||
SkBitmap CreateSkiaImageForTesting(const gfx::Size& size, SkColor color) {
|
||||
SkBitmap bitmap = CreateN32PremulSkBitmap(gfx::SizeToSkISize(size));
|
||||
bitmap.eraseColor(color);
|
||||
|
@ -6,9 +6,11 @@
|
||||
#define PDF_TEST_TEST_HELPERS_H_
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
|
||||
class SkBitmap;
|
||||
class SkImage;
|
||||
|
||||
namespace gfx {
|
||||
class Size;
|
||||
@ -20,6 +22,12 @@ namespace chrome_pdf {
|
||||
// the empty path if the source root can't be found.
|
||||
base::FilePath GetTestDataFilePath(const base::FilePath& path);
|
||||
|
||||
// Matches `actual_image` against the PNG at the file path `expected_png_file`.
|
||||
// The path must be relative to //pdf/test/data.
|
||||
testing::AssertionResult MatchesPngFile(
|
||||
const SkImage* actual_image,
|
||||
const base::FilePath& expected_png_file);
|
||||
|
||||
// Creates a Skia-format `Image` of a given size filled with a given color.
|
||||
SkBitmap CreateSkiaImageForTesting(const gfx::Size& size, SkColor color);
|
||||
|
||||
|
Reference in New Issue
Block a user