mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 01:10:08 +02:00
Merge pull request #17882 from calixteman/bug1889122
Use the string value of the field when calling the Format callback (bug 1889122)
This commit is contained in:
commit
77ee914bd6
6 changed files with 85 additions and 3 deletions
|
@ -81,6 +81,15 @@ class EventDispatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(baseEvent) {
|
dispatch(baseEvent) {
|
||||||
|
if (
|
||||||
|
typeof PDFJSDev !== "undefined" &&
|
||||||
|
PDFJSDev.test("TESTING") &&
|
||||||
|
baseEvent.name === "sandboxtripbegin"
|
||||||
|
) {
|
||||||
|
this._externalCall("send", [{ command: "sandboxTripEnd" }]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const id = baseEvent.id;
|
const id = baseEvent.id;
|
||||||
if (!(id in this._objects)) {
|
if (!(id in this._objects)) {
|
||||||
let event;
|
let event;
|
||||||
|
@ -233,7 +242,7 @@ class EventDispatcher {
|
||||||
// Run format actions if any for all the fields.
|
// Run format actions if any for all the fields.
|
||||||
const event = (globalThis.event = new Event({}));
|
const event = (globalThis.event = new Event({}));
|
||||||
for (const source of Object.values(this._objects)) {
|
for (const source of Object.values(this._objects)) {
|
||||||
event.value = source.obj.value;
|
event.value = source.obj._getValue();
|
||||||
this.runActions(source, source, event, "Format");
|
this.runActions(source, source, event, "Format");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -245,8 +254,7 @@ class EventDispatcher {
|
||||||
|
|
||||||
this.runCalculate(source, event);
|
this.runCalculate(source, event);
|
||||||
|
|
||||||
const savedValue = source.obj._getValue();
|
const savedValue = (event.value = source.obj._getValue());
|
||||||
event.value = source.obj.value;
|
|
||||||
let formattedValue = null;
|
let formattedValue = null;
|
||||||
|
|
||||||
if (this.runActions(source, source, event, "Format")) {
|
if (this.runActions(source, source, event, "Format")) {
|
||||||
|
|
|
@ -27,6 +27,7 @@ import {
|
||||||
loadAndWait,
|
loadAndWait,
|
||||||
scrollIntoView,
|
scrollIntoView,
|
||||||
waitForEntryInStorage,
|
waitForEntryInStorage,
|
||||||
|
waitForSandboxTrip,
|
||||||
waitForTimeout,
|
waitForTimeout,
|
||||||
} from "./test_utils.mjs";
|
} from "./test_utils.mjs";
|
||||||
|
|
||||||
|
@ -2367,4 +2368,41 @@ describe("Interaction", () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Textfield with a zip code starting with 0", () => {
|
||||||
|
let pages;
|
||||||
|
let otherPages;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
otherPages = await Promise.all(
|
||||||
|
global.integrationSessions.map(async session =>
|
||||||
|
session.browser.newPage()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
pages = await loadAndWait("bug1889122.pdf", getSelector("24R"));
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await closePages(pages);
|
||||||
|
await Promise.all(otherPages.map(page => page.close()));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("must check the zip code is correctly formatted", async () => {
|
||||||
|
await Promise.all(
|
||||||
|
pages.map(async ([browserName, page], i) => {
|
||||||
|
await page.waitForFunction(
|
||||||
|
"window.PDFViewerApplication.scriptingReady === true"
|
||||||
|
);
|
||||||
|
|
||||||
|
await page.click(getSelector("24R"));
|
||||||
|
await page.type(getSelector("24R"), "01234", { delay: 10 });
|
||||||
|
await page.keyboard.press("Tab");
|
||||||
|
await waitForSandboxTrip(page);
|
||||||
|
|
||||||
|
const text = await page.$eval(getSelector("24R"), el => el.value);
|
||||||
|
expect(text).withContext(`In ${browserName}`).toEqual("01234");
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -85,6 +85,16 @@ function closePages(pages) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function waitForSandboxTrip(page) {
|
||||||
|
const handle = await page.evaluateHandle(() => [
|
||||||
|
new Promise(resolve => {
|
||||||
|
window.addEventListener("sandboxtripend", resolve, { once: true });
|
||||||
|
window.PDFViewerApplication.pdfScriptingManager.sandboxTrip();
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
await awaitPromise(handle);
|
||||||
|
}
|
||||||
|
|
||||||
function waitForTimeout(milliseconds) {
|
function waitForTimeout(milliseconds) {
|
||||||
/**
|
/**
|
||||||
* Wait for the given number of milliseconds.
|
* Wait for the given number of milliseconds.
|
||||||
|
@ -583,6 +593,7 @@ export {
|
||||||
waitForAnnotationEditorLayer,
|
waitForAnnotationEditorLayer,
|
||||||
waitForEntryInStorage,
|
waitForEntryInStorage,
|
||||||
waitForEvent,
|
waitForEvent,
|
||||||
|
waitForSandboxTrip,
|
||||||
waitForSelectedEditor,
|
waitForSelectedEditor,
|
||||||
waitForSerialized,
|
waitForSerialized,
|
||||||
waitForStorageEntries,
|
waitForStorageEntries,
|
||||||
|
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
|
@ -640,3 +640,4 @@
|
||||||
!issue17808.pdf
|
!issue17808.pdf
|
||||||
!issue17871_bottom_right.pdf
|
!issue17871_bottom_right.pdf
|
||||||
!issue17871_top_right.pdf
|
!issue17871_top_right.pdf
|
||||||
|
!bug1889122.pdf
|
||||||
|
|
BIN
test/pdfs/bug1889122.pdf
Normal file
BIN
test/pdfs/bug1889122.pdf
Normal file
Binary file not shown.
|
@ -58,6 +58,19 @@ class PDFScriptingManager {
|
||||||
this.#eventBus = eventBus;
|
this.#eventBus = eventBus;
|
||||||
this.#externalServices = externalServices;
|
this.#externalServices = externalServices;
|
||||||
this.#docProperties = docProperties;
|
this.#docProperties = docProperties;
|
||||||
|
|
||||||
|
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING")) {
|
||||||
|
Object.defineProperty(this, "sandboxTrip", {
|
||||||
|
value: () =>
|
||||||
|
setTimeout(
|
||||||
|
() =>
|
||||||
|
this.#scripting?.dispatchEventInSandbox({
|
||||||
|
name: "sandboxtripbegin",
|
||||||
|
}),
|
||||||
|
0
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setViewer(pdfViewer) {
|
setViewer(pdfViewer) {
|
||||||
|
@ -258,6 +271,17 @@ class PDFScriptingManager {
|
||||||
|
|
||||||
const { id, siblings, command, value } = detail;
|
const { id, siblings, command, value } = detail;
|
||||||
if (!id) {
|
if (!id) {
|
||||||
|
if (
|
||||||
|
typeof PDFJSDev !== "undefined" &&
|
||||||
|
PDFJSDev.test("TESTING") &&
|
||||||
|
command === "sandboxTripEnd"
|
||||||
|
) {
|
||||||
|
window.setTimeout(() => {
|
||||||
|
window.dispatchEvent(new CustomEvent("sandboxtripend"));
|
||||||
|
}, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case "clear":
|
case "clear":
|
||||||
console.clear();
|
console.clear();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue