api_spec.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  17. var _test_utils = require('./test_utils');
  18. var _util = require('../../shared/util');
  19. var _dom_utils = require('../../display/dom_utils');
  20. var _api = require('../../display/api');
  21. var _global = require('../../display/global');
  22. describe('api', function () {
  23. var basicApiFileName = 'basicapi.pdf';
  24. var basicApiFileLength = 105779;
  25. var basicApiGetDocumentParams = (0, _test_utils.buildGetDocumentParams)(basicApiFileName);
  26. var CanvasFactory = void 0;
  27. beforeAll(function (done) {
  28. if ((0, _util.isNodeJS)()) {
  29. _global.PDFJS.pdfjsNext = true;
  30. } else {
  31. CanvasFactory = new _dom_utils.DOMCanvasFactory();
  32. }
  33. done();
  34. });
  35. afterAll(function (done) {
  36. CanvasFactory = null;
  37. done();
  38. });
  39. function waitSome(callback) {
  40. var WAIT_TIMEOUT = 10;
  41. setTimeout(function () {
  42. callback();
  43. }, WAIT_TIMEOUT);
  44. }
  45. describe('PDFJS', function () {
  46. describe('getDocument', function () {
  47. it('creates pdf doc from URL', function (done) {
  48. if ((0, _util.isNodeJS)()) {
  49. pending('XMLHttpRequest is not supported in Node.js.');
  50. }
  51. var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
  52. var isProgressReportedResolved = false;
  53. var progressReportedCapability = (0, _util.createPromiseCapability)();
  54. loadingTask.onProgress = function (progressData) {
  55. if (!isProgressReportedResolved) {
  56. isProgressReportedResolved = true;
  57. progressReportedCapability.resolve(progressData);
  58. }
  59. };
  60. var promises = [progressReportedCapability.promise, loadingTask.promise];
  61. Promise.all(promises).then(function (data) {
  62. expect(data[0].loaded / data[0].total > 0).toEqual(true);
  63. expect(data[1] instanceof _api.PDFDocumentProxy).toEqual(true);
  64. expect(loadingTask).toEqual(data[1].loadingTask);
  65. loadingTask.destroy().then(done);
  66. }).catch(function (reason) {
  67. done.fail(reason);
  68. });
  69. });
  70. it('creates pdf doc from URL and aborts before worker initialized', function (done) {
  71. if ((0, _util.isNodeJS)()) {
  72. pending('XMLHttpRequest is not supported in Node.js.');
  73. }
  74. var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
  75. var destroyed = loadingTask.destroy();
  76. loadingTask.promise.then(function (reason) {
  77. done.fail('shall fail loading');
  78. }).catch(function (reason) {
  79. expect(true).toEqual(true);
  80. destroyed.then(done);
  81. });
  82. });
  83. it('creates pdf doc from URL and aborts loading after worker initialized', function (done) {
  84. if ((0, _util.isNodeJS)()) {
  85. pending('XMLHttpRequest is not supported in Node.js.');
  86. }
  87. var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
  88. var destroyed = loadingTask._worker.promise.then(function () {
  89. return loadingTask.destroy();
  90. });
  91. destroyed.then(function (data) {
  92. expect(true).toEqual(true);
  93. done();
  94. }).catch(function (reason) {
  95. done.fail(reason);
  96. });
  97. });
  98. it('creates pdf doc from typed array', function (done) {
  99. var typedArrayPdf;
  100. if ((0, _util.isNodeJS)()) {
  101. typedArrayPdf = _test_utils.NodeFileReaderFactory.fetch({ path: _test_utils.TEST_PDFS_PATH.node + basicApiFileName });
  102. } else {
  103. var nonBinaryRequest = _global.PDFJS.disableWorker;
  104. var request = new XMLHttpRequest();
  105. request.open('GET', _test_utils.TEST_PDFS_PATH.dom + basicApiFileName, false);
  106. if (!nonBinaryRequest) {
  107. try {
  108. request.responseType = 'arraybuffer';
  109. nonBinaryRequest = request.responseType !== 'arraybuffer';
  110. } catch (e) {
  111. nonBinaryRequest = true;
  112. }
  113. }
  114. if (nonBinaryRequest && request.overrideMimeType) {
  115. request.overrideMimeType('text/plain; charset=x-user-defined');
  116. }
  117. request.send(null);
  118. if (nonBinaryRequest) {
  119. typedArrayPdf = (0, _util.stringToBytes)(request.responseText);
  120. } else {
  121. typedArrayPdf = new Uint8Array(request.response);
  122. }
  123. }
  124. expect(typedArrayPdf.length).toEqual(basicApiFileLength);
  125. var loadingTask = (0, _api.getDocument)(typedArrayPdf);
  126. loadingTask.promise.then(function (data) {
  127. expect(data instanceof _api.PDFDocumentProxy).toEqual(true);
  128. loadingTask.destroy().then(done);
  129. }).catch(function (reason) {
  130. done.fail(reason);
  131. });
  132. });
  133. it('creates pdf doc from invalid PDF file', function (done) {
  134. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug1020226.pdf'));
  135. loadingTask.promise.then(function () {
  136. done.fail('shall fail loading');
  137. }).catch(function (error) {
  138. expect(error instanceof _util.InvalidPDFException).toEqual(true);
  139. loadingTask.destroy().then(done);
  140. });
  141. });
  142. it('creates pdf doc from non-existent URL', function (done) {
  143. if ((0, _util.isNodeJS)()) {
  144. pending('XMLHttpRequest is not supported in Node.js.');
  145. }
  146. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('non-existent.pdf'));
  147. loadingTask.promise.then(function (error) {
  148. done.fail('shall fail loading');
  149. }).catch(function (error) {
  150. expect(error instanceof _util.MissingPDFException).toEqual(true);
  151. loadingTask.destroy().then(done);
  152. });
  153. });
  154. it('creates pdf doc from PDF file protected with user and owner password', function (done) {
  155. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('pr6531_1.pdf'));
  156. var isPasswordNeededResolved = false;
  157. var passwordNeededCapability = (0, _util.createPromiseCapability)();
  158. var isPasswordIncorrectResolved = false;
  159. var passwordIncorrectCapability = (0, _util.createPromiseCapability)();
  160. loadingTask.onPassword = function (updatePassword, reason) {
  161. if (reason === _util.PasswordResponses.NEED_PASSWORD && !isPasswordNeededResolved) {
  162. isPasswordNeededResolved = true;
  163. passwordNeededCapability.resolve();
  164. updatePassword('qwerty');
  165. return;
  166. }
  167. if (reason === _util.PasswordResponses.INCORRECT_PASSWORD && !isPasswordIncorrectResolved) {
  168. isPasswordIncorrectResolved = true;
  169. passwordIncorrectCapability.resolve();
  170. updatePassword('asdfasdf');
  171. return;
  172. }
  173. expect(false).toEqual(true);
  174. };
  175. var promises = [passwordNeededCapability.promise, passwordIncorrectCapability.promise, loadingTask.promise];
  176. Promise.all(promises).then(function (data) {
  177. expect(data[2] instanceof _api.PDFDocumentProxy).toEqual(true);
  178. loadingTask.destroy().then(done);
  179. }).catch(function (reason) {
  180. done.fail(reason);
  181. });
  182. });
  183. it('creates pdf doc from PDF file protected with only a user password', function (done) {
  184. var filename = 'pr6531_2.pdf';
  185. var passwordNeededLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, { password: '' }));
  186. var result1 = passwordNeededLoadingTask.promise.then(function () {
  187. done.fail('shall fail with no password');
  188. return Promise.reject(new Error('loadingTask should be rejected'));
  189. }, function (data) {
  190. expect(data instanceof _util.PasswordException).toEqual(true);
  191. expect(data.code).toEqual(_util.PasswordResponses.NEED_PASSWORD);
  192. return passwordNeededLoadingTask.destroy();
  193. });
  194. var passwordIncorrectLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, { password: 'qwerty' }));
  195. var result2 = passwordIncorrectLoadingTask.promise.then(function () {
  196. done.fail('shall fail with wrong password');
  197. return Promise.reject(new Error('loadingTask should be rejected'));
  198. }, function (data) {
  199. expect(data instanceof _util.PasswordException).toEqual(true);
  200. expect(data.code).toEqual(_util.PasswordResponses.INCORRECT_PASSWORD);
  201. return passwordIncorrectLoadingTask.destroy();
  202. });
  203. var passwordAcceptedLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, { password: 'asdfasdf' }));
  204. var result3 = passwordAcceptedLoadingTask.promise.then(function (data) {
  205. expect(data instanceof _api.PDFDocumentProxy).toEqual(true);
  206. return passwordAcceptedLoadingTask.destroy();
  207. });
  208. Promise.all([result1, result2, result3]).then(function () {
  209. done();
  210. }).catch(function (reason) {
  211. done.fail(reason);
  212. });
  213. });
  214. it('creates pdf doc from password protected PDF file and aborts/throws ' + 'in the onPassword callback (issue 7806)', function (done) {
  215. var filename = 'issue3371.pdf';
  216. var passwordNeededLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename));
  217. var passwordIncorrectLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, { password: 'qwerty' }));
  218. var passwordNeededDestroyed = void 0;
  219. passwordNeededLoadingTask.onPassword = function (callback, reason) {
  220. if (reason === _util.PasswordResponses.NEED_PASSWORD) {
  221. passwordNeededDestroyed = passwordNeededLoadingTask.destroy();
  222. return;
  223. }
  224. expect(false).toEqual(true);
  225. };
  226. var result1 = passwordNeededLoadingTask.promise.then(function () {
  227. done.fail('shall fail since the loadingTask should be destroyed');
  228. return Promise.reject(new Error('loadingTask should be rejected'));
  229. }, function (reason) {
  230. expect(reason instanceof _util.PasswordException).toEqual(true);
  231. expect(reason.code).toEqual(_util.PasswordResponses.NEED_PASSWORD);
  232. return passwordNeededDestroyed;
  233. });
  234. passwordIncorrectLoadingTask.onPassword = function (callback, reason) {
  235. if (reason === _util.PasswordResponses.INCORRECT_PASSWORD) {
  236. throw new Error('Incorrect password');
  237. }
  238. expect(false).toEqual(true);
  239. };
  240. var result2 = passwordIncorrectLoadingTask.promise.then(function () {
  241. done.fail('shall fail since the onPassword callback should throw');
  242. return Promise.reject(new Error('loadingTask should be rejected'));
  243. }, function (reason) {
  244. expect(reason instanceof _util.PasswordException).toEqual(true);
  245. expect(reason.code).toEqual(_util.PasswordResponses.INCORRECT_PASSWORD);
  246. return passwordIncorrectLoadingTask.destroy();
  247. });
  248. Promise.all([result1, result2]).then(function () {
  249. done();
  250. }).catch(function (reason) {
  251. done.fail(reason);
  252. });
  253. });
  254. });
  255. });
  256. describe('PDFWorker', function () {
  257. if ((0, _util.isNodeJS)()) {
  258. pending('Worker is not supported in Node.js.');
  259. }
  260. it('worker created or destroyed', function (done) {
  261. var worker = new _global.PDFJS.PDFWorker('test1');
  262. worker.promise.then(function () {
  263. expect(worker.name).toEqual('test1');
  264. expect(!!worker.port).toEqual(true);
  265. expect(worker.destroyed).toEqual(false);
  266. expect(!!worker._webWorker).toEqual(true);
  267. expect(worker.port === worker._webWorker).toEqual(true);
  268. worker.destroy();
  269. expect(!!worker.port).toEqual(false);
  270. expect(worker.destroyed).toEqual(true);
  271. done();
  272. }).catch(function (reason) {
  273. done.fail(reason);
  274. });
  275. });
  276. it('worker created or destroyed by getDocument', function (done) {
  277. var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
  278. var worker;
  279. loadingTask.promise.then(function () {
  280. worker = loadingTask._worker;
  281. expect(!!worker).toEqual(true);
  282. });
  283. var destroyPromise = loadingTask.promise.then(function () {
  284. return loadingTask.destroy();
  285. });
  286. destroyPromise.then(function () {
  287. var destroyedWorker = loadingTask._worker;
  288. expect(!!destroyedWorker).toEqual(false);
  289. expect(worker.destroyed).toEqual(true);
  290. done();
  291. }).catch(function (reason) {
  292. done.fail(reason);
  293. });
  294. });
  295. it('worker created and can be used in getDocument', function (done) {
  296. var worker = new _global.PDFJS.PDFWorker('test1');
  297. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, { worker: worker }));
  298. loadingTask.promise.then(function () {
  299. var docWorker = loadingTask._worker;
  300. expect(!!docWorker).toEqual(false);
  301. var messageHandlerPort = loadingTask._transport.messageHandler.comObj;
  302. expect(messageHandlerPort === worker.port).toEqual(true);
  303. });
  304. var destroyPromise = loadingTask.promise.then(function () {
  305. return loadingTask.destroy();
  306. });
  307. destroyPromise.then(function () {
  308. expect(worker.destroyed).toEqual(false);
  309. worker.destroy();
  310. done();
  311. }).catch(function (reason) {
  312. done.fail(reason);
  313. });
  314. });
  315. it('creates more than one worker', function (done) {
  316. var worker1 = new _global.PDFJS.PDFWorker('test1');
  317. var worker2 = new _global.PDFJS.PDFWorker('test2');
  318. var worker3 = new _global.PDFJS.PDFWorker('test3');
  319. var ready = Promise.all([worker1.promise, worker2.promise, worker3.promise]);
  320. ready.then(function () {
  321. expect(worker1.port !== worker2.port && worker1.port !== worker3.port && worker2.port !== worker3.port).toEqual(true);
  322. worker1.destroy();
  323. worker2.destroy();
  324. worker3.destroy();
  325. done();
  326. }).catch(function (reason) {
  327. done.fail(reason);
  328. });
  329. });
  330. });
  331. describe('PDFDocument', function () {
  332. var loadingTask;
  333. var doc;
  334. beforeAll(function (done) {
  335. loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
  336. loadingTask.promise.then(function (data) {
  337. doc = data;
  338. done();
  339. });
  340. });
  341. afterAll(function (done) {
  342. loadingTask.destroy().then(done);
  343. });
  344. it('gets number of pages', function () {
  345. expect(doc.numPages).toEqual(3);
  346. });
  347. it('gets fingerprint', function () {
  348. var fingerprint = doc.fingerprint;
  349. expect(typeof fingerprint === 'undefined' ? 'undefined' : _typeof(fingerprint)).toEqual('string');
  350. expect(fingerprint.length > 0).toEqual(true);
  351. });
  352. it('gets page', function (done) {
  353. var promise = doc.getPage(1);
  354. promise.then(function (data) {
  355. expect(data instanceof _api.PDFPageProxy).toEqual(true);
  356. expect(data.pageIndex).toEqual(0);
  357. done();
  358. }).catch(function (reason) {
  359. done.fail(reason);
  360. });
  361. });
  362. it('gets non-existent page', function (done) {
  363. var outOfRangePromise = doc.getPage(100);
  364. var nonIntegerPromise = doc.getPage(2.5);
  365. var nonNumberPromise = doc.getPage('1');
  366. outOfRangePromise = outOfRangePromise.then(function () {
  367. throw new Error('shall fail for out-of-range pageNumber parameter');
  368. }, function (reason) {
  369. expect(reason instanceof Error).toEqual(true);
  370. });
  371. nonIntegerPromise = nonIntegerPromise.then(function () {
  372. throw new Error('shall fail for non-integer pageNumber parameter');
  373. }, function (reason) {
  374. expect(reason instanceof Error).toEqual(true);
  375. });
  376. nonNumberPromise = nonNumberPromise.then(function () {
  377. throw new Error('shall fail for non-number pageNumber parameter');
  378. }, function (reason) {
  379. expect(reason instanceof Error).toEqual(true);
  380. });
  381. Promise.all([outOfRangePromise, nonIntegerPromise, nonNumberPromise]).then(function () {
  382. done();
  383. }).catch(function (reason) {
  384. done.fail(reason);
  385. });
  386. });
  387. it('gets page index', function (done) {
  388. var ref = {
  389. num: 17,
  390. gen: 0
  391. };
  392. var promise = doc.getPageIndex(ref);
  393. promise.then(function (pageIndex) {
  394. expect(pageIndex).toEqual(1);
  395. done();
  396. }).catch(function (reason) {
  397. done.fail(reason);
  398. });
  399. });
  400. it('gets invalid page index', function (done) {
  401. var ref = {
  402. num: 3,
  403. gen: 0
  404. };
  405. var promise = doc.getPageIndex(ref);
  406. promise.then(function () {
  407. done.fail('shall fail for invalid page reference.');
  408. }).catch(function (reason) {
  409. expect(reason instanceof Error).toEqual(true);
  410. done();
  411. });
  412. });
  413. it('gets destinations, from /Dests dictionary', function (done) {
  414. var promise = doc.getDestinations();
  415. promise.then(function (data) {
  416. expect(data).toEqual({
  417. chapter1: [{
  418. gen: 0,
  419. num: 17
  420. }, { name: 'XYZ' }, 0, 841.89, null]
  421. });
  422. done();
  423. }).catch(function (reason) {
  424. done.fail(reason);
  425. });
  426. });
  427. it('gets a destination, from /Dests dictionary', function (done) {
  428. var promise = doc.getDestination('chapter1');
  429. promise.then(function (data) {
  430. expect(data).toEqual([{
  431. gen: 0,
  432. num: 17
  433. }, { name: 'XYZ' }, 0, 841.89, null]);
  434. done();
  435. }).catch(function (reason) {
  436. done.fail(reason);
  437. });
  438. });
  439. it('gets a non-existent destination, from /Dests dictionary', function (done) {
  440. var promise = doc.getDestination('non-existent-named-destination');
  441. promise.then(function (data) {
  442. expect(data).toEqual(null);
  443. done();
  444. }).catch(function (reason) {
  445. done.fail(reason);
  446. });
  447. });
  448. it('gets destinations, from /Names (NameTree) dictionary', function (done) {
  449. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
  450. var promise = loadingTask.promise.then(function (pdfDocument) {
  451. return pdfDocument.getDestinations();
  452. });
  453. promise.then(function (destinations) {
  454. expect(destinations).toEqual({
  455. 'Page.1': [{
  456. num: 1,
  457. gen: 0
  458. }, { name: 'XYZ' }, 0, 375, null],
  459. 'Page.2': [{
  460. num: 6,
  461. gen: 0
  462. }, { name: 'XYZ' }, 0, 375, null]
  463. });
  464. loadingTask.destroy().then(done);
  465. }).catch(function (reason) {
  466. done.fail(reason);
  467. });
  468. });
  469. it('gets a destination, from /Names (NameTree) dictionary', function (done) {
  470. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
  471. var promise = loadingTask.promise.then(function (pdfDocument) {
  472. return pdfDocument.getDestination('Page.1');
  473. });
  474. promise.then(function (destination) {
  475. expect(destination).toEqual([{
  476. num: 1,
  477. gen: 0
  478. }, { name: 'XYZ' }, 0, 375, null]);
  479. loadingTask.destroy().then(done);
  480. }).catch(function (reason) {
  481. done.fail(reason);
  482. });
  483. });
  484. it('gets a non-existent destination, from /Names (NameTree) dictionary', function (done) {
  485. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
  486. var promise = loadingTask.promise.then(function (pdfDocument) {
  487. return pdfDocument.getDestination('non-existent-named-destination');
  488. });
  489. promise.then(function (destination) {
  490. expect(destination).toEqual(null);
  491. loadingTask.destroy().then(done);
  492. }).catch(function (reason) {
  493. done.fail(reason);
  494. });
  495. });
  496. it('gets non-existent page labels', function (done) {
  497. var promise = doc.getPageLabels();
  498. promise.then(function (data) {
  499. expect(data).toEqual(null);
  500. done();
  501. }).catch(function (reason) {
  502. done.fail(reason);
  503. });
  504. });
  505. it('gets page labels', function (done) {
  506. var loadingTask0 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug793632.pdf'));
  507. var promise0 = loadingTask0.promise.then(function (pdfDoc) {
  508. return pdfDoc.getPageLabels();
  509. });
  510. var loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue1453.pdf'));
  511. var promise1 = loadingTask1.promise.then(function (pdfDoc) {
  512. return pdfDoc.getPageLabels();
  513. });
  514. var loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('rotation.pdf'));
  515. var promise2 = loadingTask2.promise.then(function (pdfDoc) {
  516. return pdfDoc.getPageLabels();
  517. });
  518. var loadingTask3 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bad-PageLabels.pdf'));
  519. var promise3 = loadingTask3.promise.then(function (pdfDoc) {
  520. return pdfDoc.getPageLabels();
  521. });
  522. Promise.all([promise0, promise1, promise2, promise3]).then(function (pageLabels) {
  523. expect(pageLabels[0]).toEqual(['i', 'ii', 'iii', '1']);
  524. expect(pageLabels[1]).toEqual(['Front Page1']);
  525. expect(pageLabels[2]).toEqual(['1', '2']);
  526. expect(pageLabels[3]).toEqual(['X3']);
  527. Promise.all([loadingTask0.destroy(), loadingTask1.destroy(), loadingTask2.destroy(), loadingTask3.destroy()]).then(done);
  528. }).catch(function (reason) {
  529. done.fail(reason);
  530. });
  531. });
  532. it('gets default page mode', function (done) {
  533. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
  534. loadingTask.promise.then(function (pdfDocument) {
  535. return pdfDocument.getPageMode();
  536. }).then(function (mode) {
  537. expect(mode).toEqual('UseNone');
  538. loadingTask.destroy().then(done);
  539. }).catch(function (reason) {
  540. done.fail(reason);
  541. });
  542. });
  543. it('gets non-default page mode', function (done) {
  544. doc.getPageMode().then(function (mode) {
  545. expect(mode).toEqual('UseOutlines');
  546. done();
  547. }).catch(function (reason) {
  548. done.fail(reason);
  549. });
  550. });
  551. it('gets non-existent attachments', function (done) {
  552. var promise = doc.getAttachments();
  553. promise.then(function (data) {
  554. expect(data).toEqual(null);
  555. done();
  556. }).catch(function (reason) {
  557. done.fail(reason);
  558. });
  559. });
  560. it('gets attachments', function (done) {
  561. if ((0, _util.isNodeJS)()) {
  562. pending('TODO: Use a non-linked test-case.');
  563. }
  564. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug766138.pdf'));
  565. var promise = loadingTask.promise.then(function (pdfDoc) {
  566. return pdfDoc.getAttachments();
  567. });
  568. promise.then(function (data) {
  569. var attachment = data['Press Quality.joboptions'];
  570. expect(attachment.filename).toEqual('Press Quality.joboptions');
  571. expect(attachment.content instanceof Uint8Array).toBeTruthy();
  572. expect(attachment.content.length).toEqual(30098);
  573. loadingTask.destroy().then(done);
  574. }).catch(function (reason) {
  575. done.fail(reason);
  576. });
  577. });
  578. it('gets javascript', function (done) {
  579. var promise = doc.getJavaScript();
  580. promise.then(function (data) {
  581. expect(data).toEqual([]);
  582. done();
  583. }).catch(function (reason) {
  584. done.fail(reason);
  585. });
  586. });
  587. var viewerPrintRegExp = /\bprint\s*\(/;
  588. it('gets javascript with printing instructions (Print action)', function (done) {
  589. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug1001080.pdf'));
  590. var promise = loadingTask.promise.then(function (doc) {
  591. return doc.getJavaScript();
  592. });
  593. promise.then(function (data) {
  594. expect(data).toEqual(['print({});']);
  595. expect(data[0]).toMatch(viewerPrintRegExp);
  596. loadingTask.destroy().then(done);
  597. }).catch(function (reason) {
  598. done.fail(reason);
  599. });
  600. });
  601. it('gets javascript with printing instructions (JS action)', function (done) {
  602. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6106.pdf'));
  603. var promise = loadingTask.promise.then(function (doc) {
  604. return doc.getJavaScript();
  605. });
  606. promise.then(function (data) {
  607. expect(data).toEqual(['this.print({bUI:true,bSilent:false,bShrinkToFit:true});']);
  608. expect(data[0]).toMatch(viewerPrintRegExp);
  609. loadingTask.destroy().then(done);
  610. }).catch(function (reason) {
  611. done.fail(reason);
  612. });
  613. });
  614. it('gets non-existent outline', function (done) {
  615. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
  616. var promise = loadingTask.promise.then(function (pdfDocument) {
  617. return pdfDocument.getOutline();
  618. });
  619. promise.then(function (outline) {
  620. expect(outline).toEqual(null);
  621. loadingTask.destroy().then(done);
  622. }).catch(function (reason) {
  623. done.fail(reason);
  624. });
  625. });
  626. it('gets outline', function (done) {
  627. var promise = doc.getOutline();
  628. promise.then(function (outline) {
  629. expect(outline instanceof Array).toEqual(true);
  630. expect(outline.length).toEqual(2);
  631. var outlineItem = outline[1];
  632. expect(outlineItem.title).toEqual('Chapter 1');
  633. expect(outlineItem.dest instanceof Array).toEqual(true);
  634. expect(outlineItem.url).toEqual(null);
  635. expect(outlineItem.unsafeUrl).toBeUndefined();
  636. expect(outlineItem.newWindow).toBeUndefined();
  637. expect(outlineItem.bold).toEqual(true);
  638. expect(outlineItem.italic).toEqual(false);
  639. expect(outlineItem.color).toEqual(new Uint8Array([0, 64, 128]));
  640. expect(outlineItem.items.length).toEqual(1);
  641. expect(outlineItem.items[0].title).toEqual('Paragraph 1.1');
  642. done();
  643. }).catch(function (reason) {
  644. done.fail(reason);
  645. });
  646. });
  647. it('gets outline containing a url', function (done) {
  648. var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue3214.pdf'));
  649. loadingTask.promise.then(function (pdfDocument) {
  650. pdfDocument.getOutline().then(function (outline) {
  651. expect(outline instanceof Array).toEqual(true);
  652. expect(outline.length).toEqual(5);
  653. var outlineItemTwo = outline[2];
  654. expect(_typeof(outlineItemTwo.title)).toEqual('string');
  655. expect(outlineItemTwo.dest).toEqual(null);
  656. expect(outlineItemTwo.url).toEqual('http://google.com/');
  657. expect(outlineItemTwo.unsafeUrl).toEqual('http://google.com');
  658. expect(outlineItemTwo.newWindow).toBeUndefined();
  659. var outlineItemOne = outline[1];
  660. expect(outlineItemOne.bold).toEqual(false);
  661. expect(outlineItemOne.italic).toEqual(true);
  662. expect(outlineItemOne.color).toEqual(new Uint8Array([0, 0, 0]));
  663. loadingTask.destroy().then(done);
  664. });
  665. }).catch(function (reason) {
  666. done.fail(reason);
  667. });
  668. });
  669. it('gets metadata', function (done) {
  670. if ((0, _util.isNodeJS)()) {
  671. pending('Document is not supported in Node.js.');
  672. }
  673. var promise = doc.getMetadata();
  674. promise.then(function (metadata) {
  675. expect(metadata.info['Title']).toEqual('Basic API Test');
  676. expect(metadata.info['PDFFormatVersion']).toEqual('1.7');
  677. expect(metadata.metadata.get('dc:title')).toEqual('Basic API Test');
  678. done();
  679. }).catch(function (reason) {
  680. done.fail(reason);
  681. });
  682. });
  683. it('gets data', function (done) {
  684. var promise = doc.getData();
  685. promise.then(function (data) {
  686. expect(data instanceof Uint8Array).toEqual(true);
  687. expect(data.length).toEqual(basicApiFileLength);
  688. done();
  689. }).catch(function (reason) {
  690. done.fail(reason);
  691. });
  692. });
  693. it('gets download info', function (done) {
  694. var promise = doc.getDownloadInfo();
  695. promise.then(function (data) {
  696. expect(data).toEqual({ length: basicApiFileLength });
  697. done();
  698. }).catch(function (reason) {
  699. done.fail(reason);
  700. });
  701. });
  702. it('gets stats', function (done) {
  703. var promise = doc.getStats();
  704. promise.then(function (stats) {
  705. expect(stats).toEqual({
  706. streamTypes: [],
  707. fontTypes: []
  708. });
  709. done();
  710. }).catch(function (reason) {
  711. done.fail(reason);
  712. });
  713. });
  714. it('checks that fingerprints are unique', function (done) {
  715. var loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue4436r.pdf'));
  716. var loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue4575.pdf'));
  717. var promises = [loadingTask1.promise, loadingTask2.promise];
  718. Promise.all(promises).then(function (data) {
  719. var fingerprint1 = data[0].fingerprint;
  720. expect(typeof fingerprint1 === 'undefined' ? 'undefined' : _typeof(fingerprint1)).toEqual('string');
  721. expect(fingerprint1.length > 0).toEqual(true);
  722. var fingerprint2 = data[1].fingerprint;
  723. expect(typeof fingerprint2 === 'undefined' ? 'undefined' : _typeof(fingerprint2)).toEqual('string');
  724. expect(fingerprint2.length > 0).toEqual(true);
  725. expect(fingerprint1).not.toEqual(fingerprint2);
  726. Promise.all([loadingTask1.destroy(), loadingTask2.destroy()]).then(done);
  727. }).catch(function (reason) {
  728. done.fail(reason);
  729. });
  730. });
  731. });
  732. describe('Page', function () {
  733. var loadingTask;
  734. var pdfDocument, page;
  735. beforeAll(function (done) {
  736. loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
  737. loadingTask.promise.then(function (doc) {
  738. pdfDocument = doc;
  739. pdfDocument.getPage(1).then(function (data) {
  740. page = data;
  741. done();
  742. });
  743. }).catch(function (reason) {
  744. done.fail(reason);
  745. });
  746. });
  747. afterAll(function (done) {
  748. loadingTask.destroy().then(done);
  749. });
  750. it('gets page number', function () {
  751. expect(page.pageNumber).toEqual(1);
  752. });
  753. it('gets rotate', function () {
  754. expect(page.rotate).toEqual(0);
  755. });
  756. it('gets ref', function () {
  757. expect(page.ref).toEqual({
  758. num: 15,
  759. gen: 0
  760. });
  761. });
  762. it('gets userUnit', function () {
  763. expect(page.userUnit).toEqual(1.0);
  764. });
  765. it('gets view', function () {
  766. expect(page.view).toEqual([0, 0, 595.28, 841.89]);
  767. });
  768. it('gets viewport', function () {
  769. var viewport = page.getViewport(1.5, 90);
  770. expect(viewport.viewBox).toEqual(page.view);
  771. expect(viewport.scale).toEqual(1.5);
  772. expect(viewport.rotation).toEqual(90);
  773. expect(viewport.transform).toEqual([0, 1.5, 1.5, 0, 0, 0]);
  774. expect(viewport.width).toEqual(1262.835);
  775. expect(viewport.height).toEqual(892.92);
  776. });
  777. it('gets annotations', function (done) {
  778. var defaultPromise = page.getAnnotations().then(function (data) {
  779. expect(data.length).toEqual(4);
  780. });
  781. var displayPromise = page.getAnnotations({ intent: 'display' }).then(function (data) {
  782. expect(data.length).toEqual(4);
  783. });
  784. var printPromise = page.getAnnotations({ intent: 'print' }).then(function (data) {
  785. expect(data.length).toEqual(4);
  786. });
  787. Promise.all([defaultPromise, displayPromise, printPromise]).then(function () {
  788. done();
  789. }).catch(function (reason) {
  790. done.fail(reason);
  791. });
  792. });
  793. it('gets annotations containing relative URLs (bug 766086)', function (done) {
  794. var filename = 'bug766086.pdf';
  795. var defaultLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename));
  796. var defaultPromise = defaultLoadingTask.promise.then(function (pdfDoc) {
  797. return pdfDoc.getPage(1).then(function (pdfPage) {
  798. return pdfPage.getAnnotations();
  799. });
  800. });
  801. var docBaseUrlLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, { docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf' }));
  802. var docBaseUrlPromise = docBaseUrlLoadingTask.promise.then(function (pdfDoc) {
  803. return pdfDoc.getPage(1).then(function (pdfPage) {
  804. return pdfPage.getAnnotations();
  805. });
  806. });
  807. var invalidDocBaseUrlLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, { docBaseUrl: 'qwerty.pdf' }));
  808. var invalidDocBaseUrlPromise = invalidDocBaseUrlLoadingTask.promise.then(function (pdfDoc) {
  809. return pdfDoc.getPage(1).then(function (pdfPage) {
  810. return pdfPage.getAnnotations();
  811. });
  812. });
  813. Promise.all([defaultPromise, docBaseUrlPromise, invalidDocBaseUrlPromise]).then(function (data) {
  814. var defaultAnnotations = data[0];
  815. var docBaseUrlAnnotations = data[1];
  816. var invalidDocBaseUrlAnnotations = data[2];
  817. expect(defaultAnnotations[0].url).toBeUndefined();
  818. expect(defaultAnnotations[0].unsafeUrl).toEqual('../../0021/002156/215675E.pdf#15');
  819. expect(docBaseUrlAnnotations[0].url).toEqual('http://www.example.com/0021/002156/215675E.pdf#15');
  820. expect(docBaseUrlAnnotations[0].unsafeUrl).toEqual('../../0021/002156/215675E.pdf#15');
  821. expect(invalidDocBaseUrlAnnotations[0].url).toBeUndefined();
  822. expect(invalidDocBaseUrlAnnotations[0].unsafeUrl).toEqual('../../0021/002156/215675E.pdf#15');
  823. Promise.all([defaultLoadingTask.destroy(), docBaseUrlLoadingTask.destroy(), invalidDocBaseUrlLoadingTask.destroy()]).then(done);
  824. }).catch(function (reason) {
  825. done.fail(reason);
  826. });
  827. });
  828. it('gets text content', function (done) {
  829. var defaultPromise = page.getTextContent();
  830. var parametersPromise = page.getTextContent({
  831. normalizeWhitespace: true,
  832. disableCombineTextItems: true
  833. });
  834. var promises = [defaultPromise, parametersPromise];
  835. Promise.all(promises).then(function (data) {
  836. expect(!!data[0].items).toEqual(true);
  837. expect(data[0].items.length).toEqual(7);
  838. expect(!!data[0].styles).toEqual(true);
  839. expect(JSON.stringify(data[0])).toEqual(JSON.stringify(data[1]));
  840. done();
  841. }).catch(function (reason) {
  842. done.fail(reason);
  843. });
  844. });
  845. it('gets operator list', function (done) {
  846. var promise = page.getOperatorList();
  847. promise.then(function (oplist) {
  848. expect(!!oplist.fnArray).toEqual(true);
  849. expect(!!oplist.argsArray).toEqual(true);
  850. expect(oplist.lastChunk).toEqual(true);
  851. done();
  852. }).catch(function (reason) {
  853. done.fail(reason);
  854. });
  855. });
  856. it('gets stats after parsing page', function (done) {
  857. var promise = page.getOperatorList().then(function () {
  858. return pdfDocument.getStats();
  859. });
  860. var expectedStreamTypes = [];
  861. expectedStreamTypes[_util.StreamType.FLATE] = true;
  862. var expectedFontTypes = [];
  863. expectedFontTypes[_util.FontType.TYPE1] = true;
  864. expectedFontTypes[_util.FontType.CIDFONTTYPE2] = true;
  865. promise.then(function (stats) {
  866. expect(stats).toEqual({
  867. streamTypes: expectedStreamTypes,
  868. fontTypes: expectedFontTypes
  869. });
  870. done();
  871. }).catch(function (reason) {
  872. done.fail(reason);
  873. });
  874. });
  875. it('cancels rendering of page', function (done) {
  876. if ((0, _util.isNodeJS)()) {
  877. pending('TODO: Support Canvas testing in Node.js.');
  878. }
  879. var viewport = page.getViewport(1);
  880. var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
  881. var renderTask = page.render({
  882. canvasContext: canvasAndCtx.context,
  883. viewport: viewport
  884. });
  885. renderTask.cancel();
  886. renderTask.promise.then(function () {
  887. done.fail('shall cancel rendering');
  888. }).catch(function (error) {
  889. expect(error instanceof _dom_utils.RenderingCancelledException).toEqual(true);
  890. expect(error.type).toEqual('canvas');
  891. CanvasFactory.destroy(canvasAndCtx);
  892. done();
  893. });
  894. });
  895. it('multiple render() on the same canvas', function (done) {
  896. if ((0, _util.isNodeJS)()) {
  897. pending('TODO: Support Canvas testing in Node.js.');
  898. }
  899. var viewport = page.getViewport(1);
  900. var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
  901. var renderTask1 = page.render({
  902. canvasContext: canvasAndCtx.context,
  903. viewport: viewport
  904. });
  905. var renderTask2 = page.render({
  906. canvasContext: canvasAndCtx.context,
  907. viewport: viewport
  908. });
  909. Promise.all([renderTask1.promise, renderTask2.promise.then(function () {
  910. done.fail('shall fail rendering');
  911. }, function (reason) {
  912. expect(/multiple render\(\)/.test(reason.message)).toEqual(true);
  913. })]).then(done);
  914. });
  915. });
  916. describe('Multiple PDFJS instances', function () {
  917. if ((0, _util.isNodeJS)()) {
  918. pending('TODO: Support Canvas testing in Node.js.');
  919. }
  920. var pdf1 = (0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf');
  921. var pdf2 = (0, _test_utils.buildGetDocumentParams)('TAMReview.pdf');
  922. var pdf3 = (0, _test_utils.buildGetDocumentParams)('issue6068.pdf');
  923. var loadingTasks = [];
  924. var pdfDocuments = [];
  925. function renderPDF(filename) {
  926. var loadingTask = (0, _api.getDocument)(filename);
  927. loadingTasks.push(loadingTask);
  928. return loadingTask.promise.then(function (pdf) {
  929. pdfDocuments.push(pdf);
  930. return pdf.getPage(1);
  931. }).then(function (page) {
  932. var viewport = page.getViewport(1.2);
  933. var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
  934. return page.render({
  935. canvasContext: canvasAndCtx.context,
  936. viewport: viewport
  937. }).then(function () {
  938. var data = canvasAndCtx.canvas.toDataURL();
  939. CanvasFactory.destroy(canvasAndCtx);
  940. return data;
  941. });
  942. });
  943. }
  944. afterEach(function (done) {
  945. var destroyPromises = pdfDocuments.map(function (pdfDocument) {
  946. return pdfDocument.destroy();
  947. });
  948. var destroyPromises2 = loadingTasks.map(function (loadingTask) {
  949. return loadingTask.destroy();
  950. });
  951. Promise.all(destroyPromises.concat(destroyPromises2)).then(function () {
  952. done();
  953. });
  954. });
  955. it('should correctly render PDFs in parallel', function (done) {
  956. var baseline1, baseline2, baseline3;
  957. var promiseDone = renderPDF(pdf1).then(function (data1) {
  958. baseline1 = data1;
  959. return renderPDF(pdf2);
  960. }).then(function (data2) {
  961. baseline2 = data2;
  962. return renderPDF(pdf3);
  963. }).then(function (data3) {
  964. baseline3 = data3;
  965. return Promise.all([renderPDF(pdf1), renderPDF(pdf2), renderPDF(pdf3)]);
  966. }).then(function (dataUrls) {
  967. expect(dataUrls[0]).toEqual(baseline1);
  968. expect(dataUrls[1]).toEqual(baseline2);
  969. expect(dataUrls[2]).toEqual(baseline3);
  970. return true;
  971. });
  972. promiseDone.then(function () {
  973. done();
  974. }).catch(function (reason) {
  975. done.fail(reason);
  976. });
  977. });
  978. });
  979. describe('PDFDataRangeTransport', function () {
  980. if ((0, _util.isNodeJS)()) {
  981. pending('XMLHttpRequest is not supported in Node.js.');
  982. }
  983. var pdfPath = new URL('../pdfs/tracemonkey.pdf', window.location).href;
  984. var loadPromise;
  985. function getDocumentData() {
  986. if (loadPromise) {
  987. return loadPromise;
  988. }
  989. loadPromise = new Promise(function (resolve, reject) {
  990. var xhr = new XMLHttpRequest(pdfPath);
  991. xhr.open('GET', pdfPath);
  992. xhr.responseType = 'arraybuffer';
  993. xhr.onload = function () {
  994. resolve(new Uint8Array(xhr.response));
  995. };
  996. xhr.onerror = function () {
  997. reject(new Error('PDF is not loaded'));
  998. };
  999. xhr.send();
  1000. });
  1001. return loadPromise;
  1002. }
  1003. it('should fetch document info and page using ranges', function (done) {
  1004. var transport;
  1005. var initialDataLength = 4000;
  1006. var fetches = 0;
  1007. var getDocumentPromise = getDocumentData().then(function (data) {
  1008. var initialData = data.subarray(0, initialDataLength);
  1009. transport = new _global.PDFJS.PDFDataRangeTransport(data.length, initialData);
  1010. transport.requestDataRange = function (begin, end) {
  1011. fetches++;
  1012. waitSome(function () {
  1013. transport.onDataProgress(4000);
  1014. transport.onDataRange(begin, data.subarray(begin, end));
  1015. });
  1016. };
  1017. var loadingTask = (0, _api.getDocument)(transport);
  1018. return loadingTask.promise;
  1019. });
  1020. var pdfDocument;
  1021. var getPagePromise = getDocumentPromise.then(function (pdfDocument_) {
  1022. pdfDocument = pdfDocument_;
  1023. var pagePromise = pdfDocument.getPage(10);
  1024. return pagePromise;
  1025. });
  1026. getPagePromise.then(function (page) {
  1027. expect(pdfDocument.numPages).toEqual(14);
  1028. expect(page.rotate).toEqual(0);
  1029. expect(fetches).toBeGreaterThan(2);
  1030. done();
  1031. }).catch(function (reason) {
  1032. done.fail(reason);
  1033. });
  1034. });
  1035. it('should fetch document info and page using range and streaming', function (done) {
  1036. var transport;
  1037. var initialDataLength = 4000;
  1038. var fetches = 0;
  1039. var getDocumentPromise = getDocumentData().then(function (data) {
  1040. var initialData = data.subarray(0, initialDataLength);
  1041. transport = new _global.PDFJS.PDFDataRangeTransport(data.length, initialData);
  1042. transport.requestDataRange = function (begin, end) {
  1043. fetches++;
  1044. if (fetches === 1) {
  1045. transport.onDataProgressiveRead(data.subarray(initialDataLength));
  1046. }
  1047. waitSome(function () {
  1048. transport.onDataRange(begin, data.subarray(begin, end));
  1049. });
  1050. };
  1051. var loadingTask = (0, _api.getDocument)(transport);
  1052. return loadingTask.promise;
  1053. });
  1054. var pdfDocument;
  1055. var getPagePromise = getDocumentPromise.then(function (pdfDocument_) {
  1056. pdfDocument = pdfDocument_;
  1057. var pagePromise = pdfDocument.getPage(10);
  1058. return pagePromise;
  1059. });
  1060. getPagePromise.then(function (page) {
  1061. expect(pdfDocument.numPages).toEqual(14);
  1062. expect(page.rotate).toEqual(0);
  1063. expect(fetches).toEqual(1);
  1064. done();
  1065. }).catch(function (reason) {
  1066. done.fail(reason);
  1067. });
  1068. });
  1069. });
  1070. });