mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Merge pull request #6546 from yurydelendik/destroy
[api-minor] Adds controlled destruction of the worker.
This commit is contained in:
commit
2a5616c2aa
17 changed files with 524 additions and 167 deletions
|
@ -11,31 +11,31 @@ describe('api', function() {
|
|||
var basicApiUrl = combineUrl(window.location.href, '../pdfs/basicapi.pdf');
|
||||
var basicApiFileLength = 105779; // bytes
|
||||
function waitsForPromiseResolved(promise, successCallback) {
|
||||
var data;
|
||||
var resolved = false;
|
||||
promise.then(function(val) {
|
||||
data = val;
|
||||
successCallback(data);
|
||||
resolved = true;
|
||||
successCallback(val);
|
||||
},
|
||||
function(error) {
|
||||
// Shouldn't get here.
|
||||
expect(false).toEqual(true);
|
||||
});
|
||||
waitsFor(function() {
|
||||
return data !== undefined;
|
||||
return resolved;
|
||||
}, 20000);
|
||||
}
|
||||
function waitsForPromiseRejected(promise, failureCallback) {
|
||||
var data;
|
||||
var rejected = false;
|
||||
promise.then(function(val) {
|
||||
// Shouldn't get here.
|
||||
expect(false).toEqual(true);
|
||||
},
|
||||
function(error) {
|
||||
data = error;
|
||||
failureCallback(data);
|
||||
rejected = true;
|
||||
failureCallback(error);
|
||||
});
|
||||
waitsFor(function() {
|
||||
return data !== undefined;
|
||||
return rejected;
|
||||
}, 20000);
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,28 @@ describe('api', function() {
|
|||
waitsForPromiseResolved(Promise.all(promises), function (data) {
|
||||
expect((data[0].loaded / data[0].total) > 0).toEqual(true);
|
||||
expect(data[1] instanceof PDFDocumentProxy).toEqual(true);
|
||||
expect(loadingTask).toEqual(data[1].loadingTask);
|
||||
});
|
||||
});
|
||||
it('creates pdf doc from URL and aborts before worker initialized',
|
||||
function() {
|
||||
var loadingTask = PDFJS.getDocument(basicApiUrl);
|
||||
loadingTask.destroy();
|
||||
waitsForPromiseRejected(loadingTask.promise, function(reason) {
|
||||
expect(true).toEqual(true);
|
||||
});
|
||||
});
|
||||
it('creates pdf doc from URL and aborts loading after worker initialized',
|
||||
function() {
|
||||
var loadingTask = PDFJS.getDocument(basicApiUrl);
|
||||
// This can be somewhat random -- we cannot guarantee perfect
|
||||
// 'Terminate' message to the worker before/after setting up pdfManager.
|
||||
var destroyed = loadingTask._transport.workerInitializedCapability.
|
||||
promise.then(function () {
|
||||
return loadingTask.destroy();
|
||||
});
|
||||
waitsForPromiseResolved(destroyed, function (data) {
|
||||
expect(true).toEqual(true);
|
||||
});
|
||||
});
|
||||
it('creates pdf doc from typed array', function() {
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
/* globals expect, it, describe, PartialEvaluator, StringStream, OPS,
|
||||
OperatorList, waitsFor, runs, Dict, Name, Stream */
|
||||
OperatorList, waitsFor, runs, Dict, Name, Stream, WorkerTask */
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('evaluator', function() {
|
||||
function XrefMock(queue) {
|
||||
this.queue = queue;
|
||||
this.queue = queue || [];
|
||||
}
|
||||
XrefMock.prototype = {
|
||||
fetchIfRef: function() {
|
||||
|
@ -35,7 +35,9 @@ describe('evaluator', function() {
|
|||
var done = false;
|
||||
runs(function () {
|
||||
var result = new OperatorList();
|
||||
evaluator.getOperatorList(stream, resources, result).then(function () {
|
||||
var task = new WorkerTask('OperatorListCheck');
|
||||
evaluator.getOperatorList(stream, task, resources, result).then(
|
||||
function () {
|
||||
check(result);
|
||||
done = true;
|
||||
});
|
||||
|
@ -259,4 +261,48 @@ describe('evaluator', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('thread control', function() {
|
||||
it('should abort operator list parsing', function () {
|
||||
var evaluator = new PartialEvaluator(new PdfManagerMock(),
|
||||
new XrefMock(), new HandlerMock(),
|
||||
'prefix');
|
||||
var stream = new StringStream('qqQQ');
|
||||
var resources = new ResourcesMock();
|
||||
var done = false;
|
||||
runs(function () {
|
||||
var result = new OperatorList();
|
||||
var task = new WorkerTask('OperatorListAbort');
|
||||
task.terminate();
|
||||
evaluator.getOperatorList(stream, task, resources, result).catch(
|
||||
function () {
|
||||
done = true;
|
||||
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
||||
expect(result.fnArray.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
waitsFor(function () {
|
||||
return done;
|
||||
});
|
||||
});
|
||||
it('should abort text parsing parsing', function () {
|
||||
var resources = new ResourcesMock();
|
||||
var evaluator = new PartialEvaluator(new PdfManagerMock(),
|
||||
new XrefMock(), new HandlerMock(),
|
||||
'prefix');
|
||||
var stream = new StringStream('qqQQ');
|
||||
var done = false;
|
||||
runs(function () {
|
||||
var task = new WorkerTask('TextContentAbort');
|
||||
task.terminate();
|
||||
evaluator.getTextContent(stream, task, resources).catch(
|
||||
function () {
|
||||
done = true;
|
||||
});
|
||||
});
|
||||
waitsFor(function () {
|
||||
return done;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
<script src="../../src/core/parser.js"></script>
|
||||
<script src="../../src/core/ps_parser.js"></script>
|
||||
<script src="../../src/display/pattern_helper.js"></script>
|
||||
<script src="../../src/display/font_loader.js"></script>
|
||||
<script src="../../src/display/annotation_helper.js"></script>
|
||||
<script src="../../src/core/stream.js"></script>
|
||||
<script src="../../src/core/worker.js"></script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue