2022-07-22 19:13:47 +09:00
|
|
|
/* Copyright 2022 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2023-10-12 20:16:58 +09:00
|
|
|
import {
|
2023-12-06 23:27:31 +09:00
|
|
|
awaitPromise,
|
2022-07-22 19:13:47 +09:00
|
|
|
closePages,
|
2023-12-06 23:27:31 +09:00
|
|
|
createPromise,
|
2023-12-05 07:13:31 +09:00
|
|
|
getEditorSelector,
|
2022-07-22 19:13:47 +09:00
|
|
|
getSelectedEditors,
|
2023-10-27 05:42:41 +09:00
|
|
|
kbRedo,
|
|
|
|
kbSelectAll,
|
|
|
|
kbUndo,
|
2022-07-22 19:13:47 +09:00
|
|
|
loadAndWait,
|
2023-12-04 21:27:30 +09:00
|
|
|
scrollIntoView,
|
2023-09-29 22:01:52 +09:00
|
|
|
waitForStorageEntries,
|
2023-10-12 20:16:58 +09:00
|
|
|
} from "./test_utils.mjs";
|
2022-07-22 19:13:47 +09:00
|
|
|
|
2023-09-30 05:36:01 +09:00
|
|
|
const waitForPointerUp = page =>
|
2023-12-06 23:27:31 +09:00
|
|
|
createPromise(page, resolve => {
|
|
|
|
window.addEventListener("pointerup", resolve, { once: true });
|
|
|
|
});
|
2023-09-29 22:01:52 +09:00
|
|
|
|
|
|
|
const selectAll = async page => {
|
2023-10-27 05:42:41 +09:00
|
|
|
await kbSelectAll(page);
|
2023-09-29 22:01:52 +09:00
|
|
|
await page.waitForFunction(
|
|
|
|
() => !document.querySelector(".inkEditor.disabled:not(.selectedEditor)")
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const clearAll = async page => {
|
|
|
|
await selectAll(page);
|
|
|
|
await page.keyboard.press("Backspace");
|
|
|
|
await waitForStorageEntries(page, 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
const commit = async page => {
|
|
|
|
await page.keyboard.press("Escape");
|
|
|
|
await page.waitForSelector(".inkEditor.selectedEditor.draggable.disabled");
|
|
|
|
};
|
|
|
|
|
2023-04-17 04:36:26 +09:00
|
|
|
describe("Ink Editor", () => {
|
|
|
|
describe("Basic operations", () => {
|
2022-07-22 19:13:47 +09:00
|
|
|
let pages;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2022-07-27 21:11:29 +09:00
|
|
|
pages = await loadAndWait("aboutstacks.pdf", ".annotationEditorLayer");
|
2022-07-22 19:13:47 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await closePages(pages);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("must draw, undo a deletion and check that the editors are not selected", async () => {
|
|
|
|
await Promise.all(
|
|
|
|
pages.map(async ([browserName, page]) => {
|
|
|
|
await page.click("#editorInk");
|
|
|
|
|
|
|
|
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 { x, y } = el.getBoundingClientRect();
|
|
|
|
return { x, y };
|
|
|
|
});
|
|
|
|
|
|
|
|
for (let i = 0; i < 3; i++) {
|
|
|
|
const x = rect.x + 100 + i * 100;
|
|
|
|
const y = rect.y + 100 + i * 100;
|
2023-12-06 23:27:31 +09:00
|
|
|
const clickHandle = await waitForPointerUp(page);
|
2022-07-22 19:13:47 +09:00
|
|
|
await page.mouse.move(x, y);
|
|
|
|
await page.mouse.down();
|
|
|
|
await page.mouse.move(x + 50, y + 50);
|
|
|
|
await page.mouse.up();
|
2023-12-06 23:27:31 +09:00
|
|
|
await awaitPromise(clickHandle);
|
2022-07-22 19:13:47 +09:00
|
|
|
|
2023-09-29 22:01:52 +09:00
|
|
|
await commit(page);
|
2022-07-22 19:13:47 +09:00
|
|
|
}
|
|
|
|
|
2023-09-29 22:01:52 +09:00
|
|
|
await clearAll(page);
|
2022-07-22 19:13:47 +09:00
|
|
|
|
2023-10-27 05:42:41 +09:00
|
|
|
await kbUndo(page);
|
2023-09-29 22:01:52 +09:00
|
|
|
await waitForStorageEntries(page, 3);
|
2022-07-22 19:13:47 +09:00
|
|
|
|
|
|
|
expect(await getSelectedEditors(page))
|
|
|
|
.withContext(`In ${browserName}`)
|
|
|
|
.toEqual([]);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2022-07-29 23:53:03 +09:00
|
|
|
|
|
|
|
it("must draw, undo/redo and check that the editor don't move", async () => {
|
|
|
|
await Promise.all(
|
|
|
|
pages.map(async ([browserName, page]) => {
|
2023-09-29 22:01:52 +09:00
|
|
|
await clearAll(page);
|
2022-07-29 23:53:03 +09:00
|
|
|
|
|
|
|
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 { x, y } = el.getBoundingClientRect();
|
|
|
|
return { x, y };
|
|
|
|
});
|
|
|
|
|
|
|
|
const xStart = rect.x + 300;
|
|
|
|
const yStart = rect.y + 300;
|
2023-12-06 23:27:31 +09:00
|
|
|
const clickHandle = await waitForPointerUp(page);
|
2022-07-29 23:53:03 +09:00
|
|
|
await page.mouse.move(xStart, yStart);
|
|
|
|
await page.mouse.down();
|
|
|
|
await page.mouse.move(xStart + 50, yStart + 50);
|
|
|
|
await page.mouse.up();
|
2023-12-06 23:27:31 +09:00
|
|
|
await awaitPromise(clickHandle);
|
2022-07-29 23:53:03 +09:00
|
|
|
|
2023-09-29 22:01:52 +09:00
|
|
|
await commit(page);
|
2022-07-29 23:53:03 +09:00
|
|
|
|
|
|
|
const rectBefore = await page.$eval(".inkEditor canvas", el => {
|
|
|
|
const { x, y } = el.getBoundingClientRect();
|
|
|
|
return { x, y };
|
|
|
|
});
|
|
|
|
|
|
|
|
for (let i = 0; i < 30; i++) {
|
2023-10-27 05:42:41 +09:00
|
|
|
await kbUndo(page);
|
2023-09-29 22:01:52 +09:00
|
|
|
await waitForStorageEntries(page, 0);
|
2023-10-27 05:42:41 +09:00
|
|
|
await kbRedo(page);
|
2023-09-29 22:01:52 +09:00
|
|
|
await waitForStorageEntries(page, 1);
|
2022-07-29 23:53:03 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
const rectAfter = await page.$eval(".inkEditor canvas", el => {
|
|
|
|
const { x, y } = el.getBoundingClientRect();
|
|
|
|
return { x, y };
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(Math.round(rectBefore.x))
|
|
|
|
.withContext(`In ${browserName}`)
|
|
|
|
.toEqual(Math.round(rectAfter.x));
|
|
|
|
|
|
|
|
expect(Math.round(rectBefore.y))
|
|
|
|
.withContext(`In ${browserName}`)
|
|
|
|
.toEqual(Math.round(rectAfter.y));
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2022-07-22 19:13:47 +09:00
|
|
|
});
|
2023-04-17 04:36:26 +09:00
|
|
|
|
|
|
|
describe("with a rotated pdf", () => {
|
|
|
|
let pages;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
pages = await loadAndWait("issue16278.pdf", ".annotationEditorLayer");
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await closePages(pages);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("must draw something", async () => {
|
|
|
|
await Promise.all(
|
|
|
|
pages.map(async ([browserName, page]) => {
|
|
|
|
await page.click("#editorInk");
|
|
|
|
|
|
|
|
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 { x, y } = el.getBoundingClientRect();
|
|
|
|
return { x, y };
|
|
|
|
});
|
|
|
|
|
|
|
|
const x = rect.x + 20;
|
|
|
|
const y = rect.y + 20;
|
2023-12-06 23:27:31 +09:00
|
|
|
const clickHandle = await waitForPointerUp(page);
|
2023-04-17 04:36:26 +09:00
|
|
|
await page.mouse.move(x, y);
|
|
|
|
await page.mouse.down();
|
|
|
|
await page.mouse.move(x + 50, y + 50);
|
|
|
|
await page.mouse.up();
|
2023-12-06 23:27:31 +09:00
|
|
|
await awaitPromise(clickHandle);
|
2023-04-17 04:36:26 +09:00
|
|
|
|
2023-09-29 22:01:52 +09:00
|
|
|
await commit(page);
|
2023-04-17 04:36:26 +09:00
|
|
|
|
2023-09-29 22:01:52 +09:00
|
|
|
await selectAll(page);
|
2023-04-17 04:36:26 +09:00
|
|
|
|
|
|
|
expect(await getSelectedEditors(page))
|
|
|
|
.withContext(`In ${browserName}`)
|
|
|
|
.toEqual([0]);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2023-12-04 21:27:30 +09:00
|
|
|
|
|
|
|
describe("Invisible layers must be disabled", () => {
|
|
|
|
let pages;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
pages = await loadAndWait("tracemonkey.pdf", ".annotationEditorLayer");
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await closePages(pages);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("must check that the editor layer is disabled", async () => {
|
|
|
|
await Promise.all(
|
|
|
|
pages.map(async ([browserName, page]) => {
|
|
|
|
await page.click("#editorInk");
|
|
|
|
await page.waitForSelector(".annotationEditorLayer.inkEditing");
|
|
|
|
|
|
|
|
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 { x, y } = el.getBoundingClientRect();
|
|
|
|
return { x, y };
|
|
|
|
});
|
|
|
|
|
|
|
|
const x = rect.x + 20;
|
|
|
|
const y = rect.y + 20;
|
2023-12-06 23:27:31 +09:00
|
|
|
const clickHandle = await waitForPointerUp(page);
|
2023-12-04 21:27:30 +09:00
|
|
|
await page.mouse.move(x, y);
|
|
|
|
await page.mouse.down();
|
|
|
|
await page.mouse.move(x + 50, y + 50);
|
|
|
|
await page.mouse.up();
|
2023-12-06 23:27:31 +09:00
|
|
|
await awaitPromise(clickHandle);
|
2023-12-04 21:27:30 +09:00
|
|
|
|
|
|
|
await commit(page);
|
|
|
|
|
|
|
|
const oneToFourteen = Array.from(new Array(13).keys(), n => n + 2);
|
|
|
|
for (const pageNumber of oneToFourteen) {
|
|
|
|
await scrollIntoView(
|
|
|
|
page,
|
|
|
|
`.page[data-page-number = "${pageNumber}"]`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
await page.click("#editorInk");
|
|
|
|
await page.waitForSelector(".annotationEditorLayer:not(.inkEditing)");
|
|
|
|
|
|
|
|
const fourteenToOne = Array.from(new Array(13).keys(), n => 13 - n);
|
|
|
|
for (const pageNumber of fourteenToOne) {
|
|
|
|
await scrollIntoView(
|
|
|
|
page,
|
|
|
|
`.page[data-page-number = "${pageNumber}"]`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
await page.waitForSelector(
|
|
|
|
`.page[data-page-number = "1"] .annotationEditorLayer.disabled:not(.inkEditing)`
|
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2023-12-05 07:13:31 +09:00
|
|
|
|
|
|
|
describe("Ink editor must be committed when blurred", () => {
|
|
|
|
let pages;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
pages = await loadAndWait("tracemonkey.pdf", ".annotationEditorLayer");
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await closePages(pages);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("must check that the ink editor is committed", async () => {
|
|
|
|
await Promise.all(
|
|
|
|
pages.map(async ([browserName, page]) => {
|
|
|
|
await page.click("#editorInk");
|
|
|
|
await page.waitForSelector(".annotationEditorLayer.inkEditing");
|
|
|
|
|
|
|
|
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 { x, y } = el.getBoundingClientRect();
|
|
|
|
return { x, y };
|
|
|
|
});
|
|
|
|
|
|
|
|
const x = rect.x + 20;
|
|
|
|
const y = rect.y + 20;
|
2023-12-06 23:27:31 +09:00
|
|
|
const clickHandle = await waitForPointerUp(page);
|
2023-12-05 07:13:31 +09:00
|
|
|
await page.mouse.move(x, y);
|
|
|
|
await page.mouse.down();
|
|
|
|
await page.mouse.move(x + 50, y + 50);
|
|
|
|
await page.mouse.up();
|
2023-12-06 23:27:31 +09:00
|
|
|
await awaitPromise(clickHandle);
|
2023-12-05 07:13:31 +09:00
|
|
|
|
|
|
|
page.mouse.click(rect.x - 10, rect.y + 10);
|
|
|
|
await page.waitForSelector(`${getEditorSelector(0)}.disabled`);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2022-07-22 19:13:47 +09:00
|
|
|
});
|