Allow to have an URL as file parameter when loading the viewer
This commit is contained in:
parent
c7796c7f8d
commit
eafc040734
@ -53,9 +53,11 @@ function loadAndWait(filename, selector, zoom, setups, options, viewport) {
|
||||
app_options += `&${key}=${encodeURIComponent(value)}`;
|
||||
}
|
||||
}
|
||||
const url = `${
|
||||
global.integrationBaseUrl
|
||||
}?file=/test/pdfs/${filename}#zoom=${zoom ?? "page-fit"}${app_options}`;
|
||||
|
||||
const fileParam = filename.startsWith("http")
|
||||
? filename
|
||||
: `/test/pdfs/${filename}`;
|
||||
const url = `${global.integrationBaseUrl}?file=${fileParam}#zoom=${zoom ?? "page-fit"}${app_options}`;
|
||||
|
||||
if (setups) {
|
||||
// page.evaluateOnNewDocument allows us to run code before the
|
||||
|
||||
@ -1244,4 +1244,33 @@ describe("PDF viewer", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("File param with an URL", () => {
|
||||
let pages;
|
||||
|
||||
beforeEach(async () => {
|
||||
const baseURL = new URL(global.integrationBaseUrl);
|
||||
const url = `${baseURL.origin}/build/generic/web/compressed.tracemonkey-pldi-09.pdf`;
|
||||
pages = await loadAndWait(
|
||||
encodeURIComponent(url),
|
||||
".textLayer .endOfContent"
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await closePages(pages);
|
||||
});
|
||||
|
||||
it("must load and extract the filename correctly", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
const filename = await page.evaluate(() => document.title);
|
||||
|
||||
expect(filename)
|
||||
.withContext(`In ${browserName}`)
|
||||
.toBe("compressed.tracemonkey-pldi-09.pdf");
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -727,7 +727,11 @@ const PDFViewerApplication = {
|
||||
const queryString = document.location.search.substring(1);
|
||||
const params = parseQueryString(queryString);
|
||||
file = params.get("file") ?? AppOptions.get("defaultUrl");
|
||||
try {
|
||||
file = new URL(decodeURIComponent(file)).href;
|
||||
} catch {
|
||||
file = encodeURIComponent(file).replaceAll("%2F", "/");
|
||||
}
|
||||
validateFileURL(file);
|
||||
} else if (PDFJSDev.test("MOZCENTRAL")) {
|
||||
file = window.location.href;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user