scripting_spec.js 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756
  1. /* Copyright 2020 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. const {
  16. clearInput,
  17. closePages,
  18. getSelector,
  19. getQuerySelector,
  20. getComputedStyleSelector,
  21. loadAndWait,
  22. } = require("./test_utils.js");
  23. describe("Interaction", () => {
  24. async function actAndWaitForInput(page, selector, action, clear = true) {
  25. await page.waitForSelector(selector, {
  26. timeout: 0,
  27. });
  28. if (clear) {
  29. await clearInput(page, selector);
  30. }
  31. await action();
  32. await page.waitForFunction(
  33. `document.querySelector('${selector}').value !== ""`
  34. );
  35. return page.$eval(selector, el => el.value);
  36. }
  37. describe("in 160F-2019.pdf", () => {
  38. let pages;
  39. beforeAll(async () => {
  40. pages = await loadAndWait("160F-2019.pdf", getSelector("416R"));
  41. });
  42. afterAll(async () => {
  43. await closePages(pages);
  44. });
  45. it("must check that first text field has focus", async () => {
  46. await Promise.all(
  47. pages.map(async ([browserName, page]) => {
  48. await page.waitForFunction(
  49. "window.PDFViewerApplication.scriptingReady === true"
  50. );
  51. await page.waitForFunction(`window.document.activeElement !== null`);
  52. // The document has an open action in order to give the focus to 401R.
  53. const id = await page.evaluate(() => {
  54. const element = window.document.activeElement;
  55. return element.getAttribute("data-element-id");
  56. });
  57. expect(id).withContext(`In ${browserName}`).toEqual("401R");
  58. })
  59. );
  60. });
  61. it("must show a text field and then make in invisible when content is removed", async () => {
  62. await Promise.all(
  63. pages.map(async ([browserName, page]) => {
  64. let visibility = await page.$eval(
  65. getSelector("427R"),
  66. el => getComputedStyle(el).visibility
  67. );
  68. expect(visibility).withContext(`In ${browserName}`).toEqual("hidden");
  69. await page.type(getSelector("416R"), "3.14159", { delay: 200 });
  70. await page.click(getSelector("419R"));
  71. await page.waitForFunction(
  72. `${getComputedStyleSelector("427R")}.visibility !== "hidden"`
  73. );
  74. visibility = await page.$eval(
  75. getSelector("427R"),
  76. el => getComputedStyle(el).visibility
  77. );
  78. expect(visibility)
  79. .withContext(`In ${browserName}`)
  80. .toEqual("visible");
  81. // Clear the textfield
  82. await clearInput(page, getSelector("416R"));
  83. // and leave it
  84. await page.click(getSelector("419R"));
  85. await page.waitForFunction(
  86. `${getComputedStyleSelector("427R")}.visibility !== "visible"`
  87. );
  88. visibility = await page.$eval(
  89. getSelector("427R"),
  90. el => getComputedStyle(el).visibility
  91. );
  92. expect(visibility).withContext(`In ${browserName}`).toEqual("hidden");
  93. })
  94. );
  95. });
  96. it("must format the field with 2 digits and leave field with a click", async () => {
  97. await Promise.all(
  98. pages.map(async ([browserName, page]) => {
  99. await page.type(getSelector("416R"), "3.14159", { delay: 200 });
  100. await page.click(getSelector("419R"));
  101. const valueFnStr = `${getQuerySelector("416R")}.value !== "3.14159"`;
  102. await page.waitForFunction(valueFnStr);
  103. const text = await page.$eval(getSelector("416R"), el => el.value);
  104. expect(text).withContext(`In ${browserName}`).toEqual("3,14");
  105. const sum = await page.$eval(getSelector("427R"), el => el.value);
  106. expect(sum).withContext(`In ${browserName}`).toEqual("3,14");
  107. })
  108. );
  109. });
  110. it("must format the field with 2 digits, leave field with a click and again", async () => {
  111. await Promise.all(
  112. pages.map(async ([browserName, page]) => {
  113. await page.type(getSelector("448R"), "61803", { delay: 200 });
  114. await page.click(getSelector("419R"));
  115. const valueOneFnStr = `${getQuerySelector("448R")}.value !== "61803"`;
  116. await page.waitForFunction(valueOneFnStr);
  117. let text = await page.$eval(getSelector("448R"), el => el.value);
  118. expect(text).withContext(`In ${browserName}`).toEqual("61.803,00");
  119. await page.click(getSelector("448R"));
  120. const valueTwoFnStr = `${getQuerySelector(
  121. "448R"
  122. )}.value !== "61.803,00"`;
  123. await page.waitForFunction(valueTwoFnStr);
  124. text = await page.$eval(getSelector("448R"), el => el.value);
  125. expect(text).withContext(`In ${browserName}`).toEqual("61803");
  126. // Clear the textfield
  127. await clearInput(page, getSelector("448R"));
  128. await page.type(getSelector("448R"), "1.61803", { delay: 200 });
  129. await page.click(getSelector("419R"));
  130. const valueThreeFnStr = `${getQuerySelector(
  131. "448R"
  132. )}.value !== "1.61803"`;
  133. await page.waitForFunction(valueThreeFnStr);
  134. text = await page.$eval(getSelector("448R"), el => el.value);
  135. expect(text).withContext(`In ${browserName}`).toEqual("1,62");
  136. })
  137. );
  138. });
  139. it("must format the field with 2 digits and leave field with a TAB", async () => {
  140. await Promise.all(
  141. pages.map(async ([browserName, page]) => {
  142. const prevSum = await page.$eval(getSelector("427R"), el => el.value);
  143. await page.type(getSelector("422R"), "2.7182818", { delay: 200 });
  144. await page.keyboard.press("Tab");
  145. await page.waitForFunction(
  146. `${getQuerySelector("422R")}.value !== "2.7182818"`
  147. );
  148. const text = await page.$eval(getSelector("422R"), el => el.value);
  149. expect(text).withContext(`In ${browserName}`).toEqual("2,72");
  150. await page.waitForFunction(
  151. `${getQuerySelector("427R")}.value !== "${prevSum}"`
  152. );
  153. const sum = await page.$eval(getSelector("427R"), el => el.value);
  154. expect(sum).withContext(`In ${browserName}`).toEqual("5,86");
  155. })
  156. );
  157. });
  158. it("must format the field with 2 digits and hit ESC", async () => {
  159. await Promise.all(
  160. pages.map(async ([browserName, page]) => {
  161. let sum = await page.$eval(getSelector("471R"), el => el.value);
  162. expect(sum).withContext(`In ${browserName}`).toEqual("4,24");
  163. await page.type(getSelector("436R"), "0.69314", { delay: 200 });
  164. await page.keyboard.press("Escape");
  165. const text = await page.$eval(getSelector("436R"), el => el.value);
  166. expect(text).withContext(`In ${browserName}`).toEqual("0.69314");
  167. await page.waitForFunction(
  168. `${getQuerySelector("471R")}.value !== "${sum}"`
  169. );
  170. sum = await page.$eval(getSelector("471R"), el => el.value);
  171. expect(sum).withContext(`In ${browserName}`).toEqual("3,55");
  172. })
  173. );
  174. });
  175. it("must format the field with 2 digits on key ENTER", async () => {
  176. await Promise.all(
  177. pages.map(async ([browserName, page]) => {
  178. const prevSum = await page.$eval(getSelector("427R"), el => el.value);
  179. await page.type(getSelector("419R"), "0.577215", { delay: 200 });
  180. await page.keyboard.press("Enter");
  181. const text = await page.$eval(getSelector("419R"), el => el.value);
  182. expect(text).toEqual("0.577215");
  183. await page.waitForFunction(
  184. `${getQuerySelector("427R")}.value !== "${prevSum}"`
  185. );
  186. const sum = await page.$eval(getSelector("427R"), el => el.value);
  187. expect(sum).toEqual("6,44");
  188. })
  189. );
  190. });
  191. it("must reset all", async () => {
  192. await Promise.all(
  193. pages.map(async ([browserName, page]) => {
  194. // click on a radio button
  195. await page.click("[data-annotation-id='449R']");
  196. // this field has no actions but it must be cleared on reset
  197. await page.type(getSelector("405R"), "employee", { delay: 200 });
  198. let checked = await page.$eval(getSelector("449R"), el => el.checked);
  199. expect(checked).toEqual(true);
  200. // click on reset button
  201. await page.click("[data-annotation-id='402R']");
  202. await Promise.all(
  203. ["416R", "422R", "419R", "405R"].map(id => {
  204. const querySelector = getQuerySelector(id);
  205. return page.waitForFunction(`${querySelector}.value === ""`);
  206. })
  207. );
  208. let text = await page.$eval(getSelector("416R"), el => el.value);
  209. expect(text).toEqual("");
  210. text = await page.$eval(getSelector("422R"), el => el.value);
  211. expect(text).toEqual("");
  212. text = await page.$eval(getSelector("419R"), el => el.value);
  213. expect(text).toEqual("");
  214. text = await page.$eval(getSelector("405R"), el => el.value);
  215. expect(text).toEqual("");
  216. checked = await page.$eval(getSelector("449R"), el => el.checked);
  217. expect(checked).toEqual(false);
  218. const visibility = await page.$eval(
  219. getSelector("427R"),
  220. el => getComputedStyle(el).visibility
  221. );
  222. expect(visibility).toEqual("hidden");
  223. })
  224. );
  225. });
  226. });
  227. describe("in js-buttons.pdf", () => {
  228. let pages;
  229. beforeAll(async () => {
  230. pages = await loadAndWait("js-buttons.pdf", getSelector("80R"));
  231. });
  232. afterAll(async () => {
  233. await closePages(pages);
  234. });
  235. it("must show values in a text input when clicking on radio buttons", async () => {
  236. await Promise.all(
  237. pages.map(async ([browserName, page]) => {
  238. await page.waitForFunction(
  239. "window.PDFViewerApplication.scriptingReady === true"
  240. );
  241. const expected = [
  242. ["81R", "Group1=Choice1::1"],
  243. ["82R", "Group1=Choice2::2"],
  244. ["83R", "Group1=Choice3::3"],
  245. ["84R", "Group1=Choice4::4"],
  246. ];
  247. for (const [id, expectedText] of expected) {
  248. // Clear the textfield
  249. await clearInput(page, getSelector("80R"));
  250. await page.click(getSelector(id));
  251. await page.waitForFunction(
  252. `${getQuerySelector("80R")}.value !== ""`
  253. );
  254. const text = await page.$eval(getSelector("80R"), el => el.value);
  255. expect(text).withContext(`In ${browserName}`).toEqual(expectedText);
  256. }
  257. })
  258. );
  259. });
  260. it("must show values in a text input when clicking on checkboxes", async () => {
  261. await Promise.all(
  262. pages.map(async ([browserName, page]) => {
  263. const expected = [
  264. ["85R", "Check1=Yes::5"],
  265. ["87R", "Check2=Yes::6"],
  266. ["88R", "Check3=Yes::7"],
  267. ["89R", "Check4=Yes::8"],
  268. ["85R", "Check1=Off::5"],
  269. ["87R", "Check2=Off::6"],
  270. ["88R", "Check3=Off::7"],
  271. ["89R", "Check4=Off::8"],
  272. ];
  273. for (const [id, expectedText] of expected) {
  274. // Clear the textfield
  275. await clearInput(page, getSelector("80R"));
  276. await page.click(getSelector(id));
  277. await page.waitForFunction(
  278. `${getQuerySelector("80R")}.value !== ""`
  279. );
  280. const text = await page.$eval(getSelector("80R"), el => el.value);
  281. expect(text).withContext(`In ${browserName}`).toEqual(expectedText);
  282. }
  283. })
  284. );
  285. });
  286. it("must show values in a text input when clicking on checkboxes in a group", async () => {
  287. await Promise.all(
  288. pages.map(async ([browserName, page]) => {
  289. const expected = [
  290. ["90R", "Check5=Yes1::9"],
  291. ["91R", "Check5=Yes2::10"],
  292. ["92R", "Check5=Yes3::11"],
  293. ["93R", "Check5=Yes4::12"],
  294. ["93R", "Check5=Off::12"],
  295. ];
  296. for (const [id, expectedText] of expected) {
  297. // Clear the textfield
  298. await clearInput(page, getSelector("80R"));
  299. await page.click(getSelector(id));
  300. await page.waitForFunction(
  301. `${getQuerySelector("80R")}.value !== ""`
  302. );
  303. const text = await page.$eval(getSelector("80R"), el => el.value);
  304. expect(text).withContext(`In ${browserName}`).toEqual(expectedText);
  305. }
  306. })
  307. );
  308. });
  309. it("must show values in a text input when clicking on checkboxes or radio with no actions", async () => {
  310. await Promise.all(
  311. pages.map(async ([browserName, page]) => {
  312. const expected = [
  313. ["", "Off;Off"],
  314. ["94R", "Yes;Off"],
  315. ["95R", "Yes;NoAct2"],
  316. ["96R", "Yes;NoAct3"],
  317. ["94R", "Off;NoAct3"],
  318. ["95R", "Off;NoAct2"],
  319. ];
  320. for (const [id, expectedText] of expected) {
  321. // Clear the textfield
  322. await clearInput(page, getSelector("80R"));
  323. if (id) {
  324. await page.click(getSelector(id));
  325. }
  326. await page.click("[data-annotation-id='97R']");
  327. await page.waitForFunction(
  328. `${getQuerySelector("80R")}.value !== ""`
  329. );
  330. const text = await page.$eval(getSelector("80R"), el => el.value);
  331. expect(text).withContext(`In ${browserName}`).toEqual(expectedText);
  332. }
  333. })
  334. );
  335. });
  336. });
  337. describe("in doc_actions.pdf for printing", () => {
  338. let pages;
  339. beforeAll(async () => {
  340. pages = await loadAndWait("doc_actions.pdf", getSelector("47R"));
  341. });
  342. afterAll(async () => {
  343. await closePages(pages);
  344. });
  345. it("must execute WillPrint and DidPrint actions", async () => {
  346. await Promise.all(
  347. pages.map(async ([browserName, page]) => {
  348. if (process.platform === "win32" && browserName === "firefox") {
  349. pending("Disabled in Firefox on Windows, because of bug 1662471.");
  350. }
  351. await page.waitForFunction(
  352. "window.PDFViewerApplication.scriptingReady === true"
  353. );
  354. await clearInput(page, getSelector("47R"));
  355. await page.evaluate(_ => {
  356. window.document.activeElement.blur();
  357. });
  358. await page.waitForFunction(`${getQuerySelector("47R")}.value === ""`);
  359. let text = await actAndWaitForInput(
  360. page,
  361. getSelector("47R"),
  362. async () => {
  363. await page.click("#print");
  364. }
  365. );
  366. expect(text).withContext(`In ${browserName}`).toEqual("WillPrint");
  367. await page.waitForFunction(`${getQuerySelector("50R")}.value !== ""`);
  368. text = await page.$eval(getSelector("50R"), el => el.value);
  369. expect(text).withContext(`In ${browserName}`).toEqual("DidPrint");
  370. })
  371. );
  372. });
  373. });
  374. describe("in doc_actions.pdf for saving", () => {
  375. let pages;
  376. beforeAll(async () => {
  377. pages = await loadAndWait("doc_actions.pdf", getSelector("47R"));
  378. });
  379. afterAll(async () => {
  380. await closePages(pages);
  381. });
  382. it("must execute WillSave and DidSave actions", async () => {
  383. await Promise.all(
  384. pages.map(async ([browserName, page]) => {
  385. await page.waitForFunction(
  386. "window.PDFViewerApplication.scriptingReady === true"
  387. );
  388. try {
  389. // Disable download in chrome
  390. // (it leads to an error in firefox so the try...)
  391. await page._client.send("Page.setDownloadBehavior", {
  392. behavior: "deny",
  393. });
  394. } catch (_) {}
  395. await clearInput(page, getSelector("47R"));
  396. await page.evaluate(_ => {
  397. window.document.activeElement.blur();
  398. });
  399. await page.waitForFunction(`${getQuerySelector("47R")}.value === ""`);
  400. let text = await actAndWaitForInput(
  401. page,
  402. getSelector("47R"),
  403. async () => {
  404. await page.click("#download");
  405. }
  406. );
  407. expect(text).withContext(`In ${browserName}`).toEqual("WillSave");
  408. await page.waitForFunction(`${getQuerySelector("50R")}.value !== ""`);
  409. text = await page.$eval(getSelector("50R"), el => el.value);
  410. expect(text).withContext(`In ${browserName}`).toEqual("DidSave");
  411. })
  412. );
  413. });
  414. });
  415. describe("in doc_actions.pdf for page actions", () => {
  416. let pages;
  417. beforeAll(async () => {
  418. pages = await loadAndWait("doc_actions.pdf", getSelector("47R"));
  419. });
  420. afterAll(async () => {
  421. await closePages(pages);
  422. });
  423. it("must execute PageOpen and PageClose actions", async () => {
  424. await Promise.all(
  425. pages.map(async ([browserName, page]) => {
  426. await page.waitForFunction(
  427. "window.PDFViewerApplication.scriptingReady === true"
  428. );
  429. await page.waitForFunction(`${getQuerySelector("47R")}.value !== ""`);
  430. let text = await page.$eval(getSelector("47R"), el => el.value);
  431. expect(text).withContext(`In ${browserName}`).toEqual("PageOpen 1");
  432. for (let run = 0; run < 5; run++) {
  433. for (const ref of ["18R", "19R", "20R", "21R", "47R", "50R"]) {
  434. await page.evaluate(selector => {
  435. const element = window.document.querySelector(selector);
  436. if (element) {
  437. element.value = "";
  438. }
  439. }, getSelector(ref));
  440. }
  441. for (const [refOpen, refClose, pageNumOpen, pageNumClose] of [
  442. ["18R", "50R", 2, 1],
  443. ["21R", "19R", 3, 2],
  444. ["47R", "20R", 1, 3],
  445. ]) {
  446. text = await actAndWaitForInput(
  447. page,
  448. getSelector(refOpen),
  449. async () => {
  450. await page.evaluate(selector => {
  451. const element = window.document.querySelector(selector);
  452. element.scrollIntoView();
  453. }, getSelector(refOpen));
  454. },
  455. false
  456. );
  457. expect(text)
  458. .withContext(`In ${browserName}`)
  459. .toEqual(`PageOpen ${pageNumOpen}`);
  460. text = await page.$eval(getSelector(refClose), el => el.value);
  461. expect(text)
  462. .withContext(`In ${browserName}`)
  463. .toEqual(`PageClose ${pageNumClose}`);
  464. }
  465. }
  466. })
  467. );
  468. });
  469. });
  470. describe("in js-authors.pdf", () => {
  471. let pages;
  472. beforeAll(async () => {
  473. pages = await loadAndWait("js-authors.pdf", getSelector("25R"));
  474. });
  475. afterAll(async () => {
  476. await closePages(pages);
  477. });
  478. it("must print authors in a text field", async () => {
  479. await Promise.all(
  480. pages.map(async ([browserName, page]) => {
  481. const text = await actAndWaitForInput(
  482. page,
  483. getSelector("25R"),
  484. async () => {
  485. await page.click("[data-annotation-id='26R']");
  486. }
  487. );
  488. expect(text)
  489. .withContext(`In ${browserName}`)
  490. .toEqual("author1::author2::author3::author4::author5");
  491. })
  492. );
  493. });
  494. });
  495. describe("in listbox_actions.pdf", () => {
  496. let pages;
  497. beforeAll(async () => {
  498. pages = await loadAndWait("listbox_actions.pdf", getSelector("33R"));
  499. });
  500. afterAll(async () => {
  501. await closePages(pages);
  502. });
  503. it("must print selected value in a text field", async () => {
  504. await Promise.all(
  505. pages.map(async ([browserName, page]) => {
  506. for (const num of [7, 6, 4, 3, 2, 1]) {
  507. await clearInput(page, getSelector("33R"));
  508. await page.click(`option[value=Export${num}]`);
  509. await page.waitForFunction(
  510. `${getQuerySelector("33R")}.value !== ""`
  511. );
  512. const text = await page.$eval(getSelector("33R"), el => el.value);
  513. expect(text)
  514. .withContext(`In ${browserName}`)
  515. .toEqual(`Item${num},Export${num}`);
  516. }
  517. })
  518. );
  519. });
  520. it("must clear and restore list elements", async () => {
  521. await Promise.all(
  522. pages.map(async ([browserName, page]) => {
  523. // Click on ClearItems button.
  524. await page.click("[data-annotation-id='34R']");
  525. await page.waitForFunction(
  526. `${getQuerySelector("30R")}.children.length === 0`
  527. );
  528. // Click on Restore button.
  529. await page.click("[data-annotation-id='37R']");
  530. await page.waitForFunction(
  531. `${getQuerySelector("30R")}.children.length !== 0`
  532. );
  533. for (const num of [7, 6, 4, 3, 2, 1]) {
  534. await clearInput(page, getSelector("33R"));
  535. await page.click(`option[value=Export${num}]`);
  536. await page.waitForFunction(
  537. `${getQuerySelector("33R")}.value !== ""`
  538. );
  539. const text = await page.$eval(getSelector("33R"), el => el.value);
  540. expect(text)
  541. .withContext(`In ${browserName}`)
  542. .toEqual(`Item${num},Export${num}`);
  543. }
  544. })
  545. );
  546. });
  547. it("must insert new elements", async () => {
  548. await Promise.all(
  549. pages.map(async ([browserName, page]) => {
  550. let len = 6;
  551. for (const num of [1, 3, 5, 6, 431, -1, 0]) {
  552. ++len;
  553. await clearInput(page, getSelector("33R"));
  554. await clearInput(page, getSelector("39R"));
  555. await page.type(
  556. getSelector("39R"),
  557. `${num},Insert${num},Tresni${num}`,
  558. {
  559. delay: 10,
  560. }
  561. );
  562. // Click on AddItem button.
  563. await page.click("[data-annotation-id='38R']");
  564. await page.waitForFunction(
  565. `${getQuerySelector("30R")}.children.length === ${len}`
  566. );
  567. // Click on newly added option.
  568. await page.select(getSelector("30R"), `Tresni${num}`);
  569. await page.waitForFunction(
  570. `${getQuerySelector("33R")}.value !== ""`
  571. );
  572. const text = await page.$eval(getSelector("33R"), el => el.value);
  573. expect(text)
  574. .withContext(`In ${browserName}`)
  575. .toEqual(`Insert${num},Tresni${num}`);
  576. }
  577. })
  578. );
  579. });
  580. it("must delete some element", async () => {
  581. await Promise.all(
  582. pages.map(async ([browserName, page]) => {
  583. let len = 6;
  584. // Click on Restore button.
  585. await clearInput(page, getSelector("33R"));
  586. await page.click("[data-annotation-id='37R']");
  587. await page.waitForFunction(
  588. `${getQuerySelector("30R")}.children.length === ${len}`
  589. );
  590. for (const num of [2, 5]) {
  591. --len;
  592. await clearInput(page, getSelector("39R"));
  593. await page.type(getSelector("39R"), `${num}`);
  594. // Click on DeleteItem button.
  595. await page.click("[data-annotation-id='36R']");
  596. await page.waitForFunction(
  597. `${getQuerySelector("30R")}.children.length === ${len}`
  598. );
  599. }
  600. for (const num of [6, 4, 2, 1]) {
  601. await clearInput(page, getSelector("33R"));
  602. await page.click(`option[value=Export${num}]`);
  603. await page.waitForFunction(
  604. `${getQuerySelector("33R")}.value !== ""`
  605. );
  606. const text = await page.$eval(getSelector("33R"), el => el.value);
  607. expect(text)
  608. .withContext(`In ${browserName}`)
  609. .toEqual(`Item${num},Export${num}`);
  610. }
  611. })
  612. );
  613. });
  614. });
  615. describe("in js-colors.pdf", () => {
  616. let pages;
  617. beforeAll(async () => {
  618. pages = await loadAndWait("js-colors.pdf", getSelector("34R"));
  619. });
  620. afterAll(async () => {
  621. await closePages(pages);
  622. });
  623. it("must change colors", async () => {
  624. await Promise.all(
  625. pages.map(async ([browserName, page]) => {
  626. for (const [name, ref] of [
  627. ["Text1", "34R"],
  628. ["Check1", "35R"],
  629. ["Radio1", "37R"],
  630. ["Choice1", "38R"],
  631. ]) {
  632. await clearInput(page, getSelector("34R"));
  633. await page.type(getSelector("34R"), `${name}`, {
  634. delay: 10,
  635. });
  636. for (const [id, propName, expected] of [
  637. [41, "backgroundColor", "rgb(255, 0, 0)"],
  638. [43, "color", "rgb(0, 255, 0)"],
  639. [44, "border-top-color", "rgb(0, 0, 255)"],
  640. ]) {
  641. const current = await page.$eval(
  642. getSelector(ref),
  643. (el, _propName) => getComputedStyle(el)[_propName],
  644. propName
  645. );
  646. await page.click(`[data-annotation-id='${id}R']`);
  647. await page.waitForFunction(
  648. `${getComputedStyleSelector(
  649. ref
  650. )}["${propName}"] !== "${current}"`
  651. );
  652. const color = await page.$eval(
  653. getSelector(ref),
  654. (el, _propName) => getComputedStyle(el)[_propName],
  655. propName
  656. );
  657. expect(color).withContext(`In ${browserName}`).toEqual(expected);
  658. }
  659. }
  660. })
  661. );
  662. });
  663. });
  664. describe("in issue13132.pdf", () => {
  665. let pages;
  666. beforeAll(async () => {
  667. pages = await loadAndWait("issue13132.pdf", getSelector("171R"));
  668. });
  669. afterAll(async () => {
  670. await closePages(pages);
  671. });
  672. it("must compute sum of fields", async () => {
  673. await Promise.all(
  674. pages.map(async ([browserName, page]) => {
  675. await page.waitForFunction(
  676. "window.PDFViewerApplication.scriptingReady === true"
  677. );
  678. await page.evaluate(selector => {
  679. window.document.querySelector(selector).scrollIntoView();
  680. }, getSelector("171R"));
  681. let sum = 0;
  682. for (const [id, val] of [
  683. ["138R", 1],
  684. ["77R", 2],
  685. ["93R", 3],
  686. ["151R", 4],
  687. ["79R", 5],
  688. ]) {
  689. const prev = await page.$eval(getSelector("171R"), el => el.value);
  690. await page.type(getSelector(id), val.toString(), {
  691. delay: 100,
  692. });
  693. await page.keyboard.press("Tab");
  694. await page.waitForFunction(
  695. `${getQuerySelector("171R")}.value !== "${prev}"`
  696. );
  697. sum += val;
  698. const total = await page.$eval(getSelector("171R"), el => el.value);
  699. expect(total).withContext(`In ${browserName}`).toEqual(`£${sum}`);
  700. }
  701. // Some unrendered annotations have been updated, so check
  702. // that they've the correct value when rendered.
  703. await page.evaluate(() => {
  704. window.document
  705. .querySelectorAll('[data-page-number="4"][class="page"]')[0]
  706. .scrollIntoView();
  707. });
  708. await page.waitForSelector(getSelector("299R"), {
  709. timeout: 0,
  710. });
  711. const total = await page.$eval(getSelector("299R"), el => el.value);
  712. expect(total).withContext(`In ${browserName}`).toEqual(`£${sum}`);
  713. })
  714. );
  715. });
  716. });
  717. describe("Check field properties", () => {
  718. let pages;
  719. beforeAll(async () => {
  720. pages = await loadAndWait("evaljs.pdf", getSelector("55R"));
  721. });
  722. afterAll(async () => {
  723. await closePages(pages);
  724. });
  725. it("must check page index", async () => {
  726. await Promise.all(
  727. pages.map(async ([browserName, page]) => {
  728. await page.waitForFunction(
  729. "window.PDFViewerApplication.scriptingReady === true"
  730. );
  731. await clearInput(page, getSelector("55R"));
  732. await page.type(
  733. getSelector("55R"),
  734. `
  735. ['Text1', 'Text2', 'Text4',
  736. 'List Box7', 'Group6'].map(x => this.getField(x).page).join(',')
  737. `
  738. );
  739. // Click on execute button to eval the above code.
  740. await page.click("[data-annotation-id='57R']");
  741. await page.waitForFunction(`${getQuerySelector("56R")}.value !== ""`);
  742. const text = await page.$eval(getSelector("56R"), el => el.value);
  743. expect(text).withContext(`In ${browserName}`).toEqual("0,0,1,1,1");
  744. })
  745. );
  746. });
  747. it("must check display", async () => {
  748. await Promise.all(
  749. pages.map(async ([browserName, page]) => {
  750. for (const [type, vis] of [
  751. ["hidden", "hidden"],
  752. ["noPrint", "visible"],
  753. ["noView", "hidden"],
  754. ["visible", "visible"],
  755. ]) {
  756. let visibility = await page.$eval(
  757. getSelector("56R"),
  758. el => getComputedStyle(el).visibility
  759. );
  760. await clearInput(page, getSelector("55R"));
  761. await page.type(
  762. getSelector("55R"),
  763. `this.getField("Text2").display = display.${type};`
  764. );
  765. await page.click("[data-annotation-id='57R']");
  766. await page.waitForFunction(
  767. `${getComputedStyleSelector(
  768. "56R"
  769. )}.visibility !== "${visibility}"`
  770. );
  771. visibility = await page.$eval(
  772. getSelector("56R"),
  773. el => getComputedStyle(el).visibility
  774. );
  775. expect(visibility).withContext(`In ${browserName}`).toEqual(vis);
  776. }
  777. })
  778. );
  779. });
  780. });
  781. describe("in issue13269.pdf", () => {
  782. let pages;
  783. beforeAll(async () => {
  784. pages = await loadAndWait("issue13269.pdf", getSelector("27R"));
  785. });
  786. afterAll(async () => {
  787. await closePages(pages);
  788. });
  789. it("must update fields with the same name from JS", async () => {
  790. await Promise.all(
  791. pages.map(async ([browserName, page]) => {
  792. await page.waitForFunction(
  793. "window.PDFViewerApplication.scriptingReady === true"
  794. );
  795. await page.type(getSelector("27R"), "hello");
  796. await page.keyboard.press("Enter");
  797. await Promise.all(
  798. ["24R", "25R", "26R"].map(async id =>
  799. page.waitForFunction(`${getQuerySelector(id)}.value !== ""`)
  800. )
  801. );
  802. const expected = "hello world";
  803. for (const id of ["24R", "25R", "26R"]) {
  804. const text = await page.$eval(getSelector(id), el => el.value);
  805. expect(text).withContext(`In ${browserName}`).toEqual(expected);
  806. }
  807. })
  808. );
  809. });
  810. });
  811. describe("in secHandler.pdf", () => {
  812. let pages;
  813. beforeAll(async () => {
  814. pages = await loadAndWait("secHandler.pdf", getSelector("25R"));
  815. });
  816. afterAll(async () => {
  817. await closePages(pages);
  818. });
  819. it("must print securityHandler value in a text field", async () => {
  820. await Promise.all(
  821. pages.map(async ([browserName, page]) => {
  822. const text = await actAndWaitForInput(
  823. page,
  824. getSelector("25R"),
  825. async () => {
  826. await page.click("[data-annotation-id='26R']");
  827. }
  828. );
  829. expect(text).withContext(`In ${browserName}`).toEqual("Standard");
  830. })
  831. );
  832. });
  833. });
  834. describe("in issue14307.pdf (1)", () => {
  835. let pages;
  836. beforeAll(async () => {
  837. pages = await loadAndWait("issue14307.pdf", getSelector("30R"));
  838. pages.map(async ([, page]) => {
  839. page.on("dialog", async dialog => {
  840. await dialog.dismiss();
  841. });
  842. });
  843. });
  844. afterAll(async () => {
  845. await closePages(pages);
  846. });
  847. it("must check input for US zip format", async () => {
  848. // Run the tests sequentially to avoid any focus issues between the two
  849. // browsers when an alert is displayed.
  850. for (const [browserName, page] of pages) {
  851. await page.waitForFunction(
  852. "window.PDFViewerApplication.scriptingReady === true"
  853. );
  854. await clearInput(page, getSelector("29R"));
  855. await clearInput(page, getSelector("30R"));
  856. await page.focus(getSelector("29R"));
  857. await page.type(getSelector("29R"), "12A", { delay: 100 });
  858. await page.waitForFunction(
  859. `${getQuerySelector("29R")}.value !== "12A"`
  860. );
  861. let text = await page.$eval(getSelector(`29R`), el => el.value);
  862. expect(text).withContext(`In ${browserName}`).toEqual("12");
  863. await page.focus(getSelector("29R"));
  864. await page.type(getSelector("29R"), "34", { delay: 100 });
  865. await page.click("[data-annotation-id='30R']");
  866. await page.waitForFunction(
  867. `${getQuerySelector("29R")}.value !== "1234"`
  868. );
  869. text = await page.$eval(getSelector(`29R`), el => el.value);
  870. expect(text).withContext(`In ${browserName}`).toEqual("");
  871. await page.focus(getSelector("29R"));
  872. await page.type(getSelector("29R"), "12345", { delay: 100 });
  873. await page.click("[data-annotation-id='30R']");
  874. text = await page.$eval(getSelector(`29R`), el => el.value);
  875. expect(text).withContext(`In ${browserName}`).toEqual("12345");
  876. }
  877. });
  878. });
  879. describe("in issue14307.pdf (2)", () => {
  880. let pages;
  881. beforeAll(async () => {
  882. pages = await loadAndWait("issue14307.pdf", getSelector("30R"));
  883. pages.map(async ([, page]) => {
  884. page.on("dialog", async dialog => {
  885. await dialog.dismiss();
  886. });
  887. });
  888. });
  889. afterAll(async () => {
  890. await closePages(pages);
  891. });
  892. it("must check input for US phone number (long) format", async () => {
  893. // Run the tests sequentially to avoid any focus issues between the two
  894. // browsers when an alert is displayed.
  895. for (const [browserName, page] of pages) {
  896. await page.waitForFunction(
  897. "window.PDFViewerApplication.scriptingReady === true"
  898. );
  899. await clearInput(page, getSelector("29R"));
  900. await clearInput(page, getSelector("30R"));
  901. await page.focus(getSelector("30R"));
  902. await page.type(getSelector("30R"), "(123) 456A", { delay: 100 });
  903. await page.waitForFunction(
  904. `${getQuerySelector("30R")}.value !== "(123) 456A"`
  905. );
  906. let text = await page.$eval(getSelector(`30R`), el => el.value);
  907. expect(text).withContext(`In ${browserName}`).toEqual("(123) 456");
  908. await page.focus(getSelector("30R"));
  909. await page.type(getSelector("30R"), "-789", { delay: 100 });
  910. await page.click("[data-annotation-id='29R']");
  911. await page.waitForFunction(
  912. `${getQuerySelector("30R")}.value !== "(123) 456-789"`
  913. );
  914. text = await page.$eval(getSelector(`30R`), el => el.value);
  915. expect(text).withContext(`In ${browserName}`).toEqual("");
  916. await page.focus(getSelector("30R"));
  917. await page.type(getSelector("30R"), "(123) 456-7890", { delay: 100 });
  918. await page.click("[data-annotation-id='29R']");
  919. text = await page.$eval(getSelector("30R"), el => el.value);
  920. expect(text).withContext(`In ${browserName}`).toEqual("(123) 456-7890");
  921. }
  922. });
  923. });
  924. describe("in issue14307.pdf (3)", () => {
  925. let pages;
  926. beforeAll(async () => {
  927. pages = await loadAndWait("issue14307.pdf", getSelector("30R"));
  928. pages.map(async ([, page]) => {
  929. page.on("dialog", async dialog => {
  930. await dialog.dismiss();
  931. });
  932. });
  933. });
  934. afterAll(async () => {
  935. await closePages(pages);
  936. });
  937. it("must check input for US phone number (short) format", async () => {
  938. // Run the tests sequentially to avoid any focus issues between the two
  939. // browsers when an alert is displayed.
  940. for (const [browserName, page] of pages) {
  941. await page.waitForFunction(
  942. "window.PDFViewerApplication.scriptingReady === true"
  943. );
  944. await clearInput(page, getSelector("29R"));
  945. await clearInput(page, getSelector("30R"));
  946. await page.focus(getSelector("30R"));
  947. await page.type(getSelector("30R"), "123A", { delay: 100 });
  948. await page.waitForFunction(
  949. `${getQuerySelector("30R")}.value !== "123A"`
  950. );
  951. let text = await page.$eval(getSelector(`30R`), el => el.value);
  952. expect(text).withContext(`In ${browserName}`).toEqual("123");
  953. await page.focus(getSelector("30R"));
  954. await page.type(getSelector("30R"), "-456", { delay: 100 });
  955. await page.click("[data-annotation-id='29R']");
  956. await page.waitForFunction(
  957. `${getQuerySelector("30R")}.value !== "123-456"`
  958. );
  959. text = await page.$eval(getSelector("30R"), el => el.value);
  960. expect(text).withContext(`In ${browserName}`).toEqual("");
  961. await page.focus(getSelector("30R"));
  962. await page.type(getSelector("30R"), "123-4567", { delay: 100 });
  963. await page.click("[data-annotation-id='29R']");
  964. text = await page.$eval(getSelector("30R"), el => el.value);
  965. expect(text).withContext(`In ${browserName}`).toEqual("123-4567");
  966. }
  967. });
  968. });
  969. describe("in issue14862.pdf", () => {
  970. let pages;
  971. beforeAll(async () => {
  972. pages = await loadAndWait("issue14862.pdf", getSelector("27R"));
  973. pages.map(async ([, page]) => {
  974. page.on("dialog", async dialog => {
  975. await dialog.dismiss();
  976. });
  977. });
  978. });
  979. afterAll(async () => {
  980. await closePages(pages);
  981. });
  982. it("must convert input to uppercase", async () => {
  983. await Promise.all(
  984. pages.map(async ([browserName, page]) => {
  985. await page.waitForFunction(
  986. "window.PDFViewerApplication.scriptingReady === true"
  987. );
  988. await page.type(getSelector("27R"), "Hello", { delay: 100 });
  989. await page.waitForFunction(
  990. `${getQuerySelector("27R")}.value !== "Hello"`
  991. );
  992. let text = await page.$eval(getSelector("27R"), el => el.value);
  993. expect(text).withContext(`In ${browserName}`).toEqual("HELLO");
  994. await page.type(getSelector("27R"), " world", { delay: 100 });
  995. await page.waitForFunction(
  996. `${getQuerySelector("27R")}.value !== "HELLO world"`
  997. );
  998. text = await page.$eval(getSelector("27R"), el => el.value);
  999. expect(text).withContext(`In ${browserName}`).toEqual("HELLO WORLD");
  1000. await page.keyboard.press("Backspace");
  1001. await page.keyboard.press("Backspace");
  1002. await page.waitForFunction(
  1003. `${getQuerySelector("27R")}.value !== "HELLO WORLD"`
  1004. );
  1005. text = await page.$eval(getSelector("27R"), el => el.value);
  1006. expect(text).withContext(`In ${browserName}`).toEqual("HELLO WOR");
  1007. await page.type(getSelector("27R"), "12.dL", { delay: 100 });
  1008. await page.waitForFunction(
  1009. `${getQuerySelector("27R")}.value !== "HELLO WOR"`
  1010. );
  1011. text = await page.$eval(getSelector("27R"), el => el.value);
  1012. expect(text).withContext(`In ${browserName}`).toEqual("HELLO WORDL");
  1013. await page.type(getSelector("27R"), " ", { delay: 100 });
  1014. await page.keyboard.down("Control");
  1015. await page.keyboard.press("Backspace");
  1016. await page.keyboard.up("Control");
  1017. await page.waitForFunction(
  1018. `${getQuerySelector("27R")}.value !== "HELLO WORDL "`
  1019. );
  1020. text = await page.$eval(getSelector("27R"), el => el.value);
  1021. expect(text).withContext(`In ${browserName}`).toEqual("HELLO ");
  1022. await page.$eval(getSelector("27R"), el => {
  1023. // Select LL
  1024. el.selectionStart = 2;
  1025. el.selectionEnd = 4;
  1026. });
  1027. await page.keyboard.press("a");
  1028. text = await page.$eval(getSelector("27R"), el => el.value);
  1029. expect(text).withContext(`In ${browserName}`).toEqual("HEAO ");
  1030. })
  1031. );
  1032. });
  1033. it("must check that an infinite loop is not triggered", async () => {
  1034. await Promise.all(
  1035. pages.map(async ([browserName, page]) => {
  1036. await page.waitForFunction(
  1037. "window.PDFViewerApplication.scriptingReady === true"
  1038. );
  1039. await page.click(getSelector("28R"));
  1040. await page.$eval(getSelector("28R"), el =>
  1041. el.setSelectionRange(0, 0)
  1042. );
  1043. await page.type(getSelector("28R"), "Hello", { delay: 100 });
  1044. await page.waitForFunction(
  1045. `${getQuerySelector("28R")}.value !== "123"`
  1046. );
  1047. let text = await page.$eval(getSelector("28R"), el => el.value);
  1048. expect(text).withContext(`In ${browserName}`).toEqual("Hello123");
  1049. // The action will trigger a calculateNow which itself
  1050. // will trigger a resetForm (inducing a calculateNow) and a
  1051. // calculateNow.
  1052. await page.click("[data-annotation-id='31R']");
  1053. await page.waitForFunction(
  1054. `${getQuerySelector("28R")}.value !== "Hello123"`
  1055. );
  1056. // Without preventing against infinite loop the field is empty.
  1057. text = await page.$eval(getSelector("28R"), el => el.value);
  1058. expect(text).withContext(`In ${browserName}`).toEqual("123");
  1059. })
  1060. );
  1061. });
  1062. });
  1063. describe("in issue14705.pdf", () => {
  1064. let pages;
  1065. beforeAll(async () => {
  1066. pages = await loadAndWait("issue14705.pdf", getSelector("29R"));
  1067. pages.map(async ([, page]) => {
  1068. page.on("dialog", async dialog => {
  1069. await dialog.dismiss();
  1070. });
  1071. });
  1072. });
  1073. afterAll(async () => {
  1074. await closePages(pages);
  1075. });
  1076. it("must check that field value is correctly updated", async () => {
  1077. await Promise.all(
  1078. pages.map(async ([browserName, page]) => {
  1079. await page.waitForFunction(
  1080. "window.PDFViewerApplication.scriptingReady === true"
  1081. );
  1082. await page.type(getSelector("29R"), "Hello World", { delay: 100 });
  1083. await page.click(getSelector("27R"));
  1084. await page.waitForFunction(
  1085. `${getQuerySelector("29R")}.value !== "Hello World"`
  1086. );
  1087. let text = await page.$eval(getSelector("29R"), el => el.value);
  1088. expect(text).withContext(`In ${browserName}`).toEqual("checked");
  1089. await page.click(getSelector("27R"));
  1090. await page.waitForFunction(
  1091. `${getQuerySelector("29R")}.value !== "checked"`
  1092. );
  1093. text = await page.$eval(getSelector("29R"), el => el.value);
  1094. expect(text).withContext(`In ${browserName}`).toEqual("unchecked");
  1095. })
  1096. );
  1097. });
  1098. });
  1099. describe("in bug1766987.pdf", () => {
  1100. let pages;
  1101. beforeAll(async () => {
  1102. pages = await loadAndWait("bug1766987.pdf", getSelector("75R"));
  1103. });
  1104. afterAll(async () => {
  1105. await closePages(pages);
  1106. });
  1107. it("must check that field value is correctly formatted", async () => {
  1108. await Promise.all(
  1109. pages.map(async ([browserName, page]) => {
  1110. await page.waitForFunction(
  1111. "window.PDFViewerApplication.scriptingReady === true"
  1112. );
  1113. let text = await page.$eval(getSelector("75R"), el => el.value);
  1114. expect(text).withContext(`In ${browserName}`).toEqual("150.32 €");
  1115. text = await page.$eval(getSelector("82R"), el => el.value);
  1116. expect(text).withContext(`In ${browserName}`).toEqual("12.74 Kwh");
  1117. text = await page.$eval(getSelector("91R"), el => el.value);
  1118. expect(text).withContext(`In ${browserName}`).toEqual("352.19 Kwh");
  1119. text = await page.$eval(getSelector("101R"), el => el.value);
  1120. expect(text).withContext(`In ${browserName}`).toEqual("20.57 €");
  1121. })
  1122. );
  1123. });
  1124. });
  1125. describe("in issue15053.pdf", () => {
  1126. let pages;
  1127. beforeAll(async () => {
  1128. pages = await loadAndWait("issue15053.pdf", getSelector("44R"));
  1129. });
  1130. afterAll(async () => {
  1131. await closePages(pages);
  1132. });
  1133. it("must check that a button and text field with a border are hidden", async () => {
  1134. await Promise.all(
  1135. pages.map(async ([browserName, page]) => {
  1136. await page.waitForFunction(
  1137. "window.PDFViewerApplication.scriptingReady === true"
  1138. );
  1139. let visibility = await page.$eval(
  1140. "[data-annotation-id='35R']",
  1141. el => getComputedStyle(el).visibility
  1142. );
  1143. expect(visibility)
  1144. .withContext(`In ${browserName}`)
  1145. .toEqual("visible");
  1146. visibility = await page.$eval(
  1147. "[data-annotation-id='51R']",
  1148. el => getComputedStyle(el).visibility
  1149. );
  1150. expect(visibility)
  1151. .withContext(`In ${browserName}`)
  1152. .toEqual("visible");
  1153. await page.click(getSelector("44R"));
  1154. visibility = await page.$eval(
  1155. "[data-annotation-id='35R']",
  1156. el => getComputedStyle(el).visibility
  1157. );
  1158. expect(visibility).withContext(`In ${browserName}`).toEqual("hidden");
  1159. visibility = await page.$eval(
  1160. "[data-annotation-id='51R']",
  1161. el => getComputedStyle(el).visibility
  1162. );
  1163. expect(visibility).withContext(`In ${browserName}`).toEqual("hidden");
  1164. })
  1165. );
  1166. });
  1167. });
  1168. describe("in bug1675139.pdf", () => {
  1169. let pages;
  1170. beforeAll(async () => {
  1171. pages = await loadAndWait("bug1675139.pdf", getSelector("48R"));
  1172. });
  1173. afterAll(async () => {
  1174. await closePages(pages);
  1175. });
  1176. it("must check that data-main-rotation is correct", async () => {
  1177. await Promise.all(
  1178. pages.map(async ([browserName, page]) => {
  1179. await page.waitForFunction(
  1180. "window.PDFViewerApplication.scriptingReady === true"
  1181. );
  1182. let base = 0;
  1183. while (base !== 360) {
  1184. for (const [ref, angle] of [
  1185. [47, 0],
  1186. [42, 90],
  1187. [45, 180],
  1188. [46, 270],
  1189. ]) {
  1190. await page.waitForFunction(
  1191. (sel, b, a) => {
  1192. const el = document.querySelector(sel);
  1193. const rotation =
  1194. parseInt(el.getAttribute("data-main-rotation")) || 0;
  1195. return rotation === (360 + ((360 - (b + a)) % 360)) % 360;
  1196. },
  1197. {},
  1198. `[data-annotation-id='${ref}R']`,
  1199. base,
  1200. angle
  1201. );
  1202. }
  1203. base += 90;
  1204. await page.click(getSelector("48R"));
  1205. }
  1206. })
  1207. );
  1208. });
  1209. });
  1210. describe("in issue15092.pdf", () => {
  1211. let pages;
  1212. beforeAll(async () => {
  1213. pages = await loadAndWait("issue15092.pdf", getSelector("39R"));
  1214. });
  1215. afterAll(async () => {
  1216. await closePages(pages);
  1217. });
  1218. it("must check that a values is correctly updated on a field and its siblings", async () => {
  1219. await Promise.all(
  1220. pages.map(async ([browserName, page]) => {
  1221. await page.waitForFunction(
  1222. "window.PDFViewerApplication.scriptingReady === true"
  1223. );
  1224. await clearInput(page, getSelector("39R"));
  1225. await page.type(getSelector("39R"), "123", { delay: 10 });
  1226. const prevTotal = await page.$eval(
  1227. getSelector("43R"),
  1228. el => el.value
  1229. );
  1230. await clearInput(page, getSelector("42R"));
  1231. await page.type(getSelector("42R"), "456", { delay: 10 });
  1232. await page.click(getSelector("45R"));
  1233. await page.waitForFunction(
  1234. `${getQuerySelector("43R")}.value !== "${prevTotal}"`
  1235. );
  1236. await page.waitForFunction(
  1237. `${getQuerySelector("46R")}.value !== "${prevTotal}"`
  1238. );
  1239. let total = await page.$eval(getSelector("43R"), el => el.value);
  1240. expect(total).withContext(`In ${browserName}`).toEqual("579.00");
  1241. total = await page.$eval(getSelector("46R"), el => el.value);
  1242. expect(total).withContext(`In ${browserName}`).toEqual("579.00");
  1243. })
  1244. );
  1245. });
  1246. });
  1247. describe("in bug1782564.pdf", () => {
  1248. let pages;
  1249. beforeAll(async () => {
  1250. pages = await loadAndWait("bug1782564.pdf", getSelector("7R"));
  1251. });
  1252. afterAll(async () => {
  1253. await closePages(pages);
  1254. });
  1255. it("must check that charLimit is correctly set", async () => {
  1256. await Promise.all(
  1257. pages.map(async ([browserName, page]) => {
  1258. await page.waitForFunction(
  1259. "window.PDFViewerApplication.scriptingReady === true"
  1260. );
  1261. await clearInput(page, getSelector("7R"));
  1262. // By default the charLimit is 0 which means that the input
  1263. // length is unlimited.
  1264. await page.type(getSelector("7R"), "abcdefghijklmnopq", {
  1265. delay: 10,
  1266. });
  1267. let value = await page.$eval(getSelector("7R"), el => el.value);
  1268. expect(value)
  1269. .withContext(`In ${browserName}`)
  1270. .toEqual("abcdefghijklmnopq");
  1271. // charLimit is set to 1
  1272. await page.click(getSelector("9R"));
  1273. await page.waitForFunction(
  1274. `document.querySelector('${getSelector(
  1275. "7R"
  1276. )}').value !== "abcdefgh"`
  1277. );
  1278. value = await page.$eval(getSelector("7R"), el => el.value);
  1279. expect(value).withContext(`In ${browserName}`).toEqual("a");
  1280. await clearInput(page, getSelector("7R"));
  1281. await page.type(getSelector("7R"), "xyz", { delay: 10 });
  1282. value = await page.$eval(getSelector("7R"), el => el.value);
  1283. expect(value).withContext(`In ${browserName}`).toEqual("x");
  1284. // charLimit is set to 2
  1285. await page.click(getSelector("9R"));
  1286. await clearInput(page, getSelector("7R"));
  1287. await page.type(getSelector("7R"), "xyz", { delay: 10 });
  1288. value = await page.$eval(getSelector("7R"), el => el.value);
  1289. expect(value).withContext(`In ${browserName}`).toEqual("xy");
  1290. })
  1291. );
  1292. });
  1293. });
  1294. describe("in bug1802888.pdf", () => {
  1295. let pages;
  1296. beforeAll(async () => {
  1297. pages = await loadAndWait("bug1802888.pdf", getSelector("30R"));
  1298. });
  1299. afterAll(async () => {
  1300. await closePages(pages);
  1301. });
  1302. it("must check field value is treated by default as a number", async () => {
  1303. await Promise.all(
  1304. pages.map(async ([browserName, page]) => {
  1305. await page.waitForFunction(
  1306. "window.PDFViewerApplication.scriptingReady === true"
  1307. );
  1308. await page.type(getSelector("30R"), "123", {
  1309. delay: 10,
  1310. });
  1311. await page.click(getSelector("31R"));
  1312. await page.type(getSelector("31R"), "456", {
  1313. delay: 10,
  1314. });
  1315. await page.click(getSelector("26R"));
  1316. await page.click(getSelector("27R"));
  1317. await page.waitForFunction(`${getQuerySelector("26R")}.value !== ""`);
  1318. const value = await page.$eval(getSelector("26R"), el => el.value);
  1319. expect(value).withContext(`In ${browserName}`).toEqual("579");
  1320. })
  1321. );
  1322. });
  1323. });
  1324. describe("in issue15753.pdf", () => {
  1325. let pages;
  1326. beforeAll(async () => {
  1327. pages = await loadAndWait("issue15753.pdf", getSelector("27R"));
  1328. });
  1329. afterAll(async () => {
  1330. await closePages(pages);
  1331. });
  1332. it("must check field value is correctly updated when committed with ENTER key", async () => {
  1333. await Promise.all(
  1334. pages.map(async ([browserName, page]) => {
  1335. await page.waitForFunction(
  1336. "window.PDFViewerApplication.scriptingReady === true"
  1337. );
  1338. await page.type(getSelector("27R"), "abc", {
  1339. delay: 10,
  1340. });
  1341. await page.keyboard.press("Enter");
  1342. await page.waitForFunction(`${getQuerySelector("28R")}.value !== ""`);
  1343. let value = await page.$eval(getSelector("28R"), el => el.value);
  1344. expect(value).withContext(`In ${browserName}`).toEqual("abc");
  1345. await page.type(getSelector("27R"), "def", {
  1346. delay: 10,
  1347. });
  1348. await page.keyboard.press("Enter");
  1349. await page.waitForFunction(
  1350. `${getQuerySelector("28R")}.value !== "abc"`
  1351. );
  1352. value = await page.$eval(getSelector("28R"), el => el.value);
  1353. expect(value).withContext(`In ${browserName}`).toEqual("abcdef");
  1354. await page.keyboard.down("Control");
  1355. await page.keyboard.press("A");
  1356. await page.keyboard.up("Control");
  1357. await page.keyboard.press("Backspace");
  1358. await page.keyboard.press("Enter");
  1359. await page.waitForFunction(
  1360. `${getQuerySelector("28R")}.value !== "abcdef"`
  1361. );
  1362. value = await page.$eval(getSelector("28R"), el => el.value);
  1363. expect(value).withContext(`In ${browserName}`).toEqual("");
  1364. })
  1365. );
  1366. });
  1367. });
  1368. describe("in issue15815.pdf", () => {
  1369. let pages;
  1370. beforeAll(async () => {
  1371. pages = await loadAndWait("issue15815.pdf", getSelector("24R"));
  1372. });
  1373. afterAll(async () => {
  1374. await closePages(pages);
  1375. });
  1376. it("must check field value is correctly updated when committed with ENTER key", async () => {
  1377. await Promise.all(
  1378. pages.map(async ([browserName, page]) => {
  1379. await page.waitForFunction(
  1380. "window.PDFViewerApplication.scriptingReady === true"
  1381. );
  1382. let value = "A";
  1383. for (const [displayValue, exportValue] of [
  1384. ["B", "x2"],
  1385. ["C", "x3"],
  1386. ["A", "x1"],
  1387. ]) {
  1388. await clearInput(page, getSelector("27R"));
  1389. await page.select(getSelector("24R"), exportValue);
  1390. await page.waitForFunction(
  1391. `${getQuerySelector("27R")}.value !== ""`
  1392. );
  1393. const text = await page.$eval(getSelector("27R"), el => el.value);
  1394. expect(text)
  1395. .withContext(`In ${browserName}`)
  1396. .toEqual(`value=${value}, changeEx=${exportValue}`);
  1397. value = displayValue;
  1398. }
  1399. for (const exportValue of ["x3", "x2", "x1"]) {
  1400. await clearInput(page, getSelector("27R"));
  1401. await page.type(getSelector("27R"), exportValue);
  1402. await page.click("[data-annotation-id='28R']");
  1403. await page.waitForTimeout(10);
  1404. value = await page.$eval(getSelector("24R"), el => el.value);
  1405. expect(value).withContext(`In ${browserName}`).toEqual(exportValue);
  1406. }
  1407. })
  1408. );
  1409. });
  1410. });
  1411. describe("in issue15818.pdf", () => {
  1412. let pages;
  1413. beforeAll(async () => {
  1414. pages = await loadAndWait("issue15818.pdf", getSelector("27R"));
  1415. });
  1416. afterAll(async () => {
  1417. await closePages(pages);
  1418. });
  1419. it("must check the field value set when the document is open", async () => {
  1420. await Promise.all(
  1421. pages.map(async ([browserName, page]) => {
  1422. await page.waitForFunction(
  1423. "window.PDFViewerApplication.scriptingReady === true"
  1424. );
  1425. await page.waitForFunction(`${getQuerySelector("27R")}.value !== ""`);
  1426. const text = await page.$eval(getSelector("27R"), el => el.value);
  1427. expect(text).withContext(`In ${browserName}`).toEqual("hello world");
  1428. })
  1429. );
  1430. });
  1431. it("must check the format action is called when setFocus is used", async () => {
  1432. await Promise.all(
  1433. pages.map(async ([browserName, page]) => {
  1434. await page.waitForFunction(
  1435. "window.PDFViewerApplication.scriptingReady === true"
  1436. );
  1437. await page.type(getSelector("30R"), "abc");
  1438. await page.waitForFunction(
  1439. `${getQuerySelector("30R")}.value !== "abc"`
  1440. );
  1441. await page.waitForTimeout(10);
  1442. const focusedId = await page.evaluate(_ =>
  1443. window.document.activeElement.getAttribute("data-element-id")
  1444. );
  1445. expect(focusedId).withContext(`In ${browserName}`).toEqual("31R");
  1446. })
  1447. );
  1448. });
  1449. });
  1450. });