diff --git a/src/core/document.js b/src/core/document.js index 8c1696d8b..544fab3ee 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -128,11 +128,14 @@ class Page { }; } - #createPartialEvaluator(handler) { + #createPartialEvaluator(handler, pageIndex = this.pageIndex) { + // The pageIndex is used to identify the page some objects (like images) + // belong to. + return new PartialEvaluator({ xref: this.xref, handler, - pageIndex: this.pageIndex, + pageIndex, idFactory: this._localIdFactory, fontCache: this.fontCache, builtInCMapCache: this.builtInCMapCache, @@ -463,7 +466,6 @@ class Page { task, intent, cacheKey, - pageId = this.pageIndex, pageIndex = this.pageIndex, annotationStorage = null, modifiedIds = null, @@ -471,7 +473,7 @@ class Page { const contentStreamPromise = this.getContentStream(); const resourcesPromise = this.loadResources(RESOURCES_KEYS_OPERATOR_LIST); - const partialEvaluator = this.#createPartialEvaluator(handler); + const partialEvaluator = this.#createPartialEvaluator(handler, pageIndex); const newAnnotsByPage = !this.xfaFactory ? getNewAnnotationsMap(annotationStorage) diff --git a/test/integration/reorganize_pages_spec.mjs b/test/integration/reorganize_pages_spec.mjs index 018a92d30..c2d6d9090 100644 --- a/test/integration/reorganize_pages_spec.mjs +++ b/test/integration/reorganize_pages_spec.mjs @@ -984,4 +984,60 @@ describe("Reorganize Pages View", () => { ); }); }); + + describe("Thumbnails are not blank after cut/paste (bug 2018162)", () => { + let pages; + + beforeEach(async () => { + pages = await loadAndWait( + "two_pages.pdf", + "#viewsManagerToggleButton", + "page-fit", + null, + { enableSplitMerge: true } + ); + }); + + afterEach(async () => { + await closePages(pages); + }); + + it("should check that the thumbnail has a blob src after cut and paste", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await waitForThumbnailVisible(page, 1); + await page.waitForSelector("#viewsManagerStatusActionButton", { + visible: true, + }); + await waitAndClick( + page, + `.thumbnail:has(${getThumbnailSelector(1)}) input` + ); + + for (let i = 1; i <= 2; i++) { + await page.waitForSelector( + `${getThumbnailSelector(i)} > img[src^="blob:http:"]`, + { visible: true } + ); + } + + let handlePagesEdited = await waitForPagesEdited(page, "cut"); + await waitAndClick(page, "#viewsManagerStatusActionButton"); + await waitAndClick(page, "#viewsManagerStatusActionCut"); + await awaitPromise(handlePagesEdited); + + handlePagesEdited = await waitForPagesEdited(page); + await waitAndClick(page, `${getThumbnailSelector(1)}+button`); + await awaitPromise(handlePagesEdited); + + for (let i = 1; i <= 2; i++) { + await page.waitForSelector( + `${getThumbnailSelector(i)} > img[src^="blob:http:"]`, + { visible: true } + ); + } + }) + ); + }); + }); }); diff --git a/test/integration/thumbnail_view_spec.mjs b/test/integration/thumbnail_view_spec.mjs index ae830a754..42d167861 100644 --- a/test/integration/thumbnail_view_spec.mjs +++ b/test/integration/thumbnail_view_spec.mjs @@ -52,10 +52,9 @@ describe("PDF Thumbnail View", () => { await waitForThumbnailVisible(page, 1); - const src = await page.$eval(thumbSelector, el => el.src); - expect(src) - .withContext(`In ${browserName}`) - .toMatch(/^blob:http:/); + await page.waitForSelector(`${thumbSelector}[src^="blob:http:"]`, { + visible: true, + }); }) ); }); @@ -116,13 +115,12 @@ describe("PDF Thumbnail View", () => { `.thumbnail ${thumbSelector}[aria-current="page"]`, { visible: true } ); - const src = await page.$eval( - `${thumbSelector} > img`, - el => el.src + await page.waitForSelector( + `${thumbSelector} > img[src^="blob:http:"]`, + { + visible: true, + } ); - expect(src) - .withContext(`In ${browserName}`) - .toMatch(/^blob:http:/); } }) ); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 73665e3be..86cd69044 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -873,3 +873,4 @@ !Brotli-Prototype-FileA.pdf !bug2013793.pdf !bug2014080.pdf +!two_pages.pdf diff --git a/test/pdfs/two_pages.pdf b/test/pdfs/two_pages.pdf new file mode 100755 index 000000000..3488d77b3 Binary files /dev/null and b/test/pdfs/two_pages.pdf differ