annotation_spec.js 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2019 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 _annotation = require("../../core/annotation");
  24. var _util = require("../../shared/util");
  25. var _test_utils = require("./test_utils");
  26. var _primitives = require("../../core/primitives");
  27. var _parser = require("../../core/parser");
  28. var _stream = require("../../core/stream");
  29. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  30. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  31. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  32. describe('annotation', function () {
  33. var PDFManagerMock =
  34. /*#__PURE__*/
  35. function () {
  36. function PDFManagerMock(params) {
  37. _classCallCheck(this, PDFManagerMock);
  38. this.docBaseUrl = params.docBaseUrl || null;
  39. }
  40. _createClass(PDFManagerMock, [{
  41. key: "ensure",
  42. value: function ensure(obj, prop, args) {
  43. return new Promise(function (resolve) {
  44. var value = obj[prop];
  45. if (typeof value === 'function') {
  46. resolve(value.apply(obj, args));
  47. } else {
  48. resolve(value);
  49. }
  50. });
  51. }
  52. }]);
  53. return PDFManagerMock;
  54. }();
  55. var pdfManagerMock, idFactoryMock;
  56. beforeAll(function (done) {
  57. pdfManagerMock = new PDFManagerMock({
  58. docBaseUrl: null
  59. });
  60. idFactoryMock = (0, _test_utils.createIdFactory)(0);
  61. done();
  62. });
  63. afterAll(function () {
  64. pdfManagerMock = null;
  65. idFactoryMock = null;
  66. });
  67. describe('AnnotationFactory', function () {
  68. it('should get id for annotation', function (done) {
  69. var annotationDict = new _primitives.Dict();
  70. annotationDict.set('Type', _primitives.Name.get('Annot'));
  71. annotationDict.set('Subtype', _primitives.Name.get('Link'));
  72. var annotationRef = _primitives.Ref.get(10, 0);
  73. var xref = new _test_utils.XRefMock([{
  74. ref: annotationRef,
  75. data: annotationDict
  76. }]);
  77. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref) {
  78. var data = _ref.data;
  79. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  80. expect(data.id).toEqual('10R');
  81. done();
  82. }, done.fail);
  83. });
  84. it('should handle, and get fallback IDs for, annotations that are not ' + 'indirect objects (issue 7569)', function (done) {
  85. var annotationDict = new _primitives.Dict();
  86. annotationDict.set('Type', _primitives.Name.get('Annot'));
  87. annotationDict.set('Subtype', _primitives.Name.get('Link'));
  88. var xref = new _test_utils.XRefMock();
  89. var idFactory = (0, _test_utils.createIdFactory)(0);
  90. var annotation1 = _annotation.AnnotationFactory.create(xref, annotationDict, pdfManagerMock, idFactory).then(function (_ref2) {
  91. var data = _ref2.data;
  92. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  93. expect(data.id).toEqual('annot_p0_1');
  94. });
  95. var annotation2 = _annotation.AnnotationFactory.create(xref, annotationDict, pdfManagerMock, idFactory).then(function (_ref3) {
  96. var data = _ref3.data;
  97. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  98. expect(data.id).toEqual('annot_p0_2');
  99. });
  100. Promise.all([annotation1, annotation2]).then(done, done.fail);
  101. });
  102. it('should handle missing /Subtype', function (done) {
  103. var annotationDict = new _primitives.Dict();
  104. annotationDict.set('Type', _primitives.Name.get('Annot'));
  105. var annotationRef = _primitives.Ref.get(1, 0);
  106. var xref = new _test_utils.XRefMock([{
  107. ref: annotationRef,
  108. data: annotationDict
  109. }]);
  110. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref4) {
  111. var data = _ref4.data;
  112. expect(data.annotationType).toBeUndefined();
  113. done();
  114. }, done.fail);
  115. });
  116. });
  117. describe('Annotation', function () {
  118. var dict, ref;
  119. beforeAll(function (done) {
  120. dict = new _primitives.Dict();
  121. ref = _primitives.Ref.get(1, 0);
  122. done();
  123. });
  124. afterAll(function () {
  125. dict = ref = null;
  126. });
  127. it('should set and get valid contents', function () {
  128. var annotation = new _annotation.Annotation({
  129. dict: dict,
  130. ref: ref
  131. });
  132. annotation.setContents('Foo bar baz');
  133. expect(annotation.contents).toEqual('Foo bar baz');
  134. });
  135. it('should not set and get invalid contents', function () {
  136. var annotation = new _annotation.Annotation({
  137. dict: dict,
  138. ref: ref
  139. });
  140. annotation.setContents(undefined);
  141. expect(annotation.contents).toEqual('');
  142. });
  143. it('should set and get a valid modification date', function () {
  144. var annotation = new _annotation.Annotation({
  145. dict: dict,
  146. ref: ref
  147. });
  148. annotation.setModificationDate('D:20190422');
  149. expect(annotation.modificationDate).toEqual('D:20190422');
  150. });
  151. it('should not set and get an invalid modification date', function () {
  152. var annotation = new _annotation.Annotation({
  153. dict: dict,
  154. ref: ref
  155. });
  156. annotation.setModificationDate(undefined);
  157. expect(annotation.modificationDate).toEqual(null);
  158. });
  159. it('should set and get flags', function () {
  160. var annotation = new _annotation.Annotation({
  161. dict: dict,
  162. ref: ref
  163. });
  164. annotation.setFlags(13);
  165. expect(annotation.hasFlag(_util.AnnotationFlag.INVISIBLE)).toEqual(true);
  166. expect(annotation.hasFlag(_util.AnnotationFlag.NOZOOM)).toEqual(true);
  167. expect(annotation.hasFlag(_util.AnnotationFlag.PRINT)).toEqual(true);
  168. expect(annotation.hasFlag(_util.AnnotationFlag.READONLY)).toEqual(false);
  169. });
  170. it('should be viewable and not printable by default', function () {
  171. var annotation = new _annotation.Annotation({
  172. dict: dict,
  173. ref: ref
  174. });
  175. expect(annotation.viewable).toEqual(true);
  176. expect(annotation.printable).toEqual(false);
  177. });
  178. it('should set and get a valid rectangle', function () {
  179. var annotation = new _annotation.Annotation({
  180. dict: dict,
  181. ref: ref
  182. });
  183. annotation.setRectangle([117, 694, 164.298, 720]);
  184. expect(annotation.rectangle).toEqual([117, 694, 164.298, 720]);
  185. });
  186. it('should not set and get an invalid rectangle', function () {
  187. var annotation = new _annotation.Annotation({
  188. dict: dict,
  189. ref: ref
  190. });
  191. annotation.setRectangle([117, 694, 164.298]);
  192. expect(annotation.rectangle).toEqual([0, 0, 0, 0]);
  193. });
  194. it('should reject a color if it is not an array', function () {
  195. var annotation = new _annotation.Annotation({
  196. dict: dict,
  197. ref: ref
  198. });
  199. annotation.setColor('red');
  200. expect(annotation.color).toEqual(new Uint8ClampedArray([0, 0, 0]));
  201. });
  202. it('should set and get a transparent color', function () {
  203. var annotation = new _annotation.Annotation({
  204. dict: dict,
  205. ref: ref
  206. });
  207. annotation.setColor([]);
  208. expect(annotation.color).toEqual(null);
  209. });
  210. it('should set and get a grayscale color', function () {
  211. var annotation = new _annotation.Annotation({
  212. dict: dict,
  213. ref: ref
  214. });
  215. annotation.setColor([0.4]);
  216. expect(annotation.color).toEqual(new Uint8ClampedArray([102, 102, 102]));
  217. });
  218. it('should set and get an RGB color', function () {
  219. var annotation = new _annotation.Annotation({
  220. dict: dict,
  221. ref: ref
  222. });
  223. annotation.setColor([0, 0, 1]);
  224. expect(annotation.color).toEqual(new Uint8ClampedArray([0, 0, 255]));
  225. });
  226. it('should set and get a CMYK color', function () {
  227. var annotation = new _annotation.Annotation({
  228. dict: dict,
  229. ref: ref
  230. });
  231. annotation.setColor([0.1, 0.92, 0.84, 0.02]);
  232. expect(annotation.color).toEqual(new Uint8ClampedArray([234, 59, 48]));
  233. });
  234. it('should not set and get an invalid color', function () {
  235. var annotation = new _annotation.Annotation({
  236. dict: dict,
  237. ref: ref
  238. });
  239. annotation.setColor([0.4, 0.6]);
  240. expect(annotation.color).toEqual(new Uint8ClampedArray([0, 0, 0]));
  241. });
  242. });
  243. describe('AnnotationBorderStyle', function () {
  244. it('should set and get a valid width', function () {
  245. var borderStyle = new _annotation.AnnotationBorderStyle();
  246. borderStyle.setWidth(3);
  247. expect(borderStyle.width).toEqual(3);
  248. });
  249. it('should not set and get an invalid width', function () {
  250. var borderStyle = new _annotation.AnnotationBorderStyle();
  251. borderStyle.setWidth('three');
  252. expect(borderStyle.width).toEqual(1);
  253. });
  254. it('should set the width to zero, when the input is a `Name` (issue 10385)', function () {
  255. var borderStyleZero = new _annotation.AnnotationBorderStyle();
  256. borderStyleZero.setWidth(_primitives.Name.get('0'));
  257. var borderStyleFive = new _annotation.AnnotationBorderStyle();
  258. borderStyleFive.setWidth(_primitives.Name.get('5'));
  259. expect(borderStyleZero.width).toEqual(0);
  260. expect(borderStyleFive.width).toEqual(0);
  261. });
  262. it('should set and get a valid style', function () {
  263. var borderStyle = new _annotation.AnnotationBorderStyle();
  264. borderStyle.setStyle(_primitives.Name.get('D'));
  265. expect(borderStyle.style).toEqual(_util.AnnotationBorderStyleType.DASHED);
  266. });
  267. it('should not set and get an invalid style', function () {
  268. var borderStyle = new _annotation.AnnotationBorderStyle();
  269. borderStyle.setStyle('Dashed');
  270. expect(borderStyle.style).toEqual(_util.AnnotationBorderStyleType.SOLID);
  271. });
  272. it('should set and get a valid dash array', function () {
  273. var borderStyle = new _annotation.AnnotationBorderStyle();
  274. borderStyle.setDashArray([1, 2, 3]);
  275. expect(borderStyle.dashArray).toEqual([1, 2, 3]);
  276. });
  277. it('should not set and get an invalid dash array', function () {
  278. var borderStyle = new _annotation.AnnotationBorderStyle();
  279. borderStyle.setDashArray([0, 0]);
  280. expect(borderStyle.dashArray).toEqual([3]);
  281. });
  282. it('should set and get a valid horizontal corner radius', function () {
  283. var borderStyle = new _annotation.AnnotationBorderStyle();
  284. borderStyle.setHorizontalCornerRadius(3);
  285. expect(borderStyle.horizontalCornerRadius).toEqual(3);
  286. });
  287. it('should not set and get an invalid horizontal corner radius', function () {
  288. var borderStyle = new _annotation.AnnotationBorderStyle();
  289. borderStyle.setHorizontalCornerRadius('three');
  290. expect(borderStyle.horizontalCornerRadius).toEqual(0);
  291. });
  292. it('should set and get a valid vertical corner radius', function () {
  293. var borderStyle = new _annotation.AnnotationBorderStyle();
  294. borderStyle.setVerticalCornerRadius(3);
  295. expect(borderStyle.verticalCornerRadius).toEqual(3);
  296. });
  297. it('should not set and get an invalid vertical corner radius', function () {
  298. var borderStyle = new _annotation.AnnotationBorderStyle();
  299. borderStyle.setVerticalCornerRadius('three');
  300. expect(borderStyle.verticalCornerRadius).toEqual(0);
  301. });
  302. });
  303. describe('MarkupAnnotation', function () {
  304. var dict, ref;
  305. beforeAll(function (done) {
  306. dict = new _primitives.Dict();
  307. ref = _primitives.Ref.get(1, 0);
  308. done();
  309. });
  310. afterAll(function () {
  311. dict = ref = null;
  312. });
  313. it('should set and get a valid creation date', function () {
  314. var markupAnnotation = new _annotation.MarkupAnnotation({
  315. dict: dict,
  316. ref: ref
  317. });
  318. markupAnnotation.setCreationDate('D:20190422');
  319. expect(markupAnnotation.creationDate).toEqual('D:20190422');
  320. });
  321. it('should not set and get an invalid creation date', function () {
  322. var markupAnnotation = new _annotation.MarkupAnnotation({
  323. dict: dict,
  324. ref: ref
  325. });
  326. markupAnnotation.setCreationDate(undefined);
  327. expect(markupAnnotation.creationDate).toEqual(null);
  328. });
  329. });
  330. describe('LinkAnnotation', function () {
  331. it('should correctly parse a URI action', function (done) {
  332. var actionDict = new _primitives.Dict();
  333. actionDict.set('Type', _primitives.Name.get('Action'));
  334. actionDict.set('S', _primitives.Name.get('URI'));
  335. actionDict.set('URI', 'http://www.ctan.org/tex-archive/info/lshort');
  336. var annotationDict = new _primitives.Dict();
  337. annotationDict.set('Type', _primitives.Name.get('Annot'));
  338. annotationDict.set('Subtype', _primitives.Name.get('Link'));
  339. annotationDict.set('A', actionDict);
  340. var annotationRef = _primitives.Ref.get(820, 0);
  341. var xref = new _test_utils.XRefMock([{
  342. ref: annotationRef,
  343. data: annotationDict
  344. }]);
  345. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref5) {
  346. var data = _ref5.data;
  347. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  348. expect(data.url).toEqual('http://www.ctan.org/tex-archive/info/lshort');
  349. expect(data.unsafeUrl).toEqual('http://www.ctan.org/tex-archive/info/lshort');
  350. expect(data.dest).toBeUndefined();
  351. done();
  352. }, done.fail);
  353. });
  354. it('should correctly parse a URI action, where the URI entry ' + 'is missing a protocol', function (done) {
  355. var actionDict = new _primitives.Dict();
  356. actionDict.set('Type', _primitives.Name.get('Action'));
  357. actionDict.set('S', _primitives.Name.get('URI'));
  358. actionDict.set('URI', 'www.hmrc.gov.uk');
  359. var annotationDict = new _primitives.Dict();
  360. annotationDict.set('Type', _primitives.Name.get('Annot'));
  361. annotationDict.set('Subtype', _primitives.Name.get('Link'));
  362. annotationDict.set('A', actionDict);
  363. var annotationRef = _primitives.Ref.get(353, 0);
  364. var xref = new _test_utils.XRefMock([{
  365. ref: annotationRef,
  366. data: annotationDict
  367. }]);
  368. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref6) {
  369. var data = _ref6.data;
  370. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  371. expect(data.url).toEqual('http://www.hmrc.gov.uk/');
  372. expect(data.unsafeUrl).toEqual('http://www.hmrc.gov.uk');
  373. expect(data.dest).toBeUndefined();
  374. done();
  375. }, done.fail);
  376. });
  377. it('should correctly parse a URI action, where the URI entry ' + 'has an incorrect encoding (bug 1122280)', function (done) {
  378. var actionStream = new _stream.StringStream('<<\n' + '/Type /Action\n' + '/S /URI\n' + '/URI (http://www.example.com/\\303\\274\\303\\266\\303\\244)\n' + '>>\n');
  379. var parser = new _parser.Parser({
  380. lexer: new _parser.Lexer(actionStream),
  381. xref: null
  382. });
  383. var actionDict = parser.getObj();
  384. var annotationDict = new _primitives.Dict();
  385. annotationDict.set('Type', _primitives.Name.get('Annot'));
  386. annotationDict.set('Subtype', _primitives.Name.get('Link'));
  387. annotationDict.set('A', actionDict);
  388. var annotationRef = _primitives.Ref.get(8, 0);
  389. var xref = new _test_utils.XRefMock([{
  390. ref: annotationRef,
  391. data: annotationDict
  392. }]);
  393. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref7) {
  394. var data = _ref7.data;
  395. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  396. expect(data.url).toEqual(new URL((0, _util.stringToUTF8String)('http://www.example.com/\xC3\xBC\xC3\xB6\xC3\xA4')).href);
  397. expect(data.unsafeUrl).toEqual((0, _util.stringToUTF8String)('http://www.example.com/\xC3\xBC\xC3\xB6\xC3\xA4'));
  398. expect(data.dest).toBeUndefined();
  399. done();
  400. }, done.fail);
  401. });
  402. it('should correctly parse a GoTo action', function (done) {
  403. var actionDict = new _primitives.Dict();
  404. actionDict.set('Type', _primitives.Name.get('Action'));
  405. actionDict.set('S', _primitives.Name.get('GoTo'));
  406. actionDict.set('D', 'page.157');
  407. var annotationDict = new _primitives.Dict();
  408. annotationDict.set('Type', _primitives.Name.get('Annot'));
  409. annotationDict.set('Subtype', _primitives.Name.get('Link'));
  410. annotationDict.set('A', actionDict);
  411. var annotationRef = _primitives.Ref.get(798, 0);
  412. var xref = new _test_utils.XRefMock([{
  413. ref: annotationRef,
  414. data: annotationDict
  415. }]);
  416. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref8) {
  417. var data = _ref8.data;
  418. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  419. expect(data.url).toBeUndefined();
  420. expect(data.unsafeUrl).toBeUndefined();
  421. expect(data.dest).toEqual('page.157');
  422. done();
  423. }, done.fail);
  424. });
  425. it('should correctly parse a GoToR action, where the FileSpec entry ' + 'is a string containing a relative URL', function (done) {
  426. var actionDict = new _primitives.Dict();
  427. actionDict.set('Type', _primitives.Name.get('Action'));
  428. actionDict.set('S', _primitives.Name.get('GoToR'));
  429. actionDict.set('F', '../../0013/001346/134685E.pdf');
  430. actionDict.set('D', '4.3');
  431. actionDict.set('NewWindow', true);
  432. var annotationDict = new _primitives.Dict();
  433. annotationDict.set('Type', _primitives.Name.get('Annot'));
  434. annotationDict.set('Subtype', _primitives.Name.get('Link'));
  435. annotationDict.set('A', actionDict);
  436. var annotationRef = _primitives.Ref.get(489, 0);
  437. var xref = new _test_utils.XRefMock([{
  438. ref: annotationRef,
  439. data: annotationDict
  440. }]);
  441. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref9) {
  442. var data = _ref9.data;
  443. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  444. expect(data.url).toBeUndefined();
  445. expect(data.unsafeUrl).toEqual('../../0013/001346/134685E.pdf#4.3');
  446. expect(data.dest).toBeUndefined();
  447. expect(data.newWindow).toEqual(true);
  448. done();
  449. }, done.fail);
  450. });
  451. it('should correctly parse a GoToR action, containing a relative URL, ' + 'with the "docBaseUrl" parameter specified', function (done) {
  452. var actionDict = new _primitives.Dict();
  453. actionDict.set('Type', _primitives.Name.get('Action'));
  454. actionDict.set('S', _primitives.Name.get('GoToR'));
  455. actionDict.set('F', '../../0013/001346/134685E.pdf');
  456. actionDict.set('D', '4.3');
  457. var annotationDict = new _primitives.Dict();
  458. annotationDict.set('Type', _primitives.Name.get('Annot'));
  459. annotationDict.set('Subtype', _primitives.Name.get('Link'));
  460. annotationDict.set('A', actionDict);
  461. var annotationRef = _primitives.Ref.get(489, 0);
  462. var xref = new _test_utils.XRefMock([{
  463. ref: annotationRef,
  464. data: annotationDict
  465. }]);
  466. var pdfManager = new PDFManagerMock({
  467. docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf'
  468. });
  469. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManager, idFactoryMock).then(function (_ref10) {
  470. var data = _ref10.data;
  471. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  472. expect(data.url).toEqual('http://www.example.com/0013/001346/134685E.pdf#4.3');
  473. expect(data.unsafeUrl).toEqual('../../0013/001346/134685E.pdf#4.3');
  474. expect(data.dest).toBeUndefined();
  475. done();
  476. }, done.fail);
  477. });
  478. it('should correctly parse a GoToR action, with named destination', function (done) {
  479. var actionDict = new _primitives.Dict();
  480. actionDict.set('Type', _primitives.Name.get('Action'));
  481. actionDict.set('S', _primitives.Name.get('GoToR'));
  482. actionDict.set('F', 'http://www.example.com/test.pdf');
  483. actionDict.set('D', '15');
  484. var annotationDict = new _primitives.Dict();
  485. annotationDict.set('Type', _primitives.Name.get('Annot'));
  486. annotationDict.set('Subtype', _primitives.Name.get('Link'));
  487. annotationDict.set('A', actionDict);
  488. var annotationRef = _primitives.Ref.get(495, 0);
  489. var xref = new _test_utils.XRefMock([{
  490. ref: annotationRef,
  491. data: annotationDict
  492. }]);
  493. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref11) {
  494. var data = _ref11.data;
  495. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  496. expect(data.url).toEqual('http://www.example.com/test.pdf#15');
  497. expect(data.unsafeUrl).toEqual('http://www.example.com/test.pdf#15');
  498. expect(data.dest).toBeUndefined();
  499. expect(data.newWindow).toBeFalsy();
  500. done();
  501. }, done.fail);
  502. });
  503. it('should correctly parse a GoToR action, with explicit destination array', function (done) {
  504. var actionDict = new _primitives.Dict();
  505. actionDict.set('Type', _primitives.Name.get('Action'));
  506. actionDict.set('S', _primitives.Name.get('GoToR'));
  507. actionDict.set('F', 'http://www.example.com/test.pdf');
  508. actionDict.set('D', [14, _primitives.Name.get('XYZ'), null, 298.043, null]);
  509. var annotationDict = new _primitives.Dict();
  510. annotationDict.set('Type', _primitives.Name.get('Annot'));
  511. annotationDict.set('Subtype', _primitives.Name.get('Link'));
  512. annotationDict.set('A', actionDict);
  513. var annotationRef = _primitives.Ref.get(489, 0);
  514. var xref = new _test_utils.XRefMock([{
  515. ref: annotationRef,
  516. data: annotationDict
  517. }]);
  518. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref12) {
  519. var data = _ref12.data;
  520. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  521. expect(data.url).toEqual(new URL('http://www.example.com/test.pdf#' + '[14,{"name":"XYZ"},null,298.043,null]').href);
  522. expect(data.unsafeUrl).toEqual('http://www.example.com/test.pdf#' + '[14,{"name":"XYZ"},null,298.043,null]');
  523. expect(data.dest).toBeUndefined();
  524. expect(data.newWindow).toBeFalsy();
  525. done();
  526. }, done.fail);
  527. });
  528. it('should correctly parse a Launch action, where the FileSpec dict ' + 'contains a relative URL, with the "docBaseUrl" parameter specified', function (done) {
  529. var fileSpecDict = new _primitives.Dict();
  530. fileSpecDict.set('Type', _primitives.Name.get('FileSpec'));
  531. fileSpecDict.set('F', 'Part II/Part II.pdf');
  532. fileSpecDict.set('UF', 'Part II/Part II.pdf');
  533. var actionDict = new _primitives.Dict();
  534. actionDict.set('Type', _primitives.Name.get('Action'));
  535. actionDict.set('S', _primitives.Name.get('Launch'));
  536. actionDict.set('F', fileSpecDict);
  537. actionDict.set('NewWindow', true);
  538. var annotationDict = new _primitives.Dict();
  539. annotationDict.set('Type', _primitives.Name.get('Annot'));
  540. annotationDict.set('Subtype', _primitives.Name.get('Link'));
  541. annotationDict.set('A', actionDict);
  542. var annotationRef = _primitives.Ref.get(88, 0);
  543. var xref = new _test_utils.XRefMock([{
  544. ref: annotationRef,
  545. data: annotationDict
  546. }]);
  547. var pdfManager = new PDFManagerMock({
  548. docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf'
  549. });
  550. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManager, idFactoryMock).then(function (_ref13) {
  551. var data = _ref13.data;
  552. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  553. expect(data.url).toEqual(new URL('http://www.example.com/test/pdfs/Part II/Part II.pdf').href);
  554. expect(data.unsafeUrl).toEqual('Part II/Part II.pdf');
  555. expect(data.dest).toBeUndefined();
  556. expect(data.newWindow).toEqual(true);
  557. done();
  558. }, done.fail);
  559. });
  560. it('should recover valid URLs from JavaScript actions having certain ' + 'white-listed formats', function (done) {
  561. function checkJsAction(params) {
  562. var jsEntry = params.jsEntry;
  563. var expectedUrl = params.expectedUrl;
  564. var expectedUnsafeUrl = params.expectedUnsafeUrl;
  565. var expectedNewWindow = params.expectedNewWindow;
  566. var actionDict = new _primitives.Dict();
  567. actionDict.set('Type', _primitives.Name.get('Action'));
  568. actionDict.set('S', _primitives.Name.get('JavaScript'));
  569. actionDict.set('JS', jsEntry);
  570. var annotationDict = new _primitives.Dict();
  571. annotationDict.set('Type', _primitives.Name.get('Annot'));
  572. annotationDict.set('Subtype', _primitives.Name.get('Link'));
  573. annotationDict.set('A', actionDict);
  574. var annotationRef = _primitives.Ref.get(46, 0);
  575. var xref = new _test_utils.XRefMock([{
  576. ref: annotationRef,
  577. data: annotationDict
  578. }]);
  579. return _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref14) {
  580. var data = _ref14.data;
  581. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  582. expect(data.url).toEqual(expectedUrl);
  583. expect(data.unsafeUrl).toEqual(expectedUnsafeUrl);
  584. expect(data.dest).toBeUndefined();
  585. expect(data.newWindow).toEqual(expectedNewWindow);
  586. });
  587. }
  588. var annotation1 = checkJsAction({
  589. jsEntry: 'function someFun() { return "qwerty"; } someFun();',
  590. expectedUrl: undefined,
  591. expectedUnsafeUrl: undefined,
  592. expectedNewWindow: undefined
  593. });
  594. var annotation2 = checkJsAction({
  595. jsEntry: 'window.open(\'http://www.example.com/test.pdf\')',
  596. expectedUrl: new URL('http://www.example.com/test.pdf').href,
  597. expectedUnsafeUrl: 'http://www.example.com/test.pdf',
  598. expectedNewWindow: undefined
  599. });
  600. var annotation3 = checkJsAction({
  601. jsEntry: new _stream.StringStream('app.launchURL("http://www.example.com/test.pdf", true)'),
  602. expectedUrl: new URL('http://www.example.com/test.pdf').href,
  603. expectedUnsafeUrl: 'http://www.example.com/test.pdf',
  604. expectedNewWindow: true
  605. });
  606. Promise.all([annotation1, annotation2, annotation3]).then(done, done.fail);
  607. });
  608. it('should correctly parse a Named action', function (done) {
  609. var actionDict = new _primitives.Dict();
  610. actionDict.set('Type', _primitives.Name.get('Action'));
  611. actionDict.set('S', _primitives.Name.get('Named'));
  612. actionDict.set('N', _primitives.Name.get('GoToPage'));
  613. var annotationDict = new _primitives.Dict();
  614. annotationDict.set('Type', _primitives.Name.get('Annot'));
  615. annotationDict.set('Subtype', _primitives.Name.get('Link'));
  616. annotationDict.set('A', actionDict);
  617. var annotationRef = _primitives.Ref.get(12, 0);
  618. var xref = new _test_utils.XRefMock([{
  619. ref: annotationRef,
  620. data: annotationDict
  621. }]);
  622. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref15) {
  623. var data = _ref15.data;
  624. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  625. expect(data.url).toBeUndefined();
  626. expect(data.unsafeUrl).toBeUndefined();
  627. expect(data.action).toEqual('GoToPage');
  628. done();
  629. }, done.fail);
  630. });
  631. it('should correctly parse a simple Dest', function (done) {
  632. var annotationDict = new _primitives.Dict();
  633. annotationDict.set('Type', _primitives.Name.get('Annot'));
  634. annotationDict.set('Subtype', _primitives.Name.get('Link'));
  635. annotationDict.set('Dest', _primitives.Name.get('LI0'));
  636. var annotationRef = _primitives.Ref.get(583, 0);
  637. var xref = new _test_utils.XRefMock([{
  638. ref: annotationRef,
  639. data: annotationDict
  640. }]);
  641. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref16) {
  642. var data = _ref16.data;
  643. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  644. expect(data.url).toBeUndefined();
  645. expect(data.unsafeUrl).toBeUndefined();
  646. expect(data.dest).toEqual('LI0');
  647. done();
  648. }, done.fail);
  649. });
  650. it('should correctly parse a simple Dest, with explicit destination array', function (done) {
  651. var annotationDict = new _primitives.Dict();
  652. annotationDict.set('Type', _primitives.Name.get('Annot'));
  653. annotationDict.set('Subtype', _primitives.Name.get('Link'));
  654. annotationDict.set('Dest', [_primitives.Ref.get(17, 0), _primitives.Name.get('XYZ'), 0, 841.89, null]);
  655. var annotationRef = _primitives.Ref.get(10, 0);
  656. var xref = new _test_utils.XRefMock([{
  657. ref: annotationRef,
  658. data: annotationDict
  659. }]);
  660. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref17) {
  661. var data = _ref17.data;
  662. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  663. expect(data.url).toBeUndefined();
  664. expect(data.unsafeUrl).toBeUndefined();
  665. expect(data.dest).toEqual([{
  666. num: 17,
  667. gen: 0
  668. }, {
  669. name: 'XYZ'
  670. }, 0, 841.89, null]);
  671. done();
  672. }, done.fail);
  673. });
  674. it('should correctly parse a Dest, which violates the specification ' + 'by containing a dictionary', function (done) {
  675. var destDict = new _primitives.Dict();
  676. destDict.set('Type', _primitives.Name.get('Action'));
  677. destDict.set('S', _primitives.Name.get('GoTo'));
  678. destDict.set('D', 'page.157');
  679. var annotationDict = new _primitives.Dict();
  680. annotationDict.set('Type', _primitives.Name.get('Annot'));
  681. annotationDict.set('Subtype', _primitives.Name.get('Link'));
  682. annotationDict.set('Dest', destDict);
  683. var annotationRef = _primitives.Ref.get(798, 0);
  684. var xref = new _test_utils.XRefMock([{
  685. ref: annotationRef,
  686. data: annotationDict
  687. }]);
  688. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref18) {
  689. var data = _ref18.data;
  690. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  691. expect(data.url).toBeUndefined();
  692. expect(data.unsafeUrl).toBeUndefined();
  693. expect(data.dest).toEqual('page.157');
  694. done();
  695. }, done.fail);
  696. });
  697. });
  698. describe('WidgetAnnotation', function () {
  699. var widgetDict;
  700. beforeEach(function (done) {
  701. widgetDict = new _primitives.Dict();
  702. widgetDict.set('Type', _primitives.Name.get('Annot'));
  703. widgetDict.set('Subtype', _primitives.Name.get('Widget'));
  704. done();
  705. });
  706. afterEach(function () {
  707. widgetDict = null;
  708. });
  709. it('should handle unknown field names', function (done) {
  710. var widgetRef = _primitives.Ref.get(20, 0);
  711. var xref = new _test_utils.XRefMock([{
  712. ref: widgetRef,
  713. data: widgetDict
  714. }]);
  715. _annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock).then(function (_ref19) {
  716. var data = _ref19.data;
  717. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  718. expect(data.fieldName).toEqual('');
  719. done();
  720. }, done.fail);
  721. });
  722. it('should construct the field name when there are no ancestors', function (done) {
  723. widgetDict.set('T', 'foo');
  724. var widgetRef = _primitives.Ref.get(21, 0);
  725. var xref = new _test_utils.XRefMock([{
  726. ref: widgetRef,
  727. data: widgetDict
  728. }]);
  729. _annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock).then(function (_ref20) {
  730. var data = _ref20.data;
  731. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  732. expect(data.fieldName).toEqual('foo');
  733. done();
  734. }, done.fail);
  735. });
  736. it('should construct the field name when there are ancestors', function (done) {
  737. var firstParent = new _primitives.Dict();
  738. firstParent.set('T', 'foo');
  739. var secondParent = new _primitives.Dict();
  740. secondParent.set('Parent', firstParent);
  741. secondParent.set('T', 'bar');
  742. widgetDict.set('Parent', secondParent);
  743. widgetDict.set('T', 'baz');
  744. var widgetRef = _primitives.Ref.get(22, 0);
  745. var xref = new _test_utils.XRefMock([{
  746. ref: widgetRef,
  747. data: widgetDict
  748. }]);
  749. _annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock).then(function (_ref21) {
  750. var data = _ref21.data;
  751. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  752. expect(data.fieldName).toEqual('foo.bar.baz');
  753. done();
  754. }, done.fail);
  755. });
  756. it('should construct the field name if a parent is not a dictionary ' + '(issue 8143)', function (done) {
  757. var parentDict = new _primitives.Dict();
  758. parentDict.set('Parent', null);
  759. parentDict.set('T', 'foo');
  760. widgetDict.set('Parent', parentDict);
  761. widgetDict.set('T', 'bar');
  762. var widgetRef = _primitives.Ref.get(22, 0);
  763. var xref = new _test_utils.XRefMock([{
  764. ref: widgetRef,
  765. data: widgetDict
  766. }]);
  767. _annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock).then(function (_ref22) {
  768. var data = _ref22.data;
  769. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  770. expect(data.fieldName).toEqual('foo.bar');
  771. done();
  772. }, done.fail);
  773. });
  774. });
  775. describe('TextWidgetAnnotation', function () {
  776. var textWidgetDict;
  777. beforeEach(function (done) {
  778. textWidgetDict = new _primitives.Dict();
  779. textWidgetDict.set('Type', _primitives.Name.get('Annot'));
  780. textWidgetDict.set('Subtype', _primitives.Name.get('Widget'));
  781. textWidgetDict.set('FT', _primitives.Name.get('Tx'));
  782. done();
  783. });
  784. afterEach(function () {
  785. textWidgetDict = null;
  786. });
  787. it('should handle unknown text alignment, maximum length and flags', function (done) {
  788. var textWidgetRef = _primitives.Ref.get(124, 0);
  789. var xref = new _test_utils.XRefMock([{
  790. ref: textWidgetRef,
  791. data: textWidgetDict
  792. }]);
  793. _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref23) {
  794. var data = _ref23.data;
  795. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  796. expect(data.textAlignment).toEqual(null);
  797. expect(data.maxLen).toEqual(null);
  798. expect(data.readOnly).toEqual(false);
  799. expect(data.multiLine).toEqual(false);
  800. expect(data.comb).toEqual(false);
  801. done();
  802. }, done.fail);
  803. });
  804. it('should not set invalid text alignment, maximum length and flags', function (done) {
  805. textWidgetDict.set('Q', 'center');
  806. textWidgetDict.set('MaxLen', 'five');
  807. textWidgetDict.set('Ff', 'readonly');
  808. var textWidgetRef = _primitives.Ref.get(43, 0);
  809. var xref = new _test_utils.XRefMock([{
  810. ref: textWidgetRef,
  811. data: textWidgetDict
  812. }]);
  813. _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref24) {
  814. var data = _ref24.data;
  815. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  816. expect(data.textAlignment).toEqual(null);
  817. expect(data.maxLen).toEqual(null);
  818. expect(data.readOnly).toEqual(false);
  819. expect(data.multiLine).toEqual(false);
  820. expect(data.comb).toEqual(false);
  821. done();
  822. }, done.fail);
  823. });
  824. it('should set valid text alignment, maximum length and flags', function (done) {
  825. textWidgetDict.set('Q', 1);
  826. textWidgetDict.set('MaxLen', 20);
  827. textWidgetDict.set('Ff', _util.AnnotationFieldFlag.READONLY + _util.AnnotationFieldFlag.MULTILINE);
  828. var textWidgetRef = _primitives.Ref.get(84, 0);
  829. var xref = new _test_utils.XRefMock([{
  830. ref: textWidgetRef,
  831. data: textWidgetDict
  832. }]);
  833. _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref25) {
  834. var data = _ref25.data;
  835. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  836. expect(data.textAlignment).toEqual(1);
  837. expect(data.maxLen).toEqual(20);
  838. expect(data.readOnly).toEqual(true);
  839. expect(data.multiLine).toEqual(true);
  840. done();
  841. }, done.fail);
  842. });
  843. it('should reject comb fields without a maximum length', function (done) {
  844. textWidgetDict.set('Ff', _util.AnnotationFieldFlag.COMB);
  845. var textWidgetRef = _primitives.Ref.get(46, 0);
  846. var xref = new _test_utils.XRefMock([{
  847. ref: textWidgetRef,
  848. data: textWidgetDict
  849. }]);
  850. _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref26) {
  851. var data = _ref26.data;
  852. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  853. expect(data.comb).toEqual(false);
  854. done();
  855. }, done.fail);
  856. });
  857. it('should accept comb fields with a maximum length', function (done) {
  858. textWidgetDict.set('MaxLen', 20);
  859. textWidgetDict.set('Ff', _util.AnnotationFieldFlag.COMB);
  860. var textWidgetRef = _primitives.Ref.get(46, 0);
  861. var xref = new _test_utils.XRefMock([{
  862. ref: textWidgetRef,
  863. data: textWidgetDict
  864. }]);
  865. _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref27) {
  866. var data = _ref27.data;
  867. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  868. expect(data.comb).toEqual(true);
  869. done();
  870. }, done.fail);
  871. });
  872. it('should only accept comb fields when the flags are valid', function (done) {
  873. var invalidFieldFlags = [_util.AnnotationFieldFlag.MULTILINE, _util.AnnotationFieldFlag.PASSWORD, _util.AnnotationFieldFlag.FILESELECT];
  874. var flags = _util.AnnotationFieldFlag.COMB + _util.AnnotationFieldFlag.MULTILINE + _util.AnnotationFieldFlag.PASSWORD + _util.AnnotationFieldFlag.FILESELECT;
  875. var promise = Promise.resolve();
  876. for (var i = 0, ii = invalidFieldFlags.length; i <= ii; i++) {
  877. promise = promise.then(function () {
  878. textWidgetDict.set('MaxLen', 20);
  879. textWidgetDict.set('Ff', flags);
  880. var textWidgetRef = _primitives.Ref.get(93, 0);
  881. var xref = new _test_utils.XRefMock([{
  882. ref: textWidgetRef,
  883. data: textWidgetDict
  884. }]);
  885. return _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref28) {
  886. var data = _ref28.data;
  887. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  888. var valid = invalidFieldFlags.length === 0;
  889. expect(data.comb).toEqual(valid);
  890. if (!valid) {
  891. flags -= invalidFieldFlags.pop();
  892. }
  893. });
  894. });
  895. }
  896. promise.then(done, done.fail);
  897. });
  898. });
  899. describe('ButtonWidgetAnnotation', function () {
  900. var buttonWidgetDict;
  901. beforeEach(function (done) {
  902. buttonWidgetDict = new _primitives.Dict();
  903. buttonWidgetDict.set('Type', _primitives.Name.get('Annot'));
  904. buttonWidgetDict.set('Subtype', _primitives.Name.get('Widget'));
  905. buttonWidgetDict.set('FT', _primitives.Name.get('Btn'));
  906. done();
  907. });
  908. afterEach(function () {
  909. buttonWidgetDict = null;
  910. });
  911. it('should handle checkboxes with export value', function (done) {
  912. buttonWidgetDict.set('V', _primitives.Name.get('1'));
  913. var appearanceStatesDict = new _primitives.Dict();
  914. var exportValueOptionsDict = new _primitives.Dict();
  915. exportValueOptionsDict.set('Off', 0);
  916. exportValueOptionsDict.set('Checked', 1);
  917. appearanceStatesDict.set('D', exportValueOptionsDict);
  918. buttonWidgetDict.set('AP', appearanceStatesDict);
  919. var buttonWidgetRef = _primitives.Ref.get(124, 0);
  920. var xref = new _test_utils.XRefMock([{
  921. ref: buttonWidgetRef,
  922. data: buttonWidgetDict
  923. }]);
  924. _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref29) {
  925. var data = _ref29.data;
  926. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  927. expect(data.checkBox).toEqual(true);
  928. expect(data.fieldValue).toEqual('1');
  929. expect(data.radioButton).toEqual(false);
  930. expect(data.exportValue).toEqual('Checked');
  931. done();
  932. }, done.fail);
  933. });
  934. it('should handle checkboxes without export value', function (done) {
  935. buttonWidgetDict.set('V', _primitives.Name.get('1'));
  936. var buttonWidgetRef = _primitives.Ref.get(124, 0);
  937. var xref = new _test_utils.XRefMock([{
  938. ref: buttonWidgetRef,
  939. data: buttonWidgetDict
  940. }]);
  941. _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref30) {
  942. var data = _ref30.data;
  943. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  944. expect(data.checkBox).toEqual(true);
  945. expect(data.fieldValue).toEqual('1');
  946. expect(data.radioButton).toEqual(false);
  947. done();
  948. }, done.fail);
  949. });
  950. it('should handle radio buttons with a field value', function (done) {
  951. var parentDict = new _primitives.Dict();
  952. parentDict.set('V', _primitives.Name.get('1'));
  953. var normalAppearanceStateDict = new _primitives.Dict();
  954. normalAppearanceStateDict.set('2', null);
  955. var appearanceStatesDict = new _primitives.Dict();
  956. appearanceStatesDict.set('N', normalAppearanceStateDict);
  957. buttonWidgetDict.set('Ff', _util.AnnotationFieldFlag.RADIO);
  958. buttonWidgetDict.set('Parent', parentDict);
  959. buttonWidgetDict.set('AP', appearanceStatesDict);
  960. var buttonWidgetRef = _primitives.Ref.get(124, 0);
  961. var xref = new _test_utils.XRefMock([{
  962. ref: buttonWidgetRef,
  963. data: buttonWidgetDict
  964. }]);
  965. _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref31) {
  966. var data = _ref31.data;
  967. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  968. expect(data.checkBox).toEqual(false);
  969. expect(data.radioButton).toEqual(true);
  970. expect(data.fieldValue).toEqual('1');
  971. expect(data.buttonValue).toEqual('2');
  972. done();
  973. }, done.fail);
  974. });
  975. it('should handle radio buttons without a field value', function (done) {
  976. var normalAppearanceStateDict = new _primitives.Dict();
  977. normalAppearanceStateDict.set('2', null);
  978. var appearanceStatesDict = new _primitives.Dict();
  979. appearanceStatesDict.set('N', normalAppearanceStateDict);
  980. buttonWidgetDict.set('Ff', _util.AnnotationFieldFlag.RADIO);
  981. buttonWidgetDict.set('AP', appearanceStatesDict);
  982. var buttonWidgetRef = _primitives.Ref.get(124, 0);
  983. var xref = new _test_utils.XRefMock([{
  984. ref: buttonWidgetRef,
  985. data: buttonWidgetDict
  986. }]);
  987. _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref32) {
  988. var data = _ref32.data;
  989. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  990. expect(data.checkBox).toEqual(false);
  991. expect(data.radioButton).toEqual(true);
  992. expect(data.fieldValue).toEqual(null);
  993. expect(data.buttonValue).toEqual('2');
  994. done();
  995. }, done.fail);
  996. });
  997. });
  998. describe('ChoiceWidgetAnnotation', function () {
  999. var choiceWidgetDict;
  1000. beforeEach(function (done) {
  1001. choiceWidgetDict = new _primitives.Dict();
  1002. choiceWidgetDict.set('Type', _primitives.Name.get('Annot'));
  1003. choiceWidgetDict.set('Subtype', _primitives.Name.get('Widget'));
  1004. choiceWidgetDict.set('FT', _primitives.Name.get('Ch'));
  1005. done();
  1006. });
  1007. afterEach(function () {
  1008. choiceWidgetDict = null;
  1009. });
  1010. it('should handle missing option arrays', function (done) {
  1011. var choiceWidgetRef = _primitives.Ref.get(122, 0);
  1012. var xref = new _test_utils.XRefMock([{
  1013. ref: choiceWidgetRef,
  1014. data: choiceWidgetDict
  1015. }]);
  1016. _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref33) {
  1017. var data = _ref33.data;
  1018. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1019. expect(data.options).toEqual([]);
  1020. done();
  1021. }, done.fail);
  1022. });
  1023. it('should handle option arrays with array elements', function (done) {
  1024. var optionBarRef = _primitives.Ref.get(20, 0);
  1025. var optionBarStr = 'Bar';
  1026. var optionOneRef = _primitives.Ref.get(10, 0);
  1027. var optionOneArr = ['bar_export', optionBarRef];
  1028. var options = [['foo_export', 'Foo'], optionOneRef];
  1029. var expected = [{
  1030. exportValue: 'foo_export',
  1031. displayValue: 'Foo'
  1032. }, {
  1033. exportValue: 'bar_export',
  1034. displayValue: 'Bar'
  1035. }];
  1036. choiceWidgetDict.set('Opt', options);
  1037. var choiceWidgetRef = _primitives.Ref.get(123, 0);
  1038. var xref = new _test_utils.XRefMock([{
  1039. ref: choiceWidgetRef,
  1040. data: choiceWidgetDict
  1041. }, {
  1042. ref: optionBarRef,
  1043. data: optionBarStr
  1044. }, {
  1045. ref: optionOneRef,
  1046. data: optionOneArr
  1047. }]);
  1048. _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref34) {
  1049. var data = _ref34.data;
  1050. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1051. expect(data.options).toEqual(expected);
  1052. done();
  1053. }, done.fail);
  1054. });
  1055. it('should handle option arrays with string elements', function (done) {
  1056. var optionBarRef = _primitives.Ref.get(10, 0);
  1057. var optionBarStr = 'Bar';
  1058. var options = ['Foo', optionBarRef];
  1059. var expected = [{
  1060. exportValue: 'Foo',
  1061. displayValue: 'Foo'
  1062. }, {
  1063. exportValue: 'Bar',
  1064. displayValue: 'Bar'
  1065. }];
  1066. choiceWidgetDict.set('Opt', options);
  1067. var choiceWidgetRef = _primitives.Ref.get(981, 0);
  1068. var xref = new _test_utils.XRefMock([{
  1069. ref: choiceWidgetRef,
  1070. data: choiceWidgetDict
  1071. }, {
  1072. ref: optionBarRef,
  1073. data: optionBarStr
  1074. }]);
  1075. _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref35) {
  1076. var data = _ref35.data;
  1077. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1078. expect(data.options).toEqual(expected);
  1079. done();
  1080. }, done.fail);
  1081. });
  1082. it('should handle inherited option arrays (issue 8094)', function (done) {
  1083. var options = [['Value1', 'Description1'], ['Value2', 'Description2']];
  1084. var expected = [{
  1085. exportValue: 'Value1',
  1086. displayValue: 'Description1'
  1087. }, {
  1088. exportValue: 'Value2',
  1089. displayValue: 'Description2'
  1090. }];
  1091. var parentDict = new _primitives.Dict();
  1092. parentDict.set('Opt', options);
  1093. choiceWidgetDict.set('Parent', parentDict);
  1094. var choiceWidgetRef = _primitives.Ref.get(123, 0);
  1095. var xref = new _test_utils.XRefMock([{
  1096. ref: choiceWidgetRef,
  1097. data: choiceWidgetDict
  1098. }]);
  1099. _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref36) {
  1100. var data = _ref36.data;
  1101. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1102. expect(data.options).toEqual(expected);
  1103. done();
  1104. }, done.fail);
  1105. });
  1106. it('should sanitize display values in option arrays (issue 8947)', function (done) {
  1107. var options = ['\xFE\xFF\x00F\x00o\x00o'];
  1108. var expected = [{
  1109. exportValue: '\xFE\xFF\x00F\x00o\x00o',
  1110. displayValue: 'Foo'
  1111. }];
  1112. choiceWidgetDict.set('Opt', options);
  1113. var choiceWidgetRef = _primitives.Ref.get(984, 0);
  1114. var xref = new _test_utils.XRefMock([{
  1115. ref: choiceWidgetRef,
  1116. data: choiceWidgetDict
  1117. }]);
  1118. _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref37) {
  1119. var data = _ref37.data;
  1120. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1121. expect(data.options).toEqual(expected);
  1122. done();
  1123. }, done.fail);
  1124. });
  1125. it('should handle array field values', function (done) {
  1126. var fieldValue = ['Foo', 'Bar'];
  1127. choiceWidgetDict.set('V', fieldValue);
  1128. var choiceWidgetRef = _primitives.Ref.get(968, 0);
  1129. var xref = new _test_utils.XRefMock([{
  1130. ref: choiceWidgetRef,
  1131. data: choiceWidgetDict
  1132. }]);
  1133. _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref38) {
  1134. var data = _ref38.data;
  1135. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1136. expect(data.fieldValue).toEqual(fieldValue);
  1137. done();
  1138. }, done.fail);
  1139. });
  1140. it('should handle string field values', function (done) {
  1141. var fieldValue = 'Foo';
  1142. choiceWidgetDict.set('V', fieldValue);
  1143. var choiceWidgetRef = _primitives.Ref.get(978, 0);
  1144. var xref = new _test_utils.XRefMock([{
  1145. ref: choiceWidgetRef,
  1146. data: choiceWidgetDict
  1147. }]);
  1148. _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref39) {
  1149. var data = _ref39.data;
  1150. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1151. expect(data.fieldValue).toEqual([fieldValue]);
  1152. done();
  1153. }, done.fail);
  1154. });
  1155. it('should handle unknown flags', function (done) {
  1156. var choiceWidgetRef = _primitives.Ref.get(166, 0);
  1157. var xref = new _test_utils.XRefMock([{
  1158. ref: choiceWidgetRef,
  1159. data: choiceWidgetDict
  1160. }]);
  1161. _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref40) {
  1162. var data = _ref40.data;
  1163. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1164. expect(data.readOnly).toEqual(false);
  1165. expect(data.combo).toEqual(false);
  1166. expect(data.multiSelect).toEqual(false);
  1167. done();
  1168. }, done.fail);
  1169. });
  1170. it('should not set invalid flags', function (done) {
  1171. choiceWidgetDict.set('Ff', 'readonly');
  1172. var choiceWidgetRef = _primitives.Ref.get(165, 0);
  1173. var xref = new _test_utils.XRefMock([{
  1174. ref: choiceWidgetRef,
  1175. data: choiceWidgetDict
  1176. }]);
  1177. _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref41) {
  1178. var data = _ref41.data;
  1179. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1180. expect(data.readOnly).toEqual(false);
  1181. expect(data.combo).toEqual(false);
  1182. expect(data.multiSelect).toEqual(false);
  1183. done();
  1184. }, done.fail);
  1185. });
  1186. it('should set valid flags', function (done) {
  1187. choiceWidgetDict.set('Ff', _util.AnnotationFieldFlag.READONLY + _util.AnnotationFieldFlag.COMBO + _util.AnnotationFieldFlag.MULTISELECT);
  1188. var choiceWidgetRef = _primitives.Ref.get(512, 0);
  1189. var xref = new _test_utils.XRefMock([{
  1190. ref: choiceWidgetRef,
  1191. data: choiceWidgetDict
  1192. }]);
  1193. _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref42) {
  1194. var data = _ref42.data;
  1195. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1196. expect(data.readOnly).toEqual(true);
  1197. expect(data.combo).toEqual(true);
  1198. expect(data.multiSelect).toEqual(true);
  1199. done();
  1200. }, done.fail);
  1201. });
  1202. });
  1203. describe('LineAnnotation', function () {
  1204. it('should set the line coordinates', function (done) {
  1205. var lineDict = new _primitives.Dict();
  1206. lineDict.set('Type', _primitives.Name.get('Annot'));
  1207. lineDict.set('Subtype', _primitives.Name.get('Line'));
  1208. lineDict.set('L', [1, 2, 3, 4]);
  1209. var lineRef = _primitives.Ref.get(122, 0);
  1210. var xref = new _test_utils.XRefMock([{
  1211. ref: lineRef,
  1212. data: lineDict
  1213. }]);
  1214. _annotation.AnnotationFactory.create(xref, lineRef, pdfManagerMock, idFactoryMock).then(function (_ref43) {
  1215. var data = _ref43.data;
  1216. expect(data.annotationType).toEqual(_util.AnnotationType.LINE);
  1217. expect(data.lineCoordinates).toEqual([1, 2, 3, 4]);
  1218. done();
  1219. }, done.fail);
  1220. });
  1221. });
  1222. describe('FileAttachmentAnnotation', function () {
  1223. it('should correctly parse a file attachment', function (done) {
  1224. var fileStream = new _stream.StringStream('<<\n' + '/Type /EmbeddedFile\n' + '/Subtype /text#2Fplain\n' + '>>\n' + 'stream\n' + 'Test attachment' + 'endstream\n');
  1225. var parser = new _parser.Parser({
  1226. lexer: new _parser.Lexer(fileStream),
  1227. xref: null,
  1228. allowStreams: true
  1229. });
  1230. var fileStreamRef = _primitives.Ref.get(18, 0);
  1231. var fileStreamDict = parser.getObj();
  1232. var embeddedFileDict = new _primitives.Dict();
  1233. embeddedFileDict.set('F', fileStreamRef);
  1234. var fileSpecRef = _primitives.Ref.get(19, 0);
  1235. var fileSpecDict = new _primitives.Dict();
  1236. fileSpecDict.set('Type', _primitives.Name.get('Filespec'));
  1237. fileSpecDict.set('Desc', '');
  1238. fileSpecDict.set('EF', embeddedFileDict);
  1239. fileSpecDict.set('UF', 'Test.txt');
  1240. var fileAttachmentRef = _primitives.Ref.get(20, 0);
  1241. var fileAttachmentDict = new _primitives.Dict();
  1242. fileAttachmentDict.set('Type', _primitives.Name.get('Annot'));
  1243. fileAttachmentDict.set('Subtype', _primitives.Name.get('FileAttachment'));
  1244. fileAttachmentDict.set('FS', fileSpecRef);
  1245. fileAttachmentDict.set('T', 'Topic');
  1246. fileAttachmentDict.set('Contents', 'Test.txt');
  1247. var xref = new _test_utils.XRefMock([{
  1248. ref: fileStreamRef,
  1249. data: fileStreamDict
  1250. }, {
  1251. ref: fileSpecRef,
  1252. data: fileSpecDict
  1253. }, {
  1254. ref: fileAttachmentRef,
  1255. data: fileAttachmentDict
  1256. }]);
  1257. embeddedFileDict.assignXref(xref);
  1258. fileSpecDict.assignXref(xref);
  1259. fileAttachmentDict.assignXref(xref);
  1260. _annotation.AnnotationFactory.create(xref, fileAttachmentRef, pdfManagerMock, idFactoryMock).then(function (_ref44) {
  1261. var data = _ref44.data;
  1262. expect(data.annotationType).toEqual(_util.AnnotationType.FILEATTACHMENT);
  1263. expect(data.file.filename).toEqual('Test.txt');
  1264. expect(data.file.content).toEqual((0, _util.stringToBytes)('Test attachment'));
  1265. done();
  1266. }, done.fail);
  1267. });
  1268. });
  1269. describe('PopupAnnotation', function () {
  1270. it('should inherit properties from its parent', function (done) {
  1271. var parentDict = new _primitives.Dict();
  1272. parentDict.set('Type', _primitives.Name.get('Annot'));
  1273. parentDict.set('Subtype', _primitives.Name.get('Text'));
  1274. parentDict.set('M', 'D:20190423');
  1275. parentDict.set('C', [0, 0, 1]);
  1276. var popupDict = new _primitives.Dict();
  1277. popupDict.set('Type', _primitives.Name.get('Annot'));
  1278. popupDict.set('Subtype', _primitives.Name.get('Popup'));
  1279. popupDict.set('Parent', parentDict);
  1280. var popupRef = _primitives.Ref.get(13, 0);
  1281. var xref = new _test_utils.XRefMock([{
  1282. ref: popupRef,
  1283. data: popupDict
  1284. }]);
  1285. _annotation.AnnotationFactory.create(xref, popupRef, pdfManagerMock, idFactoryMock).then(function (_ref45) {
  1286. var data = _ref45.data,
  1287. viewable = _ref45.viewable;
  1288. expect(data.annotationType).toEqual(_util.AnnotationType.POPUP);
  1289. expect(data.modificationDate).toEqual('D:20190423');
  1290. expect(data.color).toEqual(new Uint8ClampedArray([0, 0, 255]));
  1291. done();
  1292. }, done.fail);
  1293. });
  1294. it('should handle missing parent properties', function (done) {
  1295. var parentDict = new _primitives.Dict();
  1296. parentDict.set('Type', _primitives.Name.get('Annot'));
  1297. parentDict.set('Subtype', _primitives.Name.get('Text'));
  1298. var popupDict = new _primitives.Dict();
  1299. popupDict.set('Type', _primitives.Name.get('Annot'));
  1300. popupDict.set('Subtype', _primitives.Name.get('Popup'));
  1301. popupDict.set('Parent', parentDict);
  1302. var popupRef = _primitives.Ref.get(13, 0);
  1303. var xref = new _test_utils.XRefMock([{
  1304. ref: popupRef,
  1305. data: popupDict
  1306. }]);
  1307. _annotation.AnnotationFactory.create(xref, popupRef, pdfManagerMock, idFactoryMock).then(function (_ref46) {
  1308. var data = _ref46.data,
  1309. viewable = _ref46.viewable;
  1310. expect(data.annotationType).toEqual(_util.AnnotationType.POPUP);
  1311. expect(data.modificationDate).toEqual(null);
  1312. expect(data.color).toEqual(null);
  1313. done();
  1314. }, done.fail);
  1315. });
  1316. it('should inherit the parent flags when the Popup is not viewable, ' + 'but the parent is (PR 7352)', function (done) {
  1317. var parentDict = new _primitives.Dict();
  1318. parentDict.set('Type', _primitives.Name.get('Annot'));
  1319. parentDict.set('Subtype', _primitives.Name.get('Text'));
  1320. parentDict.set('F', 28);
  1321. var popupDict = new _primitives.Dict();
  1322. popupDict.set('Type', _primitives.Name.get('Annot'));
  1323. popupDict.set('Subtype', _primitives.Name.get('Popup'));
  1324. popupDict.set('F', 25);
  1325. popupDict.set('Parent', parentDict);
  1326. var popupRef = _primitives.Ref.get(13, 0);
  1327. var xref = new _test_utils.XRefMock([{
  1328. ref: popupRef,
  1329. data: popupDict
  1330. }]);
  1331. _annotation.AnnotationFactory.create(xref, popupRef, pdfManagerMock, idFactoryMock).then(function (_ref47) {
  1332. var data = _ref47.data,
  1333. viewable = _ref47.viewable;
  1334. expect(data.annotationType).toEqual(_util.AnnotationType.POPUP);
  1335. expect(data.annotationFlags).toEqual(25);
  1336. expect(viewable).toEqual(true);
  1337. done();
  1338. }, done.fail);
  1339. });
  1340. });
  1341. describe('InkAnnotation', function () {
  1342. it('should handle a single ink list', function (done) {
  1343. var inkDict = new _primitives.Dict();
  1344. inkDict.set('Type', _primitives.Name.get('Annot'));
  1345. inkDict.set('Subtype', _primitives.Name.get('Ink'));
  1346. inkDict.set('InkList', [[1, 1, 1, 2, 2, 2, 3, 3]]);
  1347. var inkRef = _primitives.Ref.get(142, 0);
  1348. var xref = new _test_utils.XRefMock([{
  1349. ref: inkRef,
  1350. data: inkDict
  1351. }]);
  1352. _annotation.AnnotationFactory.create(xref, inkRef, pdfManagerMock, idFactoryMock).then(function (_ref48) {
  1353. var data = _ref48.data;
  1354. expect(data.annotationType).toEqual(_util.AnnotationType.INK);
  1355. expect(data.inkLists.length).toEqual(1);
  1356. expect(data.inkLists[0]).toEqual([{
  1357. x: 1,
  1358. y: 1
  1359. }, {
  1360. x: 1,
  1361. y: 2
  1362. }, {
  1363. x: 2,
  1364. y: 2
  1365. }, {
  1366. x: 3,
  1367. y: 3
  1368. }]);
  1369. done();
  1370. }, done.fail);
  1371. });
  1372. it('should handle multiple ink lists', function (done) {
  1373. var inkDict = new _primitives.Dict();
  1374. inkDict.set('Type', _primitives.Name.get('Annot'));
  1375. inkDict.set('Subtype', _primitives.Name.get('Ink'));
  1376. inkDict.set('InkList', [[1, 1, 1, 2], [3, 3, 4, 5]]);
  1377. var inkRef = _primitives.Ref.get(143, 0);
  1378. var xref = new _test_utils.XRefMock([{
  1379. ref: inkRef,
  1380. data: inkDict
  1381. }]);
  1382. _annotation.AnnotationFactory.create(xref, inkRef, pdfManagerMock, idFactoryMock).then(function (_ref49) {
  1383. var data = _ref49.data;
  1384. expect(data.annotationType).toEqual(_util.AnnotationType.INK);
  1385. expect(data.inkLists.length).toEqual(2);
  1386. expect(data.inkLists[0]).toEqual([{
  1387. x: 1,
  1388. y: 1
  1389. }, {
  1390. x: 1,
  1391. y: 2
  1392. }]);
  1393. expect(data.inkLists[1]).toEqual([{
  1394. x: 3,
  1395. y: 3
  1396. }, {
  1397. x: 4,
  1398. y: 5
  1399. }]);
  1400. done();
  1401. }, done.fail);
  1402. });
  1403. });
  1404. });