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

[Editor] Correctly set the accessibility data when copying & pasting a stamp with an alt text (bug 1903589) #18296

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions src/display/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import { noContextMenu } from "../display_utils.js";
* Base class for editors.
*/
class AnnotationEditor {
#accessibilityData = null;

#allResizerDivs = null;

#altText = null;
Expand Down Expand Up @@ -993,6 +995,10 @@ class AnnotationEditor {
}
AltText.initialize(AnnotationEditor._l10nPromise);
this.#altText = new AltText(this);
if (this.#accessibilityData) {
this.#altText.data = this.#accessibilityData;
this.#accessibilityData = null;
}
await this.addEditToolbar();
}

Expand Down Expand Up @@ -1330,6 +1336,7 @@ class AnnotationEditor {
uiManager,
});
editor.rotation = data.rotation;
editor.#accessibilityData = data.accessibilityData;

const [pageWidth, pageHeight] = editor.pageDimensions;
const [x, y, width, height] = editor.getRectInCurrentCoords(
Expand Down
51 changes: 51 additions & 0 deletions test/integration/stamp_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
*/

import {
applyFunctionToEditor,
awaitPromise,
closePages,
getEditorDimensions,
getEditorSelector,
getFirstSerialized,
getRect,
getSerialized,
kbBigMoveDown,
kbBigMoveRight,
kbCopy,
Expand Down Expand Up @@ -798,4 +800,53 @@ describe("Stamp Editor", () => {
);
});
});

describe("Copy and paste a stamp with an alt text", () => {
let pages;

beforeAll(async () => {
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer");
});

afterAll(async () => {
await closePages(pages);
});

it("must check that the pasted image has an alt text", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await switchToStamp(page);

await copyImage(page, "../images/firefox_logo.png", 0);
await page.waitForSelector(getEditorSelector(0));
await waitForSerialized(page, 1);
await applyFunctionToEditor(
page,
"pdfjs_internal_editor_0",
editor => {
editor.altTextData = {
altText: "Hello World",
decorative: false,
};
}
);
await page.waitForSelector(`${getEditorSelector(0)} .altText.done`);

await kbCopy(page);
await kbPaste(page);
await page.waitForSelector(`${getEditorSelector(1)} .altText.done`);
await waitForSerialized(page, 2);

const serialized = await getSerialized(
page,
x => x.accessibilityData?.alt
);

expect(serialized)
.withContext(`In ${browserName}`)
.toEqual(["Hello World", "Hello World"]);
})
);
});
});
});
16 changes: 16 additions & 0 deletions test/integration/test_utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,21 @@ async function waitForSerialized(page, nEntries) {
);
}

async function applyFunctionToEditor(page, editorId, func) {
return page.evaluate(
(id, f) => {
const editor =
window.PDFViewerApplication.pdfDocument.annotationStorage.getRawValue(
id
);
// eslint-disable-next-line no-eval
eval(`(${f})`)(editor);
},
editorId,
func.toString()
);
}

async function waitForSelectedEditor(page, selector) {
return page.waitForSelector(`${selector}.selectedEditor`);
}
Expand Down Expand Up @@ -615,6 +630,7 @@ async function switchToEditor(name, page, disable = false) {
}

export {
applyFunctionToEditor,
awaitPromise,
clearInput,
closePages,
Expand Down