Skip to content

Commit

Permalink
Merge pull request #17059 from calixteman/fix_copy_paste_integration_…
Browse files Browse the repository at this point in the history
…test

Remove timeouts from the copy_paste integration test
  • Loading branch information
calixteman authored Oct 3, 2023
2 parents 0986e40 + bb59f44 commit 0cc8c66
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 24 deletions.
85 changes: 61 additions & 24 deletions test/integration/copy_paste_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,44 @@
* 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("all text", () => {
let pages;

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);
});

Expand All @@ -31,30 +61,28 @@ describe("Copy and paste", () => {
it("must check that we've all the contents on copy/paste", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await page.keyboard.down("Control");
await page.keyboard.press("a");
await page.keyboard.up("Control");

await page.waitForTimeout(500);
await selectAll(page);

const promise = waitForEvent(page, "copy");
await page.keyboard.down("Control");
await page.keyboard.press("c");
await page.keyboard.up("Control");

await page.waitForTimeout(500);
await promise;

await page.waitForFunction(
`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(() =>
navigator.clipboard.readText()
);

expect(!!text).withContext(`In ${browserName}`).toEqual(true);
expect(text.includes("Dynamic languages such as JavaScript"))
.withContext(`In ${browserName}`)
.toEqual(true);
expect(
text.includes("This section provides an overview of our system")
)
Expand Down Expand Up @@ -117,42 +145,51 @@ describe("Copy and paste", () => {
);
});
});
describe("all text", () => {
describe("Copy/paste and ligatures", () => {
let pages;

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);
});

afterAll(async () => {
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(
pages.map(async ([browserName, page]) => {
await page.keyboard.down("Control");
await page.keyboard.press("a");
await page.keyboard.up("Control");

await page.waitForTimeout(100);
await selectAll(page);

const promise = waitForEvent(page, "copy");
await page.keyboard.down("Control");
await page.keyboard.press("c");
await page.keyboard.up("Control");

await page.waitForTimeout(100);
await promise;

await page.waitForFunction(
`document.querySelector('#viewerContainer').style.cursor !== "wait"`
);

await page.waitForFunction(
async () => !!(await navigator.clipboard.readText())
);

const text = await page.evaluate(() =>
navigator.clipboard.readText()
);

expect(!!text).withContext(`In ${browserName}`).toEqual(true);
expect(text)
.withContext(`In ${browserName}`)
.toEqual("abcdeffffiflffifflſtstghijklmno");
Expand Down
9 changes: 9 additions & 0 deletions test/integration/test_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ async function waitForAnnotationEditorLayer(page) {
}
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) {
const promise = page.evaluate(
sel =>
Expand Down

0 comments on commit 0cc8c66

Please sign in to comment.