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 Jun 14, 2024
1 parent e3caa3c commit 54ed774
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 52 deletions.
8 changes: 5 additions & 3 deletions test/integration/freetext_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));

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 @@ -1791,6 +1788,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 @@ -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));
}
});
});

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 @@ -615,6 +615,7 @@ export {
awaitPromise,
clearInput,
closePages,
closeSinglePage,
createPromise,
dragAndDropAnnotation,
firstPageOnTop,
Expand Down
9 changes: 3 additions & 6 deletions test/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 54ed774

Please sign in to comment.