From b41bca7da9d65f2e5f2a2300f782c73e21eec3bf Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 24 Sep 2023 12:38:00 +0200 Subject: [PATCH] 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. --- test/integration/scripting_spec.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/test/integration/scripting_spec.js b/test/integration/scripting_spec.js index 20c48a149c0b5..f7ab93cc25a74 100644 --- a/test/integration/scripting_spec.js +++ b/test/integration/scripting_spec.js @@ -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"); }) );