api_spec.js 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2020 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 _test_utils = require("./test_utils.js");
  24. var _util = require("../../shared/util.js");
  25. var _display_utils = require("../../display/display_utils.js");
  26. var _api = require("../../display/api.js");
  27. var _ui_utils = require("../../web/ui_utils.js");
  28. var _worker_options = require("../../display/worker_options.js");
  29. var _is_node = require("../../shared/is_node.js");
  30. var _metadata = require("../../display/metadata.js");
  31. describe("api", function () {
  32. const basicApiFileName = "basicapi.pdf";
  33. const basicApiFileLength = 105779;
  34. const basicApiGetDocumentParams = (0, _test_utils.buildGetDocumentParams)(basicApiFileName);
  35. let CanvasFactory;
  36. beforeAll(function (done) {
  37. if (_is_node.isNodeJS) {
  38. CanvasFactory = new _test_utils.NodeCanvasFactory();
  39. } else {
  40. CanvasFactory = new _display_utils.DOMCanvasFactory();
  41. }
  42. done();
  43. });
  44. afterAll(function (done) {
  45. CanvasFactory = null;
  46. done();
  47. });
  48. function waitSome(callback) {
  49. var WAIT_TIMEOUT = 10;
  50. setTimeout(function () {
  51. callback();
  52. }, WAIT_TIMEOUT);
  53. }
  54. describe("getDocument", function () {
  55. it("creates pdf doc from URL", function (done) {
  56. var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
  57. var progressReportedCapability = (0, _util.createPromiseCapability)();
  58. loadingTask.onProgress = function (progressData) {
  59. if (!progressReportedCapability.settled) {
  60. progressReportedCapability.resolve(progressData);
  61. }
  62. };
  63. var promises = [progressReportedCapability.promise, loadingTask.promise];
  64. Promise.all(promises).then(function (data) {
  65. expect(data[0].loaded / data[0].total >= 0).toEqual(true);
  66. expect(data[1] instanceof _api.PDFDocumentProxy).toEqual(true);
  67. expect(loadingTask).toEqual(data[1].loadingTask);
  68. loadingTask.destroy().then(done);
  69. }).catch(done.fail);
  70. });
  71. it("creates pdf doc from URL and aborts before worker initialized", function (done) {
  72. var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
  73. const destroyed = loadingTask.destroy();
  74. loadingTask.promise.then(function (reason) {
  75. done.fail("shall fail loading");
  76. }).catch(function (reason) {
  77. expect(true).toEqual(true);
  78. destroyed.then(done);
  79. });
  80. });
  81. it("creates pdf doc from URL and aborts loading after worker initialized", function (done) {
  82. var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
  83. var destroyed = loadingTask._worker.promise.then(function () {
  84. return loadingTask.destroy();
  85. });
  86. destroyed.then(function (data) {
  87. expect(true).toEqual(true);
  88. done();
  89. }).catch(done.fail);
  90. });
  91. it("creates pdf doc from typed array", function (done) {
  92. let typedArrayPdfPromise;
  93. if (_is_node.isNodeJS) {
  94. typedArrayPdfPromise = _test_utils.NodeFileReaderFactory.fetch({
  95. path: _test_utils.TEST_PDFS_PATH.node + basicApiFileName
  96. });
  97. } else {
  98. typedArrayPdfPromise = _test_utils.DOMFileReaderFactory.fetch({
  99. path: _test_utils.TEST_PDFS_PATH.dom + basicApiFileName
  100. });
  101. }
  102. typedArrayPdfPromise.then(typedArrayPdf => {
  103. expect(typedArrayPdf.length).toEqual(basicApiFileLength);
  104. const loadingTask = (0, _api.getDocument)(typedArrayPdf);
  105. const progressReportedCapability = (0, _util.createPromiseCapability)();
  106. loadingTask.onProgress = function (data) {
  107. progressReportedCapability.resolve(data);
  108. };
  109. return Promise.all([loadingTask.promise, progressReportedCapability.promise]).then(function (data) {
  110. expect(data[0] instanceof _api.PDFDocumentProxy).toEqual(true);
  111. expect(data[1].loaded / data[1].total).toEqual(1);
  112. loadingTask.destroy().then(done);
  113. });
  114. }).catch(done.fail);
  115. });
  116. it("creates pdf doc from invalid PDF file", function (done) {
  117. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("bug1020226.pdf"));
  118. loadingTask.promise.then(function () {
  119. done.fail("shall fail loading");
  120. }).catch(function (reason) {
  121. expect(reason instanceof _util.InvalidPDFException).toEqual(true);
  122. expect(reason.message).toEqual("Invalid PDF structure.");
  123. loadingTask.destroy().then(done);
  124. });
  125. });
  126. it("creates pdf doc from non-existent URL", function (done) {
  127. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("non-existent.pdf"));
  128. loadingTask.promise.then(function (error) {
  129. done.fail("shall fail loading");
  130. }).catch(function (error) {
  131. expect(error instanceof _util.MissingPDFException).toEqual(true);
  132. loadingTask.destroy().then(done);
  133. });
  134. });
  135. it("creates pdf doc from PDF file protected with user and owner password", function (done) {
  136. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("pr6531_1.pdf"));
  137. var passwordNeededCapability = (0, _util.createPromiseCapability)();
  138. var passwordIncorrectCapability = (0, _util.createPromiseCapability)();
  139. loadingTask.onPassword = function (updatePassword, reason) {
  140. if (reason === _util.PasswordResponses.NEED_PASSWORD && !passwordNeededCapability.settled) {
  141. passwordNeededCapability.resolve();
  142. updatePassword("qwerty");
  143. return;
  144. }
  145. if (reason === _util.PasswordResponses.INCORRECT_PASSWORD && !passwordIncorrectCapability.settled) {
  146. passwordIncorrectCapability.resolve();
  147. updatePassword("asdfasdf");
  148. return;
  149. }
  150. expect(false).toEqual(true);
  151. };
  152. var promises = [passwordNeededCapability.promise, passwordIncorrectCapability.promise, loadingTask.promise];
  153. Promise.all(promises).then(function (data) {
  154. expect(data[2] instanceof _api.PDFDocumentProxy).toEqual(true);
  155. loadingTask.destroy().then(done);
  156. }).catch(done.fail);
  157. });
  158. it("creates pdf doc from PDF file protected with only a user password", function (done) {
  159. var filename = "pr6531_2.pdf";
  160. var passwordNeededLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
  161. password: ""
  162. }));
  163. var result1 = passwordNeededLoadingTask.promise.then(function () {
  164. done.fail("shall fail with no password");
  165. return Promise.reject(new Error("loadingTask should be rejected"));
  166. }, function (data) {
  167. expect(data instanceof _util.PasswordException).toEqual(true);
  168. expect(data.code).toEqual(_util.PasswordResponses.NEED_PASSWORD);
  169. return passwordNeededLoadingTask.destroy();
  170. });
  171. var passwordIncorrectLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
  172. password: "qwerty"
  173. }));
  174. var result2 = passwordIncorrectLoadingTask.promise.then(function () {
  175. done.fail("shall fail with wrong password");
  176. return Promise.reject(new Error("loadingTask should be rejected"));
  177. }, function (data) {
  178. expect(data instanceof _util.PasswordException).toEqual(true);
  179. expect(data.code).toEqual(_util.PasswordResponses.INCORRECT_PASSWORD);
  180. return passwordIncorrectLoadingTask.destroy();
  181. });
  182. var passwordAcceptedLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
  183. password: "asdfasdf"
  184. }));
  185. var result3 = passwordAcceptedLoadingTask.promise.then(function (data) {
  186. expect(data instanceof _api.PDFDocumentProxy).toEqual(true);
  187. return passwordAcceptedLoadingTask.destroy();
  188. });
  189. Promise.all([result1, result2, result3]).then(function () {
  190. done();
  191. }).catch(done.fail);
  192. });
  193. it("creates pdf doc from password protected PDF file and aborts/throws " + "in the onPassword callback (issue 7806)", function (done) {
  194. var filename = "issue3371.pdf";
  195. var passwordNeededLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename));
  196. var passwordIncorrectLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
  197. password: "qwerty"
  198. }));
  199. let passwordNeededDestroyed;
  200. passwordNeededLoadingTask.onPassword = function (callback, reason) {
  201. if (reason === _util.PasswordResponses.NEED_PASSWORD) {
  202. passwordNeededDestroyed = passwordNeededLoadingTask.destroy();
  203. return;
  204. }
  205. expect(false).toEqual(true);
  206. };
  207. var result1 = passwordNeededLoadingTask.promise.then(function () {
  208. done.fail("shall fail since the loadingTask should be destroyed");
  209. return Promise.reject(new Error("loadingTask should be rejected"));
  210. }, function (reason) {
  211. expect(reason instanceof _util.PasswordException).toEqual(true);
  212. expect(reason.code).toEqual(_util.PasswordResponses.NEED_PASSWORD);
  213. return passwordNeededDestroyed;
  214. });
  215. passwordIncorrectLoadingTask.onPassword = function (callback, reason) {
  216. if (reason === _util.PasswordResponses.INCORRECT_PASSWORD) {
  217. throw new Error("Incorrect password");
  218. }
  219. expect(false).toEqual(true);
  220. };
  221. var result2 = passwordIncorrectLoadingTask.promise.then(function () {
  222. done.fail("shall fail since the onPassword callback should throw");
  223. return Promise.reject(new Error("loadingTask should be rejected"));
  224. }, function (reason) {
  225. expect(reason instanceof _util.PasswordException).toEqual(true);
  226. expect(reason.code).toEqual(_util.PasswordResponses.INCORRECT_PASSWORD);
  227. return passwordIncorrectLoadingTask.destroy();
  228. });
  229. Promise.all([result1, result2]).then(function () {
  230. done();
  231. }).catch(done.fail);
  232. });
  233. it("creates pdf doc from empty typed array", function (done) {
  234. const loadingTask = (0, _api.getDocument)(new Uint8Array(0));
  235. loadingTask.promise.then(function () {
  236. done.fail("shall not open empty file");
  237. }, function (reason) {
  238. expect(reason instanceof _util.InvalidPDFException);
  239. expect(reason.message).toEqual("The PDF file is empty, i.e. its size is zero bytes.");
  240. loadingTask.destroy().then(done);
  241. });
  242. });
  243. });
  244. describe("PDFWorker", function () {
  245. it("worker created or destroyed", function (done) {
  246. if (_is_node.isNodeJS) {
  247. pending("Worker is not supported in Node.js.");
  248. }
  249. var worker = new _api.PDFWorker({
  250. name: "test1"
  251. });
  252. worker.promise.then(function () {
  253. expect(worker.name).toEqual("test1");
  254. expect(!!worker.port).toEqual(true);
  255. expect(worker.destroyed).toEqual(false);
  256. expect(!!worker._webWorker).toEqual(true);
  257. expect(worker.port === worker._webWorker).toEqual(true);
  258. worker.destroy();
  259. expect(!!worker.port).toEqual(false);
  260. expect(worker.destroyed).toEqual(true);
  261. done();
  262. }).catch(done.fail);
  263. });
  264. it("worker created or destroyed by getDocument", function (done) {
  265. if (_is_node.isNodeJS) {
  266. pending("Worker is not supported in Node.js.");
  267. }
  268. var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
  269. var worker;
  270. loadingTask.promise.then(function () {
  271. worker = loadingTask._worker;
  272. expect(!!worker).toEqual(true);
  273. });
  274. var destroyPromise = loadingTask.promise.then(function () {
  275. return loadingTask.destroy();
  276. });
  277. destroyPromise.then(function () {
  278. var destroyedWorker = loadingTask._worker;
  279. expect(!!destroyedWorker).toEqual(false);
  280. expect(worker.destroyed).toEqual(true);
  281. done();
  282. }).catch(done.fail);
  283. });
  284. it("worker created and can be used in getDocument", function (done) {
  285. if (_is_node.isNodeJS) {
  286. pending("Worker is not supported in Node.js.");
  287. }
  288. var worker = new _api.PDFWorker({
  289. name: "test1"
  290. });
  291. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, {
  292. worker
  293. }));
  294. loadingTask.promise.then(function () {
  295. var docWorker = loadingTask._worker;
  296. expect(!!docWorker).toEqual(false);
  297. var messageHandlerPort = loadingTask._transport.messageHandler.comObj;
  298. expect(messageHandlerPort === worker.port).toEqual(true);
  299. });
  300. var destroyPromise = loadingTask.promise.then(function () {
  301. return loadingTask.destroy();
  302. });
  303. destroyPromise.then(function () {
  304. expect(worker.destroyed).toEqual(false);
  305. worker.destroy();
  306. done();
  307. }).catch(done.fail);
  308. });
  309. it("creates more than one worker", function (done) {
  310. if (_is_node.isNodeJS) {
  311. pending("Worker is not supported in Node.js.");
  312. }
  313. var worker1 = new _api.PDFWorker({
  314. name: "test1"
  315. });
  316. var worker2 = new _api.PDFWorker({
  317. name: "test2"
  318. });
  319. var worker3 = new _api.PDFWorker({
  320. name: "test3"
  321. });
  322. var ready = Promise.all([worker1.promise, worker2.promise, worker3.promise]);
  323. ready.then(function () {
  324. expect(worker1.port !== worker2.port && worker1.port !== worker3.port && worker2.port !== worker3.port).toEqual(true);
  325. worker1.destroy();
  326. worker2.destroy();
  327. worker3.destroy();
  328. done();
  329. }).catch(done.fail);
  330. });
  331. it("gets current workerSrc", function () {
  332. if (_is_node.isNodeJS) {
  333. pending("Worker is not supported in Node.js.");
  334. }
  335. const workerSrc = _api.PDFWorker.getWorkerSrc();
  336. expect(typeof workerSrc).toEqual("string");
  337. expect(workerSrc).toEqual(_worker_options.GlobalWorkerOptions.workerSrc);
  338. });
  339. });
  340. describe("PDFDocument", function () {
  341. var loadingTask;
  342. var doc;
  343. beforeAll(function (done) {
  344. loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
  345. loadingTask.promise.then(function (data) {
  346. doc = data;
  347. done();
  348. });
  349. });
  350. afterAll(function (done) {
  351. loadingTask.destroy().then(done);
  352. });
  353. it("gets number of pages", function () {
  354. expect(doc.numPages).toEqual(3);
  355. });
  356. it("gets fingerprint", function () {
  357. expect(doc.fingerprint).toEqual("ea8b35919d6279a369e835bde778611b");
  358. });
  359. it("gets page", function (done) {
  360. var promise = doc.getPage(1);
  361. promise.then(function (data) {
  362. expect(data instanceof _api.PDFPageProxy).toEqual(true);
  363. expect(data.pageNumber).toEqual(1);
  364. done();
  365. }).catch(done.fail);
  366. });
  367. it("gets non-existent page", function (done) {
  368. var outOfRangePromise = doc.getPage(100);
  369. var nonIntegerPromise = doc.getPage(2.5);
  370. var nonNumberPromise = doc.getPage("1");
  371. outOfRangePromise = outOfRangePromise.then(function () {
  372. throw new Error("shall fail for out-of-range pageNumber parameter");
  373. }, function (reason) {
  374. expect(reason instanceof Error).toEqual(true);
  375. });
  376. nonIntegerPromise = nonIntegerPromise.then(function () {
  377. throw new Error("shall fail for non-integer pageNumber parameter");
  378. }, function (reason) {
  379. expect(reason instanceof Error).toEqual(true);
  380. });
  381. nonNumberPromise = nonNumberPromise.then(function () {
  382. throw new Error("shall fail for non-number pageNumber parameter");
  383. }, function (reason) {
  384. expect(reason instanceof Error).toEqual(true);
  385. });
  386. Promise.all([outOfRangePromise, nonIntegerPromise, nonNumberPromise]).then(function () {
  387. done();
  388. }).catch(done.fail);
  389. });
  390. it("gets page, from /Pages tree with circular reference", function (done) {
  391. const loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("Pages-tree-refs.pdf"));
  392. const page1 = loadingTask.promise.then(function (pdfDoc) {
  393. return pdfDoc.getPage(1).then(function (pdfPage) {
  394. expect(pdfPage instanceof _api.PDFPageProxy).toEqual(true);
  395. expect(pdfPage.ref).toEqual({
  396. num: 6,
  397. gen: 0
  398. });
  399. }, function (reason) {
  400. throw new Error("shall not fail for valid page");
  401. });
  402. });
  403. const page2 = loadingTask.promise.then(function (pdfDoc) {
  404. return pdfDoc.getPage(2).then(function (pdfPage) {
  405. throw new Error("shall fail for invalid page");
  406. }, function (reason) {
  407. expect(reason instanceof Error).toEqual(true);
  408. expect(reason.message).toEqual("Pages tree contains circular reference.");
  409. });
  410. });
  411. Promise.all([page1, page2]).then(function () {
  412. loadingTask.destroy().then(done);
  413. }, done.fail);
  414. });
  415. it("gets page index", function (done) {
  416. var ref = {
  417. num: 17,
  418. gen: 0
  419. };
  420. var promise = doc.getPageIndex(ref);
  421. promise.then(function (pageIndex) {
  422. expect(pageIndex).toEqual(1);
  423. done();
  424. }).catch(done.fail);
  425. });
  426. it("gets invalid page index", function (done) {
  427. var ref = {
  428. num: 3,
  429. gen: 0
  430. };
  431. var promise = doc.getPageIndex(ref);
  432. promise.then(function () {
  433. done.fail("shall fail for invalid page reference.");
  434. }).catch(function (reason) {
  435. expect(reason instanceof Error).toEqual(true);
  436. done();
  437. });
  438. });
  439. it("gets destinations, from /Dests dictionary", function (done) {
  440. var promise = doc.getDestinations();
  441. promise.then(function (data) {
  442. expect(data).toEqual({
  443. chapter1: [{
  444. gen: 0,
  445. num: 17
  446. }, {
  447. name: "XYZ"
  448. }, 0, 841.89, null]
  449. });
  450. done();
  451. }).catch(done.fail);
  452. });
  453. it("gets a destination, from /Dests dictionary", function (done) {
  454. var promise = doc.getDestination("chapter1");
  455. promise.then(function (data) {
  456. expect(data).toEqual([{
  457. gen: 0,
  458. num: 17
  459. }, {
  460. name: "XYZ"
  461. }, 0, 841.89, null]);
  462. done();
  463. }).catch(done.fail);
  464. });
  465. it("gets a non-existent destination, from /Dests dictionary", function (done) {
  466. var promise = doc.getDestination("non-existent-named-destination");
  467. promise.then(function (data) {
  468. expect(data).toEqual(null);
  469. done();
  470. }).catch(done.fail);
  471. });
  472. it("gets destinations, from /Names (NameTree) dictionary", function (done) {
  473. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue6204.pdf"));
  474. var promise = loadingTask.promise.then(function (pdfDocument) {
  475. return pdfDocument.getDestinations();
  476. });
  477. promise.then(function (destinations) {
  478. expect(destinations).toEqual({
  479. "Page.1": [{
  480. num: 1,
  481. gen: 0
  482. }, {
  483. name: "XYZ"
  484. }, 0, 375, null],
  485. "Page.2": [{
  486. num: 6,
  487. gen: 0
  488. }, {
  489. name: "XYZ"
  490. }, 0, 375, null]
  491. });
  492. loadingTask.destroy().then(done);
  493. }).catch(done.fail);
  494. });
  495. it("gets a destination, from /Names (NameTree) dictionary", function (done) {
  496. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue6204.pdf"));
  497. var promise = loadingTask.promise.then(function (pdfDocument) {
  498. return pdfDocument.getDestination("Page.1");
  499. });
  500. promise.then(function (destination) {
  501. expect(destination).toEqual([{
  502. num: 1,
  503. gen: 0
  504. }, {
  505. name: "XYZ"
  506. }, 0, 375, null]);
  507. loadingTask.destroy().then(done);
  508. }).catch(done.fail);
  509. });
  510. it("gets a non-existent destination, from /Names (NameTree) dictionary", function (done) {
  511. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue6204.pdf"));
  512. var promise = loadingTask.promise.then(function (pdfDocument) {
  513. return pdfDocument.getDestination("non-existent-named-destination");
  514. });
  515. promise.then(function (destination) {
  516. expect(destination).toEqual(null);
  517. loadingTask.destroy().then(done);
  518. }).catch(done.fail);
  519. });
  520. it("gets non-string destination", function (done) {
  521. let numberPromise = doc.getDestination(4.3);
  522. let booleanPromise = doc.getDestination(true);
  523. let arrayPromise = doc.getDestination([{
  524. num: 17,
  525. gen: 0
  526. }, {
  527. name: "XYZ"
  528. }, 0, 841.89, null]);
  529. numberPromise = numberPromise.then(function () {
  530. throw new Error("shall fail for non-string destination.");
  531. }, function (reason) {
  532. expect(reason instanceof Error).toEqual(true);
  533. });
  534. booleanPromise = booleanPromise.then(function () {
  535. throw new Error("shall fail for non-string destination.");
  536. }, function (reason) {
  537. expect(reason instanceof Error).toEqual(true);
  538. });
  539. arrayPromise = arrayPromise.then(function () {
  540. throw new Error("shall fail for non-string destination.");
  541. }, function (reason) {
  542. expect(reason instanceof Error).toEqual(true);
  543. });
  544. Promise.all([numberPromise, booleanPromise, arrayPromise]).then(done, done.fail);
  545. });
  546. it("gets non-existent page labels", function (done) {
  547. var promise = doc.getPageLabels();
  548. promise.then(function (data) {
  549. expect(data).toEqual(null);
  550. done();
  551. }).catch(done.fail);
  552. });
  553. it("gets page labels", function (done) {
  554. var loadingTask0 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("bug793632.pdf"));
  555. var promise0 = loadingTask0.promise.then(function (pdfDoc) {
  556. return pdfDoc.getPageLabels();
  557. });
  558. var loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue1453.pdf"));
  559. var promise1 = loadingTask1.promise.then(function (pdfDoc) {
  560. return pdfDoc.getPageLabels();
  561. });
  562. var loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("rotation.pdf"));
  563. var promise2 = loadingTask2.promise.then(function (pdfDoc) {
  564. return pdfDoc.getPageLabels();
  565. });
  566. var loadingTask3 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("bad-PageLabels.pdf"));
  567. var promise3 = loadingTask3.promise.then(function (pdfDoc) {
  568. return pdfDoc.getPageLabels();
  569. });
  570. Promise.all([promise0, promise1, promise2, promise3]).then(function (pageLabels) {
  571. expect(pageLabels[0]).toEqual(["i", "ii", "iii", "1"]);
  572. expect(pageLabels[1]).toEqual(["Front Page1"]);
  573. expect(pageLabels[2]).toEqual(["1", "2"]);
  574. expect(pageLabels[3]).toEqual(["X3"]);
  575. Promise.all([loadingTask0.destroy(), loadingTask1.destroy(), loadingTask2.destroy(), loadingTask3.destroy()]).then(done);
  576. }).catch(done.fail);
  577. });
  578. it("gets default page layout", function (done) {
  579. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
  580. loadingTask.promise.then(function (pdfDocument) {
  581. return pdfDocument.getPageLayout();
  582. }).then(function (mode) {
  583. expect(mode).toEqual("");
  584. loadingTask.destroy().then(done);
  585. }).catch(done.fail);
  586. });
  587. it("gets non-default page layout", function (done) {
  588. doc.getPageLayout().then(function (mode) {
  589. expect(mode).toEqual("SinglePage");
  590. done();
  591. }).catch(done.fail);
  592. });
  593. it("gets default page mode", function (done) {
  594. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
  595. loadingTask.promise.then(function (pdfDocument) {
  596. return pdfDocument.getPageMode();
  597. }).then(function (mode) {
  598. expect(mode).toEqual("UseNone");
  599. loadingTask.destroy().then(done);
  600. }).catch(done.fail);
  601. });
  602. it("gets non-default page mode", function (done) {
  603. doc.getPageMode().then(function (mode) {
  604. expect(mode).toEqual("UseOutlines");
  605. done();
  606. }).catch(done.fail);
  607. });
  608. it("gets default viewer preferences", function (done) {
  609. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
  610. loadingTask.promise.then(function (pdfDocument) {
  611. return pdfDocument.getViewerPreferences();
  612. }).then(function (prefs) {
  613. expect(typeof prefs === "object" && prefs !== null && (0, _util.isEmptyObj)(prefs)).toEqual(true);
  614. loadingTask.destroy().then(done);
  615. }).catch(done.fail);
  616. });
  617. it("gets non-default viewer preferences", function (done) {
  618. doc.getViewerPreferences().then(function (prefs) {
  619. expect(prefs).toEqual({
  620. Direction: "L2R"
  621. });
  622. done();
  623. }).catch(done.fail);
  624. });
  625. it("gets default open action", function (done) {
  626. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
  627. loadingTask.promise.then(function (pdfDocument) {
  628. return pdfDocument.getOpenAction();
  629. }).then(function (openAction) {
  630. expect(openAction).toEqual(null);
  631. loadingTask.destroy().then(done);
  632. }).catch(done.fail);
  633. });
  634. it("gets non-default open action (with destination)", function (done) {
  635. doc.getOpenAction().then(function (openAction) {
  636. expect(openAction.dest).toEqual([{
  637. num: 15,
  638. gen: 0
  639. }, {
  640. name: "FitH"
  641. }, null]);
  642. expect(openAction.action).toBeUndefined();
  643. done();
  644. }).catch(done.fail);
  645. });
  646. it("gets non-default open action (with Print action)", function (done) {
  647. const loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("bug1001080.pdf"));
  648. const loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue11442_reduced.pdf"));
  649. const promise1 = loadingTask1.promise.then(function (pdfDocument) {
  650. return pdfDocument.getOpenAction();
  651. }).then(function (openAction) {
  652. expect(openAction.dest).toBeUndefined();
  653. expect(openAction.action).toEqual("Print");
  654. return loadingTask1.destroy();
  655. });
  656. const promise2 = loadingTask2.promise.then(function (pdfDocument) {
  657. return pdfDocument.getOpenAction();
  658. }).then(function (openAction) {
  659. expect(openAction.dest).toBeUndefined();
  660. expect(openAction.action).toEqual("Print");
  661. return loadingTask2.destroy();
  662. });
  663. Promise.all([promise1, promise2]).then(done, done.fail);
  664. });
  665. it("gets non-existent attachments", function (done) {
  666. var promise = doc.getAttachments();
  667. promise.then(function (data) {
  668. expect(data).toEqual(null);
  669. done();
  670. }).catch(done.fail);
  671. });
  672. it("gets attachments", function (done) {
  673. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("attachment.pdf"));
  674. var promise = loadingTask.promise.then(function (pdfDoc) {
  675. return pdfDoc.getAttachments();
  676. });
  677. promise.then(function (data) {
  678. var attachment = data["foo.txt"];
  679. expect(attachment.filename).toEqual("foo.txt");
  680. expect(attachment.content).toEqual(new Uint8Array([98, 97, 114, 32, 98, 97, 122, 32, 10]));
  681. loadingTask.destroy().then(done);
  682. }).catch(done.fail);
  683. });
  684. it("gets javascript", function (done) {
  685. var promise = doc.getJavaScript();
  686. promise.then(function (data) {
  687. expect(data).toEqual(null);
  688. done();
  689. }).catch(done.fail);
  690. });
  691. it("gets javascript with printing instructions (JS action)", function (done) {
  692. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue6106.pdf"));
  693. var promise = loadingTask.promise.then(function (doc) {
  694. return doc.getJavaScript();
  695. });
  696. promise.then(function (data) {
  697. expect(data).toEqual(["this.print({bUI:true,bSilent:false,bShrinkToFit:true});"]);
  698. expect(data[0]).toMatch(_ui_utils.AutoPrintRegExp);
  699. loadingTask.destroy().then(done);
  700. }).catch(done.fail);
  701. });
  702. it("gets non-existent outline", function (done) {
  703. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
  704. var promise = loadingTask.promise.then(function (pdfDocument) {
  705. return pdfDocument.getOutline();
  706. });
  707. promise.then(function (outline) {
  708. expect(outline).toEqual(null);
  709. loadingTask.destroy().then(done);
  710. }).catch(done.fail);
  711. });
  712. it("gets outline", function (done) {
  713. var promise = doc.getOutline();
  714. promise.then(function (outline) {
  715. expect(Array.isArray(outline)).toEqual(true);
  716. expect(outline.length).toEqual(2);
  717. var outlineItem = outline[1];
  718. expect(outlineItem.title).toEqual("Chapter 1");
  719. expect(Array.isArray(outlineItem.dest)).toEqual(true);
  720. expect(outlineItem.url).toEqual(null);
  721. expect(outlineItem.unsafeUrl).toBeUndefined();
  722. expect(outlineItem.newWindow).toBeUndefined();
  723. expect(outlineItem.bold).toEqual(true);
  724. expect(outlineItem.italic).toEqual(false);
  725. expect(outlineItem.color).toEqual(new Uint8ClampedArray([0, 64, 128]));
  726. expect(outlineItem.items.length).toEqual(1);
  727. expect(outlineItem.items[0].title).toEqual("Paragraph 1.1");
  728. done();
  729. }).catch(done.fail);
  730. });
  731. it("gets outline containing a url", function (done) {
  732. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue3214.pdf"));
  733. loadingTask.promise.then(function (pdfDocument) {
  734. pdfDocument.getOutline().then(function (outline) {
  735. expect(Array.isArray(outline)).toEqual(true);
  736. expect(outline.length).toEqual(5);
  737. var outlineItemTwo = outline[2];
  738. expect(typeof outlineItemTwo.title).toEqual("string");
  739. expect(outlineItemTwo.dest).toEqual(null);
  740. expect(outlineItemTwo.url).toEqual("http://google.com/");
  741. expect(outlineItemTwo.unsafeUrl).toEqual("http://google.com");
  742. expect(outlineItemTwo.newWindow).toBeUndefined();
  743. var outlineItemOne = outline[1];
  744. expect(outlineItemOne.bold).toEqual(false);
  745. expect(outlineItemOne.italic).toEqual(true);
  746. expect(outlineItemOne.color).toEqual(new Uint8ClampedArray([0, 0, 0]));
  747. loadingTask.destroy().then(done);
  748. });
  749. }).catch(done.fail);
  750. });
  751. it("gets non-existent permissions", function (done) {
  752. doc.getPermissions().then(function (permissions) {
  753. expect(permissions).toEqual(null);
  754. done();
  755. }).catch(done.fail);
  756. });
  757. it("gets permissions", function (done) {
  758. const loadingTask0 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue9972-1.pdf"));
  759. const promise0 = loadingTask0.promise.then(function (pdfDocument) {
  760. return pdfDocument.getPermissions();
  761. });
  762. const loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue9972-2.pdf"));
  763. const promise1 = loadingTask1.promise.then(function (pdfDocument) {
  764. return pdfDocument.getPermissions();
  765. });
  766. const loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue9972-3.pdf"));
  767. const promise2 = loadingTask2.promise.then(function (pdfDocument) {
  768. return pdfDocument.getPermissions();
  769. });
  770. const totalPermissionCount = Object.keys(_util.PermissionFlag).length;
  771. Promise.all([promise0, promise1, promise2]).then(function (permissions) {
  772. expect(permissions[0].length).toEqual(totalPermissionCount - 1);
  773. expect(permissions[0].includes(_util.PermissionFlag.MODIFY_CONTENTS)).toBeFalsy();
  774. expect(permissions[1].length).toEqual(totalPermissionCount - 2);
  775. expect(permissions[1].includes(_util.PermissionFlag.PRINT)).toBeFalsy();
  776. expect(permissions[1].includes(_util.PermissionFlag.PRINT_HIGH_QUALITY)).toBeFalsy();
  777. expect(permissions[2].length).toEqual(totalPermissionCount - 1);
  778. expect(permissions[2].includes(_util.PermissionFlag.COPY)).toBeFalsy();
  779. Promise.all([loadingTask0.destroy(), loadingTask1.destroy(), loadingTask2.destroy()]).then(done);
  780. }).catch(done.fail);
  781. });
  782. it("gets metadata", function (done) {
  783. var promise = doc.getMetadata();
  784. promise.then(function ({
  785. info,
  786. metadata,
  787. contentDispositionFilename
  788. }) {
  789. expect(info["Title"]).toEqual("Basic API Test");
  790. expect(info["Custom"]).toEqual(undefined);
  791. expect(info["PDFFormatVersion"]).toEqual("1.7");
  792. expect(info["IsLinearized"]).toEqual(false);
  793. expect(info["IsAcroFormPresent"]).toEqual(false);
  794. expect(info["IsXFAPresent"]).toEqual(false);
  795. expect(info["IsCollectionPresent"]).toEqual(false);
  796. expect(metadata instanceof _metadata.Metadata).toEqual(true);
  797. expect(metadata.get("dc:title")).toEqual("Basic API Test");
  798. expect(contentDispositionFilename).toEqual(null);
  799. done();
  800. }).catch(done.fail);
  801. });
  802. it("gets metadata, with custom info dict entries", function (done) {
  803. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
  804. loadingTask.promise.then(function (pdfDocument) {
  805. return pdfDocument.getMetadata();
  806. }).then(function ({
  807. info,
  808. metadata,
  809. contentDispositionFilename
  810. }) {
  811. expect(info["Creator"]).toEqual("TeX");
  812. expect(info["Producer"]).toEqual("pdfeTeX-1.21a");
  813. expect(info["CreationDate"]).toEqual("D:20090401163925-07'00'");
  814. const custom = info["Custom"];
  815. expect(typeof custom === "object" && custom !== null).toEqual(true);
  816. expect(custom["PTEX.Fullbanner"]).toEqual("This is pdfeTeX, " + "Version 3.141592-1.21a-2.2 (Web2C 7.5.4) kpathsea version 3.5.6");
  817. expect(info["PDFFormatVersion"]).toEqual("1.4");
  818. expect(info["IsLinearized"]).toEqual(false);
  819. expect(info["IsAcroFormPresent"]).toEqual(false);
  820. expect(info["IsXFAPresent"]).toEqual(false);
  821. expect(info["IsCollectionPresent"]).toEqual(false);
  822. expect(metadata).toEqual(null);
  823. expect(contentDispositionFilename).toEqual(null);
  824. loadingTask.destroy().then(done);
  825. }).catch(done.fail);
  826. });
  827. it("gets metadata, with missing PDF header (bug 1606566)", function (done) {
  828. const loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("bug1606566.pdf"));
  829. loadingTask.promise.then(function (pdfDocument) {
  830. return pdfDocument.getMetadata();
  831. }).then(function ({
  832. info,
  833. metadata,
  834. contentDispositionFilename
  835. }) {
  836. expect(info["PDFFormatVersion"]).toEqual(null);
  837. expect(info["IsLinearized"]).toEqual(false);
  838. expect(info["IsAcroFormPresent"]).toEqual(false);
  839. expect(info["IsXFAPresent"]).toEqual(false);
  840. expect(info["IsCollectionPresent"]).toEqual(false);
  841. expect(metadata).toEqual(null);
  842. expect(contentDispositionFilename).toEqual(null);
  843. loadingTask.destroy().then(done);
  844. }).catch(done.fail);
  845. });
  846. it("gets data", function (done) {
  847. var promise = doc.getData();
  848. promise.then(function (data) {
  849. expect(data instanceof Uint8Array).toEqual(true);
  850. expect(data.length).toEqual(basicApiFileLength);
  851. done();
  852. }).catch(done.fail);
  853. });
  854. it("gets download info", function (done) {
  855. var promise = doc.getDownloadInfo();
  856. promise.then(function (data) {
  857. expect(data).toEqual({
  858. length: basicApiFileLength
  859. });
  860. done();
  861. }).catch(done.fail);
  862. });
  863. it("gets document stats", function (done) {
  864. var promise = doc.getStats();
  865. promise.then(function (stats) {
  866. expect(stats).toEqual({
  867. streamTypes: {},
  868. fontTypes: {}
  869. });
  870. done();
  871. }).catch(done.fail);
  872. });
  873. it("cleans up document resources", function (done) {
  874. const promise = doc.cleanup();
  875. promise.then(function () {
  876. expect(true).toEqual(true);
  877. done();
  878. }, done.fail);
  879. });
  880. it("checks that fingerprints are unique", function (done) {
  881. const loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue4436r.pdf"));
  882. const loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue4575.pdf"));
  883. Promise.all([loadingTask1.promise, loadingTask2.promise]).then(function (data) {
  884. const fingerprint1 = data[0].fingerprint;
  885. const fingerprint2 = data[1].fingerprint;
  886. expect(fingerprint1).not.toEqual(fingerprint2);
  887. expect(fingerprint1).toEqual("2f695a83d6e7553c24fc08b7ac69712d");
  888. expect(fingerprint2).toEqual("04c7126b34a46b6d4d6e7a1eff7edcb6");
  889. Promise.all([loadingTask1.destroy(), loadingTask2.destroy()]).then(done);
  890. }).catch(done.fail);
  891. });
  892. describe("Cross-origin", function () {
  893. var loadingTask;
  894. function _checkCanLoad(expectSuccess, filename, options) {
  895. if (_is_node.isNodeJS) {
  896. pending("Cannot simulate cross-origin requests in Node.js");
  897. }
  898. var params = (0, _test_utils.buildGetDocumentParams)(filename, options);
  899. var url = new URL(params.url);
  900. if (url.hostname === "localhost") {
  901. url.hostname = "127.0.0.1";
  902. } else if (params.url.hostname === "127.0.0.1") {
  903. url.hostname = "localhost";
  904. } else {
  905. pending("Can only run cross-origin test on localhost!");
  906. }
  907. params.url = url.href;
  908. loadingTask = (0, _api.getDocument)(params);
  909. return loadingTask.promise.then(function (pdf) {
  910. return pdf.destroy();
  911. }).then(function () {
  912. expect(expectSuccess).toEqual(true);
  913. }, function (error) {
  914. if (expectSuccess) {
  915. expect(error).toEqual("There should not be any error");
  916. }
  917. expect(expectSuccess).toEqual(false);
  918. });
  919. }
  920. function testCanLoad(filename, options) {
  921. return _checkCanLoad(true, filename, options);
  922. }
  923. function testCannotLoad(filename, options) {
  924. return _checkCanLoad(false, filename, options);
  925. }
  926. afterEach(function (done) {
  927. if (loadingTask && !loadingTask.destroyed) {
  928. loadingTask.destroy().then(done);
  929. } else {
  930. done();
  931. }
  932. });
  933. it("server disallows cors", function (done) {
  934. testCannotLoad("basicapi.pdf").then(done);
  935. });
  936. it("server allows cors without credentials, default withCredentials", function (done) {
  937. testCanLoad("basicapi.pdf?cors=withoutCredentials").then(done);
  938. });
  939. it("server allows cors without credentials, and withCredentials=false", function (done) {
  940. testCanLoad("basicapi.pdf?cors=withoutCredentials", {
  941. withCredentials: false
  942. }).then(done);
  943. });
  944. it("server allows cors without credentials, but withCredentials=true", function (done) {
  945. testCannotLoad("basicapi.pdf?cors=withoutCredentials", {
  946. withCredentials: true
  947. }).then(done);
  948. });
  949. it("server allows cors with credentials, and withCredentials=true", function (done) {
  950. testCanLoad("basicapi.pdf?cors=withCredentials", {
  951. withCredentials: true
  952. }).then(done);
  953. });
  954. it("server allows cors with credentials, and withCredentials=false", function (done) {
  955. testCanLoad("basicapi.pdf?cors=withCredentials", {
  956. withCredentials: false
  957. }).then(done);
  958. });
  959. });
  960. });
  961. describe("Page", function () {
  962. var loadingTask;
  963. var pdfDocument, page;
  964. beforeAll(function (done) {
  965. loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
  966. loadingTask.promise.then(function (doc) {
  967. pdfDocument = doc;
  968. pdfDocument.getPage(1).then(function (data) {
  969. page = data;
  970. done();
  971. });
  972. }).catch(done.fail);
  973. });
  974. afterAll(function (done) {
  975. loadingTask.destroy().then(done);
  976. });
  977. it("gets page number", function () {
  978. expect(page.pageNumber).toEqual(1);
  979. });
  980. it("gets rotate", function () {
  981. expect(page.rotate).toEqual(0);
  982. });
  983. it("gets ref", function () {
  984. expect(page.ref).toEqual({
  985. num: 15,
  986. gen: 0
  987. });
  988. });
  989. it("gets userUnit", function () {
  990. expect(page.userUnit).toEqual(1.0);
  991. });
  992. it("gets view", function () {
  993. expect(page.view).toEqual([0, 0, 595.28, 841.89]);
  994. });
  995. it("gets view, with empty/invalid bounding boxes", function (done) {
  996. const viewLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("boundingBox_invalid.pdf"));
  997. viewLoadingTask.promise.then(pdfDoc => {
  998. const numPages = pdfDoc.numPages;
  999. expect(numPages).toEqual(3);
  1000. const viewPromises = [];
  1001. for (let i = 0; i < numPages; i++) {
  1002. viewPromises[i] = pdfDoc.getPage(i + 1).then(pdfPage => {
  1003. return pdfPage.view;
  1004. });
  1005. }
  1006. Promise.all(viewPromises).then(([page1, page2, page3]) => {
  1007. expect(page1).toEqual([0, 0, 612, 792]);
  1008. expect(page2).toEqual([0, 0, 800, 600]);
  1009. expect(page3).toEqual([0, 0, 600, 800]);
  1010. viewLoadingTask.destroy().then(done);
  1011. });
  1012. }).catch(done.fail);
  1013. });
  1014. it("gets viewport", function () {
  1015. var viewport = page.getViewport({
  1016. scale: 1.5,
  1017. rotation: 90
  1018. });
  1019. expect(viewport.viewBox).toEqual(page.view);
  1020. expect(viewport.scale).toEqual(1.5);
  1021. expect(viewport.rotation).toEqual(90);
  1022. expect(viewport.transform).toEqual([0, 1.5, 1.5, 0, 0, 0]);
  1023. expect(viewport.width).toEqual(1262.835);
  1024. expect(viewport.height).toEqual(892.92);
  1025. });
  1026. it('gets viewport with "offsetX/offsetY" arguments', function () {
  1027. const viewport = page.getViewport({
  1028. scale: 1,
  1029. rotation: 0,
  1030. offsetX: 100,
  1031. offsetY: -100
  1032. });
  1033. expect(viewport.transform).toEqual([1, 0, 0, -1, 100, 741.89]);
  1034. });
  1035. it('gets viewport respecting "dontFlip" argument', function () {
  1036. const scale = 1,
  1037. rotation = 0;
  1038. const viewport = page.getViewport({
  1039. scale,
  1040. rotation
  1041. });
  1042. const dontFlipViewport = page.getViewport({
  1043. scale,
  1044. rotation,
  1045. dontFlip: true
  1046. });
  1047. expect(dontFlipViewport).not.toEqual(viewport);
  1048. expect(dontFlipViewport).toEqual(viewport.clone({
  1049. dontFlip: true
  1050. }));
  1051. expect(viewport.transform).toEqual([1, 0, 0, -1, 0, 841.89]);
  1052. expect(dontFlipViewport.transform).toEqual([1, 0, -0, 1, 0, 0]);
  1053. });
  1054. it("gets annotations", function (done) {
  1055. var defaultPromise = page.getAnnotations().then(function (data) {
  1056. expect(data.length).toEqual(4);
  1057. });
  1058. var displayPromise = page.getAnnotations({
  1059. intent: "display"
  1060. }).then(function (data) {
  1061. expect(data.length).toEqual(4);
  1062. });
  1063. var printPromise = page.getAnnotations({
  1064. intent: "print"
  1065. }).then(function (data) {
  1066. expect(data.length).toEqual(4);
  1067. });
  1068. Promise.all([defaultPromise, displayPromise, printPromise]).then(function () {
  1069. done();
  1070. }).catch(done.fail);
  1071. });
  1072. it("gets annotations containing relative URLs (bug 766086)", function (done) {
  1073. var filename = "bug766086.pdf";
  1074. var defaultLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename));
  1075. var defaultPromise = defaultLoadingTask.promise.then(function (pdfDoc) {
  1076. return pdfDoc.getPage(1).then(function (pdfPage) {
  1077. return pdfPage.getAnnotations();
  1078. });
  1079. });
  1080. var docBaseUrlLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
  1081. docBaseUrl: "http://www.example.com/test/pdfs/qwerty.pdf"
  1082. }));
  1083. var docBaseUrlPromise = docBaseUrlLoadingTask.promise.then(function (pdfDoc) {
  1084. return pdfDoc.getPage(1).then(function (pdfPage) {
  1085. return pdfPage.getAnnotations();
  1086. });
  1087. });
  1088. var invalidDocBaseUrlLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
  1089. docBaseUrl: "qwerty.pdf"
  1090. }));
  1091. var invalidDocBaseUrlPromise = invalidDocBaseUrlLoadingTask.promise.then(function (pdfDoc) {
  1092. return pdfDoc.getPage(1).then(function (pdfPage) {
  1093. return pdfPage.getAnnotations();
  1094. });
  1095. });
  1096. Promise.all([defaultPromise, docBaseUrlPromise, invalidDocBaseUrlPromise]).then(function (data) {
  1097. var defaultAnnotations = data[0];
  1098. var docBaseUrlAnnotations = data[1];
  1099. var invalidDocBaseUrlAnnotations = data[2];
  1100. expect(defaultAnnotations[0].url).toBeUndefined();
  1101. expect(defaultAnnotations[0].unsafeUrl).toEqual("../../0021/002156/215675E.pdf#15");
  1102. expect(docBaseUrlAnnotations[0].url).toEqual("http://www.example.com/0021/002156/215675E.pdf#15");
  1103. expect(docBaseUrlAnnotations[0].unsafeUrl).toEqual("../../0021/002156/215675E.pdf#15");
  1104. expect(invalidDocBaseUrlAnnotations[0].url).toBeUndefined();
  1105. expect(invalidDocBaseUrlAnnotations[0].unsafeUrl).toEqual("../../0021/002156/215675E.pdf#15");
  1106. Promise.all([defaultLoadingTask.destroy(), docBaseUrlLoadingTask.destroy(), invalidDocBaseUrlLoadingTask.destroy()]).then(done);
  1107. }).catch(done.fail);
  1108. });
  1109. it("gets text content", function (done) {
  1110. var defaultPromise = page.getTextContent();
  1111. var parametersPromise = page.getTextContent({
  1112. normalizeWhitespace: true,
  1113. disableCombineTextItems: true
  1114. });
  1115. var promises = [defaultPromise, parametersPromise];
  1116. Promise.all(promises).then(function (data) {
  1117. expect(!!data[0].items).toEqual(true);
  1118. expect(data[0].items.length).toEqual(7);
  1119. expect(!!data[0].styles).toEqual(true);
  1120. expect(JSON.stringify(data[0])).toEqual(JSON.stringify(data[1]));
  1121. done();
  1122. }).catch(done.fail);
  1123. });
  1124. it("gets text content, with correct properties (issue 8276)", function (done) {
  1125. const loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue8276_reduced.pdf"));
  1126. loadingTask.promise.then(pdfDoc => {
  1127. pdfDoc.getPage(1).then(pdfPage => {
  1128. pdfPage.getTextContent().then(({
  1129. items,
  1130. styles
  1131. }) => {
  1132. expect(items.length).toEqual(1);
  1133. expect(Object.keys(styles)).toEqual(["Times"]);
  1134. expect(items[0]).toEqual({
  1135. dir: "ltr",
  1136. fontName: "Times",
  1137. height: 18,
  1138. str: "Issue 8276",
  1139. transform: [18, 0, 0, 18, 441.81, 708.4499999999999],
  1140. width: 77.49
  1141. });
  1142. expect(styles.Times).toEqual({
  1143. fontFamily: "serif",
  1144. ascent: NaN,
  1145. descent: NaN,
  1146. vertical: false
  1147. });
  1148. loadingTask.destroy().then(done);
  1149. });
  1150. });
  1151. }).catch(done.fail);
  1152. });
  1153. it("gets operator list", function (done) {
  1154. var promise = page.getOperatorList();
  1155. promise.then(function (oplist) {
  1156. expect(!!oplist.fnArray).toEqual(true);
  1157. expect(!!oplist.argsArray).toEqual(true);
  1158. expect(oplist.lastChunk).toEqual(true);
  1159. done();
  1160. }).catch(done.fail);
  1161. });
  1162. it("gets operatorList with JPEG image (issue 4888)", function (done) {
  1163. const loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("cmykjpeg.pdf"));
  1164. loadingTask.promise.then(pdfDoc => {
  1165. pdfDoc.getPage(1).then(pdfPage => {
  1166. pdfPage.getOperatorList().then(opList => {
  1167. const imgIndex = opList.fnArray.indexOf(_util.OPS.paintImageXObject);
  1168. const imgArgs = opList.argsArray[imgIndex];
  1169. const {
  1170. data
  1171. } = pdfPage.objs.get(imgArgs[0]);
  1172. expect(data instanceof Uint8ClampedArray).toEqual(true);
  1173. expect(data.length).toEqual(90000);
  1174. loadingTask.destroy().then(done);
  1175. });
  1176. });
  1177. }).catch(done.fail);
  1178. });
  1179. it("gets operatorList, from corrupt PDF file (issue 8702), " + "with/without `stopAtErrors` set", function (done) {
  1180. const loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue8702.pdf", {
  1181. stopAtErrors: false
  1182. }));
  1183. const loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue8702.pdf", {
  1184. stopAtErrors: true
  1185. }));
  1186. const result1 = loadingTask1.promise.then(pdfDoc => {
  1187. return pdfDoc.getPage(1).then(pdfPage => {
  1188. return pdfPage.getOperatorList().then(opList => {
  1189. expect(opList.fnArray.length).toEqual(722);
  1190. expect(opList.argsArray.length).toEqual(722);
  1191. expect(opList.lastChunk).toEqual(true);
  1192. return loadingTask1.destroy();
  1193. });
  1194. });
  1195. });
  1196. const result2 = loadingTask2.promise.then(pdfDoc => {
  1197. return pdfDoc.getPage(1).then(pdfPage => {
  1198. return pdfPage.getOperatorList().then(opList => {
  1199. expect(opList.fnArray.length).toEqual(0);
  1200. expect(opList.argsArray.length).toEqual(0);
  1201. expect(opList.lastChunk).toEqual(true);
  1202. return loadingTask2.destroy();
  1203. });
  1204. });
  1205. });
  1206. Promise.all([result1, result2]).then(done, done.fail);
  1207. });
  1208. it("gets document stats after parsing page", function (done) {
  1209. var promise = page.getOperatorList().then(function () {
  1210. return pdfDocument.getStats();
  1211. });
  1212. var expectedStreamTypes = {};
  1213. expectedStreamTypes[_util.StreamType.FLATE] = true;
  1214. var expectedFontTypes = {};
  1215. expectedFontTypes[_util.FontType.TYPE1] = true;
  1216. expectedFontTypes[_util.FontType.CIDFONTTYPE2] = true;
  1217. promise.then(function (stats) {
  1218. expect(stats).toEqual({
  1219. streamTypes: expectedStreamTypes,
  1220. fontTypes: expectedFontTypes
  1221. });
  1222. done();
  1223. }).catch(done.fail);
  1224. });
  1225. it("gets page stats after parsing page, without `pdfBug` set", function (done) {
  1226. page.getOperatorList().then(opList => {
  1227. return page.stats;
  1228. }).then(stats => {
  1229. expect(stats).toEqual(null);
  1230. done();
  1231. }, done.fail);
  1232. });
  1233. it("gets page stats after parsing page, with `pdfBug` set", function (done) {
  1234. const loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, {
  1235. pdfBug: true
  1236. }));
  1237. loadingTask.promise.then(pdfDoc => {
  1238. return pdfDoc.getPage(1).then(pdfPage => {
  1239. return pdfPage.getOperatorList().then(opList => {
  1240. return pdfPage.stats;
  1241. });
  1242. });
  1243. }).then(stats => {
  1244. expect(stats instanceof _display_utils.StatTimer).toEqual(true);
  1245. expect(stats.times.length).toEqual(1);
  1246. const [statEntry] = stats.times;
  1247. expect(statEntry.name).toEqual("Page Request");
  1248. expect(statEntry.end - statEntry.start).toBeGreaterThanOrEqual(0);
  1249. loadingTask.destroy().then(done);
  1250. }, done.fail);
  1251. });
  1252. it("gets page stats after rendering page, with `pdfBug` set", function (done) {
  1253. const loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, {
  1254. pdfBug: true
  1255. }));
  1256. let canvasAndCtx;
  1257. loadingTask.promise.then(pdfDoc => {
  1258. return pdfDoc.getPage(1).then(pdfPage => {
  1259. const viewport = pdfPage.getViewport({
  1260. scale: 1
  1261. });
  1262. canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
  1263. const renderTask = pdfPage.render({
  1264. canvasContext: canvasAndCtx.context,
  1265. canvasFactory: CanvasFactory,
  1266. viewport
  1267. });
  1268. return renderTask.promise.then(() => {
  1269. return pdfPage.stats;
  1270. });
  1271. });
  1272. }).then(stats => {
  1273. expect(stats instanceof _display_utils.StatTimer).toEqual(true);
  1274. expect(stats.times.length).toEqual(3);
  1275. const [statEntryOne, statEntryTwo, statEntryThree] = stats.times;
  1276. expect(statEntryOne.name).toEqual("Page Request");
  1277. expect(statEntryOne.end - statEntryOne.start).toBeGreaterThanOrEqual(0);
  1278. expect(statEntryTwo.name).toEqual("Rendering");
  1279. expect(statEntryTwo.end - statEntryTwo.start).toBeGreaterThan(0);
  1280. expect(statEntryThree.name).toEqual("Overall");
  1281. expect(statEntryThree.end - statEntryThree.start).toBeGreaterThan(0);
  1282. CanvasFactory.destroy(canvasAndCtx);
  1283. loadingTask.destroy().then(done);
  1284. }, done.fail);
  1285. });
  1286. it("cancels rendering of page", function (done) {
  1287. var viewport = page.getViewport({
  1288. scale: 1
  1289. });
  1290. var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
  1291. var renderTask = page.render({
  1292. canvasContext: canvasAndCtx.context,
  1293. canvasFactory: CanvasFactory,
  1294. viewport
  1295. });
  1296. renderTask.cancel();
  1297. renderTask.promise.then(function () {
  1298. done.fail("shall cancel rendering");
  1299. }).catch(function (error) {
  1300. expect(error instanceof _display_utils.RenderingCancelledException).toEqual(true);
  1301. expect(error.message).toEqual("Rendering cancelled, page 1");
  1302. expect(error.type).toEqual("canvas");
  1303. CanvasFactory.destroy(canvasAndCtx);
  1304. done();
  1305. });
  1306. });
  1307. it("re-render page, using the same canvas, after cancelling rendering", function (done) {
  1308. const viewport = page.getViewport({
  1309. scale: 1
  1310. });
  1311. const canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
  1312. const renderTask = page.render({
  1313. canvasContext: canvasAndCtx.context,
  1314. canvasFactory: CanvasFactory,
  1315. viewport
  1316. });
  1317. renderTask.cancel();
  1318. renderTask.promise.then(() => {
  1319. throw new Error("shall cancel rendering");
  1320. }, reason => {
  1321. expect(reason instanceof _display_utils.RenderingCancelledException).toEqual(true);
  1322. }).then(() => {
  1323. const reRenderTask = page.render({
  1324. canvasContext: canvasAndCtx.context,
  1325. canvasFactory: CanvasFactory,
  1326. viewport
  1327. });
  1328. return reRenderTask.promise;
  1329. }).then(() => {
  1330. CanvasFactory.destroy(canvasAndCtx);
  1331. done();
  1332. }, done.fail);
  1333. });
  1334. it("multiple render() on the same canvas", function (done) {
  1335. var viewport = page.getViewport({
  1336. scale: 1
  1337. });
  1338. var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
  1339. var renderTask1 = page.render({
  1340. canvasContext: canvasAndCtx.context,
  1341. canvasFactory: CanvasFactory,
  1342. viewport
  1343. });
  1344. var renderTask2 = page.render({
  1345. canvasContext: canvasAndCtx.context,
  1346. canvasFactory: CanvasFactory,
  1347. viewport
  1348. });
  1349. Promise.all([renderTask1.promise, renderTask2.promise.then(() => {
  1350. done.fail("shall fail rendering");
  1351. }, reason => {
  1352. expect(/multiple render\(\)/.test(reason.message)).toEqual(true);
  1353. })]).then(done);
  1354. });
  1355. it("cleans up document resources after rendering of page", function (done) {
  1356. const loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName));
  1357. let canvasAndCtx;
  1358. loadingTask.promise.then(pdfDoc => {
  1359. return pdfDoc.getPage(1).then(pdfPage => {
  1360. const viewport = pdfPage.getViewport({
  1361. scale: 1
  1362. });
  1363. canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
  1364. const renderTask = pdfPage.render({
  1365. canvasContext: canvasAndCtx.context,
  1366. canvasFactory: CanvasFactory,
  1367. viewport
  1368. });
  1369. return renderTask.promise.then(() => {
  1370. return pdfDoc.cleanup();
  1371. });
  1372. });
  1373. }).then(() => {
  1374. expect(true).toEqual(true);
  1375. CanvasFactory.destroy(canvasAndCtx);
  1376. loadingTask.destroy().then(done);
  1377. }, done.fail);
  1378. });
  1379. it("cleans up document resources during rendering of page", function (done) {
  1380. const loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
  1381. let canvasAndCtx;
  1382. loadingTask.promise.then(pdfDoc => {
  1383. return pdfDoc.getPage(1).then(pdfPage => {
  1384. const viewport = pdfPage.getViewport({
  1385. scale: 1
  1386. });
  1387. canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
  1388. const renderTask = pdfPage.render({
  1389. canvasContext: canvasAndCtx.context,
  1390. canvasFactory: CanvasFactory,
  1391. viewport
  1392. });
  1393. pdfDoc.cleanup().then(() => {
  1394. throw new Error("shall fail cleanup");
  1395. }, reason => {
  1396. expect(reason instanceof Error).toEqual(true);
  1397. expect(reason.message).toEqual("startCleanup: Page 1 is currently rendering.");
  1398. }).then(() => {
  1399. return renderTask.promise;
  1400. }).then(() => {
  1401. CanvasFactory.destroy(canvasAndCtx);
  1402. loadingTask.destroy().then(done);
  1403. });
  1404. });
  1405. }).catch(done.fail);
  1406. });
  1407. });
  1408. describe("Multiple `getDocument` instances", function () {
  1409. var pdf1 = (0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf");
  1410. var pdf2 = (0, _test_utils.buildGetDocumentParams)("TAMReview.pdf");
  1411. var pdf3 = (0, _test_utils.buildGetDocumentParams)("issue6068.pdf");
  1412. var loadingTasks = [];
  1413. async function renderPDF(filename) {
  1414. const loadingTask = (0, _api.getDocument)(filename);
  1415. loadingTasks.push(loadingTask);
  1416. const pdf = await loadingTask.promise;
  1417. const page = await pdf.getPage(1);
  1418. const viewport = page.getViewport({
  1419. scale: 1.2
  1420. });
  1421. const canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
  1422. const renderTask = page.render({
  1423. canvasContext: canvasAndCtx.context,
  1424. canvasFactory: CanvasFactory,
  1425. viewport
  1426. });
  1427. await renderTask.promise;
  1428. const data = canvasAndCtx.canvas.toDataURL();
  1429. CanvasFactory.destroy(canvasAndCtx);
  1430. return data;
  1431. }
  1432. afterEach(function (done) {
  1433. const destroyPromises = loadingTasks.map(function (loadingTask) {
  1434. return loadingTask.destroy();
  1435. });
  1436. Promise.all(destroyPromises).then(done);
  1437. });
  1438. it("should correctly render PDFs in parallel", function (done) {
  1439. var baseline1, baseline2, baseline3;
  1440. var promiseDone = renderPDF(pdf1).then(function (data1) {
  1441. baseline1 = data1;
  1442. return renderPDF(pdf2);
  1443. }).then(function (data2) {
  1444. baseline2 = data2;
  1445. return renderPDF(pdf3);
  1446. }).then(function (data3) {
  1447. baseline3 = data3;
  1448. return Promise.all([renderPDF(pdf1), renderPDF(pdf2), renderPDF(pdf3)]);
  1449. }).then(function (dataUrls) {
  1450. expect(dataUrls[0]).toEqual(baseline1);
  1451. expect(dataUrls[1]).toEqual(baseline2);
  1452. expect(dataUrls[2]).toEqual(baseline3);
  1453. return true;
  1454. });
  1455. promiseDone.then(function () {
  1456. done();
  1457. }).catch(done.fail);
  1458. });
  1459. });
  1460. describe("PDFDataRangeTransport", function () {
  1461. let dataPromise;
  1462. beforeAll(function (done) {
  1463. const fileName = "tracemonkey.pdf";
  1464. if (_is_node.isNodeJS) {
  1465. dataPromise = _test_utils.NodeFileReaderFactory.fetch({
  1466. path: _test_utils.TEST_PDFS_PATH.node + fileName
  1467. });
  1468. } else {
  1469. dataPromise = _test_utils.DOMFileReaderFactory.fetch({
  1470. path: _test_utils.TEST_PDFS_PATH.dom + fileName
  1471. });
  1472. }
  1473. done();
  1474. });
  1475. afterAll(function () {
  1476. dataPromise = null;
  1477. });
  1478. it("should fetch document info and page using ranges", function (done) {
  1479. const initialDataLength = 4000;
  1480. let fetches = 0,
  1481. loadingTask;
  1482. dataPromise.then(function (data) {
  1483. const initialData = data.subarray(0, initialDataLength);
  1484. const transport = new _api.PDFDataRangeTransport(data.length, initialData);
  1485. transport.requestDataRange = function (begin, end) {
  1486. fetches++;
  1487. waitSome(function () {
  1488. transport.onDataProgress(4000);
  1489. transport.onDataRange(begin, data.subarray(begin, end));
  1490. });
  1491. };
  1492. loadingTask = (0, _api.getDocument)(transport);
  1493. return loadingTask.promise;
  1494. }).then(function (pdfDocument) {
  1495. expect(pdfDocument.numPages).toEqual(14);
  1496. return pdfDocument.getPage(10);
  1497. }).then(function (pdfPage) {
  1498. expect(pdfPage.rotate).toEqual(0);
  1499. expect(fetches).toBeGreaterThan(2);
  1500. loadingTask.destroy().then(done);
  1501. }).catch(done.fail);
  1502. });
  1503. it("should fetch document info and page using range and streaming", function (done) {
  1504. const initialDataLength = 4000;
  1505. let fetches = 0,
  1506. loadingTask;
  1507. dataPromise.then(function (data) {
  1508. const initialData = data.subarray(0, initialDataLength);
  1509. const transport = new _api.PDFDataRangeTransport(data.length, initialData);
  1510. transport.requestDataRange = function (begin, end) {
  1511. fetches++;
  1512. if (fetches === 1) {
  1513. transport.onDataProgressiveRead(data.subarray(initialDataLength));
  1514. }
  1515. waitSome(function () {
  1516. transport.onDataRange(begin, data.subarray(begin, end));
  1517. });
  1518. };
  1519. loadingTask = (0, _api.getDocument)(transport);
  1520. return loadingTask.promise;
  1521. }).then(function (pdfDocument) {
  1522. expect(pdfDocument.numPages).toEqual(14);
  1523. return pdfDocument.getPage(10);
  1524. }).then(function (pdfPage) {
  1525. expect(pdfPage.rotate).toEqual(0);
  1526. expect(fetches).toEqual(1);
  1527. waitSome(function () {
  1528. loadingTask.destroy().then(done);
  1529. });
  1530. }).catch(done.fail);
  1531. });
  1532. it("should fetch document info and page, without range, " + "using complete initialData", function (done) {
  1533. let fetches = 0,
  1534. loadingTask;
  1535. dataPromise.then(function (data) {
  1536. const transport = new _api.PDFDataRangeTransport(data.length, data, true);
  1537. transport.requestDataRange = function (begin, end) {
  1538. fetches++;
  1539. };
  1540. loadingTask = (0, _api.getDocument)({
  1541. disableRange: true,
  1542. range: transport
  1543. });
  1544. return loadingTask.promise;
  1545. }).then(function (pdfDocument) {
  1546. expect(pdfDocument.numPages).toEqual(14);
  1547. return pdfDocument.getPage(10);
  1548. }).then(function (pdfPage) {
  1549. expect(pdfPage.rotate).toEqual(0);
  1550. expect(fetches).toEqual(0);
  1551. loadingTask.destroy().then(done);
  1552. }).catch(done.fail);
  1553. });
  1554. });
  1555. });