1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

[JS] Run the named actions before running the format when the file is open (issue #15818)

It's a follow-up of #14950: some format actions are ran when the document is open
but we must be sure we've everything ready for that, hence we have to run some
named actions before runnig the global format.
In playing with the form, I discovered that the blur event wasn't triggered when
JS called `setFocus` (because in such a case the mouse was never down). So I removed
the mouseState thing to just use the correct commitKey when blur is triggered by a
TAB key.
This commit is contained in:
Calixte Denizet 2022-12-13 16:08:36 +01:00
parent 2d596045d1
commit 2ebf8745a2
11 changed files with 182 additions and 159 deletions

View file

@ -1002,43 +1002,43 @@ describe("Interaction", () => {
});
it("must check input for US zip format", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await page.waitForFunction(
"window.PDFViewerApplication.scriptingReady === true"
);
// Run the tests sequentially to avoid any focus issues between the two
// browsers when an alert is displayed.
for (const [browserName, page] of pages) {
await page.waitForFunction(
"window.PDFViewerApplication.scriptingReady === true"
);
await clearInput(page, getSelector("29R"));
await clearInput(page, getSelector("30R"));
await clearInput(page, getSelector("29R"));
await clearInput(page, getSelector("30R"));
await page.focus(getSelector("29R"));
await page.type(getSelector("29R"), "12A", { delay: 100 });
await page.waitForFunction(
`${getQuerySelector("29R")}.value !== "12A"`
);
await page.focus(getSelector("29R"));
await page.type(getSelector("29R"), "12A", { delay: 100 });
await page.waitForFunction(
`${getQuerySelector("29R")}.value !== "12A"`
);
let text = await page.$eval(getSelector(`29R`), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("12");
let text = await page.$eval(getSelector(`29R`), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("12");
await page.focus(getSelector("29R"));
await page.type(getSelector("29R"), "34", { delay: 100 });
await page.click("[data-annotation-id='30R']");
await page.focus(getSelector("29R"));
await page.type(getSelector("29R"), "34", { delay: 100 });
await page.click("[data-annotation-id='30R']");
await page.waitForFunction(
`${getQuerySelector("29R")}.value !== "1234"`
);
await page.waitForFunction(
`${getQuerySelector("29R")}.value !== "1234"`
);
text = await page.$eval(getSelector(`29R`), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("");
text = await page.$eval(getSelector(`29R`), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("");
await page.focus(getSelector("29R"));
await page.type(getSelector("29R"), "12345", { delay: 100 });
await page.click("[data-annotation-id='30R']");
await page.focus(getSelector("29R"));
await page.type(getSelector("29R"), "12345", { delay: 100 });
await page.click("[data-annotation-id='30R']");
text = await page.$eval(getSelector(`29R`), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("12345");
})
);
text = await page.$eval(getSelector(`29R`), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("12345");
}
});
});
@ -1059,45 +1059,43 @@ describe("Interaction", () => {
});
it("must check input for US phone number (long) format", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await page.waitForFunction(
"window.PDFViewerApplication.scriptingReady === true"
);
// Run the tests sequentially to avoid any focus issues between the two
// browsers when an alert is displayed.
for (const [browserName, page] of pages) {
await page.waitForFunction(
"window.PDFViewerApplication.scriptingReady === true"
);
await clearInput(page, getSelector("29R"));
await clearInput(page, getSelector("30R"));
await clearInput(page, getSelector("29R"));
await clearInput(page, getSelector("30R"));
await page.focus(getSelector("30R"));
await page.type(getSelector("30R"), "(123) 456A", { delay: 100 });
await page.waitForFunction(
`${getQuerySelector("30R")}.value !== "(123) 456A"`
);
await page.focus(getSelector("30R"));
await page.type(getSelector("30R"), "(123) 456A", { delay: 100 });
await page.waitForFunction(
`${getQuerySelector("30R")}.value !== "(123) 456A"`
);
let text = await page.$eval(getSelector(`30R`), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("(123) 456");
let text = await page.$eval(getSelector(`30R`), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("(123) 456");
await page.focus(getSelector("30R"));
await page.type(getSelector("30R"), "-789", { delay: 100 });
await page.click("[data-annotation-id='29R']");
await page.focus(getSelector("30R"));
await page.type(getSelector("30R"), "-789", { delay: 100 });
await page.click("[data-annotation-id='29R']");
await page.waitForFunction(
`${getQuerySelector("30R")}.value !== "(123) 456-789"`
);
await page.waitForFunction(
`${getQuerySelector("30R")}.value !== "(123) 456-789"`
);
text = await page.$eval(getSelector(`30R`), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("");
text = await page.$eval(getSelector(`30R`), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("");
await page.focus(getSelector("30R"));
await page.type(getSelector("30R"), "(123) 456-7890", { delay: 100 });
await page.click("[data-annotation-id='29R']");
await page.focus(getSelector("30R"));
await page.type(getSelector("30R"), "(123) 456-7890", { delay: 100 });
await page.click("[data-annotation-id='29R']");
text = await page.$eval(getSelector("30R"), el => el.value);
expect(text)
.withContext(`In ${browserName}`)
.toEqual("(123) 456-7890");
})
);
text = await page.$eval(getSelector("30R"), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("(123) 456-7890");
}
});
});
@ -1118,43 +1116,43 @@ describe("Interaction", () => {
});
it("must check input for US phone number (short) format", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await page.waitForFunction(
"window.PDFViewerApplication.scriptingReady === true"
);
// Run the tests sequentially to avoid any focus issues between the two
// browsers when an alert is displayed.
for (const [browserName, page] of pages) {
await page.waitForFunction(
"window.PDFViewerApplication.scriptingReady === true"
);
await clearInput(page, getSelector("29R"));
await clearInput(page, getSelector("30R"));
await clearInput(page, getSelector("29R"));
await clearInput(page, getSelector("30R"));
await page.focus(getSelector("30R"));
await page.type(getSelector("30R"), "123A", { delay: 100 });
await page.waitForFunction(
`${getQuerySelector("30R")}.value !== "123A"`
);
await page.focus(getSelector("30R"));
await page.type(getSelector("30R"), "123A", { delay: 100 });
await page.waitForFunction(
`${getQuerySelector("30R")}.value !== "123A"`
);
let text = await page.$eval(getSelector(`30R`), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("123");
let text = await page.$eval(getSelector(`30R`), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("123");
await page.focus(getSelector("30R"));
await page.type(getSelector("30R"), "-456", { delay: 100 });
await page.click("[data-annotation-id='29R']");
await page.focus(getSelector("30R"));
await page.type(getSelector("30R"), "-456", { delay: 100 });
await page.click("[data-annotation-id='29R']");
await page.waitForFunction(
`${getQuerySelector("30R")}.value !== "123-456"`
);
await page.waitForFunction(
`${getQuerySelector("30R")}.value !== "123-456"`
);
text = await page.$eval(getSelector("30R"), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("");
text = await page.$eval(getSelector("30R"), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("");
await page.focus(getSelector("30R"));
await page.type(getSelector("30R"), "123-4567", { delay: 100 });
await page.click("[data-annotation-id='29R']");
await page.focus(getSelector("30R"));
await page.type(getSelector("30R"), "123-4567", { delay: 100 });
await page.click("[data-annotation-id='29R']");
text = await page.$eval(getSelector("30R"), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("123-4567");
})
);
text = await page.$eval(getSelector("30R"), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("123-4567");
}
});
});
@ -1249,6 +1247,11 @@ describe("Interaction", () => {
"window.PDFViewerApplication.scriptingReady === true"
);
await page.click(getSelector("28R"));
await page.$eval(getSelector("28R"), el =>
el.setSelectionRange(0, 0)
);
await page.type(getSelector("28R"), "Hello", { delay: 100 });
await page.waitForFunction(
`${getQuerySelector("28R")}.value !== "123"`
@ -1701,4 +1704,53 @@ describe("Interaction", () => {
);
});
});
describe("in issue15818.pdf", () => {
let pages;
beforeAll(async () => {
pages = await loadAndWait("issue15818.pdf", getSelector("27R"));
});
afterAll(async () => {
await closePages(pages);
});
it("must check the field value set when the document is open", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await page.waitForFunction(
"window.PDFViewerApplication.scriptingReady === true"
);
await page.waitForFunction(`${getQuerySelector("27R")}.value !== ""`);
const text = await page.$eval(getSelector("27R"), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("hello world");
})
);
});
it("must check the format action is called when setFocus is used", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await page.waitForFunction(
"window.PDFViewerApplication.scriptingReady === true"
);
await page.type(getSelector("30R"), "abc");
await page.waitForFunction(
`${getQuerySelector("30R")}.value !== "abc"`
);
await page.waitForTimeout(10);
const focusedId = await page.evaluate(_ =>
window.document.activeElement.getAttribute("data-element-id")
);
expect(focusedId).withContext(`In ${browserName}`).toEqual("31R");
})
);
});
});
});

View file

@ -562,3 +562,4 @@
!issue15789.pdf
!fields_order.pdf
!issue15815.pdf
!issue15818.pdf

BIN
test/pdfs/issue15818.pdf Executable file

Binary file not shown.