[Pkg-javascript-commits] [pdf.js] 56/115: Add tests for parallel rendering

David Prévot taffit at moszumanska.debian.org
Wed Dec 16 20:03:15 UTC 2015


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

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

commit 07f2a439433cf791892a71c2695760d57ea4e993
Author: Rob Wu <rob at robwu.nl>
Date:   Tue Jul 14 11:43:20 2015 +0200

    Add tests for parallel rendering
---
 test/unit/api_spec.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 67 insertions(+), 2 deletions(-)

diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 9749942..12c07d3 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -1,7 +1,7 @@
 /* globals PDFJS, expect, it, describe, Promise, combineUrl, waitsFor,
            InvalidPDFException, MissingPDFException, StreamType, FontType,
            PDFDocumentProxy, PasswordException, PasswordResponses,
-           PDFPageProxy, createPromiseCapability */
+           PDFPageProxy, createPromiseCapability, afterEach */
 
 'use strict';
 
@@ -16,7 +16,7 @@ describe('api', function() {
     },
     function(error) {
       // Shouldn't get here.
-      expect(false).toEqual(true);
+      expect(error).toEqual('the promise should not have been rejected');
     });
     waitsFor(function() {
       return resolved;
@@ -513,4 +513,69 @@ describe('api', function() {
       });
     });
   });
+  describe('Multiple PDFJS instances', function() {
+    // Regression test for https://github.com/mozilla/pdf.js/issues/6205
+    // A PDF using the Helvetica font.
+    var pdf1 = combineUrl(window.location.href, '../pdfs/tracemonkey.pdf');
+    // A PDF using the Times font.
+    var pdf2 = combineUrl(window.location.href, '../pdfs/TAMReview.pdf');
+    // A PDF using the Arial font.
+    var pdf3 = combineUrl(window.location.href, '../pdfs/issue6068.pdf');
+    var pdfDocuments = [];
+
+    // Render the first page of the given PDF file.
+    // Fulfills the promise with the base64-encoded version of the PDF.
+    function renderPDF(filename) {
+      return PDFJS.getDocument(filename)
+        .then(function(pdf) {
+          pdfDocuments.push(pdf);
+          return pdf.getPage(1);
+        }).then(function(page) {
+          var c = document.createElement('canvas');
+          var v = page.getViewport(1.2);
+          c.width = v.width;
+          c.height = v.height;
+          return page.render({
+            canvasContext: c.getContext('2d'),
+            viewport: v,
+          }).then(function() {
+            return c.toDataURL();
+          });
+        });
+    }
+
+    afterEach(function() {
+      // Issue 6205 reported an issue with font rendering, so clear the loaded
+      // fonts so that we can see whether loading PDFs in parallel does not
+      // cause any issues with the rendered fonts.
+      var destroyPromises = pdfDocuments.map(function(pdfDocument) {
+        return pdfDocument.destroy();
+      });
+      waitsForPromiseResolved(Promise.all(destroyPromises), function() {});
+    });
+
+    it('should correctly render PDFs in parallel', function() {
+      var baseline1, baseline2, baseline3;
+      var promiseDone = renderPDF(pdf1).then(function(data1) {
+        baseline1 = data1;
+        return renderPDF(pdf2);
+      }).then(function(data2) {
+        baseline2 = data2;
+        return renderPDF(pdf3);
+      }).then(function(data3) {
+        baseline3 = data3;
+        return Promise.all([
+          renderPDF(pdf1),
+          renderPDF(pdf2),
+          renderPDF(pdf3),
+        ]);
+      }).then(function(dataUrls) {
+        expect(dataUrls[0]).toEqual(baseline1);
+        expect(dataUrls[1]).toEqual(baseline2);
+        expect(dataUrls[2]).toEqual(baseline3);
+        return true;
+      });
+      waitsForPromiseResolved(promiseDone, 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