pdfjs-dist 2.0.489 → 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 (169) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +18515 -11402
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +48266 -37137
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/external/url/url-lib.js +627 -0
  10. package/image_decoders/pdf.image_decoders.js +11350 -0
  11. package/image_decoders/pdf.image_decoders.js.map +1 -0
  12. package/image_decoders/pdf.image_decoders.min.js +1 -0
  13. package/lib/core/annotation.js +587 -242
  14. package/lib/core/arithmetic_decoder.js +275 -245
  15. package/lib/core/bidi.js +65 -6
  16. package/lib/core/ccitt.js +173 -18
  17. package/lib/core/ccitt_stream.js +15 -6
  18. package/lib/core/cff_parser.js +433 -61
  19. package/lib/core/charsets.js +5 -4
  20. package/lib/core/chunked_stream.js +400 -152
  21. package/lib/core/cmap.js +326 -87
  22. package/lib/core/colorspace.js +874 -594
  23. package/lib/core/core_utils.js +147 -0
  24. package/lib/core/crypto.js +290 -45
  25. package/lib/core/document.js +560 -268
  26. package/lib/core/encodings.js +19 -10
  27. package/lib/core/evaluator.js +1005 -360
  28. package/lib/core/font_renderer.js +331 -97
  29. package/lib/core/fonts.js +812 -195
  30. package/lib/core/function.js +284 -71
  31. package/lib/core/glyphlist.js +4 -3
  32. package/lib/core/image.js +169 -62
  33. package/lib/core/image_utils.js +111 -0
  34. package/lib/core/jbig2.js +479 -66
  35. package/lib/core/jbig2_stream.js +19 -8
  36. package/lib/core/jpeg_stream.js +38 -13
  37. package/lib/core/jpg.js +253 -29
  38. package/lib/core/jpx.js +396 -6
  39. package/lib/core/jpx_stream.js +18 -6
  40. package/lib/core/metrics.js +15 -15
  41. package/lib/core/murmurhash3.js +56 -34
  42. package/lib/core/obj.js +1354 -488
  43. package/lib/core/operator_list.js +144 -31
  44. package/lib/core/parser.js +539 -191
  45. package/lib/core/pattern.js +148 -14
  46. package/lib/core/pdf_manager.js +323 -133
  47. package/lib/core/primitives.js +111 -24
  48. package/lib/core/ps_parser.js +134 -45
  49. package/lib/core/standard_fonts.js +17 -17
  50. package/lib/core/stream.js +313 -34
  51. package/lib/core/type1_parser.js +143 -13
  52. package/lib/core/unicode.js +32 -5
  53. package/lib/core/worker.js +217 -190
  54. package/lib/core/worker_stream.js +277 -0
  55. package/lib/display/annotation_layer.js +450 -133
  56. package/lib/display/api.js +1597 -784
  57. package/lib/display/api_compatibility.js +11 -13
  58. package/lib/display/canvas.js +360 -44
  59. package/lib/display/content_disposition.js +83 -32
  60. package/lib/display/display_utils.js +747 -0
  61. package/lib/display/fetch_stream.js +221 -90
  62. package/lib/display/font_loader.js +468 -236
  63. package/lib/display/metadata.js +38 -16
  64. package/lib/display/network.js +635 -428
  65. package/lib/display/network_utils.js +32 -19
  66. package/lib/display/node_stream.js +367 -175
  67. package/lib/display/pattern_helper.js +81 -31
  68. package/lib/display/svg.js +1235 -519
  69. package/lib/display/text_layer.js +153 -29
  70. package/lib/display/transport_stream.js +345 -94
  71. package/lib/display/webgl.js +64 -18
  72. package/lib/display/worker_options.js +5 -4
  73. package/lib/display/xml_parser.js +166 -53
  74. package/lib/examples/node/domstubs.js +60 -4
  75. package/lib/pdf.js +36 -14
  76. package/lib/pdf.worker.js +5 -3
  77. package/lib/shared/compatibility.js +158 -564
  78. package/lib/shared/global_scope.js +2 -2
  79. package/lib/shared/is_node.js +4 -4
  80. package/lib/shared/message_handler.js +521 -0
  81. package/lib/shared/streams_polyfill.js +21 -17
  82. package/lib/shared/url_polyfill.js +56 -0
  83. package/lib/shared/util.js +243 -710
  84. package/lib/test/unit/annotation_spec.js +870 -401
  85. package/lib/test/unit/api_spec.js +657 -345
  86. package/lib/test/unit/bidi_spec.js +7 -7
  87. package/lib/test/unit/cff_parser_spec.js +54 -11
  88. package/lib/test/unit/clitests_helper.js +10 -8
  89. package/lib/test/unit/cmap_spec.js +95 -41
  90. package/lib/test/unit/colorspace_spec.js +115 -63
  91. package/lib/test/unit/core_utils_spec.js +191 -0
  92. package/lib/test/unit/crypto_spec.js +17 -5
  93. package/lib/test/unit/custom_spec.js +43 -55
  94. package/lib/test/unit/display_svg_spec.js +34 -18
  95. package/lib/test/unit/display_utils_spec.js +273 -0
  96. package/lib/test/unit/document_spec.js +8 -13
  97. package/lib/test/unit/encodings_spec.js +25 -45
  98. package/lib/test/unit/evaluator_spec.js +38 -15
  99. package/lib/test/unit/fetch_stream_spec.js +109 -0
  100. package/lib/test/unit/function_spec.js +17 -5
  101. package/lib/test/unit/jasmine-boot.js +33 -20
  102. package/lib/test/unit/{util_stream_spec.js → message_handler_spec.js} +41 -69
  103. package/lib/test/unit/metadata_spec.js +71 -11
  104. package/lib/test/unit/murmurhash3_spec.js +3 -3
  105. package/lib/test/unit/network_spec.js +19 -54
  106. package/lib/test/unit/network_utils_spec.js +91 -14
  107. package/lib/test/unit/node_stream_spec.js +56 -32
  108. package/lib/test/unit/parser_spec.js +162 -71
  109. package/lib/test/unit/pdf_find_controller_spec.js +230 -0
  110. package/lib/test/unit/pdf_find_utils_spec.js +63 -0
  111. package/lib/test/unit/pdf_history_spec.js +21 -9
  112. package/lib/test/unit/primitives_spec.js +53 -20
  113. package/lib/test/unit/stream_spec.js +12 -4
  114. package/lib/test/unit/test_utils.js +273 -56
  115. package/lib/test/unit/testreporter.js +21 -3
  116. package/lib/test/unit/type1_parser_spec.js +8 -6
  117. package/lib/test/unit/ui_utils_spec.js +454 -16
  118. package/lib/test/unit/unicode_spec.js +18 -15
  119. package/lib/test/unit/util_spec.js +87 -128
  120. package/lib/web/annotation_layer_builder.js +39 -22
  121. package/lib/web/app.js +1290 -588
  122. package/lib/web/app_options.js +100 -62
  123. package/lib/web/base_viewer.js +511 -182
  124. package/lib/web/chromecom.js +261 -117
  125. package/lib/web/debugger.js +166 -22
  126. package/lib/web/download_manager.js +32 -13
  127. package/lib/web/firefox_print_service.js +20 -10
  128. package/lib/web/firefoxcom.js +315 -80
  129. package/lib/web/genericcom.js +89 -30
  130. package/lib/web/genericl10n.js +142 -30
  131. package/lib/web/grab_to_pan.js +28 -4
  132. package/lib/web/interfaces.js +170 -47
  133. package/lib/web/overlay_manager.js +235 -85
  134. package/lib/web/password_prompt.js +22 -14
  135. package/lib/web/pdf_attachment_viewer.js +38 -18
  136. package/lib/web/pdf_cursor_tools.js +39 -16
  137. package/lib/web/pdf_document_properties.js +255 -136
  138. package/lib/web/pdf_find_bar.js +84 -40
  139. package/lib/web/pdf_find_controller.js +495 -184
  140. package/lib/web/pdf_find_utils.js +111 -0
  141. package/lib/web/pdf_history.js +190 -53
  142. package/lib/web/pdf_link_service.js +138 -77
  143. package/lib/web/pdf_outline_viewer.js +122 -46
  144. package/lib/web/pdf_page_view.js +191 -67
  145. package/lib/web/pdf_presentation_mode.js +99 -34
  146. package/lib/web/pdf_print_service.js +61 -13
  147. package/lib/web/pdf_rendering_queue.js +28 -9
  148. package/lib/web/pdf_sidebar.js +141 -81
  149. package/lib/web/pdf_sidebar_resizer.js +42 -16
  150. package/lib/web/pdf_single_page_viewer.js +74 -66
  151. package/lib/web/pdf_thumbnail_view.js +104 -33
  152. package/lib/web/pdf_thumbnail_viewer.js +66 -26
  153. package/lib/web/pdf_viewer.component.js +112 -32
  154. package/lib/web/pdf_viewer.js +91 -52
  155. package/lib/web/preferences.js +284 -89
  156. package/lib/web/secondary_toolbar.js +165 -40
  157. package/lib/web/text_layer_builder.js +134 -59
  158. package/lib/web/toolbar.js +78 -43
  159. package/lib/web/ui_utils.js +462 -136
  160. package/lib/web/view_history.js +215 -67
  161. package/lib/web/viewer_compatibility.js +4 -13
  162. package/package.json +5 -4
  163. package/web/pdf_viewer.css +79 -11
  164. package/web/pdf_viewer.js +6107 -3748
  165. package/web/pdf_viewer.js.map +1 -1
  166. package/lib/display/dom_utils.js +0 -309
  167. package/lib/test/unit/dom_utils_spec.js +0 -89
  168. package/lib/test/unit/fonts_spec.js +0 -81
  169. 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) { 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
  });
@@ -368,7 +396,7 @@ describe('api', function () {
368
396
  });
369
397
  it('gets fingerprint', function () {
370
398
  var fingerprint = doc.fingerprint;
371
- expect(typeof fingerprint === 'undefined' ? 'undefined' : _typeof(fingerprint)).toEqual('string');
399
+ expect(_typeof(fingerprint)).toEqual('string');
372
400
  expect(fingerprint.length > 0).toEqual(true);
373
401
  });
374
402
  it('gets page', function (done) {
@@ -377,9 +405,7 @@ describe('api', function () {
377
405
  expect(data instanceof _api.PDFPageProxy).toEqual(true);
378
406
  expect(data.pageIndex).toEqual(0);
379
407
  done();
380
- }).catch(function (reason) {
381
- done.fail(reason);
382
- });
408
+ })["catch"](done.fail);
383
409
  });
384
410
  it('gets non-existent page', function (done) {
385
411
  var outOfRangePromise = doc.getPage(100);
@@ -402,9 +428,7 @@ describe('api', function () {
402
428
  });
403
429
  Promise.all([outOfRangePromise, nonIntegerPromise, nonNumberPromise]).then(function () {
404
430
  done();
405
- }).catch(function (reason) {
406
- done.fail(reason);
407
- });
431
+ })["catch"](done.fail);
408
432
  });
409
433
  it('gets page index', function (done) {
410
434
  var ref = {
@@ -415,9 +439,7 @@ describe('api', function () {
415
439
  promise.then(function (pageIndex) {
416
440
  expect(pageIndex).toEqual(1);
417
441
  done();
418
- }).catch(function (reason) {
419
- done.fail(reason);
420
- });
442
+ })["catch"](done.fail);
421
443
  });
422
444
  it('gets invalid page index', function (done) {
423
445
  var ref = {
@@ -427,7 +449,7 @@ describe('api', function () {
427
449
  var promise = doc.getPageIndex(ref);
428
450
  promise.then(function () {
429
451
  done.fail('shall fail for invalid page reference.');
430
- }).catch(function (reason) {
452
+ })["catch"](function (reason) {
431
453
  expect(reason instanceof Error).toEqual(true);
432
454
  done();
433
455
  });
@@ -439,12 +461,12 @@ describe('api', function () {
439
461
  chapter1: [{
440
462
  gen: 0,
441
463
  num: 17
442
- }, { name: 'XYZ' }, 0, 841.89, null]
464
+ }, {
465
+ name: 'XYZ'
466
+ }, 0, 841.89, null]
443
467
  });
444
468
  done();
445
- }).catch(function (reason) {
446
- done.fail(reason);
447
- });
469
+ })["catch"](done.fail);
448
470
  });
449
471
  it('gets a destination, from /Dests dictionary', function (done) {
450
472
  var promise = doc.getDestination('chapter1');
@@ -452,20 +474,18 @@ describe('api', function () {
452
474
  expect(data).toEqual([{
453
475
  gen: 0,
454
476
  num: 17
455
- }, { name: 'XYZ' }, 0, 841.89, null]);
477
+ }, {
478
+ name: 'XYZ'
479
+ }, 0, 841.89, null]);
456
480
  done();
457
- }).catch(function (reason) {
458
- done.fail(reason);
459
- });
481
+ })["catch"](done.fail);
460
482
  });
461
483
  it('gets a non-existent destination, from /Dests dictionary', function (done) {
462
484
  var promise = doc.getDestination('non-existent-named-destination');
463
485
  promise.then(function (data) {
464
486
  expect(data).toEqual(null);
465
487
  done();
466
- }).catch(function (reason) {
467
- done.fail(reason);
468
- });
488
+ })["catch"](done.fail);
469
489
  });
470
490
  it('gets destinations, from /Names (NameTree) dictionary', function (done) {
471
491
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
@@ -477,16 +497,18 @@ describe('api', function () {
477
497
  'Page.1': [{
478
498
  num: 1,
479
499
  gen: 0
480
- }, { name: 'XYZ' }, 0, 375, null],
500
+ }, {
501
+ name: 'XYZ'
502
+ }, 0, 375, null],
481
503
  'Page.2': [{
482
504
  num: 6,
483
505
  gen: 0
484
- }, { name: 'XYZ' }, 0, 375, null]
506
+ }, {
507
+ name: 'XYZ'
508
+ }, 0, 375, null]
485
509
  });
486
510
  loadingTask.destroy().then(done);
487
- }).catch(function (reason) {
488
- done.fail(reason);
489
- });
511
+ })["catch"](done.fail);
490
512
  });
491
513
  it('gets a destination, from /Names (NameTree) dictionary', function (done) {
492
514
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
@@ -497,11 +519,11 @@ describe('api', function () {
497
519
  expect(destination).toEqual([{
498
520
  num: 1,
499
521
  gen: 0
500
- }, { name: 'XYZ' }, 0, 375, null]);
522
+ }, {
523
+ name: 'XYZ'
524
+ }, 0, 375, null]);
501
525
  loadingTask.destroy().then(done);
502
- }).catch(function (reason) {
503
- done.fail(reason);
504
- });
526
+ })["catch"](done.fail);
505
527
  });
506
528
  it('gets a non-existent destination, from /Names (NameTree) dictionary', function (done) {
507
529
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
@@ -511,18 +533,40 @@ describe('api', function () {
511
533
  promise.then(function (destination) {
512
534
  expect(destination).toEqual(null);
513
535
  loadingTask.destroy().then(done);
514
- }).catch(function (reason) {
515
- done.fail(reason);
536
+ })["catch"](done.fail);
537
+ });
538
+ it('gets non-string destination', function (done) {
539
+ var numberPromise = doc.getDestination(4.3);
540
+ var booleanPromise = doc.getDestination(true);
541
+ var arrayPromise = doc.getDestination([{
542
+ num: 17,
543
+ gen: 0
544
+ }, {
545
+ name: 'XYZ'
546
+ }, 0, 841.89, null]);
547
+ numberPromise = numberPromise.then(function () {
548
+ throw new Error('shall fail for non-string destination.');
549
+ }, function (reason) {
550
+ expect(reason instanceof Error).toEqual(true);
551
+ });
552
+ booleanPromise = booleanPromise.then(function () {
553
+ throw new Error('shall fail for non-string destination.');
554
+ }, function (reason) {
555
+ expect(reason instanceof Error).toEqual(true);
556
+ });
557
+ arrayPromise = arrayPromise.then(function () {
558
+ throw new Error('shall fail for non-string destination.');
559
+ }, function (reason) {
560
+ expect(reason instanceof Error).toEqual(true);
516
561
  });
562
+ Promise.all([numberPromise, booleanPromise, arrayPromise]).then(done, done.fail);
517
563
  });
518
564
  it('gets non-existent page labels', function (done) {
519
565
  var promise = doc.getPageLabels();
520
566
  promise.then(function (data) {
521
567
  expect(data).toEqual(null);
522
568
  done();
523
- }).catch(function (reason) {
524
- done.fail(reason);
525
- });
569
+ })["catch"](done.fail);
526
570
  });
527
571
  it('gets page labels', function (done) {
528
572
  var loadingTask0 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug793632.pdf'));
@@ -547,9 +591,22 @@ describe('api', function () {
547
591
  expect(pageLabels[2]).toEqual(['1', '2']);
548
592
  expect(pageLabels[3]).toEqual(['X3']);
549
593
  Promise.all([loadingTask0.destroy(), loadingTask1.destroy(), loadingTask2.destroy(), loadingTask3.destroy()]).then(done);
550
- }).catch(function (reason) {
551
- done.fail(reason);
552
- });
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);
553
610
  });
554
611
  it('gets default page mode', function (done) {
555
612
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
@@ -558,31 +615,63 @@ describe('api', function () {
558
615
  }).then(function (mode) {
559
616
  expect(mode).toEqual('UseNone');
560
617
  loadingTask.destroy().then(done);
561
- }).catch(function (reason) {
562
- done.fail(reason);
563
- });
618
+ })["catch"](done.fail);
564
619
  });
565
620
  it('gets non-default page mode', function (done) {
566
621
  doc.getPageMode().then(function (mode) {
567
622
  expect(mode).toEqual('UseOutlines');
568
623
  done();
569
- }).catch(function (reason) {
570
- done.fail(reason);
571
- });
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);
642
+ });
643
+ it('gets default open action destination', function (done) {
644
+ var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
645
+ loadingTask.promise.then(function (pdfDocument) {
646
+ return pdfDocument.getOpenActionDestination();
647
+ }).then(function (dest) {
648
+ expect(dest).toEqual(null);
649
+ loadingTask.destroy().then(done);
650
+ })["catch"](done.fail);
651
+ });
652
+ it('gets non-default open action destination', function (done) {
653
+ doc.getOpenActionDestination().then(function (dest) {
654
+ expect(dest).toEqual([{
655
+ num: 15,
656
+ gen: 0
657
+ }, {
658
+ name: 'FitH'
659
+ }, null]);
660
+ done();
661
+ })["catch"](done.fail);
572
662
  });
573
663
  it('gets non-existent attachments', function (done) {
574
664
  var promise = doc.getAttachments();
575
665
  promise.then(function (data) {
576
666
  expect(data).toEqual(null);
577
667
  done();
578
- }).catch(function (reason) {
579
- done.fail(reason);
580
- });
668
+ })["catch"](done.fail);
581
669
  });
582
670
  it('gets attachments', function (done) {
583
- if ((0, _is_node2.default)()) {
671
+ if ((0, _is_node["default"])()) {
584
672
  pending('TODO: Use a non-linked test-case.');
585
673
  }
674
+
586
675
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug766138.pdf'));
587
676
  var promise = loadingTask.promise.then(function (pdfDoc) {
588
677
  return pdfDoc.getAttachments();
@@ -593,18 +682,14 @@ describe('api', function () {
593
682
  expect(attachment.content instanceof Uint8Array).toBeTruthy();
594
683
  expect(attachment.content.length).toEqual(30098);
595
684
  loadingTask.destroy().then(done);
596
- }).catch(function (reason) {
597
- done.fail(reason);
598
- });
685
+ })["catch"](done.fail);
599
686
  });
600
687
  it('gets javascript', function (done) {
601
688
  var promise = doc.getJavaScript();
602
689
  promise.then(function (data) {
603
690
  expect(data).toEqual(null);
604
691
  done();
605
- }).catch(function (reason) {
606
- done.fail(reason);
607
- });
692
+ })["catch"](done.fail);
608
693
  });
609
694
  var viewerPrintRegExp = /\bprint\s*\(/;
610
695
  it('gets javascript with printing instructions (Print action)', function (done) {
@@ -616,9 +701,7 @@ describe('api', function () {
616
701
  expect(data).toEqual(['print({});']);
617
702
  expect(data[0]).toMatch(viewerPrintRegExp);
618
703
  loadingTask.destroy().then(done);
619
- }).catch(function (reason) {
620
- done.fail(reason);
621
- });
704
+ })["catch"](done.fail);
622
705
  });
623
706
  it('gets javascript with printing instructions (JS action)', function (done) {
624
707
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6106.pdf'));
@@ -629,9 +712,7 @@ describe('api', function () {
629
712
  expect(data).toEqual(['this.print({bUI:true,bSilent:false,bShrinkToFit:true});']);
630
713
  expect(data[0]).toMatch(viewerPrintRegExp);
631
714
  loadingTask.destroy().then(done);
632
- }).catch(function (reason) {
633
- done.fail(reason);
634
- });
715
+ })["catch"](done.fail);
635
716
  });
636
717
  it('gets non-existent outline', function (done) {
637
718
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
@@ -641,36 +722,32 @@ describe('api', function () {
641
722
  promise.then(function (outline) {
642
723
  expect(outline).toEqual(null);
643
724
  loadingTask.destroy().then(done);
644
- }).catch(function (reason) {
645
- done.fail(reason);
646
- });
725
+ })["catch"](done.fail);
647
726
  });
648
727
  it('gets outline', function (done) {
649
728
  var promise = doc.getOutline();
650
729
  promise.then(function (outline) {
651
- expect(outline instanceof Array).toEqual(true);
730
+ expect(Array.isArray(outline)).toEqual(true);
652
731
  expect(outline.length).toEqual(2);
653
732
  var outlineItem = outline[1];
654
733
  expect(outlineItem.title).toEqual('Chapter 1');
655
- expect(outlineItem.dest instanceof Array).toEqual(true);
734
+ expect(Array.isArray(outlineItem.dest)).toEqual(true);
656
735
  expect(outlineItem.url).toEqual(null);
657
736
  expect(outlineItem.unsafeUrl).toBeUndefined();
658
737
  expect(outlineItem.newWindow).toBeUndefined();
659
738
  expect(outlineItem.bold).toEqual(true);
660
739
  expect(outlineItem.italic).toEqual(false);
661
- expect(outlineItem.color).toEqual(new Uint8Array([0, 64, 128]));
740
+ expect(outlineItem.color).toEqual(new Uint8ClampedArray([0, 64, 128]));
662
741
  expect(outlineItem.items.length).toEqual(1);
663
742
  expect(outlineItem.items[0].title).toEqual('Paragraph 1.1');
664
743
  done();
665
- }).catch(function (reason) {
666
- done.fail(reason);
667
- });
744
+ })["catch"](done.fail);
668
745
  });
669
746
  it('gets outline containing a url', function (done) {
670
747
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue3214.pdf'));
671
748
  loadingTask.promise.then(function (pdfDocument) {
672
749
  pdfDocument.getOutline().then(function (outline) {
673
- expect(outline instanceof Array).toEqual(true);
750
+ expect(Array.isArray(outline)).toEqual(true);
674
751
  expect(outline.length).toEqual(5);
675
752
  var outlineItemTwo = outline[2];
676
753
  expect(_typeof(outlineItemTwo.title)).toEqual('string');
@@ -681,24 +758,84 @@ describe('api', function () {
681
758
  var outlineItemOne = outline[1];
682
759
  expect(outlineItemOne.bold).toEqual(false);
683
760
  expect(outlineItemOne.italic).toEqual(true);
684
- expect(outlineItemOne.color).toEqual(new Uint8Array([0, 0, 0]));
761
+ expect(outlineItemOne.color).toEqual(new Uint8ClampedArray([0, 0, 0]));
685
762
  loadingTask.destroy().then(done);
686
763
  });
687
- }).catch(function (reason) {
688
- done.fail(reason);
689
- });
764
+ })["catch"](done.fail);
765
+ });
766
+ it('gets non-existent permissions', function (done) {
767
+ doc.getPermissions().then(function (permissions) {
768
+ expect(permissions).toEqual(null);
769
+ done();
770
+ })["catch"](done.fail);
771
+ });
772
+ it('gets permissions', function (done) {
773
+ var loadingTask0 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue9972-1.pdf'));
774
+ var promise0 = loadingTask0.promise.then(function (pdfDocument) {
775
+ return pdfDocument.getPermissions();
776
+ });
777
+ var loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue9972-2.pdf'));
778
+ var promise1 = loadingTask1.promise.then(function (pdfDocument) {
779
+ return pdfDocument.getPermissions();
780
+ });
781
+ var loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue9972-3.pdf'));
782
+ var promise2 = loadingTask2.promise.then(function (pdfDocument) {
783
+ return pdfDocument.getPermissions();
784
+ });
785
+ var totalPermissionCount = Object.keys(_util.PermissionFlag).length;
786
+ Promise.all([promise0, promise1, promise2]).then(function (permissions) {
787
+ expect(permissions[0].length).toEqual(totalPermissionCount - 1);
788
+ expect(permissions[0].includes(_util.PermissionFlag.MODIFY_CONTENTS)).toBeFalsy();
789
+ expect(permissions[1].length).toEqual(totalPermissionCount - 2);
790
+ expect(permissions[1].includes(_util.PermissionFlag.PRINT)).toBeFalsy();
791
+ expect(permissions[1].includes(_util.PermissionFlag.PRINT_HIGH_QUALITY)).toBeFalsy();
792
+ expect(permissions[2].length).toEqual(totalPermissionCount - 1);
793
+ expect(permissions[2].includes(_util.PermissionFlag.COPY)).toBeFalsy();
794
+ Promise.all([loadingTask0.destroy(), loadingTask1.destroy(), loadingTask2.destroy()]).then(done);
795
+ })["catch"](done.fail);
690
796
  });
691
797
  it('gets metadata', function (done) {
692
798
  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);
799
+ promise.then(function (_ref) {
800
+ var info = _ref.info,
801
+ metadata = _ref.metadata,
802
+ contentDispositionFilename = _ref.contentDispositionFilename;
803
+ expect(info['Title']).toEqual('Basic API Test');
804
+ expect(info['Custom']).toEqual(undefined);
805
+ expect(info['PDFFormatVersion']).toEqual('1.7');
806
+ expect(info['IsLinearized']).toEqual(false);
807
+ expect(info['IsAcroFormPresent']).toEqual(false);
808
+ expect(info['IsXFAPresent']).toEqual(false);
809
+ expect(info['IsCollectionPresent']).toEqual(false);
810
+ expect(metadata instanceof _metadata.Metadata).toEqual(true);
811
+ expect(metadata.get('dc:title')).toEqual('Basic API Test');
812
+ expect(contentDispositionFilename).toEqual(null);
698
813
  done();
699
- }).catch(function (reason) {
700
- done.fail(reason);
701
- });
814
+ })["catch"](done.fail);
815
+ });
816
+ it('gets metadata, with custom info dict entries', function (done) {
817
+ var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
818
+ loadingTask.promise.then(function (pdfDocument) {
819
+ return pdfDocument.getMetadata();
820
+ }).then(function (_ref2) {
821
+ var info = _ref2.info,
822
+ metadata = _ref2.metadata,
823
+ contentDispositionFilename = _ref2.contentDispositionFilename;
824
+ expect(info['Creator']).toEqual('TeX');
825
+ expect(info['Producer']).toEqual('pdfeTeX-1.21a');
826
+ expect(info['CreationDate']).toEqual('D:20090401163925-07\'00\'');
827
+ var custom = info['Custom'];
828
+ expect(_typeof(custom) === 'object' && custom !== null).toEqual(true);
829
+ expect(custom['PTEX.Fullbanner']).toEqual('This is pdfeTeX, ' + 'Version 3.141592-1.21a-2.2 (Web2C 7.5.4) kpathsea version 3.5.6');
830
+ expect(info['PDFFormatVersion']).toEqual('1.4');
831
+ expect(info['IsLinearized']).toEqual(false);
832
+ expect(info['IsAcroFormPresent']).toEqual(false);
833
+ expect(info['IsXFAPresent']).toEqual(false);
834
+ expect(info['IsCollectionPresent']).toEqual(false);
835
+ expect(metadata).toEqual(null);
836
+ expect(contentDispositionFilename).toEqual(null);
837
+ loadingTask.destroy().then(done);
838
+ })["catch"](done.fail);
702
839
  });
703
840
  it('gets data', function (done) {
704
841
  var promise = doc.getData();
@@ -706,20 +843,18 @@ describe('api', function () {
706
843
  expect(data instanceof Uint8Array).toEqual(true);
707
844
  expect(data.length).toEqual(basicApiFileLength);
708
845
  done();
709
- }).catch(function (reason) {
710
- done.fail(reason);
711
- });
846
+ })["catch"](done.fail);
712
847
  });
713
848
  it('gets download info', function (done) {
714
849
  var promise = doc.getDownloadInfo();
715
850
  promise.then(function (data) {
716
- expect(data).toEqual({ length: basicApiFileLength });
851
+ expect(data).toEqual({
852
+ length: basicApiFileLength
853
+ });
717
854
  done();
718
- }).catch(function (reason) {
719
- done.fail(reason);
720
- });
855
+ })["catch"](done.fail);
721
856
  });
722
- it('gets stats', function (done) {
857
+ it('gets document stats', function (done) {
723
858
  var promise = doc.getStats();
724
859
  promise.then(function (stats) {
725
860
  expect(stats).toEqual({
@@ -727,9 +862,7 @@ describe('api', function () {
727
862
  fontTypes: []
728
863
  });
729
864
  done();
730
- }).catch(function (reason) {
731
- done.fail(reason);
732
- });
865
+ })["catch"](done.fail);
733
866
  });
734
867
  it('checks that fingerprints are unique', function (done) {
735
868
  var loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue4436r.pdf'));
@@ -737,25 +870,26 @@ describe('api', function () {
737
870
  var promises = [loadingTask1.promise, loadingTask2.promise];
738
871
  Promise.all(promises).then(function (data) {
739
872
  var fingerprint1 = data[0].fingerprint;
740
- expect(typeof fingerprint1 === 'undefined' ? 'undefined' : _typeof(fingerprint1)).toEqual('string');
873
+ expect(_typeof(fingerprint1)).toEqual('string');
741
874
  expect(fingerprint1.length > 0).toEqual(true);
742
875
  var fingerprint2 = data[1].fingerprint;
743
- expect(typeof fingerprint2 === 'undefined' ? 'undefined' : _typeof(fingerprint2)).toEqual('string');
876
+ expect(_typeof(fingerprint2)).toEqual('string');
744
877
  expect(fingerprint2.length > 0).toEqual(true);
745
878
  expect(fingerprint1).not.toEqual(fingerprint2);
746
879
  Promise.all([loadingTask1.destroy(), loadingTask2.destroy()]).then(done);
747
- }).catch(function (reason) {
748
- done.fail(reason);
749
- });
880
+ })["catch"](done.fail);
750
881
  });
751
882
  describe('Cross-origin', function () {
752
883
  var loadingTask;
884
+
753
885
  function _checkCanLoad(expectSuccess, filename, options) {
754
- if ((0, _is_node2.default)()) {
886
+ if ((0, _is_node["default"])()) {
755
887
  pending('Cannot simulate cross-origin requests in Node.js');
756
888
  }
889
+
757
890
  var params = (0, _test_utils.buildGetDocumentParams)(filename, options);
758
891
  var url = new URL(params.url);
892
+
759
893
  if (url.hostname === 'localhost') {
760
894
  url.hostname = '127.0.0.1';
761
895
  } else if (params.url.hostname === '127.0.0.1') {
@@ -763,6 +897,7 @@ describe('api', function () {
763
897
  } else {
764
898
  pending('Can only run cross-origin test on localhost!');
765
899
  }
900
+
766
901
  params.url = url.href;
767
902
  loadingTask = (0, _api.getDocument)(params);
768
903
  return loadingTask.promise.then(function (pdf) {
@@ -773,17 +908,21 @@ describe('api', function () {
773
908
  if (expectSuccess) {
774
909
  expect(error).toEqual('There should not be any error');
775
910
  }
911
+
776
912
  expect(expectSuccess).toEqual(false);
777
913
  });
778
914
  }
915
+
779
916
  function testCanLoad(filename, options) {
780
917
  return _checkCanLoad(true, filename, options);
781
918
  }
919
+
782
920
  function testCannotLoad(filename, options) {
783
921
  return _checkCanLoad(false, filename, options);
784
922
  }
923
+
785
924
  afterEach(function (done) {
786
- if (loadingTask) {
925
+ if (loadingTask && !loadingTask.destroyed) {
787
926
  loadingTask.destroy().then(done);
788
927
  } else {
789
928
  done();
@@ -796,16 +935,24 @@ describe('api', function () {
796
935
  testCanLoad('basicapi.pdf?cors=withoutCredentials').then(done);
797
936
  });
798
937
  it('server allows cors without credentials, and withCredentials=false', function (done) {
799
- testCanLoad('basicapi.pdf?cors=withoutCredentials', { withCredentials: false }).then(done);
938
+ testCanLoad('basicapi.pdf?cors=withoutCredentials', {
939
+ withCredentials: false
940
+ }).then(done);
800
941
  });
801
942
  it('server allows cors without credentials, but withCredentials=true', function (done) {
802
- testCannotLoad('basicapi.pdf?cors=withoutCredentials', { withCredentials: true }).then(done);
943
+ testCannotLoad('basicapi.pdf?cors=withoutCredentials', {
944
+ withCredentials: true
945
+ }).then(done);
803
946
  });
804
947
  it('server allows cors with credentials, and withCredentials=true', function (done) {
805
- testCanLoad('basicapi.pdf?cors=withCredentials', { withCredentials: true }).then(done);
948
+ testCanLoad('basicapi.pdf?cors=withCredentials', {
949
+ withCredentials: true
950
+ }).then(done);
806
951
  });
807
952
  it('server allows cors with credentials, and withCredentials=false', function (done) {
808
- testCanLoad('basicapi.pdf?cors=withCredentials', { withCredentials: false }).then(done);
953
+ testCanLoad('basicapi.pdf?cors=withCredentials', {
954
+ withCredentials: false
955
+ }).then(done);
809
956
  });
810
957
  });
811
958
  });
@@ -820,9 +967,7 @@ describe('api', function () {
820
967
  page = data;
821
968
  done();
822
969
  });
823
- }).catch(function (reason) {
824
- done.fail(reason);
825
- });
970
+ })["catch"](done.fail);
826
971
  });
827
972
  afterAll(function (done) {
828
973
  loadingTask.destroy().then(done);
@@ -846,7 +991,10 @@ describe('api', function () {
846
991
  expect(page.view).toEqual([0, 0, 595.28, 841.89]);
847
992
  });
848
993
  it('gets viewport', function () {
849
- var viewport = page.getViewport(1.5, 90);
994
+ var viewport = page.getViewport({
995
+ scale: 1.5,
996
+ rotation: 90
997
+ });
850
998
  expect(viewport.viewBox).toEqual(page.view);
851
999
  expect(viewport.scale).toEqual(1.5);
852
1000
  expect(viewport.rotation).toEqual(90);
@@ -857,10 +1005,19 @@ describe('api', function () {
857
1005
  it('gets viewport respecting "dontFlip" argument', function () {
858
1006
  var scale = 1;
859
1007
  var rotation = 135;
860
- var viewport = page.getViewport(scale, rotation);
861
- var dontFlipViewport = page.getViewport(scale, rotation, true);
1008
+ var viewport = page.getViewport({
1009
+ scale: scale,
1010
+ rotation: rotation
1011
+ });
1012
+ var dontFlipViewport = page.getViewport({
1013
+ scale: scale,
1014
+ rotation: rotation,
1015
+ dontFlip: true
1016
+ });
862
1017
  expect(dontFlipViewport).not.toEqual(viewport);
863
- expect(dontFlipViewport).toEqual(viewport.clone({ dontFlip: true }));
1018
+ expect(dontFlipViewport).toEqual(viewport.clone({
1019
+ dontFlip: true
1020
+ }));
864
1021
  expect(viewport.transform).toEqual([1, 0, 0, -1, 0, 841.89]);
865
1022
  expect(dontFlipViewport.transform).toEqual([1, 0, -0, 1, 0, 0]);
866
1023
  });
@@ -868,17 +1025,19 @@ describe('api', function () {
868
1025
  var defaultPromise = page.getAnnotations().then(function (data) {
869
1026
  expect(data.length).toEqual(4);
870
1027
  });
871
- var displayPromise = page.getAnnotations({ intent: 'display' }).then(function (data) {
1028
+ var displayPromise = page.getAnnotations({
1029
+ intent: 'display'
1030
+ }).then(function (data) {
872
1031
  expect(data.length).toEqual(4);
873
1032
  });
874
- var printPromise = page.getAnnotations({ intent: 'print' }).then(function (data) {
1033
+ var printPromise = page.getAnnotations({
1034
+ intent: 'print'
1035
+ }).then(function (data) {
875
1036
  expect(data.length).toEqual(4);
876
1037
  });
877
1038
  Promise.all([defaultPromise, displayPromise, printPromise]).then(function () {
878
1039
  done();
879
- }).catch(function (reason) {
880
- done.fail(reason);
881
- });
1040
+ })["catch"](done.fail);
882
1041
  });
883
1042
  it('gets annotations containing relative URLs (bug 766086)', function (done) {
884
1043
  var filename = 'bug766086.pdf';
@@ -888,13 +1047,17 @@ describe('api', function () {
888
1047
  return pdfPage.getAnnotations();
889
1048
  });
890
1049
  });
891
- var docBaseUrlLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, { docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf' }));
1050
+ var docBaseUrlLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
1051
+ docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf'
1052
+ }));
892
1053
  var docBaseUrlPromise = docBaseUrlLoadingTask.promise.then(function (pdfDoc) {
893
1054
  return pdfDoc.getPage(1).then(function (pdfPage) {
894
1055
  return pdfPage.getAnnotations();
895
1056
  });
896
1057
  });
897
- var invalidDocBaseUrlLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, { docBaseUrl: 'qwerty.pdf' }));
1058
+ var invalidDocBaseUrlLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
1059
+ docBaseUrl: 'qwerty.pdf'
1060
+ }));
898
1061
  var invalidDocBaseUrlPromise = invalidDocBaseUrlLoadingTask.promise.then(function (pdfDoc) {
899
1062
  return pdfDoc.getPage(1).then(function (pdfPage) {
900
1063
  return pdfPage.getAnnotations();
@@ -911,9 +1074,7 @@ describe('api', function () {
911
1074
  expect(invalidDocBaseUrlAnnotations[0].url).toBeUndefined();
912
1075
  expect(invalidDocBaseUrlAnnotations[0].unsafeUrl).toEqual('../../0021/002156/215675E.pdf#15');
913
1076
  Promise.all([defaultLoadingTask.destroy(), docBaseUrlLoadingTask.destroy(), invalidDocBaseUrlLoadingTask.destroy()]).then(done);
914
- }).catch(function (reason) {
915
- done.fail(reason);
916
- });
1077
+ })["catch"](done.fail);
917
1078
  });
918
1079
  it('gets text content', function (done) {
919
1080
  var defaultPromise = page.getTextContent();
@@ -928,9 +1089,35 @@ describe('api', function () {
928
1089
  expect(!!data[0].styles).toEqual(true);
929
1090
  expect(JSON.stringify(data[0])).toEqual(JSON.stringify(data[1]));
930
1091
  done();
931
- }).catch(function (reason) {
932
- done.fail(reason);
933
- });
1092
+ })["catch"](done.fail);
1093
+ });
1094
+ it('gets text content, with correct properties (issue 8276)', function (done) {
1095
+ var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue8276_reduced.pdf'));
1096
+ loadingTask.promise.then(function (pdfDoc) {
1097
+ pdfDoc.getPage(1).then(function (pdfPage) {
1098
+ pdfPage.getTextContent().then(function (_ref3) {
1099
+ var items = _ref3.items,
1100
+ styles = _ref3.styles;
1101
+ expect(items.length).toEqual(1);
1102
+ expect(Object.keys(styles)).toEqual(['Times']);
1103
+ expect(items[0]).toEqual({
1104
+ dir: 'ltr',
1105
+ fontName: 'Times',
1106
+ height: 18,
1107
+ str: 'Issue 8276',
1108
+ transform: [18, 0, 0, 18, 441.81, 708.4499999999999],
1109
+ width: 77.49
1110
+ });
1111
+ expect(styles.Times).toEqual({
1112
+ fontFamily: 'serif',
1113
+ ascent: NaN,
1114
+ descent: NaN,
1115
+ vertical: false
1116
+ });
1117
+ loadingTask.destroy().then(done);
1118
+ });
1119
+ });
1120
+ })["catch"](done.fail);
934
1121
  });
935
1122
  it('gets operator list', function (done) {
936
1123
  var promise = page.getOperatorList();
@@ -939,9 +1126,7 @@ describe('api', function () {
939
1126
  expect(!!oplist.argsArray).toEqual(true);
940
1127
  expect(oplist.lastChunk).toEqual(true);
941
1128
  done();
942
- }).catch(function (reason) {
943
- done.fail(reason);
944
- });
1129
+ })["catch"](done.fail);
945
1130
  });
