Skip to content

Commit

Permalink
[Editor] Correctly set the accessibility data when copying & pasting …
Browse files Browse the repository at this point in the history
…a stamp with an alt text (bug 1903589)
  • Loading branch information
calixteman committed Jun 19, 2024
1 parent b7d194f commit 585748e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
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
48 changes: 48 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 @@ -795,4 +797,50 @@ 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 kbCopy(page);
await kbPaste(page);
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 @@ -231,6 +231,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 @@ -613,6 +628,7 @@ async function switchToEditor(name, page, disable = false) {
}

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

0 comments on commit 585748e

Please sign in to comment.