Merge pull request #14013 from Snuffleupagus/api-unittest-instanceof
Improve the API unit-tests, and try to expose more API-functionality in the TypeScript definitions
This commit is contained in:
commit
c870fb489e
@ -3361,9 +3361,11 @@ export {
|
|||||||
getDocument,
|
getDocument,
|
||||||
LoopbackPort,
|
LoopbackPort,
|
||||||
PDFDataRangeTransport,
|
PDFDataRangeTransport,
|
||||||
|
PDFDocumentLoadingTask,
|
||||||
PDFDocumentProxy,
|
PDFDocumentProxy,
|
||||||
PDFPageProxy,
|
PDFPageProxy,
|
||||||
PDFWorker,
|
PDFWorker,
|
||||||
|
RenderTask,
|
||||||
setPDFNetworkStreamFactory,
|
setPDFNetworkStreamFactory,
|
||||||
version,
|
version,
|
||||||
};
|
};
|
||||||
|
@ -14,6 +14,12 @@
|
|||||||
*/
|
*/
|
||||||
/* eslint-disable sort-exports/sort-exports */
|
/* eslint-disable sort-exports/sort-exports */
|
||||||
|
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
|
/** @typedef {import("./display/api").PDFDocumentLoadingTask} PDFDocumentLoadingTask */
|
||||||
|
/** @typedef {import("./display/api").PDFDocumentProxy} PDFDocumentProxy */
|
||||||
|
/** @typedef {import("./display/api").PDFPageProxy} PDFPageProxy */
|
||||||
|
/** @typedef {import("./display/api").RenderTask} RenderTask */
|
||||||
|
|
||||||
import {
|
import {
|
||||||
addLinkAttributes,
|
addLinkAttributes,
|
||||||
getFilenameFromUrl,
|
getFilenameFromUrl,
|
||||||
|
@ -35,9 +35,11 @@ import {
|
|||||||
DefaultCanvasFactory,
|
DefaultCanvasFactory,
|
||||||
getDocument,
|
getDocument,
|
||||||
PDFDataRangeTransport,
|
PDFDataRangeTransport,
|
||||||
|
PDFDocumentLoadingTask,
|
||||||
PDFDocumentProxy,
|
PDFDocumentProxy,
|
||||||
PDFPageProxy,
|
PDFPageProxy,
|
||||||
PDFWorker,
|
PDFWorker,
|
||||||
|
RenderTask,
|
||||||
} from "../../src/display/api.js";
|
} from "../../src/display/api.js";
|
||||||
import {
|
import {
|
||||||
RenderingCancelledException,
|
RenderingCancelledException,
|
||||||
@ -75,6 +77,7 @@ describe("api", function () {
|
|||||||
it("creates pdf doc from URL-string", async function () {
|
it("creates pdf doc from URL-string", async function () {
|
||||||
const urlStr = TEST_PDFS_PATH + basicApiFileName;
|
const urlStr = TEST_PDFS_PATH + basicApiFileName;
|
||||||
const loadingTask = getDocument(urlStr);
|
const loadingTask = getDocument(urlStr);
|
||||||
|
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
|
||||||
const pdfDocument = await loadingTask.promise;
|
const pdfDocument = await loadingTask.promise;
|
||||||
|
|
||||||
expect(typeof urlStr).toEqual("string");
|
expect(typeof urlStr).toEqual("string");
|
||||||
@ -93,6 +96,7 @@ describe("api", function () {
|
|||||||
window.location
|
window.location
|
||||||
);
|
);
|
||||||
const loadingTask = getDocument(urlObj);
|
const loadingTask = getDocument(urlObj);
|
||||||
|
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
|
||||||
const pdfDocument = await loadingTask.promise;
|
const pdfDocument = await loadingTask.promise;
|
||||||
|
|
||||||
expect(urlObj instanceof URL).toEqual(true);
|
expect(urlObj instanceof URL).toEqual(true);
|
||||||
@ -104,6 +108,7 @@ describe("api", function () {
|
|||||||
|
|
||||||
it("creates pdf doc from URL", async function () {
|
it("creates pdf doc from URL", async function () {
|
||||||
const loadingTask = getDocument(basicApiGetDocumentParams);
|
const loadingTask = getDocument(basicApiGetDocumentParams);
|
||||||
|
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
|
||||||
|
|
||||||
const progressReportedCapability = createPromiseCapability();
|
const progressReportedCapability = createPromiseCapability();
|
||||||
// Attach the callback that is used to report loading progress;
|
// Attach the callback that is used to report loading progress;
|
||||||
@ -128,6 +133,7 @@ describe("api", function () {
|
|||||||
|
|
||||||
it("creates pdf doc from URL and aborts before worker initialized", async function () {
|
it("creates pdf doc from URL and aborts before worker initialized", async function () {
|
||||||
const loadingTask = getDocument(basicApiGetDocumentParams);
|
const loadingTask = getDocument(basicApiGetDocumentParams);
|
||||||
|
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
|
||||||
const destroyed = loadingTask.destroy();
|
const destroyed = loadingTask.destroy();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -143,6 +149,7 @@ describe("api", function () {
|
|||||||
|
|
||||||
it("creates pdf doc from URL and aborts loading after worker initialized", async function () {
|
it("creates pdf doc from URL and aborts loading after worker initialized", async function () {
|
||||||
const loadingTask = getDocument(basicApiGetDocumentParams);
|
const loadingTask = getDocument(basicApiGetDocumentParams);
|
||||||
|
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
|
||||||
// This can be somewhat random -- we cannot guarantee perfect
|
// This can be somewhat random -- we cannot guarantee perfect
|
||||||
// 'Terminate' message to the worker before/after setting up pdfManager.
|
// 'Terminate' message to the worker before/after setting up pdfManager.
|
||||||
const destroyed = loadingTask._worker.promise.then(function () {
|
const destroyed = loadingTask._worker.promise.then(function () {
|
||||||
@ -162,6 +169,7 @@ describe("api", function () {
|
|||||||
expect(typedArrayPdf.length).toEqual(basicApiFileLength);
|
expect(typedArrayPdf.length).toEqual(basicApiFileLength);
|
||||||
|
|
||||||
const loadingTask = getDocument(typedArrayPdf);
|
const loadingTask = getDocument(typedArrayPdf);
|
||||||
|
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
|
||||||
|
|
||||||
const progressReportedCapability = createPromiseCapability();
|
const progressReportedCapability = createPromiseCapability();
|
||||||
loadingTask.onProgress = function (data) {
|
loadingTask.onProgress = function (data) {
|
||||||
@ -181,6 +189,7 @@ describe("api", function () {
|
|||||||
it("creates pdf doc from invalid PDF file", async function () {
|
it("creates pdf doc from invalid PDF file", async function () {
|
||||||
// A severely corrupt PDF file (even Adobe Reader fails to open it).
|
// A severely corrupt PDF file (even Adobe Reader fails to open it).
|
||||||
const loadingTask = getDocument(buildGetDocumentParams("bug1020226.pdf"));
|
const loadingTask = getDocument(buildGetDocumentParams("bug1020226.pdf"));
|
||||||
|
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await loadingTask.promise;
|
await loadingTask.promise;
|
||||||
@ -203,6 +212,7 @@ describe("api", function () {
|
|||||||
const loadingTask = getDocument(
|
const loadingTask = getDocument(
|
||||||
buildGetDocumentParams("non-existent.pdf")
|
buildGetDocumentParams("non-existent.pdf")
|
||||||
);
|
);
|
||||||
|
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await loadingTask.promise;
|
await loadingTask.promise;
|
||||||
@ -218,6 +228,7 @@ describe("api", function () {
|
|||||||
|
|
||||||
it("creates pdf doc from PDF file protected with user and owner password", async function () {
|
it("creates pdf doc from PDF file protected with user and owner password", async function () {
|
||||||
const loadingTask = getDocument(buildGetDocumentParams("pr6531_1.pdf"));
|
const loadingTask = getDocument(buildGetDocumentParams("pr6531_1.pdf"));
|
||||||
|
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
|
||||||
|
|
||||||
const passwordNeededCapability = createPromiseCapability();
|
const passwordNeededCapability = createPromiseCapability();
|
||||||
const passwordIncorrectCapability = createPromiseCapability();
|
const passwordIncorrectCapability = createPromiseCapability();
|
||||||
@ -264,6 +275,10 @@ describe("api", function () {
|
|||||||
password: "",
|
password: "",
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
expect(
|
||||||
|
passwordNeededLoadingTask instanceof PDFDocumentLoadingTask
|
||||||
|
).toEqual(true);
|
||||||
|
|
||||||
const result1 = passwordNeededLoadingTask.promise.then(
|
const result1 = passwordNeededLoadingTask.promise.then(
|
||||||
function () {
|
function () {
|
||||||
// Shouldn't get here.
|
// Shouldn't get here.
|
||||||
@ -282,6 +297,10 @@ describe("api", function () {
|
|||||||
password: "qwerty",
|
password: "qwerty",
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
expect(
|
||||||
|
passwordIncorrectLoadingTask instanceof PDFDocumentLoadingTask
|
||||||
|
).toEqual(true);
|
||||||
|
|
||||||
const result2 = passwordIncorrectLoadingTask.promise.then(
|
const result2 = passwordIncorrectLoadingTask.promise.then(
|
||||||
function () {
|
function () {
|
||||||
// Shouldn't get here.
|
// Shouldn't get here.
|
||||||
@ -300,6 +319,10 @@ describe("api", function () {
|
|||||||
password: "asdfasdf",
|
password: "asdfasdf",
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
expect(
|
||||||
|
passwordAcceptedLoadingTask instanceof PDFDocumentLoadingTask
|
||||||
|
).toEqual(true);
|
||||||
|
|
||||||
const result3 = passwordAcceptedLoadingTask.promise.then(function (data) {
|
const result3 = passwordAcceptedLoadingTask.promise.then(function (data) {
|
||||||
expect(data instanceof PDFDocumentProxy).toEqual(true);
|
expect(data instanceof PDFDocumentProxy).toEqual(true);
|
||||||
return passwordAcceptedLoadingTask.destroy();
|
return passwordAcceptedLoadingTask.destroy();
|
||||||
@ -317,11 +340,18 @@ describe("api", function () {
|
|||||||
const passwordNeededLoadingTask = getDocument(
|
const passwordNeededLoadingTask = getDocument(
|
||||||
buildGetDocumentParams(filename)
|
buildGetDocumentParams(filename)
|
||||||
);
|
);
|
||||||
|
expect(
|
||||||
|
passwordNeededLoadingTask instanceof PDFDocumentLoadingTask
|
||||||
|
).toEqual(true);
|
||||||
|
|
||||||
const passwordIncorrectLoadingTask = getDocument(
|
const passwordIncorrectLoadingTask = getDocument(
|
||||||
buildGetDocumentParams(filename, {
|
buildGetDocumentParams(filename, {
|
||||||
password: "qwerty",
|
password: "qwerty",
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
expect(
|
||||||
|
passwordIncorrectLoadingTask instanceof PDFDocumentLoadingTask
|
||||||
|
).toEqual(true);
|
||||||
|
|
||||||
let passwordNeededDestroyed;
|
let passwordNeededDestroyed;
|
||||||
passwordNeededLoadingTask.onPassword = function (callback, reason) {
|
passwordNeededLoadingTask.onPassword = function (callback, reason) {
|
||||||
@ -371,6 +401,7 @@ describe("api", function () {
|
|||||||
|
|
||||||
it("creates pdf doc from empty typed array", async function () {
|
it("creates pdf doc from empty typed array", async function () {
|
||||||
const loadingTask = getDocument(new Uint8Array(0));
|
const loadingTask = getDocument(new Uint8Array(0));
|
||||||
|
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await loadingTask.promise;
|
await loadingTask.promise;
|
||||||
@ -389,10 +420,12 @@ describe("api", function () {
|
|||||||
|
|
||||||
it("checks that `docId`s are unique and increasing", async function () {
|
it("checks that `docId`s are unique and increasing", async function () {
|
||||||
const loadingTask1 = getDocument(basicApiGetDocumentParams);
|
const loadingTask1 = getDocument(basicApiGetDocumentParams);
|
||||||
|
expect(loadingTask1 instanceof PDFDocumentLoadingTask).toEqual(true);
|
||||||
await loadingTask1.promise;
|
await loadingTask1.promise;
|
||||||
const docId1 = loadingTask1.docId;
|
const docId1 = loadingTask1.docId;
|
||||||
|
|
||||||
const loadingTask2 = getDocument(basicApiGetDocumentParams);
|
const loadingTask2 = getDocument(basicApiGetDocumentParams);
|
||||||
|
expect(loadingTask2 instanceof PDFDocumentLoadingTask).toEqual(true);
|
||||||
await loadingTask2.promise;
|
await loadingTask2.promise;
|
||||||
const docId2 = loadingTask2.docId;
|
const docId2 = loadingTask2.docId;
|
||||||
|
|
||||||
@ -1842,11 +1875,14 @@ describe("api", function () {
|
|||||||
viewport.width,
|
viewport.width,
|
||||||
viewport.height
|
viewport.height
|
||||||
);
|
);
|
||||||
|
|
||||||
const renderTask = pdfPage.render({
|
const renderTask = pdfPage.render({
|
||||||
canvasContext: canvasAndCtx.context,
|
canvasContext: canvasAndCtx.context,
|
||||||
canvasFactory: CanvasFactory,
|
canvasFactory: CanvasFactory,
|
||||||
viewport,
|
viewport,
|
||||||
});
|
});
|
||||||
|
expect(renderTask instanceof RenderTask).toEqual(true);
|
||||||
|
|
||||||
await renderTask.promise;
|
await renderTask.promise;
|
||||||
const stats = pdfPage.stats;
|
const stats = pdfPage.stats;
|
||||||
|
|
||||||
@ -1879,6 +1915,8 @@ describe("api", function () {
|
|||||||
canvasFactory: CanvasFactory,
|
canvasFactory: CanvasFactory,
|
||||||
viewport,
|
viewport,
|
||||||
});
|
});
|
||||||
|
expect(renderTask instanceof RenderTask).toEqual(true);
|
||||||
|
|
||||||
renderTask.cancel();
|
renderTask.cancel();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -1907,6 +1945,8 @@ describe("api", function () {
|
|||||||
canvasFactory: CanvasFactory,
|
canvasFactory: CanvasFactory,
|
||||||
viewport,
|
viewport,
|
||||||
});
|
});
|
||||||
|
expect(renderTask instanceof RenderTask).toEqual(true);
|
||||||
|
|
||||||
renderTask.cancel();
|
renderTask.cancel();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -1923,6 +1963,8 @@ describe("api", function () {
|
|||||||
canvasFactory: CanvasFactory,
|
canvasFactory: CanvasFactory,
|
||||||
viewport,
|
viewport,
|
||||||
});
|
});
|
||||||
|
expect(reRenderTask instanceof RenderTask).toEqual(true);
|
||||||
|
|
||||||
await reRenderTask.promise;
|
await reRenderTask.promise;
|
||||||
|
|
||||||
CanvasFactory.destroy(canvasAndCtx);
|
CanvasFactory.destroy(canvasAndCtx);
|
||||||
@ -1944,12 +1986,15 @@ describe("api", function () {
|
|||||||
viewport,
|
viewport,
|
||||||
optionalContentConfigPromise,
|
optionalContentConfigPromise,
|
||||||
});
|
});
|
||||||
|
expect(renderTask1 instanceof RenderTask).toEqual(true);
|
||||||
|
|
||||||
const renderTask2 = page.render({
|
const renderTask2 = page.render({
|
||||||
canvasContext: canvasAndCtx.context,
|
canvasContext: canvasAndCtx.context,
|
||||||
canvasFactory: CanvasFactory,
|
canvasFactory: CanvasFactory,
|
||||||
viewport,
|
viewport,
|
||||||
optionalContentConfigPromise,
|
optionalContentConfigPromise,
|
||||||
});
|
});
|
||||||
|
expect(renderTask2 instanceof RenderTask).toEqual(true);
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
renderTask1.promise,
|
renderTask1.promise,
|
||||||
@ -1982,8 +2027,9 @@ describe("api", function () {
|
|||||||
canvasFactory: CanvasFactory,
|
canvasFactory: CanvasFactory,
|
||||||
viewport,
|
viewport,
|
||||||
});
|
});
|
||||||
await renderTask.promise;
|
expect(renderTask instanceof RenderTask).toEqual(true);
|
||||||
|
|
||||||
|
await renderTask.promise;
|
||||||
await pdfDoc.cleanup();
|
await pdfDoc.cleanup();
|
||||||
|
|
||||||
expect(true).toEqual(true);
|
expect(true).toEqual(true);
|
||||||
@ -2010,6 +2056,8 @@ describe("api", function () {
|
|||||||
canvasFactory: CanvasFactory,
|
canvasFactory: CanvasFactory,
|
||||||
viewport,
|
viewport,
|
||||||
});
|
});
|
||||||
|
expect(renderTask instanceof RenderTask).toEqual(true);
|
||||||
|
|
||||||
// Ensure that clean-up runs during rendering.
|
// Ensure that clean-up runs during rendering.
|
||||||
renderTask.onContinue = function (cont) {
|
renderTask.onContinue = function (cont) {
|
||||||
waitSome(cont);
|
waitSome(cont);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user