1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

[api-minor] Add more general OpenAction support (PR 10334 follow-up, issue 11642)

This patch deprecates the existing `getOpenActionDestination` API method, in favor of a better and more general `getOpenAction` method instead. (For now JavaScript actions, related to printing, are still handled as before.)

By clearly separating "regular" Print actions from the JavaScript handling, it's thus possible to get rid of the somewhat annoying and strictly incorrect warning when the viewer loads.
This commit is contained in:
Jonas Jenwald 2020-02-28 14:54:07 +01:00
parent 25693c6b6d
commit 01fb309a2a
5 changed files with 117 additions and 97 deletions

View file

@ -863,29 +863,69 @@ describe("api", function() {
.catch(done.fail);
});
it("gets default open action destination", function(done) {
it("gets default open action", function(done) {
var loadingTask = getDocument(buildGetDocumentParams("tracemonkey.pdf"));
loadingTask.promise
.then(function(pdfDocument) {
return pdfDocument.getOpenActionDestination();
return pdfDocument.getOpenAction();
})
.then(function(dest) {
expect(dest).toEqual(null);
.then(function(openAction) {
expect(openAction).toEqual(null);
loadingTask.destroy().then(done);
})
.catch(done.fail);
});
it("gets non-default open action destination", function(done) {
it("gets non-default open action (with destination)", function(done) {
doc
.getOpenActionDestination()
.then(function(dest) {
expect(dest).toEqual([{ num: 15, gen: 0 }, { name: "FitH" }, null]);
.getOpenAction()
.then(function(openAction) {
expect(openAction.dest).toEqual([
{ num: 15, gen: 0 },
{ name: "FitH" },
null,
]);
expect(openAction.action).toBeUndefined();
done();
})
.catch(done.fail);
});
it("gets non-default open action (with Print action)", function(done) {
// PDF document with "Print" Named action in the OpenAction dictionary.
const loadingTask1 = getDocument(
buildGetDocumentParams("bug1001080.pdf")
);
// PDF document with "Print" Named action in the OpenAction dictionary,
// but the OpenAction dictionary is missing the `Type` entry.
const loadingTask2 = getDocument(
buildGetDocumentParams("issue11442_reduced.pdf")
);
const promise1 = loadingTask1.promise
.then(function(pdfDocument) {
return pdfDocument.getOpenAction();
})
.then(function(openAction) {
expect(openAction.dest).toBeUndefined();
expect(openAction.action).toEqual("Print");
return loadingTask1.destroy();
});
const promise2 = loadingTask2.promise
.then(function(pdfDocument) {
return pdfDocument.getOpenAction();
})
.then(function(openAction) {
expect(openAction.dest).toBeUndefined();
expect(openAction.action).toEqual("Print");
return loadingTask2.destroy();
});
Promise.all([promise1, promise2]).then(done, done.fail);
});
it("gets non-existent attachments", function(done) {
var promise = doc.getAttachments();
@ -923,37 +963,6 @@ describe("api", function() {
})
.catch(done.fail);
});
it("gets javascript with printing instructions (Print action)", function(done) {
// PDF document with "Print" Named action in the OpenAction dictionary.
var loadingTask = getDocument(buildGetDocumentParams("bug1001080.pdf"));
var promise = loadingTask.promise.then(function(doc) {
return doc.getJavaScript();
});
promise
.then(function(data) {
expect(data).toEqual(["print({});"]);
expect(data[0]).toMatch(AutoPrintRegExp);
loadingTask.destroy().then(done);
})
.catch(done.fail);
});
it("gets javascript with printing instructions (Print action without type)", function(done) {
// PDF document with "Print" Named action in the OpenAction dictionary,
// but the OpenAction dictionary is missing the `Type` entry.
var loadingTask = getDocument(
buildGetDocumentParams("issue11442_reduced.pdf")
);
var promise = loadingTask.promise.then(function(doc) {
return doc.getJavaScript();
});
promise
.then(function(data) {
expect(data).toEqual(["print({});"]);
expect(data[0]).toMatch(AutoPrintRegExp);
loadingTask.destroy().then(done);
})
.catch(done.fail);
});
it("gets javascript with printing instructions (JS action)", function(done) {
// PDF document with "JavaScript" action in the OpenAction dictionary.
var loadingTask = getDocument(buildGetDocumentParams("issue6106.pdf"));