Skip to content

Commit dea2471

Browse files
committed
[JS] UserActivation must be enabled before running document actions
else auto-print is broken (it's a regression from patch mozilla#15822).
1 parent 4faf927 commit dea2471

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

src/scripting_api/event.js

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ class EventDispatcher {
9191
if (id === "doc") {
9292
const eventName = event.name;
9393
if (eventName === "Open") {
94+
// The user has decided to open this pdf, hence we enable
95+
// userActivation.
96+
this.userActivation();
9497
// Initialize named actions before calling formatAll to avoid any
9598
// errors in the case where a formatter is using one of those named
9699
// actions (see #15818).

test/integration/scripting_spec.js

+27
Original file line numberDiff line numberDiff line change
@@ -1753,4 +1753,31 @@ describe("Interaction", () => {
17531753
);
17541754
});
17551755
});
1756+
1757+
describe("in autoprint.pdf", () => {
1758+
let pages;
1759+
1760+
beforeAll(async () => {
1761+
pages = await loadAndWait("autoprint.pdf", ".endOfContent");
1762+
});
1763+
1764+
afterAll(async () => {
1765+
await closePages(pages);
1766+
});
1767+
1768+
it("must check if printing is triggered when the document is open", async () => {
1769+
await Promise.all(
1770+
pages.map(async ([browserName, page]) => {
1771+
await page.waitForFunction(
1772+
"window.PDFViewerApplication.scriptingReady === true"
1773+
);
1774+
1775+
await page.waitForFunction(
1776+
`document.querySelector(".printedPage") !== null`
1777+
);
1778+
await page.keyboard.press("Escape");
1779+
})
1780+
);
1781+
});
1782+
});
17561783
});

test/pdfs/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -563,3 +563,4 @@
563563
!fields_order.pdf
564564
!issue15815.pdf
565565
!issue15818.pdf
566+
!autoprint.pdf

test/pdfs/autoprint.pdf

8.92 KB
Binary file not shown.

0 commit comments

Comments
 (0)