diff --git a/test/integration/reorganize_pages_spec.mjs b/test/integration/reorganize_pages_spec.mjs index e15a36bbf..850117125 100644 --- a/test/integration/reorganize_pages_spec.mjs +++ b/test/integration/reorganize_pages_spec.mjs @@ -3399,6 +3399,67 @@ describe("Reorganize Pages View", () => { ); }); + it("should merge a password-protected PDF after the current page", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await waitForThumbnailVisible(page, 1); + + // Navigate to page 2 so the merged PDF is inserted after it. + await page.evaluate(() => { + window.PDFViewerApplication.page = 2; + }); + await page.waitForFunction( + () => window.PDFViewerApplication.page === 2 + ); + await waitAndClick(page, getThumbnailSelector(2)); + + const handleMerged = await createPromise(page, resolve => { + window.PDFViewerApplication.eventBus.on( + "thumbnailsloaded", + resolve, + { once: true } + ); + }); + + const picker = await page.$("#viewsManagerAddFilePicker"); + await picker.uploadFile( + path.join(__dirname, "../pdfs/issue6010_1.pdf") + ); + + // Test with an incorrect password first, + // to ensure that re-prompting works correctly. + for (const password of ["Incorrect password", "abc"]) { + await page.waitForSelector("#passwordDialog", { visible: true }); + await page.type("#password", password); + await page.keyboard.press("Enter"); + } + + await awaitPromise(handleMerged); + + // Original 3 pages + 1 merged page = 4 pages total. + await page.waitForFunction( + () => parseInt(document.getElementById("pageNumber").max, 10) === 4 + ); + + // Focus must move to the first newly inserted page (page 3, since + // we merged after page 2). + await page.waitForFunction( + () => window.PDFViewerApplication.page === 3 + ); + + // Pages 1–2 come from the original document, then the page of + // the merged PDF, then page 3 of the original shifted to the end. + await waitForHavingContents(page, [1, 2, "Issue 6010", 3]); + + await waitForTextToBe( + page, + "#viewsManagerStatusActionLabel", + `${FSI}1${PDI} selected` + ); + }) + ); + }); + it("should merge a corrupt PDF (with invalid pages /Count) after the current page", async () => { await Promise.all( pages.map(async ([browserName, page]) => {