Improve the API unit-tests by checking that getDocument
returns a PDFDocumentLoadingTask
-instance
This is similar to existing unit-tests, which checks for `PDFDocumentProxy`- and `PDFPageProxy`-instances.
This commit is contained in:
parent
064c21d360
commit
fa7a607d33
@ -3361,6 +3361,7 @@ export {
|
|||||||
getDocument,
|
getDocument,
|
||||||
LoopbackPort,
|
LoopbackPort,
|
||||||
PDFDataRangeTransport,
|
PDFDataRangeTransport,
|
||||||
|
PDFDocumentLoadingTask,
|
||||||
PDFDocumentProxy,
|
PDFDocumentProxy,
|
||||||
PDFPageProxy,
|
PDFPageProxy,
|
||||||
PDFWorker,
|
PDFWorker,
|
||||||
|
@ -35,6 +35,7 @@ import {
|
|||||||
DefaultCanvasFactory,
|
DefaultCanvasFactory,
|
||||||
getDocument,
|
getDocument,
|
||||||
PDFDataRangeTransport,
|
PDFDataRangeTransport,
|
||||||
|
PDFDocumentLoadingTask,
|
||||||
PDFDocumentProxy,
|
PDFDocumentProxy,
|
||||||
PDFPageProxy,
|
PDFPageProxy,
|
||||||
PDFWorker,
|
PDFWorker,
|
||||||
@ -75,6 +76,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 +95,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 +107,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 +132,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 +148,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 +168,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 +188,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 +211,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 +227,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 +274,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 +296,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 +318,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 +339,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 +400,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 +419,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;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user