1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 23:28:06 +02:00

Text widget annotations: implement unit testing and sanitize data values

This commit is contained in:
Tim van der Meij 2016-09-13 14:57:11 +02:00
parent 4d1592883d
commit 323e86c442
3 changed files with 71 additions and 5 deletions

View file

@ -453,6 +453,62 @@ describe('Annotation layer', function() {
});
});
describe('TextWidgetAnnotation', function() {
var textWidgetDict;
beforeEach(function (done) {
textWidgetDict = new Dict();
textWidgetDict.set('Type', Name.get('Annot'));
textWidgetDict.set('Subtype', Name.get('Widget'));
textWidgetDict.set('FT', Name.get('Tx'));
done();
});
afterEach(function () {
textWidgetDict = null;
});
it('should handle unknown text alignment and maximum length', function() {
var textWidgetRef = new Ref(124, 0);
var xref = new XRefMock([
{ ref: textWidgetRef, data: textWidgetDict, }
]);
var textWidgetAnnotation = annotationFactory.create(xref, textWidgetRef);
expect(textWidgetAnnotation.data.textAlignment).toEqual(null);
expect(textWidgetAnnotation.data.maxLen).toEqual(null);
});
it('should not set invalid text alignment and maximum length', function() {
textWidgetDict.set('Q', 'center');
textWidgetDict.set('MaxLen', 'five');
var textWidgetRef = new Ref(43, 0);
var xref = new XRefMock([
{ ref: textWidgetRef, data: textWidgetDict, }
]);
var textWidgetAnnotation = annotationFactory.create(xref, textWidgetRef);
expect(textWidgetAnnotation.data.textAlignment).toEqual(null);
expect(textWidgetAnnotation.data.maxLen).toEqual(null);
});
it('should set valid text alignment and maximum length', function() {
textWidgetDict.set('Q', 1);
textWidgetDict.set('MaxLen', 20);
var textWidgetRef = new Ref(84, 0);
var xref = new XRefMock([
{ ref: textWidgetRef, data: textWidgetDict, }
]);
var textWidgetAnnotation = annotationFactory.create(xref, textWidgetRef);
expect(textWidgetAnnotation.data.textAlignment).toEqual(1);
expect(textWidgetAnnotation.data.maxLen).toEqual(20);
});
});
describe('FileAttachmentAnnotation', function() {
var loadingTask;
var annotations;