xfa_tohtml_spec.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2022 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * JavaScript code in this page
  21. */
  22. "use strict";
  23. var _is_node = require("../../shared/is_node.js");
  24. var _factory = require("../../core/xfa/factory.js");
  25. describe("XFAFactory", function () {
  26. function searchHtmlNode(root, name, value, byAttributes = false, nth = [0]) {
  27. if (!byAttributes && root[name] === value || byAttributes && root.attributes && root.attributes[name] === value) {
  28. if (nth[0]-- === 0) {
  29. return root;
  30. }
  31. }
  32. if (!root.children) {
  33. return null;
  34. }
  35. for (const child of root.children) {
  36. const node = searchHtmlNode(child, name, value, byAttributes, nth);
  37. if (node) {
  38. return node;
  39. }
  40. }
  41. return null;
  42. }
  43. describe("toHTML", function () {
  44. it("should convert some basic properties to CSS", async () => {
  45. const xml = `
  46. <?xml version="1.0"?>
  47. <xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
  48. <template xmlns="http://www.xfa.org/schema/xfa-template/3.3">
  49. <subform name="root" mergeMode="matchTemplate">
  50. <pageSet>
  51. <pageArea>
  52. <contentArea x="123pt" w="456pt" h="789pt"/>
  53. <medium stock="default" short="456pt" long="789pt"/>
  54. <draw y="1pt" w="11pt" h="22pt" rotate="90" x="2pt">
  55. <assist><toolTip>A tooltip !!</toolTip></assist>
  56. <font size="7pt" typeface="FooBar" baselineShift="2pt">
  57. <fill>
  58. <color value="12,23,34"/>
  59. <solid/>
  60. </fill>
  61. </font>
  62. <value/>
  63. <margin topInset="1pt" bottomInset="2pt" leftInset="3pt" rightInset="4pt"/>
  64. <para spaceAbove="1pt" spaceBelow="2pt" textIndent="3pt" marginLeft="4pt" marginRight="5pt"/>
  65. </draw>
  66. </pageArea>
  67. </pageSet>
  68. <subform name="second">
  69. <breakBefore targetType="pageArea" startNew="1"/>
  70. <subform>
  71. <draw w="1pt" h="1pt"><value><text>foo</text></value></draw>
  72. </subform>
  73. </subform>
  74. <subform name="third">
  75. <breakBefore targetType="pageArea" startNew="1"/>
  76. <subform>
  77. <draw w="1pt" h="1pt"><value><text>bar</text></value></draw>
  78. </subform>
  79. </subform>
  80. </subform>
  81. </template>
  82. <xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
  83. <xfa:data>
  84. </xfa:data>
  85. </xfa:datasets>
  86. </xdp:xdp>
  87. `;
  88. const factory = new _factory.XFAFactory({
  89. "xdp:xdp": xml
  90. });
  91. factory.setFonts([]);
  92. expect(await factory.getNumPages()).toEqual(2);
  93. const pages = await factory.getPages();
  94. const page1 = pages.children[0];
  95. expect(page1.attributes.style).toEqual({
  96. height: "789px",
  97. width: "456px"
  98. });
  99. expect(page1.children.length).toEqual(2);
  100. const container = page1.children[1];
  101. expect(container.attributes.class).toEqual(["xfaContentarea"]);
  102. expect(container.attributes.style).toEqual({
  103. height: "789px",
  104. width: "456px",
  105. left: "123px",
  106. top: "0px"
  107. });
  108. const wrapper = page1.children[0];
  109. const draw = wrapper.children[0];
  110. expect(wrapper.attributes.class).toEqual(["xfaWrapper"]);
  111. expect(wrapper.attributes.style).toEqual({
  112. alignSelf: "start",
  113. height: "22px",
  114. left: "2px",
  115. position: "absolute",
  116. top: "1px",
  117. transform: "rotate(-90deg)",
  118. transformOrigin: "top left",
  119. width: "11px"
  120. });
  121. expect(draw.attributes.class).toEqual(["xfaDraw", "xfaFont", "xfaWrapped"]);
  122. expect(draw.attributes.title).toEqual("A tooltip !!");
  123. expect(draw.attributes.style).toEqual({
  124. color: "#0c1722",
  125. fontFamily: '"FooBar"',
  126. fontKerning: "none",
  127. letterSpacing: "0px",
  128. fontStyle: "normal",
  129. fontWeight: "normal",
  130. fontSize: "6.93px",
  131. padding: "1px 4px 2px 3px",
  132. verticalAlign: "2px"
  133. });
  134. expect(draw.attributes.style).toEqual(pages.children[1].children[0].children[0].attributes.style);
  135. });
  136. it("should have an alt attribute from toolTip", async () => {
  137. if (_is_node.isNodeJS) {
  138. pending("Image is not supported in Node.js.");
  139. }
  140. const xml = `
  141. <?xml version="1.0"?>
  142. <xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
  143. <template xmlns="http://www.xfa.org/schema/xfa-template/3.3">
  144. <subform name="root" mergeMode="matchTemplate">
  145. <pageSet>
  146. <pageArea>
  147. <contentArea x="0pt" w="456pt" h="789pt"/>
  148. <draw name="BA-Logo" y="5.928mm" x="128.388mm" w="71.237mm" h="9.528mm">
  149. <value>
  150. <image contentType="image/png">iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQYV2NgYAAAAAMAAWgmWQ0AAAAASUVORK5CYII=</image>
  151. </value>
  152. <assist><toolTip>alt text</toolTip></assist>
  153. </draw>
  154. </pageArea>
  155. </pageSet>
  156. </subform>
  157. </template>
  158. <xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
  159. <xfa:data>
  160. </xfa:data>
  161. </xfa:datasets>
  162. </xdp:xdp>
  163. `;
  164. const factory = new _factory.XFAFactory({
  165. "xdp:xdp": xml
  166. });
  167. expect(await factory.getNumPages()).toEqual(1);
  168. const pages = await factory.getPages();
  169. const field = searchHtmlNode(pages, "name", "img");
  170. expect(field.attributes.alt).toEqual("alt text");
  171. });
  172. it("should have a aria heading role and level", async () => {
  173. const xml = `
  174. <?xml version="1.0"?>
  175. <xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
  176. <template xmlns="http://www.xfa.org/schema/xfa-template/3.3">
  177. <subform name="root" mergeMode="matchTemplate">
  178. <pageSet>
  179. <pageArea>
  180. <contentArea x="0pt" w="456pt" h="789pt"/>
  181. <medium stock="default" short="456pt" long="789pt"/>
  182. <draw name="BA-Logo" y="5.928mm" x="128.388mm" w="71.237mm" h="9.528mm">
  183. <value><text>foo</text></value>
  184. <assist role="H2"></assist>
  185. </draw>
  186. </pageArea>
  187. </pageSet>
  188. </subform>
  189. </template>
  190. <xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
  191. <xfa:data>
  192. </xfa:data>
  193. </xfa:datasets>
  194. </xdp:xdp>
  195. `;
  196. const factory = new _factory.XFAFactory({
  197. "xdp:xdp": xml
  198. });
  199. expect(await factory.getNumPages()).toEqual(1);
  200. const pages = await factory.getPages();
  201. const page1 = pages.children[0];
  202. const wrapper = page1.children[0];
  203. const draw = wrapper.children[0];
  204. expect(draw.attributes.role).toEqual("heading");
  205. expect(draw.attributes["aria-level"]).toEqual("2");
  206. });
  207. it("should have aria table role", async () => {
  208. const xml = `
  209. <?xml version="1.0"?>
  210. <xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
  211. <template xmlns="http://www.xfa.org/schema/xfa-template/3.3">
  212. <subform name="root" mergeMode="matchTemplate">
  213. <pageSet>
  214. <pageArea>
  215. <contentArea x="0pt" w="456pt" h="789pt"/>
  216. <medium stock="default" short="456pt" long="789pt"/>
  217. <font size="7pt" typeface="FooBar" baselineShift="2pt">
  218. </font>
  219. </pageArea>
  220. </pageSet>
  221. <subform name="table" mergeMode="matchTemplate" layout="table">
  222. <subform layout="row" name="row1">
  223. <assist role="TH"></assist>
  224. <draw name="header1" y="5.928mm" x="128.388mm" w="71.237mm" h="9.528mm">
  225. <value><text>Header Col 1</text></value>
  226. </draw>
  227. <draw name="header2" y="5.928mm" x="128.388mm" w="71.237mm" h="9.528mm">
  228. <value><text>Header Col 2</text></value>
  229. </draw>
  230. </subform>
  231. <subform layout="row" name="row2">
  232. <draw name="cell1" y="5.928mm" x="128.388mm" w="71.237mm" h="9.528mm">
  233. <value><text>Cell 1</text></value>
  234. </draw>
  235. <draw name="cell2" y="5.928mm" x="128.388mm" w="71.237mm" h="9.528mm">
  236. <value><text>Cell 2</text></value>
  237. </draw>
  238. </subform>
  239. </subform>
  240. </subform>
  241. </template>
  242. <xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
  243. <xfa:data>
  244. </xfa:data>
  245. </xfa:datasets>
  246. </xdp:xdp>
  247. `;
  248. const factory = new _factory.XFAFactory({
  249. "xdp:xdp": xml
  250. });
  251. factory.setFonts([]);
  252. expect(await factory.getNumPages()).toEqual(1);
  253. const pages = await factory.getPages();
  254. const table = searchHtmlNode(pages, "xfaName", "table", true);
  255. expect(table.attributes.role).toEqual("table");
  256. const headerRow = searchHtmlNode(pages, "xfaName", "row1", true);
  257. expect(headerRow.attributes.role).toEqual("row");
  258. const headerCell = searchHtmlNode(pages, "xfaName", "header2", true);
  259. expect(headerCell.attributes.role).toEqual("columnheader");
  260. const row = searchHtmlNode(pages, "xfaName", "row2", true);
  261. expect(row.attributes.role).toEqual("row");
  262. const cell = searchHtmlNode(pages, "xfaName", "cell2", true);
  263. expect(cell.attributes.role).toEqual("cell");
  264. });
  265. it("should have a maxLength property", async () => {
  266. const xml = `
  267. <?xml version="1.0"?>
  268. <xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
  269. <template xmlns="http://www.xfa.org/schema/xfa-template/3.3">
  270. <subform name="root" mergeMode="matchTemplate">
  271. <pageSet>
  272. <pageArea>
  273. <contentArea x="0pt" w="456pt" h="789pt"/>
  274. <medium stock="default" short="456pt" long="789pt"/>
  275. <field y="1pt" w="11pt" h="22pt" x="2pt">
  276. <ui>
  277. <textEdit multiLine="0"/>
  278. </ui>
  279. <value>
  280. <text maxChars="123"/>
  281. </value>
  282. </field>
  283. </pageArea>
  284. </pageSet>
  285. <subform name="first">
  286. <draw w="1pt" h="1pt"><value><text>foo</text></value></draw>
  287. </subform>
  288. </subform>
  289. </template>
  290. <xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
  291. <xfa:data>
  292. </xfa:data>
  293. </xfa:datasets>
  294. </xdp:xdp>
  295. `;
  296. const factory = new _factory.XFAFactory({
  297. "xdp:xdp": xml
  298. });
  299. expect(await factory.getNumPages()).toEqual(1);
  300. const pages = await factory.getPages();
  301. const field = searchHtmlNode(pages, "name", "input");
  302. expect(field.attributes.maxLength).toEqual(123);
  303. });
  304. it("should have an aria-label property from speak", async () => {
  305. const xml = `
  306. <?xml version="1.0"?>
  307. <xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
  308. <template xmlns="http://www.xfa.org/schema/xfa-template/3.3">
  309. <subform name="root" mergeMode="matchTemplate">
  310. <pageSet>
  311. <pageArea>
  312. <contentArea x="0pt" w="456pt" h="789pt"/>
  313. <medium stock="default" short="456pt" long="789pt"/>
  314. <field y="1pt" w="11pt" h="22pt" x="2pt">
  315. <assist><speak>Screen Reader</speak></assist>
  316. <ui>
  317. <textEdit multiLine="0"/>
  318. </ui>
  319. <value>
  320. <text maxChars="123"/>
  321. </value>
  322. </field>
  323. </pageArea>
  324. </pageSet>
  325. <subform name="first">
  326. <draw w="1pt" h="1pt"><value><text>foo</text></value></draw>
  327. </subform>
  328. </subform>
  329. </template>
  330. <xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
  331. <xfa:data>
  332. </xfa:data>
  333. </xfa:datasets>
  334. </xdp:xdp>
  335. `;
  336. const factory = new _factory.XFAFactory({
  337. "xdp:xdp": xml
  338. });
  339. expect(await factory.getNumPages()).toEqual(1);
  340. const pages = await factory.getPages();
  341. const field = searchHtmlNode(pages, "name", "input");
  342. expect(field.attributes["aria-label"]).toEqual("Screen Reader");
  343. });
  344. it("should have an aria-label property from toolTip", async () => {
  345. const xml = `
  346. <?xml version="1.0"?>
  347. <xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
  348. <template xmlns="http://www.xfa.org/schema/xfa-template/3.3">
  349. <subform name="root" mergeMode="matchTemplate">
  350. <pageSet>
  351. <pageArea>
  352. <contentArea x="0pt" w="456pt" h="789pt"/>
  353. <medium stock="default" short="456pt" long="789pt"/>
  354. <field y="1pt" w="11pt" h="22pt" x="2pt">
  355. <assist><toolTip>Screen Reader</toolTip></assist>
  356. <ui>
  357. <textEdit multiLine="0"/>
  358. </ui>
  359. <value>
  360. <text maxChars="123"/>
  361. </value>
  362. </field>
  363. </pageArea>
  364. </pageSet>
  365. <subform name="first">
  366. <draw w="1pt" h="1pt"><value><text>foo</text></value></draw>
  367. </subform>
  368. </subform>
  369. </template>
  370. <xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
  371. <xfa:data>
  372. </xfa:data>
  373. </xfa:datasets>
  374. </xdp:xdp>
  375. `;
  376. const factory = new _factory.XFAFactory({
  377. "xdp:xdp": xml
  378. });
  379. expect(await factory.getNumPages()).toEqual(1);
  380. const pages = await factory.getPages();
  381. const field = searchHtmlNode(pages, "name", "input");
  382. expect(field.attributes["aria-label"]).toEqual("Screen Reader");
  383. });
  384. it("should have an input or textarea", async () => {
  385. const xml = `
  386. <?xml version="1.0"?>
  387. <xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
  388. <template xmlns="http://www.xfa.org/schema/xfa-template/3.3">
  389. <subform name="root" mergeMode="matchTemplate">
  390. <pageSet>
  391. <pageArea>
  392. <contentArea x="123pt" w="456pt" h="789pt"/>
  393. <medium stock="default" short="456pt" long="789pt"/>
  394. <field y="1pt" w="11pt" h="22pt" x="2pt">
  395. <ui>
  396. <textEdit/>
  397. </ui>
  398. </field>
  399. <field y="1pt" w="11pt" h="22pt" x="2pt">
  400. <ui>
  401. <textEdit multiLine="1"/>
  402. </ui>
  403. </field>
  404. </pageArea>
  405. </pageSet>
  406. <subform name="first">
  407. <draw w="1pt" h="1pt"><value><text>foo</text></value></draw>
  408. </subform>
  409. </subform>
  410. </template>
  411. <xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
  412. <xfa:data>
  413. </xfa:data>
  414. </xfa:datasets>
  415. </xdp:xdp>
  416. `;
  417. const factory = new _factory.XFAFactory({
  418. "xdp:xdp": xml
  419. });
  420. expect(await factory.getNumPages()).toEqual(1);
  421. const pages = await factory.getPages();
  422. const field1 = searchHtmlNode(pages, "name", "input");
  423. expect(field1).not.toEqual(null);
  424. const field2 = searchHtmlNode(pages, "name", "textarea");
  425. expect(field2).not.toEqual(null);
  426. });
  427. });
  428. it("should have an input or textarea", async () => {
  429. const xml = `
  430. <?xml version="1.0"?>
  431. <xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
  432. <template xmlns="http://www.xfa.org/schema/xfa-template/3.3">
  433. <subform name="root" mergeMode="matchTemplate">
  434. <pageSet>
  435. <pageArea>
  436. <contentArea x="123pt" w="456pt" h="789pt"/>
  437. <medium stock="default" short="456pt" long="789pt"/>
  438. <field y="1pt" w="11pt" h="22pt" x="2pt">
  439. <ui>
  440. <textEdit multiLine="1"/>
  441. </ui>
  442. </field>
  443. </pageArea>
  444. </pageSet>
  445. <subform name="first">
  446. <field y="1pt" w="11pt" h="22pt" x="2pt" name="hello">
  447. <ui>
  448. <textEdit/>
  449. </ui>
  450. <value>
  451. <integer/>
  452. </value>
  453. </field>
  454. </subform>
  455. </subform>
  456. </template>
  457. <xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
  458. <xfa:data>
  459. <toto>
  460. <first>
  461. <hello>123
  462. </hello>
  463. </first>
  464. </toto>
  465. </xfa:data>
  466. </xfa:datasets>
  467. </xdp:xdp>
  468. `;
  469. const factory = new _factory.XFAFactory({
  470. "xdp:xdp": xml
  471. });
  472. expect(await factory.getNumPages()).toEqual(1);
  473. const pages = await factory.getPages();
  474. const field1 = searchHtmlNode(pages, "name", "input");
  475. expect(field1).not.toEqual(null);
  476. expect(field1.attributes.value).toEqual("123");
  477. });
  478. it("should parse URLs correctly", async () => {
  479. function getXml(href) {
  480. return `
  481. <?xml version="1.0"?>
  482. <xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
  483. <template xmlns="http://www.xfa.org/schema/xfa-template/3.3">
  484. <subform name="root" mergeMode="matchTemplate">
  485. <pageSet>
  486. <pageArea>
  487. <contentArea x="0pt" w="456pt" h="789pt"/>
  488. <medium stock="default" short="456pt" long="789pt"/>
  489. <draw name="url" y="5.928mm" x="128.388mm" w="71.237mm" h="9.528mm">
  490. <value>
  491. <exData contentType="text/html">
  492. <body xmlns="http://www.w3.org/1999/xhtml">
  493. <a href="${href}">${href}</a>
  494. </body>
  495. </exData>
  496. </value>
  497. </draw>
  498. </pageArea>
  499. </pageSet>
  500. </subform>
  501. </template>
  502. <xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
  503. <xfa:data>
  504. </xfa:data>
  505. </xfa:datasets>
  506. </xdp:xdp>
  507. `;
  508. }
  509. let factory, pages, a;
  510. factory = new _factory.XFAFactory({
  511. "xdp:xdp": getXml("https://www.example.com/")
  512. });
  513. expect(await factory.getNumPages()).toEqual(1);
  514. pages = await factory.getPages();
  515. a = searchHtmlNode(pages, "name", "a");
  516. expect(a.value).toEqual("https://www.example.com/");
  517. expect(a.attributes.href).toEqual("https://www.example.com/");
  518. factory = new _factory.XFAFactory({
  519. "xdp:xdp": getXml("www.example.com/")
  520. });
  521. expect(await factory.getNumPages()).toEqual(1);
  522. pages = await factory.getPages();
  523. a = searchHtmlNode(pages, "name", "a");
  524. expect(a.value).toEqual("www.example.com/");
  525. expect(a.attributes.href).toEqual("http://www.example.com/");
  526. factory = new _factory.XFAFactory({
  527. "xdp:xdp": getXml("mailto:test@example.com")
  528. });
  529. expect(await factory.getNumPages()).toEqual(1);
  530. pages = await factory.getPages();
  531. a = searchHtmlNode(pages, "name", "a");
  532. expect(a.value).toEqual("mailto:test@example.com");
  533. expect(a.attributes.href).toEqual("mailto:test@example.com");
  534. factory = new _factory.XFAFactory({
  535. "xdp:xdp": getXml("qwerty/")
  536. });
  537. expect(await factory.getNumPages()).toEqual(1);
  538. pages = await factory.getPages();
  539. a = searchHtmlNode(pages, "name", "a");
  540. expect(a.value).toEqual("qwerty/");
  541. expect(a.attributes.href).toEqual("");
  542. });
  543. it("should replace button with an URL by a link", async () => {
  544. const xml = `
  545. <?xml version="1.0"?>
  546. <xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
  547. <template xmlns="http://www.xfa.org/schema/xfa-template/3.3">
  548. <subform name="root" mergeMode="matchTemplate">
  549. <pageSet>
  550. <pageArea>
  551. <contentArea x="123pt" w="456pt" h="789pt"/>
  552. <medium stock="default" short="456pt" long="789pt"/>
  553. </pageArea>
  554. </pageSet>
  555. <subform name="first">
  556. <field y="1pt" w="11pt" h="22pt" x="2pt">
  557. <ui>
  558. <button/>
  559. </ui>
  560. <event activity="click" name="event__click">
  561. <script contentType="application/x-javascript">
  562. app.launchURL("https://github.com/mozilla/pdf.js", true);
  563. </script>
  564. </event>
  565. </field>
  566. <field y="1pt" w="11pt" h="22pt" x="2pt">
  567. <ui>
  568. <button/>
  569. </ui>
  570. <event activity="click" name="event__click">
  571. <script contentType="application/x-javascript">
  572. xfa.host.gotoURL("https://github.com/allizom/pdf.js");
  573. </script>
  574. </event>
  575. </field>
  576. </subform>
  577. </subform>
  578. </template>
  579. <xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
  580. <xfa:data>
  581. </xfa:data>
  582. </xfa:datasets>
  583. </xdp:xdp>
  584. `;
  585. const factory = new _factory.XFAFactory({
  586. "xdp:xdp": xml
  587. });
  588. expect(await factory.getNumPages()).toEqual(1);
  589. const pages = await factory.getPages();
  590. let a = searchHtmlNode(pages, "name", "a");
  591. expect(a.attributes.href).toEqual("https://github.com/mozilla/pdf.js");
  592. expect(a.attributes.newWindow).toEqual(true);
  593. a = searchHtmlNode(pages, "name", "a", false, [1]);
  594. expect(a.attributes.href).toEqual("https://github.com/allizom/pdf.js");
  595. expect(a.attributes.newWindow).toEqual(false);
  596. });
  597. });