Merge pull request #17059 from calixteman/fix_copy_paste_integration_test

Remove timeouts from the copy_paste integration test
This commit is contained in:
calixteman 2023-10-03 13:27:13 +02:00 committed by GitHub
commit 0cc8c6671c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 24 deletions

View File

@ -13,14 +13,44 @@
* limitations under the License. * limitations under the License.
*/ */
const { closePages, loadAndWait, mockClipboard } = require("./test_utils.js"); const {
closePages,
loadAndWait,
mockClipboard,
waitForEvent,
waitForTextLayer,
} = require("./test_utils.js");
const selectAll = async page => {
const promise = waitForEvent(page, "selectionchange");
await page.keyboard.down("Control");
await page.keyboard.press("a");
await page.keyboard.up("Control");
await promise;
await page.waitForFunction(() => {
const selection = document.getSelection();
const hiddenCopyElement = document.getElementById("hiddenCopyElement");
return selection.containsNode(hiddenCopyElement);
});
};
describe("Copy and paste", () => { describe("Copy and paste", () => {
describe("all text", () => { describe("all text", () => {
let pages; let pages;
beforeAll(async () => { beforeAll(async () => {
pages = await loadAndWait("tracemonkey.pdf", ".textLayer"); pages = await loadAndWait(
"tracemonkey.pdf",
"#hiddenCopyElement",
100,
async page => {
await page.waitForFunction(
() => !!window.PDFViewerApplication.eventBus
);
await waitForTextLayer(page);
}
);
await mockClipboard(pages); await mockClipboard(pages);
}); });
@ -31,30 +61,28 @@ describe("Copy and paste", () => {
it("must check that we've all the contents on copy/paste", async () => { it("must check that we've all the contents on copy/paste", async () => {
await Promise.all( await Promise.all(
pages.map(async ([browserName, page]) => { pages.map(async ([browserName, page]) => {
await page.keyboard.down("Control"); await selectAll(page);
await page.keyboard.press("a");
await page.keyboard.up("Control");
await page.waitForTimeout(500);
const promise = waitForEvent(page, "copy");
await page.keyboard.down("Control"); await page.keyboard.down("Control");
await page.keyboard.press("c"); await page.keyboard.press("c");
await page.keyboard.up("Control"); await page.keyboard.up("Control");
await promise;
await page.waitForTimeout(500);
await page.waitForFunction( await page.waitForFunction(
`document.querySelector('#viewerContainer').style.cursor !== "wait"` `document.querySelector('#viewerContainer').style.cursor !== "wait"`
); );
await page.waitForFunction(
async () =>
!!(await navigator.clipboard.readText())?.includes(
"Dynamic languages such as JavaScript"
)
);
const text = await page.evaluate(() => const text = await page.evaluate(() =>
navigator.clipboard.readText() navigator.clipboard.readText()
); );
expect(!!text).withContext(`In ${browserName}`).toEqual(true);
expect(text.includes("Dynamic languages such as JavaScript"))
.withContext(`In ${browserName}`)
.toEqual(true);
expect( expect(
text.includes("This section provides an overview of our system") text.includes("This section provides an overview of our system")
) )
@ -117,11 +145,21 @@ describe("Copy and paste", () => {
); );
}); });
}); });
describe("all text", () => { describe("Copy/paste and ligatures", () => {
let pages; let pages;
beforeAll(async () => { beforeAll(async () => {
pages = await loadAndWait("copy_paste_ligatures.pdf", ".textLayer"); pages = await loadAndWait(
"copy_paste_ligatures.pdf",
"#hiddenCopyElement",
100,
async page => {
await page.waitForFunction(
() => !!window.PDFViewerApplication.eventBus
);
await waitForTextLayer(page);
}
);
await mockClipboard(pages); await mockClipboard(pages);
}); });
@ -129,30 +167,29 @@ describe("Copy and paste", () => {
await closePages(pages); await closePages(pages);
}); });
it("must check that we've all the contents on copy/paste", async () => { it("must check that the ligatures have been removed when the text has been copied", async () => {
await Promise.all( await Promise.all(
pages.map(async ([browserName, page]) => { pages.map(async ([browserName, page]) => {
await page.keyboard.down("Control"); await selectAll(page);
await page.keyboard.press("a");
await page.keyboard.up("Control");
await page.waitForTimeout(100);
const promise = waitForEvent(page, "copy");
await page.keyboard.down("Control"); await page.keyboard.down("Control");
await page.keyboard.press("c"); await page.keyboard.press("c");
await page.keyboard.up("Control"); await page.keyboard.up("Control");
await promise;
await page.waitForTimeout(100);
await page.waitForFunction( await page.waitForFunction(
`document.querySelector('#viewerContainer').style.cursor !== "wait"` `document.querySelector('#viewerContainer').style.cursor !== "wait"`
); );
await page.waitForFunction(
async () => !!(await navigator.clipboard.readText())
);
const text = await page.evaluate(() => const text = await page.evaluate(() =>
navigator.clipboard.readText() navigator.clipboard.readText()
); );
expect(!!text).withContext(`In ${browserName}`).toEqual(true);
expect(text) expect(text)
.withContext(`In ${browserName}`) .withContext(`In ${browserName}`)
.toEqual("abcdeffffiflffifflſtstghijklmno"); .toEqual("abcdeffffiflffifflſtstghijklmno");

View File

@ -253,6 +253,15 @@ async function waitForAnnotationEditorLayer(page) {
} }
exports.waitForAnnotationEditorLayer = waitForAnnotationEditorLayer; exports.waitForAnnotationEditorLayer = waitForAnnotationEditorLayer;
async function waitForTextLayer(page) {
return page.evaluate(() => {
return new Promise(resolve => {
window.PDFViewerApplication.eventBus.on("textlayerrendered", resolve);
});
});
}
exports.waitForTextLayer = waitForTextLayer;
async function scrollIntoView(page, selector) { async function scrollIntoView(page, selector) {
const promise = page.evaluate( const promise = page.evaluate(
sel => sel =>