Detect scripted auto-print requests

Fixes #6106

To avoid future regressions, two new unit tests were added:
1. A new PDF based on the report from #6106, which contains an
   OpenAction of type JavaScript and a string "this.print({...}".
2. An existing PDF from https://bugzil.la/1001080 (from #4698).

Although it does not matter, since we don't execute the JavaScript code,
I have also changed "print(true)" to "print({})" since the print method
takes an object (not a boolean). See "Printing PDF documents", page 62:
http://adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_developer_guide.pdf
This commit is contained in:
Rob Wu 2015-07-20 18:25:02 +02:00
parent d3e90cf825
commit c676ecb5a0
6 changed files with 124 additions and 24 deletions

View file

@ -147,6 +147,32 @@ describe('api', function() {
expect(data).toEqual([]);
});
});
// Keep this in sync with the pattern in viewer.js. The pattern is used to
// detect whether or not to automatically start printing.
var viewerPrintRegExp = /\bprint\s*\(/;
it('gets javascript with printing instructions (Print action)', function() {
// PDF document with "Print" Named action in OpenAction
var pdfUrl = combineUrl(window.location.href, '../pdfs/bug1001080.pdf');
var promise = PDFJS.getDocument(pdfUrl).then(function(doc) {
return doc.getJavaScript();
});
waitsForPromiseResolved(promise, function (data) {
expect(data).toEqual(['print({});']);
expect(data[0]).toMatch(viewerPrintRegExp);
});
});
it('gets javascript with printing instructions (JS action)', function() {
// PDF document with "JavaScript" action in OpenAction
var pdfUrl = combineUrl(window.location.href, '../pdfs/issue6106.pdf');
var promise = PDFJS.getDocument(pdfUrl).then(function(doc) {
return doc.getJavaScript();
});
waitsForPromiseResolved(promise, function (data) {
expect(data).toEqual(
['this.print({bUI:true,bSilent:false,bShrinkToFit:true});']);
expect(data[0]).toMatch(viewerPrintRegExp);
});
});
it('gets outline', function() {
var promise = doc.getOutline();
waitsForPromiseResolved(promise, function(outline) {