|
@@ -22,18 +22,42 @@ var _dom_utils = require('../../display/dom_utils');
|
|
|
|
|
|
var _api = require('../../display/api');
|
|
|
|
|
|
+var _test_utils = require('./test_utils');
|
|
|
+
|
|
|
var _global = require('../../display/global');
|
|
|
|
|
|
+var TEST_PDFS_PATH = {
|
|
|
+ dom: '../pdfs/',
|
|
|
+ node: './test/pdfs/'
|
|
|
+};
|
|
|
+function buildGetDocumentParams(filename, options) {
|
|
|
+ var params = Object.create(null);
|
|
|
+ if ((0, _util.isNodeJS)()) {
|
|
|
+ params.data = _test_utils.NodeFileReaderFactory.fetch({ path: TEST_PDFS_PATH.node + filename });
|
|
|
+ } else {
|
|
|
+ params.url = new URL(TEST_PDFS_PATH.dom + filename, window.location).href;
|
|
|
+ }
|
|
|
+ for (var option in options) {
|
|
|
+ params[option] = options[option];
|
|
|
+ }
|
|
|
+ return params;
|
|
|
+}
|
|
|
describe('api', function () {
|
|
|
- var basicApiUrl = new URL('../pdfs/basicapi.pdf', window.location).href;
|
|
|
+ var basicApiFileName = 'basicapi.pdf';
|
|
|
var basicApiFileLength = 105779;
|
|
|
- var CanvasFactory;
|
|
|
+ var basicApiGetDocumentParams = buildGetDocumentParams(basicApiFileName);
|
|
|
+ var CanvasFactory = void 0;
|
|
|
beforeAll(function (done) {
|
|
|
- CanvasFactory = new _dom_utils.DOMCanvasFactory();
|
|
|
+ if ((0, _util.isNodeJS)()) {
|
|
|
+ _global.PDFJS.pdfjsNext = true;
|
|
|
+ } else {
|
|
|
+ CanvasFactory = new _dom_utils.DOMCanvasFactory();
|
|
|
+ }
|
|
|
done();
|
|
|
});
|
|
|
- afterAll(function () {
|
|
|
+ afterAll(function (done) {
|
|
|
CanvasFactory = null;
|
|
|
+ done();
|
|
|
});
|
|
|
function waitSome(callback) {
|
|
|
var WAIT_TIMEOUT = 10;
|
|
@@ -44,7 +68,10 @@ describe('api', function () {
|
|
|
describe('PDFJS', function () {
|
|
|
describe('getDocument', function () {
|
|
|
it('creates pdf doc from URL', function (done) {
|
|
|
- var loadingTask = _global.PDFJS.getDocument(basicApiUrl);
|
|
|
+ if ((0, _util.isNodeJS)()) {
|
|
|
+ pending('XMLHttpRequest is not supported in Node.js.');
|
|
|
+ }
|
|
|
+ var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
|
|
|
var isProgressReportedResolved = false;
|
|
|
var progressReportedCapability = (0, _util.createPromiseCapability)();
|
|
|
loadingTask.onProgress = function (progressData) {
|
|
@@ -64,7 +91,10 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('creates pdf doc from URL and aborts before worker initialized', function (done) {
|
|
|
- var loadingTask = _global.PDFJS.getDocument(basicApiUrl);
|
|
|
+ if ((0, _util.isNodeJS)()) {
|
|
|
+ pending('XMLHttpRequest is not supported in Node.js.');
|
|
|
+ }
|
|
|
+ var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
|
|
|
var destroyed = loadingTask.destroy();
|
|
|
loadingTask.promise.then(function (reason) {
|
|
|
done.fail('shall fail loading');
|
|
@@ -74,7 +104,10 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('creates pdf doc from URL and aborts loading after worker initialized', function (done) {
|
|
|
- var loadingTask = _global.PDFJS.getDocument(basicApiUrl);
|
|
|
+ if ((0, _util.isNodeJS)()) {
|
|
|
+ pending('XMLHttpRequest is not supported in Node.js.');
|
|
|
+ }
|
|
|
+ var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
|
|
|
var destroyed = loadingTask._worker.promise.then(function () {
|
|
|
return loadingTask.destroy();
|
|
|
});
|
|
@@ -86,32 +119,33 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('creates pdf doc from typed array', function (done) {
|
|
|
- var nonBinaryRequest = _global.PDFJS.disableWorker;
|
|
|
- var request = new XMLHttpRequest();
|
|
|
- request.open('GET', basicApiUrl, false);
|
|
|
- if (!nonBinaryRequest) {
|
|
|
- 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);
|
|
|
var typedArrayPdf;
|
|
|
- if (nonBinaryRequest) {
|
|
|
- var data = Array.prototype.map.call(request.responseText, function (ch) {
|
|
|
- return ch.charCodeAt(0) & 0xFF;
|
|
|
- });
|
|
|
- typedArrayPdf = new Uint8Array(data);
|
|
|
+ if ((0, _util.isNodeJS)()) {
|
|
|
+ typedArrayPdf = _test_utils.NodeFileReaderFactory.fetch({ path: TEST_PDFS_PATH.node + basicApiFileName });
|
|
|
} else {
|
|
|
- typedArrayPdf = new Uint8Array(request.response);
|
|
|
+ var nonBinaryRequest = _global.PDFJS.disableWorker;
|
|
|
+ var request = new XMLHttpRequest();
|
|
|
+ request.open('GET', TEST_PDFS_PATH.dom + basicApiFileName, false);
|
|
|
+ if (!nonBinaryRequest) {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
}
|
|
|
expect(typedArrayPdf.length).toEqual(basicApiFileLength);
|
|
|
- var loadingTask = _global.PDFJS.getDocument(typedArrayPdf);
|
|
|
+ var loadingTask = (0, _api.getDocument)(typedArrayPdf);
|
|
|
loadingTask.promise.then(function (data) {
|
|
|
expect(data instanceof _api.PDFDocumentProxy).toEqual(true);
|
|
|
loadingTask.destroy().then(done);
|
|
@@ -120,8 +154,7 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('creates pdf doc from invalid PDF file', function (done) {
|
|
|
- var url = new URL('../pdfs/bug1020226.pdf', window.location).href;
|
|
|
- var loadingTask = _global.PDFJS.getDocument(url);
|
|
|
+ var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('bug1020226.pdf'));
|
|
|
loadingTask.promise.then(function () {
|
|
|
done.fail('shall fail loading');
|
|
|
}).catch(function (error) {
|
|
@@ -130,8 +163,10 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('creates pdf doc from non-existent URL', function (done) {
|
|
|
- var nonExistentUrl = new URL('../pdfs/non-existent.pdf', window.location).href;
|
|
|
- var loadingTask = _global.PDFJS.getDocument(nonExistentUrl);
|
|
|
+ if ((0, _util.isNodeJS)()) {
|
|
|
+ pending('XMLHttpRequest is not supported in Node.js.');
|
|
|
+ }
|
|
|
+ var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('non-existent.pdf'));
|
|
|
loadingTask.promise.then(function (error) {
|
|
|
done.fail('shall fail loading');
|
|
|
}).catch(function (error) {
|
|
@@ -140,8 +175,7 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('creates pdf doc from PDF file protected with user and owner password', function (done) {
|
|
|
- var url = new URL('../pdfs/pr6531_1.pdf', window.location).href;
|
|
|
- var loadingTask = _global.PDFJS.getDocument(url);
|
|
|
+ var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('pr6531_1.pdf'));
|
|
|
var isPasswordNeededResolved = false;
|
|
|
var passwordNeededCapability = (0, _util.createPromiseCapability)();
|
|
|
var isPasswordIncorrectResolved = false;
|
|
@@ -170,11 +204,8 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('creates pdf doc from PDF file protected with only a user password', function (done) {
|
|
|
- var url = new URL('../pdfs/pr6531_2.pdf', window.location).href;
|
|
|
- var passwordNeededLoadingTask = _global.PDFJS.getDocument({
|
|
|
- url: url,
|
|
|
- password: ''
|
|
|
- });
|
|
|
+ var filename = 'pr6531_2.pdf';
|
|
|
+ var passwordNeededLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename, { password: '' }));
|
|
|
var result1 = passwordNeededLoadingTask.promise.then(function () {
|
|
|
done.fail('shall fail with no password');
|
|
|
return Promise.reject(new Error('loadingTask should be rejected'));
|
|
@@ -183,10 +214,7 @@ describe('api', function () {
|
|
|
expect(data.code).toEqual(_util.PasswordResponses.NEED_PASSWORD);
|
|
|
return passwordNeededLoadingTask.destroy();
|
|
|
});
|
|
|
- var passwordIncorrectLoadingTask = _global.PDFJS.getDocument({
|
|
|
- url: url,
|
|
|
- password: 'qwerty'
|
|
|
- });
|
|
|
+ var passwordIncorrectLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename, { password: 'qwerty' }));
|
|
|
var result2 = passwordIncorrectLoadingTask.promise.then(function () {
|
|
|
done.fail('shall fail with wrong password');
|
|
|
return Promise.reject(new Error('loadingTask should be rejected'));
|
|
@@ -195,10 +223,7 @@ describe('api', function () {
|
|
|
expect(data.code).toEqual(_util.PasswordResponses.INCORRECT_PASSWORD);
|
|
|
return passwordIncorrectLoadingTask.destroy();
|
|
|
});
|
|
|
- var passwordAcceptedLoadingTask = _global.PDFJS.getDocument({
|
|
|
- url: url,
|
|
|
- password: 'asdfasdf'
|
|
|
- });
|
|
|
+ var passwordAcceptedLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename, { password: 'asdfasdf' }));
|
|
|
var result3 = passwordAcceptedLoadingTask.promise.then(function (data) {
|
|
|
expect(data instanceof _api.PDFDocumentProxy).toEqual(true);
|
|
|
return passwordAcceptedLoadingTask.destroy();
|
|
@@ -210,12 +235,9 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('creates pdf doc from password protected PDF file and aborts/throws ' + 'in the onPassword callback (issue 7806)', function (done) {
|
|
|
- var url = new URL('../pdfs/issue3371.pdf', window.location).href;
|
|
|
- var passwordNeededLoadingTask = _global.PDFJS.getDocument(url);
|
|
|
- var passwordIncorrectLoadingTask = _global.PDFJS.getDocument({
|
|
|
- url: url,
|
|
|
- password: 'qwerty'
|
|
|
- });
|
|
|
+ var filename = 'issue3371.pdf';
|
|
|
+ var passwordNeededLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename));
|
|
|
+ var passwordIncorrectLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename, { password: 'qwerty' }));
|
|
|
var passwordNeededDestroyed = void 0;
|
|
|
passwordNeededLoadingTask.onPassword = function (callback, reason) {
|
|
|
if (reason === _util.PasswordResponses.NEED_PASSWORD) {
|
|
@@ -255,6 +277,9 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
describe('PDFWorker', function () {
|
|
|
+ if ((0, _util.isNodeJS)()) {
|
|
|
+ pending('Worker is not supported in Node.js.');
|
|
|
+ }
|
|
|
it('worker created or destroyed', function (done) {
|
|
|
var worker = new _global.PDFJS.PDFWorker('test1');
|
|
|
worker.promise.then(function () {
|
|
@@ -272,7 +297,7 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('worker created or destroyed by getDocument', function (done) {
|
|
|
- var loadingTask = _global.PDFJS.getDocument(basicApiUrl);
|
|
|
+ var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
|
|
|
var worker;
|
|
|
loadingTask.promise.then(function () {
|
|
|
worker = loadingTask._worker;
|
|
@@ -292,10 +317,7 @@ describe('api', function () {
|
|
|
});
|
|
|
it('worker created and can be used in getDocument', function (done) {
|
|
|
var worker = new _global.PDFJS.PDFWorker('test1');
|
|
|
- var loadingTask = _global.PDFJS.getDocument({
|
|
|
- url: basicApiUrl,
|
|
|
- worker: worker
|
|
|
- });
|
|
|
+ var loadingTask = (0, _api.getDocument)(buildGetDocumentParams(basicApiFileName, { worker: worker }));
|
|
|
loadingTask.promise.then(function () {
|
|
|
var docWorker = loadingTask._worker;
|
|
|
expect(!!docWorker).toEqual(false);
|
|
@@ -333,7 +355,7 @@ describe('api', function () {
|
|
|
var loadingTask;
|
|
|
var doc;
|
|
|
beforeAll(function (done) {
|
|
|
- loadingTask = _global.PDFJS.getDocument(basicApiUrl);
|
|
|
+ loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
|
|
|
loadingTask.promise.then(function (data) {
|
|
|
doc = data;
|
|
|
done();
|
|
@@ -447,8 +469,7 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('gets destinations, from /Names (NameTree) dictionary', function (done) {
|
|
|
- var url = new URL('../pdfs/issue6204.pdf', window.location).href;
|
|
|
- var loadingTask = _global.PDFJS.getDocument(url);
|
|
|
+ var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('issue6204.pdf'));
|
|
|
var promise = loadingTask.promise.then(function (pdfDocument) {
|
|
|
return pdfDocument.getDestinations();
|
|
|
});
|
|
@@ -469,8 +490,7 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('gets a destination, from /Names (NameTree) dictionary', function (done) {
|
|
|
- var url = new URL('../pdfs/issue6204.pdf', window.location).href;
|
|
|
- var loadingTask = _global.PDFJS.getDocument(url);
|
|
|
+ var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('issue6204.pdf'));
|
|
|
var promise = loadingTask.promise.then(function (pdfDocument) {
|
|
|
return pdfDocument.getDestination('Page.1');
|
|
|
});
|
|
@@ -485,8 +505,7 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('gets a non-existent destination, from /Names (NameTree) dictionary', function (done) {
|
|
|
- var url = new URL('../pdfs/issue6204.pdf', window.location).href;
|
|
|
- var loadingTask = _global.PDFJS.getDocument(url);
|
|
|
+ var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('issue6204.pdf'));
|
|
|
var promise = loadingTask.promise.then(function (pdfDocument) {
|
|
|
return pdfDocument.getDestination('non-existent-named-destination');
|
|
|
});
|
|
@@ -507,23 +526,19 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('gets page labels', function (done) {
|
|
|
- var url0 = new URL('../pdfs/bug793632.pdf', window.location).href;
|
|
|
- var loadingTask0 = _global.PDFJS.getDocument(url0);
|
|
|
+ var loadingTask0 = (0, _api.getDocument)(buildGetDocumentParams('bug793632.pdf'));
|
|
|
var promise0 = loadingTask0.promise.then(function (pdfDoc) {
|
|
|
return pdfDoc.getPageLabels();
|
|
|
});
|
|
|
- var url1 = new URL('../pdfs/issue1453.pdf', window.location).href;
|
|
|
- var loadingTask1 = _global.PDFJS.getDocument(url1);
|
|
|
+ var loadingTask1 = (0, _api.getDocument)(buildGetDocumentParams('issue1453.pdf'));
|
|
|
var promise1 = loadingTask1.promise.then(function (pdfDoc) {
|
|
|
return pdfDoc.getPageLabels();
|
|
|
});
|
|
|
- var url2 = new URL('../pdfs/rotation.pdf', window.location).href;
|
|
|
- var loadingTask2 = _global.PDFJS.getDocument(url2);
|
|
|
+ var loadingTask2 = (0, _api.getDocument)(buildGetDocumentParams('rotation.pdf'));
|
|
|
var promise2 = loadingTask2.promise.then(function (pdfDoc) {
|
|
|
return pdfDoc.getPageLabels();
|
|
|
});
|
|
|
- var url3 = new URL('../pdfs/bad-PageLabels.pdf', window.location).href;
|
|
|
- var loadingTask3 = _global.PDFJS.getDocument(url3);
|
|
|
+ var loadingTask3 = (0, _api.getDocument)(buildGetDocumentParams('bad-PageLabels.pdf'));
|
|
|
var promise3 = loadingTask3.promise.then(function (pdfDoc) {
|
|
|
return pdfDoc.getPageLabels();
|
|
|
});
|
|
@@ -547,8 +562,10 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('gets attachments', function (done) {
|
|
|
- var url = new URL('../pdfs/bug766138.pdf', window.location).href;
|
|
|
- var loadingTask = _global.PDFJS.getDocument(url);
|
|
|
+ if ((0, _util.isNodeJS)()) {
|
|
|
+ pending('TODO: Use a non-linked test-case.');
|
|
|
+ }
|
|
|
+ var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('bug766138.pdf'));
|
|
|
var promise = loadingTask.promise.then(function (pdfDoc) {
|
|
|
return pdfDoc.getAttachments();
|
|
|
});
|
|
@@ -573,8 +590,7 @@ describe('api', function () {
|
|
|
});
|
|
|
var viewerPrintRegExp = /\bprint\s*\(/;
|
|
|
it('gets javascript with printing instructions (Print action)', function (done) {
|
|
|
- var pdfUrl = new URL('../pdfs/bug1001080.pdf', window.location).href;
|
|
|
- var loadingTask = _global.PDFJS.getDocument(pdfUrl);
|
|
|
+ var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('bug1001080.pdf'));
|
|
|
var promise = loadingTask.promise.then(function (doc) {
|
|
|
return doc.getJavaScript();
|
|
|
});
|
|
@@ -587,8 +603,7 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('gets javascript with printing instructions (JS action)', function (done) {
|
|
|
- var pdfUrl = new URL('../pdfs/issue6106.pdf', window.location).href;
|
|
|
- var loadingTask = _global.PDFJS.getDocument(pdfUrl);
|
|
|
+ var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('issue6106.pdf'));
|
|
|
var promise = loadingTask.promise.then(function (doc) {
|
|
|
return doc.getJavaScript();
|
|
|
});
|
|
@@ -601,8 +616,7 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('gets non-existent outline', function (done) {
|
|
|
- var url = new URL('../pdfs/tracemonkey.pdf', window.location).href;
|
|
|
- var loadingTask = _global.PDFJS.getDocument(url);
|
|
|
+ var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('tracemonkey.pdf'));
|
|
|
var promise = loadingTask.promise.then(function (pdfDocument) {
|
|
|
return pdfDocument.getOutline();
|
|
|
});
|
|
@@ -635,8 +649,7 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('gets outline containing a url', function (done) {
|
|
|
- var pdfUrl = new URL('../pdfs/issue3214.pdf', window.location).href;
|
|
|
- var loadingTask = _global.PDFJS.getDocument(pdfUrl);
|
|
|
+ var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('issue3214.pdf'));
|
|
|
loadingTask.promise.then(function (pdfDocument) {
|
|
|
pdfDocument.getOutline().then(function (outline) {
|
|
|
expect(outline instanceof Array).toEqual(true);
|
|
@@ -658,6 +671,9 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('gets metadata', function (done) {
|
|
|
+ if ((0, _util.isNodeJS)()) {
|
|
|
+ pending('Document is not supported in Node.js.');
|
|
|
+ }
|
|
|
var promise = doc.getMetadata();
|
|
|
promise.then(function (metadata) {
|
|
|
expect(metadata.info['Title']).toEqual('Basic API Test');
|
|
@@ -700,10 +716,8 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('checks that fingerprints are unique', function (done) {
|
|
|
- var url1 = new URL('../pdfs/issue4436r.pdf', window.location).href;
|
|
|
- var loadingTask1 = _global.PDFJS.getDocument(url1);
|
|
|
- var url2 = new URL('../pdfs/issue4575.pdf', window.location).href;
|
|
|
- var loadingTask2 = _global.PDFJS.getDocument(url2);
|
|
|
+ var loadingTask1 = (0, _api.getDocument)(buildGetDocumentParams('issue4436r.pdf'));
|
|
|
+ var loadingTask2 = (0, _api.getDocument)(buildGetDocumentParams('issue4575.pdf'));
|
|
|
var promises = [loadingTask1.promise, loadingTask2.promise];
|
|
|
Promise.all(promises).then(function (data) {
|
|
|
var fingerprint1 = data[0].fingerprint;
|
|
@@ -723,7 +737,7 @@ describe('api', function () {
|
|
|
var loadingTask;
|
|
|
var pdfDocument, page;
|
|
|
beforeAll(function (done) {
|
|
|
- loadingTask = _global.PDFJS.getDocument(basicApiUrl);
|
|
|
+ loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
|
|
|
loadingTask.promise.then(function (doc) {
|
|
|
pdfDocument = doc;
|
|
|
pdfDocument.getPage(1).then(function (data) {
|
|
@@ -781,26 +795,20 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('gets annotations containing relative URLs (bug 766086)', function (done) {
|
|
|
- var url = new URL('../pdfs/bug766086.pdf', window.location).href;
|
|
|
- var defaultLoadingTask = _global.PDFJS.getDocument(url);
|
|
|
+ var filename = 'bug766086.pdf';
|
|
|
+ var defaultLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename));
|
|
|
var defaultPromise = defaultLoadingTask.promise.then(function (pdfDoc) {
|
|
|
return pdfDoc.getPage(1).then(function (pdfPage) {
|
|
|
return pdfPage.getAnnotations();
|
|
|
});
|
|
|
});
|
|
|
- var docBaseUrlLoadingTask = _global.PDFJS.getDocument({
|
|
|
- url: url,
|
|
|
- docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf'
|
|
|
- });
|
|
|
+ var docBaseUrlLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename, { docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf' }));
|
|
|
var docBaseUrlPromise = docBaseUrlLoadingTask.promise.then(function (pdfDoc) {
|
|
|
return pdfDoc.getPage(1).then(function (pdfPage) {
|
|
|
return pdfPage.getAnnotations();
|
|
|
});
|
|
|
});
|
|
|
- var invalidDocBaseUrlLoadingTask = _global.PDFJS.getDocument({
|
|
|
- url: url,
|
|
|
- docBaseUrl: 'qwerty.pdf'
|
|
|
- });
|
|
|
+ var invalidDocBaseUrlLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename, { docBaseUrl: 'qwerty.pdf' }));
|
|
|
var invalidDocBaseUrlPromise = invalidDocBaseUrlLoadingTask.promise.then(function (pdfDoc) {
|
|
|
return pdfDoc.getPage(1).then(function (pdfPage) {
|
|
|
return pdfPage.getAnnotations();
|
|
@@ -869,6 +877,9 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
it('cancels rendering of page', function (done) {
|
|
|
+ if ((0, _util.isNodeJS)()) {
|
|
|
+ pending('TODO: Support Canvas testing in Node.js.');
|
|
|
+ }
|
|
|
var viewport = page.getViewport(1);
|
|
|
var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
|
|
|
var renderTask = page.render({
|
|
@@ -887,13 +898,16 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
describe('Multiple PDFJS instances', function () {
|
|
|
- var pdf1 = new URL('../pdfs/tracemonkey.pdf', window.location).href;
|
|
|
- var pdf2 = new URL('../pdfs/TAMReview.pdf', window.location).href;
|
|
|
- var pdf3 = new URL('../pdfs/issue6068.pdf', window.location).href;
|
|
|
+ if ((0, _util.isNodeJS)()) {
|
|
|
+ pending('TODO: Support Canvas testing in Node.js.');
|
|
|
+ }
|
|
|
+ var pdf1 = buildGetDocumentParams('tracemonkey.pdf');
|
|
|
+ var pdf2 = buildGetDocumentParams('TAMReview.pdf');
|
|
|
+ var pdf3 = buildGetDocumentParams('issue6068.pdf');
|
|
|
var loadingTasks = [];
|
|
|
var pdfDocuments = [];
|
|
|
function renderPDF(filename) {
|
|
|
- var loadingTask = _global.PDFJS.getDocument(filename);
|
|
|
+ var loadingTask = (0, _api.getDocument)(filename);
|
|
|
loadingTasks.push(loadingTask);
|
|
|
return loadingTask.promise.then(function (pdf) {
|
|
|
pdfDocuments.push(pdf);
|
|
@@ -947,6 +961,9 @@ describe('api', function () {
|
|
|
});
|
|
|
});
|
|
|
describe('PDFDataRangeTransport', function () {
|
|
|
+ if ((0, _util.isNodeJS)()) {
|
|
|
+ pending('XMLHttpRequest is not supported in Node.js.');
|
|
|
+ }
|
|
|
var pdfPath = new URL('../pdfs/tracemonkey.pdf', window.location).href;
|
|
|
var loadPromise;
|
|
|
function getDocumentData() {
|
|
@@ -981,7 +998,7 @@ describe('api', function () {
|
|
|
transport.onDataRange(begin, data.subarray(begin, end));
|
|
|
});
|
|
|
};
|
|
|
- var loadingTask = _global.PDFJS.getDocument(transport);
|
|
|
+ var loadingTask = (0, _api.getDocument)(transport);
|
|
|
return loadingTask.promise;
|
|
|
});
|
|
|
var pdfDocument;
|
|
@@ -1015,7 +1032,7 @@ describe('api', function () {
|
|
|
transport.onDataRange(begin, data.subarray(begin, end));
|
|
|
});
|
|
|
};
|
|
|
- var loadingTask = _global.PDFJS.getDocument(transport);
|
|
|
+ var loadingTask = (0, _api.getDocument)(transport);
|
|
|
return loadingTask.promise;
|
|
|
});
|
|
|
var pdfDocument;
|