pdfjs-dist 2.1.266 → 2.2.228

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pdfjs-dist might be problematic. Click here for more details.

Files changed (166) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +3349 -2324
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +2804 -1975
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/image_decoders/pdf.image_decoders.js +431 -511
  10. package/image_decoders/pdf.image_decoders.js.map +1 -1
  11. package/image_decoders/pdf.image_decoders.min.js +1 -1
  12. package/lib/core/annotation.js +294 -224
  13. package/lib/core/arithmetic_decoder.js +1 -1
  14. package/lib/core/bidi.js +1 -1
  15. package/lib/core/ccitt.js +1 -1
  16. package/lib/core/ccitt_stream.js +1 -1
  17. package/lib/core/cff_parser.js +61 -12
  18. package/lib/core/charsets.js +1 -1
  19. package/lib/core/chunked_stream.js +24 -14
  20. package/lib/core/cmap.js +17 -13
  21. package/lib/core/colorspace.js +1 -1
  22. package/lib/core/core_utils.js +147 -0
  23. package/lib/core/crypto.js +1 -1
  24. package/lib/core/document.js +47 -40
  25. package/lib/core/encodings.js +1 -1
  26. package/lib/core/evaluator.js +346 -279
  27. package/lib/core/font_renderer.js +1 -1
  28. package/lib/core/fonts.js +23 -11
  29. package/lib/core/function.js +1 -1
  30. package/lib/core/glyphlist.js +2 -2
  31. package/lib/core/image.js +2 -2
  32. package/lib/core/image_utils.js +111 -0
  33. package/lib/core/jbig2.js +1 -1
  34. package/lib/core/jbig2_stream.js +1 -1
  35. package/lib/core/jpeg_stream.js +1 -1
  36. package/lib/core/jpg.js +2 -1
  37. package/lib/core/jpx.js +1 -1
  38. package/lib/core/jpx_stream.js +1 -1
  39. package/lib/core/metrics.js +13 -13
  40. package/lib/core/murmurhash3.js +37 -33
  41. package/lib/core/obj.js +245 -41
  42. package/lib/core/operator_list.js +43 -32
  43. package/lib/core/parser.js +228 -133
  44. package/lib/core/pattern.js +4 -2
  45. package/lib/core/pdf_manager.js +17 -15
  46. package/lib/core/primitives.js +40 -6
  47. package/lib/core/ps_parser.js +1 -1
  48. package/lib/core/standard_fonts.js +9 -9
  49. package/lib/core/stream.js +1 -1
  50. package/lib/core/type1_parser.js +1 -1
  51. package/lib/core/unicode.js +2 -2
  52. package/lib/core/worker.js +54 -171
  53. package/lib/core/worker_stream.js +277 -0
  54. package/lib/display/annotation_layer.js +112 -33
  55. package/lib/display/api.js +211 -123
  56. package/lib/display/api_compatibility.js +1 -1
  57. package/lib/display/canvas.js +40 -19
  58. package/lib/display/content_disposition.js +1 -1
  59. package/lib/display/display_utils.js +747 -0
  60. package/lib/display/fetch_stream.js +19 -12
  61. package/lib/display/font_loader.js +11 -8
  62. package/lib/display/metadata.js +1 -1
  63. package/lib/display/network.js +563 -521
  64. package/lib/display/network_utils.js +1 -1
  65. package/lib/display/node_stream.js +21 -12
  66. package/lib/display/pattern_helper.js +24 -25
  67. package/lib/display/svg.js +1068 -565
  68. package/lib/display/text_layer.js +24 -14
  69. package/lib/display/transport_stream.js +192 -70
  70. package/lib/display/webgl.js +1 -1
  71. package/lib/display/worker_options.js +1 -1
  72. package/lib/display/xml_parser.js +1 -1
  73. package/lib/examples/node/domstubs.js +4 -1
  74. package/lib/pdf.js +20 -15
  75. package/lib/pdf.worker.js +3 -3
  76. package/lib/shared/compatibility.js +6 -6
  77. package/lib/shared/global_scope.js +1 -1
  78. package/lib/shared/is_node.js +2 -2
  79. package/lib/shared/message_handler.js +7 -7
  80. package/lib/shared/streams_polyfill.js +1 -1
  81. package/lib/shared/url_polyfill.js +1 -1
  82. package/lib/shared/util.js +13 -125
  83. package/lib/test/unit/annotation_spec.js +278 -93
  84. package/lib/test/unit/api_spec.js +198 -188
  85. package/lib/test/unit/bidi_spec.js +1 -1
  86. package/lib/test/unit/cff_parser_spec.js +15 -1
  87. package/lib/test/unit/clitests_helper.js +3 -3
  88. package/lib/test/unit/cmap_spec.js +20 -20
  89. package/lib/test/unit/colorspace_spec.js +17 -12
  90. package/lib/test/unit/core_utils_spec.js +191 -0
  91. package/lib/test/unit/crypto_spec.js +1 -1
  92. package/lib/test/unit/custom_spec.js +8 -8
  93. package/lib/test/unit/display_svg_spec.js +8 -8
  94. package/lib/test/unit/display_utils_spec.js +273 -0
  95. package/lib/test/unit/document_spec.js +7 -12
  96. package/lib/test/unit/encodings_spec.js +5 -5
  97. package/lib/test/unit/evaluator_spec.js +8 -10
  98. package/lib/test/unit/fetch_stream_spec.js +109 -0
  99. package/lib/test/unit/function_spec.js +1 -1
  100. package/lib/test/unit/jasmine-boot.js +4 -4
  101. package/lib/test/unit/message_handler_spec.js +1 -1
  102. package/lib/test/unit/metadata_spec.js +1 -1
  103. package/lib/test/unit/murmurhash3_spec.js +1 -1
  104. package/lib/test/unit/network_spec.js +5 -55
  105. package/lib/test/unit/network_utils_spec.js +51 -1
  106. package/lib/test/unit/node_stream_spec.js +8 -8
  107. package/lib/test/unit/parser_spec.js +150 -86
  108. package/lib/test/unit/pdf_find_controller_spec.js +1 -1
  109. package/lib/test/unit/pdf_find_utils_spec.js +1 -1
  110. package/lib/test/unit/pdf_history_spec.js +1 -1
  111. package/lib/test/unit/primitives_spec.js +30 -17
  112. package/lib/test/unit/stream_spec.js +1 -1
  113. package/lib/test/unit/test_utils.js +197 -43
  114. package/lib/test/unit/testreporter.js +1 -1
  115. package/lib/test/unit/type1_parser_spec.js +1 -1
  116. package/lib/test/unit/ui_utils_spec.js +20 -20
  117. package/lib/test/unit/unicode_spec.js +5 -5
  118. package/lib/test/unit/util_spec.js +1 -164
  119. package/lib/web/annotation_layer_builder.js +1 -1
  120. package/lib/web/app.js +104 -60
  121. package/lib/web/app_options.js +45 -37
  122. package/lib/web/base_viewer.js +7 -7
  123. package/lib/web/chromecom.js +8 -8
  124. package/lib/web/debugger.js +7 -7
  125. package/lib/web/download_manager.js +3 -2
  126. package/lib/web/firefox_print_service.js +4 -2
  127. package/lib/web/firefoxcom.js +50 -19
  128. package/lib/web/genericcom.js +8 -8
  129. package/lib/web/genericl10n.js +10 -10
  130. package/lib/web/grab_to_pan.js +3 -1
  131. package/lib/web/interfaces.js +13 -13
  132. package/lib/web/overlay_manager.js +10 -10
  133. package/lib/web/password_prompt.js +2 -2
  134. package/lib/web/pdf_attachment_viewer.js +1 -1
  135. package/lib/web/pdf_cursor_tools.js +1 -1
  136. package/lib/web/pdf_document_properties.js +188 -119
  137. package/lib/web/pdf_find_bar.js +1 -1
  138. package/lib/web/pdf_find_controller.js +3 -3
  139. package/lib/web/pdf_find_utils.js +1 -1
  140. package/lib/web/pdf_history.js +1 -1
  141. package/lib/web/pdf_link_service.js +2 -2
  142. package/lib/web/pdf_outline_viewer.js +53 -28
  143. package/lib/web/pdf_page_view.js +9 -18
  144. package/lib/web/pdf_presentation_mode.js +1 -1
  145. package/lib/web/pdf_print_service.js +5 -3
  146. package/lib/web/pdf_rendering_queue.js +4 -7
  147. package/lib/web/pdf_sidebar.js +24 -17
  148. package/lib/web/pdf_sidebar_resizer.js +1 -1
  149. package/lib/web/pdf_single_page_viewer.js +1 -1
  150. package/lib/web/pdf_thumbnail_view.js +2 -2
  151. package/lib/web/pdf_thumbnail_viewer.js +3 -3
  152. package/lib/web/pdf_viewer.component.js +3 -3
  153. package/lib/web/pdf_viewer.js +3 -3
  154. package/lib/web/preferences.js +30 -30
  155. package/lib/web/secondary_toolbar.js +1 -1
  156. package/lib/web/text_layer_builder.js +23 -45
  157. package/lib/web/toolbar.js +1 -1
  158. package/lib/web/ui_utils.js +14 -14
  159. package/lib/web/view_history.js +15 -15
  160. package/lib/web/viewer_compatibility.js +1 -1
  161. package/package.json +1 -1
  162. package/web/pdf_viewer.css +21 -10
  163. package/web/pdf_viewer.js +126 -194
  164. package/web/pdf_viewer.js.map +1 -1
  165. package/lib/display/dom_utils.js +0 -494
  166. package/lib/test/unit/dom_utils_spec.js +0 -89
@@ -2,7 +2,7 @@
2
2
  * @licstart The following is the entire license notice for the
3
3
  * Javascript code in this page
4
4
  *
5
- * Copyright 2018 Mozilla Foundation
5
+ * Copyright 2019 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@ var _test_utils = require("./test_utils");
27
27
 
28
28
  var _util = require("../../shared/util");
29
29
 
30
- var _dom_utils = require("../../display/dom_utils");
30
+ var _display_utils = require("../../display/display_utils");
31
31
 
32
32
  var _api = require("../../display/api");
33
33
 
@@ -37,7 +37,7 @@ var _is_node = _interopRequireDefault(require("../../shared/is_node"));
37
37
 
38
38
  var _metadata = require("../../display/metadata");
39
39
 
40
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
40
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
41
41
 
42
42
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
43
43
 
@@ -59,10 +59,10 @@ describe('api', function () {
59
59
  var basicApiGetDocumentParams = (0, _test_utils.buildGetDocumentParams)(basicApiFileName);
60
60
  var CanvasFactory;
61
61
  beforeAll(function (done) {
62
- if ((0, _is_node.default)()) {
62
+ if ((0, _is_node["default"])()) {
63
63
  CanvasFactory = new _test_utils.NodeCanvasFactory();
64
64
  } else {
65
- CanvasFactory = new _dom_utils.DOMCanvasFactory();
65
+ CanvasFactory = new _display_utils.DOMCanvasFactory();
66
66
  }
67
67
 
68
68
  done();
@@ -96,14 +96,14 @@ describe('api', function () {
96
96
  expect(data[1] instanceof _api.PDFDocumentProxy).toEqual(true);
97
97
  expect(loadingTask).toEqual(data[1].loadingTask);
98
98
  loadingTask.destroy().then(done);
99
- }).catch(done.fail);
99
+ })["catch"](done.fail);
100
100
  });
101
101
  it('creates pdf doc from URL and aborts before worker initialized', function (done) {
102
102
  var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
103
103
  var destroyed = loadingTask.destroy();
104
104
  loadingTask.promise.then(function (reason) {
105
105
  done.fail('shall fail loading');
106
- }).catch(function (reason) {
106
+ })["catch"](function (reason) {
107
107
  expect(true).toEqual(true);
108
108
  destroyed.then(done);
109
109
  });
@@ -118,59 +118,42 @@ describe('api', function () {
118
118
  destroyed.then(function (data) {
119
119
  expect(true).toEqual(true);
120
120
  done();
121
- }).catch(done.fail);
121
+ })["catch"](done.fail);
122
122
  });
123
123
  it('creates pdf doc from typed array', function (done) {
124
- var typedArrayPdf;
124
+ var typedArrayPdfPromise;
125
125
 
126
- if ((0, _is_node.default)()) {
127
- typedArrayPdf = _test_utils.NodeFileReaderFactory.fetch({
126
+ if ((0, _is_node["default"])()) {
127
+ typedArrayPdfPromise = _test_utils.NodeFileReaderFactory.fetch({
128
128
  path: _test_utils.TEST_PDFS_PATH.node + basicApiFileName
129
129
  });
130
130
  } else {
131
- var nonBinaryRequest = false;
132
- var request = new XMLHttpRequest();
133
- request.open('GET', _test_utils.TEST_PDFS_PATH.dom + basicApiFileName, false);
134
-
135
- try {
136
- request.responseType = 'arraybuffer';
137
- nonBinaryRequest = request.responseType !== 'arraybuffer';
138
- } catch (e) {
139
- nonBinaryRequest = true;
140
- }
141
-
142
- if (nonBinaryRequest && request.overrideMimeType) {
143
- request.overrideMimeType('text/plain; charset=x-user-defined');
144
- }
145
-
146
- request.send(null);
147
-
148
- if (nonBinaryRequest) {
149
- typedArrayPdf = (0, _util.stringToBytes)(request.responseText);
150
- } else {
151
- typedArrayPdf = new Uint8Array(request.response);
152
- }
131
+ typedArrayPdfPromise = _test_utils.DOMFileReaderFactory.fetch({
132
+ path: _test_utils.TEST_PDFS_PATH.dom + basicApiFileName
133
+ });
153
134
  }
154
135
 
155
- expect(typedArrayPdf.length).toEqual(basicApiFileLength);
156
- var loadingTask = (0, _api.getDocument)(typedArrayPdf);
157
- var progressReportedCapability = (0, _util.createPromiseCapability)();
136
+ typedArrayPdfPromise.then(function (typedArrayPdf) {
137
+ expect(typedArrayPdf.length).toEqual(basicApiFileLength);
138
+ var loadingTask = (0, _api.getDocument)(typedArrayPdf);
139
+ var progressReportedCapability = (0, _util.createPromiseCapability)();
158
140
 
159
- loadingTask.onProgress = function (data) {
160
- progressReportedCapability.resolve(data);
161
- };
141
+ loadingTask.onProgress = function (data) {
142
+ progressReportedCapability.resolve(data);
143
+ };
162
144
 
163
- Promise.all([loadingTask.promise, progressReportedCapability.promise]).then(function (data) {
164
- expect(data[0] instanceof _api.PDFDocumentProxy).toEqual(true);
165
- expect(data[1].loaded / data[1].total).toEqual(1);
166
- loadingTask.destroy().then(done);
167
- }).catch(done.fail);
145
+ return Promise.all([loadingTask.promise, progressReportedCapability.promise]).then(function (data) {
146
+ expect(data[0] instanceof _api.PDFDocumentProxy).toEqual(true);
147
+ expect(data[1].loaded / data[1].total).toEqual(1);
148
+ loadingTask.destroy().then(done);
149
+ });
150
+ })["catch"](done.fail);
168
151
  });
169
152
  it('creates pdf doc from invalid PDF file', function (done) {
170
153
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug1020226.pdf'));
171
154
  loadingTask.promise.then(function () {
172
155
  done.fail('shall fail loading');
173
- }).catch(function (error) {
156
+ })["catch"](function (error) {
174
157
  expect(error instanceof _util.InvalidPDFException).toEqual(true);
175
158
  loadingTask.destroy().then(done);
176
159
  });
@@ -179,7 +162,7 @@ describe('api', function () {
179
162
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('non-existent.pdf'));
180
163
  loadingTask.promise.then(function (error) {
181
164
  done.fail('shall fail loading');
182
- }).catch(function (error) {
165
+ })["catch"](function (error) {
183
166
  expect(error instanceof _util.MissingPDFException).toEqual(true);
184
167
  loadingTask.destroy().then(done);
185
168
  });
@@ -209,7 +192,7 @@ describe('api', function () {
209
192
  Promise.all(promises).then(function (data) {
210
193
  expect(data[2] instanceof _api.PDFDocumentProxy).toEqual(true);
211
194
  loadingTask.destroy().then(done);
212
- }).catch(done.fail);
195
+ })["catch"](done.fail);
213
196
  });
214
197
  it('creates pdf doc from PDF file protected with only a user password', function (done) {
215
198
  var filename = 'pr6531_2.pdf';
@@ -244,7 +227,7 @@ describe('api', function () {
244
227
  });
245
228
  Promise.all([result1, result2, result3]).then(function () {
246
229
  done();
247
- }).catch(done.fail);
230
+ })["catch"](done.fail);
248
231
  });
249
232
  it('creates pdf doc from password protected PDF file and aborts/throws ' + 'in the onPassword callback (issue 7806)', function (done) {
250
233
  var filename = 'issue3371.pdf';
@@ -290,12 +273,12 @@ describe('api', function () {
290
273
  });
291
274
  Promise.all([result1, result2]).then(function () {
292
275
  done();
293
- }).catch(done.fail);
276
+ })["catch"](done.fail);
294
277
  });
295
278
  });
