|
@@ -2,7 +2,7 @@
|
|
* @licstart The following is the entire license notice for the
|
|
* @licstart The following is the entire license notice for the
|
|
* Javascript code in this page
|
|
* Javascript code in this page
|
|
*
|
|
*
|
|
- * Copyright 2018 Mozilla Foundation
|
|
|
|
|
|
+ * Copyright 2019 Mozilla Foundation
|
|
*
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -27,7 +27,7 @@ var _test_utils = require("./test_utils");
|
|
|
|
|
|
var _util = require("../../shared/util");
|
|
var _util = require("../../shared/util");
|
|
|
|
|
|
-var _dom_utils = require("../../display/dom_utils");
|
|
|
|
|
|
+var _display_utils = require("../../display/display_utils");
|
|
|
|
|
|
var _api = require("../../display/api");
|
|
var _api = require("../../display/api");
|
|
|
|
|
|
@@ -37,7 +37,7 @@ var _is_node = _interopRequireDefault(require("../../shared/is_node"));
|
|
|
|
|
|
var _metadata = require("../../display/metadata");
|
|
var _metadata = require("../../display/metadata");
|
|
|
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
|
|
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
|
|
|
|
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); } }
|
|
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); } }
|
|
|
|
|
|
@@ -59,10 +59,10 @@ describe('api', function () {
|
|
var basicApiGetDocumentParams = (0, _test_utils.buildGetDocumentParams)(basicApiFileName);
|
|
var basicApiGetDocumentParams = (0, _test_utils.buildGetDocumentParams)(basicApiFileName);
|
|
var CanvasFactory;
|
|
var CanvasFactory;
|
|
beforeAll(function (done) {
|
|
beforeAll(function (done) {
|
|
- if ((0, _is_node.default)()) {
|
|
|
|
|
|
+ if ((0, _is_node["default"])()) {
|
|
CanvasFactory = new _test_utils.NodeCanvasFactory();
|
|
CanvasFactory = new _test_utils.NodeCanvasFactory();
|
|
} else {
|
|
} else {
|
|
- CanvasFactory = new _dom_utils.DOMCanvasFactory();
|
|
|
|
|
|
+ CanvasFactory = new _display_utils.DOMCanvasFactory();
|
|
}
|
|
}
|
|
|
|
|
|
done();
|
|
done();
|
|
@@ -96,14 +96,14 @@ describe('api', function () {
|
|
expect(data[1] instanceof _api.PDFDocumentProxy).toEqual(true);
|
|
expect(data[1] instanceof _api.PDFDocumentProxy).toEqual(true);
|
|
expect(loadingTask).toEqual(data[1].loadingTask);
|
|
expect(loadingTask).toEqual(data[1].loadingTask);
|
|
loadingTask.destroy().then(done);
|
|
loadingTask.destroy().then(done);
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('creates pdf doc from URL and aborts before worker initialized', function (done) {
|
|
it('creates pdf doc from URL and aborts before worker initialized', function (done) {
|
|
var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
|
|
var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
|
|
var destroyed = loadingTask.destroy();
|
|
var destroyed = loadingTask.destroy();
|
|
loadingTask.promise.then(function (reason) {
|
|
loadingTask.promise.then(function (reason) {
|
|
done.fail('shall fail loading');
|
|
done.fail('shall fail loading');
|
|
- }).catch(function (reason) {
|
|
|
|
|
|
+ })["catch"](function (reason) {
|
|
expect(true).toEqual(true);
|
|
expect(true).toEqual(true);
|
|
destroyed.then(done);
|
|
destroyed.then(done);
|
|
});
|
|
});
|
|
@@ -118,59 +118,42 @@ describe('api', function () {
|
|
destroyed.then(function (data) {
|
|
destroyed.then(function (data) {
|
|
expect(true).toEqual(true);
|
|
expect(true).toEqual(true);
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('creates pdf doc from typed array', function (done) {
|
|
it('creates pdf doc from typed array', function (done) {
|
|
- var typedArrayPdf;
|
|
|
|
|
|
+ var typedArrayPdfPromise;
|
|
|
|
|
|
- if ((0, _is_node.default)()) {
|
|
|
|
- typedArrayPdf = _test_utils.NodeFileReaderFactory.fetch({
|
|
|
|
|
|
+ if ((0, _is_node["default"])()) {
|
|
|
|
+ typedArrayPdfPromise = _test_utils.NodeFileReaderFactory.fetch({
|
|
path: _test_utils.TEST_PDFS_PATH.node + basicApiFileName
|
|
path: _test_utils.TEST_PDFS_PATH.node + basicApiFileName
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
- var nonBinaryRequest = false;
|
|
|
|
- var request = new XMLHttpRequest();
|
|
|
|
- request.open('GET', _test_utils.TEST_PDFS_PATH.dom + basicApiFileName, false);
|
|
|
|
-
|
|
|
|
- try {
|
|
|
|
- request.responseType = 'arraybuffer';
|
|
|
|
- nonBinaryRequest = request.responseType !== 'arraybuffer';
|
|
|
|
- } catch (e) {
|
|
|
|
- nonBinaryRequest = true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (nonBinaryRequest && request.overrideMimeType) {
|
|
|
|
- request.overrideMimeType('text/plain; charset=x-user-defined');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- request.send(null);
|
|
|
|
-
|
|
|
|
- if (nonBinaryRequest) {
|
|
|
|
- typedArrayPdf = (0, _util.stringToBytes)(request.responseText);
|
|
|
|
- } else {
|
|
|
|
- typedArrayPdf = new Uint8Array(request.response);
|
|
|
|
- }
|
|
|
|
|
|
+ typedArrayPdfPromise = _test_utils.DOMFileReaderFactory.fetch({
|
|
|
|
+ path: _test_utils.TEST_PDFS_PATH.dom + basicApiFileName
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
- expect(typedArrayPdf.length).toEqual(basicApiFileLength);
|
|
|
|
- var loadingTask = (0, _api.getDocument)(typedArrayPdf);
|
|
|
|
- var progressReportedCapability = (0, _util.createPromiseCapability)();
|
|
|
|
|
|
+ typedArrayPdfPromise.then(function (typedArrayPdf) {
|
|
|
|
+ expect(typedArrayPdf.length).toEqual(basicApiFileLength);
|
|
|
|
+ var loadingTask = (0, _api.getDocument)(typedArrayPdf);
|
|
|
|
+ var progressReportedCapability = (0, _util.createPromiseCapability)();
|
|
|
|
|
|
- loadingTask.onProgress = function (data) {
|
|
|
|
- progressReportedCapability.resolve(data);
|
|
|
|
- };
|
|
|
|
|
|
+ loadingTask.onProgress = function (data) {
|
|
|
|
+ progressReportedCapability.resolve(data);
|
|
|
|
+ };
|
|
|
|
|
|
- Promise.all([loadingTask.promise, progressReportedCapability.promise]).then(function (data) {
|
|
|
|
- expect(data[0] instanceof _api.PDFDocumentProxy).toEqual(true);
|
|
|
|
- expect(data[1].loaded / data[1].total).toEqual(1);
|
|
|
|
- loadingTask.destroy().then(done);
|
|
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ return Promise.all([loadingTask.promise, progressReportedCapability.promise]).then(function (data) {
|
|
|
|
+ expect(data[0] instanceof _api.PDFDocumentProxy).toEqual(true);
|
|
|
|
+ expect(data[1].loaded / data[1].total).toEqual(1);
|
|
|
|
+ loadingTask.destroy().then(done);
|
|
|
|
+ });
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('creates pdf doc from invalid PDF file', function (done) {
|
|
it('creates pdf doc from invalid PDF file', function (done) {
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug1020226.pdf'));
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug1020226.pdf'));
|
|
loadingTask.promise.then(function () {
|
|
loadingTask.promise.then(function () {
|
|
done.fail('shall fail loading');
|
|
done.fail('shall fail loading');
|
|
- }).catch(function (error) {
|
|
|
|
|
|
+ })["catch"](function (error) {
|
|
expect(error instanceof _util.InvalidPDFException).toEqual(true);
|
|
expect(error instanceof _util.InvalidPDFException).toEqual(true);
|
|
loadingTask.destroy().then(done);
|
|
loadingTask.destroy().then(done);
|
|
});
|
|
});
|
|
@@ -179,7 +162,7 @@ describe('api', function () {
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('non-existent.pdf'));
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('non-existent.pdf'));
|
|
loadingTask.promise.then(function (error) {
|
|
loadingTask.promise.then(function (error) {
|
|
done.fail('shall fail loading');
|
|
done.fail('shall fail loading');
|
|
- }).catch(function (error) {
|
|
|
|
|
|
+ })["catch"](function (error) {
|
|
expect(error instanceof _util.MissingPDFException).toEqual(true);
|
|
expect(error instanceof _util.MissingPDFException).toEqual(true);
|
|
loadingTask.destroy().then(done);
|
|
loadingTask.destroy().then(done);
|
|
});
|
|
});
|
|
@@ -209,7 +192,7 @@ describe('api', function () {
|
|
Promise.all(promises).then(function (data) {
|
|
Promise.all(promises).then(function (data) {
|
|
expect(data[2] instanceof _api.PDFDocumentProxy).toEqual(true);
|
|
expect(data[2] instanceof _api.PDFDocumentProxy).toEqual(true);
|
|
loadingTask.destroy().then(done);
|
|
loadingTask.destroy().then(done);
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('creates pdf doc from PDF file protected with only a user password', function (done) {
|
|
it('creates pdf doc from PDF file protected with only a user password', function (done) {
|
|
var filename = 'pr6531_2.pdf';
|
|
var filename = 'pr6531_2.pdf';
|
|
@@ -244,7 +227,7 @@ describe('api', function () {
|
|
});
|
|
});
|
|
Promise.all([result1, result2, result3]).then(function () {
|
|
Promise.all([result1, result2, result3]).then(function () {
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('creates pdf doc from password protected PDF file and aborts/throws ' + 'in the onPassword callback (issue 7806)', function (done) {
|
|
it('creates pdf doc from password protected PDF file and aborts/throws ' + 'in the onPassword callback (issue 7806)', function (done) {
|
|
var filename = 'issue3371.pdf';
|
|
var filename = 'issue3371.pdf';
|
|
@@ -290,12 +273,12 @@ describe('api', function () {
|
|
});
|
|
});
|
|
Promise.all([result1, result2]).then(function () {
|
|
Promise.all([result1, result2]).then(function () {
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
describe('PDFWorker', function () {
|
|
describe('PDFWorker', function () {
|
|
it('worker created or destroyed', function (done) {
|
|
it('worker created or destroyed', function (done) {
|
|
- if ((0, _is_node.default)()) {
|
|
|
|
|
|
+ if ((0, _is_node["default"])()) {
|
|
pending('Worker is not supported in Node.js.');
|
|
pending('Worker is not supported in Node.js.');
|
|
}
|
|
}
|
|
|
|
|
|
@@ -312,10 +295,10 @@ describe('api', function () {
|
|
expect(!!worker.port).toEqual(false);
|
|
expect(!!worker.port).toEqual(false);
|
|
expect(worker.destroyed).toEqual(true);
|
|
expect(worker.destroyed).toEqual(true);
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('worker created or destroyed by getDocument', function (done) {
|
|
it('worker created or destroyed by getDocument', function (done) {
|
|
- if ((0, _is_node.default)()) {
|
|
|
|
|
|
+ if ((0, _is_node["default"])()) {
|
|
pending('Worker is not supported in Node.js.');
|
|
pending('Worker is not supported in Node.js.');
|
|
}
|
|
}
|
|
|
|
|
|
@@ -333,10 +316,10 @@ describe('api', function () {
|
|
expect(!!destroyedWorker).toEqual(false);
|
|
expect(!!destroyedWorker).toEqual(false);
|
|
expect(worker.destroyed).toEqual(true);
|
|
expect(worker.destroyed).toEqual(true);
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('worker created and can be used in getDocument', function (done) {
|
|
it('worker created and can be used in getDocument', function (done) {
|
|
- if ((0, _is_node.default)()) {
|
|
|
|
|
|
+ if ((0, _is_node["default"])()) {
|
|
pending('Worker is not supported in Node.js.');
|
|
pending('Worker is not supported in Node.js.');
|
|
}
|
|
}
|
|
|
|
|
|
@@ -359,10 +342,10 @@ describe('api', function () {
|
|
expect(worker.destroyed).toEqual(false);
|
|
expect(worker.destroyed).toEqual(false);
|
|
worker.destroy();
|
|
worker.destroy();
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('creates more than one worker', function (done) {
|
|
it('creates more than one worker', function (done) {
|
|
- if ((0, _is_node.default)()) {
|
|
|
|
|
|
+ if ((0, _is_node["default"])()) {
|
|
pending('Worker is not supported in Node.js.');
|
|
pending('Worker is not supported in Node.js.');
|
|
}
|
|
}
|
|
|
|
|
|
@@ -382,10 +365,10 @@ describe('api', function () {
|
|
worker2.destroy();
|
|
worker2.destroy();
|
|
worker3.destroy();
|
|
worker3.destroy();
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets current workerSrc', function () {
|
|
it('gets current workerSrc', function () {
|
|
- if ((0, _is_node.default)()) {
|
|
|
|
|
|
+ if ((0, _is_node["default"])()) {
|
|
pending('Worker is not supported in Node.js.');
|
|
pending('Worker is not supported in Node.js.');
|
|
}
|
|
}
|
|
|
|
|
|
@@ -422,7 +405,7 @@ describe('api', function () {
|
|
expect(data instanceof _api.PDFPageProxy).toEqual(true);
|
|
expect(data instanceof _api.PDFPageProxy).toEqual(true);
|
|
expect(data.pageIndex).toEqual(0);
|
|
expect(data.pageIndex).toEqual(0);
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets non-existent page', function (done) {
|
|
it('gets non-existent page', function (done) {
|
|
var outOfRangePromise = doc.getPage(100);
|
|
var outOfRangePromise = doc.getPage(100);
|
|
@@ -445,7 +428,7 @@ describe('api', function () {
|
|
});
|
|
});
|
|
Promise.all([outOfRangePromise, nonIntegerPromise, nonNumberPromise]).then(function () {
|
|
Promise.all([outOfRangePromise, nonIntegerPromise, nonNumberPromise]).then(function () {
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets page index', function (done) {
|
|
it('gets page index', function (done) {
|
|
var ref = {
|
|
var ref = {
|
|
@@ -456,7 +439,7 @@ describe('api', function () {
|
|
promise.then(function (pageIndex) {
|
|
promise.then(function (pageIndex) {
|
|
expect(pageIndex).toEqual(1);
|
|
expect(pageIndex).toEqual(1);
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets invalid page index', function (done) {
|
|
it('gets invalid page index', function (done) {
|
|
var ref = {
|
|
var ref = {
|
|
@@ -466,7 +449,7 @@ describe('api', function () {
|
|
var promise = doc.getPageIndex(ref);
|
|
var promise = doc.getPageIndex(ref);
|
|
promise.then(function () {
|
|
promise.then(function () {
|
|
done.fail('shall fail for invalid page reference.');
|
|
done.fail('shall fail for invalid page reference.');
|
|
- }).catch(function (reason) {
|
|
|
|
|
|
+ })["catch"](function (reason) {
|
|
expect(reason instanceof Error).toEqual(true);
|
|
expect(reason instanceof Error).toEqual(true);
|
|
done();
|
|
done();
|
|
});
|
|
});
|
|
@@ -483,7 +466,7 @@ describe('api', function () {
|
|
}, 0, 841.89, null]
|
|
}, 0, 841.89, null]
|
|
});
|
|
});
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets a destination, from /Dests dictionary', function (done) {
|
|
it('gets a destination, from /Dests dictionary', function (done) {
|
|
var promise = doc.getDestination('chapter1');
|
|
var promise = doc.getDestination('chapter1');
|
|
@@ -495,14 +478,14 @@ describe('api', function () {
|
|
name: 'XYZ'
|
|
name: 'XYZ'
|
|
}, 0, 841.89, null]);
|
|
}, 0, 841.89, null]);
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets a non-existent destination, from /Dests dictionary', function (done) {
|
|
it('gets a non-existent destination, from /Dests dictionary', function (done) {
|
|
var promise = doc.getDestination('non-existent-named-destination');
|
|
var promise = doc.getDestination('non-existent-named-destination');
|
|
promise.then(function (data) {
|
|
promise.then(function (data) {
|
|
expect(data).toEqual(null);
|
|
expect(data).toEqual(null);
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets destinations, from /Names (NameTree) dictionary', function (done) {
|
|
it('gets destinations, from /Names (NameTree) dictionary', function (done) {
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
|
|
@@ -525,7 +508,7 @@ describe('api', function () {
|
|
}, 0, 375, null]
|
|
}, 0, 375, null]
|
|
});
|
|
});
|
|
loadingTask.destroy().then(done);
|
|
loadingTask.destroy().then(done);
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets a destination, from /Names (NameTree) dictionary', function (done) {
|
|
it('gets a destination, from /Names (NameTree) dictionary', function (done) {
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
|
|
@@ -540,7 +523,7 @@ describe('api', function () {
|
|
name: 'XYZ'
|
|
name: 'XYZ'
|
|
}, 0, 375, null]);
|
|
}, 0, 375, null]);
|
|
loadingTask.destroy().then(done);
|
|
loadingTask.destroy().then(done);
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets a non-existent destination, from /Names (NameTree) dictionary', function (done) {
|
|
it('gets a non-existent destination, from /Names (NameTree) dictionary', function (done) {
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
|
|
@@ -550,7 +533,7 @@ describe('api', function () {
|
|
promise.then(function (destination) {
|
|
promise.then(function (destination) {
|
|
expect(destination).toEqual(null);
|
|
expect(destination).toEqual(null);
|
|
loadingTask.destroy().then(done);
|
|
loadingTask.destroy().then(done);
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets non-string destination', function (done) {
|
|
it('gets non-string destination', function (done) {
|
|
var numberPromise = doc.getDestination(4.3);
|
|
var numberPromise = doc.getDestination(4.3);
|
|
@@ -583,7 +566,7 @@ describe('api', function () {
|
|
promise.then(function (data) {
|
|
promise.then(function (data) {
|
|
expect(data).toEqual(null);
|
|
expect(data).toEqual(null);
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets page labels', function (done) {
|
|
it('gets page labels', function (done) {
|
|
var loadingTask0 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug793632.pdf'));
|
|
var loadingTask0 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug793632.pdf'));
|
|
@@ -608,7 +591,22 @@ describe('api', function () {
|
|
expect(pageLabels[2]).toEqual(['1', '2']);
|
|
expect(pageLabels[2]).toEqual(['1', '2']);
|
|
expect(pageLabels[3]).toEqual(['X3']);
|
|
expect(pageLabels[3]).toEqual(['X3']);
|
|
Promise.all([loadingTask0.destroy(), loadingTask1.destroy(), loadingTask2.destroy(), loadingTask3.destroy()]).then(done);
|
|
Promise.all([loadingTask0.destroy(), loadingTask1.destroy(), loadingTask2.destroy(), loadingTask3.destroy()]).then(done);
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
|
|
+ });
|
|
|
|
+ it('gets default page layout', function (done) {
|
|
|
|
+ var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
|
|
|
|
+ loadingTask.promise.then(function (pdfDocument) {
|
|
|
|
+ return pdfDocument.getPageLayout();
|
|
|
|
+ }).then(function (mode) {
|
|
|
|
+ expect(mode).toEqual('');
|
|
|
|
+ loadingTask.destroy().then(done);
|
|
|
|
+ })["catch"](done.fail);
|
|
|
|
+ });
|
|
|
|
+ it('gets non-default page layout', function (done) {
|
|
|
|
+ doc.getPageLayout().then(function (mode) {
|
|
|
|
+ expect(mode).toEqual('SinglePage');
|
|
|
|
+ done();
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets default page mode', function (done) {
|
|
it('gets default page mode', function (done) {
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
|
|
@@ -617,13 +615,30 @@ describe('api', function () {
|
|
}).then(function (mode) {
|
|
}).then(function (mode) {
|
|
expect(mode).toEqual('UseNone');
|
|
expect(mode).toEqual('UseNone');
|
|
loadingTask.destroy().then(done);
|
|
loadingTask.destroy().then(done);
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets non-default page mode', function (done) {
|
|
it('gets non-default page mode', function (done) {
|
|
doc.getPageMode().then(function (mode) {
|
|
doc.getPageMode().then(function (mode) {
|
|
expect(mode).toEqual('UseOutlines');
|
|
expect(mode).toEqual('UseOutlines');
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
|
|
+ });
|
|
|
|
+ it('gets default viewer preferences', function (done) {
|
|
|
|
+ var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
|
|
|
|
+ loadingTask.promise.then(function (pdfDocument) {
|
|
|
|
+ return pdfDocument.getViewerPreferences();
|
|
|
|
+ }).then(function (prefs) {
|
|
|
|
+ expect(_typeof(prefs) === 'object' && prefs !== null && (0, _util.isEmptyObj)(prefs)).toEqual(true);
|
|
|
|
+ loadingTask.destroy().then(done);
|
|
|
|
+ })["catch"](done.fail);
|
|
|
|
+ });
|
|
|
|
+ it('gets non-default viewer preferences', function (done) {
|
|
|
|
+ doc.getViewerPreferences().then(function (prefs) {
|
|
|
|
+ expect(prefs).toEqual({
|
|
|
|
+ Direction: 'L2R'
|
|
|
|
+ });
|
|
|
|
+ done();
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets default open action destination', function (done) {
|
|
it('gets default open action destination', function (done) {
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
|
|
@@ -632,7 +647,7 @@ describe('api', function () {
|
|
}).then(function (dest) {
|
|
}).then(function (dest) {
|
|
expect(dest).toEqual(null);
|
|
expect(dest).toEqual(null);
|
|
loadingTask.destroy().then(done);
|
|
loadingTask.destroy().then(done);
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets non-default open action destination', function (done) {
|
|
it('gets non-default open action destination', function (done) {
|
|
doc.getOpenActionDestination().then(function (dest) {
|
|
doc.getOpenActionDestination().then(function (dest) {
|
|
@@ -643,17 +658,17 @@ describe('api', function () {
|
|
name: 'FitH'
|
|
name: 'FitH'
|
|
}, null]);
|
|
}, null]);
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets non-existent attachments', function (done) {
|
|
it('gets non-existent attachments', function (done) {
|
|
var promise = doc.getAttachments();
|
|
var promise = doc.getAttachments();
|
|
promise.then(function (data) {
|
|
promise.then(function (data) {
|
|
expect(data).toEqual(null);
|
|
expect(data).toEqual(null);
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets attachments', function (done) {
|
|
it('gets attachments', function (done) {
|
|
- if ((0, _is_node.default)()) {
|
|
|
|
|
|
+ if ((0, _is_node["default"])()) {
|
|
pending('TODO: Use a non-linked test-case.');
|
|
pending('TODO: Use a non-linked test-case.');
|
|
}
|
|
}
|
|
|
|
|
|
@@ -667,14 +682,14 @@ describe('api', function () {
|
|
expect(attachment.content instanceof Uint8Array).toBeTruthy();
|
|
expect(attachment.content instanceof Uint8Array).toBeTruthy();
|
|
expect(attachment.content.length).toEqual(30098);
|
|
expect(attachment.content.length).toEqual(30098);
|
|
loadingTask.destroy().then(done);
|
|
loadingTask.destroy().then(done);
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets javascript', function (done) {
|
|
it('gets javascript', function (done) {
|
|
var promise = doc.getJavaScript();
|
|
var promise = doc.getJavaScript();
|
|
promise.then(function (data) {
|
|
promise.then(function (data) {
|
|
expect(data).toEqual(null);
|
|
expect(data).toEqual(null);
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
var viewerPrintRegExp = /\bprint\s*\(/;
|
|
var viewerPrintRegExp = /\bprint\s*\(/;
|
|
it('gets javascript with printing instructions (Print action)', function (done) {
|
|
it('gets javascript with printing instructions (Print action)', function (done) {
|
|
@@ -686,7 +701,7 @@ describe('api', function () {
|
|
expect(data).toEqual(['print({});']);
|
|
expect(data).toEqual(['print({});']);
|
|
expect(data[0]).toMatch(viewerPrintRegExp);
|
|
expect(data[0]).toMatch(viewerPrintRegExp);
|
|
loadingTask.destroy().then(done);
|
|
loadingTask.destroy().then(done);
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets javascript with printing instructions (JS action)', function (done) {
|
|
it('gets javascript with printing instructions (JS action)', function (done) {
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6106.pdf'));
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6106.pdf'));
|
|
@@ -697,7 +712,7 @@ describe('api', function () {
|
|
expect(data).toEqual(['this.print({bUI:true,bSilent:false,bShrinkToFit:true});']);
|
|
expect(data).toEqual(['this.print({bUI:true,bSilent:false,bShrinkToFit:true});']);
|
|
expect(data[0]).toMatch(viewerPrintRegExp);
|
|
expect(data[0]).toMatch(viewerPrintRegExp);
|
|
loadingTask.destroy().then(done);
|
|
loadingTask.destroy().then(done);
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets non-existent outline', function (done) {
|
|
it('gets non-existent outline', function (done) {
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
|
|
@@ -707,7 +722,7 @@ describe('api', function () {
|
|
promise.then(function (outline) {
|
|
promise.then(function (outline) {
|
|
expect(outline).toEqual(null);
|
|
expect(outline).toEqual(null);
|
|
loadingTask.destroy().then(done);
|
|
loadingTask.destroy().then(done);
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets outline', function (done) {
|
|
it('gets outline', function (done) {
|
|
var promise = doc.getOutline();
|
|
var promise = doc.getOutline();
|
|
@@ -726,7 +741,7 @@ describe('api', function () {
|
|
expect(outlineItem.items.length).toEqual(1);
|
|
expect(outlineItem.items.length).toEqual(1);
|
|
expect(outlineItem.items[0].title).toEqual('Paragraph 1.1');
|
|
expect(outlineItem.items[0].title).toEqual('Paragraph 1.1');
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets outline containing a url', function (done) {
|
|
it('gets outline containing a url', function (done) {
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue3214.pdf'));
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue3214.pdf'));
|
|
@@ -746,13 +761,13 @@ describe('api', function () {
|
|
expect(outlineItemOne.color).toEqual(new Uint8ClampedArray([0, 0, 0]));
|
|
expect(outlineItemOne.color).toEqual(new Uint8ClampedArray([0, 0, 0]));
|
|
loadingTask.destroy().then(done);
|
|
loadingTask.destroy().then(done);
|
|
});
|
|
});
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets non-existent permissions', function (done) {
|
|
it('gets non-existent permissions', function (done) {
|
|
doc.getPermissions().then(function (permissions) {
|
|
doc.getPermissions().then(function (permissions) {
|
|
expect(permissions).toEqual(null);
|
|
expect(permissions).toEqual(null);
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets permissions', function (done) {
|
|
it('gets permissions', function (done) {
|
|
var loadingTask0 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue9972-1.pdf'));
|
|
var loadingTask0 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue9972-1.pdf'));
|
|
@@ -777,7 +792,7 @@ describe('api', function () {
|
|
expect(permissions[2].length).toEqual(totalPermissionCount - 1);
|
|
expect(permissions[2].length).toEqual(totalPermissionCount - 1);
|
|
expect(permissions[2].includes(_util.PermissionFlag.COPY)).toBeFalsy();
|
|
expect(permissions[2].includes(_util.PermissionFlag.COPY)).toBeFalsy();
|
|
Promise.all([loadingTask0.destroy(), loadingTask1.destroy(), loadingTask2.destroy()]).then(done);
|
|
Promise.all([loadingTask0.destroy(), loadingTask1.destroy(), loadingTask2.destroy()]).then(done);
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets metadata', function (done) {
|
|
it('gets metadata', function (done) {
|
|
var promise = doc.getMetadata();
|
|
var promise = doc.getMetadata();
|
|
@@ -791,11 +806,12 @@ describe('api', function () {
|
|
expect(info['IsLinearized']).toEqual(false);
|
|
expect(info['IsLinearized']).toEqual(false);
|
|
expect(info['IsAcroFormPresent']).toEqual(false);
|
|
expect(info['IsAcroFormPresent']).toEqual(false);
|
|
expect(info['IsXFAPresent']).toEqual(false);
|
|
expect(info['IsXFAPresent']).toEqual(false);
|
|
|
|
+ expect(info['IsCollectionPresent']).toEqual(false);
|
|
expect(metadata instanceof _metadata.Metadata).toEqual(true);
|
|
expect(metadata instanceof _metadata.Metadata).toEqual(true);
|
|
expect(metadata.get('dc:title')).toEqual('Basic API Test');
|
|
expect(metadata.get('dc:title')).toEqual('Basic API Test');
|
|
expect(contentDispositionFilename).toEqual(null);
|
|
expect(contentDispositionFilename).toEqual(null);
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets metadata, with custom info dict entries', function (done) {
|
|
it('gets metadata, with custom info dict entries', function (done) {
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
|
|
@@ -815,10 +831,11 @@ describe('api', function () {
|
|
expect(info['IsLinearized']).toEqual(false);
|
|
expect(info['IsLinearized']).toEqual(false);
|
|
expect(info['IsAcroFormPresent']).toEqual(false);
|
|
expect(info['IsAcroFormPresent']).toEqual(false);
|
|
expect(info['IsXFAPresent']).toEqual(false);
|
|
expect(info['IsXFAPresent']).toEqual(false);
|
|
|
|
+ expect(info['IsCollectionPresent']).toEqual(false);
|
|
expect(metadata).toEqual(null);
|
|
expect(metadata).toEqual(null);
|
|
expect(contentDispositionFilename).toEqual(null);
|
|
expect(contentDispositionFilename).toEqual(null);
|
|
loadingTask.destroy().then(done);
|
|
loadingTask.destroy().then(done);
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets data', function (done) {
|
|
it('gets data', function (done) {
|
|
var promise = doc.getData();
|
|
var promise = doc.getData();
|
|
@@ -826,7 +843,7 @@ describe('api', function () {
|
|
expect(data instanceof Uint8Array).toEqual(true);
|
|
expect(data instanceof Uint8Array).toEqual(true);
|
|
expect(data.length).toEqual(basicApiFileLength);
|
|
expect(data.length).toEqual(basicApiFileLength);
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets download info', function (done) {
|
|
it('gets download info', function (done) {
|
|
var promise = doc.getDownloadInfo();
|
|
var promise = doc.getDownloadInfo();
|
|
@@ -835,7 +852,7 @@ describe('api', function () {
|
|
length: basicApiFileLength
|
|
length: basicApiFileLength
|
|
});
|
|
});
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets document stats', function (done) {
|
|
it('gets document stats', function (done) {
|
|
var promise = doc.getStats();
|
|
var promise = doc.getStats();
|
|
@@ -845,7 +862,7 @@ describe('api', function () {
|
|
fontTypes: []
|
|
fontTypes: []
|
|
});
|
|
});
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('checks that fingerprints are unique', function (done) {
|
|
it('checks that fingerprints are unique', function (done) {
|
|
var loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue4436r.pdf'));
|
|
var loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue4436r.pdf'));
|
|
@@ -860,13 +877,13 @@ describe('api', function () {
|
|
expect(fingerprint2.length > 0).toEqual(true);
|
|
expect(fingerprint2.length > 0).toEqual(true);
|
|
expect(fingerprint1).not.toEqual(fingerprint2);
|
|
expect(fingerprint1).not.toEqual(fingerprint2);
|
|
Promise.all([loadingTask1.destroy(), loadingTask2.destroy()]).then(done);
|
|
Promise.all([loadingTask1.destroy(), loadingTask2.destroy()]).then(done);
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
describe('Cross-origin', function () {
|
|
describe('Cross-origin', function () {
|
|
var loadingTask;
|
|
var loadingTask;
|
|
|
|
|
|
function _checkCanLoad(expectSuccess, filename, options) {
|
|
function _checkCanLoad(expectSuccess, filename, options) {
|
|
- if ((0, _is_node.default)()) {
|
|
|
|
|
|
+ if ((0, _is_node["default"])()) {
|
|
pending('Cannot simulate cross-origin requests in Node.js');
|
|
pending('Cannot simulate cross-origin requests in Node.js');
|
|
}
|
|
}
|
|
|
|
|
|
@@ -905,7 +922,7 @@ describe('api', function () {
|
|
}
|
|
}
|
|
|
|
|
|
afterEach(function (done) {
|
|
afterEach(function (done) {
|
|
- if (loadingTask) {
|
|
|
|
|
|
+ if (loadingTask && !loadingTask.destroyed) {
|
|
loadingTask.destroy().then(done);
|
|
loadingTask.destroy().then(done);
|
|
} else {
|
|
} else {
|
|
done();
|
|
done();
|
|
@@ -950,7 +967,7 @@ describe('api', function () {
|
|
page = data;
|
|
page = data;
|
|
done();
|
|
done();
|
|
});
|
|
});
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
afterAll(function (done) {
|
|
afterAll(function (done) {
|
|
loadingTask.destroy().then(done);
|
|
loadingTask.destroy().then(done);
|
|
@@ -1020,7 +1037,7 @@ describe('api', function () {
|
|
});
|
|
});
|
|
Promise.all([defaultPromise, displayPromise, printPromise]).then(function () {
|
|
Promise.all([defaultPromise, displayPromise, printPromise]).then(function () {
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets annotations containing relative URLs (bug 766086)', function (done) {
|
|
it('gets annotations containing relative URLs (bug 766086)', function (done) {
|
|
var filename = 'bug766086.pdf';
|
|
var filename = 'bug766086.pdf';
|
|
@@ -1057,7 +1074,7 @@ describe('api', function () {
|
|
expect(invalidDocBaseUrlAnnotations[0].url).toBeUndefined();
|
|
expect(invalidDocBaseUrlAnnotations[0].url).toBeUndefined();
|
|
expect(invalidDocBaseUrlAnnotations[0].unsafeUrl).toEqual('../../0021/002156/215675E.pdf#15');
|
|
expect(invalidDocBaseUrlAnnotations[0].unsafeUrl).toEqual('../../0021/002156/215675E.pdf#15');
|
|
Promise.all([defaultLoadingTask.destroy(), docBaseUrlLoadingTask.destroy(), invalidDocBaseUrlLoadingTask.destroy()]).then(done);
|
|
Promise.all([defaultLoadingTask.destroy(), docBaseUrlLoadingTask.destroy(), invalidDocBaseUrlLoadingTask.destroy()]).then(done);
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets text content', function (done) {
|
|
it('gets text content', function (done) {
|
|
var defaultPromise = page.getTextContent();
|
|
var defaultPromise = page.getTextContent();
|
|
@@ -1072,7 +1089,7 @@ describe('api', function () {
|
|
expect(!!data[0].styles).toEqual(true);
|
|
expect(!!data[0].styles).toEqual(true);
|
|
expect(JSON.stringify(data[0])).toEqual(JSON.stringify(data[1]));
|
|
expect(JSON.stringify(data[0])).toEqual(JSON.stringify(data[1]));
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets text content, with correct properties (issue 8276)', function (done) {
|
|
it('gets text content, with correct properties (issue 8276)', function (done) {
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue8276_reduced.pdf'));
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue8276_reduced.pdf'));
|
|
@@ -1100,7 +1117,7 @@ describe('api', function () {
|
|
loadingTask.destroy().then(done);
|
|
loadingTask.destroy().then(done);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets operator list', function (done) {
|
|
it('gets operator list', function (done) {
|
|
var promise = page.getOperatorList();
|
|
var promise = page.getOperatorList();
|
|
@@ -1109,7 +1126,7 @@ describe('api', function () {
|
|
expect(!!oplist.argsArray).toEqual(true);
|
|
expect(!!oplist.argsArray).toEqual(true);
|
|
expect(oplist.lastChunk).toEqual(true);
|
|
expect(oplist.lastChunk).toEqual(true);
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets operatorList with JPEG image (issue 4888)', function (done) {
|
|
it('gets operatorList with JPEG image (issue 4888)', function (done) {
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('cmykjpeg.pdf'));
|
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('cmykjpeg.pdf'));
|
|
@@ -1127,7 +1144,7 @@ describe('api', function () {
|
|
loadingTask.destroy().then(done);
|
|
loadingTask.destroy().then(done);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets document stats after parsing page', function (done) {
|
|
it('gets document stats after parsing page', function (done) {
|
|
var promise = page.getOperatorList().then(function () {
|
|
var promise = page.getOperatorList().then(function () {
|
|
@@ -1144,7 +1161,7 @@ describe('api', function () {
|
|
fontTypes: expectedFontTypes
|
|
fontTypes: expectedFontTypes
|
|
});
|
|
});
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('gets page stats after parsing page, without `pdfBug` set', function (done) {
|
|
it('gets page stats after parsing page, without `pdfBug` set', function (done) {
|
|
page.getOperatorList().then(function (opList) {
|
|
page.getOperatorList().then(function (opList) {
|
|
@@ -1165,7 +1182,7 @@ describe('api', function () {
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}).then(function (stats) {
|
|
}).then(function (stats) {
|
|
- expect(stats instanceof _dom_utils.StatTimer).toEqual(true);
|
|
|
|
|
|
+ expect(stats instanceof _display_utils.StatTimer).toEqual(true);
|
|
expect(stats.times.length).toEqual(1);
|
|
expect(stats.times.length).toEqual(1);
|
|
|
|
|
|
var _stats$times = _slicedToArray(stats.times, 1),
|
|
var _stats$times = _slicedToArray(stats.times, 1),
|
|
@@ -1197,7 +1214,7 @@ describe('api', function () {
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}).then(function (stats) {
|
|
}).then(function (stats) {
|
|
- expect(stats instanceof _dom_utils.StatTimer).toEqual(true);
|
|
|
|
|
|
+ expect(stats instanceof _display_utils.StatTimer).toEqual(true);
|
|
expect(stats.times.length).toEqual(3);
|
|
expect(stats.times.length).toEqual(3);
|
|
|
|
|
|
var _stats$times2 = _slicedToArray(stats.times, 3),
|
|
var _stats$times2 = _slicedToArray(stats.times, 3),
|
|
@@ -1228,8 +1245,8 @@ describe('api', function () {
|
|
renderTask.cancel();
|
|
renderTask.cancel();
|
|
renderTask.promise.then(function () {
|
|
renderTask.promise.then(function () {
|
|
done.fail('shall cancel rendering');
|
|
done.fail('shall cancel rendering');
|
|
- }).catch(function (error) {
|
|
|
|
- expect(error instanceof _dom_utils.RenderingCancelledException).toEqual(true);
|
|
|
|
|
|
+ })["catch"](function (error) {
|
|
|
|
+ expect(error instanceof _display_utils.RenderingCancelledException).toEqual(true);
|
|
expect(error.type).toEqual('canvas');
|
|
expect(error.type).toEqual('canvas');
|
|
CanvasFactory.destroy(canvasAndCtx);
|
|
CanvasFactory.destroy(canvasAndCtx);
|
|
done();
|
|
done();
|
|
@@ -1249,7 +1266,7 @@ describe('api', function () {
|
|
renderTask.promise.then(function () {
|
|
renderTask.promise.then(function () {
|
|
throw new Error('shall cancel rendering');
|
|
throw new Error('shall cancel rendering');
|
|
}, function (reason) {
|
|
}, function (reason) {
|
|
- expect(reason instanceof _dom_utils.RenderingCancelledException).toEqual(true);
|
|
|
|
|
|
+ expect(reason instanceof _display_utils.RenderingCancelledException).toEqual(true);
|
|
}).then(function () {
|
|
}).then(function () {
|
|
var reRenderTask = page.render({
|
|
var reRenderTask = page.render({
|
|
canvasContext: canvasAndCtx.context,
|
|
canvasContext: canvasAndCtx.context,
|
|
@@ -1289,7 +1306,6 @@ describe('api', function () {
|
|
var pdf2 = (0, _test_utils.buildGetDocumentParams)('TAMReview.pdf');
|
|
var pdf2 = (0, _test_utils.buildGetDocumentParams)('TAMReview.pdf');
|
|
var pdf3 = (0, _test_utils.buildGetDocumentParams)('issue6068.pdf');
|
|
var pdf3 = (0, _test_utils.buildGetDocumentParams)('issue6068.pdf');
|
|
var loadingTasks = [];
|
|
var loadingTasks = [];
|
|
- var pdfDocuments = [];
|
|
|
|
|
|
|
|
function renderPDF(_x) {
|
|
function renderPDF(_x) {
|
|
return _renderPDF.apply(this, arguments);
|
|
return _renderPDF.apply(this, arguments);
|
|
@@ -1298,9 +1314,9 @@ describe('api', function () {
|
|
function _renderPDF() {
|
|
function _renderPDF() {
|
|
_renderPDF = _asyncToGenerator(
|
|
_renderPDF = _asyncToGenerator(
|
|
/*#__PURE__*/
|
|
/*#__PURE__*/
|
|
- _regenerator.default.mark(function _callee(filename) {
|
|
|
|
|
|
+ _regenerator["default"].mark(function _callee(filename) {
|
|
var loadingTask, pdf, page, viewport, canvasAndCtx, renderTask, data;
|
|
var loadingTask, pdf, page, viewport, canvasAndCtx, renderTask, data;
|
|
- return _regenerator.default.wrap(function _callee$(_context) {
|
|
|
|
|
|
+ return _regenerator["default"].wrap(function _callee$(_context) {
|
|
while (1) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
case 0:
|
|
@@ -1311,11 +1327,10 @@ describe('api', function () {
|
|
|
|
|
|
case 4:
|
|
case 4:
|
|
pdf = _context.sent;
|
|
pdf = _context.sent;
|
|
- pdfDocuments.push(pdf);
|
|
|
|
- _context.next = 8;
|
|
|
|
|
|
+ _context.next = 7;
|
|
return pdf.getPage(1);
|
|
return pdf.getPage(1);
|
|
|
|
|
|
- case 8:
|
|
|
|
|
|
+ case 7:
|
|
page = _context.sent;
|
|
page = _context.sent;
|
|
viewport = page.getViewport({
|
|
viewport = page.getViewport({
|
|
scale: 1.2
|
|
scale: 1.2
|
|
@@ -1326,34 +1341,29 @@ describe('api', function () {
|
|
canvasFactory: CanvasFactory,
|
|
canvasFactory: CanvasFactory,
|
|
viewport: viewport
|
|
viewport: viewport
|
|
});
|
|
});
|
|
- _context.next = 14;
|
|
|
|
|
|
+ _context.next = 13;
|
|
return renderTask.promise;
|
|
return renderTask.promise;
|
|
|
|
|
|
- case 14:
|
|
|
|
|
|
+ case 13:
|
|
data = canvasAndCtx.canvas.toDataURL();
|
|
data = canvasAndCtx.canvas.toDataURL();
|
|
CanvasFactory.destroy(canvasAndCtx);
|
|
CanvasFactory.destroy(canvasAndCtx);
|
|
return _context.abrupt("return", data);
|
|
return _context.abrupt("return", data);
|
|
|
|
|
|
- case 17:
|
|
|
|
|
|
+ case 16:
|
|
case "end":
|
|
case "end":
|
|
return _context.stop();
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }, _callee, this);
|
|
|
|
|
|
+ }, _callee);
|
|
}));
|
|
}));
|
|
return _renderPDF.apply(this, arguments);
|
|
return _renderPDF.apply(this, arguments);
|
|
}
|
|
}
|
|
|
|
|
|
afterEach(function (done) {
|
|
afterEach(function (done) {
|
|
- var destroyPromises = pdfDocuments.map(function (pdfDocument) {
|
|
|
|
- return pdfDocument.destroy();
|
|
|
|
- });
|
|
|
|
- var destroyPromises2 = loadingTasks.map(function (loadingTask) {
|
|
|
|
|
|
+ var destroyPromises = loadingTasks.map(function (loadingTask) {
|
|
return loadingTask.destroy();
|
|
return loadingTask.destroy();
|
|
});
|
|
});
|
|
- Promise.all(destroyPromises.concat(destroyPromises2)).then(function () {
|
|
|
|
- done();
|
|
|
|
- });
|
|
|
|
|
|
+ Promise.all(destroyPromises).then(done);
|
|
});
|
|
});
|
|
it('should correctly render PDFs in parallel', function (done) {
|
|
it('should correctly render PDFs in parallel', function (done) {
|
|
var baseline1, baseline2, baseline3;
|
|
var baseline1, baseline2, baseline3;
|
|
@@ -1374,48 +1384,36 @@ describe('api', function () {
|
|
});
|
|
});
|
|
promiseDone.then(function () {
|
|
promiseDone.then(function () {
|
|
done();
|
|
done();
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
describe('PDFDataRangeTransport', function () {
|
|
describe('PDFDataRangeTransport', function () {
|
|
- var loadPromise;
|
|
|
|
-
|
|
|
|
- function getDocumentData() {
|
|
|
|
- var pdfPath = new URL('../pdfs/tracemonkey.pdf', window.location).href;
|
|
|
|
|
|
+ var dataPromise;
|
|
|
|
+ beforeAll(function (done) {
|
|
|
|
+ var fileName = 'tracemonkey.pdf';
|
|
|
|
|
|
- if (loadPromise) {
|
|
|
|
- return loadPromise;
|
|
|
|
|
|
+ if ((0, _is_node["default"])()) {
|
|
|
|
+ dataPromise = _test_utils.NodeFileReaderFactory.fetch({
|
|
|
|
+ path: _test_utils.TEST_PDFS_PATH.node + fileName
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ dataPromise = _test_utils.DOMFileReaderFactory.fetch({
|
|
|
|
+ path: _test_utils.TEST_PDFS_PATH.dom + fileName
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
- loadPromise = new Promise(function (resolve, reject) {
|
|
|
|
- var xhr = new XMLHttpRequest(pdfPath);
|
|
|
|
- xhr.open('GET', pdfPath);
|
|
|
|
- xhr.responseType = 'arraybuffer';
|
|
|
|
-
|
|
|
|
- xhr.onload = function () {
|
|
|
|
- resolve(new Uint8Array(xhr.response));
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- xhr.onerror = function () {
|
|
|
|
- reject(new Error('PDF is not loaded'));
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- xhr.send();
|
|
|
|
- });
|
|
|
|
- return loadPromise;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ done();
|
|
|
|
+ });
|
|
|
|
+ afterAll(function () {
|
|
|
|
+ dataPromise = null;
|
|
|
|
+ });
|
|
it('should fetch document info and page using ranges', function (done) {
|
|
it('should fetch document info and page using ranges', function (done) {
|
|
- if ((0, _is_node.default)()) {
|
|
|
|
- pending('XMLHttpRequest is not supported in Node.js.');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var transport;
|
|
|
|
var initialDataLength = 4000;
|
|
var initialDataLength = 4000;
|
|
- var fetches = 0;
|
|
|
|
- var getDocumentPromise = getDocumentData().then(function (data) {
|
|
|
|
|
|
+ var fetches = 0,
|
|
|
|
+ loadingTask;
|
|
|
|
+ dataPromise.then(function (data) {
|
|
var initialData = data.subarray(0, initialDataLength);
|
|
var initialData = data.subarray(0, initialDataLength);
|
|
- transport = new _api.PDFDataRangeTransport(data.length, initialData);
|
|
|
|
|
|
+ var transport = new _api.PDFDataRangeTransport(data.length, initialData);
|
|
|
|
|
|
transport.requestDataRange = function (begin, end) {
|
|
transport.requestDataRange = function (begin, end) {
|
|
fetches++;
|
|
fetches++;
|
|
@@ -1425,33 +1423,24 @@ describe('api', function () {
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
|
|
- var loadingTask = (0, _api.getDocument)(transport);
|
|
|
|
|
|
+ loadingTask = (0, _api.getDocument)(transport);
|
|
return loadingTask.promise;
|
|
return loadingTask.promise;
|
|
- });
|
|
|
|
- var pdfDocument;
|
|
|
|
- var getPagePromise = getDocumentPromise.then(function (pdfDocument_) {
|
|
|
|
- pdfDocument = pdfDocument_;
|
|
|
|
- var pagePromise = pdfDocument.getPage(10);
|
|
|
|
- return pagePromise;
|
|
|
|
- });
|
|
|
|
- getPagePromise.then(function (page) {
|
|
|
|
|
|
+ }).then(function (pdfDocument) {
|
|
expect(pdfDocument.numPages).toEqual(14);
|
|
expect(pdfDocument.numPages).toEqual(14);
|
|
- expect(page.rotate).toEqual(0);
|
|
|
|
|
|
+ return pdfDocument.getPage(10);
|
|
|
|
+ }).then(function (pdfPage) {
|
|
|
|
+ expect(pdfPage.rotate).toEqual(0);
|
|
expect(fetches).toBeGreaterThan(2);
|
|
expect(fetches).toBeGreaterThan(2);
|
|
- done();
|
|
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ loadingTask.destroy().then(done);
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
it('should fetch document info and page using range and streaming', function (done) {
|
|
it('should fetch document info and page using range and streaming', function (done) {
|
|
- if ((0, _is_node.default)()) {
|
|
|
|
- pending('XMLHttpRequest is not supported in Node.js.');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var transport;
|
|
|
|
var initialDataLength = 4000;
|
|
var initialDataLength = 4000;
|
|
- var fetches = 0;
|
|
|
|
- var getDocumentPromise = getDocumentData().then(function (data) {
|
|
|
|
|
|
+ var fetches = 0,
|
|
|
|
+ loadingTask;
|
|
|
|
+ dataPromise.then(function (data) {
|
|
var initialData = data.subarray(0, initialDataLength);
|
|
var initialData = data.subarray(0, initialDataLength);
|
|
- transport = new _api.PDFDataRangeTransport(data.length, initialData);
|
|
|
|
|
|
+ var transport = new _api.PDFDataRangeTransport(data.length, initialData);
|
|
|
|
|
|
transport.requestDataRange = function (begin, end) {
|
|
transport.requestDataRange = function (begin, end) {
|
|
fetches++;
|
|
fetches++;
|
|
@@ -1465,21 +1454,42 @@ describe('api', function () {
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
|
|
- var loadingTask = (0, _api.getDocument)(transport);
|
|
|
|
|
|
+ loadingTask = (0, _api.getDocument)(transport);
|
|
return loadingTask.promise;
|
|
return loadingTask.promise;
|
|
- });
|
|
|
|
- var pdfDocument;
|
|
|
|
- var getPagePromise = getDocumentPromise.then(function (pdfDocument_) {
|
|
|
|
- pdfDocument = pdfDocument_;
|
|
|
|
- var pagePromise = pdfDocument.getPage(10);
|
|
|
|
- return pagePromise;
|
|
|
|
- });
|
|
|
|
- getPagePromise.then(function (page) {
|
|
|
|
|
|
+ }).then(function (pdfDocument) {
|
|
expect(pdfDocument.numPages).toEqual(14);
|
|
expect(pdfDocument.numPages).toEqual(14);
|
|
- expect(page.rotate).toEqual(0);
|
|
|
|
|
|
+ return pdfDocument.getPage(10);
|
|
|
|
+ }).then(function (pdfPage) {
|
|
|
|
+ expect(pdfPage.rotate).toEqual(0);
|
|
expect(fetches).toEqual(1);
|
|
expect(fetches).toEqual(1);
|
|
- done();
|
|
|
|
- }).catch(done.fail);
|
|
|
|
|
|
+ waitSome(function () {
|
|
|
|
+ loadingTask.destroy().then(done);
|
|
|
|
+ });
|
|
|
|
+ })["catch"](done.fail);
|
|
|
|
+ });
|
|
|
|
+ it('should fetch document info and page, without range, ' + 'using complete initialData', function (done) {
|
|
|
|
+ var fetches = 0,
|
|
|
|
+ loadingTask;
|
|
|
|
+ dataPromise.then(function (data) {
|
|
|
|
+ var transport = new _api.PDFDataRangeTransport(data.length, data, true);
|
|
|
|
+
|
|
|
|
+ transport.requestDataRange = function (begin, end) {
|
|
|
|
+ fetches++;
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ loadingTask = (0, _api.getDocument)({
|
|
|
|
+ disableRange: true,
|
|
|
|
+ range: transport
|
|
|
|
+ });
|
|
|
|
+ return loadingTask.promise;
|
|
|
|
+ }).then(function (pdfDocument) {
|
|
|
|
+ expect(pdfDocument.numPages).toEqual(14);
|
|
|
|
+ return pdfDocument.getPage(10);
|
|
|
|
+ }).then(function (pdfPage) {
|
|
|
|
+ expect(pdfPage.rotate).toEqual(0);
|
|
|
|
+ expect(fetches).toEqual(0);
|
|
|
|
+ loadingTask.destroy().then(done);
|
|
|
|
+ })["catch"](done.fail);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|