mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
[Editor] Avoid an exception when undoing the deletion of a pre-existing annotation
It fixes #18849. When such an annotation is deleted, we make sure that there are some data to restore. The version of this patch was making undoing a svg deletion buggy, so it's fixed now and an integration test has been added for this case.
This commit is contained in:
parent
e5b6144bfa
commit
b6e60d033a
3 changed files with 117 additions and 8 deletions
|
@ -101,7 +101,23 @@ describe("Stamp Editor", () => {
|
|||
let pages;
|
||||
|
||||
beforeAll(async () => {
|
||||
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer");
|
||||
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer", null, {
|
||||
eventBusSetup: eventBus => {
|
||||
eventBus.on("annotationeditoruimanager", ({ uiManager }) => {
|
||||
window.uiManager = uiManager;
|
||||
});
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
for (const [, page] of pages) {
|
||||
await page.evaluate(() => {
|
||||
window.uiManager.reset();
|
||||
});
|
||||
// Disable editing mode.
|
||||
await switchToStamp(page, /* disable */ true);
|
||||
}
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
|
@ -129,8 +145,6 @@ describe("Stamp Editor", () => {
|
|||
const [bitmap] = await serializeBitmapDimensions(page);
|
||||
expect(bitmap.width).toEqual(512);
|
||||
expect(bitmap.height).toEqual(543);
|
||||
|
||||
await clearAll(page);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
@ -138,14 +152,15 @@ describe("Stamp Editor", () => {
|
|||
it("must load a SVG", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
await switchToStamp(page);
|
||||
await page.click("#editorStampAddImage");
|
||||
const input = await page.$("#stampEditorFileInput");
|
||||
await input.uploadFile(
|
||||
`${path.join(__dirname, "../images/firefox_logo.svg")}`
|
||||
);
|
||||
await waitForImage(page, getEditorSelector(1));
|
||||
await waitForImage(page, getEditorSelector(0));
|
||||
|
||||
const { width } = await getEditorDimensions(page, 1);
|
||||
const { width } = await getEditorDimensions(page, 0);
|
||||
|
||||
expect(Math.round(parseFloat(width))).toEqual(40);
|
||||
|
||||
|
@ -157,8 +172,32 @@ describe("Stamp Editor", () => {
|
|||
);
|
||||
expect(Math.abs(bitmap.width - 242 * ratio) < 1).toBeTrue();
|
||||
expect(Math.abs(bitmap.height - 80 * ratio) < 1).toBeTrue();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
await clearAll(page);
|
||||
it("must load a SVG, delete it and undo", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
await switchToStamp(page);
|
||||
await page.click("#editorStampAddImage");
|
||||
const input = await page.$("#stampEditorFileInput");
|
||||
await input.uploadFile(
|
||||
`${path.join(__dirname, "../images/firefox_logo.svg")}`
|
||||
);
|
||||
const editorSelector = getEditorSelector(0);
|
||||
await waitForImage(page, editorSelector);
|
||||
|
||||
await waitForSerialized(page, 1);
|
||||
await page.waitForSelector(`${editorSelector} button.delete`);
|
||||
await page.click(`${editorSelector} button.delete`);
|
||||
|
||||
await waitForSerialized(page, 0);
|
||||
|
||||
await kbUndo(page);
|
||||
await waitForSerialized(page, 1);
|
||||
|
||||
await waitForSelectedEditor(page, editorSelector);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
@ -1388,4 +1427,50 @@ describe("Stamp Editor", () => {
|
|||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Stamp (delete existing and undo)", () => {
|
||||
let pages;
|
||||
|
||||
beforeAll(async () => {
|
||||
pages = await loadAndWait("stamps.pdf", getAnnotationSelector("37R"));
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await closePages(pages);
|
||||
});
|
||||
|
||||
it("must check that the annotation is correctly restored", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
await page.click(getAnnotationSelector("37R"), { count: 2 });
|
||||
const editorSelector = getEditorSelector(2);
|
||||
await waitForSelectedEditor(page, editorSelector);
|
||||
|
||||
const editorIds = await getEditors(page, "stamp");
|
||||
expect(editorIds.length).withContext(`In ${browserName}`).toEqual(5);
|
||||
|
||||
// All the current annotations should be serialized as null objects
|
||||
// because they haven't been edited yet.
|
||||
let serialized = await getSerialized(page);
|
||||
expect(serialized).withContext(`In ${browserName}`).toEqual([]);
|
||||
|
||||
await page.waitForSelector(`${editorSelector} button.delete`);
|
||||
await page.click(`${editorSelector} button.delete`);
|
||||
|
||||
await waitForSerialized(page, 1);
|
||||
serialized = await getSerialized(page);
|
||||
expect(serialized)
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual([
|
||||
{ id: "37R", deleted: true, pageIndex: 0, popupRef: "44R" },
|
||||
]);
|
||||
|
||||
await kbUndo(page);
|
||||
await waitForSerialized(page, 0);
|
||||
|
||||
await waitForSelectedEditor(page, editorSelector);
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue