2017-01-10 01:40:57 +09:00
|
|
|
/* Copyright 2017 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2017-04-17 05:30:27 +09:00
|
|
|
|
2017-05-16 20:01:03 +09:00
|
|
|
import {
|
2019-02-17 20:34:37 +09:00
|
|
|
buildGetDocumentParams, DOMFileReaderFactory, NodeCanvasFactory,
|
|
|
|
NodeFileReaderFactory, TEST_PDFS_PATH
|
2017-05-16 20:01:03 +09:00
|
|
|
} from './test_utils';
|
2017-04-17 05:30:27 +09:00
|
|
|
import {
|
2019-04-14 20:13:59 +09:00
|
|
|
createPromiseCapability, FontType, InvalidPDFException, isEmptyObj,
|
|
|
|
MissingPDFException, OPS, PasswordException, PasswordResponses,
|
|
|
|
PermissionFlag, StreamType
|
2017-04-17 05:30:27 +09:00
|
|
|
} from '../../src/shared/util';
|
|
|
|
import {
|
2018-06-25 20:19:29 +09:00
|
|
|
DOMCanvasFactory, RenderingCancelledException, StatTimer
|
2019-02-23 23:41:02 +09:00
|
|
|
} from '../../src/display/display_utils';
|
2017-04-09 00:09:54 +09:00
|
|
|
import {
|
2018-02-14 22:49:24 +09:00
|
|
|
getDocument, PDFDataRangeTransport, PDFDocumentProxy, PDFPageProxy, PDFWorker
|
2017-04-09 00:09:54 +09:00
|
|
|
} from '../../src/display/api';
|
2018-02-14 22:49:24 +09:00
|
|
|
import { GlobalWorkerOptions } from '../../src/display/worker_options';
|
2019-11-10 23:10:18 +09:00
|
|
|
import { isNodeJS } from '../../src/shared/is_node';
|
2018-07-24 22:02:14 +09:00
|
|
|
import { Metadata } from '../../src/display/metadata';
|
2017-01-10 01:40:57 +09:00
|
|
|
|
2012-04-13 09:59:30 +09:00
|
|
|
describe('api', function() {
|
2017-04-09 00:09:54 +09:00
|
|
|
let basicApiFileName = 'basicapi.pdf';
|
|
|
|
let basicApiFileLength = 105779; // bytes
|
|
|
|
let basicApiGetDocumentParams = buildGetDocumentParams(basicApiFileName);
|
|
|
|
|
|
|
|
let CanvasFactory;
|
2017-03-13 21:56:59 +09:00
|
|
|
|
|
|
|
beforeAll(function(done) {
|
2019-11-11 00:42:46 +09:00
|
|
|
if (isNodeJS) {
|
2019-02-11 03:29:38 +09:00
|
|
|
CanvasFactory = new NodeCanvasFactory();
|
2017-04-09 00:09:54 +09:00
|
|
|
} else {
|
|
|
|
CanvasFactory = new DOMCanvasFactory();
|
|
|
|
}
|
2017-03-13 21:56:59 +09:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2017-04-09 00:09:54 +09:00
|
|
|
afterAll(function(done) {
|
2017-03-13 21:56:59 +09:00
|
|
|
CanvasFactory = null;
|
2017-04-09 00:09:54 +09:00
|
|
|
done();
|
2017-03-13 21:56:59 +09:00
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
|
2016-02-10 05:55:11 +09:00
|
|
|
function waitSome(callback) {
|
|
|
|
var WAIT_TIMEOUT = 10;
|
|
|
|
setTimeout(function () {
|
|
|
|
callback();
|
|
|
|
}, WAIT_TIMEOUT);
|
2014-08-24 04:08:27 +09:00
|
|
|
}
|
2015-10-17 23:08:10 +09:00
|
|
|
|
2018-02-18 07:51:24 +09:00
|
|
|
describe('getDocument', function() {
|
|
|
|
it('creates pdf doc from URL', function(done) {
|
|
|
|
var loadingTask = getDocument(basicApiGetDocumentParams);
|
2015-10-17 23:08:10 +09:00
|
|
|
|
2018-02-18 07:51:24 +09:00
|
|
|
var progressReportedCapability = createPromiseCapability();
|
|
|
|
// Attach the callback that is used to report loading progress;
|
|
|
|
// similarly to how viewer.js works.
|
|
|
|
loadingTask.onProgress = function (progressData) {
|
2019-02-02 21:10:06 +09:00
|
|
|
if (!progressReportedCapability.settled) {
|
2018-02-18 07:51:24 +09:00
|
|
|
progressReportedCapability.resolve(progressData);
|
|
|
|
}
|
|
|
|
};
|
2015-10-17 23:08:10 +09:00
|
|
|
|
2018-02-18 07:51:24 +09:00
|
|
|
var promises = [
|
|
|
|
progressReportedCapability.promise,
|
|
|
|
loadingTask.promise
|
|
|
|
];
|
|
|
|
Promise.all(promises).then(function (data) {
|
2018-08-04 02:11:35 +09:00
|
|
|
expect((data[0].loaded / data[0].total) >= 0).toEqual(true);
|
2018-02-18 07:51:24 +09:00
|
|
|
expect(data[1] instanceof PDFDocumentProxy).toEqual(true);
|
|
|
|
expect(loadingTask).toEqual(data[1].loadingTask);
|
|
|
|
loadingTask.destroy().then(done);
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2018-02-18 07:51:24 +09:00
|
|
|
});
|
|
|
|
it('creates pdf doc from URL and aborts before worker initialized',
|
|
|
|
function(done) {
|
|
|
|
var loadingTask = getDocument(basicApiGetDocumentParams);
|
|
|
|
let destroyed = loadingTask.destroy();
|
2017-05-10 07:21:09 +09:00
|
|
|
|
2018-02-18 07:51:24 +09:00
|
|
|
loadingTask.promise.then(function(reason) {
|
|
|
|
done.fail('shall fail loading');
|
|
|
|
}).catch(function (reason) {
|
|
|
|
expect(true).toEqual(true);
|
|
|
|
destroyed.then(done);
|
2015-10-21 07:45:55 +09:00
|
|
|
});
|
2018-02-18 07:51:24 +09:00
|
|
|
});
|
|
|
|
it('creates pdf doc from URL and aborts loading after worker initialized',
|
|
|
|
function(done) {
|
|
|
|
var loadingTask = getDocument(basicApiGetDocumentParams);
|
|
|
|
// This can be somewhat random -- we cannot guarantee perfect
|
|
|
|
// 'Terminate' message to the worker before/after setting up pdfManager.
|
|
|
|
var destroyed = loadingTask._worker.promise.then(function () {
|
|
|
|
return loadingTask.destroy();
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|
2018-02-18 07:51:24 +09:00
|
|
|
destroyed.then(function (data) {
|
|
|
|
expect(true).toEqual(true);
|
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2018-02-18 07:51:24 +09:00
|
|
|
});
|
|
|
|
it('creates pdf doc from typed array', function(done) {
|
2019-02-17 20:34:37 +09:00
|
|
|
let typedArrayPdfPromise;
|
2019-11-11 00:42:46 +09:00
|
|
|
if (isNodeJS) {
|
2019-02-17 20:34:37 +09:00
|
|
|
typedArrayPdfPromise = NodeFileReaderFactory.fetch({
|
2018-02-18 07:51:24 +09:00
|
|
|
path: TEST_PDFS_PATH.node + basicApiFileName,
|
|
|
|
});
|
|
|
|
} else {
|
2019-02-17 20:34:37 +09:00
|
|
|
typedArrayPdfPromise = DOMFileReaderFactory.fetch({
|
|
|
|
path: TEST_PDFS_PATH.dom + basicApiFileName,
|
|
|
|
});
|
2018-02-18 07:51:24 +09:00
|
|
|
}
|
2014-08-15 23:04:39 +09:00
|
|
|
|
2019-02-17 20:34:37 +09:00
|
|
|
typedArrayPdfPromise.then((typedArrayPdf) => {
|
|
|
|
// Sanity check to make sure that we fetched the entire PDF file.
|
|
|
|
expect(typedArrayPdf.length).toEqual(basicApiFileLength);
|
Ensure that `onProgress` is always called when the entire PDF file has been loaded, regardless of how it was fetched (issue 10160)
*Please note:* I'm totally fine with this patch being rejected, and the issue closed as WONTFIX; however these changes should address the issue if that's desired.
From a conceptual point of view, reporting loading progress doesn't really make a lot of sense for PDF files opened by passing raw binary data directly to `getDocument` (since obviously *all* data was loaded).
This is compared to PDF files loaded via e.g. `XMLHttpRequest` or the Fetch API, where the entire PDF file isn't available from the start and knowing the loading progress makes total sense.
However I can certainly see why the current API could be considered inconsistent, which isn't great, since a registered `onProgress` callback will never be called for certain `getDocument` calls.
The simplest solution to this inconsistency thus seem to be to ensure that `onProgress` is always called when handling the `DataLoaded` message, since that will *always* be dispatched[1] from the worker-thread.
---
[1] Note that this isn't guaranteed to happen, since setting `disableAutoFetch = true` often prevents the *entire* file from ever loading. However, this isn't relevant for the issue at hand, and is a well-known consequence of using `disableAutoFetch = true`; note how the default viewer even has a specialized code-path for hiding the loadingBar.
2018-10-16 20:24:02 +09:00
|
|
|
|
2019-02-17 20:34:37 +09:00
|
|
|
const loadingTask = getDocument(typedArrayPdf);
|
Ensure that `onProgress` is always called when the entire PDF file has been loaded, regardless of how it was fetched (issue 10160)
*Please note:* I'm totally fine with this patch being rejected, and the issue closed as WONTFIX; however these changes should address the issue if that's desired.
From a conceptual point of view, reporting loading progress doesn't really make a lot of sense for PDF files opened by passing raw binary data directly to `getDocument` (since obviously *all* data was loaded).
This is compared to PDF files loaded via e.g. `XMLHttpRequest` or the Fetch API, where the entire PDF file isn't available from the start and knowing the loading progress makes total sense.
However I can certainly see why the current API could be considered inconsistent, which isn't great, since a registered `onProgress` callback will never be called for certain `getDocument` calls.
The simplest solution to this inconsistency thus seem to be to ensure that `onProgress` is always called when handling the `DataLoaded` message, since that will *always* be dispatched[1] from the worker-thread.
---
[1] Note that this isn't guaranteed to happen, since setting `disableAutoFetch = true` often prevents the *entire* file from ever loading. However, this isn't relevant for the issue at hand, and is a well-known consequence of using `disableAutoFetch = true`; note how the default viewer even has a specialized code-path for hiding the loadingBar.
2018-10-16 20:24:02 +09:00
|
|
|
|
2019-02-17 20:34:37 +09:00
|
|
|
const progressReportedCapability = createPromiseCapability();
|
|
|
|
loadingTask.onProgress = function(data) {
|
|
|
|
progressReportedCapability.resolve(data);
|
|
|
|
};
|
Ensure that `onProgress` is always called when the entire PDF file has been loaded, regardless of how it was fetched (issue 10160)
*Please note:* I'm totally fine with this patch being rejected, and the issue closed as WONTFIX; however these changes should address the issue if that's desired.
From a conceptual point of view, reporting loading progress doesn't really make a lot of sense for PDF files opened by passing raw binary data directly to `getDocument` (since obviously *all* data was loaded).
This is compared to PDF files loaded via e.g. `XMLHttpRequest` or the Fetch API, where the entire PDF file isn't available from the start and knowing the loading progress makes total sense.
However I can certainly see why the current API could be considered inconsistent, which isn't great, since a registered `onProgress` callback will never be called for certain `getDocument` calls.
The simplest solution to this inconsistency thus seem to be to ensure that `onProgress` is always called when handling the `DataLoaded` message, since that will *always* be dispatched[1] from the worker-thread.
---
[1] Note that this isn't guaranteed to happen, since setting `disableAutoFetch = true` often prevents the *entire* file from ever loading. However, this isn't relevant for the issue at hand, and is a well-known consequence of using `disableAutoFetch = true`; note how the default viewer even has a specialized code-path for hiding the loadingBar.
2018-10-16 20:24:02 +09:00
|
|
|
|
2019-02-17 20:34:37 +09:00
|
|
|
return Promise.all([
|
|
|
|
loadingTask.promise,
|
|
|
|
progressReportedCapability.promise,
|
|
|
|
]).then(function(data) {
|
|
|
|
expect(data[0] instanceof PDFDocumentProxy).toEqual(true);
|
|
|
|
expect(data[1].loaded / data[1].total).toEqual(1);
|
|
|
|
|
|
|
|
loadingTask.destroy().then(done);
|
|
|
|
});
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2018-02-18 07:51:24 +09:00
|
|
|
});
|
|
|
|
it('creates pdf doc from invalid PDF file', function(done) {
|
|
|
|
// A severely corrupt PDF file (even Adobe Reader fails to open it).
|
|
|
|
var loadingTask = getDocument(buildGetDocumentParams('bug1020226.pdf'));
|
|
|
|
loadingTask.promise.then(function () {
|
|
|
|
done.fail('shall fail loading');
|
2019-12-09 23:00:45 +09:00
|
|
|
}).catch(function(reason) {
|
|
|
|
expect(reason instanceof InvalidPDFException).toEqual(true);
|
|
|
|
expect(reason.message).toEqual('Invalid PDF structure.');
|
|
|
|
|
2018-02-18 07:51:24 +09:00
|
|
|
loadingTask.destroy().then(done);
|
2015-10-03 01:04:08 +09:00
|
|
|
});
|
2018-02-18 07:51:24 +09:00
|
|
|
});
|
|
|
|
it('creates pdf doc from non-existent URL', function(done) {
|
|
|
|
var loadingTask = getDocument(
|
|
|
|
buildGetDocumentParams('non-existent.pdf'));
|
|
|
|
loadingTask.promise.then(function(error) {
|
|
|
|
done.fail('shall fail loading');
|
|
|
|
}).catch(function (error) {
|
|
|
|
expect(error instanceof MissingPDFException).toEqual(true);
|
|
|
|
loadingTask.destroy().then(done);
|
2014-09-08 00:39:49 +09:00
|
|
|
});
|
2018-02-18 07:51:24 +09:00
|
|
|
});
|
|
|
|
it('creates pdf doc from PDF file protected with user and owner password',
|
|
|
|
function (done) {
|
|
|
|
var loadingTask = getDocument(buildGetDocumentParams('pr6531_1.pdf'));
|
2015-10-17 01:48:26 +09:00
|
|
|
|
2018-02-18 07:51:24 +09:00
|
|
|
var passwordNeededCapability = createPromiseCapability();
|
|
|
|
var passwordIncorrectCapability = createPromiseCapability();
|
|
|
|
// Attach the callback that is used to request a password;
|
|
|
|
// similarly to how viewer.js handles passwords.
|
|
|
|
loadingTask.onPassword = function (updatePassword, reason) {
|
|
|
|
if (reason === PasswordResponses.NEED_PASSWORD &&
|
2019-02-02 21:10:06 +09:00
|
|
|
!passwordNeededCapability.settled) {
|
2018-02-18 07:51:24 +09:00
|
|
|
passwordNeededCapability.resolve();
|
2015-10-17 01:48:26 +09:00
|
|
|
|
2018-02-18 07:51:24 +09:00
|
|
|
updatePassword('qwerty'); // Provide an incorrect password.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (reason === PasswordResponses.INCORRECT_PASSWORD &&
|
2019-02-02 21:10:06 +09:00
|
|
|
!passwordIncorrectCapability.settled) {
|
2018-02-18 07:51:24 +09:00
|
|
|
passwordIncorrectCapability.resolve();
|
2015-10-17 23:08:10 +09:00
|
|
|
|
2018-02-18 07:51:24 +09:00
|
|
|
updatePassword('asdfasdf'); // Provide the correct password.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Shouldn't get here.
|
|
|
|
expect(false).toEqual(true);
|
|
|
|
};
|
2015-10-17 23:08:10 +09:00
|
|
|
|
2018-02-18 07:51:24 +09:00
|
|
|
var promises = [
|
|
|
|
passwordNeededCapability.promise,
|
|
|
|
passwordIncorrectCapability.promise,
|
|
|
|
loadingTask.promise
|
|
|
|
];
|
|
|
|
Promise.all(promises).then(function (data) {
|
|
|
|
expect(data[2] instanceof PDFDocumentProxy).toEqual(true);
|
|
|
|
loadingTask.destroy().then(done);
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2018-02-18 07:51:24 +09:00
|
|
|
});
|
|
|
|
it('creates pdf doc from PDF file protected with only a user password',
|
|
|
|
function (done) {
|
|
|
|
var filename = 'pr6531_2.pdf';
|
2015-10-17 01:48:26 +09:00
|
|
|
|
2018-02-18 07:51:24 +09:00
|
|
|
var passwordNeededLoadingTask = getDocument(
|
|
|
|
buildGetDocumentParams(filename, {
|
|
|
|
password: '',
|
|
|
|
}));
|
|
|
|
var result1 = passwordNeededLoadingTask.promise.then(function () {
|
|
|
|
done.fail('shall fail with no password');
|
|
|
|
return Promise.reject(new Error('loadingTask should be rejected'));
|
|
|
|
}, function (data) {
|
|
|
|
expect(data instanceof PasswordException).toEqual(true);
|
|
|
|
expect(data.code).toEqual(PasswordResponses.NEED_PASSWORD);
|
|
|
|
return passwordNeededLoadingTask.destroy();
|
|
|
|
});
|
2015-10-17 01:48:26 +09:00
|
|
|
|
2018-02-18 07:51:24 +09:00
|
|
|
var passwordIncorrectLoadingTask = getDocument(
|
|
|
|
buildGetDocumentParams(filename, {
|
|
|
|
password: 'qwerty',
|
|
|
|
}));
|
|
|
|
var result2 = passwordIncorrectLoadingTask.promise.then(function () {
|
|
|
|
done.fail('shall fail with wrong password');
|
|
|
|
return Promise.reject(new Error('loadingTask should be rejected'));
|
|
|
|
}, function (data) {
|
|
|
|
expect(data instanceof PasswordException).toEqual(true);
|
|
|
|
expect(data.code).toEqual(PasswordResponses.INCORRECT_PASSWORD);
|
|
|
|
return passwordIncorrectLoadingTask.destroy();
|
|
|
|
});
|
2015-10-17 01:48:26 +09:00
|
|
|
|
2018-02-18 07:51:24 +09:00
|
|
|
var passwordAcceptedLoadingTask = getDocument(
|
|
|
|
buildGetDocumentParams(filename, {
|
|
|
|
password: 'asdfasdf',
|
|
|
|
}));
|
|
|
|
var result3 = passwordAcceptedLoadingTask.promise.then(function (data) {
|
|
|
|
expect(data instanceof PDFDocumentProxy).toEqual(true);
|
|
|
|
return passwordAcceptedLoadingTask.destroy();
|
2015-10-17 01:48:26 +09:00
|
|
|
});
|
2018-02-18 07:51:24 +09:00
|
|
|
Promise.all([result1, result2, result3]).then(function () {
|
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2018-02-18 07:51:24 +09:00
|
|
|
});
|
2016-12-31 21:59:07 +09:00
|
|
|
|
2018-02-18 07:51:24 +09:00
|
|
|
it('creates pdf doc from password protected PDF file and aborts/throws ' +
|
|
|
|
'in the onPassword callback (issue 7806)', function (done) {
|
|
|
|
var filename = 'issue3371.pdf';
|
2017-04-09 00:09:54 +09:00
|
|
|
|
2018-02-18 07:51:24 +09:00
|
|
|
var passwordNeededLoadingTask = getDocument(
|
|
|
|
buildGetDocumentParams(filename));
|
|
|
|
var passwordIncorrectLoadingTask = getDocument(
|
|
|
|
buildGetDocumentParams(filename, {
|
|
|
|
password: 'qwerty',
|
|
|
|
}));
|
2016-12-31 21:59:07 +09:00
|
|
|
|
2018-02-18 07:51:24 +09:00
|
|
|
let passwordNeededDestroyed;
|
|
|
|
passwordNeededLoadingTask.onPassword = function (callback, reason) {
|
|
|
|
if (reason === PasswordResponses.NEED_PASSWORD) {
|
|
|
|
passwordNeededDestroyed = passwordNeededLoadingTask.destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Shouldn't get here.
|
|
|
|
expect(false).toEqual(true);
|
|
|
|
};
|
|
|
|
var result1 = passwordNeededLoadingTask.promise.then(function () {
|
|
|
|
done.fail('shall fail since the loadingTask should be destroyed');
|
|
|
|
return Promise.reject(new Error('loadingTask should be rejected'));
|
|
|
|
}, function (reason) {
|
|
|
|
expect(reason instanceof PasswordException).toEqual(true);
|
|
|
|
expect(reason.code).toEqual(PasswordResponses.NEED_PASSWORD);
|
|
|
|
return passwordNeededDestroyed;
|
|
|
|
});
|
2016-12-31 21:59:07 +09:00
|
|
|
|
2018-02-18 07:51:24 +09:00
|
|
|
passwordIncorrectLoadingTask.onPassword = function (callback, reason) {
|
|
|
|
if (reason === PasswordResponses.INCORRECT_PASSWORD) {
|
|
|
|
throw new Error('Incorrect password');
|
|
|
|
}
|
|
|
|
// Shouldn't get here.
|
|
|
|
expect(false).toEqual(true);
|
|
|
|
};
|
|
|
|
var result2 = passwordIncorrectLoadingTask.promise.then(function () {
|
|
|
|
done.fail('shall fail since the onPassword callback should throw');
|
|
|
|
return Promise.reject(new Error('loadingTask should be rejected'));
|
|
|
|
}, function (reason) {
|
|
|
|
expect(reason instanceof PasswordException).toEqual(true);
|
|
|
|
expect(reason.code).toEqual(PasswordResponses.INCORRECT_PASSWORD);
|
|
|
|
return passwordIncorrectLoadingTask.destroy();
|
|
|
|
});
|
2016-12-31 21:59:07 +09:00
|
|
|
|
2018-02-18 07:51:24 +09:00
|
|
|
Promise.all([result1, result2]).then(function () {
|
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|
2019-12-09 23:00:45 +09:00
|
|
|
|
|
|
|
it('creates pdf doc from empty typed array', function(done) {
|
|
|
|
const loadingTask = getDocument(new Uint8Array(0));
|
|
|
|
|
|
|
|
loadingTask.promise.then(function() {
|
|
|
|
done.fail('shall not open empty file');
|
|
|
|
}, function(reason) {
|
|
|
|
expect(reason instanceof InvalidPDFException);
|
|
|
|
expect(reason.message).toEqual(
|
|
|
|
'The PDF file is empty, i.e. its size is zero bytes.');
|
|
|
|
|
|
|
|
loadingTask.destroy().then(done);
|
|
|
|
});
|
|
|
|
});
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|
2018-02-18 07:51:24 +09:00
|
|
|
|
2015-10-28 02:55:15 +09:00
|
|
|
describe('PDFWorker', function() {
|
2016-03-29 23:34:13 +09:00
|
|
|
it('worker created or destroyed', function (done) {
|
2019-11-11 00:42:46 +09:00
|
|
|
if (isNodeJS) {
|
2018-03-18 03:56:39 +09:00
|
|
|
pending('Worker is not supported in Node.js.');
|
|
|
|
}
|
|
|
|
|
2018-02-15 00:03:54 +09:00
|
|
|
var worker = new PDFWorker({ name: 'test1', });
|
2016-03-29 23:34:13 +09:00
|
|
|
worker.promise.then(function () {
|
2015-10-28 02:55:15 +09:00
|
|
|
expect(worker.name).toEqual('test1');
|
|
|
|
expect(!!worker.port).toEqual(true);
|
|
|
|
expect(worker.destroyed).toEqual(false);
|
|
|
|
expect(!!worker._webWorker).toEqual(true);
|
|
|
|
expect(worker.port === worker._webWorker).toEqual(true);
|
|
|
|
|
|
|
|
worker.destroy();
|
|
|
|
expect(!!worker.port).toEqual(false);
|
|
|
|
expect(worker.destroyed).toEqual(true);
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2015-10-28 02:55:15 +09:00
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
it('worker created or destroyed by getDocument', function (done) {
|
2019-11-11 00:42:46 +09:00
|
|
|
if (isNodeJS) {
|
2018-03-18 03:56:39 +09:00
|
|
|
pending('Worker is not supported in Node.js.');
|
|
|
|
}
|
|
|
|
|
2017-04-09 00:09:54 +09:00
|
|
|
var loadingTask = getDocument(basicApiGetDocumentParams);
|
2015-10-28 02:55:15 +09:00
|
|
|
var worker;
|
2016-03-29 23:34:13 +09:00
|
|
|
loadingTask.promise.then(function () {
|
2015-10-28 02:55:15 +09:00
|
|
|
worker = loadingTask._worker;
|
|
|
|
expect(!!worker).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
var destroyPromise = loadingTask.promise.then(function () {
|
|
|
|
return loadingTask.destroy();
|
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
destroyPromise.then(function () {
|
2015-10-28 02:55:15 +09:00
|
|
|
var destroyedWorker = loadingTask._worker;
|
|
|
|
expect(!!destroyedWorker).toEqual(false);
|
|
|
|
expect(worker.destroyed).toEqual(true);
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2015-10-28 02:55:15 +09:00
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
it('worker created and can be used in getDocument', function (done) {
|
2019-11-11 00:42:46 +09:00
|
|
|
if (isNodeJS) {
|
2018-03-18 03:56:39 +09:00
|
|
|
pending('Worker is not supported in Node.js.');
|
|
|
|
}
|
|
|
|
|
2018-02-15 00:03:54 +09:00
|
|
|
var worker = new PDFWorker({ name: 'test1', });
|
2017-04-09 00:09:54 +09:00
|
|
|
var loadingTask = getDocument(
|
|
|
|
buildGetDocumentParams(basicApiFileName, {
|
|
|
|
worker,
|
|
|
|
}));
|
2016-03-29 23:34:13 +09:00
|
|
|
loadingTask.promise.then(function () {
|
2015-10-28 02:55:15 +09:00
|
|
|
var docWorker = loadingTask._worker;
|
|
|
|
expect(!!docWorker).toEqual(false);
|
|
|
|
// checking is the same port is used in the MessageHandler
|
|
|
|
var messageHandlerPort = loadingTask._transport.messageHandler.comObj;
|
|
|
|
expect(messageHandlerPort === worker.port).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
var destroyPromise = loadingTask.promise.then(function () {
|
|
|
|
return loadingTask.destroy();
|
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
destroyPromise.then(function () {
|
2015-10-28 02:55:15 +09:00
|
|
|
expect(worker.destroyed).toEqual(false);
|
|
|
|
worker.destroy();
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2015-10-28 02:55:15 +09:00
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
it('creates more than one worker', function (done) {
|
2019-11-11 00:42:46 +09:00
|
|
|
if (isNodeJS) {
|
2018-03-18 03:56:39 +09:00
|
|
|
pending('Worker is not supported in Node.js.');
|
|
|
|
}
|
|
|
|
|
2018-02-15 00:03:54 +09:00
|
|
|
var worker1 = new PDFWorker({ name: 'test1', });
|
|
|
|
var worker2 = new PDFWorker({ name: 'test2', });
|
|
|
|
var worker3 = new PDFWorker({ name: 'test3', });
|
2015-10-28 02:55:15 +09:00
|
|
|
var ready = Promise.all([worker1.promise, worker2.promise,
|
|
|
|
worker3.promise]);
|
2016-03-29 23:34:13 +09:00
|
|
|
ready.then(function () {
|
2015-10-28 02:55:15 +09:00
|
|
|
expect(worker1.port !== worker2.port &&
|
|
|
|
worker1.port !== worker3.port &&
|
|
|
|
worker2.port !== worker3.port).toEqual(true);
|
|
|
|
worker1.destroy();
|
|
|
|
worker2.destroy();
|
|
|
|
worker3.destroy();
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2015-10-28 02:55:15 +09:00
|
|
|
});
|
2018-01-29 23:58:40 +09:00
|
|
|
it('gets current workerSrc', function() {
|
2019-11-11 00:42:46 +09:00
|
|
|
if (isNodeJS) {
|
2018-03-18 03:56:39 +09:00
|
|
|
pending('Worker is not supported in Node.js.');
|
|
|
|
}
|
|
|
|
|
2018-01-29 23:58:40 +09:00
|
|
|
let workerSrc = PDFWorker.getWorkerSrc();
|
|
|
|
expect(typeof workerSrc).toEqual('string');
|
2018-02-14 22:49:24 +09:00
|
|
|
expect(workerSrc).toEqual(GlobalWorkerOptions.workerSrc);
|
2018-01-29 23:58:40 +09:00
|
|
|
});
|
2015-10-28 02:55:15 +09:00
|
|
|
});
|
2012-04-13 09:59:30 +09:00
|
|
|
describe('PDFDocument', function() {
|
2016-01-21 07:57:17 +09:00
|
|
|
var loadingTask;
|
2012-04-13 09:59:30 +09:00
|
|
|
var doc;
|
2016-01-21 07:57:17 +09:00
|
|
|
|
2016-03-30 22:24:57 +09:00
|
|
|
beforeAll(function(done) {
|
2017-04-09 00:09:54 +09:00
|
|
|
loadingTask = getDocument(basicApiGetDocumentParams);
|
2016-03-29 23:34:13 +09:00
|
|
|
loadingTask.promise.then(function(data) {
|
2016-01-21 07:57:17 +09:00
|
|
|
doc = data;
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2016-01-21 07:57:17 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-10 07:21:09 +09:00
|
|
|
afterAll(function(done) {
|
|
|
|
loadingTask.destroy().then(done);
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|
2016-01-21 07:57:17 +09:00
|
|
|
|
2012-04-13 09:59:30 +09:00
|
|
|
it('gets number of pages', function() {
|
|
|
|
expect(doc.numPages).toEqual(3);
|
|
|
|
});
|
|
|
|
it('gets fingerprint', function() {
|
2019-07-15 18:19:17 +09:00
|
|
|
expect(doc.fingerprint).toEqual('ea8b35919d6279a369e835bde778611b');
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
it('gets page', function(done) {
|
2012-04-13 09:59:30 +09:00
|
|
|
var promise = doc.getPage(1);
|
2016-03-29 23:34:13 +09:00
|
|
|
promise.then(function(data) {
|
2015-10-04 21:28:24 +09:00
|
|
|
expect(data instanceof PDFPageProxy).toEqual(true);
|
|
|
|
expect(data.pageIndex).toEqual(0);
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2015-10-04 21:28:24 +09:00
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
it('gets non-existent page', function(done) {
|
2016-09-05 21:43:16 +09:00
|
|
|
var outOfRangePromise = doc.getPage(100);
|
|
|
|
var nonIntegerPromise = doc.getPage(2.5);
|
|
|
|
var nonNumberPromise = doc.getPage('1');
|
|
|
|
|
|
|
|
outOfRangePromise = outOfRangePromise.then(function () {
|
|
|
|
throw new Error('shall fail for out-of-range pageNumber parameter');
|
|
|
|
}, function (reason) {
|
|
|
|
expect(reason instanceof Error).toEqual(true);
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|
2016-09-05 21:43:16 +09:00
|
|
|
nonIntegerPromise = nonIntegerPromise.then(function () {
|
|
|
|
throw new Error('shall fail for non-integer pageNumber parameter');
|
|
|
|
}, function (reason) {
|
|
|
|
expect(reason instanceof Error).toEqual(true);
|
|
|
|
});
|
|
|
|
nonNumberPromise = nonNumberPromise.then(function () {
|
|
|
|
throw new Error('shall fail for non-number pageNumber parameter');
|
|
|
|
}, function (reason) {
|
|
|
|
expect(reason instanceof Error).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
Promise.all([outOfRangePromise, nonIntegerPromise, nonNumberPromise]).
|
|
|
|
then(function () {
|
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
it('gets page index', function(done) {
|
2014-03-19 18:17:58 +09:00
|
|
|
// reference to second page
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
var ref = { num: 17, gen: 0, };
|
2014-03-19 18:17:58 +09:00
|
|
|
var promise = doc.getPageIndex(ref);
|
2016-03-29 23:34:13 +09:00
|
|
|
promise.then(function(pageIndex) {
|
2014-03-19 18:17:58 +09:00
|
|
|
expect(pageIndex).toEqual(1);
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2014-03-19 18:17:58 +09:00
|
|
|
});
|
2016-05-16 23:28:25 +09:00
|
|
|
it('gets invalid page index', function (done) {
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
var ref = { num: 3, gen: 0, }; // Reference to a font dictionary.
|
2016-05-16 23:28:25 +09:00
|
|
|
var promise = doc.getPageIndex(ref);
|
|
|
|
promise.then(function () {
|
|
|
|
done.fail('shall fail for invalid page reference.');
|
2016-09-05 21:43:16 +09:00
|
|
|
}).catch(function (reason) {
|
|
|
|
expect(reason instanceof Error).toEqual(true);
|
2016-05-16 23:28:25 +09:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2016-03-29 22:46:21 +09:00
|
|
|
|
|
|
|
it('gets destinations, from /Dests dictionary', function(done) {
|
2012-04-13 09:59:30 +09:00
|
|
|
var promise = doc.getDestinations();
|
2016-03-29 23:34:13 +09:00
|
|
|
promise.then(function(data) {
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
expect(data).toEqual({
|
|
|
|
chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
|
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|
2016-03-29 22:46:21 +09:00
|
|
|
it('gets a destination, from /Dests dictionary', function(done) {
|
2014-10-05 22:56:40 +09:00
|
|
|
var promise = doc.getDestination('chapter1');
|
2016-03-29 23:34:13 +09:00
|
|
|
promise.then(function(data) {
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
expect(data).toEqual([{ gen: 0, num: 17, }, { name: 'XYZ', },
|
2014-10-05 22:56:40 +09:00
|
|
|
0, 841.89, null]);
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2014-10-05 22:56:40 +09:00
|
|
|
});
|
2016-03-29 22:46:21 +09:00
|
|
|
it('gets a non-existent destination, from /Dests dictionary',
|
|
|
|
function(done) {
|
2015-07-08 04:48:57 +09:00
|
|
|
var promise = doc.getDestination('non-existent-named-destination');
|
2016-03-29 23:34:13 +09:00
|
|
|
promise.then(function(data) {
|
2015-07-08 04:48:57 +09:00
|
|
|
expect(data).toEqual(null);
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2015-07-08 04:48:57 +09:00
|
|
|
});
|
2016-03-29 22:46:21 +09:00
|
|
|
|
|
|
|
it('gets destinations, from /Names (NameTree) dictionary', function(done) {
|
2017-04-09 00:09:54 +09:00
|
|
|
var loadingTask = getDocument(buildGetDocumentParams('issue6204.pdf'));
|
2016-03-29 22:46:21 +09:00
|
|
|
var promise = loadingTask.promise.then(function (pdfDocument) {
|
|
|
|
return pdfDocument.getDestinations();
|
|
|
|
});
|
|
|
|
promise.then(function (destinations) {
|
|
|
|
expect(destinations).toEqual({
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
'Page.1': [{ num: 1, gen: 0, }, { name: 'XYZ', }, 0, 375, null],
|
|
|
|
'Page.2': [{ num: 6, gen: 0, }, { name: 'XYZ', }, 0, 375, null],
|
2016-03-29 22:46:21 +09:00
|
|
|
});
|
|
|
|
|
2017-05-10 07:21:09 +09:00
|
|
|
loadingTask.destroy().then(done);
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2016-03-29 22:46:21 +09:00
|
|
|
});
|
|
|
|
it('gets a destination, from /Names (NameTree) dictionary', function(done) {
|
2017-04-09 00:09:54 +09:00
|
|
|
var loadingTask = getDocument(buildGetDocumentParams('issue6204.pdf'));
|
2016-03-29 22:46:21 +09:00
|
|
|
var promise = loadingTask.promise.then(function (pdfDocument) {
|
|
|
|
return pdfDocument.getDestination('Page.1');
|
|
|
|
});
|
|
|
|
promise.then(function (destination) {
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
expect(destination).toEqual([{ num: 1, gen: 0, }, { name: 'XYZ', },
|
2016-03-29 22:46:21 +09:00
|
|
|
0, 375, null]);
|
|
|
|
|
2017-05-10 07:21:09 +09:00
|
|
|
loadingTask.destroy().then(done);
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2016-03-29 22:46:21 +09:00
|
|
|
});
|
|
|
|
it('gets a non-existent destination, from /Names (NameTree) dictionary',
|
|
|
|
function(done) {
|
2017-04-09 00:09:54 +09:00
|
|
|
var loadingTask = getDocument(buildGetDocumentParams('issue6204.pdf'));
|
2016-03-29 22:46:21 +09:00
|
|
|
var promise = loadingTask.promise.then(function (pdfDocument) {
|
|
|
|
return pdfDocument.getDestination('non-existent-named-destination');
|
|
|
|
});
|
|
|
|
promise.then(function (destination) {
|
|
|
|
expect(destination).toEqual(null);
|
|
|
|
|
2017-05-10 07:21:09 +09:00
|
|
|
loadingTask.destroy().then(done);
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2016-03-29 22:46:21 +09:00
|
|
|
});
|
|
|
|
|
2018-08-11 23:00:48 +09:00
|
|
|
it('gets non-string destination', function(done) {
|
|
|
|
let numberPromise = doc.getDestination(4.3);
|
|
|
|
let booleanPromise = doc.getDestination(true);
|
|
|
|
let arrayPromise = doc.getDestination([
|
|
|
|
{ num: 17, gen: 0, }, { name: 'XYZ', }, 0, 841.89, null]);
|
|
|
|
|
|
|
|
numberPromise = numberPromise.then(function() {
|
|
|
|
throw new Error('shall fail for non-string destination.');
|
|
|
|
}, function(reason) {
|
|
|
|
expect(reason instanceof Error).toEqual(true);
|
|
|
|
});
|
|
|
|
booleanPromise = booleanPromise.then(function() {
|
|
|
|
throw new Error('shall fail for non-string destination.');
|
|
|
|
}, function(reason) {
|
|
|
|
expect(reason instanceof Error).toEqual(true);
|
|
|
|
});
|
|
|
|
arrayPromise = arrayPromise.then(function() {
|
|
|
|
throw new Error('shall fail for non-string destination.');
|
|
|
|
}, function(reason) {
|
|
|
|
expect(reason instanceof Error).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
Promise.all([numberPromise, booleanPromise, arrayPromise]).then(
|
|
|
|
done, done.fail);
|
|
|
|
});
|
|
|
|
|
2016-03-29 23:34:13 +09:00
|
|
|
it('gets non-existent page labels', function (done) {
|
2015-12-26 05:57:08 +09:00
|
|
|
var promise = doc.getPageLabels();
|
2016-03-29 23:34:13 +09:00
|
|
|
promise.then(function (data) {
|
2015-12-26 05:57:08 +09:00
|
|
|
expect(data).toEqual(null);
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2015-12-26 05:57:08 +09:00
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
it('gets page labels', function (done) {
|
2015-12-26 05:57:08 +09:00
|
|
|
// PageLabels with Roman/Arabic numerals.
|
2017-04-09 00:09:54 +09:00
|
|
|
var loadingTask0 = getDocument(buildGetDocumentParams('bug793632.pdf'));
|
2016-01-27 07:01:38 +09:00
|
|
|
var promise0 = loadingTask0.promise.then(function (pdfDoc) {
|
2015-12-26 05:57:08 +09:00
|
|
|
return pdfDoc.getPageLabels();
|
|
|
|
});
|
2016-01-27 07:01:38 +09:00
|
|
|
|
2015-12-26 05:57:08 +09:00
|
|
|
// PageLabels with only a label prefix.
|
2017-04-09 00:09:54 +09:00
|
|
|
var loadingTask1 = getDocument(buildGetDocumentParams('issue1453.pdf'));
|
2016-01-27 07:01:38 +09:00
|
|
|
var promise1 = loadingTask1.promise.then(function (pdfDoc) {
|
2015-12-26 05:57:08 +09:00
|
|
|
return pdfDoc.getPageLabels();
|
|
|
|
});
|
2016-01-27 07:01:38 +09:00
|
|
|
|
2015-12-26 05:57:08 +09:00
|
|
|
// PageLabels identical to standard page numbering.
|
2017-04-09 00:09:54 +09:00
|
|
|
var loadingTask2 = getDocument(buildGetDocumentParams('rotation.pdf'));
|
2016-01-27 07:01:38 +09:00
|
|
|
var promise2 = loadingTask2.promise.then(function (pdfDoc) {
|
2015-12-26 05:57:08 +09:00
|
|
|
return pdfDoc.getPageLabels();
|
|
|
|
});
|
|
|
|
|
2016-11-04 03:48:08 +09:00
|
|
|
// PageLabels with bad "Prefix" entries.
|
2017-04-09 00:09:54 +09:00
|
|
|
var loadingTask3 = getDocument(
|
|
|
|
buildGetDocumentParams('bad-PageLabels.pdf'));
|
2016-11-04 03:48:08 +09:00
|
|
|
var promise3 = loadingTask3.promise.then(function (pdfDoc) {
|
|
|
|
return pdfDoc.getPageLabels();
|
|
|
|
});
|
|
|
|
|
|
|
|
Promise.all([promise0, promise1, promise2, promise3]).then(
|
|
|
|
function (pageLabels) {
|
2015-12-26 05:57:08 +09:00
|
|
|
expect(pageLabels[0]).toEqual(['i', 'ii', 'iii', '1']);
|
|
|
|
expect(pageLabels[1]).toEqual(['Front Page1']);
|
2016-01-27 07:01:38 +09:00
|
|
|
expect(pageLabels[2]).toEqual(['1', '2']);
|
2016-12-04 21:03:22 +09:00
|
|
|
expect(pageLabels[3]).toEqual(['X3']);
|
2016-01-27 07:01:38 +09:00
|
|
|
|
2017-05-10 07:21:09 +09:00
|
|
|
Promise.all([
|
|
|
|
loadingTask0.destroy(),
|
|
|
|
loadingTask1.destroy(),
|
|
|
|
loadingTask2.destroy(),
|
|
|
|
loadingTask3.destroy()
|
|
|
|
]).then(done);
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2015-12-26 05:57:08 +09:00
|
|
|
});
|
2016-07-02 20:13:30 +09:00
|
|
|
|
2019-04-03 20:48:18 +09:00
|
|
|
it('gets default page layout', function(done) {
|
|
|
|
var loadingTask = getDocument(buildGetDocumentParams('tracemonkey.pdf'));
|
|
|
|
|
|
|
|
loadingTask.promise.then(function(pdfDocument) {
|
|
|
|
return pdfDocument.getPageLayout();
|
|
|
|
}).then(function(mode) {
|
|
|
|
expect(mode).toEqual('');
|
|
|
|
|
|
|
|
loadingTask.destroy().then(done);
|
|
|
|
}).catch(done.fail);
|
|
|
|
});
|
|
|
|
it('gets non-default page layout', function(done) {
|
|
|
|
doc.getPageLayout().then(function(mode) {
|
|
|
|
expect(mode).toEqual('SinglePage');
|
|
|
|
done();
|
|
|
|
}).catch(done.fail);
|
|
|
|
});
|
|
|
|
|
2017-07-18 20:08:02 +09:00
|
|
|
it('gets default page mode', function(done) {
|
|
|
|
var loadingTask = getDocument(buildGetDocumentParams('tracemonkey.pdf'));
|
|
|
|
|
|
|
|
loadingTask.promise.then(function(pdfDocument) {
|
|
|
|
return pdfDocument.getPageMode();
|
|
|
|
}).then(function(mode) {
|
|
|
|
expect(mode).toEqual('UseNone');
|
|
|
|
|
|
|
|
loadingTask.destroy().then(done);
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2017-07-18 20:08:02 +09:00
|
|
|
});
|
|
|
|
it('gets non-default page mode', function(done) {
|
|
|
|
doc.getPageMode().then(function(mode) {
|
|
|
|
expect(mode).toEqual('UseOutlines');
|
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2017-07-18 20:08:02 +09:00
|
|
|
});
|
|
|
|
|
2019-04-14 20:13:59 +09:00
|
|
|
it('gets default viewer preferences', function(done) {
|
|
|
|
var loadingTask = getDocument(buildGetDocumentParams('tracemonkey.pdf'));
|
|
|
|
|
|
|
|
loadingTask.promise.then(function(pdfDocument) {
|
|
|
|
return pdfDocument.getViewerPreferences();
|
|
|
|
}).then(function(prefs) {
|
|
|
|
expect(typeof prefs === 'object' && prefs !== null &&
|
|
|
|
isEmptyObj(prefs)).toEqual(true);
|
|
|
|
|
|
|
|
loadingTask.destroy().then(done);
|
|
|
|
}).catch(done.fail);
|
|
|
|
});
|
|
|
|
it('gets non-default viewer preferences', function(done) {
|
|
|
|
doc.getViewerPreferences().then(function(prefs) {
|
|
|
|
expect(prefs).toEqual({
|
|
|
|
Direction: 'L2R',
|
|
|
|
});
|
|
|
|
done();
|
|
|
|
}).catch(done.fail);
|
|
|
|
});
|
|
|
|
|
2018-12-06 04:09:15 +09:00
|
|
|
it('gets default open action destination', function(done) {
|
|
|
|
var loadingTask = getDocument(buildGetDocumentParams('tracemonkey.pdf'));
|
|
|
|
|
|
|
|
loadingTask.promise.then(function(pdfDocument) {
|
|
|
|
return pdfDocument.getOpenActionDestination();
|
|
|
|
}).then(function(dest) {
|
|
|
|
expect(dest).toEqual(null);
|
|
|
|
|
|
|
|
loadingTask.destroy().then(done);
|
|
|
|
}).catch(done.fail);
|
|
|
|
});
|
|
|
|
it('gets non-default open action destination', function(done) {
|
|
|
|
doc.getOpenActionDestination().then(function(dest) {
|
|
|
|
expect(dest).toEqual([{ num: 15, gen: 0, }, { name: 'FitH', }, null]);
|
|
|
|
done();
|
|
|
|
}).catch(done.fail);
|
|
|
|
});
|
|
|
|
|
2016-07-02 20:13:30 +09:00
|
|
|
it('gets non-existent attachments', function(done) {
|
2014-05-19 06:35:29 +09:00
|
|
|
var promise = doc.getAttachments();
|
2016-03-29 23:34:13 +09:00
|
|
|
promise.then(function (data) {
|
2014-05-19 06:35:29 +09:00
|
|
|
expect(data).toEqual(null);
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2014-05-19 06:35:29 +09:00
|
|
|
});
|
2016-07-02 20:13:30 +09:00
|
|
|
it('gets attachments', function(done) {
|
2019-08-25 02:57:35 +09:00
|
|
|
var loadingTask = getDocument(buildGetDocumentParams('attachment.pdf'));
|
2016-07-02 20:13:30 +09:00
|
|
|
var promise = loadingTask.promise.then(function (pdfDoc) {
|
|
|
|
return pdfDoc.getAttachments();
|
|
|
|
});
|
|
|
|
promise.then(function (data) {
|
2019-08-25 02:57:35 +09:00
|
|
|
var attachment = data['foo.txt'];
|
|
|
|
expect(attachment.filename).toEqual('foo.txt');
|
|
|
|
expect(attachment.content).toEqual(
|
|
|
|
new Uint8Array([98, 97, 114, 32, 98, 97, 122, 32, 10]));
|
2016-07-02 20:13:30 +09:00
|
|
|
|
2017-05-10 07:21:09 +09:00
|
|
|
loadingTask.destroy().then(done);
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2016-07-02 20:13:30 +09:00
|
|
|
});
|
|
|
|
|
2016-03-29 23:34:13 +09:00
|
|
|
it('gets javascript', function(done) {
|
2014-05-19 06:35:29 +09:00
|
|
|
var promise = doc.getJavaScript();
|
2016-03-29 23:34:13 +09:00
|
|
|
promise.then(function (data) {
|
2017-10-16 05:13:58 +09:00
|
|
|
expect(data).toEqual(null);
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2014-05-19 06:35:29 +09:00
|
|
|
});
|
2015-07-21 01:25:02 +09:00
|
|
|
// Keep this in sync with the pattern in viewer.js. The pattern is used to
|
|
|
|
// detect whether or not to automatically start printing.
|
|
|
|
var viewerPrintRegExp = /\bprint\s*\(/;
|
2016-03-29 23:34:13 +09:00
|
|
|
it('gets javascript with printing instructions (Print action)',
|
|
|
|
function(done) {
|
2015-07-21 01:25:02 +09:00
|
|
|
// PDF document with "Print" Named action in OpenAction
|
2017-04-09 00:09:54 +09:00
|
|
|
var loadingTask = getDocument(buildGetDocumentParams('bug1001080.pdf'));
|
2016-01-21 07:57:17 +09:00
|
|
|
var promise = loadingTask.promise.then(function(doc) {
|
2015-07-21 01:25:02 +09:00
|
|
|
return doc.getJavaScript();
|
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
promise.then(function (data) {
|
2015-07-21 01:25:02 +09:00
|
|
|
expect(data).toEqual(['print({});']);
|
|
|
|
expect(data[0]).toMatch(viewerPrintRegExp);
|
2017-05-10 07:21:09 +09:00
|
|
|
loadingTask.destroy().then(done);
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2015-07-21 01:25:02 +09:00
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
it('gets javascript with printing instructions (JS action)',
|
|
|
|
function(done) {
|
2015-07-21 01:25:02 +09:00
|
|
|
// PDF document with "JavaScript" action in OpenAction
|
2017-04-09 00:09:54 +09:00
|
|
|
var loadingTask = getDocument(buildGetDocumentParams('issue6106.pdf'));
|
2016-01-21 07:57:17 +09:00
|
|
|
var promise = loadingTask.promise.then(function(doc) {
|
2015-07-21 01:25:02 +09:00
|
|
|
return doc.getJavaScript();
|
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
promise.then(function (data) {
|
2015-07-21 01:25:02 +09:00
|
|
|
expect(data).toEqual(
|
|
|
|
['this.print({bUI:true,bSilent:false,bShrinkToFit:true});']);
|
|
|
|
expect(data[0]).toMatch(viewerPrintRegExp);
|
2017-05-10 07:21:09 +09:00
|
|
|
loadingTask.destroy().then(done);
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2015-07-21 01:25:02 +09:00
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
it('gets non-existent outline', function(done) {
|
2017-04-09 00:09:54 +09:00
|
|
|
var loadingTask = getDocument(buildGetDocumentParams('tracemonkey.pdf'));
|
2016-02-14 07:13:01 +09:00
|
|
|
|
|
|
|
var promise = loadingTask.promise.then(function (pdfDocument) {
|
|
|
|
return pdfDocument.getOutline();
|
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
promise.then(function (outline) {
|
2016-02-14 07:13:01 +09:00
|
|
|
expect(outline).toEqual(null);
|
|
|
|
|
2017-05-10 07:21:09 +09:00
|
|
|
loadingTask.destroy().then(done);
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2016-02-14 07:13:01 +09:00
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
it('gets outline', function(done) {
|
2012-04-13 09:59:30 +09:00
|
|
|
var promise = doc.getOutline();
|
2016-03-29 23:34:13 +09:00
|
|
|
promise.then(function(outline) {
|
2012-04-13 09:59:30 +09:00
|
|
|
// Two top level entries.
|
2018-07-09 20:11:35 +09:00
|
|
|
expect(Array.isArray(outline)).toEqual(true);
|
2012-04-13 09:59:30 +09:00
|
|
|
expect(outline.length).toEqual(2);
|
|
|
|
// Make sure some basic attributes are set.
|
2015-12-22 20:59:23 +09:00
|
|
|
var outlineItem = outline[1];
|
|
|
|
expect(outlineItem.title).toEqual('Chapter 1');
|
2018-07-09 20:11:35 +09:00
|
|
|
expect(Array.isArray(outlineItem.dest)).toEqual(true);
|
2015-12-22 20:59:23 +09:00
|
|
|
expect(outlineItem.url).toEqual(null);
|
2016-10-21 20:29:15 +09:00
|
|
|
expect(outlineItem.unsafeUrl).toBeUndefined();
|
|
|
|
expect(outlineItem.newWindow).toBeUndefined();
|
2015-12-22 20:59:23 +09:00
|
|
|
|
2016-01-31 23:35:57 +09:00
|
|
|
expect(outlineItem.bold).toEqual(true);
|
|
|
|
expect(outlineItem.italic).toEqual(false);
|
2018-06-12 00:25:40 +09:00
|
|
|
expect(outlineItem.color).toEqual(new Uint8ClampedArray([0, 64, 128]));
|
2016-01-31 23:35:57 +09:00
|
|
|
|
2015-12-22 20:59:23 +09:00
|
|
|
expect(outlineItem.items.length).toEqual(1);
|
|
|
|
expect(outlineItem.items[0].title).toEqual('Paragraph 1.1');
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2015-12-22 20:59:23 +09:00
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
it('gets outline containing a url', function(done) {
|
2017-04-09 00:09:54 +09:00
|
|
|
var loadingTask = getDocument(buildGetDocumentParams('issue3214.pdf'));
|
2015-12-22 20:59:23 +09:00
|
|
|
|
|
|
|
loadingTask.promise.then(function (pdfDocument) {
|
|
|
|
pdfDocument.getOutline().then(function (outline) {
|
2018-07-09 20:11:35 +09:00
|
|
|
expect(Array.isArray(outline)).toEqual(true);
|
2015-12-22 20:59:23 +09:00
|
|
|
expect(outline.length).toEqual(5);
|
|
|
|
|
2016-01-31 23:35:57 +09:00
|
|
|
var outlineItemTwo = outline[2];
|
|
|
|
expect(typeof outlineItemTwo.title).toEqual('string');
|
|
|
|
expect(outlineItemTwo.dest).toEqual(null);
|
2016-09-30 23:32:22 +09:00
|
|
|
expect(outlineItemTwo.url).toEqual('http://google.com/');
|
2016-10-21 20:29:15 +09:00
|
|
|
expect(outlineItemTwo.unsafeUrl).toEqual('http://google.com');
|
2016-09-30 23:08:03 +09:00
|
|
|
expect(outlineItemTwo.newWindow).toBeUndefined();
|
2016-01-31 23:35:57 +09:00
|
|
|
|
|
|
|
var outlineItemOne = outline[1];
|
|
|
|
expect(outlineItemOne.bold).toEqual(false);
|
|
|
|
expect(outlineItemOne.italic).toEqual(true);
|
2018-06-12 00:25:40 +09:00
|
|
|
expect(outlineItemOne.color).toEqual(
|
|
|
|
new Uint8ClampedArray([0, 0, 0]));
|
2015-12-22 20:59:23 +09:00
|
|
|
|
2017-05-10 07:21:09 +09:00
|
|
|
loadingTask.destroy().then(done);
|
2015-12-22 20:59:23 +09:00
|
|
|
});
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|
2018-08-27 04:37:05 +09:00
|
|
|
|
|
|
|
it('gets non-existent permissions', function(done) {
|
|
|
|
doc.getPermissions().then(function(permissions) {
|
|
|
|
expect(permissions).toEqual(null);
|
|
|
|
|
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2018-08-27 04:37:05 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
it('gets permissions', function (done) {
|
|
|
|
// Editing not allowed.
|
|
|
|
const loadingTask0 =
|
|
|
|
getDocument(buildGetDocumentParams('issue9972-1.pdf'));
|
|
|
|
const promise0 = loadingTask0.promise.then(function(pdfDocument) {
|
|
|
|
return pdfDocument.getPermissions();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Printing not allowed.
|
|
|
|
const loadingTask1 =
|
|
|
|
getDocument(buildGetDocumentParams('issue9972-2.pdf'));
|
|
|
|
const promise1 = loadingTask1.promise.then(function(pdfDocument) {
|
|
|
|
return pdfDocument.getPermissions();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Copying not allowed.
|
|
|
|
const loadingTask2 =
|
|
|
|
getDocument(buildGetDocumentParams('issue9972-3.pdf'));
|
|
|
|
const promise2 = loadingTask2.promise.then(function(pdfDocument) {
|
|
|
|
return pdfDocument.getPermissions();
|
|
|
|
});
|
|
|
|
|
|
|
|
const totalPermissionCount = Object.keys(PermissionFlag).length;
|
|
|
|
Promise.all([promise0, promise1, promise2]).then(function(permissions) {
|
|
|
|
expect(permissions[0].length).toEqual(totalPermissionCount - 1);
|
|
|
|
expect(permissions[0].includes(PermissionFlag.MODIFY_CONTENTS))
|
|
|
|
.toBeFalsy();
|
|
|
|
|
|
|
|
expect(permissions[1].length).toEqual(totalPermissionCount - 2);
|
|
|
|
expect(permissions[1].includes(PermissionFlag.PRINT)).toBeFalsy();
|
|
|
|
expect(permissions[1].includes(PermissionFlag.PRINT_HIGH_QUALITY))
|
|
|
|
.toBeFalsy();
|
|
|
|
|
|
|
|
expect(permissions[2].length).toEqual(totalPermissionCount - 1);
|
|
|
|
expect(permissions[2].includes(PermissionFlag.COPY)).toBeFalsy();
|
|
|
|
|
|
|
|
Promise.all([
|
|
|
|
loadingTask0.destroy(),
|
|
|
|
loadingTask1.destroy(),
|
|
|
|
loadingTask2.destroy(),
|
|
|
|
]).then(done);
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2018-08-27 04:37:05 +09:00
|
|
|
});
|
|
|
|
|
2016-03-29 23:34:13 +09:00
|
|
|
it('gets metadata', function(done) {
|
2012-04-13 09:59:30 +09:00
|
|
|
var promise = doc.getMetadata();
|
2018-07-24 22:02:14 +09:00
|
|
|
promise.then(function({ info, metadata, contentDispositionFilename, }) {
|
|
|
|
expect(info['Title']).toEqual('Basic API Test');
|
2018-12-19 07:26:02 +09:00
|
|
|
// Custom, non-standard, information dictionary entries.
|
|
|
|
expect(info['Custom']).toEqual(undefined);
|
2018-07-24 22:02:14 +09:00
|
|
|
// The following are PDF.js specific, non-standard, properties.
|
|
|
|
expect(info['PDFFormatVersion']).toEqual('1.7');
|
|
|
|
expect(info['IsLinearized']).toEqual(false);
|
|
|
|
expect(info['IsAcroFormPresent']).toEqual(false);
|
|
|
|
expect(info['IsXFAPresent']).toEqual(false);
|
2019-02-15 22:42:50 +09:00
|
|
|
expect(info['IsCollectionPresent']).toEqual(false);
|
2018-07-24 22:02:14 +09:00
|
|
|
|
|
|
|
expect(metadata instanceof Metadata).toEqual(true);
|
|
|
|
expect(metadata.get('dc:title')).toEqual('Basic API Test');
|
|
|
|
|
|
|
|
expect(contentDispositionFilename).toEqual(null);
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|
2018-12-19 07:26:02 +09:00
|
|
|
it('gets metadata, with custom info dict entries', function(done) {
|
|
|
|
var loadingTask = getDocument(buildGetDocumentParams('tracemonkey.pdf'));
|
|
|
|
|
|
|
|
loadingTask.promise.then(function(pdfDocument) {
|
|
|
|
return pdfDocument.getMetadata();
|
|
|
|
}).then(function({ info, metadata, contentDispositionFilename, }) {
|
|
|
|
expect(info['Creator']).toEqual('TeX');
|
|
|
|
expect(info['Producer']).toEqual('pdfeTeX-1.21a');
|
|
|
|
expect(info['CreationDate']).toEqual('D:20090401163925-07\'00\'');
|
|
|
|
// Custom, non-standard, information dictionary entries.
|
|
|
|
const custom = info['Custom'];
|
|
|
|
expect(typeof custom === 'object' && custom !== null).toEqual(true);
|
|
|
|
|
|
|
|
expect(custom['PTEX.Fullbanner']).toEqual('This is pdfeTeX, ' +
|
|
|
|
'Version 3.141592-1.21a-2.2 (Web2C 7.5.4) kpathsea version 3.5.6');
|
|
|
|
// The following are PDF.js specific, non-standard, properties.
|
|
|
|
expect(info['PDFFormatVersion']).toEqual('1.4');
|
|
|
|
expect(info['IsLinearized']).toEqual(false);
|
|
|
|
expect(info['IsAcroFormPresent']).toEqual(false);
|
|
|
|
expect(info['IsXFAPresent']).toEqual(false);
|
2019-02-15 22:42:50 +09:00
|
|
|
expect(info['IsCollectionPresent']).toEqual(false);
|
2018-12-19 07:26:02 +09:00
|
|
|
|
|
|
|
expect(metadata).toEqual(null);
|
|
|
|
expect(contentDispositionFilename).toEqual(null);
|
|
|
|
|
|
|
|
loadingTask.destroy().then(done);
|
|
|
|
}).catch(done.fail);
|
|
|
|
});
|
|
|
|
|
2016-03-29 23:34:13 +09:00
|
|
|
it('gets data', function(done) {
|
2014-05-14 18:57:48 +09:00
|
|
|
var promise = doc.getData();
|
2016-03-29 23:34:13 +09:00
|
|
|
promise.then(function (data) {
|
2014-09-23 20:16:58 +09:00
|
|
|
expect(data instanceof Uint8Array).toEqual(true);
|
|
|
|
expect(data.length).toEqual(basicApiFileLength);
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2014-05-14 18:57:48 +09:00
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
it('gets download info', function(done) {
|
2014-05-19 06:35:29 +09:00
|
|
|
var promise = doc.getDownloadInfo();
|
2016-03-29 23:34:13 +09:00
|
|
|
promise.then(function (data) {
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
expect(data).toEqual({ length: basicApiFileLength, });
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2014-05-19 06:35:29 +09:00
|
|
|
});
|
2018-06-25 20:19:29 +09:00
|
|
|
it('gets document stats', function(done) {
|
2014-08-31 05:12:34 +09:00
|
|
|
var promise = doc.getStats();
|
2016-03-29 23:34:13 +09:00
|
|
|
promise.then(function (stats) {
|
2019-08-02 20:55:37 +09:00
|
|
|
expect(stats).toEqual({ streamTypes: {}, fontTypes: {}, });
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2014-08-31 05:12:34 +09:00
|
|
|
});
|
2015-10-24 21:15:47 +09:00
|
|
|
|
2016-03-29 23:34:13 +09:00
|
|
|
it('checks that fingerprints are unique', function(done) {
|
2019-07-15 18:19:17 +09:00
|
|
|
const loadingTask1 = getDocument(
|
|
|
|
buildGetDocumentParams('issue4436r.pdf'));
|
|
|
|
const loadingTask2 = getDocument(buildGetDocumentParams('issue4575.pdf'));
|
2015-10-24 21:15:47 +09:00
|
|
|
|
2019-07-15 18:19:17 +09:00
|
|
|
Promise.all([
|
|
|
|
loadingTask1.promise,
|
|
|
|
loadingTask2.promise
|
|
|
|
]).then(function(data) {
|
|
|
|
const fingerprint1 = data[0].fingerprint;
|
|
|
|
const fingerprint2 = data[1].fingerprint;
|
2015-10-24 21:15:47 +09:00
|
|
|
|
|
|
|
expect(fingerprint1).not.toEqual(fingerprint2);
|
2016-01-21 07:57:17 +09:00
|
|
|
|
2019-07-15 18:19:17 +09:00
|
|
|
expect(fingerprint1).toEqual('2f695a83d6e7553c24fc08b7ac69712d');
|
|
|
|
expect(fingerprint2).toEqual('04c7126b34a46b6d4d6e7a1eff7edcb6');
|
|
|
|
|
2017-05-10 07:21:09 +09:00
|
|
|
Promise.all([
|
|
|
|
loadingTask1.destroy(),
|
|
|
|
loadingTask2.destroy()
|
|
|
|
]).then(done);
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2015-10-24 21:15:47 +09:00
|
|
|
});
|
2017-08-31 21:08:22 +09:00
|
|
|
|
|
|
|
describe('Cross-origin', function() {
|
|
|
|
var loadingTask;
|
|
|
|
function _checkCanLoad(expectSuccess, filename, options) {
|
2019-11-11 00:42:46 +09:00
|
|
|
if (isNodeJS) {
|
2017-08-31 21:08:22 +09:00
|
|
|
pending('Cannot simulate cross-origin requests in Node.js');
|
|
|
|
}
|
|
|
|
var params = buildGetDocumentParams(filename, options);
|
|
|
|
var url = new URL(params.url);
|
|
|
|
if (url.hostname === 'localhost') {
|
|
|
|
url.hostname = '127.0.0.1';
|
|
|
|
} else if (params.url.hostname === '127.0.0.1') {
|
|
|
|
url.hostname = 'localhost';
|
|
|
|
} else {
|
|
|
|
pending('Can only run cross-origin test on localhost!');
|
|
|
|
}
|
|
|
|
params.url = url.href;
|
|
|
|
loadingTask = getDocument(params);
|
|
|
|
return loadingTask.promise.then(function(pdf) {
|
|
|
|
return pdf.destroy();
|
|
|
|
}).then(function() {
|
|
|
|
expect(expectSuccess).toEqual(true);
|
|
|
|
}, function(error) {
|
|
|
|
if (expectSuccess) {
|
|
|
|
// For ease of debugging.
|
|
|
|
expect(error).toEqual('There should not be any error');
|
|
|
|
}
|
|
|
|
expect(expectSuccess).toEqual(false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function testCanLoad(filename, options) {
|
|
|
|
return _checkCanLoad(true, filename, options);
|
|
|
|
}
|
|
|
|
function testCannotLoad(filename, options) {
|
|
|
|
return _checkCanLoad(false, filename, options);
|
|
|
|
}
|
|
|
|
afterEach(function(done) {
|
2019-03-11 20:43:44 +09:00
|
|
|
if (loadingTask && !loadingTask.destroyed) {
|
2017-08-31 21:08:22 +09:00
|
|
|
loadingTask.destroy().then(done);
|
|
|
|
} else {
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
it('server disallows cors', function(done) {
|
|
|
|
testCannotLoad('basicapi.pdf').then(done);
|
|
|
|
});
|
|
|
|
it('server allows cors without credentials, default withCredentials',
|
|
|
|
function(done) {
|
|
|
|
testCanLoad('basicapi.pdf?cors=withoutCredentials').then(done);
|
|
|
|
});
|
|
|
|
it('server allows cors without credentials, and withCredentials=false',
|
|
|
|
function(done) {
|
|
|
|
testCanLoad('basicapi.pdf?cors=withoutCredentials', {
|
|
|
|
withCredentials: false,
|
|
|
|
}).then(done);
|
|
|
|
});
|
|
|
|
it('server allows cors without credentials, but withCredentials=true',
|
|
|
|
function(done) {
|
|
|
|
testCannotLoad('basicapi.pdf?cors=withoutCredentials', {
|
|
|
|
withCredentials: true,
|
|
|
|
}).then(done);
|
|
|
|
});
|
|
|
|
it('server allows cors with credentials, and withCredentials=true',
|
|
|
|
function(done) {
|
|
|
|
testCanLoad('basicapi.pdf?cors=withCredentials', {
|
|
|
|
withCredentials: true,
|
|
|
|
}).then(done);
|
|
|
|
});
|
|
|
|
it('server allows cors with credentials, and withCredentials=false',
|
|
|
|
function(done) {
|
|
|
|
// The server supports even more than we need, so if the previous tests
|
|
|
|
// pass, then this should pass for sure.
|
|
|
|
// The only case where this test fails is when the server does not reply
|
|
|
|
// with the Access-Control-Allow-Origin header.
|
|
|
|
testCanLoad('basicapi.pdf?cors=withCredentials', {
|
|
|
|
withCredentials: false,
|
|
|
|
}).then(done);
|
|
|
|
});
|
|
|
|
});
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|
|
|
|
describe('Page', function() {
|
2016-01-21 07:57:17 +09:00
|
|
|
var loadingTask;
|
|
|
|
var pdfDocument, page;
|
|
|
|
|
2016-03-30 22:24:57 +09:00
|
|
|
beforeAll(function(done) {
|
2017-04-09 00:09:54 +09:00
|
|
|
loadingTask = getDocument(basicApiGetDocumentParams);
|
2016-03-29 23:34:13 +09:00
|
|
|
loadingTask.promise.then(function(doc) {
|
2016-01-21 07:57:17 +09:00
|
|
|
pdfDocument = doc;
|
2016-03-29 23:34:13 +09:00
|
|
|
pdfDocument.getPage(1).then(function(data) {
|
2016-01-21 07:57:17 +09:00
|
|
|
page = data;
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2016-01-21 07:57:17 +09:00
|
|
|
});
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|
2016-01-21 07:57:17 +09:00
|
|
|
|
2017-05-10 07:21:09 +09:00
|
|
|
afterAll(function(done) {
|
|
|
|
loadingTask.destroy().then(done);
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|
2016-01-21 07:57:17 +09:00
|
|
|
|
2014-08-12 19:04:00 +09:00
|
|
|
it('gets page number', function () {
|
|
|
|
expect(page.pageNumber).toEqual(1);
|
|
|
|
});
|
|
|
|
it('gets rotate', function () {
|
|
|
|
expect(page.rotate).toEqual(0);
|
|
|
|
});
|
|
|
|
it('gets ref', function () {
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
expect(page.ref).toEqual({ num: 15, gen: 0, });
|
2014-08-12 19:04:00 +09:00
|
|
|
});
|
2016-11-22 06:39:04 +09:00
|
|
|
it('gets userUnit', function () {
|
|
|
|
expect(page.userUnit).toEqual(1.0);
|
|
|
|
});
|
Fallback gracefully when encountering corrupt PDF files with empty /MediaBox and /CropBox entries
This is based on a real-world PDF file I encountered very recently[1], although I'm currently unable to recall where I saw it.
Note that different PDF viewers handle these sort of errors differently, with Adobe Reader outright failing to render the attached PDF file whereas PDFium mostly handles it "correctly".
The patch makes the following notable changes:
- Refactor the `cropBox` and `mediaBox` getters, on the `Page`, to reduce unnecessary duplication. (This will also help in the future, if support for extracting additional page bounding boxes are added to the API.)
- Ensure that the page bounding boxes, i.e. `cropBox` and `mediaBox`, are never empty to prevent issues/weirdness in the viewer.
- Ensure that the `view` getter on the `Page` will never return an empty intersection of the `cropBox` and `mediaBox`.
- Add an *optional* parameter to `Util.intersect`, to allow checking that the computed intersection isn't actually empty.
- Change `Util.intersect` to have consistent return types, since Arrays are of type `Object` and falling back to returning a `Boolean` thus seem strange.
---
[1] In that case I believe that only the `cropBox` was empty, but it seemed like a good idea to attempt to fix a bunch of related cases all at once.
2019-08-08 22:54:46 +09:00
|
|
|
|
|
|
|
it('gets view', function() {
|
2014-08-12 19:04:00 +09:00
|
|
|
expect(page.view).toEqual([0, 0, 595.28, 841.89]);
|
|
|
|
});
|
Fallback gracefully when encountering corrupt PDF files with empty /MediaBox and /CropBox entries
This is based on a real-world PDF file I encountered very recently[1], although I'm currently unable to recall where I saw it.
Note that different PDF viewers handle these sort of errors differently, with Adobe Reader outright failing to render the attached PDF file whereas PDFium mostly handles it "correctly".
The patch makes the following notable changes:
- Refactor the `cropBox` and `mediaBox` getters, on the `Page`, to reduce unnecessary duplication. (This will also help in the future, if support for extracting additional page bounding boxes are added to the API.)
- Ensure that the page bounding boxes, i.e. `cropBox` and `mediaBox`, are never empty to prevent issues/weirdness in the viewer.
- Ensure that the `view` getter on the `Page` will never return an empty intersection of the `cropBox` and `mediaBox`.
- Add an *optional* parameter to `Util.intersect`, to allow checking that the computed intersection isn't actually empty.
- Change `Util.intersect` to have consistent return types, since Arrays are of type `Object` and falling back to returning a `Boolean` thus seem strange.
---
[1] In that case I believe that only the `cropBox` was empty, but it seemed like a good idea to attempt to fix a bunch of related cases all at once.
2019-08-08 22:54:46 +09:00
|
|
|
it('gets view, with empty/invalid bounding boxes', function(done) {
|
|
|
|
const viewLoadingTask = getDocument(buildGetDocumentParams(
|
|
|
|
'boundingBox_invalid.pdf'));
|
|
|
|
|
|
|
|
viewLoadingTask.promise.then((pdfDoc) => {
|
|
|
|
const numPages = pdfDoc.numPages;
|
|
|
|
expect(numPages).toEqual(3);
|
|
|
|
|
|
|
|
const viewPromises = [];
|
|
|
|
for (let i = 0; i < numPages; i++) {
|
|
|
|
viewPromises[i] = pdfDoc.getPage(i + 1).then((pdfPage) => {
|
|
|
|
return pdfPage.view;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Promise.all(viewPromises).then(([page1, page2, page3]) => {
|
|
|
|
expect(page1).toEqual([0, 0, 612, 792]);
|
|
|
|
expect(page2).toEqual([0, 0, 800, 600]);
|
|
|
|
expect(page3).toEqual([0, 0, 600, 800]);
|
|
|
|
|
|
|
|
viewLoadingTask.destroy().then(done);
|
|
|
|
});
|
|
|
|
}).catch(done.fail);
|
|
|
|
});
|
|
|
|
|
2014-08-12 19:04:00 +09:00
|
|
|
it('gets viewport', function () {
|
2018-12-21 19:47:37 +09:00
|
|
|
var viewport = page.getViewport({ scale: 1.5, rotation: 90, });
|
2014-08-12 19:04:00 +09:00
|
|
|
expect(viewport.viewBox).toEqual(page.view);
|
|
|
|
expect(viewport.scale).toEqual(1.5);
|
|
|
|
expect(viewport.rotation).toEqual(90);
|
|
|
|
expect(viewport.transform).toEqual([0, 1.5, 1.5, 0, 0, 0]);
|
|
|
|
expect(viewport.width).toEqual(1262.835);
|
|
|
|
expect(viewport.height).toEqual(892.92);
|
|
|
|
});
|
2019-10-24 03:35:49 +09:00
|
|
|
it('gets viewport with "offsetX/offsetY" arguments', function () {
|
|
|
|
const viewport = page.getViewport({ scale: 1, rotation: 0,
|
|
|
|
offsetX: 100, offsetY: -100, });
|
|
|
|
expect(viewport.transform).toEqual([1, 0, 0, -1, 100, 741.89]);
|
|
|
|
});
|
2017-11-04 01:05:53 +09:00
|
|
|
it('gets viewport respecting "dontFlip" argument', function () {
|
2019-10-24 03:30:25 +09:00
|
|
|
const scale = 1, rotation = 0;
|
2018-12-21 19:47:37 +09:00
|
|
|
let viewport = page.getViewport({ scale, rotation, });
|
|
|
|
let dontFlipViewport = page.getViewport({ scale, rotation,
|
|
|
|
dontFlip: true, });
|
2017-11-04 01:05:53 +09:00
|
|
|
|
|
|
|
expect(dontFlipViewport).not.toEqual(viewport);
|
|
|
|
expect(dontFlipViewport).toEqual(viewport.clone({ dontFlip: true, }));
|
|
|
|
|
|
|
|
expect(viewport.transform).toEqual([1, 0, 0, -1, 0, 841.89]);
|
|
|
|
expect(dontFlipViewport.transform).toEqual([1, 0, -0, 1, 0, 0]);
|
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
it('gets annotations', function (done) {
|
|
|
|
var defaultPromise = page.getAnnotations().then(function (data) {
|
2015-11-22 21:56:52 +09:00
|
|
|
expect(data.length).toEqual(4);
|
|
|
|
});
|
|
|
|
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
var displayPromise = page.getAnnotations({ intent: 'display', }).then(
|
2016-03-29 23:34:13 +09:00
|
|
|
function (data) {
|
2015-11-22 21:56:52 +09:00
|
|
|
expect(data.length).toEqual(4);
|
|
|
|
});
|
|
|
|
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
var printPromise = page.getAnnotations({ intent: 'print', }).then(
|
2016-03-29 23:34:13 +09:00
|
|
|
function (data) {
|
2014-08-12 19:04:00 +09:00
|
|
|
expect(data.length).toEqual(4);
|
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
Promise.all([defaultPromise, displayPromise, printPromise]).then(
|
|
|
|
function () {
|
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2014-08-12 19:04:00 +09:00
|
|
|
});
|
2016-10-01 19:05:07 +09:00
|
|
|
|
|
|
|
it('gets annotations containing relative URLs (bug 766086)',
|
|
|
|
function (done) {
|
2017-04-09 00:09:54 +09:00
|
|
|
var filename = 'bug766086.pdf';
|
2016-10-01 19:05:07 +09:00
|
|
|
|
2017-04-09 00:09:54 +09:00
|
|
|
var defaultLoadingTask = getDocument(buildGetDocumentParams(filename));
|
2016-10-01 19:05:07 +09:00
|
|
|
var defaultPromise = defaultLoadingTask.promise.then(function (pdfDoc) {
|
|
|
|
return pdfDoc.getPage(1).then(function (pdfPage) {
|
|
|
|
return pdfPage.getAnnotations();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-09 00:09:54 +09:00
|
|
|
var docBaseUrlLoadingTask = getDocument(
|
|
|
|
buildGetDocumentParams(filename, {
|
|
|
|
docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf',
|
|
|
|
}));
|
2016-10-01 19:05:07 +09:00
|
|
|
var docBaseUrlPromise = docBaseUrlLoadingTask.promise.then(
|
|
|
|
function (pdfDoc) {
|
|
|
|
return pdfDoc.getPage(1).then(function (pdfPage) {
|
|
|
|
return pdfPage.getAnnotations();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-09 00:09:54 +09:00
|
|
|
var invalidDocBaseUrlLoadingTask = getDocument(
|
|
|
|
buildGetDocumentParams(filename, {
|
|
|
|
docBaseUrl: 'qwerty.pdf',
|
|
|
|
}));
|
2016-10-01 19:05:07 +09:00
|
|
|
var invalidDocBaseUrlPromise = invalidDocBaseUrlLoadingTask.promise.then(
|
|
|
|
function (pdfDoc) {
|
|
|
|
return pdfDoc.getPage(1).then(function (pdfPage) {
|
|
|
|
return pdfPage.getAnnotations();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
Promise.all([defaultPromise, docBaseUrlPromise,
|
|
|
|
invalidDocBaseUrlPromise]).then(function (data) {
|
|
|
|
var defaultAnnotations = data[0];
|
|
|
|
var docBaseUrlAnnotations = data[1];
|
|
|
|
var invalidDocBaseUrlAnnotations = data[2];
|
|
|
|
|
|
|
|
expect(defaultAnnotations[0].url).toBeUndefined();
|
|
|
|
expect(defaultAnnotations[0].unsafeUrl).toEqual(
|
2017-05-17 03:35:44 +09:00
|
|
|
'../../0021/002156/215675E.pdf#15');
|
2016-10-01 19:05:07 +09:00
|
|
|
|
|
|
|
expect(docBaseUrlAnnotations[0].url).toEqual(
|
2017-05-17 03:35:44 +09:00
|
|
|
'http://www.example.com/0021/002156/215675E.pdf#15');
|
2016-10-01 19:05:07 +09:00
|
|
|
expect(docBaseUrlAnnotations[0].unsafeUrl).toEqual(
|
2017-05-17 03:35:44 +09:00
|
|
|
'../../0021/002156/215675E.pdf#15');
|
2016-10-01 19:05:07 +09:00
|
|
|
|
|
|
|
expect(invalidDocBaseUrlAnnotations[0].url).toBeUndefined();
|
|
|
|
expect(invalidDocBaseUrlAnnotations[0].unsafeUrl).toEqual(
|
2017-05-17 03:35:44 +09:00
|
|
|
'../../0021/002156/215675E.pdf#15');
|
2016-10-01 19:05:07 +09:00
|
|
|
|
2017-05-10 07:21:09 +09:00
|
|
|
Promise.all([
|
|
|
|
defaultLoadingTask.destroy(),
|
|
|
|
docBaseUrlLoadingTask.destroy(),
|
|
|
|
invalidDocBaseUrlLoadingTask.destroy()
|
|
|
|
]).then(done);
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2016-10-01 19:05:07 +09:00
|
|
|
});
|
|
|
|
|
2016-03-29 23:34:13 +09:00
|
|
|
it('gets text content', function (done) {
|
2015-11-24 00:57:43 +09:00
|
|
|
var defaultPromise = page.getTextContent();
|
2016-07-04 01:29:47 +09:00
|
|
|
var parametersPromise = page.getTextContent({
|
|
|
|
normalizeWhitespace: true,
|
|
|
|
disableCombineTextItems: true,
|
|
|
|
});
|
2015-11-24 00:57:43 +09:00
|
|
|
|
|
|
|
var promises = [
|
|
|
|
defaultPromise,
|
2016-07-04 01:29:47 +09:00
|
|
|
parametersPromise,
|
2015-11-24 00:57:43 +09:00
|
|
|
];
|
2016-03-29 23:34:13 +09:00
|
|
|
Promise.all(promises).then(function (data) {
|
2015-11-24 00:57:43 +09:00
|
|
|
expect(!!data[0].items).toEqual(true);
|
|
|
|
expect(data[0].items.length).toEqual(7);
|
|
|
|
expect(!!data[0].styles).toEqual(true);
|
|
|
|
|
|
|
|
// A simple check that ensures the two `textContent` object match.
|
|
|
|
expect(JSON.stringify(data[0])).toEqual(JSON.stringify(data[1]));
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|
2019-01-29 22:24:48 +09:00
|
|
|
|
|
|
|
it('gets text content, with correct properties (issue 8276)',
|
|
|
|
function(done) {
|
|
|
|
const loadingTask = getDocument(
|
|
|
|
buildGetDocumentParams('issue8276_reduced.pdf'));
|
|
|
|
|
|
|
|
loadingTask.promise.then((pdfDoc) => {
|
|
|
|
pdfDoc.getPage(1).then((pdfPage) => {
|
|
|
|
pdfPage.getTextContent().then(({ items, styles, }) => {
|
|
|
|
expect(items.length).toEqual(1);
|
|
|
|
expect(Object.keys(styles)).toEqual(['Times']);
|
|
|
|
|
|
|
|
expect(items[0]).toEqual({
|
|
|
|
dir: 'ltr',
|
|
|
|
fontName: 'Times',
|
|
|
|
height: 18,
|
|
|
|
str: 'Issue 8276',
|
|
|
|
transform: [18, 0, 0, 18, 441.81, 708.4499999999999],
|
|
|
|
width: 77.49,
|
|
|
|
});
|
|
|
|
expect(styles.Times).toEqual({
|
|
|
|
fontFamily: 'serif',
|
|
|
|
ascent: NaN,
|
|
|
|
descent: NaN,
|
|
|
|
vertical: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
loadingTask.destroy().then(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}).catch(done.fail);
|
|
|
|
});
|
|
|
|
|
2016-03-29 23:34:13 +09:00
|
|
|
it('gets operator list', function(done) {
|
2014-06-17 03:35:38 +09:00
|
|
|
var promise = page.getOperatorList();
|
2016-03-29 23:34:13 +09:00
|
|
|
promise.then(function (oplist) {
|
2014-06-17 03:35:38 +09:00
|
|
|
expect(!!oplist.fnArray).toEqual(true);
|
|
|
|
expect(!!oplist.argsArray).toEqual(true);
|
|
|
|
expect(oplist.lastChunk).toEqual(true);
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2014-06-17 03:35:38 +09:00
|
|
|
});
|
2019-07-13 23:06:05 +09:00
|
|
|
|
2018-02-11 21:13:11 +09:00
|
|
|
it('gets operatorList with JPEG image (issue 4888)', function(done) {
|
|
|
|
let loadingTask = getDocument(buildGetDocumentParams('cmykjpeg.pdf'));
|
|
|
|
|
|
|
|
loadingTask.promise.then((pdfDoc) => {
|
|
|
|
pdfDoc.getPage(1).then((pdfPage) => {
|
|
|
|
pdfPage.getOperatorList().then((opList) => {
|
|
|
|
let imgIndex = opList.fnArray.indexOf(OPS.paintImageXObject);
|
|
|
|
let imgArgs = opList.argsArray[imgIndex];
|
2019-01-29 22:25:47 +09:00
|
|
|
let { data, } = pdfPage.objs.get(imgArgs[0]);
|
2018-02-11 21:13:11 +09:00
|
|
|
|
2019-01-29 22:25:47 +09:00
|
|
|
expect(data instanceof Uint8ClampedArray).toEqual(true);
|
|
|
|
expect(data.length).toEqual(90000);
|
|
|
|
|
|
|
|
loadingTask.destroy().then(done);
|
2018-02-11 21:13:11 +09:00
|
|
|
});
|
|
|
|
});
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2018-02-11 21:13:11 +09:00
|
|
|
});
|
2019-07-13 23:06:05 +09:00
|
|
|
|
|
|
|
it('gets operatorList, from corrupt PDF file (issue 8702), ' +
|
|
|
|
'with/without `stopAtErrors` set', function(done) {
|
|
|
|
const loadingTask1 = getDocument(buildGetDocumentParams('issue8702.pdf', {
|
|
|
|
stopAtErrors: false, // The default value.
|
|
|
|
}));
|
|
|
|
const loadingTask2 = getDocument(buildGetDocumentParams('issue8702.pdf', {
|
|
|
|
stopAtErrors: true,
|
|
|
|
}));
|
|
|
|
|
|
|
|
const result1 = loadingTask1.promise.then((pdfDoc) => {
|
|
|
|
return pdfDoc.getPage(1).then((pdfPage) => {
|
|
|
|
return pdfPage.getOperatorList().then((opList) => {
|
|
|
|
expect(opList.fnArray.length).toEqual(722);
|
|
|
|
expect(opList.argsArray.length).toEqual(722);
|
|
|
|
expect(opList.lastChunk).toEqual(true);
|
|
|
|
|
|
|
|
return loadingTask1.destroy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const result2 = loadingTask2.promise.then((pdfDoc) => {
|
|
|
|
return pdfDoc.getPage(1).then((pdfPage) => {
|
|
|
|
return pdfPage.getOperatorList().then((opList) => {
|
|
|
|
expect(opList.fnArray.length).toEqual(0);
|
|
|
|
expect(opList.argsArray.length).toEqual(0);
|
|
|
|
expect(opList.lastChunk).toEqual(true);
|
|
|
|
|
|
|
|
return loadingTask2.destroy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
Promise.all([result1, result2]).then(done, done.fail);
|
|
|
|
});
|
|
|
|
|
2018-06-25 20:19:29 +09:00
|
|
|
it('gets document stats after parsing page', function(done) {
|
2015-06-26 05:51:17 +09:00
|
|
|
var promise = page.getOperatorList().then(function () {
|
|
|
|
return pdfDocument.getStats();
|
|
|
|
});
|
2019-08-02 20:55:37 +09:00
|
|
|
var expectedStreamTypes = {};
|
2015-06-26 05:51:17 +09:00
|
|
|
expectedStreamTypes[StreamType.FLATE] = true;
|
2019-08-02 20:55:37 +09:00
|
|
|
var expectedFontTypes = {};
|
2015-06-26 05:51:17 +09:00
|
|
|
expectedFontTypes[FontType.TYPE1] = true;
|
|
|
|
expectedFontTypes[FontType.CIDFONTTYPE2] = true;
|
|
|
|
|
2016-03-29 23:34:13 +09:00
|
|
|
promise.then(function (stats) {
|
2015-06-26 05:51:17 +09:00
|
|
|
expect(stats).toEqual({ streamTypes: expectedStreamTypes,
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
fontTypes: expectedFontTypes, });
|
2016-03-29 23:34:13 +09:00
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2015-06-26 05:51:17 +09:00
|
|
|
});
|
2017-03-13 21:32:23 +09:00
|
|
|
|
2018-06-25 20:19:29 +09:00
|
|
|
it('gets page stats after parsing page, without `pdfBug` set',
|
|
|
|
function(done) {
|
|
|
|
page.getOperatorList().then((opList) => {
|
|
|
|
return page.stats;
|
|
|
|
}).then((stats) => {
|
|
|
|
expect(stats).toEqual(null);
|
|
|
|
done();
|
|
|
|
}, done.fail);
|
|
|
|
});
|
|
|
|
it('gets page stats after parsing page, with `pdfBug` set', function(done) {
|
|
|
|
let loadingTask = getDocument(
|
|
|
|
buildGetDocumentParams(basicApiFileName, { pdfBug: true, }));
|
|
|
|
|
|
|
|
loadingTask.promise.then((pdfDoc) => {
|
|
|
|
return pdfDoc.getPage(1).then((pdfPage) => {
|
|
|
|
return pdfPage.getOperatorList().then((opList) => {
|
|
|
|
return pdfPage.stats;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}).then((stats) => {
|
|
|
|
expect(stats instanceof StatTimer).toEqual(true);
|
|
|
|
expect(stats.times.length).toEqual(1);
|
|
|
|
|
|
|
|
let [statEntry] = stats.times;
|
|
|
|
expect(statEntry.name).toEqual('Page Request');
|
2019-07-22 18:40:00 +09:00
|
|
|
expect(statEntry.end - statEntry.start).toBeGreaterThanOrEqual(0);
|
2018-06-25 20:19:29 +09:00
|
|
|
|
|
|
|
loadingTask.destroy().then(done);
|
|
|
|
}, done.fail);
|
|
|
|
});
|
|
|
|
it('gets page stats after rendering page, with `pdfBug` set',
|
|
|
|
function(done) {
|
|
|
|
let loadingTask = getDocument(
|
|
|
|
buildGetDocumentParams(basicApiFileName, { pdfBug: true, }));
|
|
|
|
let canvasAndCtx;
|
|
|
|
|
|
|
|
loadingTask.promise.then((pdfDoc) => {
|
|
|
|
return pdfDoc.getPage(1).then((pdfPage) => {
|
2018-12-21 19:47:37 +09:00
|
|
|
let viewport = pdfPage.getViewport({ scale: 1, });
|
2018-06-25 20:19:29 +09:00
|
|
|
canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
|
|
|
|
|
|
|
|
let renderTask = pdfPage.render({
|
|
|
|
canvasContext: canvasAndCtx.context,
|
2019-02-11 03:29:38 +09:00
|
|
|
canvasFactory: CanvasFactory,
|
2018-06-25 20:19:29 +09:00
|
|
|
viewport,
|
|
|
|
});
|
|
|
|
return renderTask.promise.then(() => {
|
|
|
|
return pdfPage.stats;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}).then((stats) => {
|
|
|
|
expect(stats instanceof StatTimer).toEqual(true);
|
|
|
|
expect(stats.times.length).toEqual(3);
|
|
|
|
|
|
|
|
let [statEntryOne, statEntryTwo, statEntryThree] = stats.times;
|
|
|
|
expect(statEntryOne.name).toEqual('Page Request');
|
2019-12-24 06:57:01 +09:00
|
|
|
expect(statEntryOne.end - statEntryOne.start).toBeGreaterThanOrEqual(0);
|
2018-06-25 20:19:29 +09:00
|
|
|
|
|
|
|
expect(statEntryTwo.name).toEqual('Rendering');
|
|
|
|
expect(statEntryTwo.end - statEntryTwo.start).toBeGreaterThan(0);
|
|
|
|
|
|
|
|
expect(statEntryThree.name).toEqual('Overall');
|
|
|
|
expect(statEntryThree.end - statEntryThree.start).toBeGreaterThan(0);
|
|
|
|
|
|
|
|
CanvasFactory.destroy(canvasAndCtx);
|
|
|
|
loadingTask.destroy().then(done);
|
|
|
|
}, done.fail);
|
|
|
|
});
|
|
|
|
|
2017-03-13 21:32:23 +09:00
|
|
|
it('cancels rendering of page', function(done) {
|
2018-12-21 19:47:37 +09:00
|
|
|
var viewport = page.getViewport({ scale: 1, });
|
2017-03-13 21:56:59 +09:00
|
|
|
var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
|
2017-03-13 21:32:23 +09:00
|
|
|
|
|
|
|
var renderTask = page.render({
|
2017-03-13 21:56:59 +09:00
|
|
|
canvasContext: canvasAndCtx.context,
|
2019-02-11 03:29:38 +09:00
|
|
|
canvasFactory: CanvasFactory,
|
2017-04-28 20:40:47 +09:00
|
|
|
viewport,
|
2017-03-13 21:32:23 +09:00
|
|
|
});
|
|
|
|
renderTask.cancel();
|
|
|
|
|
|
|
|
renderTask.promise.then(function() {
|
|
|
|
done.fail('shall cancel rendering');
|
|
|
|
}).catch(function (error) {
|
|
|
|
expect(error instanceof RenderingCancelledException).toEqual(true);
|
|
|
|
expect(error.type).toEqual('canvas');
|
2017-03-13 21:56:59 +09:00
|
|
|
CanvasFactory.destroy(canvasAndCtx);
|
2017-03-13 21:32:23 +09:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-06-29 05:38:09 +09:00
|
|
|
|
|
|
|
it('re-render page, using the same canvas, after cancelling rendering',
|
|
|
|
function(done) {
|
2018-12-21 19:47:37 +09:00
|
|
|
let viewport = page.getViewport({ scale: 1, });
|
2018-06-29 05:38:09 +09:00
|
|
|
let canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
|
|
|
|
|
|
|
|
let renderTask = page.render({
|
|
|
|
canvasContext: canvasAndCtx.context,
|
2019-02-11 03:29:38 +09:00
|
|
|
canvasFactory: CanvasFactory,
|
2018-06-29 05:38:09 +09:00
|
|
|
viewport,
|
|
|
|
});
|
|
|
|
renderTask.cancel();
|
|
|
|
|
|
|
|
renderTask.promise.then(() => {
|
|
|
|
throw new Error('shall cancel rendering');
|
|
|
|
}, (reason) => {
|
|
|
|
expect(reason instanceof RenderingCancelledException).toEqual(true);
|
|
|
|
}).then(() => {
|
|
|
|
let reRenderTask = page.render({
|
|
|
|
canvasContext: canvasAndCtx.context,
|
2019-02-11 03:29:38 +09:00
|
|
|
canvasFactory: CanvasFactory,
|
2018-06-29 05:38:09 +09:00
|
|
|
viewport,
|
|
|
|
});
|
|
|
|
return reRenderTask.promise;
|
|
|
|
}).then(() => {
|
|
|
|
CanvasFactory.destroy(canvasAndCtx);
|
|
|
|
done();
|
|
|
|
}, done.fail);
|
|
|
|
});
|
|
|
|
|
2017-06-13 06:04:35 +09:00
|
|
|
it('multiple render() on the same canvas', function(done) {
|
2018-12-21 19:47:37 +09:00
|
|
|
var viewport = page.getViewport({ scale: 1, });
|
2017-06-13 06:04:35 +09:00
|
|
|
var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
|
|
|
|
|
|
|
|
var renderTask1 = page.render({
|
|
|
|
canvasContext: canvasAndCtx.context,
|
2019-02-11 03:29:38 +09:00
|
|
|
canvasFactory: CanvasFactory,
|
2017-06-13 06:04:35 +09:00
|
|
|
viewport,
|
|
|
|
});
|
|
|
|
var renderTask2 = page.render({
|
|
|
|
canvasContext: canvasAndCtx.context,
|
2019-02-11 03:29:38 +09:00
|
|
|
canvasFactory: CanvasFactory,
|
2017-06-13 06:04:35 +09:00
|
|
|
viewport,
|
|
|
|
});
|
|
|
|
|
|
|
|
Promise.all([
|
|
|
|
renderTask1.promise,
|
|
|
|
renderTask2.promise.then(() => {
|
|
|
|
done.fail('shall fail rendering');
|
|
|
|
}, (reason) => {
|
|
|
|
/* it fails because we already using this canvas */
|
|
|
|
expect(/multiple render\(\)/.test(reason.message)).toEqual(true);
|
|
|
|
})
|
|
|
|
]).then(done);
|
|
|
|
});
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|
2018-03-18 03:56:39 +09:00
|
|
|
describe('Multiple `getDocument` instances', function() {
|
2015-07-14 18:43:20 +09:00
|
|
|
// Regression test for https://github.com/mozilla/pdf.js/issues/6205
|
|
|
|
// A PDF using the Helvetica font.
|
2017-04-09 00:09:54 +09:00
|
|
|
var pdf1 = buildGetDocumentParams('tracemonkey.pdf');
|
2015-07-14 18:43:20 +09:00
|
|
|
// A PDF using the Times font.
|
2017-04-09 00:09:54 +09:00
|
|
|
var pdf2 = buildGetDocumentParams('TAMReview.pdf');
|
2015-07-14 18:43:20 +09:00
|
|
|
// A PDF using the Arial font.
|
2017-04-09 00:09:54 +09:00
|
|
|
var pdf3 = buildGetDocumentParams('issue6068.pdf');
|
2016-01-21 07:57:17 +09:00
|
|
|
var loadingTasks = [];
|
2015-07-14 18:43:20 +09:00
|
|
|
|
|
|
|
// Render the first page of the given PDF file.
|
|
|
|
// Fulfills the promise with the base64-encoded version of the PDF.
|
2018-11-08 21:46:02 +09:00
|
|
|
async function renderPDF(filename) {
|
|
|
|
const loadingTask = getDocument(filename);
|
2016-01-21 07:57:17 +09:00
|
|
|
loadingTasks.push(loadingTask);
|
2018-11-08 21:46:02 +09:00
|
|
|
const pdf = await loadingTask.promise;
|
|
|
|
const page = await pdf.getPage(1);
|
2018-12-21 19:47:37 +09:00
|
|
|
const viewport = page.getViewport({ scale: 1.2, });
|
2018-11-08 21:46:02 +09:00
|
|
|
const canvasAndCtx = CanvasFactory.create(viewport.width,
|
|
|
|
viewport.height);
|
|
|
|
const renderTask = page.render({
|
|
|
|
canvasContext: canvasAndCtx.context,
|
2019-02-11 03:29:38 +09:00
|
|
|
canvasFactory: CanvasFactory,
|
2018-11-08 21:46:02 +09:00
|
|
|
viewport,
|
|
|
|
});
|
|
|
|
await renderTask.promise;
|
|
|
|
const data = canvasAndCtx.canvas.toDataURL();
|
|
|
|
CanvasFactory.destroy(canvasAndCtx);
|
|
|
|
return data;
|
2015-07-14 18:43:20 +09:00
|
|
|
}
|
|
|
|
|
2016-03-29 23:34:13 +09:00
|
|
|
afterEach(function(done) {
|
2015-07-14 18:43:20 +09:00
|
|
|
// 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.
|
2019-03-11 20:43:44 +09:00
|
|
|
const destroyPromises = loadingTasks.map(function(loadingTask) {
|
2016-01-21 07:57:17 +09:00
|
|
|
return loadingTask.destroy();
|
|
|
|
});
|
2019-03-11 20:43:44 +09:00
|
|
|
Promise.all(destroyPromises).then(done);
|
2015-07-14 18:43:20 +09:00
|
|
|
});
|
|
|
|
|
2016-03-29 23:34:13 +09:00
|
|
|
it('should correctly render PDFs in parallel', function(done) {
|
2015-07-14 18:43:20 +09:00
|
|
|
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;
|
|
|
|
});
|
2016-03-29 23:34:13 +09:00
|
|
|
promiseDone.then(function() {
|
|
|
|
done();
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2015-07-14 18:43:20 +09:00
|
|
|
});
|
|
|
|
});
|
2019-02-17 22:38:41 +09:00
|
|
|
|
|
|
|
describe('PDFDataRangeTransport', function() {
|
|
|
|
let dataPromise;
|
|
|
|
|
|
|
|
beforeAll(function(done) {
|
|
|
|
const fileName = 'tracemonkey.pdf';
|
2019-11-11 00:42:46 +09:00
|
|
|
if (isNodeJS) {
|
2019-02-17 22:38:41 +09:00
|
|
|
dataPromise = NodeFileReaderFactory.fetch({
|
|
|
|
path: TEST_PDFS_PATH.node + fileName,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
dataPromise = DOMFileReaderFactory.fetch({
|
|
|
|
path: TEST_PDFS_PATH.dom + fileName,
|
|
|
|
});
|
2018-03-18 03:56:39 +09:00
|
|
|
}
|
2019-02-17 22:38:41 +09:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(function() {
|
|
|
|
dataPromise = null;
|
|
|
|
});
|
2018-03-18 03:56:39 +09:00
|
|
|
|
2019-02-17 22:38:41 +09:00
|
|
|
it('should fetch document info and page using ranges', function(done) {
|
|
|
|
const initialDataLength = 4000;
|
|
|
|
let fetches = 0, loadingTask;
|
|
|
|
|
|
|
|
dataPromise.then(function(data) {
|
|
|
|
const initialData = data.subarray(0, initialDataLength);
|
|
|
|
const transport = new PDFDataRangeTransport(data.length, initialData);
|
|
|
|
transport.requestDataRange = function(begin, end) {
|
2016-02-10 05:55:11 +09:00
|
|
|
fetches++;
|
2019-02-17 22:38:41 +09:00
|
|
|
waitSome(function() {
|
2016-02-10 05:55:11 +09:00
|
|
|
transport.onDataProgress(4000);
|
|
|
|
transport.onDataRange(begin, data.subarray(begin, end));
|
|
|
|
});
|
|
|
|
};
|
2019-02-17 22:38:41 +09:00
|
|
|
loadingTask = getDocument(transport);
|
2016-02-10 05:55:11 +09:00
|
|
|
return loadingTask.promise;
|
2019-02-17 22:38:41 +09:00
|
|
|
}).then(function(pdfDocument) {
|
2016-02-10 05:55:11 +09:00
|
|
|
expect(pdfDocument.numPages).toEqual(14);
|
2019-02-17 22:38:41 +09:00
|
|
|
|
|
|
|
return pdfDocument.getPage(10);
|
|
|
|
}).then(function(pdfPage) {
|
|
|
|
expect(pdfPage.rotate).toEqual(0);
|
2016-02-10 05:55:11 +09:00
|
|
|
expect(fetches).toBeGreaterThan(2);
|
2019-02-17 22:38:41 +09:00
|
|
|
|
|
|
|
loadingTask.destroy().then(done);
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2016-02-10 05:55:11 +09:00
|
|
|
});
|
2019-02-17 22:38:41 +09:00
|
|
|
|
2016-02-10 05:55:11 +09:00
|
|
|
it('should fetch document info and page using range and streaming',
|
2019-02-17 22:38:41 +09:00
|
|
|
function(done) {
|
|
|
|
const initialDataLength = 4000;
|
|
|
|
let fetches = 0, loadingTask;
|
2018-03-18 03:56:39 +09:00
|
|
|
|
2019-02-17 22:38:41 +09:00
|
|
|
dataPromise.then(function(data) {
|
|
|
|
const initialData = data.subarray(0, initialDataLength);
|
|
|
|
const transport = new PDFDataRangeTransport(data.length, initialData);
|
|
|
|
transport.requestDataRange = function(begin, end) {
|
2016-02-10 05:55:11 +09:00
|
|
|
fetches++;
|
|
|
|
if (fetches === 1) {
|
2019-02-17 22:38:41 +09:00
|
|
|
// Send rest of the data on first range request.
|
2016-02-10 05:55:11 +09:00
|
|
|
transport.onDataProgressiveRead(data.subarray(initialDataLength));
|
|
|
|
}
|
2019-02-17 22:38:41 +09:00
|
|
|
waitSome(function() {
|
2016-02-10 05:55:11 +09:00
|
|
|
transport.onDataRange(begin, data.subarray(begin, end));
|
|
|
|
});
|
|
|
|
};
|
2019-02-17 22:38:41 +09:00
|
|
|
loadingTask = getDocument(transport);
|
2016-02-10 05:55:11 +09:00
|
|
|
return loadingTask.promise;
|
2019-02-17 22:38:41 +09:00
|
|
|
}).then(function(pdfDocument) {
|
2016-02-10 05:55:11 +09:00
|
|
|
expect(pdfDocument.numPages).toEqual(14);
|
2019-02-17 22:38:41 +09:00
|
|
|
|
|
|
|
return pdfDocument.getPage(10);
|
|
|
|
}).then(function(pdfPage) {
|
|
|
|
expect(pdfPage.rotate).toEqual(0);
|
2016-02-10 05:55:11 +09:00
|
|
|
expect(fetches).toEqual(1);
|
2019-02-17 22:38:41 +09:00
|
|
|
|
|
|
|
waitSome(function() {
|
|
|
|
loadingTask.destroy().then(done);
|
|
|
|
});
|
2018-09-03 04:15:08 +09:00
|
|
|
}).catch(done.fail);
|
2016-02-10 05:55:11 +09:00
|
|
|
});
|
[Firefox regression] Fix `disableRange=true` bug in `PDFDataTransportStream`
Currently if trying to set `disableRange=true` in the built-in PDF Viewer in Firefox, either through `about:config` or via the URL hash, the PDF document will never load. It appears that this has been broken for a couple of years, without anyone noticing.
Obviously it's not a good idea to set `disableRange=true`, however it seems that this bug affects the PDF Viewer in Firefox even with default settings:
- In the case where `initialData` already contains the *entire* file, we're forced to dispatch a range request to re-fetch already available data just so that file loading may complete.
- (In the case where the data arrives, via streaming, before being specifically requested through `requestDataRange`, we're also forced to re-fetch data unnecessarily.) *This part was removed, to reduce the scope/risk of the patch somewhat.*
In the cases outlined above, we're having to re-fetch already available data thus potentially delaying loading/rendering of PDF files in Firefox (and wasting resources in the process).
2019-03-27 00:05:30 +09:00
|
|
|
|
|
|
|
it('should fetch document info and page, without range, ' +
|
|
|
|
'using complete initialData', function(done) {
|
|
|
|
let fetches = 0, loadingTask;
|
|
|
|
|
|
|
|
dataPromise.then(function(data) {
|
|
|
|
const transport =
|
|
|
|
new PDFDataRangeTransport(data.length, data,
|
|
|
|
/* progressiveDone = */ true);
|
|
|
|
transport.requestDataRange = function(begin, end) {
|
|
|
|
fetches++;
|
|
|
|
};
|
|
|
|
loadingTask = getDocument({ disableRange: true, range: transport, });
|
|
|
|
return loadingTask.promise;
|
|
|
|
}).then(function(pdfDocument) {
|
|
|
|
expect(pdfDocument.numPages).toEqual(14);
|
|
|
|
|
|
|
|
return pdfDocument.getPage(10);
|
|
|
|
}).then(function(pdfPage) {
|
|
|
|
expect(pdfPage.rotate).toEqual(0);
|
|
|
|
expect(fetches).toEqual(0);
|
|
|
|
|
|
|
|
loadingTask.destroy().then(done);
|
|
|
|
}).catch(done.fail);
|
|
|
|
});
|
2016-02-10 05:55:11 +09:00
|
|
|
});
|
2012-04-13 09:59:30 +09:00
|
|
|
});
|