296
279
  describe('PDFWorker', function () {
297
280
  it('worker created or destroyed', function (done) {
298
- if ((0, _is_node.default)()) {
281
+ if ((0, _is_node["default"])()) {
299
282
  pending('Worker is not supported in Node.js.');
300
283
  }
301
284
 
@@ -312,10 +295,10 @@ describe('api', function () {
312
295
  expect(!!worker.port).toEqual(false);
313
296
  expect(worker.destroyed).toEqual(true);
314
297
  done();
315
- }).catch(done.fail);
298
+ })["catch"](done.fail);
316
299
  });
317
300
  it('worker created or destroyed by getDocument', function (done) {
318
- if ((0, _is_node.default)()) {
301
+ if ((0, _is_node["default"])()) {
319
302
  pending('Worker is not supported in Node.js.');
320
303
  }
321
304
 
@@ -333,10 +316,10 @@ describe('api', function () {
333
316
  expect(!!destroyedWorker).toEqual(false);
334
317
  expect(worker.destroyed).toEqual(true);
335
318
  done();
336
- }).catch(done.fail);
319
+ })["catch"](done.fail);
337
320
  });
338
321
  it('worker created and can be used in getDocument', function (done) {
339
- if ((0, _is_node.default)()) {
322
+ if ((0, _is_node["default"])()) {
340
323
  pending('Worker is not supported in Node.js.');
341
324
  }
342
325
 
@@ -359,10 +342,10 @@ describe('api', function () {
359
342
  expect(worker.destroyed).toEqual(false);
360
343
  worker.destroy();
361
344
  done();
362
- }).catch(done.fail);
345
+ })["catch"](done.fail);
363
346
  });
364
347
  it('creates more than one worker', function (done) {
365
- if ((0, _is_node.default)()) {
348
+ if ((0, _is_node["default"])()) {
366
349
  pending('Worker is not supported in Node.js.');
367
350
  }
368
351
 
@@ -382,10 +365,10 @@ describe('api', function () {
382
365
  worker2.destroy();
383
366
  worker3.destroy();
384
367
  done();
385
- }).catch(done.fail);
368
+ })["catch"](done.fail);
386
369
  });
387
370
  it('gets current workerSrc', function () {
388
- if ((0, _is_node.default)()) {
371
+ if ((0, _is_node["default"])()) {
389
372
  pending('Worker is not supported in Node.js.');
390
373
  }
391
374
 
@@ -422,7 +405,7 @@ describe('api', function () {
422
405
  expect(data instanceof _api.PDFPageProxy).toEqual(true);
423
406
  expect(data.pageIndex).toEqual(0);
424
407
  done();
425
- }).catch(done.fail);
408
+ })["catch"](done.fail);
426
409
  });
427
410
  it('gets non-existent page', function (done) {
428
411
  var outOfRangePromise = doc.getPage(100);
@@ -445,7 +428,7 @@ describe('api', function () {
445
428
  });
446
429
  Promise.all([outOfRangePromise, nonIntegerPromise, nonNumberPromise]).then(function () {
447
430
  done();
448
- }).catch(done.fail);
431
+ })["catch"](done.fail);
449
432
  });
450
433
  it('gets page index', function (done) {
451
434
  var ref = {
@@ -456,7 +439,7 @@ describe('api', function () {
456
439
  promise.then(function (pageIndex) {
457
440
  expect(pageIndex).toEqual(1);
458
441
  done();
459
- }).catch(done.fail);
442
+ })["catch"](done.fail);
460
443
  });
461
444
  it('gets invalid page index', function (done) {
462
445
  var ref = {
@@ -466,7 +449,7 @@ describe('api', function () {
466
449
  var promise = doc.getPageIndex(ref);
467
450
  promise.then(function () {
468
451
  done.fail('shall fail for invalid page reference.');
469
- }).catch(function (reason) {
452
+ })["catch"](function (reason) {
470
453
  expect(reason instanceof Error).toEqual(true);
471
454
  done();
472
455
  });
@@ -483,7 +466,7 @@ describe('api', function () {
483
466
  }, 0, 841.89, null]
484
467
  });
485
468
  done();
486
- }).catch(done.fail);
469
+ })["catch"](done.fail);
487
470
  });
488
471
  it('gets a destination, from /Dests dictionary', function (done) {
489
472
  var promise = doc.getDestination('chapter1');
@@ -495,14 +478,14 @@ describe('api', function () {
495
478
  name: 'XYZ'
496
479
  }, 0, 841.89, null]);
497
480
  done();
498
- }).catch(done.fail);
481
+ })["catch"](done.fail);
499
482
  });
500
483
  it('gets a non-existent destination, from /Dests dictionary', function (done) {
501
484
  var promise = doc.getDestination('non-existent-named-destination');
502
485
  promise.then(function (data) {
503
486
  expect(data).toEqual(null);
504
487
  done();
505
- }).catch(done.fail);
488
+ })["catch"](done.fail);
506
489
  });
507
490
  it('gets destinations, from /Names (NameTree) dictionary', function (done) {
508
491
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
@@ -525,7 +508,7 @@ describe('api', function () {
525
508
  }, 0, 375, null]
526
509
  });
527
510
  loadingTask.destroy().then(done);
528
- }).catch(done.fail);
511
+ })["catch"](done.fail);
529
512
  });
530
513
  it('gets a destination, from /Names (NameTree) dictionary', function (done) {
531
514
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
@@ -540,7 +523,7 @@ describe('api', function () {
540
523
  name: 'XYZ'
541
524
  }, 0, 375, null]);
542
525
  loadingTask.destroy().then(done);
543
- }).catch(done.fail);
526
+ })["catch"](done.fail);
544
527
  });
545
528
  it('gets a non-existent destination, from /Names (NameTree) dictionary', function (done) {
546
529
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
@@ -550,7 +533,7 @@ describe('api', function () {
550
533
  promise.then(function (destination) {
551
534
  expect(destination).toEqual(null);
552
535
  loadingTask.destroy().then(done);
553
- }).catch(done.fail);
536
+ })["catch"](done.fail);
554
537
  });
555
538
  it('gets non-string destination', function (done) {
556
539
  var numberPromise = doc.getDestination(4.3);
@@ -583,7 +566,7 @@ describe('api', function () {
583
566
  promise.then(function (data) {
584
567
  expect(data).toEqual(null);
585
568
  done();
586
- }).catch(done.fail);
569
+ })["catch"](done.fail);
587
570
  });
588
571
  it('gets page labels', function (done) {
589
572
  var loadingTask0 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug793632.pdf'));
@@ -608,7 +591,22 @@ describe('api', function () {
608
591
  expect(pageLabels[2]).toEqual(['1', '2']);
609
592
  expect(pageLabels[3]).toEqual(['X3']);
610
593
  Promise.all([loadingTask0.destroy(), loadingTask1.destroy(), loadingTask2.destroy(), loadingTask3.destroy()]).then(done);
611
- }).catch(done.fail);
594
+ })["catch"](done.fail);
595
+ });
596
+ it('gets default page layout', function (done) {
597
+ var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
598
+ loadingTask.promise.then(function (pdfDocument) {
599
+ return pdfDocument.getPageLayout();
600
+ }).then(function (mode) {
601
+ expect(mode).toEqual('');
602
+ loadingTask.destroy().then(done);
603
+ })["catch"](done.fail);
604
+ });
605
+ it('gets non-default page layout', function (done) {
606
+ doc.getPageLayout().then(function (mode) {
607
+ expect(mode).toEqual('SinglePage');
608
+ done();
609
+ })["catch"](done.fail);
612
610
  });
613
611
  it('gets default page mode', function (done) {
614
612
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
@@ -617,13 +615,30 @@ describe('api', function () {
617
615
  }).then(function (mode) {
618
616
  expect(mode).toEqual('UseNone');
619
617
  loadingTask.destroy().then(done);
620
- }).catch(done.fail);
618
+ })["catch"](done.fail);
621
619
  });
622
620
  it('gets non-default page mode', function (done) {
623
621
  doc.getPageMode().then(function (mode) {
624
622
  expect(mode).toEqual('UseOutlines');
625
623
  done();
626
- }).catch(done.fail);
624
+ })["catch"](done.fail);
625
+ });
626
+ it('gets default viewer preferences', function (done) {
627
+ var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
628
+ loadingTask.promise.then(function (pdfDocument) {
629
+ return pdfDocument.getViewerPreferences();
630
+ }).then(function (prefs) {
631
+ expect(_typeof(prefs) === 'object' && prefs !== null && (0, _util.isEmptyObj)(prefs)).toEqual(true);
632
+ loadingTask.destroy().then(done);
633
+ })["catch"](done.fail);
634
+ });
635
+ it('gets non-default viewer preferences', function (done) {
636
+ doc.getViewerPreferences().then(function (prefs) {
637
+ expect(prefs).toEqual({
638
+ Direction: 'L2R'
639
+ });
640
+ done();
641
+ })["catch"](done.fail);
627
642
  });
628
643
  it('gets default open action destination', function (done) {
629
644
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
@@ -632,7 +647,7 @@ describe('api', function () {
632
647
  }).then(function (dest) {
633
648
  expect(dest).toEqual(null);
634
649
  loadingTask.destroy().then(done);
635
- }).catch(done.fail);
650
+ })["catch"](done.fail);
636
651
  });
637
652
  it('gets non-default open action destination', function (done) {
638
653
  doc.getOpenActionDestination().then(function (dest) {
@@ -643,17 +658,17 @@ describe('api', function () {
643
658
  name: 'FitH'
644
659
  }, null]);
645
660
  done();
646
- }).catch(done.fail);
661
+ })["catch"](done.fail);
647
662
  });
648
663
  it('gets non-existent attachments', function (done) {
649
664
  var promise = doc.getAttachments();
650
665
  promise.then(function (data) {
651
666
  expect(data).toEqual(null);
652
667
  done();
653
- }).catch(done.fail);
668
+ })["catch"](done.fail);
654
669
  });
655
670
  it('gets attachments', function (done) {
656
- if ((0, _is_node.default)()) {
671
+ if ((0, _is_node["default"])()) {
657
672
  pending('TODO: Use a non-linked test-case.');
658
673
  }
659
674
 
@@ -667,14 +682,14 @@ describe('api', function () {
667
682
  expect(attachment.content instanceof Uint8Array).toBeTruthy();
668
683
  expect(attachment.content.length).toEqual(30098);
669
684
  loadingTask.destroy().then(done);
670
- }).catch(done.fail);
685
+ })["catch"](done.fail);
671
686
  });
672
687
  it('gets javascript', function (done) {
673
688
  var promise = doc.getJavaScript();
674
689
  promise.then(function (data) {
675
690
  expect(data).toEqual(null);
676
691
  done();
677
- }).catch(done.fail);
692
+ })["catch"](done.fail);
678
693
  });
679
694
  var viewerPrintRegExp = /\bprint\s*\(/;
680
695
  it('gets javascript with printing instructions (Print action)', function (done) {
@@ -686,7 +701,7 @@ describe('api', function () {
686
701
  expect(data).toEqual(['print({});']);
687
702
  expect(data[0]).toMatch(viewerPrintRegExp);
688
703
  loadingTask.destroy().then(done);
689
- }).catch(done.fail);
704
+ })["catch"](done.fail);
690
705
  });
691
706
  it('gets javascript with printing instructions (JS action)', function (done) {
692
707
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6106.pdf'));
@@ -697,7 +712,7 @@ describe('api', function () {
697
712
  expect(data).toEqual(['this.print({bUI:true,bSilent:false,bShrinkToFit:true});']);
698
713
  expect(data[0]).toMatch(viewerPrintRegExp);
699
714
  loadingTask.destroy().then(done);
700
- }).catch(done.fail);
715
+ })["catch"](done.fail);
701
716
  });
702
717
  it('gets non-existent outline', function (done) {
703
718
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
@@ -707,7 +722,7 @@ describe('api', function () {
707
722
  promise.then(function (outline) {
708
723
  expect(outline).toEqual(null);
709
724
  loadingTask.destroy().then(done);
710
- }).catch(done.fail);
725
+ })["catch"](done.fail);
711
726
  });
712
727
  it('gets outline', function (done) {
713
728
  var promise = doc.getOutline();
@@ -726,7 +741,7 @@ describe('api', function () {
726
741
  expect(outlineItem.items.length).toEqual(1);
727
742
  expect(outlineItem.items[0].title).toEqual('Paragraph 1.1');
728
743
  done();
729
- }).catch(done.fail);
744
+ })["catch"](done.fail);
730
745
  });
731
746
  it('gets outline containing a url', function (done) {
732
747
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue3214.pdf'));
@@ -746,13 +761,13 @@ describe('api', function () {
746
761
  expect(outlineItemOne.color).toEqual(new Uint8ClampedArray([0, 0, 0]));
747
762
  loadingTask.destroy().then(done);
748
763
  });
749
- }).catch(done.fail);
764
+ })["catch"](done.fail);
750
765
  });
751
766
  it('gets non-existent permissions', function (done) {
752
767
  doc.getPermissions().then(function (permissions) {
753
768
  expect(permissions).toEqual(null);
754
769
  done();
755
- }).catch(done.fail);
770
+ })["catch"](done.fail);
756
771
  });
757
772
  it('gets permissions', function (done) {
758
773
  var loadingTask0 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue9972-1.pdf'));
@@ -777,7 +792,7 @@ describe('api', function () {
777
792
  expect(permissions[2].length).toEqual(totalPermissionCount - 1);
778
793
  expect(permissions[2].includes(_util.PermissionFlag.COPY)).toBeFalsy();
779
794
  Promise.all([loadingTask0.destroy(), loadingTask1.destroy(), loadingTask2.destroy()]).then(done);
780
- }).catch(done.fail);
795
+ })["catch"](done.fail);
781
796
  });
782
797
  it('gets metadata', function (done) {
783
798
  var promise = doc.getMetadata();
@@ -791,11 +806,12 @@ describe('api', function () {
791
806
  expect(info['IsLinearized']).toEqual(false);
792
807
  expect(info['IsAcroFormPresent']).toEqual(false);
793
808
  expect(info['IsXFAPresent']).toEqual(false);
809
+ expect(info['IsCollectionPresent']).toEqual(false);
794
810
  expect(metadata instanceof _metadata.Metadata).toEqual(true);
795
811
  expect(metadata.get('dc:title')).toEqual('Basic API Test');
796
812
  expect(contentDispositionFilename).toEqual(null);
797
813
  done();
798
- }).catch(done.fail);
814
+ })["catch"](done.fail);
799
815
  });
800
816
  it('gets metadata, with custom info dict entries', function (done) {
801
817
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
@@ -815,10 +831,11 @@ describe('api', function () {
815
831
  expect(info['IsLinearized']).toEqual(false);
816
832
  expect(info['IsAcroFormPresent']).toEqual(false);
817
833
  expect(info['IsXFAPresent']).toEqual(false);
834
+ expect(info['IsCollectionPresent']).toEqual(false);
818
835
  expect(metadata).toEqual(null);
819
836
  expect(contentDispositionFilename).toEqual(null);
820
837
  loadingTask.destroy().then(done);
821
- }).catch(done.fail);
838
+ })["catch"](done.fail);
822
839
  });
823
840
  it('gets data', function (done) {
824
841
  var promise = doc.getData();
@@ -826,7 +843,7 @@ describe('api', function () {
826
843
  expect(data instanceof Uint8Array).toEqual(true);
827
844
  expect(data.length).toEqual(basicApiFileLength);
828
845
  done();
829
- }).catch(done.fail);
846
+ })["catch"](done.fail);
830
847
  });
831
848
  it('gets download info', function (done) {
832
849
  var promise = doc.getDownloadInfo();
@@ -835,7 +852,7 @@ describe('api', function () {
835
852
  length: basicApiFileLength
836
853
  });
837
854
  done();
838
- }).catch(done.fail);
855
+ })["catch"](done.fail);
839
856
  });
840
857
  it('gets document stats', function (done) {
841
858
  var promise = doc.getStats();
@@ -845,7 +862,7 @@ describe('api', function () {
845
862
  fontTypes: []
846
863
  });
847
864
  done();
848
- }).catch(done.fail);
865
+ })["catch"](done.fail);
849
866
  });
850
867
  it('checks that fingerprints are unique', function (done) {
851
868
  var loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue4436r.pdf'));
@@ -860,13 +877,13 @@ describe('api', function () {
860
877
  expect(fingerprint2.length > 0).toEqual(true);
861
878
  expect(fingerprint1).not.toEqual(fingerprint2);
862
879
  Promise.all([loadingTask1.destroy(), loadingTask2.destroy()]).then(done);
863
- }).catch(done.fail);
880
+ })["catch"](done.fail);
864
881
  });
865
882
  describe('Cross-origin', function () {
866
883
  var loadingTask;
867
884
 
868
885
  function _checkCanLoad(expectSuccess, filename, options) {
869
- if ((0, _is_node.default)()) {
886
+ if ((0, _is_node["default"])()) {
870
887
  pending('Cannot simulate cross-origin requests in Node.js');
871
888
  }
872
889
 
@@ -905,7 +922,7 @@ describe('api', function () {
905
922
  }
906
923
 
907
924
  afterEach(function (done) {
908
- if (loadingTask) {
925
+ if (loadingTask && !loadingTask.destroyed) {
909
926
  loadingTask.destroy().then(done);
910
927
  } else {
911
928
  done();
@@ -950,7 +967,7 @@ describe('api', function () {
950
967
  page = data;
951
968
  done();
952
969
  });
953
- }).catch(done.fail);
970
+ })["catch"](done.fail);
954
971
  });
955
972
  afterAll(function (done) {
956
973
  loadingTask.destroy().then(done);
@@ -1020,7 +1037,7 @@ describe('api', function () {
1020
1037
  });
1021
1038
  Promise.all([defaultPromise, displayPromise, printPromise]).then(function () {
1022
1039
  done();
1023
- }).catch(done.fail);
1040
+ })["catch"](done.fail);
1024
1041
  });
1025
1042
  it('gets annotations containing relative URLs (bug 766086)', function (done) {
1026
1043
  var filename = 'bug766086.pdf';
@@ -1057,7 +1074,7 @@ describe('api', function () {
1057
1074
  expect(invalidDocBaseUrlAnnotations[0].url).toBeUndefined();
1058
1075
  expect(invalidDocBaseUrlAnnotations[0].unsafeUrl).toEqual('../../0021/002156/215675E.pdf#15');
1059
1076
  Promise.all([defaultLoadingTask.destroy(), docBaseUrlLoadingTask.destroy(), invalidDocBaseUrlLoadingTask.destroy()]).then(done);
1060
- }).catch(done.fail);
1077
+ })["catch"](done.fail);
1061
1078
  });
1062
1079
  it('gets text content', function (done) {
1063
1080
  var defaultPromise = page.getTextContent();
@@ -1072,7 +1089,7 @@ describe('api', function () {
1072
1089
  expect(!!data[0].styles).toEqual(true);
1073
1090
  expect(JSON.stringify(data[0])).toEqual(JSON.stringify(data[1]));
1074
1091
  done();
1075
- }).catch(done.fail);
1092
+ })["catch"](done.fail);
1076
1093
  });
1077
1094
  it('gets text content, with correct properties (issue 8276)', function (done) {
1078
1095
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue8276_reduced.pdf'));
@@ -1100,7 +1117,7 @@ describe('api', function () {
1100
1117
  loadingTask.destroy().then(done);
1101
1118
  });
1102
1119
  });
1103
- }).catch(done.fail);
1120
+ })["catch"](done.fail);
1104
1121
  });
1105
1122
  it('gets operator list', function (done) {
1106
1123
  var promise = page.getOperatorList();
@@ -1109,7 +1126,7 @@ describe('api', function () {
1109
1126
  expect(!!oplist.argsArray).toEqual(true);
1110
1127
  expect(oplist.lastChunk).toEqual(true);
1111
1128
  done();
1112
- }).catch(done.fail);
1129
+ })["catch"](done.fail);
1113
1130
  });
1114
1131
  it('gets operatorList with JPEG image (issue 4888)', function (done) {
1115
1132
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('cmykjpeg.pdf'));
@@ -1127,7 +1144,7 @@ describe('api', function () {
1127
1144
  loadingTask.destroy().then(done);
1128
1145
  });
1129
1146
  });
1130
- }).catch(done.fail);
1147
+ })["catch"](done.fail);
1131
1148
  });
1132
1149
  it('gets document stats after parsing page', function (done) {
1133
1150
  var promise = page.getOperatorList().then(function () {
@@ -1144,7 +1161,7 @@ describe('api', function () {
1144
1161
  fontTypes: expectedFontTypes
1145
1162
  });
1146
1163
  done();
1147
- }).catch(done.fail);
1164
+ })["catch"](done.fail);
1148
1165
  });
