Skip to content

Commit

Permalink
Don't wait for scripting to be ready in the autoprint integration test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
timvandermeij committed Sep 24, 2023
1 parent 587a3a2 commit b41bca7
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions test/integration/scripting_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
})
);
Expand Down

0 comments on commit b41bca7

Please sign in to comment.