mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-28 23:28:16 +02:00
[Editor] Avoid editor creation/selection on right click (bug 1781762)
This commit is contained in:
parent
8ebd2d3dfd
commit
ce4144eee4
6 changed files with 100 additions and 18 deletions
|
@ -25,7 +25,7 @@ describe("Editor", () => {
|
|||
let pages;
|
||||
|
||||
beforeAll(async () => {
|
||||
pages = await loadAndWait("tracemonkey.pdf", ".annotationEditorLayer");
|
||||
pages = await loadAndWait("aboutstacks.pdf", ".annotationEditorLayer");
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
|
@ -204,13 +204,13 @@ describe("Editor", () => {
|
|||
it("must check that aria-owns is correct", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
const [adobeComRect, oldAriaOwns] = await page.$eval(
|
||||
const [stacksRect, oldAriaOwns] = await page.$eval(
|
||||
".textLayer",
|
||||
el => {
|
||||
for (const span of el.querySelectorAll(
|
||||
`span[role="presentation"]`
|
||||
)) {
|
||||
if (span.innerText.includes("adobe.com")) {
|
||||
if (span.innerText.includes("Stacks are simple to create")) {
|
||||
span.setAttribute("pdfjs", true);
|
||||
const { x, y, width, height } = span.getBoundingClientRect();
|
||||
return [
|
||||
|
@ -227,21 +227,13 @@ describe("Editor", () => {
|
|||
|
||||
const data = "Hello PDF.js World !!";
|
||||
await page.mouse.click(
|
||||
adobeComRect.x + adobeComRect.width + 10,
|
||||
adobeComRect.y + adobeComRect.height / 2
|
||||
stacksRect.x + stacksRect.width + 1,
|
||||
stacksRect.y + stacksRect.height / 2
|
||||
);
|
||||
await page.type(`${editorPrefix}5 .internal`, data);
|
||||
|
||||
const editorRect = await page.$eval(`${editorPrefix}5`, el => {
|
||||
const { x, y, width, height } = el.getBoundingClientRect();
|
||||
return { x, y, width, height };
|
||||
});
|
||||
|
||||
// Commit.
|
||||
await page.mouse.click(
|
||||
editorRect.x,
|
||||
editorRect.y + 2 * editorRect.height
|
||||
);
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
const ariaOwns = await page.$eval(".textLayer", el => {
|
||||
const span = el.querySelector(`span[pdfjs="true"]`);
|
||||
|
@ -254,13 +246,77 @@ describe("Editor", () => {
|
|||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("must check that right click doesn't select", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
const rect = await page.$eval(".annotationEditorLayer", el => {
|
||||
const { x, y } = el.getBoundingClientRect();
|
||||
return { x, y };
|
||||
});
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("a");
|
||||
await page.keyboard.up("Control");
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("Backspace");
|
||||
await page.keyboard.up("Control");
|
||||
|
||||
const data = "Hello PDF.js World !!";
|
||||
await page.mouse.click(rect.x + 100, rect.y + 100);
|
||||
await page.type(`${editorPrefix}6 .internal`, data);
|
||||
|
||||
const editorRect = await page.$eval(`${editorPrefix}6`, el => {
|
||||
const { x, y, width, height } = el.getBoundingClientRect();
|
||||
return { x, y, width, height };
|
||||
});
|
||||
|
||||
// Commit.
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
expect(await getSelectedEditors(page))
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual([6]);
|
||||
|
||||
await page.keyboard.press("Escape");
|
||||
expect(await getSelectedEditors(page))
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual([]);
|
||||
|
||||
await page.mouse.click(
|
||||
editorRect.x + editorRect.width / 2,
|
||||
editorRect.y + editorRect.height / 2
|
||||
);
|
||||
|
||||
expect(await getSelectedEditors(page))
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual([6]);
|
||||
|
||||
// Escape.
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
expect(await getSelectedEditors(page))
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual([]);
|
||||
|
||||
// TODO: uncomment that stuff once we've a way to dismiss
|
||||
// the context menu.
|
||||
/* await page.mouse.click(
|
||||
editorRect.x + editorRect.width / 2,
|
||||
editorRect.y + editorRect.height / 2,
|
||||
{ button: "right" }
|
||||
); */
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("FreeText (multiselection)", () => {
|
||||
let pages;
|
||||
|
||||
beforeAll(async () => {
|
||||
pages = await loadAndWait("tracemonkey.pdf", ".annotationEditorLayer");
|
||||
pages = await loadAndWait("aboutstacks.pdf", ".annotationEditorLayer");
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue