How to use AnnotationFactory method in wpt

Best JavaScript code snippet using wpt

annotation_spec.js

Source:annotation_spec.js Github

copy

Full Screen

1/**2 * @licstart The following is the entire license notice for the3 * Javascript code in this page4 *5 * Copyright 2020 Mozilla Foundation6 *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 at10 *11 * http://www.apache.org/licenses/LICENSE-2.012 *13 * Unless required by applicable law or agreed to in writing, software14 * 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 and17 * limitations under the License.18 *19 * @licend The above is the entire license notice for the20 * Javascript code in this page21 */22"use strict";23var _annotation = require("../../core/annotation.js");24var _util = require("../../shared/util.js");25var _test_utils = require("./test_utils.js");26var _primitives = require("../../core/primitives.js");27var _parser = require("../../core/parser.js");28var _stream = require("../../core/stream.js");29describe("annotation", function () {30 class PDFManagerMock {31 constructor(params) {32 this.docBaseUrl = params.docBaseUrl || null;33 }34 ensure(obj, prop, args) {35 return new Promise(function (resolve) {36 const value = obj[prop];37 if (typeof value === "function") {38 resolve(value.apply(obj, args));39 } else {40 resolve(value);41 }42 });43 }44 }45 let pdfManagerMock, idFactoryMock;46 beforeAll(function (done) {47 pdfManagerMock = new PDFManagerMock({48 docBaseUrl: null49 });50 idFactoryMock = (0, _test_utils.createIdFactory)(0);51 done();52 });53 afterAll(function () {54 pdfManagerMock = null;55 idFactoryMock = null;56 });57 describe("AnnotationFactory", function () {58 it("should get id for annotation", function (done) {59 const annotationDict = new _primitives.Dict();60 annotationDict.set("Type", _primitives.Name.get("Annot"));61 annotationDict.set("Subtype", _primitives.Name.get("Link"));62 const annotationRef = _primitives.Ref.get(10, 0);63 const xref = new _test_utils.XRefMock([{64 ref: annotationRef,65 data: annotationDict66 }]);67 _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({68 data69 }) => {70 expect(data.annotationType).toEqual(_util.AnnotationType.LINK);71 expect(data.id).toEqual("10R");72 done();73 }, done.fail);74 });75 it("should handle, and get fallback IDs for, annotations that are not " + "indirect objects (issue 7569)", function (done) {76 const annotationDict = new _primitives.Dict();77 annotationDict.set("Type", _primitives.Name.get("Annot"));78 annotationDict.set("Subtype", _primitives.Name.get("Link"));79 const xref = new _test_utils.XRefMock();80 const idFactory = (0, _test_utils.createIdFactory)(0);81 const annotation1 = _annotation.AnnotationFactory.create(xref, annotationDict, pdfManagerMock, idFactory).then(({82 data83 }) => {84 expect(data.annotationType).toEqual(_util.AnnotationType.LINK);85 expect(data.id).toEqual("annot_p0_1");86 });87 const annotation2 = _annotation.AnnotationFactory.create(xref, annotationDict, pdfManagerMock, idFactory).then(({88 data89 }) => {90 expect(data.annotationType).toEqual(_util.AnnotationType.LINK);91 expect(data.id).toEqual("annot_p0_2");92 });93 Promise.all([annotation1, annotation2]).then(done, done.fail);94 });95 it("should handle missing /Subtype", function (done) {96 const annotationDict = new _primitives.Dict();97 annotationDict.set("Type", _primitives.Name.get("Annot"));98 const annotationRef = _primitives.Ref.get(1, 0);99 const xref = new _test_utils.XRefMock([{100 ref: annotationRef,101 data: annotationDict102 }]);103 _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({104 data105 }) => {106 expect(data.annotationType).toBeUndefined();107 done();108 }, done.fail);109 });110 });111 describe("getQuadPoints", function () {112 let dict, rect;113 beforeEach(function (done) {114 dict = new _primitives.Dict();115 rect = [];116 done();117 });118 afterEach(function () {119 dict = null;120 rect = null;121 });122 it("should ignore missing quadpoints", function () {123 expect((0, _annotation.getQuadPoints)(dict, rect)).toEqual(null);124 });125 it("should ignore non-array values", function () {126 dict.set("QuadPoints", "foo");127 expect((0, _annotation.getQuadPoints)(dict, rect)).toEqual(null);128 });129 it("should ignore arrays where the length is not a multiple of eight", function () {130 dict.set("QuadPoints", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);131 expect((0, _annotation.getQuadPoints)(dict, rect)).toEqual(null);132 });133 it("should ignore quadpoints if one coordinate lies outside the rectangle", function () {134 rect = [10, 10, 20, 20];135 const inputs = [[11, 11, 12, 12, 9, 13, 14, 14], [11, 11, 12, 12, 13, 9, 14, 14], [11, 11, 12, 12, 21, 13, 14, 14], [11, 11, 12, 12, 13, 21, 14, 14]];136 for (const input of inputs) {137 dict.set("QuadPoints", input);138 expect((0, _annotation.getQuadPoints)(dict, rect)).toEqual(null);139 }140 });141 it("should process valid quadpoints arrays", function () {142 rect = [10, 10, 20, 20];143 dict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18]);144 expect((0, _annotation.getQuadPoints)(dict, rect)).toEqual([[{145 x: 11,146 y: 11147 }, {148 x: 12,149 y: 12150 }, {151 x: 13,152 y: 13153 }, {154 x: 14,155 y: 14156 }], [{157 x: 15,158 y: 15159 }, {160 x: 16,161 y: 16162 }, {163 x: 17,164 y: 17165 }, {166 x: 18,167 y: 18168 }]]);169 });170 });171 describe("Annotation", function () {172 let dict, ref;173 beforeAll(function (done) {174 dict = new _primitives.Dict();175 ref = _primitives.Ref.get(1, 0);176 done();177 });178 afterAll(function () {179 dict = ref = null;180 });181 it("should set and get valid contents", function () {182 const annotation = new _annotation.Annotation({183 dict,184 ref185 });186 annotation.setContents("Foo bar baz");187 expect(annotation.contents).toEqual("Foo bar baz");188 });189 it("should not set and get invalid contents", function () {190 const annotation = new _annotation.Annotation({191 dict,192 ref193 });194 annotation.setContents(undefined);195 expect(annotation.contents).toEqual("");196 });197 it("should set and get a valid modification date", function () {198 const annotation = new _annotation.Annotation({199 dict,200 ref201 });202 annotation.setModificationDate("D:20190422");203 expect(annotation.modificationDate).toEqual("D:20190422");204 });205 it("should not set and get an invalid modification date", function () {206 const annotation = new _annotation.Annotation({207 dict,208 ref209 });210 annotation.setModificationDate(undefined);211 expect(annotation.modificationDate).toEqual(null);212 });213 it("should set and get flags", function () {214 const annotation = new _annotation.Annotation({215 dict,216 ref217 });218 annotation.setFlags(13);219 expect(annotation.hasFlag(_util.AnnotationFlag.INVISIBLE)).toEqual(true);220 expect(annotation.hasFlag(_util.AnnotationFlag.NOZOOM)).toEqual(true);221 expect(annotation.hasFlag(_util.AnnotationFlag.PRINT)).toEqual(true);222 expect(annotation.hasFlag(_util.AnnotationFlag.READONLY)).toEqual(false);223 });224 it("should be viewable and not printable by default", function () {225 const annotation = new _annotation.Annotation({226 dict,227 ref228 });229 expect(annotation.viewable).toEqual(true);230 expect(annotation.printable).toEqual(false);231 });232 it("should set and get a valid rectangle", function () {233 const annotation = new _annotation.Annotation({234 dict,235 ref236 });237 annotation.setRectangle([117, 694, 164.298, 720]);238 expect(annotation.rectangle).toEqual([117, 694, 164.298, 720]);239 });240 it("should not set and get an invalid rectangle", function () {241 const annotation = new _annotation.Annotation({242 dict,243 ref244 });245 annotation.setRectangle([117, 694, 164.298]);246 expect(annotation.rectangle).toEqual([0, 0, 0, 0]);247 });248 it("should reject a color if it is not an array", function () {249 const annotation = new _annotation.Annotation({250 dict,251 ref252 });253 annotation.setColor("red");254 expect(annotation.color).toEqual(new Uint8ClampedArray([0, 0, 0]));255 });256 it("should set and get a transparent color", function () {257 const annotation = new _annotation.Annotation({258 dict,259 ref260 });261 annotation.setColor([]);262 expect(annotation.color).toEqual(null);263 });264 it("should set and get a grayscale color", function () {265 const annotation = new _annotation.Annotation({266 dict,267 ref268 });269 annotation.setColor([0.4]);270 expect(annotation.color).toEqual(new Uint8ClampedArray([102, 102, 102]));271 });272 it("should set and get an RGB color", function () {273 const annotation = new _annotation.Annotation({274 dict,275 ref276 });277 annotation.setColor([0, 0, 1]);278 expect(annotation.color).toEqual(new Uint8ClampedArray([0, 0, 255]));279 });280 it("should set and get a CMYK color", function () {281 const annotation = new _annotation.Annotation({282 dict,283 ref284 });285 annotation.setColor([0.1, 0.92, 0.84, 0.02]);286 expect(annotation.color).toEqual(new Uint8ClampedArray([234, 59, 48]));287 });288 it("should not set and get an invalid color", function () {289 const annotation = new _annotation.Annotation({290 dict,291 ref292 });293 annotation.setColor([0.4, 0.6]);294 expect(annotation.color).toEqual(new Uint8ClampedArray([0, 0, 0]));295 });296 });297 describe("AnnotationBorderStyle", function () {298 it("should set and get a valid width", function () {299 const borderStyle = new _annotation.AnnotationBorderStyle();300 borderStyle.setWidth(3);301 expect(borderStyle.width).toEqual(3);302 });303 it("should not set and get an invalid width", function () {304 const borderStyle = new _annotation.AnnotationBorderStyle();305 borderStyle.setWidth("three");306 expect(borderStyle.width).toEqual(1);307 });308 it("should set the width to zero, when the input is a `Name` (issue 10385)", function () {309 const borderStyleZero = new _annotation.AnnotationBorderStyle();310 borderStyleZero.setWidth(_primitives.Name.get("0"));311 const borderStyleFive = new _annotation.AnnotationBorderStyle();312 borderStyleFive.setWidth(_primitives.Name.get("5"));313 expect(borderStyleZero.width).toEqual(0);314 expect(borderStyleFive.width).toEqual(0);315 });316 it("should set and get a valid style", function () {317 const borderStyle = new _annotation.AnnotationBorderStyle();318 borderStyle.setStyle(_primitives.Name.get("D"));319 expect(borderStyle.style).toEqual(_util.AnnotationBorderStyleType.DASHED);320 });321 it("should not set and get an invalid style", function () {322 const borderStyle = new _annotation.AnnotationBorderStyle();323 borderStyle.setStyle("Dashed");324 expect(borderStyle.style).toEqual(_util.AnnotationBorderStyleType.SOLID);325 });326 it("should set and get a valid dash array", function () {327 const borderStyle = new _annotation.AnnotationBorderStyle();328 borderStyle.setDashArray([1, 2, 3]);329 expect(borderStyle.dashArray).toEqual([1, 2, 3]);330 });331 it("should not set and get an invalid dash array", function () {332 const borderStyle = new _annotation.AnnotationBorderStyle();333 borderStyle.setDashArray([0, 0]);334 expect(borderStyle.dashArray).toEqual([3]);335 });336 it("should set and get a valid horizontal corner radius", function () {337 const borderStyle = new _annotation.AnnotationBorderStyle();338 borderStyle.setHorizontalCornerRadius(3);339 expect(borderStyle.horizontalCornerRadius).toEqual(3);340 });341 it("should not set and get an invalid horizontal corner radius", function () {342 const borderStyle = new _annotation.AnnotationBorderStyle();343 borderStyle.setHorizontalCornerRadius("three");344 expect(borderStyle.horizontalCornerRadius).toEqual(0);345 });346 it("should set and get a valid vertical corner radius", function () {347 const borderStyle = new _annotation.AnnotationBorderStyle();348 borderStyle.setVerticalCornerRadius(3);349 expect(borderStyle.verticalCornerRadius).toEqual(3);350 });351 it("should not set and get an invalid vertical corner radius", function () {352 const borderStyle = new _annotation.AnnotationBorderStyle();353 borderStyle.setVerticalCornerRadius("three");354 expect(borderStyle.verticalCornerRadius).toEqual(0);355 });356 });357 describe("MarkupAnnotation", function () {358 let dict, ref;359 beforeAll(function (done) {360 dict = new _primitives.Dict();361 ref = _primitives.Ref.get(1, 0);362 done();363 });364 afterAll(function () {365 dict = ref = null;366 });367 it("should set and get a valid creation date", function () {368 const markupAnnotation = new _annotation.MarkupAnnotation({369 dict,370 ref371 });372 markupAnnotation.setCreationDate("D:20190422");373 expect(markupAnnotation.creationDate).toEqual("D:20190422");374 });375 it("should not set and get an invalid creation date", function () {376 const markupAnnotation = new _annotation.MarkupAnnotation({377 dict,378 ref379 });380 markupAnnotation.setCreationDate(undefined);381 expect(markupAnnotation.creationDate).toEqual(null);382 });383 it("should not parse IRT/RT when not defined", function (done) {384 dict.set("Type", _primitives.Name.get("Annot"));385 dict.set("Subtype", _primitives.Name.get("Text"));386 const xref = new _test_utils.XRefMock([{387 ref,388 data: dict389 }]);390 _annotation.AnnotationFactory.create(xref, ref, pdfManagerMock, idFactoryMock).then(({391 data392 }) => {393 expect(data.inReplyTo).toBeUndefined();394 expect(data.replyType).toBeUndefined();395 done();396 }, done.fail);397 });398 it("should parse IRT and set default RT when not defined.", function (done) {399 const annotationRef = _primitives.Ref.get(819, 0);400 const annotationDict = new _primitives.Dict();401 annotationDict.set("Type", _primitives.Name.get("Annot"));402 annotationDict.set("Subtype", _primitives.Name.get("Text"));403 const replyRef = _primitives.Ref.get(820, 0);404 const replyDict = new _primitives.Dict();405 replyDict.set("Type", _primitives.Name.get("Annot"));406 replyDict.set("Subtype", _primitives.Name.get("Text"));407 replyDict.set("IRT", annotationRef);408 const xref = new _test_utils.XRefMock([{409 ref: annotationRef,410 data: annotationDict411 }, {412 ref: replyRef,413 data: replyDict414 }]);415 annotationDict.assignXref(xref);416 replyDict.assignXref(xref);417 _annotation.AnnotationFactory.create(xref, replyRef, pdfManagerMock, idFactoryMock).then(({418 data419 }) => {420 expect(data.inReplyTo).toEqual(annotationRef.toString());421 expect(data.replyType).toEqual("R");422 done();423 }, done.fail);424 });425 it("should parse IRT/RT for a group type", function (done) {426 const annotationRef = _primitives.Ref.get(819, 0);427 const annotationDict = new _primitives.Dict();428 annotationDict.set("Type", _primitives.Name.get("Annot"));429 annotationDict.set("Subtype", _primitives.Name.get("Text"));430 annotationDict.set("T", "ParentTitle");431 annotationDict.set("Contents", "ParentText");432 annotationDict.set("CreationDate", "D:20180423");433 annotationDict.set("M", "D:20190423");434 annotationDict.set("C", [0, 0, 1]);435 const popupRef = _primitives.Ref.get(820, 0);436 const popupDict = new _primitives.Dict();437 popupDict.set("Type", _primitives.Name.get("Annot"));438 popupDict.set("Subtype", _primitives.Name.get("Popup"));439 popupDict.set("Parent", annotationRef);440 annotationDict.set("Popup", popupRef);441 const replyRef = _primitives.Ref.get(821, 0);442 const replyDict = new _primitives.Dict();443 replyDict.set("Type", _primitives.Name.get("Annot"));444 replyDict.set("Subtype", _primitives.Name.get("Text"));445 replyDict.set("IRT", annotationRef);446 replyDict.set("RT", _primitives.Name.get("Group"));447 replyDict.set("T", "ReplyTitle");448 replyDict.set("Contents", "ReplyText");449 replyDict.set("CreationDate", "D:20180523");450 replyDict.set("M", "D:20190523");451 replyDict.set("C", [0.4]);452 const xref = new _test_utils.XRefMock([{453 ref: annotationRef,454 data: annotationDict455 }, {456 ref: popupRef,457 data: popupDict458 }, {459 ref: replyRef,460 data: replyDict461 }]);462 annotationDict.assignXref(xref);463 popupDict.assignXref(xref);464 replyDict.assignXref(xref);465 _annotation.AnnotationFactory.create(xref, replyRef, pdfManagerMock, idFactoryMock).then(({466 data467 }) => {468 expect(data.inReplyTo).toEqual(annotationRef.toString());469 expect(data.replyType).toEqual("Group");470 expect(data.title).toEqual("ParentTitle");471 expect(data.contents).toEqual("ParentText");472 expect(data.creationDate).toEqual("D:20180423");473 expect(data.modificationDate).toEqual("D:20190423");474 expect(data.color).toEqual(new Uint8ClampedArray([0, 0, 255]));475 expect(data.hasPopup).toEqual(true);476 done();477 }, done.fail);478 });479 it("should parse IRT/RT for a reply type", function (done) {480 const annotationRef = _primitives.Ref.get(819, 0);481 const annotationDict = new _primitives.Dict();482 annotationDict.set("Type", _primitives.Name.get("Annot"));483 annotationDict.set("Subtype", _primitives.Name.get("Text"));484 annotationDict.set("T", "ParentTitle");485 annotationDict.set("Contents", "ParentText");486 annotationDict.set("CreationDate", "D:20180423");487 annotationDict.set("M", "D:20190423");488 annotationDict.set("C", [0, 0, 1]);489 const popupRef = _primitives.Ref.get(820, 0);490 const popupDict = new _primitives.Dict();491 popupDict.set("Type", _primitives.Name.get("Annot"));492 popupDict.set("Subtype", _primitives.Name.get("Popup"));493 popupDict.set("Parent", annotationRef);494 annotationDict.set("Popup", popupRef);495 const replyRef = _primitives.Ref.get(821, 0);496 const replyDict = new _primitives.Dict();497 replyDict.set("Type", _primitives.Name.get("Annot"));498 replyDict.set("Subtype", _primitives.Name.get("Text"));499 replyDict.set("IRT", annotationRef);500 replyDict.set("RT", _primitives.Name.get("R"));501 replyDict.set("T", "ReplyTitle");502 replyDict.set("Contents", "ReplyText");503 replyDict.set("CreationDate", "D:20180523");504 replyDict.set("M", "D:20190523");505 replyDict.set("C", [0.4]);506 const xref = new _test_utils.XRefMock([{507 ref: annotationRef,508 data: annotationDict509 }, {510 ref: popupRef,511 data: popupDict512 }, {513 ref: replyRef,514 data: replyDict515 }]);516 annotationDict.assignXref(xref);517 popupDict.assignXref(xref);518 replyDict.assignXref(xref);519 _annotation.AnnotationFactory.create(xref, replyRef, pdfManagerMock, idFactoryMock).then(({520 data521 }) => {522 expect(data.inReplyTo).toEqual(annotationRef.toString());523 expect(data.replyType).toEqual("R");524 expect(data.title).toEqual("ReplyTitle");525 expect(data.contents).toEqual("ReplyText");526 expect(data.creationDate).toEqual("D:20180523");527 expect(data.modificationDate).toEqual("D:20190523");528 expect(data.color).toEqual(new Uint8ClampedArray([102, 102, 102]));529 expect(data.hasPopup).toEqual(false);530 done();531 }, done.fail);532 });533 });534 describe("TextAnnotation", function () {535 it("should not parse state model and state when not defined", function (done) {536 const annotationRef = _primitives.Ref.get(819, 0);537 const annotationDict = new _primitives.Dict();538 annotationDict.set("Type", _primitives.Name.get("Annot"));539 annotationDict.set("Subtype", _primitives.Name.get("Text"));540 annotationDict.set("Contents", "TestText");541 const replyRef = _primitives.Ref.get(820, 0);542 const replyDict = new _primitives.Dict();543 replyDict.set("Type", _primitives.Name.get("Annot"));544 replyDict.set("Subtype", _primitives.Name.get("Text"));545 replyDict.set("IRT", annotationRef);546 replyDict.set("RT", _primitives.Name.get("R"));547 replyDict.set("Contents", "ReplyText");548 const xref = new _test_utils.XRefMock([{549 ref: annotationRef,550 data: annotationDict551 }, {552 ref: replyRef,553 data: replyDict554 }]);555 annotationDict.assignXref(xref);556 replyDict.assignXref(xref);557 _annotation.AnnotationFactory.create(xref, replyRef, pdfManagerMock, idFactoryMock).then(({558 data559 }) => {560 expect(data.stateModel).toBeNull();561 expect(data.state).toBeNull();562 done();563 }, done.fail);564 });565 it("should correctly parse state model and state when defined", function (done) {566 const annotationRef = _primitives.Ref.get(819, 0);567 const annotationDict = new _primitives.Dict();568 annotationDict.set("Type", _primitives.Name.get("Annot"));569 annotationDict.set("Subtype", _primitives.Name.get("Text"));570 const replyRef = _primitives.Ref.get(820, 0);571 const replyDict = new _primitives.Dict();572 replyDict.set("Type", _primitives.Name.get("Annot"));573 replyDict.set("Subtype", _primitives.Name.get("Text"));574 replyDict.set("IRT", annotationRef);575 replyDict.set("RT", _primitives.Name.get("R"));576 replyDict.set("StateModel", "Review");577 replyDict.set("State", "Rejected");578 const xref = new _test_utils.XRefMock([{579 ref: annotationRef,580 data: annotationDict581 }, {582 ref: replyRef,583 data: replyDict584 }]);585 annotationDict.assignXref(xref);586 replyDict.assignXref(xref);587 _annotation.AnnotationFactory.create(xref, replyRef, pdfManagerMock, idFactoryMock).then(({588 data589 }) => {590 expect(data.stateModel).toEqual("Review");591 expect(data.state).toEqual("Rejected");592 done();593 }, done.fail);594 });595 });596 describe("LinkAnnotation", function () {597 it("should correctly parse a URI action", function (done) {598 const actionDict = new _primitives.Dict();599 actionDict.set("Type", _primitives.Name.get("Action"));600 actionDict.set("S", _primitives.Name.get("URI"));601 actionDict.set("URI", "http://www.ctan.org/tex-archive/info/lshort");602 const annotationDict = new _primitives.Dict();603 annotationDict.set("Type", _primitives.Name.get("Annot"));604 annotationDict.set("Subtype", _primitives.Name.get("Link"));605 annotationDict.set("A", actionDict);606 const annotationRef = _primitives.Ref.get(820, 0);607 const xref = new _test_utils.XRefMock([{608 ref: annotationRef,609 data: annotationDict610 }]);611 _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({612 data613 }) => {614 expect(data.annotationType).toEqual(_util.AnnotationType.LINK);615 expect(data.url).toEqual("http://www.ctan.org/tex-archive/info/lshort");616 expect(data.unsafeUrl).toEqual("http://www.ctan.org/tex-archive/info/lshort");617 expect(data.dest).toBeUndefined();618 done();619 }, done.fail);620 });621 it("should correctly parse a URI action, where the URI entry " + "is missing a protocol", function (done) {622 const actionDict = new _primitives.Dict();623 actionDict.set("Type", _primitives.Name.get("Action"));624 actionDict.set("S", _primitives.Name.get("URI"));625 actionDict.set("URI", "www.hmrc.gov.uk");626 const annotationDict = new _primitives.Dict();627 annotationDict.set("Type", _primitives.Name.get("Annot"));628 annotationDict.set("Subtype", _primitives.Name.get("Link"));629 annotationDict.set("A", actionDict);630 const annotationRef = _primitives.Ref.get(353, 0);631 const xref = new _test_utils.XRefMock([{632 ref: annotationRef,633 data: annotationDict634 }]);635 _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({636 data637 }) => {638 expect(data.annotationType).toEqual(_util.AnnotationType.LINK);639 expect(data.url).toEqual("http://www.hmrc.gov.uk/");640 expect(data.unsafeUrl).toEqual("http://www.hmrc.gov.uk");641 expect(data.dest).toBeUndefined();642 done();643 }, done.fail);644 });645 it("should correctly parse a URI action, where the URI entry " + "has an incorrect encoding (bug 1122280)", function (done) {646 const actionStream = new _stream.StringStream("<<\n" + "/Type /Action\n" + "/S /URI\n" + "/URI (http://www.example.com/\\303\\274\\303\\266\\303\\244)\n" + ">>\n");647 const parser = new _parser.Parser({648 lexer: new _parser.Lexer(actionStream),649 xref: null650 });651 const actionDict = parser.getObj();652 const annotationDict = new _primitives.Dict();653 annotationDict.set("Type", _primitives.Name.get("Annot"));654 annotationDict.set("Subtype", _primitives.Name.get("Link"));655 annotationDict.set("A", actionDict);656 const annotationRef = _primitives.Ref.get(8, 0);657 const xref = new _test_utils.XRefMock([{658 ref: annotationRef,659 data: annotationDict660 }]);661 _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({662 data663 }) => {664 expect(data.annotationType).toEqual(_util.AnnotationType.LINK);665 expect(data.url).toEqual(new URL((0, _util.stringToUTF8String)("http://www.example.com/\xC3\xBC\xC3\xB6\xC3\xA4")).href);666 expect(data.unsafeUrl).toEqual((0, _util.stringToUTF8String)("http://www.example.com/\xC3\xBC\xC3\xB6\xC3\xA4"));667 expect(data.dest).toBeUndefined();668 done();669 }, done.fail);670 });671 it("should correctly parse a GoTo action", function (done) {672 const actionDict = new _primitives.Dict();673 actionDict.set("Type", _primitives.Name.get("Action"));674 actionDict.set("S", _primitives.Name.get("GoTo"));675 actionDict.set("D", "page.157");676 const annotationDict = new _primitives.Dict();677 annotationDict.set("Type", _primitives.Name.get("Annot"));678 annotationDict.set("Subtype", _primitives.Name.get("Link"));679 annotationDict.set("A", actionDict);680 const annotationRef = _primitives.Ref.get(798, 0);681 const xref = new _test_utils.XRefMock([{682 ref: annotationRef,683 data: annotationDict684 }]);685 _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({686 data687 }) => {688 expect(data.annotationType).toEqual(_util.AnnotationType.LINK);689 expect(data.url).toBeUndefined();690 expect(data.unsafeUrl).toBeUndefined();691 expect(data.dest).toEqual("page.157");692 done();693 }, done.fail);694 });695 it("should correctly parse a GoToR action, where the FileSpec entry " + "is a string containing a relative URL", function (done) {696 const actionDict = new _primitives.Dict();697 actionDict.set("Type", _primitives.Name.get("Action"));698 actionDict.set("S", _primitives.Name.get("GoToR"));699 actionDict.set("F", "../../0013/001346/134685E.pdf");700 actionDict.set("D", "4.3");701 actionDict.set("NewWindow", true);702 const annotationDict = new _primitives.Dict();703 annotationDict.set("Type", _primitives.Name.get("Annot"));704 annotationDict.set("Subtype", _primitives.Name.get("Link"));705 annotationDict.set("A", actionDict);706 const annotationRef = _primitives.Ref.get(489, 0);707 const xref = new _test_utils.XRefMock([{708 ref: annotationRef,709 data: annotationDict710 }]);711 _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({712 data713 }) => {714 expect(data.annotationType).toEqual(_util.AnnotationType.LINK);715 expect(data.url).toBeUndefined();716 expect(data.unsafeUrl).toEqual("../../0013/001346/134685E.pdf#4.3");717 expect(data.dest).toBeUndefined();718 expect(data.newWindow).toEqual(true);719 done();720 }, done.fail);721 });722 it("should correctly parse a GoToR action, containing a relative URL, " + 'with the "docBaseUrl" parameter specified', function (done) {723 const actionDict = new _primitives.Dict();724 actionDict.set("Type", _primitives.Name.get("Action"));725 actionDict.set("S", _primitives.Name.get("GoToR"));726 actionDict.set("F", "../../0013/001346/134685E.pdf");727 actionDict.set("D", "4.3");728 const annotationDict = new _primitives.Dict();729 annotationDict.set("Type", _primitives.Name.get("Annot"));730 annotationDict.set("Subtype", _primitives.Name.get("Link"));731 annotationDict.set("A", actionDict);732 const annotationRef = _primitives.Ref.get(489, 0);733 const xref = new _test_utils.XRefMock([{734 ref: annotationRef,735 data: annotationDict736 }]);737 const pdfManager = new PDFManagerMock({738 docBaseUrl: "http://www.example.com/test/pdfs/qwerty.pdf"739 });740 _annotation.AnnotationFactory.create(xref, annotationRef, pdfManager, idFactoryMock).then(({741 data742 }) => {743 expect(data.annotationType).toEqual(_util.AnnotationType.LINK);744 expect(data.url).toEqual("http://www.example.com/0013/001346/134685E.pdf#4.3");745 expect(data.unsafeUrl).toEqual("../../0013/001346/134685E.pdf#4.3");746 expect(data.dest).toBeUndefined();747 done();748 }, done.fail);749 });750 it("should correctly parse a GoToR action, with named destination", function (done) {751 const actionDict = new _primitives.Dict();752 actionDict.set("Type", _primitives.Name.get("Action"));753 actionDict.set("S", _primitives.Name.get("GoToR"));754 actionDict.set("F", "http://www.example.com/test.pdf");755 actionDict.set("D", "15");756 const annotationDict = new _primitives.Dict();757 annotationDict.set("Type", _primitives.Name.get("Annot"));758 annotationDict.set("Subtype", _primitives.Name.get("Link"));759 annotationDict.set("A", actionDict);760 const annotationRef = _primitives.Ref.get(495, 0);761 const xref = new _test_utils.XRefMock([{762 ref: annotationRef,763 data: annotationDict764 }]);765 _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({766 data767 }) => {768 expect(data.annotationType).toEqual(_util.AnnotationType.LINK);769 expect(data.url).toEqual("http://www.example.com/test.pdf#15");770 expect(data.unsafeUrl).toEqual("http://www.example.com/test.pdf#15");771 expect(data.dest).toBeUndefined();772 expect(data.newWindow).toBeFalsy();773 done();774 }, done.fail);775 });776 it("should correctly parse a GoToR action, with explicit destination array", function (done) {777 const actionDict = new _primitives.Dict();778 actionDict.set("Type", _primitives.Name.get("Action"));779 actionDict.set("S", _primitives.Name.get("GoToR"));780 actionDict.set("F", "http://www.example.com/test.pdf");781 actionDict.set("D", [14, _primitives.Name.get("XYZ"), null, 298.043, null]);782 const annotationDict = new _primitives.Dict();783 annotationDict.set("Type", _primitives.Name.get("Annot"));784 annotationDict.set("Subtype", _primitives.Name.get("Link"));785 annotationDict.set("A", actionDict);786 const annotationRef = _primitives.Ref.get(489, 0);787 const xref = new _test_utils.XRefMock([{788 ref: annotationRef,789 data: annotationDict790 }]);791 _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({792 data793 }) => {794 expect(data.annotationType).toEqual(_util.AnnotationType.LINK);795 expect(data.url).toEqual(new URL("http://www.example.com/test.pdf#" + '[14,{"name":"XYZ"},null,298.043,null]').href);796 expect(data.unsafeUrl).toEqual("http://www.example.com/test.pdf#" + '[14,{"name":"XYZ"},null,298.043,null]');797 expect(data.dest).toBeUndefined();798 expect(data.newWindow).toBeFalsy();799 done();800 }, done.fail);801 });802 it("should correctly parse a Launch action, where the FileSpec dict " + 'contains a relative URL, with the "docBaseUrl" parameter specified', function (done) {803 const fileSpecDict = new _primitives.Dict();804 fileSpecDict.set("Type", _primitives.Name.get("FileSpec"));805 fileSpecDict.set("F", "Part II/Part II.pdf");806 fileSpecDict.set("UF", "Part II/Part II.pdf");807 const actionDict = new _primitives.Dict();808 actionDict.set("Type", _primitives.Name.get("Action"));809 actionDict.set("S", _primitives.Name.get("Launch"));810 actionDict.set("F", fileSpecDict);811 actionDict.set("NewWindow", true);812 const annotationDict = new _primitives.Dict();813 annotationDict.set("Type", _primitives.Name.get("Annot"));814 annotationDict.set("Subtype", _primitives.Name.get("Link"));815 annotationDict.set("A", actionDict);816 const annotationRef = _primitives.Ref.get(88, 0);817 const xref = new _test_utils.XRefMock([{818 ref: annotationRef,819 data: annotationDict820 }]);821 const pdfManager = new PDFManagerMock({822 docBaseUrl: "http://www.example.com/test/pdfs/qwerty.pdf"823 });824 _annotation.AnnotationFactory.create(xref, annotationRef, pdfManager, idFactoryMock).then(({825 data826 }) => {827 expect(data.annotationType).toEqual(_util.AnnotationType.LINK);828 expect(data.url).toEqual(new URL("http://www.example.com/test/pdfs/Part II/Part II.pdf").href);829 expect(data.unsafeUrl).toEqual("Part II/Part II.pdf");830 expect(data.dest).toBeUndefined();831 expect(data.newWindow).toEqual(true);832 done();833 }, done.fail);834 });835 it("should recover valid URLs from JavaScript actions having certain " + "white-listed formats", function (done) {836 function checkJsAction(params) {837 const jsEntry = params.jsEntry;838 const expectedUrl = params.expectedUrl;839 const expectedUnsafeUrl = params.expectedUnsafeUrl;840 const expectedNewWindow = params.expectedNewWindow;841 const actionDict = new _primitives.Dict();842 actionDict.set("Type", _primitives.Name.get("Action"));843 actionDict.set("S", _primitives.Name.get("JavaScript"));844 actionDict.set("JS", jsEntry);845 const annotationDict = new _primitives.Dict();846 annotationDict.set("Type", _primitives.Name.get("Annot"));847 annotationDict.set("Subtype", _primitives.Name.get("Link"));848 annotationDict.set("A", actionDict);849 const annotationRef = _primitives.Ref.get(46, 0);850 const xref = new _test_utils.XRefMock([{851 ref: annotationRef,852 data: annotationDict853 }]);854 return _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({855 data856 }) => {857 expect(data.annotationType).toEqual(_util.AnnotationType.LINK);858 expect(data.url).toEqual(expectedUrl);859 expect(data.unsafeUrl).toEqual(expectedUnsafeUrl);860 expect(data.dest).toBeUndefined();861 expect(data.newWindow).toEqual(expectedNewWindow);862 });863 }864 const annotation1 = checkJsAction({865 jsEntry: 'function someFun() { return "qwerty"; } someFun();',866 expectedUrl: undefined,867 expectedUnsafeUrl: undefined,868 expectedNewWindow: undefined869 });870 const annotation2 = checkJsAction({871 jsEntry: "window.open('http://www.example.com/test.pdf')",872 expectedUrl: new URL("http://www.example.com/test.pdf").href,873 expectedUnsafeUrl: "http://www.example.com/test.pdf",874 expectedNewWindow: undefined875 });876 const annotation3 = checkJsAction({877 jsEntry: new _stream.StringStream('app.launchURL("http://www.example.com/test.pdf", true)'),878 expectedUrl: new URL("http://www.example.com/test.pdf").href,879 expectedUnsafeUrl: "http://www.example.com/test.pdf",880 expectedNewWindow: true881 });882 Promise.all([annotation1, annotation2, annotation3]).then(done, done.fail);883 });884 it("should correctly parse a Named action", function (done) {885 const actionDict = new _primitives.Dict();886 actionDict.set("Type", _primitives.Name.get("Action"));887 actionDict.set("S", _primitives.Name.get("Named"));888 actionDict.set("N", _primitives.Name.get("GoToPage"));889 const annotationDict = new _primitives.Dict();890 annotationDict.set("Type", _primitives.Name.get("Annot"));891 annotationDict.set("Subtype", _primitives.Name.get("Link"));892 annotationDict.set("A", actionDict);893 const annotationRef = _primitives.Ref.get(12, 0);894 const xref = new _test_utils.XRefMock([{895 ref: annotationRef,896 data: annotationDict897 }]);898 _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({899 data900 }) => {901 expect(data.annotationType).toEqual(_util.AnnotationType.LINK);902 expect(data.url).toBeUndefined();903 expect(data.unsafeUrl).toBeUndefined();904 expect(data.action).toEqual("GoToPage");905 done();906 }, done.fail);907 });908 it("should correctly parse a simple Dest", function (done) {909 const annotationDict = new _primitives.Dict();910 annotationDict.set("Type", _primitives.Name.get("Annot"));911 annotationDict.set("Subtype", _primitives.Name.get("Link"));912 annotationDict.set("Dest", _primitives.Name.get("LI0"));913 const annotationRef = _primitives.Ref.get(583, 0);914 const xref = new _test_utils.XRefMock([{915 ref: annotationRef,916 data: annotationDict917 }]);918 _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({919 data920 }) => {921 expect(data.annotationType).toEqual(_util.AnnotationType.LINK);922 expect(data.url).toBeUndefined();923 expect(data.unsafeUrl).toBeUndefined();924 expect(data.dest).toEqual("LI0");925 done();926 }, done.fail);927 });928 it("should correctly parse a simple Dest, with explicit destination array", function (done) {929 const annotationDict = new _primitives.Dict();930 annotationDict.set("Type", _primitives.Name.get("Annot"));931 annotationDict.set("Subtype", _primitives.Name.get("Link"));932 annotationDict.set("Dest", [_primitives.Ref.get(17, 0), _primitives.Name.get("XYZ"), 0, 841.89, null]);933 const annotationRef = _primitives.Ref.get(10, 0);934 const xref = new _test_utils.XRefMock([{935 ref: annotationRef,936 data: annotationDict937 }]);938 _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({939 data940 }) => {941 expect(data.annotationType).toEqual(_util.AnnotationType.LINK);942 expect(data.url).toBeUndefined();943 expect(data.unsafeUrl).toBeUndefined();944 expect(data.dest).toEqual([{945 num: 17,946 gen: 0947 }, {948 name: "XYZ"949 }, 0, 841.89, null]);950 done();951 }, done.fail);952 });953 it("should correctly parse a Dest, which violates the specification " + "by containing a dictionary", function (done) {954 const destDict = new _primitives.Dict();955 destDict.set("Type", _primitives.Name.get("Action"));956 destDict.set("S", _primitives.Name.get("GoTo"));957 destDict.set("D", "page.157");958 const annotationDict = new _primitives.Dict();959 annotationDict.set("Type", _primitives.Name.get("Annot"));960 annotationDict.set("Subtype", _primitives.Name.get("Link"));961 annotationDict.set("Dest", destDict);962 const annotationRef = _primitives.Ref.get(798, 0);963 const xref = new _test_utils.XRefMock([{964 ref: annotationRef,965 data: annotationDict966 }]);967 _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({968 data969 }) => {970 expect(data.annotationType).toEqual(_util.AnnotationType.LINK);971 expect(data.url).toBeUndefined();972 expect(data.unsafeUrl).toBeUndefined();973 expect(data.dest).toEqual("page.157");974 done();975 }, done.fail);976 });977 it("should not set quadpoints if not defined", function (done) {978 const annotationDict = new _primitives.Dict();979 annotationDict.set("Type", _primitives.Name.get("Annot"));980 annotationDict.set("Subtype", _primitives.Name.get("Link"));981 const annotationRef = _primitives.Ref.get(121, 0);982 const xref = new _test_utils.XRefMock([{983 ref: annotationRef,984 data: annotationDict985 }]);986 _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({987 data988 }) => {989 expect(data.annotationType).toEqual(_util.AnnotationType.LINK);990 expect(data.quadPoints).toBeUndefined();991 done();992 }, done.fail);993 });994 it("should set quadpoints if defined", function (done) {995 const annotationDict = new _primitives.Dict();996 annotationDict.set("Type", _primitives.Name.get("Annot"));997 annotationDict.set("Subtype", _primitives.Name.get("Link"));998 annotationDict.set("Rect", [10, 10, 20, 20]);999 annotationDict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14]);1000 const annotationRef = _primitives.Ref.get(121, 0);1001 const xref = new _test_utils.XRefMock([{1002 ref: annotationRef,1003 data: annotationDict1004 }]);1005 _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({1006 data1007 }) => {1008 expect(data.annotationType).toEqual(_util.AnnotationType.LINK);1009 expect(data.quadPoints).toEqual([[{1010 x: 11,1011 y: 111012 }, {1013 x: 12,1014 y: 121015 }, {1016 x: 13,1017 y: 131018 }, {1019 x: 14,1020 y: 141021 }]]);1022 done();1023 }, done.fail);1024 });1025 });1026 describe("WidgetAnnotation", function () {1027 let widgetDict;1028 beforeEach(function (done) {1029 widgetDict = new _primitives.Dict();1030 widgetDict.set("Type", _primitives.Name.get("Annot"));1031 widgetDict.set("Subtype", _primitives.Name.get("Widget"));1032 done();1033 });1034 afterEach(function () {1035 widgetDict = null;1036 });1037 it("should handle unknown field names", function (done) {1038 const widgetRef = _primitives.Ref.get(20, 0);1039 const xref = new _test_utils.XRefMock([{1040 ref: widgetRef,1041 data: widgetDict1042 }]);1043 _annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock).then(({1044 data1045 }) => {1046 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1047 expect(data.fieldName).toEqual("");1048 done();1049 }, done.fail);1050 });1051 it("should construct the field name when there are no ancestors", function (done) {1052 widgetDict.set("T", "foo");1053 const widgetRef = _primitives.Ref.get(21, 0);1054 const xref = new _test_utils.XRefMock([{1055 ref: widgetRef,1056 data: widgetDict1057 }]);1058 _annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock).then(({1059 data1060 }) => {1061 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1062 expect(data.fieldName).toEqual("foo");1063 done();1064 }, done.fail);1065 });1066 it("should construct the field name when there are ancestors", function (done) {1067 const firstParent = new _primitives.Dict();1068 firstParent.set("T", "foo");1069 const secondParent = new _primitives.Dict();1070 secondParent.set("Parent", firstParent);1071 secondParent.set("T", "bar");1072 widgetDict.set("Parent", secondParent);1073 widgetDict.set("T", "baz");1074 const widgetRef = _primitives.Ref.get(22, 0);1075 const xref = new _test_utils.XRefMock([{1076 ref: widgetRef,1077 data: widgetDict1078 }]);1079 _annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock).then(({1080 data1081 }) => {1082 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1083 expect(data.fieldName).toEqual("foo.bar.baz");1084 done();1085 }, done.fail);1086 });1087 it("should construct the field name if a parent is not a dictionary " + "(issue 8143)", function (done) {1088 const parentDict = new _primitives.Dict();1089 parentDict.set("Parent", null);1090 parentDict.set("T", "foo");1091 widgetDict.set("Parent", parentDict);1092 widgetDict.set("T", "bar");1093 const widgetRef = _primitives.Ref.get(22, 0);1094 const xref = new _test_utils.XRefMock([{1095 ref: widgetRef,1096 data: widgetDict1097 }]);1098 _annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock).then(({1099 data1100 }) => {1101 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1102 expect(data.fieldName).toEqual("foo.bar");1103 done();1104 }, done.fail);1105 });1106 });1107 describe("TextWidgetAnnotation", function () {1108 let textWidgetDict;1109 beforeEach(function (done) {1110 textWidgetDict = new _primitives.Dict();1111 textWidgetDict.set("Type", _primitives.Name.get("Annot"));1112 textWidgetDict.set("Subtype", _primitives.Name.get("Widget"));1113 textWidgetDict.set("FT", _primitives.Name.get("Tx"));1114 done();1115 });1116 afterEach(function () {1117 textWidgetDict = null;1118 });1119 it("should handle unknown text alignment, maximum length and flags", function (done) {1120 const textWidgetRef = _primitives.Ref.get(124, 0);1121 const xref = new _test_utils.XRefMock([{1122 ref: textWidgetRef,1123 data: textWidgetDict1124 }]);1125 _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(({1126 data1127 }) => {1128 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1129 expect(data.textAlignment).toEqual(null);1130 expect(data.maxLen).toEqual(null);1131 expect(data.readOnly).toEqual(false);1132 expect(data.multiLine).toEqual(false);1133 expect(data.comb).toEqual(false);1134 done();1135 }, done.fail);1136 });1137 it("should not set invalid text alignment, maximum length and flags", function (done) {1138 textWidgetDict.set("Q", "center");1139 textWidgetDict.set("MaxLen", "five");1140 textWidgetDict.set("Ff", "readonly");1141 const textWidgetRef = _primitives.Ref.get(43, 0);1142 const xref = new _test_utils.XRefMock([{1143 ref: textWidgetRef,1144 data: textWidgetDict1145 }]);1146 _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(({1147 data1148 }) => {1149 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1150 expect(data.textAlignment).toEqual(null);1151 expect(data.maxLen).toEqual(null);1152 expect(data.readOnly).toEqual(false);1153 expect(data.multiLine).toEqual(false);1154 expect(data.comb).toEqual(false);1155 done();1156 }, done.fail);1157 });1158 it("should set valid text alignment, maximum length and flags", function (done) {1159 textWidgetDict.set("Q", 1);1160 textWidgetDict.set("MaxLen", 20);1161 textWidgetDict.set("Ff", _util.AnnotationFieldFlag.READONLY + _util.AnnotationFieldFlag.MULTILINE);1162 const textWidgetRef = _primitives.Ref.get(84, 0);1163 const xref = new _test_utils.XRefMock([{1164 ref: textWidgetRef,1165 data: textWidgetDict1166 }]);1167 _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(({1168 data1169 }) => {1170 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1171 expect(data.textAlignment).toEqual(1);1172 expect(data.maxLen).toEqual(20);1173 expect(data.readOnly).toEqual(true);1174 expect(data.multiLine).toEqual(true);1175 done();1176 }, done.fail);1177 });1178 it("should reject comb fields without a maximum length", function (done) {1179 textWidgetDict.set("Ff", _util.AnnotationFieldFlag.COMB);1180 const textWidgetRef = _primitives.Ref.get(46, 0);1181 const xref = new _test_utils.XRefMock([{1182 ref: textWidgetRef,1183 data: textWidgetDict1184 }]);1185 _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(({1186 data1187 }) => {1188 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1189 expect(data.comb).toEqual(false);1190 done();1191 }, done.fail);1192 });1193 it("should accept comb fields with a maximum length", function (done) {1194 textWidgetDict.set("MaxLen", 20);1195 textWidgetDict.set("Ff", _util.AnnotationFieldFlag.COMB);1196 const textWidgetRef = _primitives.Ref.get(46, 0);1197 const xref = new _test_utils.XRefMock([{1198 ref: textWidgetRef,1199 data: textWidgetDict1200 }]);1201 _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(({1202 data1203 }) => {1204 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1205 expect(data.comb).toEqual(true);1206 done();1207 }, done.fail);1208 });1209 it("should only accept comb fields when the flags are valid", function (done) {1210 const invalidFieldFlags = [_util.AnnotationFieldFlag.MULTILINE, _util.AnnotationFieldFlag.PASSWORD, _util.AnnotationFieldFlag.FILESELECT];1211 let flags = _util.AnnotationFieldFlag.COMB + _util.AnnotationFieldFlag.MULTILINE + _util.AnnotationFieldFlag.PASSWORD + _util.AnnotationFieldFlag.FILESELECT;1212 let promise = Promise.resolve();1213 for (let i = 0, ii = invalidFieldFlags.length; i <= ii; i++) {1214 promise = promise.then(() => {1215 textWidgetDict.set("MaxLen", 20);1216 textWidgetDict.set("Ff", flags);1217 const textWidgetRef = _primitives.Ref.get(93, 0);1218 const xref = new _test_utils.XRefMock([{1219 ref: textWidgetRef,1220 data: textWidgetDict1221 }]);1222 return _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(({1223 data1224 }) => {1225 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1226 const valid = invalidFieldFlags.length === 0;1227 expect(data.comb).toEqual(valid);1228 if (!valid) {1229 flags -= invalidFieldFlags.pop();1230 }1231 });1232 });1233 }1234 promise.then(done, done.fail);1235 });1236 });1237 describe("ButtonWidgetAnnotation", function () {1238 let buttonWidgetDict;1239 beforeEach(function (done) {1240 buttonWidgetDict = new _primitives.Dict();1241 buttonWidgetDict.set("Type", _primitives.Name.get("Annot"));1242 buttonWidgetDict.set("Subtype", _primitives.Name.get("Widget"));1243 buttonWidgetDict.set("FT", _primitives.Name.get("Btn"));1244 done();1245 });1246 afterEach(function () {1247 buttonWidgetDict = null;1248 });1249 it("should handle checkboxes with export value", function (done) {1250 buttonWidgetDict.set("V", _primitives.Name.get("1"));1251 const appearanceStatesDict = new _primitives.Dict();1252 const exportValueOptionsDict = new _primitives.Dict();1253 exportValueOptionsDict.set("Off", 0);1254 exportValueOptionsDict.set("Checked", 1);1255 appearanceStatesDict.set("D", exportValueOptionsDict);1256 buttonWidgetDict.set("AP", appearanceStatesDict);1257 const buttonWidgetRef = _primitives.Ref.get(124, 0);1258 const xref = new _test_utils.XRefMock([{1259 ref: buttonWidgetRef,1260 data: buttonWidgetDict1261 }]);1262 _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(({1263 data1264 }) => {1265 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1266 expect(data.checkBox).toEqual(true);1267 expect(data.fieldValue).toEqual("1");1268 expect(data.radioButton).toEqual(false);1269 expect(data.exportValue).toEqual("Checked");1270 done();1271 }, done.fail);1272 });1273 it("should handle checkboxes without export value", function (done) {1274 buttonWidgetDict.set("V", _primitives.Name.get("1"));1275 const buttonWidgetRef = _primitives.Ref.get(124, 0);1276 const xref = new _test_utils.XRefMock([{1277 ref: buttonWidgetRef,1278 data: buttonWidgetDict1279 }]);1280 _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(({1281 data1282 }) => {1283 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1284 expect(data.checkBox).toEqual(true);1285 expect(data.fieldValue).toEqual("1");1286 expect(data.radioButton).toEqual(false);1287 done();1288 }, done.fail);1289 });1290 it("should handle radio buttons with a field value", function (done) {1291 const parentDict = new _primitives.Dict();1292 parentDict.set("V", _primitives.Name.get("1"));1293 const normalAppearanceStateDict = new _primitives.Dict();1294 normalAppearanceStateDict.set("2", null);1295 const appearanceStatesDict = new _primitives.Dict();1296 appearanceStatesDict.set("N", normalAppearanceStateDict);1297 buttonWidgetDict.set("Ff", _util.AnnotationFieldFlag.RADIO);1298 buttonWidgetDict.set("Parent", parentDict);1299 buttonWidgetDict.set("AP", appearanceStatesDict);1300 const buttonWidgetRef = _primitives.Ref.get(124, 0);1301 const xref = new _test_utils.XRefMock([{1302 ref: buttonWidgetRef,1303 data: buttonWidgetDict1304 }]);1305 _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(({1306 data1307 }) => {1308 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1309 expect(data.checkBox).toEqual(false);1310 expect(data.radioButton).toEqual(true);1311 expect(data.fieldValue).toEqual("1");1312 expect(data.buttonValue).toEqual("2");1313 done();1314 }, done.fail);1315 });1316 it("should handle radio buttons without a field value", function (done) {1317 const normalAppearanceStateDict = new _primitives.Dict();1318 normalAppearanceStateDict.set("2", null);1319 const appearanceStatesDict = new _primitives.Dict();1320 appearanceStatesDict.set("N", normalAppearanceStateDict);1321 buttonWidgetDict.set("Ff", _util.AnnotationFieldFlag.RADIO);1322 buttonWidgetDict.set("AP", appearanceStatesDict);1323 const buttonWidgetRef = _primitives.Ref.get(124, 0);1324 const xref = new _test_utils.XRefMock([{1325 ref: buttonWidgetRef,1326 data: buttonWidgetDict1327 }]);1328 _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(({1329 data1330 }) => {1331 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1332 expect(data.checkBox).toEqual(false);1333 expect(data.radioButton).toEqual(true);1334 expect(data.fieldValue).toEqual(null);1335 expect(data.buttonValue).toEqual("2");1336 done();1337 }, done.fail);1338 });1339 });1340 describe("ChoiceWidgetAnnotation", function () {1341 let choiceWidgetDict;1342 beforeEach(function (done) {1343 choiceWidgetDict = new _primitives.Dict();1344 choiceWidgetDict.set("Type", _primitives.Name.get("Annot"));1345 choiceWidgetDict.set("Subtype", _primitives.Name.get("Widget"));1346 choiceWidgetDict.set("FT", _primitives.Name.get("Ch"));1347 done();1348 });1349 afterEach(function () {1350 choiceWidgetDict = null;1351 });1352 it("should handle missing option arrays", function (done) {1353 const choiceWidgetRef = _primitives.Ref.get(122, 0);1354 const xref = new _test_utils.XRefMock([{1355 ref: choiceWidgetRef,1356 data: choiceWidgetDict1357 }]);1358 _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({1359 data1360 }) => {1361 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1362 expect(data.options).toEqual([]);1363 done();1364 }, done.fail);1365 });1366 it("should handle option arrays with array elements", function (done) {1367 const optionBarRef = _primitives.Ref.get(20, 0);1368 const optionBarStr = "Bar";1369 const optionOneRef = _primitives.Ref.get(10, 0);1370 const optionOneArr = ["bar_export", optionBarRef];1371 const options = [["foo_export", "Foo"], optionOneRef];1372 const expected = [{1373 exportValue: "foo_export",1374 displayValue: "Foo"1375 }, {1376 exportValue: "bar_export",1377 displayValue: "Bar"1378 }];1379 choiceWidgetDict.set("Opt", options);1380 const choiceWidgetRef = _primitives.Ref.get(123, 0);1381 const xref = new _test_utils.XRefMock([{1382 ref: choiceWidgetRef,1383 data: choiceWidgetDict1384 }, {1385 ref: optionBarRef,1386 data: optionBarStr1387 }, {1388 ref: optionOneRef,1389 data: optionOneArr1390 }]);1391 _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({1392 data1393 }) => {1394 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1395 expect(data.options).toEqual(expected);1396 done();1397 }, done.fail);1398 });1399 it("should handle option arrays with string elements", function (done) {1400 const optionBarRef = _primitives.Ref.get(10, 0);1401 const optionBarStr = "Bar";1402 const options = ["Foo", optionBarRef];1403 const expected = [{1404 exportValue: "Foo",1405 displayValue: "Foo"1406 }, {1407 exportValue: "Bar",1408 displayValue: "Bar"1409 }];1410 choiceWidgetDict.set("Opt", options);1411 const choiceWidgetRef = _primitives.Ref.get(981, 0);1412 const xref = new _test_utils.XRefMock([{1413 ref: choiceWidgetRef,1414 data: choiceWidgetDict1415 }, {1416 ref: optionBarRef,1417 data: optionBarStr1418 }]);1419 _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({1420 data1421 }) => {1422 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1423 expect(data.options).toEqual(expected);1424 done();1425 }, done.fail);1426 });1427 it("should handle inherited option arrays (issue 8094)", function (done) {1428 const options = [["Value1", "Description1"], ["Value2", "Description2"]];1429 const expected = [{1430 exportValue: "Value1",1431 displayValue: "Description1"1432 }, {1433 exportValue: "Value2",1434 displayValue: "Description2"1435 }];1436 const parentDict = new _primitives.Dict();1437 parentDict.set("Opt", options);1438 choiceWidgetDict.set("Parent", parentDict);1439 const choiceWidgetRef = _primitives.Ref.get(123, 0);1440 const xref = new _test_utils.XRefMock([{1441 ref: choiceWidgetRef,1442 data: choiceWidgetDict1443 }]);1444 _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({1445 data1446 }) => {1447 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1448 expect(data.options).toEqual(expected);1449 done();1450 }, done.fail);1451 });1452 it("should sanitize display values in option arrays (issue 8947)", function (done) {1453 const options = ["\xFE\xFF\x00F\x00o\x00o"];1454 const expected = [{1455 exportValue: "\xFE\xFF\x00F\x00o\x00o",1456 displayValue: "Foo"1457 }];1458 choiceWidgetDict.set("Opt", options);1459 const choiceWidgetRef = _primitives.Ref.get(984, 0);1460 const xref = new _test_utils.XRefMock([{1461 ref: choiceWidgetRef,1462 data: choiceWidgetDict1463 }]);1464 _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({1465 data1466 }) => {1467 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1468 expect(data.options).toEqual(expected);1469 done();1470 }, done.fail);1471 });1472 it("should handle array field values", function (done) {1473 const fieldValue = ["Foo", "Bar"];1474 choiceWidgetDict.set("V", fieldValue);1475 const choiceWidgetRef = _primitives.Ref.get(968, 0);1476 const xref = new _test_utils.XRefMock([{1477 ref: choiceWidgetRef,1478 data: choiceWidgetDict1479 }]);1480 _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({1481 data1482 }) => {1483 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1484 expect(data.fieldValue).toEqual(fieldValue);1485 done();1486 }, done.fail);1487 });1488 it("should handle string field values", function (done) {1489 const fieldValue = "Foo";1490 choiceWidgetDict.set("V", fieldValue);1491 const choiceWidgetRef = _primitives.Ref.get(978, 0);1492 const xref = new _test_utils.XRefMock([{1493 ref: choiceWidgetRef,1494 data: choiceWidgetDict1495 }]);1496 _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({1497 data1498 }) => {1499 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1500 expect(data.fieldValue).toEqual([fieldValue]);1501 done();1502 }, done.fail);1503 });1504 it("should handle unknown flags", function (done) {1505 const choiceWidgetRef = _primitives.Ref.get(166, 0);1506 const xref = new _test_utils.XRefMock([{1507 ref: choiceWidgetRef,1508 data: choiceWidgetDict1509 }]);1510 _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({1511 data1512 }) => {1513 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1514 expect(data.readOnly).toEqual(false);1515 expect(data.combo).toEqual(false);1516 expect(data.multiSelect).toEqual(false);1517 done();1518 }, done.fail);1519 });1520 it("should not set invalid flags", function (done) {1521 choiceWidgetDict.set("Ff", "readonly");1522 const choiceWidgetRef = _primitives.Ref.get(165, 0);1523 const xref = new _test_utils.XRefMock([{1524 ref: choiceWidgetRef,1525 data: choiceWidgetDict1526 }]);1527 _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({1528 data1529 }) => {1530 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1531 expect(data.readOnly).toEqual(false);1532 expect(data.combo).toEqual(false);1533 expect(data.multiSelect).toEqual(false);1534 done();1535 }, done.fail);1536 });1537 it("should set valid flags", function (done) {1538 choiceWidgetDict.set("Ff", _util.AnnotationFieldFlag.READONLY + _util.AnnotationFieldFlag.COMBO + _util.AnnotationFieldFlag.MULTISELECT);1539 const choiceWidgetRef = _primitives.Ref.get(512, 0);1540 const xref = new _test_utils.XRefMock([{1541 ref: choiceWidgetRef,1542 data: choiceWidgetDict1543 }]);1544 _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({1545 data1546 }) => {1547 expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);1548 expect(data.readOnly).toEqual(true);1549 expect(data.combo).toEqual(true);1550 expect(data.multiSelect).toEqual(true);1551 done();1552 }, done.fail);1553 });1554 });1555 describe("LineAnnotation", function () {1556 it("should set the line coordinates", function (done) {1557 const lineDict = new _primitives.Dict();1558 lineDict.set("Type", _primitives.Name.get("Annot"));1559 lineDict.set("Subtype", _primitives.Name.get("Line"));1560 lineDict.set("L", [1, 2, 3, 4]);1561 const lineRef = _primitives.Ref.get(122, 0);1562 const xref = new _test_utils.XRefMock([{1563 ref: lineRef,1564 data: lineDict1565 }]);1566 _annotation.AnnotationFactory.create(xref, lineRef, pdfManagerMock, idFactoryMock).then(({1567 data1568 }) => {1569 expect(data.annotationType).toEqual(_util.AnnotationType.LINE);1570 expect(data.lineCoordinates).toEqual([1, 2, 3, 4]);1571 done();1572 }, done.fail);1573 });1574 });1575 describe("FileAttachmentAnnotation", function () {1576 it("should correctly parse a file attachment", function (done) {1577 const fileStream = new _stream.StringStream("<<\n" + "/Type /EmbeddedFile\n" + "/Subtype /text#2Fplain\n" + ">>\n" + "stream\n" + "Test attachment" + "endstream\n");1578 const parser = new _parser.Parser({1579 lexer: new _parser.Lexer(fileStream),1580 xref: null,1581 allowStreams: true1582 });1583 const fileStreamRef = _primitives.Ref.get(18, 0);1584 const fileStreamDict = parser.getObj();1585 const embeddedFileDict = new _primitives.Dict();1586 embeddedFileDict.set("F", fileStreamRef);1587 const fileSpecRef = _primitives.Ref.get(19, 0);1588 const fileSpecDict = new _primitives.Dict();1589 fileSpecDict.set("Type", _primitives.Name.get("Filespec"));1590 fileSpecDict.set("Desc", "");1591 fileSpecDict.set("EF", embeddedFileDict);1592 fileSpecDict.set("UF", "Test.txt");1593 const fileAttachmentRef = _primitives.Ref.get(20, 0);1594 const fileAttachmentDict = new _primitives.Dict();1595 fileAttachmentDict.set("Type", _primitives.Name.get("Annot"));1596 fileAttachmentDict.set("Subtype", _primitives.Name.get("FileAttachment"));1597 fileAttachmentDict.set("FS", fileSpecRef);1598 fileAttachmentDict.set("T", "Topic");1599 fileAttachmentDict.set("Contents", "Test.txt");1600 const xref = new _test_utils.XRefMock([{1601 ref: fileStreamRef,1602 data: fileStreamDict1603 }, {1604 ref: fileSpecRef,1605 data: fileSpecDict1606 }, {1607 ref: fileAttachmentRef,1608 data: fileAttachmentDict1609 }]);1610 embeddedFileDict.assignXref(xref);1611 fileSpecDict.assignXref(xref);1612 fileAttachmentDict.assignXref(xref);1613 _annotation.AnnotationFactory.create(xref, fileAttachmentRef, pdfManagerMock, idFactoryMock).then(({1614 data1615 }) => {1616 expect(data.annotationType).toEqual(_util.AnnotationType.FILEATTACHMENT);1617 expect(data.file.filename).toEqual("Test.txt");1618 expect(data.file.content).toEqual((0, _util.stringToBytes)("Test attachment"));1619 done();1620 }, done.fail);1621 });1622 });1623 describe("PopupAnnotation", function () {1624 it("should inherit properties from its parent", function (done) {1625 const parentDict = new _primitives.Dict();1626 parentDict.set("Type", _primitives.Name.get("Annot"));1627 parentDict.set("Subtype", _primitives.Name.get("Text"));1628 parentDict.set("M", "D:20190423");1629 parentDict.set("C", [0, 0, 1]);1630 const popupDict = new _primitives.Dict();1631 popupDict.set("Type", _primitives.Name.get("Annot"));1632 popupDict.set("Subtype", _primitives.Name.get("Popup"));1633 popupDict.set("Parent", parentDict);1634 const popupRef = _primitives.Ref.get(13, 0);1635 const xref = new _test_utils.XRefMock([{1636 ref: popupRef,1637 data: popupDict1638 }]);1639 _annotation.AnnotationFactory.create(xref, popupRef, pdfManagerMock, idFactoryMock).then(({1640 data,1641 viewable1642 }) => {1643 expect(data.annotationType).toEqual(_util.AnnotationType.POPUP);1644 expect(data.modificationDate).toEqual("D:20190423");1645 expect(data.color).toEqual(new Uint8ClampedArray([0, 0, 255]));1646 done();1647 }, done.fail);1648 });1649 it("should handle missing parent properties", function (done) {1650 const parentDict = new _primitives.Dict();1651 parentDict.set("Type", _primitives.Name.get("Annot"));1652 parentDict.set("Subtype", _primitives.Name.get("Text"));1653 const popupDict = new _primitives.Dict();1654 popupDict.set("Type", _primitives.Name.get("Annot"));1655 popupDict.set("Subtype", _primitives.Name.get("Popup"));1656 popupDict.set("Parent", parentDict);1657 const popupRef = _primitives.Ref.get(13, 0);1658 const xref = new _test_utils.XRefMock([{1659 ref: popupRef,1660 data: popupDict1661 }]);1662 _annotation.AnnotationFactory.create(xref, popupRef, pdfManagerMock, idFactoryMock).then(({1663 data,1664 viewable1665 }) => {1666 expect(data.annotationType).toEqual(_util.AnnotationType.POPUP);1667 expect(data.modificationDate).toEqual(null);1668 expect(data.color).toEqual(null);1669 done();1670 }, done.fail);1671 });1672 it("should inherit the parent flags when the Popup is not viewable, " + "but the parent is (PR 7352)", function (done) {1673 const parentDict = new _primitives.Dict();1674 parentDict.set("Type", _primitives.Name.get("Annot"));1675 parentDict.set("Subtype", _primitives.Name.get("Text"));1676 parentDict.set("F", 28);1677 const popupDict = new _primitives.Dict();1678 popupDict.set("Type", _primitives.Name.get("Annot"));1679 popupDict.set("Subtype", _primitives.Name.get("Popup"));1680 popupDict.set("F", 25);1681 popupDict.set("Parent", parentDict);1682 const popupRef = _primitives.Ref.get(13, 0);1683 const xref = new _test_utils.XRefMock([{1684 ref: popupRef,1685 data: popupDict1686 }]);1687 _annotation.AnnotationFactory.create(xref, popupRef, pdfManagerMock, idFactoryMock).then(({1688 data,1689 viewable1690 }) => {1691 expect(data.annotationType).toEqual(_util.AnnotationType.POPUP);1692 expect(data.annotationFlags).toEqual(25);1693 expect(viewable).toEqual(true);1694 done();1695 }, done.fail);1696 });1697 it("should correctly inherit Contents from group-master annotation " + "if parent has ReplyType == Group", function (done) {1698 const annotationRef = _primitives.Ref.get(819, 0);1699 const annotationDict = new _primitives.Dict();1700 annotationDict.set("Type", _primitives.Name.get("Annot"));1701 annotationDict.set("Subtype", _primitives.Name.get("Text"));1702 annotationDict.set("T", "Correct Title");1703 annotationDict.set("Contents", "Correct Text");1704 annotationDict.set("M", "D:20190423");1705 annotationDict.set("C", [0, 0, 1]);1706 const replyRef = _primitives.Ref.get(820, 0);1707 const replyDict = new _primitives.Dict();1708 replyDict.set("Type", _primitives.Name.get("Annot"));1709 replyDict.set("Subtype", _primitives.Name.get("Text"));1710 replyDict.set("IRT", annotationRef);1711 replyDict.set("RT", _primitives.Name.get("Group"));1712 replyDict.set("T", "Reply Title");1713 replyDict.set("Contents", "Reply Text");1714 replyDict.set("M", "D:20190523");1715 replyDict.set("C", [0.4]);1716 const popupRef = _primitives.Ref.get(821, 0);1717 const popupDict = new _primitives.Dict();1718 popupDict.set("Type", _primitives.Name.get("Annot"));1719 popupDict.set("Subtype", _primitives.Name.get("Popup"));1720 popupDict.set("T", "Wrong Title");1721 popupDict.set("Contents", "Wrong Text");1722 popupDict.set("Parent", replyRef);1723 popupDict.set("M", "D:20190623");1724 popupDict.set("C", [0.8]);1725 replyDict.set("Popup", popupRef);1726 const xref = new _test_utils.XRefMock([{1727 ref: annotationRef,1728 data: annotationDict1729 }, {1730 ref: replyRef,1731 data: replyDict1732 }, {1733 ref: popupRef,1734 data: popupDict1735 }]);1736 annotationDict.assignXref(xref);1737 popupDict.assignXref(xref);1738 replyDict.assignXref(xref);1739 _annotation.AnnotationFactory.create(xref, popupRef, pdfManagerMock, idFactoryMock).then(({1740 data1741 }) => {1742 expect(data.title).toEqual("Correct Title");1743 expect(data.contents).toEqual("Correct Text");1744 expect(data.modificationDate).toEqual("D:20190423");1745 expect(data.color).toEqual(new Uint8ClampedArray([0, 0, 255]));1746 done();1747 }, done.fail);1748 });1749 });1750 describe("InkAnnotation", function () {1751 it("should handle a single ink list", function (done) {1752 const inkDict = new _primitives.Dict();1753 inkDict.set("Type", _primitives.Name.get("Annot"));1754 inkDict.set("Subtype", _primitives.Name.get("Ink"));1755 inkDict.set("InkList", [[1, 1, 1, 2, 2, 2, 3, 3]]);1756 const inkRef = _primitives.Ref.get(142, 0);1757 const xref = new _test_utils.XRefMock([{1758 ref: inkRef,1759 data: inkDict1760 }]);1761 _annotation.AnnotationFactory.create(xref, inkRef, pdfManagerMock, idFactoryMock).then(({1762 data1763 }) => {1764 expect(data.annotationType).toEqual(_util.AnnotationType.INK);1765 expect(data.inkLists.length).toEqual(1);1766 expect(data.inkLists[0]).toEqual([{1767 x: 1,1768 y: 11769 }, {1770 x: 1,1771 y: 21772 }, {1773 x: 2,1774 y: 21775 }, {1776 x: 3,1777 y: 31778 }]);1779 done();1780 }, done.fail);1781 });1782 it("should handle multiple ink lists", function (done) {1783 const inkDict = new _primitives.Dict();1784 inkDict.set("Type", _primitives.Name.get("Annot"));1785 inkDict.set("Subtype", _primitives.Name.get("Ink"));1786 inkDict.set("InkList", [[1, 1, 1, 2], [3, 3, 4, 5]]);1787 const inkRef = _primitives.Ref.get(143, 0);1788 const xref = new _test_utils.XRefMock([{1789 ref: inkRef,1790 data: inkDict1791 }]);1792 _annotation.AnnotationFactory.create(xref, inkRef, pdfManagerMock, idFactoryMock).then(({1793 data1794 }) => {1795 expect(data.annotationType).toEqual(_util.AnnotationType.INK);1796 expect(data.inkLists.length).toEqual(2);1797 expect(data.inkLists[0]).toEqual([{1798 x: 1,1799 y: 11800 }, {1801 x: 1,1802 y: 21803 }]);1804 expect(data.inkLists[1]).toEqual([{1805 x: 3,1806 y: 31807 }, {1808 x: 4,1809 y: 51810 }]);1811 done();1812 }, done.fail);1813 });1814 });1815 describe("HightlightAnnotation", function () {1816 it("should not set quadpoints if not defined", function (done) {1817 const highlightDict = new _primitives.Dict();1818 highlightDict.set("Type", _primitives.Name.get("Annot"));1819 highlightDict.set("Subtype", _primitives.Name.get("Highlight"));1820 const highlightRef = _primitives.Ref.get(121, 0);1821 const xref = new _test_utils.XRefMock([{1822 ref: highlightRef,1823 data: highlightDict1824 }]);1825 _annotation.AnnotationFactory.create(xref, highlightRef, pdfManagerMock, idFactoryMock).then(({1826 data1827 }) => {1828 expect(data.annotationType).toEqual(_util.AnnotationType.HIGHLIGHT);1829 expect(data.quadPoints).toBeUndefined();1830 done();1831 }, done.fail);1832 });1833 it("should set quadpoints if defined", function (done) {1834 const highlightDict = new _primitives.Dict();1835 highlightDict.set("Type", _primitives.Name.get("Annot"));1836 highlightDict.set("Subtype", _primitives.Name.get("Highlight"));1837 highlightDict.set("Rect", [10, 10, 20, 20]);1838 highlightDict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14]);1839 const highlightRef = _primitives.Ref.get(121, 0);1840 const xref = new _test_utils.XRefMock([{1841 ref: highlightRef,1842 data: highlightDict1843 }]);1844 _annotation.AnnotationFactory.create(xref, highlightRef, pdfManagerMock, idFactoryMock).then(({1845 data1846 }) => {1847 expect(data.annotationType).toEqual(_util.AnnotationType.HIGHLIGHT);1848 expect(data.quadPoints).toEqual([[{1849 x: 11,1850 y: 111851 }, {1852 x: 12,1853 y: 121854 }, {1855 x: 13,1856 y: 131857 }, {1858 x: 14,1859 y: 141860 }]]);1861 done();1862 }, done.fail);1863 });1864 });1865 describe("UnderlineAnnotation", function () {1866 it("should not set quadpoints if not defined", function (done) {1867 const underlineDict = new _primitives.Dict();1868 underlineDict.set("Type", _primitives.Name.get("Annot"));1869 underlineDict.set("Subtype", _primitives.Name.get("Underline"));1870 const underlineRef = _primitives.Ref.get(121, 0);1871 const xref = new _test_utils.XRefMock([{1872 ref: underlineRef,1873 data: underlineDict1874 }]);1875 _annotation.AnnotationFactory.create(xref, underlineRef, pdfManagerMock, idFactoryMock).then(({1876 data1877 }) => {1878 expect(data.annotationType).toEqual(_util.AnnotationType.UNDERLINE);1879 expect(data.quadPoints).toBeUndefined();1880 done();1881 }, done.fail);1882 });1883 it("should set quadpoints if defined", function (done) {1884 const underlineDict = new _primitives.Dict();1885 underlineDict.set("Type", _primitives.Name.get("Annot"));1886 underlineDict.set("Subtype", _primitives.Name.get("Underline"));1887 underlineDict.set("Rect", [10, 10, 20, 20]);1888 underlineDict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14]);1889 const underlineRef = _primitives.Ref.get(121, 0);1890 const xref = new _test_utils.XRefMock([{1891 ref: underlineRef,1892 data: underlineDict1893 }]);1894 _annotation.AnnotationFactory.create(xref, underlineRef, pdfManagerMock, idFactoryMock).then(({1895 data1896 }) => {1897 expect(data.annotationType).toEqual(_util.AnnotationType.UNDERLINE);1898 expect(data.quadPoints).toEqual([[{1899 x: 11,1900 y: 111901 }, {1902 x: 12,1903 y: 121904 }, {1905 x: 13,1906 y: 131907 }, {1908 x: 14,1909 y: 141910 }]]);1911 done();1912 }, done.fail);1913 });1914 });1915 describe("SquigglyAnnotation", function () {1916 it("should not set quadpoints if not defined", function (done) {1917 const squigglyDict = new _primitives.Dict();1918 squigglyDict.set("Type", _primitives.Name.get("Annot"));1919 squigglyDict.set("Subtype", _primitives.Name.get("Squiggly"));1920 const squigglyRef = _primitives.Ref.get(121, 0);1921 const xref = new _test_utils.XRefMock([{1922 ref: squigglyRef,1923 data: squigglyDict1924 }]);1925 _annotation.AnnotationFactory.create(xref, squigglyRef, pdfManagerMock, idFactoryMock).then(({1926 data1927 }) => {1928 expect(data.annotationType).toEqual(_util.AnnotationType.SQUIGGLY);1929 expect(data.quadPoints).toBeUndefined();1930 done();1931 }, done.fail);1932 });1933 it("should set quadpoints if defined", function (done) {1934 const squigglyDict = new _primitives.Dict();1935 squigglyDict.set("Type", _primitives.Name.get("Annot"));1936 squigglyDict.set("Subtype", _primitives.Name.get("Squiggly"));1937 squigglyDict.set("Rect", [10, 10, 20, 20]);1938 squigglyDict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14]);1939 const squigglyRef = _primitives.Ref.get(121, 0);1940 const xref = new _test_utils.XRefMock([{1941 ref: squigglyRef,1942 data: squigglyDict1943 }]);1944 _annotation.AnnotationFactory.create(xref, squigglyRef, pdfManagerMock, idFactoryMock).then(({1945 data1946 }) => {1947 expect(data.annotationType).toEqual(_util.AnnotationType.SQUIGGLY);1948 expect(data.quadPoints).toEqual([[{1949 x: 11,1950 y: 111951 }, {1952 x: 12,1953 y: 121954 }, {1955 x: 13,1956 y: 131957 }, {1958 x: 14,1959 y: 141960 }]]);1961 done();1962 }, done.fail);1963 });1964 });1965 describe("StrikeOutAnnotation", function () {1966 it("should not set quadpoints if not defined", function (done) {1967 const strikeOutDict = new _primitives.Dict();1968 strikeOutDict.set("Type", _primitives.Name.get("Annot"));1969 strikeOutDict.set("Subtype", _primitives.Name.get("StrikeOut"));1970 const strikeOutRef = _primitives.Ref.get(121, 0);1971 const xref = new _test_utils.XRefMock([{1972 ref: strikeOutRef,1973 data: strikeOutDict1974 }]);1975 _annotation.AnnotationFactory.create(xref, strikeOutRef, pdfManagerMock, idFactoryMock).then(({1976 data1977 }) => {1978 expect(data.annotationType).toEqual(_util.AnnotationType.STRIKEOUT);1979 expect(data.quadPoints).toBeUndefined();1980 done();1981 }, done.fail);1982 });1983 it("should set quadpoints if defined", function (done) {1984 const strikeOutDict = new _primitives.Dict();1985 strikeOutDict.set("Type", _primitives.Name.get("Annot"));1986 strikeOutDict.set("Subtype", _primitives.Name.get("StrikeOut"));1987 strikeOutDict.set("Rect", [10, 10, 20, 20]);1988 strikeOutDict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14]);1989 const strikeOutRef = _primitives.Ref.get(121, 0);1990 const xref = new _test_utils.XRefMock([{1991 ref: strikeOutRef,1992 data: strikeOutDict1993 }]);1994 _annotation.AnnotationFactory.create(xref, strikeOutRef, pdfManagerMock, idFactoryMock).then(({1995 data1996 }) => {1997 expect(data.annotationType).toEqual(_util.AnnotationType.STRIKEOUT);1998 expect(data.quadPoints).toEqual([[{1999 x: 11,2000 y: 112001 }, {2002 x: 12,2003 y: 122004 }, {2005 x: 13,2006 y: 132007 }, {2008 x: 14,2009 y: 142010 }]]);2011 done();2012 }, done.fail);2013 });2014 });...

Full Screen

Full Screen

main.ts

Source:main.ts Github

copy

Full Screen

1import "reflect-metadata";2import {container} from "./inversify.config"3import {4 AnnotationFactory, ANNOTATOR_TYPES, FileAndConsoleLogger, LogConfig, SHARED_TYPES,5} from "bugfinder-framework";6import {CommitPath} from "bugfinder-localityrecorder-commitpath";7import _ from 'underscore';8import {Logger} from "ts-log";9async function topLevelAwaitWrapper() {10 try {11 const annotationFactory =12 container.get<AnnotationFactory<CommitPath, number>>(ANNOTATOR_TYPES.annotationFactory)13 const annotator = annotationFactory.createAnnotator();14 const db = annotationFactory.createDB();15 const localities = await db.readLocalities("Preprocessed_Localities")16 const logger = container.get<Logger>(SHARED_TYPES.logger)17 CommitPath.logger = logger18 const annotations = await annotator.annotate(localities, localities)19 await db.writeAnnotations(annotations, "PostAnnotations_n3")20 } catch (error) {21 console.log("ERROR: 02b-annotation: ", error);22 }23}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.runTest('www.yahoo.com', { location: 'Dulles:Chrome' }, function(err, data) {4 if (err) return console.error(err);5 console.log('Test status: ' + data.statusText);6 console.log('Test ID: ' + data.data.testId);7 console.log('Test URL: ' + data.data.summary);8 console.log('Test results available at: ' + data.data.userUrl);9});10var wpt = require('webpagetest');11var wpt = new WebPageTest('www.webpagetest.org');12wpt.runTest('www.yahoo.com', { location: 'Dulles:Chrome' }, function(err, data) {13 if (err) return console.error(err);14 console.log('Test status: ' + data.statusText);15 console.log('Test ID: ' + data.data.testId);16 console.log('Test URL: ' + data.data.summary);17 console.log('Test results available at: ' + data.data.userUrl);18});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var annotations = wpt.AnnotationFactory();3annotations.add('test', 'test', 'test', 'test', 'test', 'test');4annotations.add('test', 'test', 'test', 'test', 'test', 'test');5var wpt = require('wpt');6var annotations = wpt.AnnotationFactory();7annotations.add('test', 'test', 'test', 'test', 'test', 'test');8annotations.add('test', 'test', 'test', 'test', 'test', 'test');9var wpt = require('wpt');10var annotations = wpt.AnnotationFactory();11annotations.add('test', 'test', 'test', 'test', 'test', 'test');12annotations.add('test', 'test', 'test', 'test', 'test', 'test');13var wpt = require('wpt');14var annotations = wpt.AnnotationFactory();15annotations.add('test', 'test', 'test', 'test', 'test', 'test');16annotations.add('test', 'test', 'test', 'test', 'test', 'test');17var wpt = require('wpt');18var annotations = wpt.AnnotationFactory();19annotations.add('test', 'test', 'test', 'test', 'test', 'test');20annotations.add('test', 'test', 'test', 'test', 'test', 'test');21var wpt = require('wpt');22var annotations = wpt.AnnotationFactory();23annotations.add('test', 'test', 'test', 'test', 'test', 'test');24annotations.add('test', 'test', 'test', 'test', 'test', 'test');25var wpt = require('wpt');26var annotations = wpt.AnnotationFactory();27annotations.add('test', 'test', 'test', 'test', 'test', 'test');28annotations.add('test', 'test', 'test

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('WebPageTest');2var wpt = new WebPageTest('www.webpagetest.org');3var annotationFactory = wpt.annotationFactory();4var annotation = annotationFactory.createAnnotation("Test Annotation");5annotation.addAnnotation("This is a test annotation");6annotation.addAnnotation("This is another test annotation");7annotation.addAnnotation("This is a third test annotation");8console.log(annotation.getAnnotations());9console.log(annotation.getAnnotationsJSON());10console.log(annotation.getAnnotationsHTML());11console.log(annotation.getAnnotationsMarkdown());12console.log(annotation.getAnnotationsCSV());13console.log(annotation.getAnnotationsXML());14console.log(annotation.getAnnotationsYAML());15console.log(annotation.getAnnotationsJIRA());16console.log(annotation.getAnnotationsTrello());17console.log(annotation.getAnnotationsTextile());18console.log(annotation.getAnnotationsConfluence());19console.log(annotation.getAnnotationsMediaWiki());20console.log(annotation.getAnnotationsReStructuredText());21console.log(annotation.getAnnotationsText());22console.log(annotation.getAnnotationsTracWiki());23console.log(annotation.getAnnotationsDokuWiki());24console.log(annotation.getAnnotationsCustom("<li>%s</li>"));25console.log(annotation.getAnnotationsCustom("<li>%s</li>", "Test Header"));26console.log(annotation.getAnnotationsCustom("<li>%s</li>", "Test Header", "</ul>"));27console.log(annotation.getAnnotationsCustom("<li>%s</li>", "Test Header", "</ul>", "<br>"));28console.log(annotation.getAnnotationsCustom("<li>%s</li>", "Test Header", "</ul

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var factory = wpt.AnnotationFactory;3var annotation = factory.createAnnotation('TextAnnotation', 'This is a text annotation');4var wpt = require('wpt');5var factory = wpt.AnnotationFactory;6var annotation = factory.createAnnotation('TextAnnotation', 'This is a text annotation');7var wpt = require('wpt');8var factory = wpt.AnnotationFactory;9var annotation = factory.createAnnotation('TextAnnotation', 'This is a text annotation');10var wpt = require('wpt');11var factory = wpt.AnnotationFactory;12var annotation = factory.createAnnotation('TextAnnotation', 'This is a text annotation');13var wpt = require('wpt');14var factory = wpt.AnnotationFactory;15var annotation = factory.createAnnotation('TextAnnotation', 'This is a text annotation');16var wpt = require('wpt');17var factory = wpt.AnnotationFactory;18var annotation = factory.createAnnotation('TextAnnotation', 'This is a text annotation');19var wpt = require('wpt');20var factory = wpt.AnnotationFactory;21var annotation = factory.createAnnotation('TextAnnotation', 'This is a text annotation');22var wpt = require('wpt');23var factory = wpt.AnnotationFactory;24var annotation = factory.createAnnotation('TextAnnotation', 'This is a text annotation');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2console.log(annotation);3console.log(annotation);4console.log(annotation);5console.log(annotation);6console.log(annotation);7console.log(annotation);8var wpt = require('wpt');9console.log(annotation);10console.log(annotation);11console.log(annotation);12console.log(annotation);13console.log(annotation);14console.log(annotation);15var wpt = require('wpt');16console.log(annotation);

Full Screen

Using AI Code Generation

copy

Full Screen

1var AnnotationFactory = require('wptools').AnnotationFactory;2var factory = new AnnotationFactory();3var annotation = factory.createAnnotation('test');4annotation.setLabel('test');5annotation.setTarget('test');6var AnnotationFactory = require('wptools').AnnotationFactory;7var factory = new AnnotationFactory();8var annotation = factory.createAnnotation('test');9annotation.setLabel('test');10annotation.setTarget('test');11var AnnotationFactory = require('wptools').AnnotationFactory;12var factory = new AnnotationFactory();13var annotation = factory.createAnnotation('test');14annotation.setLabel('test');15annotation.setTarget('test');16var AnnotationFactory = require('wptools').AnnotationFactory;17var factory = new AnnotationFactory();18var annotation = factory.createAnnotation('test');19annotation.setLabel('test');20annotation.setTarget('test');21var AnnotationFactory = require('wptools').AnnotationFactory;22var factory = new AnnotationFactory();23var annotation = factory.createAnnotation('test');24annotation.setLabel('test');25annotation.setTarget('test');26var AnnotationFactory = require('wptools').AnnotationFactory;27var factory = new AnnotationFactory();28var annotation = factory.createAnnotation('test');29annotation.setLabel('test');30annotation.setTarget('test');31var AnnotationFactory = require('wptools').AnnotationFactory;32var factory = new AnnotationFactory();33var annotation = factory.createAnnotation('test');34annotation.setLabel('test');35annotation.setTarget('test');36var AnnotationFactory = require('wptools').AnnotationFactory;37var factory = new AnnotationFactory();38var annotation = factory.createAnnotation('test');39annotation.setLabel('test');40annotation.setTarget('test');41var AnnotationFactory = require('wptools').AnnotationFactory;42var factory = new AnnotationFactory();43var annotation = factory.createAnnotation('test');44annotation.setLabel('test');45annotation.setTarget('test');46var AnnotationFactory = require('wptools').AnnotationFactory;47var factory = new AnnotationFactory();

Full Screen

Using AI Code Generation

copy

Full Screen

1function test() {2 var annotationFactory = new AnnotationFactory();3 var annotation = annotationFactory.createAnnotation();4 annotation.setText("Hello World");5 annotation.setType("Text");6 var pageTextPattern = new PageTextPattern();7 var pageTextPatternOptions = new PageTextPatternOptions();8 pageTextPatternOptions.setText("Hello World");9 pageTextPatternOptions.setType("Text");10 pageTextPatternOptions.setCaseSensitive(true);11 pageTextPatternOptions.setWholeWord(true);12 pageTextPatternOptions.setMatchCase(true);13 pageTextPatternOptions.setMatchWholeWord(true);14 pageTextPatternOptions.setMatchPrefix(true);15 pageTextPatternOptions.setMatchSuffix(true);16 pageTextPatternOptions.setMatchSubstring(true);17 pageTextPatternOptions.setMatchAll(true);18 pageTextPatternOptions.setMatchAny(true);19 pageTextPatternOptions.setMatchNone(true);20 pageTextPatternOptions.setMatchRegex(true);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var af = wpt.AnnotationFactory;3var ann = af.createAnnotation('CustomAnnotation', 'This is a custom annotation');4var f = function() {5 return 'hello';6};7af.annotate(f, ann);8console.log(f.annotations);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful