@ -16,36 +16,20 @@
@@ -16,36 +16,20 @@
var _typeof = typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ? function ( obj ) { return typeof obj ; } : function ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ; } ;
var _test _utils = require ( './test_utils' ) ;
var _util = require ( '../../shared/util' ) ;
var _dom _utils = require ( '../../display/dom_utils' ) ;
var _api = require ( '../../display/api' ) ;
var _test _utils = require ( './test_utils' ) ;
var _global = require ( '../../display/global' ) ;
var TEST _PDFS _PATH = {
dom : '../pdfs/' ,
node : './test/pdfs/'
} ;
function buildGetDocumentParams ( filename , options ) {
var params = Object . create ( null ) ;
if ( ( 0 , _util . isNodeJS ) ( ) ) {
params . data = _test _utils . NodeFileReaderFactory . fetch ( { path : TEST _PDFS _PATH . node + filename } ) ;
} else {
params . url = new URL ( TEST _PDFS _PATH . dom + filename , window . location ) . href ;
}
for ( var option in options ) {
params [ option ] = options [ option ] ;
}
return params ;
}
describe ( 'api' , function ( ) {
var basicApiFileName = 'basicapi.pdf' ;
var basicApiFileLength = 105779 ;
var basicApiGetDocumentParams = buildGetDocumentParams ( basicApiFileName ) ;
var basicApiGetDocumentParams = ( 0 , _test _utils . buildGetDocumentParams ) ( basicApiFileName ) ;
var CanvasFactory = void 0 ;
beforeAll ( function ( done ) {
if ( ( 0 , _util . isNodeJS ) ( ) ) {
@ -121,11 +105,11 @@ describe('api', function () {
@@ -121,11 +105,11 @@ describe('api', function () {
it ( 'creates pdf doc from typed array' , function ( done ) {
var typedArrayPdf ;
if ( ( 0 , _util . isNodeJS ) ( ) ) {
typedArrayPdf = _test _utils . NodeFileReaderFactory . fetch ( { path : TEST _PDFS _PATH . node + basicApiFileName } ) ;
typedArrayPdf = _test _utils . NodeFileReaderFactory . fetch ( { path : _test _utils . TEST _PDFS _PATH . node + basicApiFileName } ) ;
} else {
var nonBinaryRequest = _global . PDFJS . disableWorker ;
var request = new XMLHttpRequest ( ) ;
request . open ( 'GET' , TEST _PDFS _PATH . dom + basicApiFileName , false ) ;
request . open ( 'GET' , _test _utils . TEST _PDFS _PATH . dom + basicApiFileName , false ) ;
if ( ! nonBinaryRequest ) {
try {
request . responseType = 'arraybuffer' ;
@ -154,7 +138,7 @@ describe('api', function () {
@@ -154,7 +138,7 @@ describe('api', function () {
} ) ;
} ) ;
it ( 'creates pdf doc from invalid PDF file' , function ( done ) {
var loadingTask = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( 'bug1020226.pdf' ) ) ;
var loadingTask = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( 'bug1020226.pdf' ) ) ;
loadingTask . promise . then ( function ( ) {
done . fail ( 'shall fail loading' ) ;
} ) . catch ( function ( error ) {
@ -166,7 +150,7 @@ describe('api', function () {
@@ -166,7 +150,7 @@ describe('api', function () {
if ( ( 0 , _util . isNodeJS ) ( ) ) {
pending ( 'XMLHttpRequest is not supported in Node.js.' ) ;
}
var loadingTask = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( 'non-existent.pdf' ) ) ;
var loadingTask = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( 'non-existent.pdf' ) ) ;
loadingTask . promise . then ( function ( error ) {
done . fail ( 'shall fail loading' ) ;
} ) . catch ( function ( error ) {
@ -175,7 +159,7 @@ describe('api', function () {
@@ -175,7 +159,7 @@ describe('api', function () {
} ) ;
} ) ;
it ( 'creates pdf doc from PDF file protected with user and owner password' , function ( done ) {
var loadingTask = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( 'pr6531_1.pdf' ) ) ;
var loadingTask = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( 'pr6531_1.pdf' ) ) ;
var isPasswordNeededResolved = false ;
var passwordNeededCapability = ( 0 , _util . createPromiseCapability ) ( ) ;
var isPasswordIncorrectResolved = false ;
@ -205,7 +189,7 @@ describe('api', function () {
@@ -205,7 +189,7 @@ describe('api', function () {
} ) ;
it ( 'creates pdf doc from PDF file protected with only a user password' , function ( done ) {
var filename = 'pr6531_2.pdf' ;
var passwordNeededLoadingTask = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( filename , { password : '' } ) ) ;
var passwordNeededLoadingTask = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( filename , { password : '' } ) ) ;
var result1 = passwordNeededLoadingTask . promise . then ( function ( ) {
done . fail ( 'shall fail with no password' ) ;
return Promise . reject ( new Error ( 'loadingTask should be rejected' ) ) ;
@ -214,7 +198,7 @@ describe('api', function () {
@@ -214,7 +198,7 @@ describe('api', function () {
expect ( data . code ) . toEqual ( _util . PasswordResponses . NEED _PASSWORD ) ;
return passwordNeededLoadingTask . destroy ( ) ;
} ) ;
var passwordIncorrectLoadingTask = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( filename , { password : 'qwerty' } ) ) ;
var passwordIncorrectLoadingTask = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( filename , { password : 'qwerty' } ) ) ;
var result2 = passwordIncorrectLoadingTask . promise . then ( function ( ) {
done . fail ( 'shall fail with wrong password' ) ;
return Promise . reject ( new Error ( 'loadingTask should be rejected' ) ) ;
@ -223,7 +207,7 @@ describe('api', function () {
@@ -223,7 +207,7 @@ describe('api', function () {
expect ( data . code ) . toEqual ( _util . PasswordResponses . INCORRECT _PASSWORD ) ;
return passwordIncorrectLoadingTask . destroy ( ) ;
} ) ;
var passwordAcceptedLoadingTask = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( filename , { password : 'asdfasdf' } ) ) ;
var passwordAcceptedLoadingTask = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( filename , { password : 'asdfasdf' } ) ) ;
var result3 = passwordAcceptedLoadingTask . promise . then ( function ( data ) {
expect ( data instanceof _api . PDFDocumentProxy ) . toEqual ( true ) ;
return passwordAcceptedLoadingTask . destroy ( ) ;
@ -236,8 +220,8 @@ describe('api', function () {
@@ -236,8 +220,8 @@ describe('api', function () {
} ) ;
it ( 'creates pdf doc from password protected PDF file and aborts/throws ' + 'in the onPassword callback (issue 7806)' , function ( done ) {
var filename = 'issue3371.pdf' ;
var passwordNeededLoadingTask = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( filename ) ) ;
var passwordIncorrectLoadingTask = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( filename , { password : 'qwerty' } ) ) ;
var passwordNeededLoadingTask = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( filename ) ) ;
var passwordIncorrectLoadingTask = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( filename , { password : 'qwerty' } ) ) ;
var passwordNeededDestroyed = void 0 ;
passwordNeededLoadingTask . onPassword = function ( callback , reason ) {
if ( reason === _util . PasswordResponses . NEED _PASSWORD ) {
@ -317,7 +301,7 @@ describe('api', function () {
@@ -317,7 +301,7 @@ describe('api', function () {
} ) ;
it ( 'worker created and can be used in getDocument' , function ( done ) {
var worker = new _global . PDFJS . PDFWorker ( 'test1' ) ;
var loadingTask = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( basicApiFileName , { worker : worker } ) ) ;
var loadingTask = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( basicApiFileName , { worker : worker } ) ) ;
loadingTask . promise . then ( function ( ) {
var docWorker = loadingTask . _worker ;
expect ( ! ! docWorker ) . toEqual ( false ) ;
@ -469,7 +453,7 @@ describe('api', function () {
@@ -469,7 +453,7 @@ describe('api', function () {
} ) ;
} ) ;
it ( 'gets destinations, from /Names (NameTree) dictionary' , function ( done ) {
var loadingTask = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( 'issue6204.pdf' ) ) ;
var loadingTask = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( 'issue6204.pdf' ) ) ;
var promise = loadingTask . promise . then ( function ( pdfDocument ) {
return pdfDocument . getDestinations ( ) ;
} ) ;
@ -490,7 +474,7 @@ describe('api', function () {
@@ -490,7 +474,7 @@ describe('api', function () {
} ) ;
} ) ;
it ( 'gets a destination, from /Names (NameTree) dictionary' , function ( done ) {
var loadingTask = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( 'issue6204.pdf' ) ) ;
var loadingTask = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( 'issue6204.pdf' ) ) ;
var promise = loadingTask . promise . then ( function ( pdfDocument ) {
return pdfDocument . getDestination ( 'Page.1' ) ;
} ) ;
@ -505,7 +489,7 @@ describe('api', function () {
@@ -505,7 +489,7 @@ describe('api', function () {
} ) ;
} ) ;
it ( 'gets a non-existent destination, from /Names (NameTree) dictionary' , function ( done ) {
var loadingTask = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( 'issue6204.pdf' ) ) ;
var loadingTask = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( 'issue6204.pdf' ) ) ;
var promise = loadingTask . promise . then ( function ( pdfDocument ) {
return pdfDocument . getDestination ( 'non-existent-named-destination' ) ;
} ) ;
@ -526,19 +510,19 @@ describe('api', function () {
@@ -526,19 +510,19 @@ describe('api', function () {
} ) ;
} ) ;
it ( 'gets page labels' , function ( done ) {
var loadingTask0 = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( 'bug793632.pdf' ) ) ;
var loadingTask0 = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( 'bug793632.pdf' ) ) ;
var promise0 = loadingTask0 . promise . then ( function ( pdfDoc ) {
return pdfDoc . getPageLabels ( ) ;
} ) ;
var loadingTask1 = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( 'issue1453.pdf' ) ) ;
var loadingTask1 = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( 'issue1453.pdf' ) ) ;
var promise1 = loadingTask1 . promise . then ( function ( pdfDoc ) {
return pdfDoc . getPageLabels ( ) ;
} ) ;
var loadingTask2 = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( 'rotation.pdf' ) ) ;
var loadingTask2 = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( 'rotation.pdf' ) ) ;
var promise2 = loadingTask2 . promise . then ( function ( pdfDoc ) {
return pdfDoc . getPageLabels ( ) ;
} ) ;
var loadingTask3 = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( 'bad-PageLabels.pdf' ) ) ;
var loadingTask3 = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( 'bad-PageLabels.pdf' ) ) ;
var promise3 = loadingTask3 . promise . then ( function ( pdfDoc ) {
return pdfDoc . getPageLabels ( ) ;
} ) ;
@ -565,7 +549,7 @@ describe('api', function () {
@@ -565,7 +549,7 @@ describe('api', function () {
if ( ( 0 , _util . isNodeJS ) ( ) ) {
pending ( 'TODO: Use a non-linked test-case.' ) ;
}
var loadingTask = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( 'bug766138.pdf' ) ) ;
var loadingTask = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( 'bug766138.pdf' ) ) ;
var promise = loadingTask . promise . then ( function ( pdfDoc ) {
return pdfDoc . getAttachments ( ) ;
} ) ;
@ -590,7 +574,7 @@ describe('api', function () {
@@ -590,7 +574,7 @@ describe('api', function () {
} ) ;
var viewerPrintRegExp = /\bprint\s*\(/ ;
it ( 'gets javascript with printing instructions (Print action)' , function ( done ) {
var loadingTask = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( 'bug1001080.pdf' ) ) ;
var loadingTask = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( 'bug1001080.pdf' ) ) ;
var promise = loadingTask . promise . then ( function ( doc ) {
return doc . getJavaScript ( ) ;
} ) ;
@ -603,7 +587,7 @@ describe('api', function () {
@@ -603,7 +587,7 @@ describe('api', function () {
} ) ;
} ) ;
it ( 'gets javascript with printing instructions (JS action)' , function ( done ) {
var loadingTask = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( 'issue6106.pdf' ) ) ;
var loadingTask = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( 'issue6106.pdf' ) ) ;
var promise = loadingTask . promise . then ( function ( doc ) {
return doc . getJavaScript ( ) ;
} ) ;
@ -616,7 +600,7 @@ describe('api', function () {
@@ -616,7 +600,7 @@ describe('api', function () {
} ) ;
} ) ;
it ( 'gets non-existent outline' , function ( done ) {
var loadingTask = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( 'tracemonkey.pdf' ) ) ;
var loadingTask = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( 'tracemonkey.pdf' ) ) ;
var promise = loadingTask . promise . then ( function ( pdfDocument ) {
return pdfDocument . getOutline ( ) ;
} ) ;
@ -649,7 +633,7 @@ describe('api', function () {
@@ -649,7 +633,7 @@ describe('api', function () {
} ) ;
} ) ;
it ( 'gets outline containing a url' , function ( done ) {
var loadingTask = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( 'issue3214.pdf' ) ) ;
var loadingTask = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( 'issue3214.pdf' ) ) ;
loadingTask . promise . then ( function ( pdfDocument ) {
pdfDocument . getOutline ( ) . then ( function ( outline ) {
expect ( outline instanceof Array ) . toEqual ( true ) ;
@ -716,8 +700,8 @@ describe('api', function () {
@@ -716,8 +700,8 @@ describe('api', function () {
} ) ;
} ) ;
it ( 'checks that fingerprints are unique' , function ( done ) {
var loadingTask1 = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( 'issue4436r.pdf' ) ) ;
var loadingTask2 = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( 'issue4575.pdf' ) ) ;
var loadingTask1 = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( 'issue4436r.pdf' ) ) ;
var loadingTask2 = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( 'issue4575.pdf' ) ) ;
var promises = [ loadingTask1 . promise , loadingTask2 . promise ] ;
Promise . all ( promises ) . then ( function ( data ) {
var fingerprint1 = data [ 0 ] . fingerprint ;
@ -796,19 +780,19 @@ describe('api', function () {
@@ -796,19 +780,19 @@ describe('api', function () {
} ) ;
it ( 'gets annotations containing relative URLs (bug 766086)' , function ( done ) {
var filename = 'bug766086.pdf' ;
var defaultLoadingTask = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( filename ) ) ;
var defaultLoadingTask = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( filename ) ) ;
var defaultPromise = defaultLoadingTask . promise . then ( function ( pdfDoc ) {
return pdfDoc . getPage ( 1 ) . then ( function ( pdfPage ) {
return pdfPage . getAnnotations ( ) ;
} ) ;
} ) ;
var docBaseUrlLoadingTask = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( filename , { docBaseUrl : 'http://www.example.com/test/pdfs/qwerty.pdf' } ) ) ;
var docBaseUrlLoadingTask = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( filename , { docBaseUrl : 'http://www.example.com/test/pdfs/qwerty.pdf' } ) ) ;
var docBaseUrlPromise = docBaseUrlLoadingTask . promise . then ( function ( pdfDoc ) {
return pdfDoc . getPage ( 1 ) . then ( function ( pdfPage ) {
return pdfPage . getAnnotations ( ) ;
} ) ;
} ) ;
var invalidDocBaseUrlLoadingTask = ( 0 , _api . getDocument ) ( buildGetDocumentParams ( filename , { docBaseUrl : 'qwerty.pdf' } ) ) ;
var invalidDocBaseUrlLoadingTask = ( 0 , _api . getDocument ) ( ( 0 , _test _utils . buildGetDocumentParams ) ( filename , { docBaseUrl : 'qwerty.pdf' } ) ) ;
var invalidDocBaseUrlPromise = invalidDocBaseUrlLoadingTask . promise . then ( function ( pdfDoc ) {
return pdfDoc . getPage ( 1 ) . then ( function ( pdfPage ) {
return pdfPage . getAnnotations ( ) ;
@ -901,9 +885,9 @@ describe('api', function () {
@@ -901,9 +885,9 @@ describe('api', function () {
if ( ( 0 , _util . isNodeJS ) ( ) ) {
pending ( 'TODO: Support Canvas testing in Node.js.' ) ;
}
var pdf1 = buildGetDocumentParams ( 'tracemonkey.pdf' ) ;
var pdf2 = buildGetDocumentParams ( 'TAMReview.pdf' ) ;
var pdf3 = buildGetDocumentParams ( 'issue6068.pdf' ) ;
var pdf1 = ( 0 , _test _utils . buildGetDocumentParams ) ( 'tracemonkey.pdf' ) ;
var pdf2 = ( 0 , _test _utils . buildGetDocumentParams ) ( 'TAMReview.pdf' ) ;
var pdf3 = ( 0 , _test _utils . buildGetDocumentParams ) ( 'issue6068.pdf' ) ;
var loadingTasks = [ ] ;
var pdfDocuments = [ ] ;
function renderPDF ( filename ) {