Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the integration tests related to printing #18383

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 33 additions & 34 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 @@ -1789,17 +1786,19 @@ describe("Interaction", () => {
pages = await loadAndWait(
"autoprint.pdf",
"",
null /* pageSetup = */,
null /* zoom = */,
async page => {
printHandles.set(
page,
await page.evaluateHandle(() => [
page.evaluateHandle(() => [
new Promise(resolve => {
globalThis.printResolve = resolve;
}),
])
);
await page.waitForFunction(() => {
// We don't really need to print the document.
window.print = () => {};
if (!window.PDFViewerApplication?.eventBus) {
return false;
}
Expand All @@ -1826,7 +1825,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 awaitPromise(printHandles.get(page));
await awaitPromise(await printHandles.get(page));
})
);
});
Expand Down