mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 01:10:08 +02:00
Set the event handlers in the integration tests before any event is triggered
The function evaluateOnNewDocument in Puppeteer allow us to execute some js before the pdf.js one is loaded. It allows us to stub some setters before there are used and then set some event handlers very soon.
This commit is contained in:
parent
d8d9cff715
commit
5e4948062c
4 changed files with 81 additions and 70 deletions
|
@ -1764,38 +1764,28 @@ describe("Interaction", () => {
|
|||
// it is usually very fast and therefore activating the selector check
|
||||
// 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 = */,
|
||||
async page => {
|
||||
pages = await loadAndWait("autoprint.pdf", "", null /* zoom = */, {
|
||||
postPageSetup: async page => {
|
||||
printHandles.set(
|
||||
page,
|
||||
page.evaluateHandle(() => [
|
||||
new Promise(resolve => {
|
||||
globalThis.printResolve = resolve;
|
||||
}),
|
||||
window.PDFViewerApplication._testPrintResolver.promise,
|
||||
])
|
||||
);
|
||||
await page.waitForFunction(() => {
|
||||
// We don't really need to print the document.
|
||||
window.print = () => {};
|
||||
if (!window.PDFViewerApplication?.eventBus) {
|
||||
return false;
|
||||
}
|
||||
window.PDFViewerApplication.eventBus.on(
|
||||
"print",
|
||||
() => {
|
||||
const resolve = globalThis.printResolve;
|
||||
delete globalThis.printResolve;
|
||||
resolve();
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
);
|
||||
},
|
||||
appSetup: app => {
|
||||
app._testPrintResolver = Promise.withResolvers();
|
||||
},
|
||||
eventBusSetup: eventBus => {
|
||||
eventBus.on(
|
||||
"print",
|
||||
() => {
|
||||
window.PDFViewerApplication._testPrintResolver.resolve();
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue