From 54ed7741333dcb368f3115969adc9ad824296a28 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Wed, 17 Apr 2024 21:10:23 +0200 Subject: [PATCH] Use BiDi protocol for Chrome tests --- test/integration/freetext_editor_spec.mjs | 8 ++- test/integration/scripting_spec.mjs | 70 +++++++++++------------ test/integration/test_utils.mjs | 15 ++--- test/test.mjs | 9 +-- 4 files changed, 50 insertions(+), 52 deletions(-) diff --git a/test/integration/freetext_editor_spec.mjs b/test/integration/freetext_editor_spec.mjs index d7afe96ab52c4c..445b303e76f1ee 100644 --- a/test/integration/freetext_editor_spec.mjs +++ b/test/integration/freetext_editor_spec.mjs @@ -2256,6 +2256,7 @@ describe("FreeText Editor", () => { rect = await getRect(page, getEditorSelector(0)); + // Create a new editor. await page.mouse.click( rect.x + 5 * rect.width, rect.y + 5 * rect.height @@ -2271,11 +2272,12 @@ describe("FreeText Editor", () => { `${getEditorSelector(1)} .overlay.enabled` ); - rect = await getRect(page, getEditorSelector(0)); + // Select the second editor. + rect = await getRect(page, getEditorSelector(1)); await page.mouse.click( - rect.x + 5 * rect.width, - rect.y + 5 * rect.height + rect.x + 0.5 * rect.width, + rect.y + 0.5 * rect.height ); await waitForSelectedEditor(page, getEditorSelector(1)); diff --git a/test/integration/scripting_spec.mjs b/test/integration/scripting_spec.mjs index 50e2cfe961f426..ba40a8eddb2d64 100644 --- a/test/integration/scripting_spec.mjs +++ b/test/integration/scripting_spec.mjs @@ -17,6 +17,7 @@ import { awaitPromise, clearInput, closePages, + closeSinglePage, getAnnotationStorage, getComputedStyleSelector, getFirstSerialized, @@ -418,41 +419,37 @@ describe("Interaction", () => { pages = await loadAndWait("doc_actions.pdf", getSelector("47R")); }); - afterAll(async () => { - await closePages(pages); - }); - it("must execute WillPrint and DidPrint actions", async () => { - await Promise.all( - pages.map(async ([browserName, page]) => { - if (process.platform === "win32" && browserName === "firefox") { - pending("Disabled in Firefox on Windows, because of bug 1662471."); - } - await page.waitForFunction( - "window.PDFViewerApplication.scriptingReady === true" - ); - - await clearInput(page, getSelector("47R")); - await page.evaluate(_ => { - window.document.activeElement.blur(); - }); - await page.waitForFunction(`${getQuerySelector("47R")}.value === ""`); + // Run the tests sequentially to avoid to use the same printer at the same + // time. + // And to make sure that a printer isn't locked by a process we close the + // page before running the next test. + for (const [browserName, page] of pages) { + await page.waitForFunction( + "window.PDFViewerApplication.scriptingReady === true" + ); - let text = await actAndWaitForInput( - page, - getSelector("47R"), - async () => { - await page.click("#print"); - } - ); - expect(text).withContext(`In ${browserName}`).toEqual("WillPrint"); + await clearInput(page, getSelector("47R")); + await page.evaluate(_ => { + window.document.activeElement.blur(); + }); + await page.waitForFunction(`${getQuerySelector("47R")}.value === ""`); - await page.waitForFunction(`${getQuerySelector("50R")}.value !== ""`); + const text = await actAndWaitForInput( + page, + getSelector("47R"), + async () => { + await page.click("#print"); + } + ); + expect(text).withContext(`In ${browserName}`).toEqual("WillPrint"); + await page.keyboard.press("Escape"); - text = await page.$eval(getSelector("50R"), el => el.value); - expect(text).withContext(`In ${browserName}`).toEqual("DidPrint"); - }) - ); + await page.waitForFunction( + `${getQuerySelector("50R")}.value === "DidPrint"` + ); + await closeSinglePage(page); + } }); }); @@ -1791,6 +1788,9 @@ describe("Interaction", () => { "", null /* pageSetup = */, async page => { + page.on("dialog", async dialog => { + await dialog.dismiss(); + }); printHandles.set( page, await page.evaluateHandle(() => [ @@ -1824,11 +1824,9 @@ describe("Interaction", () => { }); it("must check if printing is triggered when the document is open", async () => { - await Promise.all( - pages.map(async ([browserName, page]) => { - await awaitPromise(printHandles.get(page)); - }) - ); + for (const [, page] of pages) { + await awaitPromise(printHandles.get(page)); + } }); }); diff --git a/test/integration/test_utils.mjs b/test/integration/test_utils.mjs index a282aaeeadd1fb..7293af9dea667c 100644 --- a/test/integration/test_utils.mjs +++ b/test/integration/test_utils.mjs @@ -76,13 +76,13 @@ function awaitPromise(promise) { } function closePages(pages) { - return Promise.all( - pages.map(async ([_, page]) => { - // Avoid to keep something from a previous test. - await page.evaluate(() => window.localStorage.clear()); - await page.close({ runBeforeUnload: false }); - }) - ); + return Promise.all(pages.map(async ([_, page]) => closeSinglePage(page))); +} + +async function closeSinglePage(page) { + // Avoid to keep something from a previous test. + await page.evaluate(() => window.localStorage.clear()); + await page.close({ runBeforeUnload: false }); } async function waitForSandboxTrip(page) { @@ -615,6 +615,7 @@ export { awaitPromise, clearInput, closePages, + closeSinglePage, createPromise, dragAndDropAnnotation, firstPageOnTop, diff --git a/test/test.mjs b/test/test.mjs index 034097178fce49..8c099f3d28037f 100644 --- a/test/test.mjs +++ b/test/test.mjs @@ -883,11 +883,12 @@ async function startBrowser({ }) { const options = { product: browserName, - protocol: "cdp", + protocol: "webDriverBiDi", headless, + dumpio: true, defaultViewport: null, ignoreDefaultArgs: ["--disable-extensions"], - // The timeout for individual protocol (CDP) calls should always be lower + // The timeout for individual protocol (BiDi) calls should always be lower // than the Jasmine timeout. This way protocol errors are always raised in // the context of the tests that actually triggered them and don't leak // through to other tests (causing unrelated failures or tracebacks). The @@ -910,10 +911,6 @@ async function startBrowser({ } if (browserName === "firefox") { - // Run tests with the WebDriver BiDi protocol enabled only for Firefox for - // now given that for Chrome further fixes are needed first. - options.protocol = "webDriverBiDi"; - options.extraPrefsFirefox = { // avoid to have a prompt when leaving a page with a form "dom.disable_beforeunload": true,