2012-04-13 09:59:30 +09:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
2013-02-05 03:01:19 +09:00
|
|
|
/* globals PDFJS, expect, it, describe, Promise, combineUrl, waitsFor, runs */
|
2012-04-13 09:59:30 +09:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
describe('api', function() {
|
2012-04-13 10:09:25 +09:00
|
|
|
// TODO run with worker enabled
|
2012-06-24 05:35:59 +09:00
|
|
|
var basicApiUrl = combineUrl(window.location.href, '../pdfs/basicapi.pdf');
|
2013-06-06 04:28:31 +09:00
|
|
|
function waitsForPromise(promise, successCallback) {
|
|
|
|
var data;
|
|
|
|
promise.then(function(val) {
|
|
|
|
data = val;
|
|
|
|
successCallback(data);
|
|
|
|
},
|
|
|
|
function(error) {
|
|
|
|
// Shouldn't get here.
|
|
|
|
expect(false).toEqual(true);
|
|
|
|
});
|
2012-04-13 09:59:30 +09:00
|
|
|
waitsFor(function() {
|
2013-06-06 04:28:31 +09:00
|
|
|
return data !== undefined;
|
2013-09-25 01:30:54 +09:00
|
|
|
}, 20000);
|
2012-04-13 09:59:30 +09:00
|
|
|
}
|
|
|
|
describe('PDFJS', function() {
|
|
|
|
describe('getDocument', function() {
|
|
|
|
it('creates pdf doc from URL', function() {
|
|
|
|
var promise = PDFJS.getDocument(basicApiUrl);
|
2013-06-06 04:28:31 +09:00
|
|
|
waitsForPromise(promise, function(data) {
|
2012-04-13 09:59:30 +09:00
|
|
|
expect(true).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
/*
|
|
|
|
it('creates pdf doc from typed array', function() {
|
|
|
|
// TODO
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('PDFDocument', function() {
|
|
|
|
var promise = PDFJS.getDocument(basicApiUrl);
|
|
|
|
var doc;
|
2013-06-06 04:28:31 +09:00
|
|
|
waitsForPromise(promise, function(data) {
|
|
|
|
doc = data;
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|
|
|
|
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);
|
2013-06-06 04:28:31 +09:00
|
|
|
waitsForPromise(promise, function(data) {
|
2012-04-13 09:59:30 +09:00
|
|
|
expect(true).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
2014-03-19 18:17:58 +09:00
|
|
|
it('gets page index', function() {
|
|
|
|
// reference to second page
|
|
|
|
var ref = {num: 17, gen: 0};
|
|
|
|
var promise = doc.getPageIndex(ref);
|
|
|
|
waitsForPromise(promise, function(pageIndex) {
|
|
|
|
expect(pageIndex).toEqual(1);
|
|
|
|
});
|
|
|
|
});
|
2012-04-13 09:59:30 +09:00
|
|
|
it('gets destinations', function() {
|
|
|
|
var promise = doc.getDestinations();
|
2013-06-06 04:28:31 +09:00
|
|
|
waitsForPromise(promise, function(data) {
|
2014-05-14 19:54:18 +09:00
|
|
|
expect(data).toEqual({ chapter1: [{ gen: 0, num: 17 }, { name: 'XYZ' },
|
|
|
|
0, 841.89, null] });
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|
|
|
|
});
|
2014-05-19 06:35:29 +09:00
|
|
|
it('gets attachments', function() {
|
|
|
|
var promise = doc.getAttachments();
|
|
|
|
waitsForPromise(promise, function (data) {
|
|
|
|
expect(data).toEqual(null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('gets javascript', function() {
|
|
|
|
var promise = doc.getJavaScript();
|
|
|
|
waitsForPromise(promise, function (data) {
|
|
|
|
expect(data).toEqual([]);
|
|
|
|
});
|
|
|
|
});
|
2012-04-13 09:59:30 +09:00
|
|
|
it('gets outline', function() {
|
|
|
|
var promise = doc.getOutline();
|
2013-06-06 04:28:31 +09:00
|
|
|
waitsForPromise(promise, function(outline) {
|
2012-04-13 09:59:30 +09:00
|
|
|
// 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();
|
2013-06-06 04:28:31 +09:00
|
|
|
waitsForPromise(promise, function(metadata) {
|
2012-04-13 09:59:30 +09:00
|
|
|
expect(metadata.info['Title']).toEqual('Basic API Test');
|
|
|
|
expect(metadata.metadata.get('dc:title')).toEqual('Basic API Test');
|
|
|
|
});
|
|
|
|
});
|
2014-05-14 18:57:48 +09:00
|
|
|
it('gets data', function() {
|
|
|
|
var promise = doc.getData();
|
|
|
|
waitsForPromise(promise, function (data) {
|
|
|
|
expect(true).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
2014-05-19 06:35:29 +09:00
|
|
|
it('gets filesize in bytes', function() {
|
|
|
|
var promise = doc.getDownloadInfo();
|
|
|
|
waitsForPromise(promise, function (data) {
|
|
|
|
expect(data.length).toEqual(105779);
|
|
|
|
});
|
|
|
|
});
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|
|
|
|
describe('Page', function() {
|
2014-01-04 09:17:05 +09:00
|
|
|
var resolvePromise;
|
|
|
|
var promise = new Promise(function (resolve) {
|
|
|
|
resolvePromise = resolve;
|
|
|
|
});
|
2012-04-13 09:59:30 +09:00
|
|
|
PDFJS.getDocument(basicApiUrl).then(function(doc) {
|
|
|
|
doc.getPage(1).then(function(data) {
|
2014-01-04 09:17:05 +09:00
|
|
|
resolvePromise(data);
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
var page;
|
2013-06-06 04:28:31 +09:00
|
|
|
waitsForPromise(promise, function(data) {
|
|
|
|
page = data;
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|
2013-06-06 04:28:31 +09:00
|
|
|
|
2012-04-13 09:59:30 +09:00
|
|
|
it('gets ref', function() {
|
|
|
|
expect(page.ref).toEqual({num: 15, gen: 0});
|
|
|
|
});
|
2014-06-17 03:35:38 +09:00
|
|
|
|
|
|
|
it('gets operator list', function() {
|
|
|
|
var promise = page.getOperatorList();
|
|
|
|
waitsForPromise(promise, function (oplist) {
|
|
|
|
expect(!!oplist.fnArray).toEqual(true);
|
|
|
|
expect(!!oplist.argsArray).toEqual(true);
|
|
|
|
expect(oplist.lastChunk).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
2012-04-13 09:59:30 +09:00
|
|
|
// TODO rotate
|
|
|
|
// TODO viewport
|
|
|
|
// TODO annotaions
|
|
|
|
// TOOD text content
|
|
|
|
});
|
|
|
|
});
|