mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-08-02 20:37:21 +02:00
Merge pull request #21131 from Snuffleupagus/fix-CopyLocalImage-unittests
Improve the "CopyLocalImage" unit-tests
This commit is contained in:
commit
e070944ff0
@ -2794,7 +2794,11 @@ class WorkerTransport {
|
|||||||
if (!data.dataLen) {
|
if (!data.dataLen) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
this.commonObjs.resolve(id, structuredClone(data));
|
const copy = structuredClone(data);
|
||||||
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
||||||
|
copy.CopyLocalImage = true;
|
||||||
|
}
|
||||||
|
this.commonObjs.resolve(id, copy);
|
||||||
return data.dataLen;
|
return data.dataLen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4883,8 +4883,7 @@ have written that much by now. So, here’s to squashing bugs.`);
|
|||||||
const pdfDoc = await loadingTask.promise;
|
const pdfDoc = await loadingTask.promise;
|
||||||
const { canvasFactory } = pdfDoc;
|
const { canvasFactory } = pdfDoc;
|
||||||
let checkedCopyLocalImage = false,
|
let checkedCopyLocalImage = false,
|
||||||
firstImgData = null,
|
firstImgData = null;
|
||||||
firstStatsOverall = null;
|
|
||||||
|
|
||||||
for (let i = 1; i <= pdfDoc.numPages; i++) {
|
for (let i = 1; i <= pdfDoc.numPages; i++) {
|
||||||
const pdfPage = await pdfDoc.getPage(i);
|
const pdfPage = await pdfDoc.getPage(i);
|
||||||
@ -4905,10 +4904,6 @@ have written that much by now. So, here’s to squashing bugs.`);
|
|||||||
// the image-data below.
|
// the image-data below.
|
||||||
canvasFactory.destroy(canvasAndCtx);
|
canvasFactory.destroy(canvasAndCtx);
|
||||||
|
|
||||||
const [statsOverall] = pdfPage.stats.times
|
|
||||||
.filter(time => time.name === "Overall")
|
|
||||||
.map(time => time.end - time.start);
|
|
||||||
|
|
||||||
const { commonObjs, objs } = pdfPage;
|
const { commonObjs, objs } = pdfPage;
|
||||||
const imgIndex = opList.fnArray.indexOf(OPS.paintImageXObject);
|
const imgIndex = opList.fnArray.indexOf(OPS.paintImageXObject);
|
||||||
const [objId, width, height] = opList.argsArray[imgIndex];
|
const [objId, width, height] = opList.argsArray[imgIndex];
|
||||||
@ -4932,7 +4927,6 @@ have written that much by now. So, here’s to squashing bugs.`);
|
|||||||
// Ensure that the actual image data is identical for all pages.
|
// Ensure that the actual image data is identical for all pages.
|
||||||
if (i === 1) {
|
if (i === 1) {
|
||||||
firstImgData = objs.get(objId);
|
firstImgData = objs.get(objId);
|
||||||
firstStatsOverall = statsOverall;
|
|
||||||
|
|
||||||
expect(firstImgData.width).toEqual(EXPECTED_WIDTH);
|
expect(firstImgData.width).toEqual(EXPECTED_WIDTH);
|
||||||
expect(firstImgData.height).toEqual(EXPECTED_HEIGHT);
|
expect(firstImgData.height).toEqual(EXPECTED_HEIGHT);
|
||||||
@ -4958,10 +4952,9 @@ have written that much by now. So, here’s to squashing bugs.`);
|
|||||||
).toEqual(true);
|
).toEqual(true);
|
||||||
|
|
||||||
if (i === NUM_PAGES_THRESHOLD) {
|
if (i === NUM_PAGES_THRESHOLD) {
|
||||||
checkedCopyLocalImage = true;
|
// Ensure that the image was copied in the main-thread (into
|
||||||
// Ensure that the image was copied in the main-thread, rather
|
// commonObjs), rather than being re-parsed in the worker-thread.
|
||||||
// than being re-parsed in the worker-thread (which is slower).
|
checkedCopyLocalImage = currentImgData.CopyLocalImage;
|
||||||
expect(statsOverall).toBeLessThan(firstStatsOverall / 2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4969,7 +4962,6 @@ have written that much by now. So, here’s to squashing bugs.`);
|
|||||||
|
|
||||||
await loadingTask.destroy();
|
await loadingTask.destroy();
|
||||||
firstImgData = null;
|
firstImgData = null;
|
||||||
firstStatsOverall = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("caches image resources at the document/page level, with main-thread copying of complex images (issue 11518)", async function () {
|
it("caches image resources at the document/page level, with main-thread copying of complex images (issue 11518)", async function () {
|
||||||
@ -5011,11 +5003,13 @@ have written that much by now. So, here’s to squashing bugs.`);
|
|||||||
expect(objs.has(objId)).toEqual(true);
|
expect(objs.has(objId)).toEqual(true);
|
||||||
expect(commonObjs.has(objId)).toEqual(false);
|
expect(commonObjs.has(objId)).toEqual(false);
|
||||||
} else if (i === NUM_PAGES_THRESHOLD) {
|
} else if (i === NUM_PAGES_THRESHOLD) {
|
||||||
checkedCopyLocalImage = true;
|
|
||||||
// Ensure that the image was copied in the main-thread (into
|
|
||||||
// commonObjs), rather than being re-parsed in the worker-thread.
|
|
||||||
expect(objs.has(objId)).toEqual(false);
|
expect(objs.has(objId)).toEqual(false);
|
||||||
expect(commonObjs.has(objId)).toEqual(true);
|
expect(commonObjs.has(objId)).toEqual(true);
|
||||||
|
|
||||||
|
// Ensure that the image was copied in the main-thread (into
|
||||||
|
// commonObjs), rather than being re-parsed in the worker-thread.
|
||||||
|
const imgData = commonObjs.get(objId);
|
||||||
|
checkedCopyLocalImage = imgData.CopyLocalImage;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user