|
| 1 | +/* Copyright 2024 Mozilla Foundation |
| 2 | + * |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +import { closePages, FSI, loadAndWait, PDI } from "./test_utils.mjs"; |
| 17 | + |
| 18 | +const FIELDS = [ |
| 19 | + "fileName", |
| 20 | + "fileSize", |
| 21 | + "title", |
| 22 | + "author", |
| 23 | + "subject", |
| 24 | + "keywords", |
| 25 | + "creationDate", |
| 26 | + "modificationDate", |
| 27 | + "creator", |
| 28 | + "producer", |
| 29 | + "version", |
| 30 | + "pageCount", |
| 31 | + "pageSize", |
| 32 | + "linearized", |
| 33 | +]; |
| 34 | + |
| 35 | +describe("PDFDocumentProperties", () => { |
| 36 | + async function getFieldProperties(page) { |
| 37 | + const promises = []; |
| 38 | + |
| 39 | + for (const name of FIELDS) { |
| 40 | + promises.push( |
| 41 | + page.evaluate( |
| 42 | + n => [n, document.getElementById(`${n}Field`).textContent], |
| 43 | + name |
| 44 | + ) |
| 45 | + ); |
| 46 | + } |
| 47 | + return Object.fromEntries(await Promise.all(promises)); |
| 48 | + } |
| 49 | + |
| 50 | + describe("Document with both /Info and /Metadata", () => { |
| 51 | + let pages; |
| 52 | + |
| 53 | + beforeEach(async () => { |
| 54 | + pages = await loadAndWait("basicapi.pdf", ".textLayer .endOfContent"); |
| 55 | + }); |
| 56 | + |
| 57 | + afterEach(async () => { |
| 58 | + await closePages(pages); |
| 59 | + }); |
| 60 | + |
| 61 | + it("must check that the document properties dialog has the correct information", async () => { |
| 62 | + await Promise.all( |
| 63 | + pages.map(async ([browserName, page]) => { |
| 64 | + await page.click("#secondaryToolbarToggleButton"); |
| 65 | + await page.waitForSelector("#secondaryToolbar", { hidden: false }); |
| 66 | + |
| 67 | + await page.click("#documentProperties"); |
| 68 | + await page.waitForSelector("#documentPropertiesDialog", { |
| 69 | + hidden: false, |
| 70 | + }); |
| 71 | + |
| 72 | + await page.waitForFunction( |
| 73 | + `document.getElementById("fileSizeField").textContent !== "-"` |
| 74 | + ); |
| 75 | + const props = await getFieldProperties(page); |
| 76 | + |
| 77 | + expect(props).toEqual({ |
| 78 | + fileName: "basicapi.pdf", |
| 79 | + fileSize: `${FSI}103${PDI} KB (${FSI}105,779${PDI} bytes)`, |
| 80 | + title: "Basic API Test", |
| 81 | + author: "Brendan Dahl", |
| 82 | + subject: "-", |
| 83 | + keywords: "TCPDF", |
| 84 | + creationDate: "4/10/12, 7:30:26 AM", |
| 85 | + modificationDate: "4/10/12, 7:30:26 AM", |
| 86 | + creator: "TCPDF", |
| 87 | + producer: "TCPDF 5.9.133 (http://www.tcpdf.org)", |
| 88 | + version: "1.7", |
| 89 | + pageCount: "3", |
| 90 | + pageSize: `${FSI}8.27${PDI} × ${FSI}11.69${PDI} ${FSI}in${PDI} (${FSI}A4${PDI}, ${FSI}portrait${PDI})`, |
| 91 | + linearized: "No", |
| 92 | + }); |
| 93 | + }) |
| 94 | + ); |
| 95 | + }); |
| 96 | + }); |
| 97 | +}); |
0 commit comments