From 9f1e140c4fa3b0e5db8b535363e2d8275341df08 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 15 Aug 2014 16:04:39 +0200 Subject: [PATCH] Add unit test for PDF file loaded as typed array --- test/unit/api_spec.js | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 67790dc90..3019b2650 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -29,11 +29,41 @@ describe('api', function() { expect(true).toEqual(true); }); }); - /* it('creates pdf doc from typed array', function() { - // TODO + var nonBinaryRequest = PDFJS.disableWorker; + var request = new XMLHttpRequest(); + request.open('GET', basicApiUrl, false); + if (!nonBinaryRequest) { + try { + request.responseType = 'arraybuffer'; + nonBinaryRequest = request.responseType !== 'arraybuffer'; + } catch (e) { + nonBinaryRequest = true; + } + } + if (nonBinaryRequest && request.overrideMimeType) { + request.overrideMimeType('text/plain; charset=x-user-defined'); + } + request.send(null); + + var typedArrayPdf; + if (nonBinaryRequest) { + var data = Array.prototype.map.call(request.responseText, + function (ch) { + return ch.charCodeAt(0) & 0xFF; + }); + typedArrayPdf = new Uint8Array(data); + } else { + typedArrayPdf = new Uint8Array(request.response); + } + // Sanity check to make sure that we fetched the entire PDF file. + expect(typedArrayPdf.length).toEqual(105779); + + var promise = PDFJS.getDocument(typedArrayPdf); + waitsForPromise(promise, function(data) { + expect(true).toEqual(true); + }); }); - */ }); }); describe('PDFDocument', function() {