Merge pull request #7629 from timvandermeij/interactive-form-unit-tests
Text widget annotations: implement unit testing and sanitize data values
This commit is contained in:
commit
a7c35025fe
@ -671,8 +671,19 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
|
|||||||
function TextWidgetAnnotation(params) {
|
function TextWidgetAnnotation(params) {
|
||||||
WidgetAnnotation.call(this, params);
|
WidgetAnnotation.call(this, params);
|
||||||
|
|
||||||
this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
|
// Determine the alignment of text in the field.
|
||||||
this.data.maxLen = Util.getInheritableProperty(params.dict, 'MaxLen');
|
var alignment = Util.getInheritableProperty(params.dict, 'Q');
|
||||||
|
if (!isInt(alignment) || alignment < 0 || alignment > 2) {
|
||||||
|
alignment = null;
|
||||||
|
}
|
||||||
|
this.data.textAlignment = alignment;
|
||||||
|
|
||||||
|
// Determine the maximum length of text in the field.
|
||||||
|
var maximumLength = Util.getInheritableProperty(params.dict, 'MaxLen');
|
||||||
|
if (!isInt(maximumLength) || maximumLength < 0) {
|
||||||
|
maximumLength = null;
|
||||||
|
}
|
||||||
|
this.data.maxLen = maximumLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
|
Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
|
|
||||||
var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
|
var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
|
||||||
var AnnotationType = sharedUtil.AnnotationType;
|
var AnnotationType = sharedUtil.AnnotationType;
|
||||||
var isInt = sharedUtil.isInt;
|
|
||||||
var Util = sharedUtil.Util;
|
var Util = sharedUtil.Util;
|
||||||
var addLinkAttributes = displayDOMUtils.addLinkAttributes;
|
var addLinkAttributes = displayDOMUtils.addLinkAttributes;
|
||||||
var LinkTarget = displayDOMUtils.LinkTarget;
|
var LinkTarget = displayDOMUtils.LinkTarget;
|
||||||
@ -451,7 +450,7 @@ var TextWidgetAnnotationElement = (
|
|||||||
element.type = 'text';
|
element.type = 'text';
|
||||||
element.value = this.data.fieldValue;
|
element.value = this.data.fieldValue;
|
||||||
|
|
||||||
if (isInt(this.data.maxLen)) {
|
if (this.data.maxLen !== null) {
|
||||||
element.maxLength = this.data.maxLen;
|
element.maxLength = this.data.maxLen;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -467,7 +466,7 @@ var TextWidgetAnnotationElement = (
|
|||||||
this._setTextStyle(element, font);
|
this._setTextStyle(element, font);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isInt(this.data.textAlignment)) {
|
if (this.data.textAlignment !== null) {
|
||||||
element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
|
element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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() {
|
describe('FileAttachmentAnnotation', function() {
|
||||||
var loadingTask;
|
var loadingTask;
|
||||||
var annotations;
|
var annotations;
|
||||||
|
Loading…
Reference in New Issue
Block a user