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

Merge pull request #7775 from timvandermeij/widget-annotation-name

Widget annotation: implement field name according to the specification
This commit is contained in:
Tim van der Meij 2016-11-02 22:43:17 +01:00 committed by GitHub
commit 9f8d67475e
3 changed files with 110 additions and 33 deletions

View file

@ -616,6 +616,74 @@ describe('Annotation layer', function() {
});
});
describe('WidgetAnnotation', function() {
var widgetDict;
beforeEach(function (done) {
widgetDict = new Dict();
widgetDict.set('Type', Name.get('Annot'));
widgetDict.set('Subtype', Name.get('Widget'));
done();
});
afterEach(function () {
widgetDict = null;
});
it('should handle unknown field names', function() {
var widgetRef = new Ref(20, 0);
var xref = new XRefMock([
{ ref: widgetRef, data: widgetDict, }
]);
var widgetAnnotation = annotationFactory.create(xref, widgetRef,
pdfManagerMock);
var data = widgetAnnotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.fieldName).toEqual('');
});
it('should construct the field name when there are no ancestors',
function() {
widgetDict.set('T', 'foo');
var widgetRef = new Ref(21, 0);
var xref = new XRefMock([
{ ref: widgetRef, data: widgetDict, }
]);
var widgetAnnotation = annotationFactory.create(xref, widgetRef,
pdfManagerMock);
var data = widgetAnnotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.fieldName).toEqual('foo');
});
it('should construct the field name when there are ancestors', function() {
var firstParent = new Dict();
firstParent.set('T', 'foo');
var secondParent = new Dict();
secondParent.set('Parent', firstParent);
secondParent.set('T', 'bar');
widgetDict.set('Parent', secondParent);
widgetDict.set('T', 'baz');
var widgetRef = new Ref(22, 0);
var xref = new XRefMock([
{ ref: widgetRef, data: widgetDict, }
]);
var widgetAnnotation = annotationFactory.create(xref, widgetRef,
pdfManagerMock);
var data = widgetAnnotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.fieldName).toEqual('foo.bar.baz');
});
});
describe('TextWidgetAnnotation', function() {
var textWidgetDict;