Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper functions to load image blob/bitmap data in test/unit/api_spec.js #19003

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 22 additions & 46 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
RenderTask,
} from "../../src/display/api.js";
import {
fetchData as fetchDataDOM,
PageViewport,
RenderingCancelledException,
StatTimer,
Expand Down Expand Up @@ -117,6 +118,21 @@ describe("api", function () {
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 () {
it("creates pdf doc from URL-string", async function () {
const urlStr = TEST_PDFS_PATH + basicApiFileName;
Expand Down Expand Up @@ -2472,14 +2488,7 @@ describe("api", function () {
if (isNodeJS) {
pending("Cannot create a bitmap from Node.js.");
}

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);
const bitmap = await getImageBitmap("firefox_logo.png");

let loadingTask = getDocument(buildGetDocumentParams("empty.pdf"));
let pdfDoc = await loadingTask.promise;
Expand Down Expand Up @@ -2524,14 +2533,7 @@ describe("api", function () {
if (isNodeJS) {
pending("Cannot create a bitmap from Node.js.");
}

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);
const bitmap = await getImageBitmap("firefox_logo.png");

let loadingTask = getDocument(buildGetDocumentParams("bug1823296.pdf"));
let pdfDoc = await loadingTask.promise;
Expand Down Expand Up @@ -2636,14 +2638,7 @@ describe("api", function () {
if (isNodeJS) {
pending("Cannot create a bitmap from Node.js.");
}

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);
const bitmap = await getImageBitmap("firefox_logo.png");

let loadingTask = getDocument(
buildGetDocumentParams("pdfjs_wikipedia.pdf")
Expand Down Expand Up @@ -2734,13 +2729,8 @@ describe("api", function () {
if (isNodeJS) {
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 data = buildGetDocumentParams("empty.pdf");

Expand Down Expand Up @@ -2804,14 +2794,7 @@ describe("api", function () {
if (isNodeJS) {
pending("Cannot create a bitmap from Node.js.");
}

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);
const bitmap = await getImageBitmap("firefox_logo.png");

let loadingTask = getDocument(buildGetDocumentParams("empty.pdf"));
let pdfDoc = await loadingTask.promise;
Expand Down Expand Up @@ -2860,14 +2843,7 @@ describe("api", function () {
if (isNodeJS) {
pending("Cannot create a bitmap from Node.js.");
}

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);
const bitmap = await getImageBitmap("firefox_logo.png");

let loadingTask = getDocument(buildGetDocumentParams("empty.pdf"));
let pdfDoc = await loadingTask.promise;
Expand Down