Merge pull request #19003 from Snuffleupagus/api-unittest-image-helpers
Add helper functions to load image blob/bitmap data in `test/unit/api_spec.js`
This commit is contained in:
commit
1a56b35af7
@ -46,6 +46,7 @@ import {
|
|||||||
RenderTask,
|
RenderTask,
|
||||||
} from "../../src/display/api.js";
|
} from "../../src/display/api.js";
|
||||||
import {
|
import {
|
||||||
|
fetchData as fetchDataDOM,
|
||||||
PageViewport,
|
PageViewport,
|
||||||
RenderingCancelledException,
|
RenderingCancelledException,
|
||||||
StatTimer,
|
StatTimer,
|
||||||
@ -117,6 +118,21 @@ describe("api", function () {
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getImageBlob(filename) {
|
||||||
|
if (isNodeJS) {
|
||||||
|
throw new Error("Not implemented.");
|
||||||
|
}
|
||||||
|
const TEST_IMAGES_PATH = "../images/";
|
||||||
|
const url = new URL(TEST_IMAGES_PATH + filename, window.location).href;
|
||||||
|
|
||||||
|
return fetchDataDOM(url, /* type = */ "blob");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getImageBitmap(filename) {
|
||||||
|
const blob = await getImageBlob(filename);
|
||||||
|
return createImageBitmap(blob);
|
||||||
|
}
|
||||||
|
|
||||||
describe("getDocument", function () {
|
describe("getDocument", 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;
|
||||||
@ -2472,14 +2488,7 @@ describe("api", function () {
|
|||||||
if (isNodeJS) {
|
if (isNodeJS) {
|
||||||
pending("Cannot create a bitmap from Node.js.");
|
pending("Cannot create a bitmap from Node.js.");
|
||||||
}
|
}
|
||||||
|
const bitmap = await getImageBitmap("firefox_logo.png");
|
||||||
const TEST_IMAGES_PATH = "../images/";
|
|
||||||
const filename = "firefox_logo.png";
|
|
||||||
const path = new URL(TEST_IMAGES_PATH + filename, window.location).href;
|
|
||||||
|
|
||||||
const response = await fetch(path);
|
|
||||||
const blob = await response.blob();
|
|
||||||
const bitmap = await createImageBitmap(blob);
|
|
||||||
|
|
||||||
let loadingTask = getDocument(buildGetDocumentParams("empty.pdf"));
|
let loadingTask = getDocument(buildGetDocumentParams("empty.pdf"));
|
||||||
let pdfDoc = await loadingTask.promise;
|
let pdfDoc = await loadingTask.promise;
|
||||||
@ -2524,14 +2533,7 @@ describe("api", function () {
|
|||||||
if (isNodeJS) {
|
if (isNodeJS) {
|
||||||
pending("Cannot create a bitmap from Node.js.");
|
pending("Cannot create a bitmap from Node.js.");
|
||||||
}
|
}
|
||||||
|
const bitmap = await getImageBitmap("firefox_logo.png");
|
||||||
const TEST_IMAGES_PATH = "../images/";
|
|
||||||
const filename = "firefox_logo.png";
|
|
||||||
const path = new URL(TEST_IMAGES_PATH + filename, window.location).href;
|
|
||||||
|
|
||||||
const response = await fetch(path);
|
|
||||||
const blob = await response.blob();
|
|
||||||
const bitmap = await createImageBitmap(blob);
|
|
||||||
|
|
||||||
let loadingTask = getDocument(buildGetDocumentParams("bug1823296.pdf"));
|
let loadingTask = getDocument(buildGetDocumentParams("bug1823296.pdf"));
|
||||||
let pdfDoc = await loadingTask.promise;
|
let pdfDoc = await loadingTask.promise;
|
||||||
@ -2636,14 +2638,7 @@ describe("api", function () {
|
|||||||
if (isNodeJS) {
|
if (isNodeJS) {
|
||||||
pending("Cannot create a bitmap from Node.js.");
|
pending("Cannot create a bitmap from Node.js.");
|
||||||
}
|
}
|
||||||
|
const bitmap = await getImageBitmap("firefox_logo.png");
|
||||||
const TEST_IMAGES_PATH = "../images/";
|
|
||||||
const filename = "firefox_logo.png";
|
|
||||||
const path = new URL(TEST_IMAGES_PATH + filename, window.location).href;
|
|
||||||
|
|
||||||
const response = await fetch(path);
|
|
||||||
const blob = await response.blob();
|
|
||||||
const bitmap = await createImageBitmap(blob);
|
|
||||||
|
|
||||||
let loadingTask = getDocument(
|
let loadingTask = getDocument(
|
||||||
buildGetDocumentParams("pdfjs_wikipedia.pdf")
|
buildGetDocumentParams("pdfjs_wikipedia.pdf")
|
||||||
@ -2734,13 +2729,8 @@ describe("api", function () {
|
|||||||
if (isNodeJS) {
|
if (isNodeJS) {
|
||||||
pending("Cannot create a bitmap from Node.js.");
|
pending("Cannot create a bitmap from Node.js.");
|
||||||
}
|
}
|
||||||
|
const blob = await getImageBlob("firefox_logo.png");
|
||||||
|
|
||||||
const TEST_IMAGES_PATH = "../images/";
|
|
||||||
const filename = "firefox_logo.png";
|
|
||||||
const path = new URL(TEST_IMAGES_PATH + filename, window.location).href;
|
|
||||||
|
|
||||||
const response = await fetch(path);
|
|
||||||
const blob = await response.blob();
|
|
||||||
let loadingTask, pdfDoc;
|
let loadingTask, pdfDoc;
|
||||||
let data = buildGetDocumentParams("empty.pdf");
|
let data = buildGetDocumentParams("empty.pdf");
|
||||||
|
|
||||||
@ -2804,14 +2794,7 @@ describe("api", function () {
|
|||||||
if (isNodeJS) {
|
if (isNodeJS) {
|
||||||
pending("Cannot create a bitmap from Node.js.");
|
pending("Cannot create a bitmap from Node.js.");
|
||||||
}
|
}
|
||||||
|
const bitmap = await getImageBitmap("firefox_logo.png");
|
||||||
const TEST_IMAGES_PATH = "../images/";
|
|
||||||
const filename = "firefox_logo.png";
|
|
||||||
const path = new URL(TEST_IMAGES_PATH + filename, window.location).href;
|
|
||||||
|
|
||||||
const response = await fetch(path);
|
|
||||||
const blob = await response.blob();
|
|
||||||
const bitmap = await createImageBitmap(blob);
|
|
||||||
|
|
||||||
let loadingTask = getDocument(buildGetDocumentParams("empty.pdf"));
|
let loadingTask = getDocument(buildGetDocumentParams("empty.pdf"));
|
||||||
let pdfDoc = await loadingTask.promise;
|
let pdfDoc = await loadingTask.promise;
|
||||||
@ -2860,14 +2843,7 @@ describe("api", function () {
|
|||||||
if (isNodeJS) {
|
if (isNodeJS) {
|
||||||
pending("Cannot create a bitmap from Node.js.");
|
pending("Cannot create a bitmap from Node.js.");
|
||||||
}
|
}
|
||||||
|
const bitmap = await getImageBitmap("firefox_logo.png");
|
||||||
const TEST_IMAGES_PATH = "../images/";
|
|
||||||
const filename = "firefox_logo.png";
|
|
||||||
const path = new URL(TEST_IMAGES_PATH + filename, window.location).href;
|
|
||||||
|
|
||||||
const response = await fetch(path);
|
|
||||||
const blob = await response.blob();
|
|
||||||
const bitmap = await createImageBitmap(blob);
|
|
||||||
|
|
||||||
let loadingTask = getDocument(buildGetDocumentParams("empty.pdf"));
|
let loadingTask = getDocument(buildGetDocumentParams("empty.pdf"));
|
||||||
let pdfDoc = await loadingTask.promise;
|
let pdfDoc = await loadingTask.promise;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user