0

[PDF] Add test for text selection that involves a page with no text

Add a new test PDF where there is an empty page in the middle. Use it in
a new PDFiumEngineTest.SelectTextAcrossEmptyPage test case to exercise
more PDFiumEngine code.

Change-Id: I2b91595005cdac9d2272d481cdcdd7b6cc637f7a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6221114
Reviewed-by: Ramin Halavati <rhalavati@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1415045}
This commit is contained in:
Lei Zhang
2025-02-03 10:35:01 -08:00
committed by Chromium LUCI CQ
parent d932d25da6
commit e967cc2938
3 changed files with 205 additions and 0 deletions

@ -1059,6 +1059,56 @@ TEST_P(PDFiumEngineTest, SelectLinkAreaWithNoText) {
EXPECT_EQ(kExpectedText, engine->GetSelectedText());
}
TEST_P(PDFiumEngineTest, SelectTextAcrossEmptyPage) {
NiceMock<MockTestClient> client;
std::unique_ptr<PDFiumEngine> engine = InitializeEngine(
&client, FILE_PATH_LITERAL("multi_page_hello_world_with_empty_page.pdf"));
ASSERT_TRUE(engine);
// Plugin size chosen so all pages of the document are visible.
engine->PluginSizeUpdated({1024, 4096});
EXPECT_THAT(engine->GetSelectedText(), IsEmpty());
static constexpr gfx::PointF kStartPosition(80, 200);
static constexpr gfx::PointF kEndPosition(95, 765);
// Forward selection.
EXPECT_TRUE(engine->HandleInputEvent(
CreateLeftClickWebMouseEventAtPosition(kStartPosition)));
EXPECT_TRUE(engine->HandleInputEvent(
CreateMoveWebMouseEventToPosition(kEndPosition)));
#if BUILDFLAG(IS_WIN)
static constexpr char kExpectedForwardSelection[] = "world!\r\nGoodbye";
#else
static constexpr char kExpectedForwardSelection[] = "world!\nGoodbye";
#endif
EXPECT_EQ(kExpectedForwardSelection, engine->GetSelectedText());
// Backward selection.
EXPECT_TRUE(engine->HandleInputEvent(
CreateLeftClickWebMouseEventAtPosition(kEndPosition)));
EXPECT_TRUE(engine->HandleInputEvent(
CreateMoveWebMouseEventToPosition(kStartPosition)));
#if BUILDFLAG(IS_WIN)
static constexpr char kExpectedBackwardSelection[] = "world!\r\nGoodbye,";
#else
static constexpr char kExpectedBackwardSelection[] = "world!\nGoodbye,";
#endif
EXPECT_EQ(kExpectedBackwardSelection, engine->GetSelectedText());
// Select all.
engine->SelectAll();
#if BUILDFLAG(IS_WIN)
static constexpr char kExpectedAllSelection[] =
"Hello, world!\r\nGoodbye, world!";
#else
static constexpr char kExpectedAllSelection[] =
"Hello, world!\nGoodbye, world!";
#endif
EXPECT_EQ(kExpectedAllSelection, engine->GetSelectedText());
}
TEST_P(PDFiumEngineTest, DrawTextSelectionsHelloWorld) {
constexpr int kPageIndex = 0;
NiceMock<MockTestClient> client;

@ -0,0 +1,70 @@
{{header}}
{{object 1 0}} <<
/Type /Catalog
/Pages 2 0 R
>>
endobj
{{object 2 0}} <<
/Type /Pages
/Count 3
/Kids [4 0 R 6 0 R 7 0 R]
/MediaBox [0 0 200 200]
/Resources <<
/Font <<
/F1 3 0 R
>>
>>
>>
endobj
{{object 3 0}} <<
/Type /Font
/Subtype /Type1
/BaseFont /Times-Roman
>>
endobj
{{object 4 0}} <<
/Type /Page
/Parent 2 0 R
/Contents 5 0 R
>>
endobj
{{object 5 0}} <<
{{streamlen}}
>>
stream
BT
20 50 Td
/F1 12 Tf
(Hello, world!) Tj
0 50 Td
ET
endstream
endobj
{{object 6 0}} <<
/Type /Page
/Parent 2 0 R
% This page deliberately has no contents.
>>
endobj
{{object 7 0}} <<
/Type /Page
/Parent 2 0 R
/Contents 8 0 R
>>
endobj
{{object 8 0}} <<
{{streamlen}}
>>
stream
BT
20 50 Td
/F1 12 Tf
(Goodbye, world!) Tj
0 50 Td
ET
endstream
endobj
{{xref}}
{{trailer}}
{{startxref}}
%%EOF

@ -0,0 +1,85 @@
%PDF-1.7
%<25><><EFBFBD><EFBFBD>
1 0 obj <<
/Type /Catalog
/Pages 2 0 R
>>
endobj
2 0 obj <<
/Type /Pages
/Count 3
/Kids [4 0 R 6 0 R 7 0 R]
/MediaBox [0 0 200 200]
/Resources <<
/Font <<
/F1 3 0 R
>>
>>
>>
endobj
3 0 obj <<
/Type /Font
/Subtype /Type1
/BaseFont /Times-Roman
>>
endobj
4 0 obj <<
/Type /Page
/Parent 2 0 R
/Contents 5 0 R
>>
endobj
5 0 obj <<
/Length 52
>>
stream
BT
20 50 Td
/F1 12 Tf
(Hello, world!) Tj
0 50 Td
ET
endstream
endobj
6 0 obj <<
/Type /Page
/Parent 2 0 R
% This page deliberately has no contents.
>>
endobj
7 0 obj <<
/Type /Page
/Parent 2 0 R
/Contents 8 0 R
>>
endobj
8 0 obj <<
/Length 54
>>
stream
BT
20 50 Td
/F1 12 Tf
(Goodbye, world!) Tj
0 50 Td
ET
endstream
endobj
xref
0 9
0000000000 65535 f
0000000015 00000 n
0000000068 00000 n
0000000226 00000 n
0000000304 00000 n
0000000373 00000 n
0000000476 00000 n
0000000571 00000 n
0000000640 00000 n
trailer <<
/Root 1 0 R
/Size 9
>>
startxref
745
%%EOF