diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 2a7c27875..e4b9fb10c 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -31,4 +31,4 @@ !issue1002.pdf !issue925.pdf !gradientfill.pdf - +!basicapi.pdf diff --git a/test/pdfs/basicapi.pdf b/test/pdfs/basicapi.pdf new file mode 100644 index 000000000..31ffcfe9f Binary files /dev/null and b/test/pdfs/basicapi.pdf differ diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js new file mode 100644 index 000000000..72c6434b1 --- /dev/null +++ b/test/unit/api_spec.js @@ -0,0 +1,107 @@ +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ + +'use strict'; + +describe('api', function() { + var basicApiUrl = '/basicapi.pdf'; + function waitsForPromise(promise) { + waitsFor(function() { + return promise.isResolved || promise.isRejected; + }, 250); + } + function expectAfterPromise(promise, successCallback) { + waitsForPromise(promise); + runs(function() { + promise.then(successCallback, + function(error, e) { + // Shouldn't get here. + expect(false).toEqual(true); + }); + }); + } + describe('PDFJS', function() { + describe('getDocument', function() { + it('creates pdf doc from URL', function() { + console.log('what is'); + debugger; + var promise = PDFJS.getDocument(basicApiUrl); + expectAfterPromise(promise, function(data) { + expect(true).toEqual(true); + }); + }); + /* + it('creates pdf doc from typed array', function() { + // TODO + }); + */ + }); + }); + describe('PDFDocument', function() { + var promise = PDFJS.getDocument(basicApiUrl); + waitsForPromise(promise); + var doc; + runs(function() { + promise.then(function(data) { doc = data; }); + }); + it('gets number of pages', function() { + expect(doc.numPages).toEqual(3); + }); + it('gets fingerprint', function() { + expect(typeof doc.fingerprint).toEqual('string'); + }); + it('gets page', function() { + var promise = doc.getPage(1); + expectAfterPromise(promise, function(data) { + expect(true).toEqual(true); + }); + }); + it('gets destinations', function() { + var promise = doc.getDestinations(); + expectAfterPromise(promise, function(data) { + // TODO this seems to be broken for the test pdf + }); + }); + it('gets outline', function() { + var promise = doc.getOutline(); + expectAfterPromise(promise, function(outline) { + // Two top level entries. + expect(outline.length).toEqual(2); + // Make sure some basic attributes are set. + expect(outline[1].title).toEqual('Chapter 1'); + expect(outline[1].items.length).toEqual(1); + expect(outline[1].items[0].title).toEqual('Paragraph 1.1'); + }); + }); + it('gets metadata', function() { + var promise = doc.getMetadata(); + expectAfterPromise(promise, function(metadata) { + expect(metadata.info['Title']).toEqual('Basic API Test'); + expect(metadata.metadata.get('dc:title')).toEqual('Basic API Test'); + }); + }); + }); + describe('Page', function() { + var promise = new Promise(); + PDFJS.getDocument(basicApiUrl).then(function(doc) { + doc.getPage(1).then(function(data) { + promise.resolve(data); + }); + }); + waitsForPromise(promise); + var page; + runs(function() { + promise.then(function(data) { + page = data; + }); + }); + it('gets ref', function() { + expect(page.ref).toEqual({num: 15, gen: 0}); + }); + // TODO rotate + // TODO viewport + // TODO annotaions + // TOOD text content + // TODO operation list + }); +}); diff --git a/test/unit/jsTestDriver.conf b/test/unit/jsTestDriver.conf index 9a26df6a4..8ff218093 100644 --- a/test/unit/jsTestDriver.conf +++ b/test/unit/jsTestDriver.conf @@ -1,32 +1,34 @@ server: http://localhost:4224 -load: - - ../../external/jasmine/jasmine.js - - ../../external/jasmineAdapter/JasmineAdapter.js - - ../../src/obj.js - - ../../src/core.js - - ../../src/util.js - - ../../src/canvas.js - - ../../src/obj.js - - ../../src/function.js - - ../../src/charsets.js - - ../../src/cidmaps.js - - ../../src/colorspace.js - - ../../src/crypto.js - - ../../src/evaluator.js - - ../../src/fonts.js - - ../../src/glyphlist.js - - ../../src/image.js - - ../../src/metrics.js - - ../../src/parser.js - - ../../src/pattern.js - - ../../src/stream.js - - ../../src/worker.js - - ../../src/bidi.js - - ../../external/jpgjs/jpg.js - - ../unit/obj_spec.js - - ../unit/font_spec.js - - ../unit/function_spec.js - - ../unit/crypto_spec.js - - ../unit/stream_spec.js +basepath: .. +load: + - ../external/jasmine/jasmine.js + - ../external/jasmineAdapter/JasmineAdapter.js + - ../src/obj.js + - ../src/core.js + - ../src/util.js + - ../src/api.js + - ../src/canvas.js + - ../src/obj.js + - ../src/function.js + - ../src/charsets.js + - ../src/cidmaps.js + - ../src/colorspace.js + - ../src/crypto.js + - ../src/evaluator.js + - ../src/fonts.js + - ../src/glyphlist.js + - ../src/image.js + - ../src/metrics.js + - ../src/parser.js + - ../src/pattern.js + - ../src/stream.js + - ../src/worker.js + - ../src/bidi.js + - ../src/metadata.js + - ../external/jpgjs/jpg.js + - unit/api_spec.js + +gateway: + - {matcher: "*.pdf", server: "http://localhost:8888/test/pdfs/"}