Don't wait for scripting to be ready in the autoprint integration test

This integration test fails often because we wait for scripting to be
ready before we check the printed page, but most of the time the PDF
is already done printing before scripting is reported to be ready.

This happens because the print trigger is on the `Open` event, which is
one of the first events to be dispatched and, most notably, before
scripting is marked as ready; please see
https://github.com/mozilla/pdf.js/blob/master/web/pdf_scripting_manager.js#L176-L191.
Given that the PDF document is only one page, printing it is usually
finished between triggering the `Open` event and scripting reported
to be ready. If this happens the printed page is already destroyed
before we get to our actual test, which will then timeout because it
will never find the printed page in the DOM.

This commit fixes the problem by not awaiting scripting to be ready
because the fact that the printed page appears is already enough to know
that autoprint was triggered (after all, there is no other user
interaction involved here). While we're here we also switch to the
shorter `page.waitForSelector` function.
This commit is contained in:
Tim van der Meij 2023-09-24 12:38:00 +02:00
parent 587a3a2eae
commit b41bca7da9
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762

View File

@ -1793,13 +1793,7 @@ describe("Interaction", () => {
it("must check if printing is triggered when the document is open", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await page.waitForFunction(
"window.PDFViewerApplication.scriptingReady === true"
);
await page.waitForFunction(
`document.querySelector(".printedPage") !== null`
);
await page.waitForSelector(".printedPage");
await page.keyboard.press("Escape");
})
);