mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Merge pull request #18635 from calixteman/avoid_print_dialog
Don't show the print dialog when printing in some integration tests
This commit is contained in:
commit
5f7637b9ea
2 changed files with 48 additions and 41 deletions
|
@ -439,38 +439,40 @@ describe("Interaction", () => {
|
|||
let pages;
|
||||
|
||||
beforeAll(async () => {
|
||||
pages = await loadAndWait("doc_actions.pdf", getSelector("47R"));
|
||||
pages = await loadAndWait("doc_actions.pdf", getSelector("47R"), null, {
|
||||
earlySetup: () => {
|
||||
// No need to trigger the print dialog.
|
||||
window.print = () => {};
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("must execute WillPrint and DidPrint actions", async () => {
|
||||
// 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 waitForScripting(page);
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
await waitForScripting(page);
|
||||
|
||||
await clearInput(page, getSelector("47R"));
|
||||
await page.evaluate(_ => {
|
||||
window.document.activeElement.blur();
|
||||
});
|
||||
await page.waitForFunction(`${getQuerySelector("47R")}.value === ""`);
|
||||
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");
|
||||
}
|
||||
);
|
||||
expect(text).withContext(`In ${browserName}`).toEqual("WillPrint");
|
||||
await page.keyboard.press("Escape");
|
||||
const text = await actAndWaitForInput(
|
||||
page,
|
||||
getSelector("47R"),
|
||||
async () => {
|
||||
await page.click("#print");
|
||||
}
|
||||
);
|
||||
expect(text).withContext(`In ${browserName}`).toEqual("WillPrint");
|
||||
|
||||
await page.waitForFunction(
|
||||
`${getQuerySelector("50R")}.value === "DidPrint"`
|
||||
);
|
||||
await closeSinglePage(page);
|
||||
}
|
||||
await page.waitForFunction(
|
||||
`${getQuerySelector("50R")}.value === "DidPrint"`
|
||||
);
|
||||
await closeSinglePage(page);
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1742,7 +1744,6 @@ describe("Interaction", () => {
|
|||
|
||||
describe("in autoprint.pdf", () => {
|
||||
let pages;
|
||||
const printHandles = new Map();
|
||||
|
||||
beforeAll(async () => {
|
||||
// Autoprinting is triggered by the `Open` event, which is one of the
|
||||
|
@ -1754,13 +1755,9 @@ describe("Interaction", () => {
|
|||
// too late will cause it to never resolve because printing is already
|
||||
// done (and the printed page div removed) before we even get to it.
|
||||
pages = await loadAndWait("autoprint.pdf", "", null /* zoom = */, {
|
||||
postPageSetup: async page => {
|
||||
printHandles.set(
|
||||
page,
|
||||
page.evaluateHandle(() => [
|
||||
window.PDFViewerApplication._testPrintResolver.promise,
|
||||
])
|
||||
);
|
||||
earlySetup: () => {
|
||||
// No need to trigger the print dialog.
|
||||
window.print = () => {};
|
||||
},
|
||||
appSetup: app => {
|
||||
app._testPrintResolver = Promise.withResolvers();
|
||||
|
@ -1779,7 +1776,6 @@ describe("Interaction", () => {
|
|||
|
||||
afterAll(async () => {
|
||||
await closePages(pages);
|
||||
printHandles.clear();
|
||||
});
|
||||
|
||||
it("must check if printing is triggered when the document is open", async () => {
|
||||
|
@ -1787,7 +1783,11 @@ describe("Interaction", () => {
|
|||
pages.map(async ([browserName, page]) => {
|
||||
await waitForScripting(page);
|
||||
|
||||
await awaitPromise(await printHandles.get(page));
|
||||
await awaitPromise(
|
||||
await page.evaluateHandle(() => [
|
||||
window.PDFViewerApplication._testPrintResolver.promise,
|
||||
])
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
|
|
@ -60,11 +60,15 @@ function loadAndWait(filename, selector, zoom, setups, options) {
|
|||
// and EventBus, so we can inject some code to do whatever we want
|
||||
// soon enough especially before the first event in the eventBus is
|
||||
// dispatched.
|
||||
const { prePageSetup, appSetup, eventBusSetup } = setups;
|
||||
const { prePageSetup, appSetup, earlySetup, eventBusSetup } = setups;
|
||||
await prePageSetup?.(page);
|
||||
if (appSetup || eventBusSetup) {
|
||||
if (earlySetup || appSetup || eventBusSetup) {
|
||||
await page.evaluateOnNewDocument(
|
||||
(aSetup, eSetup) => {
|
||||
(eaSetup, aSetup, evSetup) => {
|
||||
if (eaSetup) {
|
||||
// eslint-disable-next-line no-eval
|
||||
eval(`(${eaSetup})`)();
|
||||
}
|
||||
let app;
|
||||
let eventBus;
|
||||
Object.defineProperty(window, "PDFViewerApplication", {
|
||||
|
@ -83,13 +87,16 @@ function loadAndWait(filename, selector, zoom, setups, options) {
|
|||
},
|
||||
set(newV) {
|
||||
eventBus = newV;
|
||||
// eslint-disable-next-line no-eval
|
||||
eval(`(${eSetup})`)(eventBus);
|
||||
if (evSetup) {
|
||||
// eslint-disable-next-line no-eval
|
||||
eval(`(${evSetup})`)(eventBus);
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
earlySetup?.toString(),
|
||||
appSetup?.toString(),
|
||||
eventBusSetup?.toString()
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue