Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ TEST_F(CPDFSecurityHandlerEmbedderTest, SetRuntimeOwnerPermissions) {

TEST_F(CPDFSecurityHandlerEmbedderTest, PasswordAfterGenerateSave) {
{
// Plain in layer mode too: the test asks for linearized loading.
ASSERT_TRUE(OpenDocumentWithOptions("encrypted.pdf", "5678",
LinearizeOption::kMustLinearize,
JavaScriptOption::kEnableJavaScript));
Expand Down
14 changes: 10 additions & 4 deletions fpdfsdk/fpdf_save_embeddertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,25 @@ TEST_F(FPDFSaveEmbedderTest, SaveLinearizedDoc) {
original_md5[i] = HashBitmap(bitmap.get());
}

// EmbedPDF(layer-mode): the whole file, as layer mode loads it. Loading the
// pages never fetched the metadata stream (26), and a save before this
// leaves it out while the catalog still refers to it.
SetWholeFileAvailable();
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
EXPECT_THAT(GetString(), StartsWith("%PDF-1.6\r\n"));
EXPECT_THAT(GetString(), HasSubstr("/Root "));
EXPECT_THAT(GetString(), HasSubstr("/Info "));
EXPECT_THAT(GetString(), HasSubstr("/Size 37"));
EXPECT_THAT(GetString(), HasSubstr("/Metadata 26 0 R"));
EXPECT_THAT(GetString(), HasSubstr("\r\n26 0 obj\r\n"));
EXPECT_THAT(GetString(), HasSubstr("35 0 obj"));
EXPECT_THAT(GetString(), HasSubstr("36 0 obj"));
EXPECT_THAT(GetString(), Not(HasSubstr("37 0 obj")));
EXPECT_THAT(GetString(), Not(HasSubstr("38 0 obj")));
// EmbedPDF(complete-xref): one subsection; 26 and 28 (the linearization
// dictionary), which the save doesn't reach, are free entries in it.
EXPECT_THAT(GetString(), HasSubstr("xref\r\n0 37\r\n0000000026 65535 f\r\n"));
EXPECT_EQ(7912u, GetString().size());
// EmbedPDF(complete-xref): one subsection; 28 (the linearization
// dictionary), which the save doesn't reach, is its free entry.
EXPECT_THAT(GetString(), HasSubstr("xref\r\n0 37\r\n0000000028 65535 f\r\n"));
EXPECT_EQ(10982u, GetString().size());

// Make sure new document renders the same as the old one.
ScopedSavedDoc saved_document = OpenScopedSavedDocument();
Expand Down
8 changes: 7 additions & 1 deletion testing/embedder_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,13 @@ bool EmbedderTest::OpenDocumentHelper(const ByteString& password,
network_simulator->GetFileAccess()));
FPDF_AVAIL avail_ptr = avail->get();
FPDF_DOCUMENT document_ptr = nullptr;
if (FPDFAvail_IsLinearized(avail_ptr) == PDF_LINEARIZED) {
// EmbedPDF(layer-mode): in layer mode a linearized file opens through the
// layer like any other file, unless the test asks for linearized loading.
const bool load_linearized =
FPDFAvail_IsLinearized(avail_ptr) == PDF_LINEARIZED &&
(linearize_option == LinearizeOption::kMustLinearize ||
!embedpdf_test::IsLayerModeEnabled());
if (load_linearized) {
int32_t nRet = PDF_DATA_NOTAVAIL;
while (nRet == PDF_DATA_NOTAVAIL) {
network_simulator->SetRequestedDataAvailable();
Expand Down
4 changes: 3 additions & 1 deletion testing/embedpdf_layer_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ namespace embedpdf_test {
// Layer mode runs the embedder tests through EmbedPDF's layer documents
// (docs/embedpdf/fork-ledger.md, rule layer-mode). With
// EPDF_EMBEDDER_LAYER_MODE=1 set, every document a test opens from a file is a
// fresh layer over a frozen base. The base is never written, so a write that
// fresh layer over a frozen base, a linearized file included. Only a test that
// asks for linearized loading (LinearizeOption::kMustLinearize) still gets
// FPDFAvail's plain document. The base is never written, so a write that
// bypasses the layer's copy-up door trips DCHECK_PDF_WRITABLE. Like the
// engine, layer mode never drives the form-fill environment: the harness
// still creates one, but sends it no page events and doesn't draw with it.
Expand Down
5 changes: 5 additions & 0 deletions testing/embedpdf_layer_mode_writers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ EPDFAnnotEmbedderTest.RedactRemovesInvisibleOcrLayerText 4
EPDFAnnotEmbedderTest.RedactRemovesTextWithEmptyGlyphBoxes 3
EPDFAnnotEmbedderTest.RedactVerticalTextLeadingGlyphKeepsRestInPlace 3
EPDFAnnotEmbedderTest.RedactVerticalTextMiddleGlyphsKeepsTailInPlace 3
EPDFAnnotEmbedderTest.RefitWrapsAStampAcrobatTurnedUpright 5
EPDFAnnotEmbedderTest.RegisteredCffFontEmitsCidFontType0 12
EPDFAnnotEmbedderTest.RegisteredCidKeyedCffKeepsCidsInAppearance 12
EPDFAnnotEmbedderTest.RegisteredFallbackFontRendersPageMissingGlyph 5
Expand Down Expand Up @@ -287,7 +288,9 @@ EPDFOutlineEmbedderTest.SetOpenFlipsTheSignAndCountsAgain 3
EPDFOutlineEmbedderTest.SharedListsAreCountedOnce 3001
EPDFOutlineEmbedderTest.TitleColorAndStyle 3
EPDFOutlineEmbedderTest.WrongLinksAndCountsAreWrittenRight 6
EPDFPageLabelsEmbedderTest.NoSectionsRemovesTheLabels 1
EPDFPageLabelsEmbedderTest.ReadsATreeAsPageLabelsDo 11
EPDFPageLabelsEmbedderTest.RefusesSectionsThatBreakTheRules 1
EPDFPageLabelsEmbedderTest.WritesSectionsThatLabelThePages 8
EPDFPieceInfoEmbedderTest.CatalogGranularClearPreservesOtherData 4
EPDFPieceInfoEmbedderTest.CatalogTypedValuesSaveReloadAndLayerRead 4
Expand Down Expand Up @@ -500,6 +503,8 @@ FPDFTransformEmbedderTest.TransFormWithClip 9
FPDFTransformEmbedderTest.TransFormWithClipAndSave 5
FPDFTransformEmbedderTest.TransFormWithClipAndSaveWithLocale 5
PDFEditImgTest.GetAndSetMatrixForFormWithImage 3
RichTextParityTest.BorderWidthsFixtureMatchesAcrobat 26
RichTextParityTest.CalloutWidthsFixtureMatchesAcrobat 12
RichTextParityTest.DecorationsFixtureMatchesAcrobat 2
RichTextParityTest.LinesFixtureMatchesAcrobat 2
RichTextParityTest.PropertiesFixtureMatchesAcrobat 2
Expand Down