1149
1166
  it('gets page stats after parsing page, without `pdfBug` set', function (done) {
1150
1167
  page.getOperatorList().then(function (opList) {
@@ -1165,7 +1182,7 @@ describe('api', function () {
1165
1182
  });
1166
1183
  });
1167
1184
  }).then(function (stats) {
1168
- expect(stats instanceof _dom_utils.StatTimer).toEqual(true);
1185
+ expect(stats instanceof _display_utils.StatTimer).toEqual(true);
1169
1186
  expect(stats.times.length).toEqual(1);
1170
1187
 
1171
1188
  var _stats$times = _slicedToArray(stats.times, 1),
@@ -1197,7 +1214,7 @@ describe('api', function () {
1197
1214
  });
1198
1215
  });
1199
1216
  }).then(function (stats) {
1200
- expect(stats instanceof _dom_utils.StatTimer).toEqual(true);
1217
+ expect(stats instanceof _display_utils.StatTimer).toEqual(true);
1201
1218
  expect(stats.times.length).toEqual(3);
1202
1219
 
1203
1220
  var _stats$times2 = _slicedToArray(stats.times, 3),
@@ -1228,8 +1245,8 @@ describe('api', function () {
1228
1245
  renderTask.cancel();
1229
1246
  renderTask.promise.then(function () {
1230
1247
  done.fail('shall cancel rendering');
1231
- }).catch(function (error) {
1232
- expect(error instanceof _dom_utils.RenderingCancelledException).toEqual(true);
1248
+ })["catch"](function (error) {
1249
+ expect(error instanceof _display_utils.RenderingCancelledException).toEqual(true);
1233
1250
  expect(error.type).toEqual('canvas');
1234
1251
  CanvasFactory.destroy(canvasAndCtx);
1235
1252
  done();
@@ -1249,7 +1266,7 @@ describe('api', function () {
1249
1266
  renderTask.promise.then(function () {
1250
1267
  throw new Error('shall cancel rendering');
1251
1268
  }, function (reason) {
1252
- expect(reason instanceof _dom_utils.RenderingCancelledException).toEqual(true);
1269
+ expect(reason instanceof _display_utils.RenderingCancelledException).toEqual(true);
1253
1270
  }).then(function () {
1254
1271
  var reRenderTask = page.render({
1255
1272
  canvasContext: canvasAndCtx.context,
@@ -1289,7 +1306,6 @@ describe('api', function () {
1289
1306
  var pdf2 = (0, _test_utils.buildGetDocumentParams)('TAMReview.pdf');
1290
1307
  var pdf3 = (0, _test_utils.buildGetDocumentParams)('issue6068.pdf');
1291
1308
  var loadingTasks = [];
1292
- var pdfDocuments = [];
1293
1309
 
1294
1310
  function renderPDF(_x) {
1295
1311
  return _renderPDF.apply(this, arguments);
@@ -1298,9 +1314,9 @@ describe('api', function () {
1298
1314
  function _renderPDF() {
1299
1315
  _renderPDF = _asyncToGenerator(
1300
1316
  /*#__PURE__*/
1301
- _regenerator.default.mark(function _callee(filename) {
1317
+ _regenerator["default"].mark(function _callee(filename) {
1302
1318
  var loadingTask, pdf, page, viewport, canvasAndCtx, renderTask, data;
1303
- return _regenerator.default.wrap(function _callee$(_context) {
1319
+ return _regenerator["default"].wrap(function _callee$(_context) {
1304
1320
  while (1) {
1305
1321
  switch (_context.prev = _context.next) {
1306
1322
  case 0:
@@ -1311,11 +1327,10 @@ describe('api', function () {
1311
1327
 
1312
1328
  case 4:
1313
1329
  pdf = _context.sent;
1314
- pdfDocuments.push(pdf);
1315
- _context.next = 8;
1330
+ _context.next = 7;
1316
1331
  return pdf.getPage(1);
1317
1332
 
1318
- case 8:
1333
+ case 7:
1319
1334
  page = _context.sent;
1320
1335
  viewport = page.getViewport({
1321
1336
  scale: 1.2
@@ -1326,34 +1341,29 @@ describe('api', function () {
1326
1341
  canvasFactory: CanvasFactory,
1327
1342
  viewport: viewport
1328
1343
  });
1329
- _context.next = 14;
1344
+ _context.next = 13;
1330
1345
  return renderTask.promise;
1331
1346
 
1332
- case 14:
1347
+ case 13:
1333
1348
  data = canvasAndCtx.canvas.toDataURL();
1334
1349
  CanvasFactory.destroy(canvasAndCtx);
1335
1350
  return _context.abrupt("return", data);
1336
1351
 
1337
- case 17:
1352
+ case 16:
1338
1353
  case "end":
1339
1354
  return _context.stop();
1340
1355
  }
1341
1356
  }
1342
- }, _callee, this);
1357
+ }, _callee);
1343
1358
  }));
1344
1359
  return _renderPDF.apply(this, arguments);
1345
1360
  }
1346
1361
 
1347
1362
  afterEach(function (done) {
1348
- var destroyPromises = pdfDocuments.map(function (pdfDocument) {
1349
- return pdfDocument.destroy();
1350
- });
1351
- var destroyPromises2 = loadingTasks.map(function (loadingTask) {
1363
+ var destroyPromises = loadingTasks.map(function (loadingTask) {
1352
1364
  return loadingTask.destroy();
1353
1365
  });
1354
- Promise.all(destroyPromises.concat(destroyPromises2)).then(function () {
1355
- done();
1356
- });
1366
+ Promise.all(destroyPromises).then(done);
1357
1367
  });
1358
1368
  it('should correctly render PDFs in parallel', function (done) {
1359
1369
  var baseline1, baseline2, baseline3;
@@ -1374,48 +1384,36 @@ describe('api', function () {
1374
1384
  });
1375
1385
  promiseDone.then(function () {
1376
1386
  done();
1377
- }).catch(done.fail);
1387
+ })["catch"](done.fail);
1378
1388
  });
1379
1389
  });
1380
1390
  describe('PDFDataRangeTransport', function () {
1381
- var loadPromise;
1382
-
1383
- function getDocumentData() {
1384
- var pdfPath = new URL('../pdfs/tracemonkey.pdf', window.location).href;
1391
+ var dataPromise;
1392
+ beforeAll(function (done) {
1393
+ var fileName = 'tracemonkey.pdf';
1385
1394
 
1386
- if (loadPromise) {
1387
- return loadPromise;
1395
+ if ((0, _is_node["default"])()) {
1396
+ dataPromise = _test_utils.NodeFileReaderFactory.fetch({
1397
+ path: _test_utils.TEST_PDFS_PATH.node + fileName
1398
+ });
1399
+ } else {
1400
+ dataPromise = _test_utils.DOMFileReaderFactory.fetch({
1401
+ path: _test_utils.TEST_PDFS_PATH.dom + fileName
1402
+ });
1388
1403
  }
1389
1404
 
1390
- loadPromise = new Promise(function (resolve, reject) {
1391
- var xhr = new XMLHttpRequest(pdfPath);
1392
- xhr.open('GET', pdfPath);
1393
- xhr.responseType = 'arraybuffer';
1394
-
1395
- xhr.onload = function () {
1396
- resolve(new Uint8Array(xhr.response));
1397
- };
1398
-
1399
- xhr.onerror = function () {
1400
- reject(new Error('PDF is not loaded'));
1401
- };
1402
-
1403
- xhr.send();
1404
- });
1405
- return loadPromise;
1406
- }
1407
-
1405
+ done();
1406
+ });
1407
+ afterAll(function () {
1408
+ dataPromise = null;
1409
+ });
1408
1410
  it('should fetch document info and page using ranges', function (done) {
1409
- if ((0, _is_node.default)()) {
1410
- pending('XMLHttpRequest is not supported in Node.js.');
1411
- }
1412
-
1413
- var transport;
1414
1411
  var initialDataLength = 4000;
1415
- var fetches = 0;
1416
- var getDocumentPromise = getDocumentData().then(function (data) {
1412
+ var fetches = 0,
1413
+ loadingTask;
1414
+ dataPromise.then(function (data) {
1417
1415
  var initialData = data.subarray(0, initialDataLength);
1418
- transport = new _api.PDFDataRangeTransport(data.length, initialData);
1416
+ var transport = new _api.PDFDataRangeTransport(data.length, initialData);
1419
1417
 
1420
1418
  transport.requestDataRange = function (begin, end) {
1421
1419
  fetches++;
@@ -1425,33 +1423,24 @@ describe('api', function () {
1425
1423
  });
1426
1424
  };
1427
1425
 
1428
- var loadingTask = (0, _api.getDocument)(transport);
1426
+ loadingTask = (0, _api.getDocument)(transport);
1429
1427
  return loadingTask.promise;
1430
- });
1431
- var pdfDocument;
1432
- var getPagePromise = getDocumentPromise.then(function (pdfDocument_) {
1433
- pdfDocument = pdfDocument_;
1434
- var pagePromise = pdfDocument.getPage(10);
1435
- return pagePromise;
1436
- });
1437
- getPagePromise.then(function (page) {
1428
+ }).then(function (pdfDocument) {
1438
1429
  expect(pdfDocument.numPages).toEqual(14);
1439
- expect(page.rotate).toEqual(0);
1430
+ return pdfDocument.getPage(10);
1431
+ }).then(function (pdfPage) {
1432
+ expect(pdfPage.rotate).toEqual(0);
1440
1433
  expect(fetches).toBeGreaterThan(2);
1441
- done();
1442
- }).catch(done.fail);
1434
+ loadingTask.destroy().then(done);
1435
+ })["catch"](done.fail);
1443
1436
  });
1444
1437
  it('should fetch document info and page using range and streaming', function (done) {
1445
- if ((0, _is_node.default)()) {
1446
- pending('XMLHttpRequest is not supported in Node.js.');
1447
- }
1448
-
1449
- var transport;
1450
1438
  var initialDataLength = 4000;
1451
- var fetches = 0;
1452
- var getDocumentPromise = getDocumentData().then(function (data) {
1439
+ var fetches = 0,
1440
+ loadingTask;
1441
+ dataPromise.then(function (data) {
1453
1442
  var initialData = data.subarray(0, initialDataLength);
1454
- transport = new _api.PDFDataRangeTransport(data.length, initialData);
1443
+ var transport = new _api.PDFDataRangeTransport(data.length, initialData);
1455
1444
 
1456
1445
  transport.requestDataRange = function (begin, end) {
1457
1446
  fetches++;
@@ -1465,21 +1454,42 @@ describe('api', function () {
1465
1454
  });
1466
1455
  };
1467
1456
 
1468
- var loadingTask = (0, _api.getDocument)(transport);
1457
+ loadingTask = (0, _api.getDocument)(transport);
1469
1458
  return loadingTask.promise;
1470
- });
1471
- var pdfDocument;
1472
- var getPagePromise = getDocumentPromise.then(function (pdfDocument_) {
1473
- pdfDocument = pdfDocument_;
1474
- var pagePromise = pdfDocument.getPage(10);
1475
- return pagePromise;
1476
- });
1477
- getPagePromise.then(function (page) {
1459
+ }).then(function (pdfDocument) {
1478
1460
  expect(pdfDocument.numPages).toEqual(14);
1479
- expect(page.rotate).toEqual(0);
1461
+ return pdfDocument.getPage(10);
1462
+ }).then(function (pdfPage) {
1463
+ expect(pdfPage.rotate).toEqual(0);
1480
1464
  expect(fetches).toEqual(1);
1481
- done();
1482
- }).catch(done.fail);
1465
+ waitSome(function () {
1466
+ loadingTask.destroy().then(done);
1467
+ });
1468
+ })["catch"](done.fail);
1469
+ });
1470
+ it('should fetch document info and page, without range, ' + 'using complete initialData', function (done) {
1471
+ var fetches = 0,
1472
+ loadingTask;
1473
+ dataPromise.then(function (data) {
1474
+ var transport = new _api.PDFDataRangeTransport(data.length, data, true);
1475
+
1476
+ transport.requestDataRange = function (begin, end) {
1477
+ fetches++;
1478
+ };
1479
+
1480
+ loadingTask = (0, _api.getDocument)({
1481
+ disableRange: true,
1482
+ range: transport
1483
+ });
1484
+ return loadingTask.promise;
1485
+ }).then(function (pdfDocument) {
1486
+ expect(pdfDocument.numPages).toEqual(14);
1487
+ return pdfDocument.getPage(10);
1488
+ }).then(function (pdfPage) {
1489
+ expect(pdfPage.rotate).toEqual(0);
1490
+ expect(fetches).toEqual(0);
1491
+ loadingTask.destroy().then(done);
1492
+ })["catch"](done.fail);
1483
1493
  });
1484
1494
  });
1485
1495
  });