Skip to content

Commit

Permalink
Use BiDi protocol for Chrome tests
Browse files Browse the repository at this point in the history
  • Loading branch information
calixteman committed Apr 17, 2024
1 parent 7290faf commit c6c48e6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 51 deletions.
6 changes: 3 additions & 3 deletions test/integration/freetext_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2354,14 +2354,14 @@ describe("FreeText Editor", () => {
`${getEditorSelector(1)} .overlay.enabled`
);

rect = await page.$eval(getEditorSelector(0), el => {
rect = await page.$eval(getEditorSelector(1), el => {
const { x, y, width, height } = el.getBoundingClientRect();
return { x, y, width, height };
});

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));

Expand Down
70 changes: 34 additions & 36 deletions test/integration/scripting_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
awaitPromise,
clearInput,
closePages,
closeSinglePage,
getAnnotationStorage,
getComputedStyleSelector,
getFirstSerialized,
Expand Down Expand Up @@ -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);
}
});
});

Expand Down Expand Up @@ -1792,6 +1789,9 @@ describe("Interaction", () => {
"",
null /* pageSetup = */,
async page => {
page.on("dialog", async dialog => {
await dialog.dismiss();
});
printHandles.set(
page,
await page.evaluateHandle(() => [
Expand Down Expand Up @@ -1825,11 +1825,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));
}
});
});

Expand Down
15 changes: 8 additions & 7 deletions test/integration/test_utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -557,6 +557,7 @@ export {
awaitPromise,
clearInput,
closePages,
closeSinglePage,
createPromise,
dragAndDropAnnotation,
firstPageOnTop,
Expand Down
6 changes: 1 addition & 5 deletions test/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ function unitTestPostHandler(req, res) {
async function startBrowser({ browserName, headless, startUrl }) {
const options = {
product: browserName,
protocol: "cdp",
protocol: "webDriverBiDi",
headless,
defaultViewport: null,
ignoreDefaultArgs: ["--disable-extensions"],
Expand All @@ -905,10 +905,6 @@ async function startBrowser({ browserName, headless, startUrl }) {
}

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,
Expand Down

0 comments on commit c6c48e6

Please sign in to comment.