From dea2471e961061fcc9bf8362d14dd3a57f8c2a84 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Wed, 4 Jan 2023 19:49:31 +0100 Subject: [PATCH] [JS] UserActivation must be enabled before running document actions else auto-print is broken (it's a regression from patch #15822). --- src/scripting_api/event.js | 3 +++ test/integration/scripting_spec.js | 27 +++++++++++++++++++++++++++ test/pdfs/.gitignore | 1 + test/pdfs/autoprint.pdf | Bin 0 -> 9138 bytes 4 files changed, 31 insertions(+) create mode 100755 test/pdfs/autoprint.pdf diff --git a/src/scripting_api/event.js b/src/scripting_api/event.js index e1713c9ec..30b5b1878 100644 --- a/src/scripting_api/event.js +++ b/src/scripting_api/event.js @@ -91,6 +91,9 @@ class EventDispatcher { if (id === "doc") { const eventName = event.name; if (eventName === "Open") { + // The user has decided to open this pdf, hence we enable + // userActivation. + this.userActivation(); // Initialize named actions before calling formatAll to avoid any // errors in the case where a formatter is using one of those named // actions (see #15818). diff --git a/test/integration/scripting_spec.js b/test/integration/scripting_spec.js index 72666a501..c60feb1cd 100644 --- a/test/integration/scripting_spec.js +++ b/test/integration/scripting_spec.js @@ -1753,4 +1753,31 @@ describe("Interaction", () => { ); }); }); + + describe("in autoprint.pdf", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait("autoprint.pdf", ".endOfContent"); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must check if printing is triggered when the document is open", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await page.waitForFunction( + "window.PDFViewerApplication.scriptingReady === true" + ); + + await page.waitForFunction( + `document.querySelector(".printedPage") !== null` + ); + await page.keyboard.press("Escape"); + }) + ); + }); + }); }); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 68c603873..4439ffd3d 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -563,3 +563,4 @@ !fields_order.pdf !issue15815.pdf !issue15818.pdf +!autoprint.pdf diff --git a/test/pdfs/autoprint.pdf b/test/pdfs/autoprint.pdf new file mode 100755 index 0000000000000000000000000000000000000000..bc678d9243952e5af604db9707eef41061738611 GIT binary patch literal 9138 zcmeHNe{3699Z#CH%S>EKsm6*x9Nse0*7keve%a?aZu}!wliG=!n58Tf`FwXy+{QlZ zd`{dbXl>WA7TRf@HbF%ZTN$MpLTkE8AW_6LTC|4HDOpKXF-@>dNDPVov7rcPH{P8c z``TPfjW*y9N6P8$-uLI{ecwBO-g|AaP}qT-thMc}w_khRYC(vAgq+-I^?E@hot1bc zJt2t%0uh2iE)w(+hyq;%f`|pZ_;sA1-7E*T5JLn_GX$dH4xi5|Wkt;fVfKf8FjXHR zNsvV;#w(dT_862$3z=-5pg~NL#I&Hw3V}$U4}{aBs-%GMD6dK-70?|T@=`E>y+c0? zGh`q{yWK%VkxUr5LQIIF{eGX9CS8H9K!AaMzdu0Ies|CX{ef_h^ShWJ*X8!@0Nq(p zDh}bqIqg0rygfV)2p{!v+{|g_??w&g~a|fAFjXrVN(li zh>xwDw^}f6Wz8~zd6iexq9UcN7HGA!wRQD{t(G#X7)Y)Pq!~hli(ATqVR6^76c`{V z_J;5hiNp#UT16yUg_oP{t)JWCeV{#+I4LBCXB+;KOe8+I`?>Xh-OIq1^?|=%ZdlRU zP#A08X%eXpO1W^NlFEy`%40AzAba_YlqV3YKlByUQCwGfqVyQ!hw;6ZM}G;(Al4g| zhpR<|sA`fyMa~7};t+J=F2esTBJtJ5;p+|%#TCQfvK5z@lvT@~`lY;FPy`9r94@YY zS;b{VlzUQ($l#r>dN+YMoL2I|3rz2;qca`I64P%5%5@-^l_`-NBS3r$Df!i-;YO6 zJ^byFpm1t3B(8fkx%Ixs&dwh@w*7kI>x@b0*nob+mI}4nN8ZiF953vWR3a%2r?VZlt3UsxjYx|fwm~Keqq(3olHM|* zNCOkSabaSYz=^iaK8v^LDQ0pRT=qmUGn&nNiXAo{Pl1vL-)padjnGBZT^%;R)vCe5T*Xl~@6?lY3UUS%`5Zt_2+Wj3p`w#3D5H94q5z~(DTBvk z9_t}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