diff --git a/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp b/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp index 113aec93c..7bb119187 100644 --- a/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp +++ b/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp @@ -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)); diff --git a/fpdfsdk/fpdf_save_embeddertest.cpp b/fpdfsdk/fpdf_save_embeddertest.cpp index cfa5fb6bf..1a09c2e80 100644 --- a/fpdfsdk/fpdf_save_embeddertest.cpp +++ b/fpdfsdk/fpdf_save_embeddertest.cpp @@ -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(); diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp index 75371fe9a..926a4e298 100644 --- a/testing/embedder_test.cpp +++ b/testing/embedder_test.cpp @@ -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(); diff --git a/testing/embedpdf_layer_mode.h b/testing/embedpdf_layer_mode.h index 498ea8c58..f3bc91e01 100644 --- a/testing/embedpdf_layer_mode.h +++ b/testing/embedpdf_layer_mode.h @@ -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. diff --git a/testing/embedpdf_layer_mode_writers.txt b/testing/embedpdf_layer_mode_writers.txt index 0fe63f0ca..589f04a2c 100644 --- a/testing/embedpdf_layer_mode_writers.txt +++ b/testing/embedpdf_layer_mode_writers.txt @@ -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 @@ -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 @@ -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