pdfjs-dist 2.0.550 → 2.3.200

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