mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 09:20:06 +02:00
Merge pull request #18383 from calixteman/fix_print_test
Fix the integration tests related to printing
This commit is contained in:
commit
790470c1aa
1 changed files with 34 additions and 35 deletions
|
@ -17,6 +17,7 @@ import {
|
||||||
awaitPromise,
|
awaitPromise,
|
||||||
clearInput,
|
clearInput,
|
||||||
closePages,
|
closePages,
|
||||||
|
closeSinglePage,
|
||||||
getAnnotationStorage,
|
getAnnotationStorage,
|
||||||
getComputedStyleSelector,
|
getComputedStyleSelector,
|
||||||
getFirstSerialized,
|
getFirstSerialized,
|
||||||
|
@ -418,41 +419,37 @@ describe("Interaction", () => {
|
||||||
pages = await loadAndWait("doc_actions.pdf", getSelector("47R"));
|
pages = await loadAndWait("doc_actions.pdf", getSelector("47R"));
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
await closePages(pages);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("must execute WillPrint and DidPrint actions", async () => {
|
it("must execute WillPrint and DidPrint actions", async () => {
|
||||||
await Promise.all(
|
// Run the tests sequentially to avoid to use the same printer at the same
|
||||||
pages.map(async ([browserName, page]) => {
|
// time.
|
||||||
if (process.platform === "win32" && browserName === "firefox") {
|
// And to make sure that a printer isn't locked by a process we close the
|
||||||
pending("Disabled in Firefox on Windows, because of bug 1662471.");
|
// page before running the next test.
|
||||||
|
for (const [browserName, page] of pages) {
|
||||||
|
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 === ""`);
|
||||||
|
|
||||||
|
const text = await actAndWaitForInput(
|
||||||
|
page,
|
||||||
|
getSelector("47R"),
|
||||||
|
async () => {
|
||||||
|
await page.click("#print");
|
||||||
}
|
}
|
||||||
await page.waitForFunction(
|
);
|
||||||
"window.PDFViewerApplication.scriptingReady === true"
|
expect(text).withContext(`In ${browserName}`).toEqual("WillPrint");
|
||||||
);
|
await page.keyboard.press("Escape");
|
||||||
|
|
||||||
await clearInput(page, getSelector("47R"));
|
await page.waitForFunction(
|
||||||
await page.evaluate(_ => {
|
`${getQuerySelector("50R")}.value === "DidPrint"`
|
||||||
window.document.activeElement.blur();
|
);
|
||||||
});
|
await closeSinglePage(page);
|
||||||
await page.waitForFunction(`${getQuerySelector("47R")}.value === ""`);
|
}
|
||||||
|
|
||||||
let text = await actAndWaitForInput(
|
|
||||||
page,
|
|
||||||
getSelector("47R"),
|
|
||||||
async () => {
|
|
||||||
await page.click("#print");
|
|
||||||
}
|
|
||||||
);
|
|
||||||
expect(text).withContext(`In ${browserName}`).toEqual("WillPrint");
|
|
||||||
|
|
||||||
await page.waitForFunction(`${getQuerySelector("50R")}.value !== ""`);
|
|
||||||
|
|
||||||
text = await page.$eval(getSelector("50R"), el => el.value);
|
|
||||||
expect(text).withContext(`In ${browserName}`).toEqual("DidPrint");
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1789,17 +1786,19 @@ describe("Interaction", () => {
|
||||||
pages = await loadAndWait(
|
pages = await loadAndWait(
|
||||||
"autoprint.pdf",
|
"autoprint.pdf",
|
||||||
"",
|
"",
|
||||||
null /* pageSetup = */,
|
null /* zoom = */,
|
||||||
async page => {
|
async page => {
|
||||||
printHandles.set(
|
printHandles.set(
|
||||||
page,
|
page,
|
||||||
await page.evaluateHandle(() => [
|
page.evaluateHandle(() => [
|
||||||
new Promise(resolve => {
|
new Promise(resolve => {
|
||||||
globalThis.printResolve = resolve;
|
globalThis.printResolve = resolve;
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
await page.waitForFunction(() => {
|
await page.waitForFunction(() => {
|
||||||
|
// We don't really need to print the document.
|
||||||
|
window.print = () => {};
|
||||||
if (!window.PDFViewerApplication?.eventBus) {
|
if (!window.PDFViewerApplication?.eventBus) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1826,7 +1825,7 @@ describe("Interaction", () => {
|
||||||
it("must check if printing is triggered when the document is open", async () => {
|
it("must check if printing is triggered when the document is open", async () => {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
pages.map(async ([browserName, page]) => {
|
pages.map(async ([browserName, page]) => {
|
||||||
await awaitPromise(printHandles.get(page));
|
await awaitPromise(await printHandles.get(page));
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue