Fix editor tests on Windows
- In #15373, we implemented copy/paste actions in using the system clipboard. For any reasons, on Windows, the clipboard doesn't contain the expected data when the tests are ran in parallel, hence the tests which are using the clipboard need to be ran sequentially. - Make sure that we can paste after having copied.
This commit is contained in:
parent
22225a1eaa
commit
2384fbcb89
@ -18,8 +18,25 @@ const {
|
||||
getEditorSelector,
|
||||
getSelectedEditors,
|
||||
loadAndWait,
|
||||
waitForEvent,
|
||||
} = require("./test_utils.js");
|
||||
|
||||
const copyPaste = async page => {
|
||||
let promise = waitForEvent(page, "copy");
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("c");
|
||||
await page.keyboard.up("Control");
|
||||
await promise;
|
||||
|
||||
await page.waitForTimeout(10);
|
||||
|
||||
promise = waitForEvent(page, "paste");
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("v");
|
||||
await page.keyboard.up("Control");
|
||||
await promise;
|
||||
};
|
||||
|
||||
describe("Editor", () => {
|
||||
describe("FreeText", () => {
|
||||
let pages;
|
||||
@ -32,10 +49,22 @@ describe("Editor", () => {
|
||||
await closePages(pages);
|
||||
});
|
||||
|
||||
const countStorageEntries = async page =>
|
||||
page.evaluate(
|
||||
() => window.PDFViewerApplication.pdfDocument.annotationStorage.size
|
||||
const waitForStorageEntries = async (page, nEntries) => {
|
||||
await page.waitForFunction(
|
||||
n =>
|
||||
window.PDFViewerApplication.pdfDocument.annotationStorage.size === n,
|
||||
{},
|
||||
nEntries
|
||||
);
|
||||
};
|
||||
|
||||
const waitForSelected = async (page, selector) => {
|
||||
await page.waitForFunction(
|
||||
sel => document.querySelector(sel).classList.contains("selectedEditor"),
|
||||
{},
|
||||
selector
|
||||
);
|
||||
};
|
||||
|
||||
it("must write a string in a FreeText editor", async () => {
|
||||
await Promise.all(
|
||||
@ -69,9 +98,8 @@ describe("Editor", () => {
|
||||
editorRect.y + 2 * editorRect.height
|
||||
);
|
||||
|
||||
expect(await countStorageEntries(page))
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(1);
|
||||
await waitForSelected(page, getEditorSelector(0));
|
||||
await waitForStorageEntries(page, 1);
|
||||
|
||||
const content = await page.$eval(getEditorSelector(0), el =>
|
||||
el.innerText.trimEnd()
|
||||
@ -82,8 +110,8 @@ describe("Editor", () => {
|
||||
});
|
||||
|
||||
it("must copy/paste", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
// Run sequentially to avoid clipboard issues.
|
||||
for (const [browserName, page] of pages) {
|
||||
const editorRect = await page.$eval(getEditorSelector(0), el => {
|
||||
const { x, y, width, height } = el.getBoundingClientRect();
|
||||
return { x, y, width, height };
|
||||
@ -95,17 +123,9 @@ describe("Editor", () => {
|
||||
editorRect.y + editorRect.height / 2
|
||||
);
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("c");
|
||||
await page.keyboard.up("Control");
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("v");
|
||||
await page.keyboard.up("Control");
|
||||
|
||||
expect(await countStorageEntries(page))
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(2);
|
||||
await waitForSelected(page, getEditorSelector(0));
|
||||
await copyPaste(page);
|
||||
await waitForStorageEntries(page, 2);
|
||||
|
||||
const content = await page.$eval(getEditorSelector(0), el =>
|
||||
el.innerText.trimEnd()
|
||||
@ -115,30 +135,16 @@ describe("Editor", () => {
|
||||
el.innerText.trimEnd()
|
||||
);
|
||||
|
||||
expect(pastedContent)
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(content);
|
||||
expect(pastedContent).withContext(`In ${browserName}`).toEqual(content);
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("c");
|
||||
await page.keyboard.up("Control");
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("v");
|
||||
await page.keyboard.up("Control");
|
||||
|
||||
expect(await countStorageEntries(page))
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(3);
|
||||
await copyPaste(page);
|
||||
await waitForStorageEntries(page, 3);
|
||||
|
||||
pastedContent = await page.$eval(getEditorSelector(2), el =>
|
||||
el.innerText.trimEnd()
|
||||
);
|
||||
expect(pastedContent)
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(content);
|
||||
})
|
||||
);
|
||||
expect(pastedContent).withContext(`In ${browserName}`).toEqual(content);
|
||||
}
|
||||
});
|
||||
|
||||
it("must clear all", async () => {
|
||||
@ -160,16 +166,14 @@ describe("Editor", () => {
|
||||
expect(hasEditor).withContext(`In ${browserName}`).toEqual(false);
|
||||
}
|
||||
|
||||
expect(await countStorageEntries(page))
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(0);
|
||||
await waitForStorageEntries(page, 0);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("must check that a paste has been undone", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
// Run sequentially to avoid clipboard issues.
|
||||
for (const [browserName, page] of pages) {
|
||||
const rect = await page.$eval(".annotationEditorLayer", el => {
|
||||
const { x, y } = el.getBoundingClientRect();
|
||||
return { x, y };
|
||||
@ -195,13 +199,8 @@ describe("Editor", () => {
|
||||
editorRect.y + editorRect.height / 2
|
||||
);
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("c");
|
||||
await page.keyboard.up("Control");
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("v");
|
||||
await page.keyboard.up("Control");
|
||||
await waitForSelected(page, getEditorSelector(3));
|
||||
await copyPaste(page);
|
||||
|
||||
let hasEditor = await page.evaluate(sel => {
|
||||
return !!document.querySelector(sel);
|
||||
@ -212,6 +211,7 @@ describe("Editor", () => {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("z");
|
||||
await page.keyboard.up("Control");
|
||||
await page.waitForTimeout(10);
|
||||
|
||||
hasEditor = await page.evaluate(sel => {
|
||||
return !!document.querySelector(sel);
|
||||
@ -220,9 +220,12 @@ describe("Editor", () => {
|
||||
expect(hasEditor).withContext(`In ${browserName}`).toEqual(false);
|
||||
|
||||
for (let i = 0; i < 2; i++) {
|
||||
const promise = waitForEvent(page, "paste");
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("v");
|
||||
await page.keyboard.up("Control");
|
||||
await promise;
|
||||
await page.waitForTimeout(10);
|
||||
}
|
||||
|
||||
let length = await page.evaluate(sel => {
|
||||
@ -234,14 +237,14 @@ describe("Editor", () => {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("z");
|
||||
await page.keyboard.up("Control");
|
||||
await page.waitForTimeout(10);
|
||||
}
|
||||
|
||||
length = await page.evaluate(sel => {
|
||||
return document.querySelectorAll(sel).length;
|
||||
}, `${getEditorSelector(5)}, ${getEditorSelector(6)}`);
|
||||
expect(length).withContext(`In ${browserName}`).toEqual(0);
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it("must check that aria-owns is correct", async () => {
|
||||
@ -332,6 +335,8 @@ describe("Editor", () => {
|
||||
editorRect.y + editorRect.height / 2
|
||||
);
|
||||
|
||||
await waitForSelected(page, getEditorSelector(8));
|
||||
|
||||
expect(await getSelectedEditors(page))
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual([8]);
|
||||
@ -367,8 +372,8 @@ describe("Editor", () => {
|
||||
});
|
||||
|
||||
it("must select/unselect several editors and check copy, paste and delete operations", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
// Run sequentially to avoid clipboard issues.
|
||||
for (const [browserName, page] of pages) {
|
||||
await page.click("#editorFreeText");
|
||||
|
||||
const rect = await page.$eval(".annotationEditorLayer", el => {
|
||||
@ -436,13 +441,7 @@ describe("Editor", () => {
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual([0, 1, 3]);
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("c");
|
||||
await page.keyboard.up("Control");
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("v");
|
||||
await page.keyboard.up("Control");
|
||||
await copyPaste(page);
|
||||
|
||||
// 0,1,3 are unselected and new pasted editors are selected.
|
||||
expect(await getSelectedEditors(page))
|
||||
@ -510,8 +509,7 @@ describe("Editor", () => {
|
||||
expect(await getSelectedEditors(page))
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual([0, 2, 4, 5, 6]);
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -24,6 +24,9 @@ const {
|
||||
|
||||
describe("Interaction", () => {
|
||||
async function actAndWaitForInput(page, selector, action, clear = true) {
|
||||
await page.waitForSelector(selector, {
|
||||
timeout: 0,
|
||||
});
|
||||
if (clear) {
|
||||
await clearInput(page, selector);
|
||||
}
|
||||
@ -1430,13 +1433,18 @@ describe("Interaction", () => {
|
||||
[45, 180],
|
||||
[46, 270],
|
||||
]) {
|
||||
const rotation = await page.$eval(
|
||||
await page.waitForFunction(
|
||||
(sel, b, a) => {
|
||||
const el = document.querySelector(sel);
|
||||
const rotation =
|
||||
parseInt(el.getAttribute("data-main-rotation")) || 0;
|
||||
return rotation === (360 + ((360 - (b + a)) % 360)) % 360;
|
||||
},
|
||||
{},
|
||||
`[data-annotation-id='${ref}R']`,
|
||||
el => parseInt(el.getAttribute("data-main-rotation") || 0)
|
||||
base,
|
||||
angle
|
||||
);
|
||||
expect(rotation)
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual((360 + ((360 - (base + angle)) % 360)) % 360);
|
||||
}
|
||||
base += 90;
|
||||
await page.click(getSelector("48R"));
|
||||
|
@ -87,3 +87,16 @@ function getSelectedEditors(page) {
|
||||
});
|
||||
}
|
||||
exports.getSelectedEditors = getSelectedEditors;
|
||||
|
||||
async function waitForEvent(page, eventName, timeout = 30000) {
|
||||
await Promise.race([
|
||||
// add event listener and wait for event to fire before returning
|
||||
page.evaluate(name => {
|
||||
return new Promise(resolve => {
|
||||
document.addEventListener(name, resolve, { once: true });
|
||||
});
|
||||
}, eventName),
|
||||
page.waitForTimeout(timeout),
|
||||
]);
|
||||
}
|
||||
exports.waitForEvent = waitForEvent;
|
||||
|
Loading…
Reference in New Issue
Block a user