946
1131
  it('gets operatorList with JPEG image (issue 4888)', function (done) {
947
1132
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('cmykjpeg.pdf'));
@@ -952,18 +1137,16 @@ describe('api', function () {
952
1137
  var imgArgs = opList.argsArray[imgIndex];
953
1138
 
954
1139
  var _pdfPage$objs$get = pdfPage.objs.get(imgArgs[0]),
955
- imgData = _pdfPage$objs$get.data;
1140
+ data = _pdfPage$objs$get.data;
956
1141
 
957
- expect(imgData instanceof Uint8ClampedArray).toEqual(true);
958
- expect(imgData.length).toEqual(90000);
959
- done();
1142
+ expect(data instanceof Uint8ClampedArray).toEqual(true);
1143
+ expect(data.length).toEqual(90000);
1144
+ loadingTask.destroy().then(done);
960
1145
  });
961
1146
  });
962
- }).catch(function (reason) {
963
- done.fail(reason);
964
- });
1147
+ })["catch"](done.fail);
965
1148
  });
966
- it('gets stats after parsing page', function (done) {
1149
+ it('gets document stats after parsing page', function (done) {
967
1150
  var promise = page.getOperatorList().then(function () {
968
1151
  return pdfDocument.getStats();
969
1152
  });
@@ -978,42 +1161,137 @@ describe('api', function () {
978
1161
  fontTypes: expectedFontTypes
979
1162
  });
980
1163
  done();
981
- }).catch(function (reason) {
982
- done.fail(reason);
983
- });
1164
+ })["catch"](done.fail);
1165
+ });
1166
+ it('gets page stats after parsing page, without `pdfBug` set', function (done) {
1167
+ page.getOperatorList().then(function (opList) {
1168
+ return page.stats;
1169
+ }).then(function (stats) {
1170
+ expect(stats).toEqual(null);
1171
+ done();
1172
+ }, done.fail);
1173
+ });
1174
+ it('gets page stats after parsing page, with `pdfBug` set', function (done) {
1175
+ var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, {
1176
+ pdfBug: true
1177
+ }));
1178
+ loadingTask.promise.then(function (pdfDoc) {
1179
+ return pdfDoc.getPage(1).then(function (pdfPage) {
1180
+ return pdfPage.getOperatorList().then(function (opList) {
1181
+ return pdfPage.stats;
1182
+ });
1183
+ });
1184
+ }).then(function (stats) {
1185
+ expect(stats instanceof _display_utils.StatTimer).toEqual(true);
1186
+ expect(stats.times.length).toEqual(1);
1187
+
1188
+ var _stats$times = _slicedToArray(stats.times, 1),
1189
+ statEntry = _stats$times[0];
1190
+
1191
+ expect(statEntry.name).toEqual('Page Request');
1192
+ expect(statEntry.end - statEntry.start).toBeGreaterThan(0);
1193
+ loadingTask.destroy().then(done);
1194
+ }, done.fail);
1195
+ });
1196
+ it('gets page stats after rendering page, with `pdfBug` set', function (done) {
1197
+ var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, {
1198
+ pdfBug: true
1199
+ }));
1200
+ var canvasAndCtx;
1201
+ loadingTask.promise.then(function (pdfDoc) {
1202
+ return pdfDoc.getPage(1).then(function (pdfPage) {
1203
+ var viewport = pdfPage.getViewport({
1204
+ scale: 1
1205
+ });
1206
+ canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
1207
+ var renderTask = pdfPage.render({
1208
+ canvasContext: canvasAndCtx.context,
1209
+ canvasFactory: CanvasFactory,
1210
+ viewport: viewport
1211
+ });
1212
+ return renderTask.promise.then(function () {
1213
+ return pdfPage.stats;
1214
+ });
1215
+ });
1216
+ }).then(function (stats) {
1217
+ expect(stats instanceof _display_utils.StatTimer).toEqual(true);
1218
+ expect(stats.times.length).toEqual(3);
1219
+
1220
+ var _stats$times2 = _slicedToArray(stats.times, 3),
1221
+ statEntryOne = _stats$times2[0],
1222
+ statEntryTwo = _stats$times2[1],
1223
+ statEntryThree = _stats$times2[2];
1224
+
1225
+ expect(statEntryOne.name).toEqual('Page Request');
1226
+ expect(statEntryOne.end - statEntryOne.start).toBeGreaterThan(0);
1227
+ expect(statEntryTwo.name).toEqual('Rendering');
1228
+ expect(statEntryTwo.end - statEntryTwo.start).toBeGreaterThan(0);
1229
+ expect(statEntryThree.name).toEqual('Overall');
1230
+ expect(statEntryThree.end - statEntryThree.start).toBeGreaterThan(0);
1231
+ CanvasFactory.destroy(canvasAndCtx);
1232
+ loadingTask.destroy().then(done);
1233
+ }, done.fail);
984
1234
  });
985
1235
  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);
1236
+ var viewport = page.getViewport({
1237
+ scale: 1
1238
+ });
990
1239
  var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
991
1240
  var renderTask = page.render({
992
1241
  canvasContext: canvasAndCtx.context,
1242
+ canvasFactory: CanvasFactory,
993
1243
  viewport: viewport
994
1244
  });
995
1245
  renderTask.cancel();
996
1246
  renderTask.promise.then(function () {
997
1247
  done.fail('shall cancel rendering');
998
- }).catch(function (error) {
999
- expect(error instanceof _dom_utils.RenderingCancelledException).toEqual(true);
1248
+ })["catch"](function (error) {
1249
+ expect(error instanceof _display_utils.RenderingCancelledException).toEqual(true);
1000
1250
  expect(error.type).toEqual('canvas');
1001
1251
  CanvasFactory.destroy(canvasAndCtx);
1002
1252
  done();
1003
1253
  });
1004
1254
  });
1255
+ it('re-render page, using the same canvas, after cancelling rendering', function (done) {
1256
+ var viewport = page.getViewport({
1257
+ scale: 1
1258
+ });
1259
+ var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
1260
+ var renderTask = page.render({
1261
+ canvasContext: canvasAndCtx.context,
1262
+ canvasFactory: CanvasFactory,
1263
+ viewport: viewport
1264
+ });
1265
+ renderTask.cancel();
1266
+ renderTask.promise.then(function () {
1267
+ throw new Error('shall cancel rendering');
1268
+ }, function (reason) {
1269
+ expect(reason instanceof _display_utils.RenderingCancelledException).toEqual(true);
1270
+ }).then(function () {
1271
+ var reRenderTask = page.render({
1272
+ canvasContext: canvasAndCtx.context,
1273
+ canvasFactory: CanvasFactory,
1274
+ viewport: viewport
1275
+ });
1276
+ return reRenderTask.promise;
1277
+ }).then(function () {
1278
+ CanvasFactory.destroy(canvasAndCtx);
1279
+ done();
1280
+ }, done.fail);
1281
+ });
1005
1282
  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);
1283
+ var viewport = page.getViewport({
1284
+ scale: 1
1285
+ });
1010
1286
  var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
1011
1287
  var renderTask1 = page.render({
1012
1288
  canvasContext: canvasAndCtx.context,
1289
+ canvasFactory: CanvasFactory,
1013
1290
  viewport: viewport
1014
1291
  });
1015
1292
  var renderTask2 = page.render({
1016
1293
  canvasContext: canvasAndCtx.context,
1294
+ canvasFactory: CanvasFactory,
1017
1295
  viewport: viewport
1018
1296
  });
1019
1297
  Promise.all([renderTask1.promise, renderTask2.promise.then(function () {
@@ -1028,41 +1306,66 @@ describe('api', function () {
1028
1306
  var pdf2 = (0, _test_utils.buildGetDocumentParams)('TAMReview.pdf');
1029
1307
  var pdf3 = (0, _test_utils.buildGetDocumentParams)('issue6068.pdf');
1030
1308
  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
- });
1309
+
1310
+ function renderPDF(_x) {
1311
+ return _renderPDF.apply(this, arguments);
1050
1312
  }
1313
+
1314
+ function _renderPDF() {
1315
+ _renderPDF = _asyncToGenerator(
1316
+ /*#__PURE__*/
1317
+ _regenerator["default"].mark(function _callee(filename) {
1318
+ var loadingTask, pdf, page, viewport, canvasAndCtx, renderTask, data;
1319
+ return _regenerator["default"].wrap(function _callee$(_context) {
1320
+ while (1) {
1321
+ switch (_context.prev = _context.next) {
1322
+ case 0:
1323
+ loadingTask = (0, _api.getDocument)(filename);
1324
+ loadingTasks.push(loadingTask);
1325
+ _context.next = 4;
1326
+ return loadingTask.promise;
1327
+
1328
+ case 4:
1329
+ pdf = _context.sent;
1330
+ _context.next = 7;
1331
+ return pdf.getPage(1);
1332
+
1333
+ case 7:
1334
+ page = _context.sent;
1335
+ viewport = page.getViewport({
1336
+ scale: 1.2
1337
+ });
1338
+ canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
1339
+ renderTask = page.render({
1340
+ canvasContext: canvasAndCtx.context,
1341
+ canvasFactory: CanvasFactory,
1342
+ viewport: viewport
1343
+ });
1344
+ _context.next = 13;
1345
+ return renderTask.promise;
1346
+
1347
+ case 13:
1348
+ data = canvasAndCtx.canvas.toDataURL();
1349
+ CanvasFactory.destroy(canvasAndCtx);
1350
+ return _context.abrupt("return", data);
1351
+
1352
+ case 16:
1353
+ case "end":
1354
+ return _context.stop();
1355
+ }
1356
+ }
1357
+ }, _callee);
1358
+ }));
1359
+ return _renderPDF.apply(this, arguments);
1360
+ }
1361
+
1051
1362
  afterEach(function (done) {
1052
- var destroyPromises = pdfDocuments.map(function (pdfDocument) {
1053
- return pdfDocument.destroy();
1054
- });
1055
- var destroyPromises2 = loadingTasks.map(function (loadingTask) {
1363
+ var destroyPromises = loadingTasks.map(function (loadingTask) {
1056
1364
  return loadingTask.destroy();
1057
1365
  });
1058
- Promise.all(destroyPromises.concat(destroyPromises2)).then(function () {
1059
- done();
1060
- });
1366
+ Promise.all(destroyPromises).then(done);
1061
1367
  });
1062
1368
  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
1369
  var baseline1, baseline2, baseline3;
1067
1370
  var promiseDone = renderPDF(pdf1).then(function (data1) {
1068
1371
  baseline1 = data1;
@@ -1081,42 +1384,37 @@ describe('api', function () {
1081
1384
  });
1082
1385
  promiseDone.then(function () {
1083
1386
  done();
1084
- }).catch(function (reason) {
1085
- done.fail(reason);
1086
- });
1387
+ })["catch"](done.fail);
1087
1388
  });
1088
1389
  });
1089
1390
  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;
1391
+ var dataPromise;
1392
+ beforeAll(function (done) {
1393
+ var fileName = 'tracemonkey.pdf';
1394
+
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
+ });
1095
1403
  }
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
- }
1404
+
1405
+ done();
1406
+ });
1407
+ afterAll(function () {
1408
+ dataPromise = null;
1409
+ });
1110
1410
  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
1411
  var initialDataLength = 4000;
1116
- var fetches = 0;
1117
- var getDocumentPromise = getDocumentData().then(function (data) {
1412
+ var fetches = 0,
1413
+ loadingTask;
1414
+ dataPromise.then(function (data) {
1118
1415
  var initialData = data.subarray(0, initialDataLength);
1119
- transport = new _api.PDFDataRangeTransport(data.length, initialData);
1416
+ var transport = new _api.PDFDataRangeTransport(data.length, initialData);
1417
+
1120
1418
  transport.requestDataRange = function (begin, end) {
1121
1419
  fetches++;
1122
1420
  waitSome(function () {
@@ -1124,60 +1422,74 @@ describe('api', function () {
1124
1422
  transport.onDataRange(begin, data.subarray(begin, end));
1125
1423
  });
1126
1424
  };
1127
- var loadingTask = (0, _api.getDocument)(transport);
1425
+
1426
+ loadingTask = (0, _api.getDocument)(transport);
1128
1427
  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) {
1428
+ }).then(function (pdfDocument) {
1137
1429
  expect(pdfDocument.numPages).toEqual(14);
1138
- expect(page.rotate).toEqual(0);
1430
+ return pdfDocument.getPage(10);
1431
+ }).then(function (pdfPage) {
1432
+ expect(pdfPage.rotate).toEqual(0);
1139
1433
  expect(fetches).toBeGreaterThan(2);
1140
- done();
1141
- }).catch(function (reason) {
1142
- done.fail(reason);
1143
- });
1434
+ loadingTask.destroy().then(done);
1435
+ })["catch"](done.fail);
1144
1436
  });
1145
1437
  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
1438
  var initialDataLength = 4000;
1151
- var fetches = 0;
1152
- var getDocumentPromise = getDocumentData().then(function (data) {
1439
+ var fetches = 0,
1440
+ loadingTask;
1441
+ dataPromise.then(function (data) {
1153
1442
  var initialData = data.subarray(0, initialDataLength);
1154
- transport = new _api.PDFDataRangeTransport(data.length, initialData);
1443
+ var transport = new _api.PDFDataRangeTransport(data.length, initialData);
1444
+
1155
1445
  transport.requestDataRange = function (begin, end) {
1156
1446
  fetches++;
1447
+
1157
1448
  if (fetches === 1) {
1158
1449
  transport.onDataProgressiveRead(data.subarray(initialDataLength));
1159
1450
  }
1451
+
1160
1452
  waitSome(function () {
1161
1453
  transport.onDataRange(begin, data.subarray(begin, end));
1162
1454
  });
1163
1455
  };
1164
- var loadingTask = (0, _api.getDocument)(transport);
1456
+
1457
+ loadingTask = (0, _api.getDocument)(transport);
1165
1458
  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) {
1459
+ }).then(function (pdfDocument) {
1174
1460
  expect(pdfDocument.numPages).toEqual(14);
1175
- expect(page.rotate).toEqual(0);
1461
+ return pdfDocument.getPage(10);
1462
+ }).then(function (pdfPage) {
1463
+ expect(pdfPage.rotate).toEqual(0);
1176
1464
  expect(fetches).toEqual(1);
1177
- done();
1178
- }).catch(function (reason) {
1179
- done.fail(reason);
1180
- });
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);
1181
1493
  });
1182
1494
  });
1183
1495
  });