1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

[Editor] Avoid to have some part of an editor outside its page (bug 1843303)

This commit is contained in:
Calixte Denizet 2023-07-13 18:31:08 +02:00
parent 717c766a42
commit a8867cf68a
7 changed files with 105 additions and 5 deletions

View file

@ -128,4 +128,51 @@ describe("Stamp Editor", () => {
);
});
});
describe("Page overflow", () => {
let pages;
beforeAll(async () => {
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer", 50);
});
afterAll(async () => {
await closePages(pages);
});
it("must check that an added image stay within the page", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
if (browserName === "firefox") {
pending(
"Disabled in Firefox, because of https://bugzilla.mozilla.org/1553847."
);
}
await page.click("#editorStamp");
const rect = await page.$eval(".annotationEditorLayer", el => {
// With Chrome something is wrong when serializing a DomRect,
// hence we extract the values and just return them.
const { right, bottom } = el.getBoundingClientRect();
return { x: right, y: bottom };
});
await page.mouse.click(rect.x - 10, rect.y - 10);
const input = await page.$("#stampEditorFileInput");
await input.uploadFile(
`${path.join(__dirname, "../images/firefox_logo.png")}`
);
await page.waitForTimeout(300);
const { left } = await getEditorDimensions(page, 0);
// The image is bigger than the page, so it has been scaled down to
// 75% of the page width.
expect(left).toEqual("25%");
})
);
});
});
});

View file

@ -161,7 +161,12 @@ function getEditorDimensions(page, id) {
return page.evaluate(n => {
const element = document.getElementById(`pdfjs_internal_editor_${n}`);
const { style } = element;
return { width: style.width, height: style.height };
return {
left: style.left,
top: style.top,
width: style.width,
height: style.height,
};
}, id);
}
exports.getEditorDimensions = getEditorDimensions;