Add an API unit-test for the stopAtErrors option (PRs 8240 and 8922 follow-up)

Also fixes an inconsistency in the 'PageError' handler, for `getOperatorList`, in the API.
This commit is contained in:
Jonas Jenwald 2019-07-13 16:06:05 +02:00
parent b01cc55cfd
commit c7fb7116d6
2 changed files with 40 additions and 0 deletions

View File

@ -2101,6 +2101,8 @@ class WorkerTransport {
if (intentState.displayReadyCapability) {
intentState.displayReadyCapability.reject(new Error(data.error));
} else if (intentState.opListReadCapability) {
intentState.opListReadCapability.reject(new Error(data.error));
} else {
throw new Error(data.error);
}

View File

@ -1236,6 +1236,7 @@ describe('api', function() {
done();
}).catch(done.fail);
});
it('gets operatorList with JPEG image (issue 4888)', function(done) {
let loadingTask = getDocument(buildGetDocumentParams('cmykjpeg.pdf'));
@ -1254,6 +1255,43 @@ describe('api', function() {
});
}).catch(done.fail);
});
it('gets operatorList, from corrupt PDF file (issue 8702), ' +
'with/without `stopAtErrors` set', function(done) {
const loadingTask1 = getDocument(buildGetDocumentParams('issue8702.pdf', {
stopAtErrors: false, // The default value.
}));
const loadingTask2 = getDocument(buildGetDocumentParams('issue8702.pdf', {
stopAtErrors: true,
}));
const result1 = loadingTask1.promise.then((pdfDoc) => {
return pdfDoc.getPage(1).then((pdfPage) => {
return pdfPage.getOperatorList().then((opList) => {
expect(opList.fnArray.length).toEqual(722);
expect(opList.argsArray.length).toEqual(722);
expect(opList.lastChunk).toEqual(true);
return loadingTask1.destroy();
});
});
});
const result2 = loadingTask2.promise.then((pdfDoc) => {
return pdfDoc.getPage(1).then((pdfPage) => {
return pdfPage.getOperatorList().then((opList) => {
expect(opList.fnArray.length).toEqual(0);
expect(opList.argsArray.length).toEqual(0);
expect(opList.lastChunk).toEqual(true);
return loadingTask2.destroy();
});
});
});
Promise.all([result1, result2]).then(done, done.fail);
});
it('gets document stats after parsing page', function(done) {
var promise = page.getOperatorList().then(function () {
return pdfDocument.getStats();