
This is a reland for CL [1]. Link flag "pdf-use-skia-renderer" with PDFiumEngine so that it can actually switch the renderer type for the PDF viewer upon initialization. This CL also changes PDFiumTestBase and tests derived from it into parameterized tests so that they can be tested with Skia renderer enabled: - For the tests which involve image rendering results comparison, add the Skia expectations for them. - Test PDFiumPageImageDataTest.ImageData is currently skipped because it crashes when Skia renderer is in use. - Disable PDFiumPageThumbnailTest.GenerateThumbnail on macOS with ARM64. The test expectations need to be updated before it can be re-enabled. [1] https://chromium-review.googlesource.com/4000168 Bug: 1379872,1382257 Change-Id: I140e8769d7102bc9070cfa2f1c39b95e59c6e872 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4021705 Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Nico Weber <thakis@chromium.org> Commit-Queue: Nigi <nigi@chromium.org> Cr-Commit-Position: refs/heads/main@{#1070525}
117 lines
3.2 KiB
C++
117 lines
3.2 KiB
C++
// Copyright 2022 The Chromium Authors
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "pdf/pdfium/pdfium_range.h"
|
|
|
|
#include <memory>
|
|
|
|
#include "pdf/pdfium/pdfium_engine.h"
|
|
#include "pdf/pdfium/pdfium_page.h"
|
|
#include "pdf/pdfium/pdfium_test_base.h"
|
|
#include "pdf/test/test_client.h"
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace chrome_pdf {
|
|
|
|
class PDFiumRangeTest : public PDFiumTestBase {
|
|
public:
|
|
void SetUp() override {
|
|
PDFiumTestBase::SetUp();
|
|
engine_ = InitializeEngine(&client_, FILE_PATH_LITERAL("hello_world2.pdf"));
|
|
ASSERT_TRUE(engine_);
|
|
}
|
|
|
|
void TearDown() override {
|
|
// Must reset the PDFiumEngine before PDFiumTestBase uninitializes PDFium
|
|
// altogether.
|
|
engine_.reset();
|
|
PDFiumTestBase::TearDown();
|
|
}
|
|
|
|
PDFiumEngine* engine() { return engine_.get(); }
|
|
|
|
private:
|
|
TestClient client_;
|
|
std::unique_ptr<PDFiumEngine> engine_;
|
|
};
|
|
|
|
TEST_P(PDFiumRangeTest, Empty) {
|
|
PDFiumPage page(engine(), 0);
|
|
page.MarkAvailable();
|
|
{
|
|
PDFiumRange range(&page, /*char_index=*/0, /*char_count=*/0);
|
|
EXPECT_EQ(0, range.char_index());
|
|
EXPECT_EQ(0, range.char_count());
|
|
EXPECT_EQ(u"", range.GetText());
|
|
}
|
|
{
|
|
PDFiumRange range(&page, /*char_index=*/1, /*char_count=*/0);
|
|
EXPECT_EQ(1, range.char_index());
|
|
EXPECT_EQ(0, range.char_count());
|
|
EXPECT_EQ(u"", range.GetText());
|
|
}
|
|
}
|
|
|
|
TEST_P(PDFiumRangeTest, Forward) {
|
|
PDFiumPage page(engine(), 0);
|
|
page.MarkAvailable();
|
|
{
|
|
PDFiumRange range(&page, /*char_index=*/0, /*char_count=*/2);
|
|
EXPECT_EQ(0, range.char_index());
|
|
EXPECT_EQ(2, range.char_count());
|
|
EXPECT_EQ(u"He", range.GetText());
|
|
}
|
|
{
|
|
PDFiumRange range(&page, /*char_index=*/15, /*char_count=*/3);
|
|
EXPECT_EQ(15, range.char_index());
|
|
EXPECT_EQ(3, range.char_count());
|
|
EXPECT_EQ(u"Goo", range.GetText());
|
|
}
|
|
{
|
|
PDFiumRange range(&page, /*char_index=*/28, /*char_count=*/2);
|
|
EXPECT_EQ(28, range.char_index());
|
|
EXPECT_EQ(2, range.char_count());
|
|
EXPECT_EQ(u"d!", range.GetText());
|
|
}
|
|
{
|
|
PDFiumRange range(&page, /*char_index=*/29, /*char_count=*/1);
|
|
EXPECT_EQ(29, range.char_index());
|
|
EXPECT_EQ(1, range.char_count());
|
|
EXPECT_EQ(u"!", range.GetText());
|
|
}
|
|
}
|
|
|
|
TEST_P(PDFiumRangeTest, Backward) {
|
|
PDFiumPage page(engine(), 0);
|
|
page.MarkAvailable();
|
|
{
|
|
PDFiumRange range(&page, /*char_index=*/1, /*char_count=*/-2);
|
|
EXPECT_EQ(1, range.char_index());
|
|
EXPECT_EQ(-2, range.char_count());
|
|
EXPECT_EQ(u"He", range.GetText());
|
|
}
|
|
{
|
|
PDFiumRange range(&page, /*char_index=*/17, /*char_count=*/-3);
|
|
EXPECT_EQ(17, range.char_index());
|
|
EXPECT_EQ(-3, range.char_count());
|
|
EXPECT_EQ(u"Goo", range.GetText());
|
|
}
|
|
{
|
|
PDFiumRange range(&page, /*char_index=*/29, /*char_count=*/-2);
|
|
EXPECT_EQ(29, range.char_index());
|
|
EXPECT_EQ(-2, range.char_count());
|
|
EXPECT_EQ(u"d!", range.GetText());
|
|
}
|
|
{
|
|
PDFiumRange range(&page, /*char_index=*/29, /*char_count=*/-1);
|
|
EXPECT_EQ(29, range.char_index());
|
|
EXPECT_EQ(-1, range.char_count());
|
|
EXPECT_EQ(u"!", range.GetText());
|
|
}
|
|
}
|
|
|
|
INSTANTIATE_TEST_SUITE_P(All, PDFiumRangeTest, testing::Bool());
|
|
|
|
} // namespace chrome_pdf
|