diff --git a/test/integration/document_properties_spec.mjs b/test/integration/document_properties_spec.mjs index dcb9bc6c1..6afb20f1a 100644 --- a/test/integration/document_properties_spec.mjs +++ b/test/integration/document_properties_spec.mjs @@ -68,6 +68,14 @@ async function checkFieldProperties(page, expectedProps) { expect(props).toEqual(expectedProps); } +function getFieldDataLastUpdated(page) { + return page.evaluate( + () => + document.getElementById("documentPropertiesDialog").dataset + .fieldDataLastUpdated + ); +} + describe("PDFDocumentProperties", () => { describe("Document with both /Info and /Metadata", () => { let pages; @@ -199,4 +207,151 @@ describe("PDFDocumentProperties", () => { ); }); }); + + describe("Document with multiple pages, and changed viewer page/rotation", () => { + let pages; + + beforeEach(async () => { + pages = await loadAndWait("basicapi.pdf", ".textLayer .endOfContent"); + }); + + afterEach(async () => { + await closePages(pages); + }); + + it("must check that the document properties dialog has the correct information", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await openDocumentProperties(page); + + await checkFieldProperties(page, { + fileName: "basicapi.pdf", + fileSize: `${FSI}103${PDI} KB (${FSI}105,779${PDI} bytes)`, + title: "Basic API Test", + author: "Brendan Dahl", + subject: "-", + keywords: "TCPDF", + creationDate: "4/10/12, 7:30:26 AM", + modificationDate: "4/10/12, 7:30:26 AM", + creator: "TCPDF", + producer: "TCPDF 5.9.133 (http://www.tcpdf.org)", + version: "1.7", + pageCount: "3", + pageSize: `${FSI}8.27${PDI} × ${FSI}11.69${PDI} ${FSI}in${PDI} (${FSI}A4${PDI}, ${FSI}portrait${PDI})`, + linearized: "No", + }); + const fieldDataLastUpdated = await getFieldDataLastUpdated(page); + + await closeDocumentProperties(page); + + // Ensure that immediately re-opening the dialog doesn't cause + // the field-data to be fetched and parsed again. + await openDocumentProperties(page); + + expect(await getFieldDataLastUpdated(page)).toEqual( + fieldDataLastUpdated + ); + + await closeDocumentProperties(page); + + // Goto the second page, and rotate the document. + await page.click("#next"); + await page.waitForFunction( + () => window.PDFViewerApplication.page === 2 + ); + await page.keyboard.press("r"); + await page.waitForFunction( + () => window.PDFViewerApplication.pdfViewer.pagesRotation === 90 + ); + + await openDocumentProperties(page); + + await checkFieldProperties(page, { + fileName: "basicapi.pdf", + fileSize: `${FSI}103${PDI} KB (${FSI}105,779${PDI} bytes)`, + title: "Basic API Test", + author: "Brendan Dahl", + subject: "-", + keywords: "TCPDF", + creationDate: "4/10/12, 7:30:26 AM", + modificationDate: "4/10/12, 7:30:26 AM", + creator: "TCPDF", + producer: "TCPDF 5.9.133 (http://www.tcpdf.org)", + version: "1.7", + pageCount: "3", + pageSize: `${FSI}11.69${PDI} × ${FSI}8.27${PDI} ${FSI}in${PDI} (${FSI}A4${PDI}, ${FSI}landscape${PDI})`, + linearized: "No", + }); + + await closeDocumentProperties(page); + }) + ); + }); + }); + + describe("Document with different page sizes", () => { + let pages; + + beforeEach(async () => { + pages = await loadAndWait("sizes.pdf", ".textLayer .endOfContent"); + }); + + afterEach(async () => { + await closePages(pages); + }); + + it("must check that the document properties dialog has the correct information", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await openDocumentProperties(page); + + await checkFieldProperties(page, { + fileName: "sizes.pdf", + fileSize: `${FSI}13.4${PDI} KB (${FSI}13,739${PDI} bytes)`, + title: "-", + author: "Yury ", + subject: "-", + keywords: "-", + creationDate: "6/26/11, 1:26:03 PM", + modificationDate: "-", + creator: "Writer", + producer: "OpenOffice.org 3.3", + version: "1.4", + pageCount: "3", + pageSize: `${FSI}8.5${PDI} × ${FSI}11${PDI} ${FSI}in${PDI} (${FSI}Letter${PDI}, ${FSI}portrait${PDI})`, + linearized: "No", + }); + + await closeDocumentProperties(page); + + // Goto the second page. + await page.click("#next"); + await page.waitForFunction( + () => window.PDFViewerApplication.page === 2 + ); + + await openDocumentProperties(page); + + await checkFieldProperties(page, { + fileName: "sizes.pdf", + fileSize: `${FSI}13.4${PDI} KB (${FSI}13,739${PDI} bytes)`, + title: "-", + author: "Yury ", + subject: "-", + keywords: "-", + creationDate: "6/26/11, 1:26:03 PM", + modificationDate: "-", + creator: "Writer", + producer: "OpenOffice.org 3.3", + version: "1.4", + pageCount: "3", + pageSize: `${FSI}9.01${PDI} × ${FSI}4.49${PDI} ${FSI}in${PDI} (${FSI}landscape${PDI})`, + linearized: "No", + }); + + await closeDocumentProperties(page); + }) + ); + }); + }); }); diff --git a/web/pdf_document_properties.js b/web/pdf_document_properties.js index 98de92bf7..f7150b72c 100644 --- a/web/pdf_document_properties.js +++ b/web/pdf_document_properties.js @@ -111,6 +111,9 @@ class PDFDocumentProperties { this.#updateUI(); return; } + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) { + this._fieldDataLastUpdated = Date.now(); + } // Get the document properties. const [ @@ -220,6 +223,9 @@ class PDFDocumentProperties { // since it will be updated the next time `this.open` is called. return; } + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) { + this.dialog.dataset.fieldDataLastUpdated = this._fieldDataLastUpdated; + } for (const id in this.fields) { const content = this.#fieldData?.[id]; this.fields[id].textContent = content || content === 0 ? content : "-";