1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-21 07:38:07 +02:00

Improve the error handling when loading of built-in CMap files fail (PR 8064 follow-up)

I happened to notice that the error handling wasn't that great, which I missed previously since there were no unit-tests for failure to load built-in CMap files.
Hence this patch, which improves the error handling *and* adds tests.
This commit is contained in:
Jonas Jenwald 2017-03-28 12:08:44 +02:00
parent 07f7c97b2b
commit 437104969d
3 changed files with 48 additions and 6 deletions

View file

@ -269,5 +269,45 @@ describe('cmap', function() {
done.fail(reason);
});
});
it('attempts to load a non-existent built-in CMap', function(done) {
var cmapPromise = CMapFactory.create({
encoding: Name.get('null'),
fetchBuiltInCMap: fetchBuiltInCMap,
useCMap: null,
});
cmapPromise.then(function () {
done.fail('No CMap should be loaded');
}, function (reason) {
expect(reason instanceof Error).toEqual(true);
expect(reason.message).toEqual('Unknown CMap name: null');
done();
});
});
it('attempts to load a built-in CMap without the necessary API parameters',
function(done) {
function tmpFetchBuiltInCMap(name) {
var CMapReaderFactory = isNodeJS() ?
new NodeCMapReaderFactory({ }) : new DOMCMapReaderFactory({ });
return CMapReaderFactory.fetch({
name: name,
});
}
var cmapPromise = CMapFactory.create({
encoding: Name.get('Adobe-Japan1-1'),
fetchBuiltInCMap: tmpFetchBuiltInCMap,
useCMap: null,
});
cmapPromise.then(function () {
done.fail('No CMap should be loaded');
}, function (reason) {
expect(reason instanceof Error).toEqual(true);
expect(reason.message).toEqual(
'Unable to load CMap at: nullAdobe-Japan1-1');
done();
});
});
});
}));