From e8ad6c9d131dd629b176860f3eea5bbaff81a1a9 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 2 Oct 2015 18:04:08 +0200 Subject: [PATCH] Add a unit-test for bug 1020226 For reference, see PR 4902 and https://bugzilla.mozilla.org/show_bug.cgi?id=1020226. --- test/pdfs/.gitignore | 1 + test/pdfs/bug1020226.pdf | 24 ++++++++++++++++++++++++ test/unit/api_spec.js | 12 +++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 test/pdfs/bug1020226.pdf diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index de2d8b754..2c286cfe1 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -114,6 +114,7 @@ !bug1065245.pdf !bug1151216.pdf !bug1175962.pdf +!bug1020226.pdf !basicapi.pdf !mixedfonts.pdf !shading_extend.pdf diff --git a/test/pdfs/bug1020226.pdf b/test/pdfs/bug1020226.pdf new file mode 100644 index 000000000..655b4fa7f --- /dev/null +++ b/test/pdfs/bug1020226.pdf @@ -0,0 +1,24 @@ +%PDF-1.4 +1 0 obj +<< +/Pages 2 0 R +2 0 obj +<< +/Resources +>> +/Contents 811 0 R +811 0 obj +<< +/Length 17863 +>> +stream +BI +/W 62 +/H 62 +/D[1 +0] +/F/CCFŠ/DP<> diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 26683681b..5a85a5435 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -1,7 +1,8 @@ /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ /* globals PDFJS, expect, it, describe, Promise, combineUrl, waitsFor, - MissingPDFException, StreamType, FontType, PDFPageProxy */ + InvalidPDFException, MissingPDFException, StreamType, FontType, + PDFPageProxy */ 'use strict'; @@ -79,6 +80,15 @@ describe('api', function() { expect(true).toEqual(true); }); }); + it('creates pdf doc from invalid PDF file', function() { + // A severely corrupt PDF file (even Adobe Reader fails to open it). + var url = combineUrl(window.location.href, '../pdfs/bug1020226.pdf'); + + var promise = PDFJS.getDocument(url); + waitsForPromiseRejected(promise, function (error) { + expect(error instanceof InvalidPDFException).toEqual(true); + }); + }); it('creates pdf doc from non-existent URL', function() { var nonExistentUrl = combineUrl(window.location.href, '../pdfs/non-existent.pdf');