[Pkg-javascript-commits] [pdf.js] 217/246: Add unit test for PDF file loaded as typed array

David Prévot taffit at moszumanska.debian.org
Sun Sep 7 15:36:42 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit 9f1e140c4fa3b0e5db8b535363e2d8275341df08
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Fri Aug 15 16:04:39 2014 +0200

    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 67790dc..3019b26 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() {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list