mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 14:48:08 +02:00
Add test for drawing delay with CSS-only zoom
This commit adds a test for 0603d1ac18
.
Before the fix the `pagerendered` events would be fired just 2-3
milliseconds after the call to `increaseScale`/`decreaseScale`.
This commit is contained in:
parent
9ee7c07b83
commit
53d866660a
2 changed files with 95 additions and 1 deletions
|
@ -13,7 +13,12 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { closePages, loadAndWait } from "./test_utils.mjs";
|
||||
import {
|
||||
awaitPromise,
|
||||
closePages,
|
||||
createPromise,
|
||||
loadAndWait,
|
||||
} from "./test_utils.mjs";
|
||||
|
||||
describe("PDF viewer", () => {
|
||||
describe("Zoom with the mouse wheel", () => {
|
||||
|
@ -87,4 +92,87 @@ describe("PDF viewer", () => {
|
|||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("CSS-only zoom", () => {
|
||||
let pages;
|
||||
|
||||
beforeAll(async () => {
|
||||
pages = await loadAndWait(
|
||||
"tracemonkey.pdf",
|
||||
".textLayer .endOfContent",
|
||||
null,
|
||||
null,
|
||||
{
|
||||
maxCanvasPixels: 0,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await closePages(pages);
|
||||
});
|
||||
|
||||
function createPromiseForFirstPageRendered(page) {
|
||||
return createPromise(page, (resolve, reject) => {
|
||||
const controller = new AbortController();
|
||||
window.PDFViewerApplication.eventBus.on(
|
||||
"pagerendered",
|
||||
({ pageNumber, timestamp }) => {
|
||||
if (pageNumber === 1) {
|
||||
resolve(timestamp);
|
||||
controller.abort();
|
||||
}
|
||||
},
|
||||
{ signal: controller.signal }
|
||||
);
|
||||
setTimeout(reject, 1000, new Error("Timeout"));
|
||||
});
|
||||
}
|
||||
|
||||
it("respects drawing delay when zooming out", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
const promise = await createPromiseForFirstPageRendered(page);
|
||||
|
||||
const start = await page.evaluate(() => {
|
||||
const startTime = performance.now();
|
||||
window.PDFViewerApplication.pdfViewer.decreaseScale({
|
||||
drawingDelay: 100,
|
||||
scaleFactor: 0.9,
|
||||
});
|
||||
return startTime;
|
||||
});
|
||||
|
||||
const end = await awaitPromise(promise);
|
||||
|
||||
expect(end - start)
|
||||
.withContext(`In ${browserName}`)
|
||||
.toBeGreaterThanOrEqual(100);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("respects drawing delay when zooming in", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
const promise = await createPromiseForFirstPageRendered(page);
|
||||
|
||||
const start = await page.evaluate(() => {
|
||||
const startTime = performance.now();
|
||||
window.PDFViewerApplication.pdfViewer.increaseScale({
|
||||
drawingDelay: 100,
|
||||
scaleFactor: 1.1,
|
||||
});
|
||||
return startTime;
|
||||
});
|
||||
|
||||
const end = await awaitPromise(promise);
|
||||
|
||||
expect(end - start)
|
||||
.withContext(`In ${browserName}`)
|
||||
.toBeGreaterThanOrEqual(100);
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -359,6 +359,12 @@ const PDFViewerApplication = {
|
|||
params.get("highlighteditorcolors")
|
||||
);
|
||||
}
|
||||
if (params.has("maxcanvaspixels")) {
|
||||
AppOptions.set(
|
||||
"maxCanvasPixels",
|
||||
Number(params.get("maxcanvaspixels"))
|
||||
);
|
||||
}
|
||||
if (params.has("supportscaretbrowsingmode")) {
|
||||
AppOptions.set(
|
||||
"supportsCaretBrowsingMode",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue