[Pkg-javascript-commits] [pdf.js] 227/414: Implement unit and reference testing for FileAttachment annotations

David Prévot taffit at moszumanska.debian.org
Tue Jun 28 17:12:25 UTC 2016


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

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

commit 10902fd882055c8a03b0da32de3d293b0e9b472c
Author: Tim van der Meij <timvandermeij at gmail.com>
Date:   Sun Feb 14 21:27:53 2016 +0100

    Implement unit and reference testing for FileAttachment annotations
---
 test/pdfs/.gitignore                    |   1 +
 test/pdfs/annotation-fileattachment.pdf | Bin 0 -> 93322 bytes
 test/test_manifest.json                 |   7 +++++
 test/unit/annotation_layer_spec.js      |  47 +++++++++++++++++++++++++++++++-
 4 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore
index 911781e..ec2d056 100644
--- a/test/pdfs/.gitignore
+++ b/test/pdfs/.gitignore
@@ -217,3 +217,4 @@
 !annotation-strikeout.pdf
 !annotation-squiggly.pdf
 !annotation-highlight.pdf
+!annotation-fileattachment.pdf
diff --git a/test/pdfs/annotation-fileattachment.pdf b/test/pdfs/annotation-fileattachment.pdf
new file mode 100644
index 0000000..c3b60cd
Binary files /dev/null and b/test/pdfs/annotation-fileattachment.pdf differ
diff --git a/test/test_manifest.json b/test/test_manifest.json
index 589f96b..7b40b66 100644
--- a/test/test_manifest.json
+++ b/test/test_manifest.json
@@ -2764,6 +2764,13 @@
        "type": "eq",
        "annotations": true
     },
+    {  "id": "annotation-fileattachment",
+       "file": "pdfs/annotation-fileattachment.pdf",
+       "md5": "d20ecee4b53c81b2dd44c8715a1b4a83",
+       "rounds": 1,
+       "type": "eq",
+       "annotations": true
+    },
     {  "id": "issue6108",
        "file": "pdfs/issue6108.pdf",
        "md5": "8961cb55149495989a80bf0487e0f076",
diff --git a/test/unit/annotation_layer_spec.js b/test/unit/annotation_layer_spec.js
index d97861a..df44e62 100644
--- a/test/unit/annotation_layer_spec.js
+++ b/test/unit/annotation_layer_spec.js
@@ -1,9 +1,25 @@
 /* globals expect, it, describe, Dict, Name, Annotation, AnnotationBorderStyle,
-           AnnotationBorderStyleType, AnnotationFlag */
+           AnnotationBorderStyleType, AnnotationFlag, PDFJS, combineUrl,
+           waitsFor, beforeEach, afterEach, stringToBytes */
 
 'use strict';
 
 describe('Annotation layer', function() {
+  function waitsForPromiseResolved(promise, successCallback) {
+    var resolved = false;
+    promise.then(function(val) {
+      resolved = true;
+      successCallback(val);
+    },
+    function(error) {
+      // Shouldn't get here.
+      expect(error).toEqual('the promise should not have been rejected');
+    });
+    waitsFor(function() {
+      return resolved;
+    }, 20000);
+  }
+
   describe('Annotation', function() {
     it('should set and get flags', function() {
       var dict = new Dict();
@@ -172,4 +188,33 @@ describe('Annotation layer', function() {
       expect(borderStyle.verticalCornerRadius).toEqual(0);
     });
   });
+
+  describe('FileAttachmentAnnotation', function() {
+    var loadingTask;
+    var annotations;
+
+    beforeEach(function() {
+      var pdfUrl = combineUrl(window.location.href,
+                              '../pdfs/annotation-fileattachment.pdf');
+      loadingTask = PDFJS.getDocument(pdfUrl);
+      waitsForPromiseResolved(loadingTask.promise, function(pdfDocument) {
+        waitsForPromiseResolved(pdfDocument.getPage(1), function(pdfPage) {
+          waitsForPromiseResolved(pdfPage.getAnnotations(),
+              function (pdfAnnotations) {
+            annotations = pdfAnnotations;
+          });
+        });
+      });
+    });
+
+    afterEach(function() {
+      loadingTask.destroy();
+    });
+
+    it('should correctly parse a file attachment', function() {
+      var annotation = annotations[0];
+      expect(annotation.file.filename).toEqual('Test.txt');
+      expect(annotation.file.content).toEqual(stringToBytes('Test attachment'));
+    });
+  });
 });

-- 
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