mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
JS -- Plug PageOpen and PageClose actions
This commit is contained in:
parent
ed3758f84d
commit
6523f8880b
5 changed files with 172 additions and 16 deletions
|
@ -16,8 +16,10 @@
|
|||
const { clearInput, closePages, loadAndWait } = require("./test_utils.js");
|
||||
|
||||
describe("Interaction", () => {
|
||||
async function actAndWaitForInput(page, selector, action) {
|
||||
await clearInput(page, selector);
|
||||
async function actAndWaitForInput(page, selector, action, clear = true) {
|
||||
if (clear) {
|
||||
await clearInput(page, selector);
|
||||
}
|
||||
await action();
|
||||
await page.waitForFunction(
|
||||
`document.querySelector("${selector.replace("\\", "\\\\")}").value !== ""`
|
||||
|
@ -307,6 +309,18 @@ describe("Interaction", () => {
|
|||
if (process.platform === "win32" && browserName === "firefox") {
|
||||
pending("Disabled in Firefox on Windows, because of bug 1662471.");
|
||||
}
|
||||
await page.waitForFunction(
|
||||
"window.PDFViewerApplication.scriptingReady === true"
|
||||
);
|
||||
|
||||
await clearInput(page, "#\\34 7R");
|
||||
await page.evaluate(_ => {
|
||||
window.document.activeElement.blur();
|
||||
});
|
||||
await page.waitForFunction(
|
||||
`document.querySelector("#\\\\34 7R").value === ""`
|
||||
);
|
||||
|
||||
let text = await actAndWaitForInput(page, "#\\34 7R", async () => {
|
||||
await page.click("#print");
|
||||
});
|
||||
|
@ -337,6 +351,10 @@ describe("Interaction", () => {
|
|||
it("must execute WillSave and DidSave actions", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
await page.waitForFunction(
|
||||
"window.PDFViewerApplication.scriptingReady === true"
|
||||
);
|
||||
|
||||
try {
|
||||
// Disable download in chrome
|
||||
// (it leads to an error in firefox so the try...)
|
||||
|
@ -345,6 +363,13 @@ describe("Interaction", () => {
|
|||
});
|
||||
} catch (_) {}
|
||||
await clearInput(page, "#\\34 7R");
|
||||
await page.evaluate(_ => {
|
||||
window.document.activeElement.blur();
|
||||
});
|
||||
await page.waitForFunction(
|
||||
`document.querySelector("#\\\\34 7R").value === ""`
|
||||
);
|
||||
|
||||
let text = await actAndWaitForInput(page, "#\\34 7R", async () => {
|
||||
await page.click("#download");
|
||||
});
|
||||
|
@ -360,4 +385,70 @@ describe("Interaction", () => {
|
|||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("in doc_actions.pdf for page actions", () => {
|
||||
let pages;
|
||||
|
||||
beforeAll(async () => {
|
||||
pages = await loadAndWait("doc_actions.pdf", "#\\34 7R");
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await closePages(pages);
|
||||
});
|
||||
|
||||
it("must execute PageOpen and PageClose actions", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
await page.waitForFunction(
|
||||
"window.PDFViewerApplication.scriptingReady === true"
|
||||
);
|
||||
|
||||
let text = await page.$eval("#\\34 7R", el => el.value);
|
||||
expect(text).withContext(`In ${browserName}`).toEqual("PageOpen 1");
|
||||
|
||||
for (let run = 0; run < 5; run++) {
|
||||
for (const ref of [18, 19, 20, 21, 47, 50]) {
|
||||
await page.evaluate(refElem => {
|
||||
const element = window.document.getElementById(`${refElem}R`);
|
||||
if (element) {
|
||||
element.value = "";
|
||||
}
|
||||
}, ref);
|
||||
}
|
||||
|
||||
for (const [refOpen, refClose, pageNumOpen, pageNumClose] of [
|
||||
[18, 50, 2, 1],
|
||||
[21, 19, 3, 2],
|
||||
[47, 20, 1, 3],
|
||||
]) {
|
||||
text = await actAndWaitForInput(
|
||||
page,
|
||||
`#\\3${Math.floor(refOpen / 10)} ${refOpen % 10}R`,
|
||||
async () => {
|
||||
await page.evaluate(refElem => {
|
||||
window.document
|
||||
.getElementById(`${refElem}R`)
|
||||
.scrollIntoView();
|
||||
}, refOpen);
|
||||
},
|
||||
false
|
||||
);
|
||||
expect(text)
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(`PageOpen ${pageNumOpen}`);
|
||||
|
||||
text = await page.$eval(
|
||||
`#\\3${Math.floor(refClose / 10)} ${refClose % 10}R`,
|
||||
el => el.value
|
||||
);
|
||||
expect(text)
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(`PageClose ${pageNumClose}`);
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue